laya.d3.js 1.4 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346
  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. try{
  17922. var index = element._getIndexInList();
  17923. if (index !== -1)
  17924. throw "SimpleSingletonList:" + element + " has in SingletonList.";
  17925. this._add(element);
  17926. element._setIndexInList(this.length++);
  17927. }
  17928. catch(err){
  17929. console.log("SimpleSingletonList异常处理");
  17930. }
  17931. }
  17932. remove(element) {
  17933. try{
  17934. var index = element._getIndexInList();
  17935. this.length--;
  17936. if (index !== this.length) {
  17937. var end = this.elements[this.length];
  17938. this.elements[index] = end;
  17939. end._setIndexInList(index);
  17940. }
  17941. element._setIndexInList(-1);
  17942. }
  17943. catch(err){
  17944. console.log("SimpleSingletonList异常处理");
  17945. }
  17946. }
  17947. }
  17948. class MouseTouch {
  17949. constructor() {
  17950. this._pressedSprite = null;
  17951. this._pressedLoopCount = -1;
  17952. this.sprite = null;
  17953. this.mousePositionX = 0;
  17954. this.mousePositionY = 0;
  17955. }
  17956. }
  17957. class Touch {
  17958. constructor() {
  17959. this._indexInList = -1;
  17960. this._identifier = -1;
  17961. this._position = new Vector2();
  17962. }
  17963. get identifier() {
  17964. return this._identifier;
  17965. }
  17966. get position() {
  17967. return this._position;
  17968. }
  17969. _getIndexInList() {
  17970. return this._indexInList;
  17971. }
  17972. _setIndexInList(index) {
  17973. this._indexInList = index;
  17974. }
  17975. }
  17976. class Input3D {
  17977. constructor() {
  17978. this._eventList = [];
  17979. this._mouseTouch = new MouseTouch();
  17980. this._touchPool = [];
  17981. this._touches = new SimpleSingletonList();
  17982. this._multiTouchEnabled = true;
  17983. this._pushEventList = ((e) => {
  17984. e.preventDefault();
  17985. this._eventList.push(e);
  17986. }).bind(this);
  17987. }
  17988. __init__(canvas, scene) {
  17989. this._scene = scene;
  17990. canvas.oncontextmenu = function (e) {
  17991. return false;
  17992. };
  17993. }
  17994. _onCanvasEvent(canvas) {
  17995. canvas.addEventListener('mousedown', this._pushEventList);
  17996. canvas.addEventListener('mouseup', this._pushEventList, true);
  17997. canvas.addEventListener('mousemove', this._pushEventList, true);
  17998. canvas.addEventListener("touchstart", this._pushEventList);
  17999. canvas.addEventListener("touchend", this._pushEventList, true);
  18000. canvas.addEventListener("touchmove", this._pushEventList, true);
  18001. canvas.addEventListener("touchcancel", this._pushEventList, true);
  18002. }
  18003. _offCanvasEvent(canvas) {
  18004. canvas.removeEventListener('mousedown', this._pushEventList);
  18005. canvas.removeEventListener('mouseup', this._pushEventList, true);
  18006. canvas.removeEventListener('mousemove', this._pushEventList, true);
  18007. canvas.removeEventListener("touchstart", this._pushEventList);
  18008. canvas.removeEventListener("touchend", this._pushEventList, true);
  18009. canvas.removeEventListener("touchmove", this._pushEventList, true);
  18010. canvas.removeEventListener("touchcancel", this._pushEventList, true);
  18011. this._eventList.length = 0;
  18012. this._touches.length = 0;
  18013. }
  18014. touchCount() {
  18015. return this._touches.length;
  18016. }
  18017. get multiTouchEnabled() {
  18018. return this._multiTouchEnabled;
  18019. }
  18020. set multiTouchEnabled(value) {
  18021. this._multiTouchEnabled = value;
  18022. }
  18023. _getTouch(touchID) {
  18024. var touch = this._touchPool[touchID];
  18025. if (!touch) {
  18026. touch = new Touch();
  18027. this._touchPool[touchID] = touch;
  18028. touch._identifier = touchID;
  18029. }
  18030. return touch;
  18031. }
  18032. _mouseTouchDown() {
  18033. var touch = this._mouseTouch;
  18034. var sprite = touch.sprite;
  18035. touch._pressedSprite = sprite;
  18036. touch._pressedLoopCount = Laya.Stat.loopCount;
  18037. if (sprite) {
  18038. var scripts = sprite._scripts;
  18039. if (scripts) {
  18040. for (var i = 0, n = scripts.length; i < n; i++)
  18041. scripts[i].onMouseDown();
  18042. }
  18043. }
  18044. }
  18045. _mouseTouchUp() {
  18046. var i, n;
  18047. var touch = this._mouseTouch;
  18048. var lastPressedSprite = touch._pressedSprite;
  18049. touch._pressedSprite = null;
  18050. touch._pressedLoopCount = -1;
  18051. var sprite = touch.sprite;
  18052. if (sprite) {
  18053. if (sprite === lastPressedSprite) {
  18054. var scripts = sprite._scripts;
  18055. if (scripts) {
  18056. for (i = 0, n = scripts.length; i < n; i++)
  18057. scripts[i].onMouseClick();
  18058. }
  18059. }
  18060. }
  18061. if (lastPressedSprite) {
  18062. var lastScripts = lastPressedSprite._scripts;
  18063. if (lastScripts) {
  18064. for (i = 0, n = lastScripts.length; i < n; i++)
  18065. lastScripts[i].onMouseUp();
  18066. }
  18067. }
  18068. }
  18069. _mouseTouchRayCast(cameras) {
  18070. var touchHitResult = Input3D._tempHitResult0;
  18071. var touchPos = Input3D._tempVector20;
  18072. var touchRay = Input3D._tempRay0;
  18073. touchHitResult.succeeded = false;
  18074. var x = this._mouseTouch.mousePositionX;
  18075. var y = this._mouseTouch.mousePositionY;
  18076. touchPos.x = x;
  18077. touchPos.y = y;
  18078. for (var i = cameras.length - 1; i >= 0; i--) {
  18079. var camera = cameras[i];
  18080. var viewport = camera.viewport;
  18081. if (touchPos.x >= viewport.x && touchPos.y >= viewport.y && touchPos.x <= viewport.width && touchPos.y <= viewport.height) {
  18082. camera.viewportPointToRay(touchPos, touchRay);
  18083. var sucess = this._scene._physicsSimulation.rayCast(touchRay, touchHitResult);
  18084. if (sucess || (camera.clearFlag === BaseCamera.CLEARFLAG_SOLIDCOLOR || camera.clearFlag === BaseCamera.CLEARFLAG_SKY))
  18085. break;
  18086. }
  18087. }
  18088. var touch = this._mouseTouch;
  18089. var lastSprite = touch.sprite;
  18090. if (touchHitResult.succeeded) {
  18091. var touchSprite = touchHitResult.collider.owner;
  18092. touch.sprite = touchSprite;
  18093. var scripts = touchSprite._scripts;
  18094. if (lastSprite !== touchSprite) {
  18095. if (scripts) {
  18096. for (var j = 0, m = scripts.length; j < m; j++)
  18097. scripts[j].onMouseEnter();
  18098. }
  18099. }
  18100. }
  18101. else {
  18102. touch.sprite = null;
  18103. }
  18104. if (lastSprite && (lastSprite !== touchSprite)) {
  18105. var outScripts = lastSprite._scripts;
  18106. if (outScripts) {
  18107. for (j = 0, m = outScripts.length; j < m; j++)
  18108. outScripts[j].onMouseOut();
  18109. }
  18110. }
  18111. }
  18112. _changeTouches(changedTouches, flag) {
  18113. var offsetX = 0, offsetY = 0;
  18114. var lastCount = this._touches.length;
  18115. for (var j = 0, m = changedTouches.length; j < m; j++) {
  18116. var nativeTouch = changedTouches[j];
  18117. var identifier = nativeTouch.identifier;
  18118. if (!this._multiTouchEnabled && identifier !== 0)
  18119. continue;
  18120. var touch = this._getTouch(identifier);
  18121. var pos = touch._position;
  18122. var mousePoint = Input3D._tempPoint;
  18123. mousePoint.setTo(nativeTouch.pageX, nativeTouch.pageY);
  18124. Laya.ILaya.stage._canvasTransform.invertTransformPoint(mousePoint);
  18125. var posX = mousePoint.x;
  18126. var posY = mousePoint.y;
  18127. switch (flag) {
  18128. case 0:
  18129. this._touches.add(touch);
  18130. offsetX += posX;
  18131. offsetY += posY;
  18132. break;
  18133. case 1:
  18134. this._touches.remove(touch);
  18135. offsetX -= posX;
  18136. offsetY -= posY;
  18137. break;
  18138. case 2:
  18139. offsetX = posX - pos.x;
  18140. offsetY = posY - pos.y;
  18141. break;
  18142. }
  18143. pos.x = posX;
  18144. pos.y = posY;
  18145. }
  18146. var touchCount = this._touches.length;
  18147. if (touchCount === 0) {
  18148. this._mouseTouch.mousePositionX = 0;
  18149. this._mouseTouch.mousePositionY = 0;
  18150. }
  18151. else {
  18152. this._mouseTouch.mousePositionX = (this._mouseTouch.mousePositionX * lastCount + offsetX) / touchCount;
  18153. this._mouseTouch.mousePositionY = (this._mouseTouch.mousePositionY * lastCount + offsetY) / touchCount;
  18154. }
  18155. }
  18156. _update() {
  18157. var enablePhysics = Physics3D._enbalePhysics && !PhysicsSimulation.disableSimulation;
  18158. var i, n, j, m;
  18159. n = this._eventList.length;
  18160. var cameras = this._scene._cameraPool;
  18161. if (n > 0) {
  18162. var rayCast = false;
  18163. for (i = 0; i < n; i++) {
  18164. var e = this._eventList[i];
  18165. switch (e.type) {
  18166. case "mousedown":
  18167. (enablePhysics) && (this._mouseTouchDown());
  18168. break;
  18169. case "mouseup":
  18170. (enablePhysics) && (this._mouseTouchUp());
  18171. break;
  18172. case "mousemove":
  18173. var mousePoint = Input3D._tempPoint;
  18174. mousePoint.setTo(e.pageX, e.pageY);
  18175. Laya.ILaya.stage._canvasTransform.invertTransformPoint(mousePoint);
  18176. this._mouseTouch.mousePositionX = mousePoint.x;
  18177. this._mouseTouch.mousePositionY = mousePoint.y;
  18178. (enablePhysics) && (rayCast = true);
  18179. break;
  18180. case "touchstart":
  18181. var lastLength = this._touches.length;
  18182. this._changeTouches(e.changedTouches, 0);
  18183. if (enablePhysics) {
  18184. rayCast = true;
  18185. (lastLength === 0) && (this._mouseTouchDown());
  18186. }
  18187. break;
  18188. case "touchend":
  18189. case "touchcancel":
  18190. this._changeTouches(e.changedTouches, 1);
  18191. (enablePhysics && this._touches.length === 0) && (this._mouseTouchUp());
  18192. break;
  18193. case "touchmove":
  18194. this._changeTouches(e.changedTouches, 2);
  18195. (enablePhysics) && (rayCast = true);
  18196. break;
  18197. default:
  18198. throw "Input3D:unkonwn event type.";
  18199. }
  18200. }
  18201. (rayCast) && (this._mouseTouchRayCast(cameras));
  18202. this._eventList.length = 0;
  18203. }
  18204. if (enablePhysics) {
  18205. var mouseTouch = this._mouseTouch;
  18206. var pressedSprite = mouseTouch._pressedSprite;
  18207. if (pressedSprite && (Laya.Stat.loopCount > mouseTouch._pressedLoopCount)) {
  18208. var pressedScripts = pressedSprite._scripts;
  18209. if (pressedScripts) {
  18210. for (j = 0, m = pressedScripts.length; j < m; j++)
  18211. pressedScripts[j].onMouseDrag();
  18212. }
  18213. }
  18214. var touchSprite = mouseTouch.sprite;
  18215. if (touchSprite) {
  18216. var scripts = touchSprite._scripts;
  18217. if (scripts) {
  18218. for (j = 0, m = scripts.length; j < m; j++)
  18219. scripts[j].onMouseOver();
  18220. }
  18221. }
  18222. }
  18223. }
  18224. getTouch(index) {
  18225. if (index < this._touches.length) {
  18226. return this._touches.elements[index];
  18227. }
  18228. else {
  18229. return null;
  18230. }
  18231. }
  18232. }
  18233. Input3D._tempPoint = new Laya.Point();
  18234. Input3D._tempVector20 = new Vector2();
  18235. Input3D._tempRay0 = new Ray(new Vector3(), new Vector3());
  18236. Input3D._tempHitResult0 = new HitResult();
  18237. class PhysicsSettings {
  18238. constructor() {
  18239. this.flags = 0;
  18240. this.maxSubSteps = 1;
  18241. this.fixedTimeStep = 1.0 / 60.0;
  18242. }
  18243. }
  18244. class VertexPositionTexture0 {
  18245. static get vertexDeclaration() {
  18246. return VertexPositionTexture0._vertexDeclaration;
  18247. }
  18248. static __init__() {
  18249. VertexPositionTexture0._vertexDeclaration = new VertexDeclaration(20, [new VertexElement(0, VertexElementFormat.Vector3, VertexMesh.MESH_POSITION0),
  18250. new VertexElement(12, VertexElementFormat.Vector2, VertexMesh.MESH_TEXTURECOORDINATE0)]);
  18251. }
  18252. get position() {
  18253. return this._position;
  18254. }
  18255. get textureCoordinate0() {
  18256. return this._textureCoordinate0;
  18257. }
  18258. get vertexDeclaration() {
  18259. return VertexPositionTexture0._vertexDeclaration;
  18260. }
  18261. constructor(position, textureCoordinate0) {
  18262. this._position = position;
  18263. this._textureCoordinate0 = textureCoordinate0;
  18264. }
  18265. }
  18266. class SkyDome extends SkyMesh {
  18267. constructor(stacks = 48, slices = 48) {
  18268. super();
  18269. var gl = Laya.LayaGL.instance;
  18270. this._stacks = stacks;
  18271. this._slices = slices;
  18272. var vertexDeclaration = VertexPositionTexture0.vertexDeclaration;
  18273. var vertexFloatCount = vertexDeclaration.vertexStride / 4;
  18274. var numberVertices = (this._stacks + 1) * (this._slices + 1);
  18275. var numberIndices = (3 * this._stacks * (this._slices + 1)) * 2;
  18276. var vertices = new Float32Array(numberVertices * vertexFloatCount);
  18277. var indices = new Uint16Array(numberIndices);
  18278. var stackAngle = Math.PI / this._stacks;
  18279. var sliceAngle = (Math.PI * 2.0) / this._slices;
  18280. var vertexIndex = 0;
  18281. var vertexCount = 0;
  18282. var indexCount = 0;
  18283. for (var stack = 0; stack < (this._stacks + 1); stack++) {
  18284. var r = Math.sin(stack * stackAngle);
  18285. var y = Math.cos(stack * stackAngle);
  18286. for (var slice = 0; slice < (this._slices + 1); slice++) {
  18287. var x = r * Math.sin(slice * sliceAngle);
  18288. var z = r * Math.cos(slice * sliceAngle);
  18289. vertices[vertexCount + 0] = x * SkyDome._radius;
  18290. vertices[vertexCount + 1] = y * SkyDome._radius;
  18291. vertices[vertexCount + 2] = z * SkyDome._radius;
  18292. vertices[vertexCount + 3] = -(slice / this._slices) + 0.75;
  18293. vertices[vertexCount + 4] = stack / this._stacks;
  18294. vertexCount += vertexFloatCount;
  18295. if (stack != (this._stacks - 1)) {
  18296. indices[indexCount++] = vertexIndex + 1;
  18297. indices[indexCount++] = vertexIndex;
  18298. indices[indexCount++] = vertexIndex + (this._slices + 1);
  18299. indices[indexCount++] = vertexIndex + (this._slices + 1);
  18300. indices[indexCount++] = vertexIndex;
  18301. indices[indexCount++] = vertexIndex + (this._slices);
  18302. vertexIndex++;
  18303. }
  18304. }
  18305. }
  18306. this._vertexBuffer = new VertexBuffer3D(vertices.length * 4, gl.STATIC_DRAW, false);
  18307. this._vertexBuffer.vertexDeclaration = vertexDeclaration;
  18308. this._indexBuffer = new IndexBuffer3D(IndexBuffer3D.INDEXTYPE_USHORT, indices.length, gl.STATIC_DRAW, false);
  18309. this._vertexBuffer.setData(vertices.buffer);
  18310. this._indexBuffer.setData(indices);
  18311. var bufferState = new BufferState();
  18312. bufferState.bind();
  18313. bufferState.applyVertexBuffer(this._vertexBuffer);
  18314. bufferState.applyIndexBuffer(this._indexBuffer);
  18315. bufferState.unBind();
  18316. this._bufferState = bufferState;
  18317. }
  18318. static __init__() {
  18319. SkyDome.instance = new SkyDome();
  18320. }
  18321. get stacks() {
  18322. return this._stacks;
  18323. }
  18324. get slices() {
  18325. return this._slices;
  18326. }
  18327. _render(state) {
  18328. var gl = Laya.LayaGL.instance;
  18329. var indexCount = this._indexBuffer.indexCount;
  18330. gl.drawElements(gl.TRIANGLES, indexCount, gl.UNSIGNED_SHORT, 0);
  18331. Laya.Stat.trianglesFaces += indexCount / 3;
  18332. Laya.Stat.renderBatches++;
  18333. }
  18334. }
  18335. SkyDome._radius = 1;
  18336. class PostProcessRenderContext {
  18337. constructor() {
  18338. this.source = null;
  18339. this.destination = null;
  18340. this.camera = null;
  18341. this.compositeShaderData = null;
  18342. this.command = null;
  18343. this.deferredReleaseTextures = [];
  18344. }
  18345. }
  18346. class PostProcess {
  18347. constructor() {
  18348. this._compositeShader = Shader3D.find("PostProcessComposite");
  18349. this._compositeShaderData = new ShaderData();
  18350. this._context = null;
  18351. this._effects = [];
  18352. this._context = new PostProcessRenderContext();
  18353. this._context.compositeShaderData = this._compositeShaderData;
  18354. }
  18355. static __init__() {
  18356. PostProcess.SHADERDEFINE_BLOOM_LOW = PostProcess.shaderDefines.registerDefine("BLOOM_LOW");
  18357. PostProcess.SHADERDEFINE_BLOOM = PostProcess.shaderDefines.registerDefine("BLOOM");
  18358. PostProcess.SHADERDEFINE_FINALPASS = PostProcess.shaderDefines.registerDefine("FINALPASS");
  18359. }
  18360. _init(camera, command) {
  18361. this._context.camera = camera;
  18362. this._context.command = command;
  18363. }
  18364. _render() {
  18365. var noteValue = ShaderData._SET_RUNTIME_VALUE_MODE_REFERENCE_;
  18366. Laya.ILaya.Render.supportWebGLPlusRendering && ShaderData.setRuntimeValueMode(false);
  18367. var camera = this._context.camera;
  18368. var screenTexture = RenderTexture.createFromPool(RenderContext3D.clientWidth, RenderContext3D.clientHeight, camera._getRenderTextureFormat(), Laya.BaseTexture.FORMAT_DEPTHSTENCIL_NONE);
  18369. var cameraTarget = camera._renderTexture;
  18370. this._context.command.clear();
  18371. this._context.source = screenTexture;
  18372. this._context.destination = cameraTarget;
  18373. this._context.compositeShaderData.clearDefine();
  18374. this._context.command.blitScreenTriangle(cameraTarget, screenTexture);
  18375. this._context.compositeShaderData.setTexture(PostProcess.SHADERVALUE_AUTOEXPOSURETEX, Laya.Texture2D.whiteTexture);
  18376. for (var i = 0, n = this._effects.length; i < n; i++)
  18377. this._effects[i].render(this._context);
  18378. this._compositeShaderData.addDefine(PostProcess.SHADERDEFINE_FINALPASS);
  18379. var offScreenTexture = camera.renderTarget;
  18380. var dest = offScreenTexture ? offScreenTexture : null;
  18381. this._context.destination = dest;
  18382. this._context.command.blitScreenTriangle(this._context.source, dest, this._compositeShader, this._compositeShaderData);
  18383. RenderTexture.recoverToPool(screenTexture);
  18384. var tempRenderTextures = this._context.deferredReleaseTextures;
  18385. for (i = 0, n = tempRenderTextures.length; i < n; i++)
  18386. RenderTexture.recoverToPool(tempRenderTextures[i]);
  18387. tempRenderTextures.length = 0;
  18388. Laya.ILaya.Render.supportWebGLPlusRendering && ShaderData.setRuntimeValueMode(noteValue);
  18389. }
  18390. addEffect(effect) {
  18391. this._effects.push(effect);
  18392. }
  18393. removeEffect(effect) {
  18394. var index = this._effects.indexOf(effect);
  18395. if (index !== -1)
  18396. this._effects.splice(index, 1);
  18397. }
  18398. }
  18399. PostProcess.SHADERVALUE_MAINTEX = Shader3D.propertyNameToID("u_MainTex");
  18400. PostProcess.SHADERVALUE_BLOOMTEX = Shader3D.propertyNameToID("u_BloomTex");
  18401. PostProcess.SHADERVALUE_AUTOEXPOSURETEX = Shader3D.propertyNameToID("u_AutoExposureTex");
  18402. PostProcess.SHADERVALUE_BLOOM_DIRTTEX = Shader3D.propertyNameToID("u_Bloom_DirtTex");
  18403. PostProcess.SHADERVALUE_BLOOMTEX_TEXELSIZE = Shader3D.propertyNameToID("u_BloomTex_TexelSize");
  18404. PostProcess.SHADERVALUE_BLOOM_DIRTTILEOFFSET = Shader3D.propertyNameToID("u_Bloom_DirtTileOffset");
  18405. PostProcess.SHADERVALUE_BLOOM_SETTINGS = Shader3D.propertyNameToID("u_Bloom_Settings");
  18406. PostProcess.SHADERVALUE_BLOOM_COLOR = Shader3D.propertyNameToID("u_Bloom_Color");
  18407. PostProcess.shaderDefines = new ShaderDefines();
  18408. class EffectMaterial extends BaseMaterial {
  18409. constructor() {
  18410. super();
  18411. this.setShaderName("Effect");
  18412. this._color = new Vector4(1.0, 1.0, 1.0, 1.0);
  18413. this._shaderValues.setVector(EffectMaterial.TINTCOLOR, new Vector4(1.0, 1.0, 1.0, 1.0));
  18414. this.renderMode = EffectMaterial.RENDERMODE_ADDTIVE;
  18415. }
  18416. static __initDefine__() {
  18417. EffectMaterial.shaderDefines = new ShaderDefines(BaseMaterial.shaderDefines);
  18418. EffectMaterial.SHADERDEFINE_MAINTEXTURE = EffectMaterial.shaderDefines.registerDefine("MAINTEXTURE");
  18419. EffectMaterial.SHADERDEFINE_TILINGOFFSET = EffectMaterial.shaderDefines.registerDefine("TILINGOFFSET");
  18420. EffectMaterial.SHADERDEFINE_ADDTIVEFOG = EffectMaterial.shaderDefines.registerDefine("ADDTIVEFOG");
  18421. }
  18422. get _TintColorR() {
  18423. return this._color.x;
  18424. }
  18425. set _TintColorR(value) {
  18426. this._color.x = value;
  18427. this.color = this._color;
  18428. }
  18429. get _TintColorG() {
  18430. return this._color.y;
  18431. }
  18432. set _TintColorG(value) {
  18433. this._color.y = value;
  18434. this.color = this._color;
  18435. }
  18436. get _TintColorB() {
  18437. return this._color.z;
  18438. }
  18439. set _TintColorB(value) {
  18440. this._color.z = value;
  18441. this.color = this._color;
  18442. }
  18443. get _TintColorA() {
  18444. return this._color.w;
  18445. }
  18446. set _TintColorA(value) {
  18447. this._color.w = value;
  18448. this.color = this._color;
  18449. }
  18450. get _MainTex_STX() {
  18451. return this._shaderValues.getVector(EffectMaterial.TILINGOFFSET).x;
  18452. }
  18453. set _MainTex_STX(x) {
  18454. var tilOff = this._shaderValues.getVector(EffectMaterial.TILINGOFFSET);
  18455. tilOff.x = x;
  18456. this.tilingOffset = tilOff;
  18457. }
  18458. get _MainTex_STY() {
  18459. return this._shaderValues.getVector(EffectMaterial.TILINGOFFSET).y;
  18460. }
  18461. set _MainTex_STY(y) {
  18462. var tilOff = this._shaderValues.getVector(EffectMaterial.TILINGOFFSET);
  18463. tilOff.y = y;
  18464. this.tilingOffset = tilOff;
  18465. }
  18466. get _MainTex_STZ() {
  18467. return this._shaderValues.getVector(EffectMaterial.TILINGOFFSET).z;
  18468. }
  18469. set _MainTex_STZ(z) {
  18470. var tilOff = this._shaderValues.getVector(EffectMaterial.TILINGOFFSET);
  18471. tilOff.z = z;
  18472. this.tilingOffset = tilOff;
  18473. }
  18474. get _MainTex_STW() {
  18475. return this._shaderValues.getVector(EffectMaterial.TILINGOFFSET).w;
  18476. }
  18477. set _MainTex_STW(w) {
  18478. var tilOff = this._shaderValues.getVector(EffectMaterial.TILINGOFFSET);
  18479. tilOff.w = w;
  18480. this.tilingOffset = tilOff;
  18481. }
  18482. set renderMode(value) {
  18483. switch (value) {
  18484. case EffectMaterial.RENDERMODE_ADDTIVE:
  18485. this.renderQueue = BaseMaterial.RENDERQUEUE_TRANSPARENT;
  18486. this.alphaTest = false;
  18487. this.depthWrite = false;
  18488. this.cull = RenderState.CULL_NONE;
  18489. this.blend = RenderState.BLEND_ENABLE_ALL;
  18490. this.blendSrc = RenderState.BLENDPARAM_SRC_ALPHA;
  18491. this.blendDst = RenderState.BLENDPARAM_ONE;
  18492. this.depthTest = RenderState.DEPTHTEST_LESS;
  18493. this._shaderValues.addDefine(EffectMaterial.SHADERDEFINE_ADDTIVEFOG);
  18494. break;
  18495. case EffectMaterial.RENDERMODE_ALPHABLENDED:
  18496. this.renderQueue = BaseMaterial.RENDERQUEUE_TRANSPARENT;
  18497. this.alphaTest = false;
  18498. this.depthWrite = false;
  18499. this.cull = RenderState.CULL_NONE;
  18500. this.blend = RenderState.BLEND_ENABLE_ALL;
  18501. this.blendSrc = RenderState.BLENDPARAM_SRC_ALPHA;
  18502. this.blendDst = RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA;
  18503. this.depthTest = RenderState.DEPTHTEST_LESS;
  18504. this._shaderValues.removeDefine(EffectMaterial.SHADERDEFINE_ADDTIVEFOG);
  18505. break;
  18506. default:
  18507. throw new Error("MeshEffectMaterial : renderMode value error.");
  18508. }
  18509. }
  18510. get colorR() {
  18511. return this._TintColorR;
  18512. }
  18513. set colorR(value) {
  18514. this._TintColorR = value;
  18515. }
  18516. get colorG() {
  18517. return this._TintColorG;
  18518. }
  18519. set colorG(value) {
  18520. this._TintColorG = value;
  18521. }
  18522. get colorB() {
  18523. return this._TintColorB;
  18524. }
  18525. set colorB(value) {
  18526. this._TintColorB = value;
  18527. }
  18528. get colorA() {
  18529. return this._TintColorA;
  18530. }
  18531. set colorA(value) {
  18532. this._TintColorA = value;
  18533. }
  18534. get color() {
  18535. return this._shaderValues.getVector(EffectMaterial.TINTCOLOR);
  18536. }
  18537. set color(value) {
  18538. this._shaderValues.setVector(EffectMaterial.TINTCOLOR, value);
  18539. }
  18540. get texture() {
  18541. return this._shaderValues.getTexture(EffectMaterial.MAINTEXTURE);
  18542. }
  18543. set texture(value) {
  18544. if (value)
  18545. this._shaderValues.addDefine(EffectMaterial.SHADERDEFINE_MAINTEXTURE);
  18546. else
  18547. this._shaderValues.removeDefine(EffectMaterial.SHADERDEFINE_MAINTEXTURE);
  18548. this._shaderValues.setTexture(EffectMaterial.MAINTEXTURE, value);
  18549. }
  18550. get tilingOffsetX() {
  18551. return this._MainTex_STX;
  18552. }
  18553. set tilingOffsetX(x) {
  18554. this._MainTex_STX = x;
  18555. }
  18556. get tilingOffsetY() {
  18557. return this._MainTex_STY;
  18558. }
  18559. set tilingOffsetY(y) {
  18560. this._MainTex_STY = y;
  18561. }
  18562. get tilingOffsetZ() {
  18563. return this._MainTex_STZ;
  18564. }
  18565. set tilingOffsetZ(z) {
  18566. this._MainTex_STZ = z;
  18567. }
  18568. get tilingOffsetW() {
  18569. return this._MainTex_STW;
  18570. }
  18571. set tilingOffsetW(w) {
  18572. this._MainTex_STW = w;
  18573. }
  18574. get tilingOffset() {
  18575. return this._shaderValues.getVector(EffectMaterial.TILINGOFFSET);
  18576. }
  18577. set tilingOffset(value) {
  18578. if (value) {
  18579. if (value.x != 1 || value.y != 1 || value.z != 0 || value.w != 0)
  18580. this._shaderValues.addDefine(EffectMaterial.SHADERDEFINE_TILINGOFFSET);
  18581. else
  18582. this._shaderValues.removeDefine(EffectMaterial.SHADERDEFINE_TILINGOFFSET);
  18583. }
  18584. else {
  18585. this._shaderValues.removeDefine(EffectMaterial.SHADERDEFINE_TILINGOFFSET);
  18586. }
  18587. this._shaderValues.setVector(EffectMaterial.TILINGOFFSET, value);
  18588. }
  18589. set depthWrite(value) {
  18590. this._shaderValues.setBool(EffectMaterial.DEPTH_WRITE, value);
  18591. }
  18592. get depthWrite() {
  18593. return this._shaderValues.getBool(EffectMaterial.DEPTH_WRITE);
  18594. }
  18595. set cull(value) {
  18596. this._shaderValues.setInt(EffectMaterial.CULL, value);
  18597. }
  18598. get cull() {
  18599. return this._shaderValues.getInt(EffectMaterial.CULL);
  18600. }
  18601. set blend(value) {
  18602. this._shaderValues.setInt(EffectMaterial.BLEND, value);
  18603. }
  18604. get blend() {
  18605. return this._shaderValues.getInt(EffectMaterial.BLEND);
  18606. }
  18607. set blendSrc(value) {
  18608. this._shaderValues.setInt(EffectMaterial.BLEND_SRC, value);
  18609. }
  18610. get blendSrc() {
  18611. return this._shaderValues.getInt(EffectMaterial.BLEND_SRC);
  18612. }
  18613. set blendDst(value) {
  18614. this._shaderValues.setInt(EffectMaterial.BLEND_DST, value);
  18615. }
  18616. get blendDst() {
  18617. return this._shaderValues.getInt(EffectMaterial.BLEND_DST);
  18618. }
  18619. set depthTest(value) {
  18620. this._shaderValues.setInt(EffectMaterial.DEPTH_TEST, value);
  18621. }
  18622. get depthTest() {
  18623. return this._shaderValues.getInt(EffectMaterial.DEPTH_TEST);
  18624. }
  18625. clone() {
  18626. var dest = new EffectMaterial();
  18627. this.cloneTo(dest);
  18628. return dest;
  18629. }
  18630. }
  18631. EffectMaterial.RENDERMODE_ADDTIVE = 0;
  18632. EffectMaterial.RENDERMODE_ALPHABLENDED = 1;
  18633. EffectMaterial.MAINTEXTURE = Shader3D.propertyNameToID("u_AlbedoTexture");
  18634. EffectMaterial.TINTCOLOR = Shader3D.propertyNameToID("u_AlbedoColor");
  18635. EffectMaterial.TILINGOFFSET = Shader3D.propertyNameToID("u_TilingOffset");
  18636. EffectMaterial.CULL = Shader3D.propertyNameToID("s_Cull");
  18637. EffectMaterial.BLEND = Shader3D.propertyNameToID("s_Blend");
  18638. EffectMaterial.BLEND_SRC = Shader3D.propertyNameToID("s_BlendSrc");
  18639. EffectMaterial.BLEND_DST = Shader3D.propertyNameToID("s_BlendDst");
  18640. EffectMaterial.DEPTH_TEST = Shader3D.propertyNameToID("s_DepthTest");
  18641. EffectMaterial.DEPTH_WRITE = Shader3D.propertyNameToID("s_DepthWrite");
  18642. EffectMaterial.shaderDefines = null;
  18643. class ExtendTerrainMaterial extends BaseMaterial {
  18644. constructor() {
  18645. super();
  18646. this._enableLighting = true;
  18647. this.setShaderName("ExtendTerrain");
  18648. this.renderMode = ExtendTerrainMaterial.RENDERMODE_OPAQUE;
  18649. }
  18650. static __initDefine__() {
  18651. ExtendTerrainMaterial.shaderDefines = new ShaderDefines(BaseMaterial.shaderDefines);
  18652. ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM1 = ExtendTerrainMaterial.shaderDefines.registerDefine("ExtendTerrain_DETAIL_NUM1");
  18653. ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM2 = ExtendTerrainMaterial.shaderDefines.registerDefine("ExtendTerrain_DETAIL_NUM2");
  18654. ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM3 = ExtendTerrainMaterial.shaderDefines.registerDefine("ExtendTerrain_DETAIL_NUM3");
  18655. ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM4 = ExtendTerrainMaterial.shaderDefines.registerDefine("ExtendTerrain_DETAIL_NUM4");
  18656. ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM5 = ExtendTerrainMaterial.shaderDefines.registerDefine("ExtendTerrain_DETAIL_NUM5");
  18657. }
  18658. get splatAlphaTexture() {
  18659. return this._shaderValues.getTexture(ExtendTerrainMaterial.SPLATALPHATEXTURE);
  18660. }
  18661. set splatAlphaTexture(value) {
  18662. this._shaderValues.setTexture(ExtendTerrainMaterial.SPLATALPHATEXTURE, value);
  18663. }
  18664. set diffuseTexture1(value) {
  18665. this._shaderValues.setTexture(ExtendTerrainMaterial.DIFFUSETEXTURE1, value);
  18666. this._setDetailNum(1);
  18667. }
  18668. get diffuseTexture2() {
  18669. return this._shaderValues.getTexture(ExtendTerrainMaterial.DIFFUSETEXTURE2);
  18670. }
  18671. set diffuseTexture2(value) {
  18672. this._shaderValues.setTexture(ExtendTerrainMaterial.DIFFUSETEXTURE2, value);
  18673. this._setDetailNum(2);
  18674. }
  18675. get diffuseTexture3() {
  18676. return this._shaderValues.getTexture(ExtendTerrainMaterial.DIFFUSETEXTURE3);
  18677. }
  18678. set diffuseTexture3(value) {
  18679. this._shaderValues.setTexture(ExtendTerrainMaterial.DIFFUSETEXTURE3, value);
  18680. this._setDetailNum(3);
  18681. }
  18682. get diffuseTexture4() {
  18683. return this._shaderValues.getTexture(ExtendTerrainMaterial.DIFFUSETEXTURE4);
  18684. }
  18685. set diffuseTexture4(value) {
  18686. this._shaderValues.setTexture(ExtendTerrainMaterial.DIFFUSETEXTURE4, value);
  18687. this._setDetailNum(4);
  18688. }
  18689. get diffuseTexture5() {
  18690. return this._shaderValues.getTexture(ExtendTerrainMaterial.DIFFUSETEXTURE5);
  18691. }
  18692. set diffuseTexture5(value) {
  18693. this._shaderValues.setTexture(ExtendTerrainMaterial.DIFFUSETEXTURE5, value);
  18694. this._setDetailNum(5);
  18695. }
  18696. _setDetailNum(value) {
  18697. switch (value) {
  18698. case 1:
  18699. this._shaderValues.addDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM1);
  18700. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM2);
  18701. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM3);
  18702. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM4);
  18703. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM5);
  18704. break;
  18705. case 2:
  18706. this._shaderValues.addDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM2);
  18707. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM1);
  18708. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM3);
  18709. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM4);
  18710. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM5);
  18711. break;
  18712. case 3:
  18713. this._shaderValues.addDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM3);
  18714. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM1);
  18715. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM2);
  18716. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM4);
  18717. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM5);
  18718. break;
  18719. case 4:
  18720. this._shaderValues.addDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM4);
  18721. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM1);
  18722. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM2);
  18723. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM3);
  18724. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM5);
  18725. break;
  18726. case 5:
  18727. this._shaderValues.addDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM5);
  18728. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM1);
  18729. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM2);
  18730. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM3);
  18731. this._shaderValues.removeDefine(ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM4);
  18732. break;
  18733. }
  18734. }
  18735. set diffuseScaleOffset1(scaleOffset1) {
  18736. this._shaderValues.setVector(ExtendTerrainMaterial.DIFFUSESCALEOFFSET1, scaleOffset1);
  18737. }
  18738. set diffuseScaleOffset2(scaleOffset2) {
  18739. this._shaderValues.setVector(ExtendTerrainMaterial.DIFFUSESCALEOFFSET2, scaleOffset2);
  18740. }
  18741. set diffuseScaleOffset3(scaleOffset3) {
  18742. this._shaderValues.setVector(ExtendTerrainMaterial.DIFFUSESCALEOFFSET3, scaleOffset3);
  18743. }
  18744. set diffuseScaleOffset4(scaleOffset4) {
  18745. this._shaderValues.setVector(ExtendTerrainMaterial.DIFFUSESCALEOFFSET4, scaleOffset4);
  18746. }
  18747. set diffuseScaleOffset5(scaleOffset5) {
  18748. this._shaderValues.setVector(ExtendTerrainMaterial.DIFFUSESCALEOFFSET5, scaleOffset5);
  18749. }
  18750. get enableLighting() {
  18751. return this._enableLighting;
  18752. }
  18753. set enableLighting(value) {
  18754. if (this._enableLighting !== value) {
  18755. if (value)
  18756. this._disablePublicDefineDatas.remove(Scene3DShaderDeclaration.SHADERDEFINE_POINTLIGHT | Scene3DShaderDeclaration.SHADERDEFINE_SPOTLIGHT | Scene3DShaderDeclaration.SHADERDEFINE_DIRECTIONLIGHT);
  18757. else
  18758. this._disablePublicDefineDatas.add(Scene3DShaderDeclaration.SHADERDEFINE_POINTLIGHT | Scene3DShaderDeclaration.SHADERDEFINE_SPOTLIGHT | Scene3DShaderDeclaration.SHADERDEFINE_DIRECTIONLIGHT);
  18759. this._enableLighting = value;
  18760. }
  18761. }
  18762. set renderMode(value) {
  18763. switch (value) {
  18764. case ExtendTerrainMaterial.RENDERMODE_OPAQUE:
  18765. this.renderQueue = BaseMaterial.RENDERQUEUE_OPAQUE;
  18766. this.depthWrite = true;
  18767. this.cull = RenderState.CULL_BACK;
  18768. this.blend = RenderState.BLEND_DISABLE;
  18769. this.depthTest = RenderState.DEPTHTEST_LESS;
  18770. break;
  18771. case ExtendTerrainMaterial.RENDERMODE_TRANSPARENT:
  18772. this.renderQueue = BaseMaterial.RENDERQUEUE_OPAQUE;
  18773. this.depthWrite = false;
  18774. this.cull = RenderState.CULL_BACK;
  18775. this.blend = RenderState.BLEND_ENABLE_ALL;
  18776. this.blendSrc = RenderState.BLENDPARAM_SRC_ALPHA;
  18777. this.blendDst = RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA;
  18778. this.depthTest = RenderState.DEPTHTEST_LEQUAL;
  18779. break;
  18780. default:
  18781. throw new Error("ExtendTerrainMaterial:renderMode value error.");
  18782. }
  18783. }
  18784. set depthWrite(value) {
  18785. this._shaderValues.setBool(ExtendTerrainMaterial.DEPTH_WRITE, value);
  18786. }
  18787. get depthWrite() {
  18788. return this._shaderValues.getBool(ExtendTerrainMaterial.DEPTH_WRITE);
  18789. }
  18790. set cull(value) {
  18791. this._shaderValues.setInt(ExtendTerrainMaterial.CULL, value);
  18792. }
  18793. get cull() {
  18794. return this._shaderValues.getInt(ExtendTerrainMaterial.CULL);
  18795. }
  18796. set blend(value) {
  18797. this._shaderValues.setInt(ExtendTerrainMaterial.BLEND, value);
  18798. }
  18799. get blend() {
  18800. return this._shaderValues.getInt(ExtendTerrainMaterial.BLEND);
  18801. }
  18802. set blendSrc(value) {
  18803. this._shaderValues.setInt(ExtendTerrainMaterial.BLEND_SRC, value);
  18804. }
  18805. get blendSrc() {
  18806. return this._shaderValues.getInt(ExtendTerrainMaterial.BLEND_SRC);
  18807. }
  18808. set blendDst(value) {
  18809. this._shaderValues.setInt(ExtendTerrainMaterial.BLEND_DST, value);
  18810. }
  18811. get blendDst() {
  18812. return this._shaderValues.getInt(ExtendTerrainMaterial.BLEND_DST);
  18813. }
  18814. set depthTest(value) {
  18815. this._shaderValues.setInt(ExtendTerrainMaterial.DEPTH_TEST, value);
  18816. }
  18817. get depthTest() {
  18818. return this._shaderValues.getInt(ExtendTerrainMaterial.DEPTH_TEST);
  18819. }
  18820. clone() {
  18821. var dest = new ExtendTerrainMaterial();
  18822. this.cloneTo(dest);
  18823. return dest;
  18824. }
  18825. }
  18826. ExtendTerrainMaterial.RENDERMODE_OPAQUE = 1;
  18827. ExtendTerrainMaterial.RENDERMODE_TRANSPARENT = 2;
  18828. ExtendTerrainMaterial.SPLATALPHATEXTURE = Shader3D.propertyNameToID("u_SplatAlphaTexture");
  18829. ExtendTerrainMaterial.DIFFUSETEXTURE1 = Shader3D.propertyNameToID("u_DiffuseTexture1");
  18830. ExtendTerrainMaterial.DIFFUSETEXTURE2 = Shader3D.propertyNameToID("u_DiffuseTexture2");
  18831. ExtendTerrainMaterial.DIFFUSETEXTURE3 = Shader3D.propertyNameToID("u_DiffuseTexture3");
  18832. ExtendTerrainMaterial.DIFFUSETEXTURE4 = Shader3D.propertyNameToID("u_DiffuseTexture4");
  18833. ExtendTerrainMaterial.DIFFUSETEXTURE5 = Shader3D.propertyNameToID("u_DiffuseTexture5");
  18834. ExtendTerrainMaterial.DIFFUSESCALEOFFSET1 = Shader3D.propertyNameToID("u_DiffuseScaleOffset1");
  18835. ExtendTerrainMaterial.DIFFUSESCALEOFFSET2 = Shader3D.propertyNameToID("u_DiffuseScaleOffset2");
  18836. ExtendTerrainMaterial.DIFFUSESCALEOFFSET3 = Shader3D.propertyNameToID("u_DiffuseScaleOffset3");
  18837. ExtendTerrainMaterial.DIFFUSESCALEOFFSET4 = Shader3D.propertyNameToID("u_DiffuseScaleOffset4");
  18838. ExtendTerrainMaterial.DIFFUSESCALEOFFSET5 = Shader3D.propertyNameToID("u_DiffuseScaleOffset5");
  18839. ExtendTerrainMaterial.CULL = Shader3D.propertyNameToID("s_Cull");
  18840. ExtendTerrainMaterial.BLEND = Shader3D.propertyNameToID("s_Blend");
  18841. ExtendTerrainMaterial.BLEND_SRC = Shader3D.propertyNameToID("s_BlendSrc");
  18842. ExtendTerrainMaterial.BLEND_DST = Shader3D.propertyNameToID("s_BlendDst");
  18843. ExtendTerrainMaterial.DEPTH_TEST = Shader3D.propertyNameToID("s_DepthTest");
  18844. ExtendTerrainMaterial.DEPTH_WRITE = Shader3D.propertyNameToID("s_DepthWrite");
  18845. ExtendTerrainMaterial.shaderDefines = null;
  18846. class PBRSpecularMaterial extends BaseMaterial {
  18847. constructor() {
  18848. super();
  18849. this.setShaderName("PBRSpecular");
  18850. this._albedoColor = new Vector4(1.0, 1.0, 1.0, 1.0);
  18851. this._shaderValues.setVector(PBRSpecularMaterial.ALBEDOCOLOR, new Vector4(1.0, 1.0, 1.0, 1.0));
  18852. this._emissionColor = new Vector4(0.0, 0.0, 0.0, 0.0);
  18853. this._shaderValues.setVector(PBRSpecularMaterial.EMISSIONCOLOR, new Vector4(0.0, 0.0, 0.0, 0.0));
  18854. this._specularColor = new Vector4(0.2, 0.2, 0.2, 0.2);
  18855. this._shaderValues.setVector(PBRSpecularMaterial.SPECULARCOLOR, new Vector4(0.2, 0.2, 0.2, 0.2));
  18856. this._shaderValues.setNumber(PBRSpecularMaterial.SMOOTHNESS, 0.5);
  18857. this._shaderValues.setNumber(PBRSpecularMaterial.SMOOTHNESSSCALE, 1.0);
  18858. this._shaderValues.setNumber(PBRSpecularMaterial.SMOOTHNESSSOURCE, 0);
  18859. this._shaderValues.setNumber(PBRSpecularMaterial.OCCLUSIONSTRENGTH, 1.0);
  18860. this._shaderValues.setNumber(PBRSpecularMaterial.NORMALSCALE, 1.0);
  18861. this._shaderValues.setNumber(PBRSpecularMaterial.PARALLAXSCALE, 0.001);
  18862. this._shaderValues.setBool(PBRSpecularMaterial.ENABLEEMISSION, false);
  18863. this._shaderValues.setNumber(BaseMaterial.ALPHATESTVALUE, 0.5);
  18864. this.renderMode = PBRSpecularMaterial.RENDERMODE_OPAQUE;
  18865. }
  18866. static __initDefine__() {
  18867. PBRSpecularMaterial.shaderDefines = new ShaderDefines(BaseMaterial.shaderDefines);
  18868. PBRSpecularMaterial.SHADERDEFINE_ALBEDOTEXTURE = PBRSpecularMaterial.shaderDefines.registerDefine("ALBEDOTEXTURE");
  18869. PBRSpecularMaterial.SHADERDEFINE_SPECULARTEXTURE = PBRSpecularMaterial.shaderDefines.registerDefine("SPECULARTEXTURE");
  18870. PBRSpecularMaterial.SHADERDEFINE_SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA = PBRSpecularMaterial.shaderDefines.registerDefine("SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA");
  18871. PBRSpecularMaterial.SHADERDEFINE_NORMALTEXTURE = PBRSpecularMaterial.shaderDefines.registerDefine("NORMALTEXTURE");
  18872. PBRSpecularMaterial.SHADERDEFINE_PARALLAXTEXTURE = PBRSpecularMaterial.shaderDefines.registerDefine("PARALLAXTEXTURE");
  18873. PBRSpecularMaterial.SHADERDEFINE_OCCLUSIONTEXTURE = PBRSpecularMaterial.shaderDefines.registerDefine("OCCLUSIONTEXTURE");
  18874. PBRSpecularMaterial.SHADERDEFINE_EMISSION = PBRSpecularMaterial.shaderDefines.registerDefine("EMISSION");
  18875. PBRSpecularMaterial.SHADERDEFINE_EMISSIONTEXTURE = PBRSpecularMaterial.shaderDefines.registerDefine("EMISSIONTEXTURE");
  18876. PBRSpecularMaterial.SHADERDEFINE_TILINGOFFSET = PBRSpecularMaterial.shaderDefines.registerDefine("TILINGOFFSET");
  18877. PBRSpecularMaterial.SHADERDEFINE_ALPHAPREMULTIPLY = PBRSpecularMaterial.shaderDefines.registerDefine("ALPHAPREMULTIPLY");
  18878. }
  18879. get _ColorR() {
  18880. return this._albedoColor.x;
  18881. }
  18882. set _ColorR(value) {
  18883. this._albedoColor.x = value;
  18884. this.albedoColor = this._albedoColor;
  18885. }
  18886. get _ColorG() {
  18887. return this._albedoColor.y;
  18888. }
  18889. set _ColorG(value) {
  18890. this._albedoColor.y = value;
  18891. this.albedoColor = this._albedoColor;
  18892. }
  18893. get _ColorB() {
  18894. return this._albedoColor.z;
  18895. }
  18896. set _ColorB(value) {
  18897. this._albedoColor.z = value;
  18898. this.albedoColor = this._albedoColor;
  18899. }
  18900. get _ColorA() {
  18901. return this._albedoColor.w;
  18902. }
  18903. set _ColorA(value) {
  18904. this._albedoColor.w = value;
  18905. this.albedoColor = this._albedoColor;
  18906. }
  18907. get _SpecColorR() {
  18908. return this._specularColor.x;
  18909. }
  18910. set _SpecColorR(value) {
  18911. this._specularColor.x = value;
  18912. this.specularColor = this._specularColor;
  18913. }
  18914. get _SpecColorG() {
  18915. return this._specularColor.y;
  18916. }
  18917. set _SpecColorG(value) {
  18918. this._specularColor.y = value;
  18919. this.specularColor = this._specularColor;
  18920. }
  18921. get _SpecColorB() {
  18922. return this._specularColor.z;
  18923. }
  18924. set _SpecColorB(value) {
  18925. this._specularColor.z = value;
  18926. this.specularColor = this._specularColor;
  18927. }
  18928. get _SpecColorA() {
  18929. return this._specularColor.w;
  18930. }
  18931. set _SpecColorA(value) {
  18932. this._specularColor.w = value;
  18933. this.specularColor = this._specularColor;
  18934. }
  18935. get _Glossiness() {
  18936. return this._shaderValues.getNumber(PBRSpecularMaterial.SMOOTHNESS);
  18937. }
  18938. set _Glossiness(value) {
  18939. this._shaderValues.setNumber(PBRSpecularMaterial.SMOOTHNESS, value);
  18940. }
  18941. get _GlossMapScale() {
  18942. return this._shaderValues.getNumber(PBRSpecularMaterial.SMOOTHNESSSCALE);
  18943. }
  18944. set _GlossMapScale(value) {
  18945. this._shaderValues.setNumber(PBRSpecularMaterial.SMOOTHNESSSCALE, value);
  18946. }
  18947. get _BumpScale() {
  18948. return this._shaderValues.getNumber(PBRSpecularMaterial.NORMALSCALE);
  18949. }
  18950. set _BumpScale(value) {
  18951. this._shaderValues.setNumber(PBRSpecularMaterial.NORMALSCALE, value);
  18952. }
  18953. get _Parallax() {
  18954. return this._shaderValues.getNumber(PBRSpecularMaterial.PARALLAXSCALE);
  18955. }
  18956. set _Parallax(value) {
  18957. this._shaderValues.setNumber(PBRSpecularMaterial.PARALLAXSCALE, value);
  18958. }
  18959. get _OcclusionStrength() {
  18960. return this._shaderValues.getNumber(PBRSpecularMaterial.OCCLUSIONSTRENGTH);
  18961. }
  18962. set _OcclusionStrength(value) {
  18963. this._shaderValues.setNumber(PBRSpecularMaterial.OCCLUSIONSTRENGTH, value);
  18964. }
  18965. get _EmissionColorR() {
  18966. return this._emissionColor.x;
  18967. }
  18968. set _EmissionColorR(value) {
  18969. this._emissionColor.x = value;
  18970. this.emissionColor = this._emissionColor;
  18971. }
  18972. get _EmissionColorG() {
  18973. return this._emissionColor.y;
  18974. }
  18975. set _EmissionColorG(value) {
  18976. this._emissionColor.y = value;
  18977. this.emissionColor = this._emissionColor;
  18978. }
  18979. get _EmissionColorB() {
  18980. return this._emissionColor.z;
  18981. }
  18982. set _EmissionColorB(value) {
  18983. this._emissionColor.z = value;
  18984. this.emissionColor = this._emissionColor;
  18985. }
  18986. get _EmissionColorA() {
  18987. return this._emissionColor.w;
  18988. }
  18989. set _EmissionColorA(value) {
  18990. this._emissionColor.w = value;
  18991. this.emissionColor = this._emissionColor;
  18992. }
  18993. get _MainTex_STX() {
  18994. return this._shaderValues.getVector(PBRSpecularMaterial.TILINGOFFSET).x;
  18995. }
  18996. set _MainTex_STX(x) {
  18997. var tilOff = this._shaderValues.getVector(PBRSpecularMaterial.TILINGOFFSET);
  18998. tilOff.x = x;
  18999. this.tilingOffset = tilOff;
  19000. }
  19001. get _MainTex_STY() {
  19002. return this._shaderValues.getVector(PBRSpecularMaterial.TILINGOFFSET).y;
  19003. }
  19004. set _MainTex_STY(y) {
  19005. var tilOff = this._shaderValues.getVector(PBRSpecularMaterial.TILINGOFFSET);
  19006. tilOff.y = y;
  19007. this.tilingOffset = tilOff;
  19008. }
  19009. get _MainTex_STZ() {
  19010. return this._shaderValues.getVector(PBRSpecularMaterial.TILINGOFFSET).z;
  19011. }
  19012. set _MainTex_STZ(z) {
  19013. var tilOff = this._shaderValues.getVector(PBRSpecularMaterial.TILINGOFFSET);
  19014. tilOff.z = z;
  19015. this.tilingOffset = tilOff;
  19016. }
  19017. get _MainTex_STW() {
  19018. return this._shaderValues.getVector(PBRSpecularMaterial.TILINGOFFSET).w;
  19019. }
  19020. set _MainTex_STW(w) {
  19021. var tilOff = this._shaderValues.getVector(PBRSpecularMaterial.TILINGOFFSET);
  19022. tilOff.w = w;
  19023. this.tilingOffset = tilOff;
  19024. }
  19025. get _Cutoff() {
  19026. return this.alphaTestValue;
  19027. }
  19028. set _Cutoff(value) {
  19029. this.alphaTestValue = value;
  19030. }
  19031. get albedoColorR() {
  19032. return this._ColorR;
  19033. }
  19034. set albedoColorR(value) {
  19035. this._ColorR = value;
  19036. }
  19037. get albedoColorG() {
  19038. return this._ColorG;
  19039. }
  19040. set albedoColorG(value) {
  19041. this._ColorG = value;
  19042. }
  19043. get albedoColorB() {
  19044. return this._ColorB;
  19045. }
  19046. set albedoColorB(value) {
  19047. this._ColorB = value;
  19048. }
  19049. get albedoColorA() {
  19050. return this._ColorA;
  19051. }
  19052. set albedoColorA(value) {
  19053. this._ColorA = value;
  19054. }
  19055. get albedoColor() {
  19056. return this._albedoColor;
  19057. }
  19058. set albedoColor(value) {
  19059. this._albedoColor = value;
  19060. this._shaderValues.setVector(PBRSpecularMaterial.ALBEDOCOLOR, value);
  19061. }
  19062. get albedoTexture() {
  19063. return this._shaderValues.getTexture(PBRSpecularMaterial.ALBEDOTEXTURE);
  19064. }
  19065. set albedoTexture(value) {
  19066. if (value) {
  19067. this._shaderValues.addDefine(PBRSpecularMaterial.SHADERDEFINE_ALBEDOTEXTURE);
  19068. }
  19069. else {
  19070. this._shaderValues.removeDefine(PBRSpecularMaterial.SHADERDEFINE_ALBEDOTEXTURE);
  19071. }
  19072. this._shaderValues.setTexture(PBRSpecularMaterial.ALBEDOTEXTURE, value);
  19073. }
  19074. get normalTexture() {
  19075. return this._shaderValues.getTexture(PBRSpecularMaterial.NORMALTEXTURE);
  19076. }
  19077. set normalTexture(value) {
  19078. if (value) {
  19079. this._shaderValues.addDefine(PBRSpecularMaterial.SHADERDEFINE_NORMALTEXTURE);
  19080. }
  19081. else {
  19082. this._shaderValues.removeDefine(PBRSpecularMaterial.SHADERDEFINE_NORMALTEXTURE);
  19083. }
  19084. this._shaderValues.setTexture(PBRSpecularMaterial.NORMALTEXTURE, value);
  19085. }
  19086. get normalTextureScale() {
  19087. return this._BumpScale;
  19088. }
  19089. set normalTextureScale(value) {
  19090. this._BumpScale = value;
  19091. }
  19092. get parallaxTexture() {
  19093. return this._shaderValues.getTexture(PBRSpecularMaterial.PARALLAXTEXTURE);
  19094. }
  19095. set parallaxTexture(value) {
  19096. if (value) {
  19097. this._shaderValues.addDefine(PBRSpecularMaterial.SHADERDEFINE_PARALLAXTEXTURE);
  19098. }
  19099. else {
  19100. this._shaderValues.removeDefine(PBRSpecularMaterial.SHADERDEFINE_PARALLAXTEXTURE);
  19101. }
  19102. this._shaderValues.setTexture(PBRSpecularMaterial.PARALLAXTEXTURE, value);
  19103. }
  19104. get parallaxTextureScale() {
  19105. return this._Parallax;
  19106. }
  19107. set parallaxTextureScale(value) {
  19108. this._Parallax = Math.max(0.005, Math.min(0.08, value));
  19109. }
  19110. get occlusionTexture() {
  19111. return this._shaderValues.getTexture(PBRSpecularMaterial.OCCLUSIONTEXTURE);
  19112. }
  19113. set occlusionTexture(value) {
  19114. if (value) {
  19115. this._shaderValues.addDefine(PBRSpecularMaterial.SHADERDEFINE_OCCLUSIONTEXTURE);
  19116. }
  19117. else {
  19118. this._shaderValues.removeDefine(PBRSpecularMaterial.SHADERDEFINE_OCCLUSIONTEXTURE);
  19119. }
  19120. this._shaderValues.setTexture(PBRSpecularMaterial.OCCLUSIONTEXTURE, value);
  19121. }
  19122. get occlusionTextureStrength() {
  19123. return this._OcclusionStrength;
  19124. }
  19125. set occlusionTextureStrength(value) {
  19126. this._OcclusionStrength = Math.max(0.0, Math.min(1.0, value));
  19127. }
  19128. get specularTexture() {
  19129. return this._shaderValues.getTexture(PBRSpecularMaterial.SPECULARTEXTURE);
  19130. }
  19131. set specularTexture(value) {
  19132. if (value) {
  19133. this._shaderValues.addDefine(PBRSpecularMaterial.SHADERDEFINE_SPECULARTEXTURE);
  19134. }
  19135. else {
  19136. this._shaderValues.removeDefine(PBRSpecularMaterial.SHADERDEFINE_SPECULARTEXTURE);
  19137. }
  19138. this._shaderValues.setTexture(PBRSpecularMaterial.SPECULARTEXTURE, value);
  19139. }
  19140. get specularColorR() {
  19141. return this._SpecColorR;
  19142. }
  19143. set specularColorR(value) {
  19144. this._SpecColorR = value;
  19145. }
  19146. get specularColorG() {
  19147. return this._SpecColorG;
  19148. }
  19149. set specularColorG(value) {
  19150. this._SpecColorG = value;
  19151. }
  19152. get specularColorB() {
  19153. return this._SpecColorB;
  19154. }
  19155. set specularColorB(value) {
  19156. this._SpecColorB = value;
  19157. }
  19158. get specularColorA() {
  19159. return this._SpecColorA;
  19160. }
  19161. set specularColorA(value) {
  19162. this._SpecColorA = value;
  19163. }
  19164. get specularColor() {
  19165. return this._shaderValues.getVector(PBRSpecularMaterial.SPECULARCOLOR);
  19166. }
  19167. set specularColor(value) {
  19168. this._shaderValues.setVector(PBRSpecularMaterial.SPECULARCOLOR, value);
  19169. }
  19170. get smoothness() {
  19171. return this._Glossiness;
  19172. }
  19173. set smoothness(value) {
  19174. this._Glossiness = Math.max(0.0, Math.min(1.0, value));
  19175. }
  19176. get smoothnessTextureScale() {
  19177. return this._GlossMapScale;
  19178. }
  19179. set smoothnessTextureScale(value) {
  19180. this._GlossMapScale = Math.max(0.0, Math.min(1.0, value));
  19181. }
  19182. get smoothnessSource() {
  19183. return this._shaderValues.getInt(PBRSpecularMaterial.SMOOTHNESSSOURCE);
  19184. }
  19185. set smoothnessSource(value) {
  19186. if (value) {
  19187. this._shaderValues.addDefine(PBRSpecularMaterial.SHADERDEFINE_SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA);
  19188. this._shaderValues.setInt(PBRSpecularMaterial.SMOOTHNESSSOURCE, 1);
  19189. }
  19190. else {
  19191. this._shaderValues.removeDefine(PBRSpecularMaterial.SHADERDEFINE_SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA);
  19192. this._shaderValues.setInt(PBRSpecularMaterial.SMOOTHNESSSOURCE, 0);
  19193. }
  19194. }
  19195. get enableEmission() {
  19196. return this._shaderValues.getBool(PBRSpecularMaterial.ENABLEEMISSION);
  19197. }
  19198. set enableEmission(value) {
  19199. if (value)
  19200. this._shaderValues.addDefine(PBRSpecularMaterial.SHADERDEFINE_EMISSION);
  19201. else {
  19202. this._shaderValues.removeDefine(PBRSpecularMaterial.SHADERDEFINE_EMISSION);
  19203. }
  19204. this._shaderValues.setBool(PBRSpecularMaterial.ENABLEEMISSION, value);
  19205. }
  19206. get emissionColor() {
  19207. return this._shaderValues.getVector(PBRSpecularMaterial.EMISSIONCOLOR);
  19208. }
  19209. set emissionColor(value) {
  19210. this._shaderValues.setVector(PBRSpecularMaterial.EMISSIONCOLOR, value);
  19211. }
  19212. get emissionTexture() {
  19213. return this._shaderValues.getTexture(PBRSpecularMaterial.EMISSIONTEXTURE);
  19214. }
  19215. set emissionTexture(value) {
  19216. if (value)
  19217. this._shaderValues.addDefine(PBRSpecularMaterial.SHADERDEFINE_EMISSIONTEXTURE);
  19218. else
  19219. this._shaderValues.removeDefine(PBRSpecularMaterial.SHADERDEFINE_EMISSIONTEXTURE);
  19220. this._shaderValues.setTexture(PBRSpecularMaterial.EMISSIONTEXTURE, value);
  19221. }
  19222. get enableReflection() {
  19223. return this._shaderValues.getBool(PBRSpecularMaterial.ENABLEREFLECT);
  19224. }
  19225. set enableReflection(value) {
  19226. this._shaderValues.setBool(PBRSpecularMaterial.ENABLEREFLECT, true);
  19227. if (value)
  19228. this._disablePublicDefineDatas.remove(Scene3DShaderDeclaration.SHADERDEFINE_REFLECTMAP);
  19229. else
  19230. this._disablePublicDefineDatas.add(Scene3DShaderDeclaration.SHADERDEFINE_REFLECTMAP);
  19231. }
  19232. get tilingOffsetX() {
  19233. return this._MainTex_STX;
  19234. }
  19235. set tilingOffsetX(x) {
  19236. this._MainTex_STX = x;
  19237. }
  19238. get tilingOffsetY() {
  19239. return this._MainTex_STY;
  19240. }
  19241. set tilingOffsetY(y) {
  19242. this._MainTex_STY = y;
  19243. }
  19244. get tilingOffsetZ() {
  19245. return this._MainTex_STZ;
  19246. }
  19247. set tilingOffsetZ(z) {
  19248. this._MainTex_STZ = z;
  19249. }
  19250. get tilingOffsetW() {
  19251. return this._MainTex_STW;
  19252. }
  19253. set tilingOffsetW(w) {
  19254. this._MainTex_STW = w;
  19255. }
  19256. get tilingOffset() {
  19257. return this._shaderValues.getVector(PBRSpecularMaterial.TILINGOFFSET);
  19258. }
  19259. set tilingOffset(value) {
  19260. if (value) {
  19261. if (value.x != 1 || value.y != 1 || value.z != 0 || value.w != 0)
  19262. this._shaderValues.addDefine(PBRSpecularMaterial.SHADERDEFINE_TILINGOFFSET);
  19263. else
  19264. this._shaderValues.removeDefine(PBRSpecularMaterial.SHADERDEFINE_TILINGOFFSET);
  19265. }
  19266. else {
  19267. this._shaderValues.removeDefine(PBRSpecularMaterial.SHADERDEFINE_TILINGOFFSET);
  19268. }
  19269. this._shaderValues.setVector(PBRSpecularMaterial.TILINGOFFSET, value);
  19270. }
  19271. set renderMode(value) {
  19272. switch (value) {
  19273. case PBRSpecularMaterial.RENDERMODE_OPAQUE:
  19274. this.alphaTest = false;
  19275. this.renderQueue = BaseMaterial.RENDERQUEUE_OPAQUE;
  19276. this.depthWrite = true;
  19277. this.cull = RenderState.CULL_BACK;
  19278. this.blend = RenderState.BLEND_DISABLE;
  19279. this.depthTest = RenderState.DEPTHTEST_LESS;
  19280. this._shaderValues.removeDefine(PBRSpecularMaterial.SHADERDEFINE_ALPHAPREMULTIPLY);
  19281. break;
  19282. case PBRSpecularMaterial.RENDERMODE_CUTOUT:
  19283. this.renderQueue = BaseMaterial.RENDERQUEUE_ALPHATEST;
  19284. this.alphaTest = true;
  19285. this.depthWrite = true;
  19286. this.cull = RenderState.CULL_BACK;
  19287. this.blend = RenderState.BLEND_DISABLE;
  19288. this.depthTest = RenderState.DEPTHTEST_LESS;
  19289. this._shaderValues.removeDefine(PBRSpecularMaterial.SHADERDEFINE_ALPHAPREMULTIPLY);
  19290. break;
  19291. case PBRSpecularMaterial.RENDERMODE_FADE:
  19292. this.renderQueue = BaseMaterial.RENDERQUEUE_TRANSPARENT;
  19293. this.alphaTest = false;
  19294. this.depthWrite = false;
  19295. this.cull = RenderState.CULL_BACK;
  19296. this.blend = RenderState.BLEND_ENABLE_ALL;
  19297. this.blendSrc = RenderState.BLENDPARAM_SRC_ALPHA;
  19298. this.blendDst = RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA;
  19299. this.depthTest = RenderState.DEPTHTEST_LESS;
  19300. this._shaderValues.removeDefine(PBRSpecularMaterial.SHADERDEFINE_ALPHAPREMULTIPLY);
  19301. break;
  19302. case PBRSpecularMaterial.RENDERMODE_TRANSPARENT:
  19303. this.renderQueue = BaseMaterial.RENDERQUEUE_TRANSPARENT;
  19304. this.alphaTest = false;
  19305. this.depthWrite = false;
  19306. this.cull = RenderState.CULL_BACK;
  19307. this.blend = RenderState.BLEND_ENABLE_ALL;
  19308. this.blendSrc = RenderState.BLENDPARAM_ONE;
  19309. this.blendDst = RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA;
  19310. this.depthTest = RenderState.DEPTHTEST_LESS;
  19311. this._shaderValues.addDefine(PBRSpecularMaterial.SHADERDEFINE_ALPHAPREMULTIPLY);
  19312. break;
  19313. default:
  19314. throw new Error("PBRSpecularMaterial : renderMode value error.");
  19315. }
  19316. }
  19317. set depthWrite(value) {
  19318. this._shaderValues.setBool(PBRSpecularMaterial.DEPTH_WRITE, value);
  19319. }
  19320. get depthWrite() {
  19321. return this._shaderValues.getBool(PBRSpecularMaterial.DEPTH_WRITE);
  19322. }
  19323. set cull(value) {
  19324. this._shaderValues.setInt(PBRSpecularMaterial.CULL, value);
  19325. }
  19326. get cull() {
  19327. return this._shaderValues.getInt(PBRSpecularMaterial.CULL);
  19328. }
  19329. set blend(value) {
  19330. this._shaderValues.setInt(PBRSpecularMaterial.BLEND, value);
  19331. }
  19332. get blend() {
  19333. return this._shaderValues.getInt(PBRSpecularMaterial.BLEND);
  19334. }
  19335. set blendSrc(value) {
  19336. this._shaderValues.setInt(PBRSpecularMaterial.BLEND_SRC, value);
  19337. }
  19338. get blendSrc() {
  19339. return this._shaderValues.getInt(PBRSpecularMaterial.BLEND_SRC);
  19340. }
  19341. set blendDst(value) {
  19342. this._shaderValues.setInt(PBRSpecularMaterial.BLEND_DST, value);
  19343. }
  19344. get blendDst() {
  19345. return this._shaderValues.getInt(PBRSpecularMaterial.BLEND_DST);
  19346. }
  19347. set depthTest(value) {
  19348. this._shaderValues.setInt(PBRSpecularMaterial.DEPTH_TEST, value);
  19349. }
  19350. get depthTest() {
  19351. return this._shaderValues.getInt(PBRSpecularMaterial.DEPTH_TEST);
  19352. }
  19353. clone() {
  19354. var dest = new PBRSpecularMaterial();
  19355. this.cloneTo(dest);
  19356. return dest;
  19357. }
  19358. cloneTo(destObject) {
  19359. super.cloneTo(destObject);
  19360. var destMaterial = destObject;
  19361. this._albedoColor.cloneTo(destMaterial._albedoColor);
  19362. this._specularColor.cloneTo(destMaterial._specularColor);
  19363. this._emissionColor.cloneTo(destMaterial._emissionColor);
  19364. }
  19365. }
  19366. PBRSpecularMaterial.SmoothnessSource_SpecularTexture_Alpha = 0;
  19367. PBRSpecularMaterial.SmoothnessSource_AlbedoTexture_Alpha = 1;
  19368. PBRSpecularMaterial.RENDERMODE_OPAQUE = 0;
  19369. PBRSpecularMaterial.RENDERMODE_CUTOUT = 1;
  19370. PBRSpecularMaterial.RENDERMODE_FADE = 2;
  19371. PBRSpecularMaterial.RENDERMODE_TRANSPARENT = 3;
  19372. PBRSpecularMaterial.ALBEDOTEXTURE = Shader3D.propertyNameToID("u_AlbedoTexture");
  19373. PBRSpecularMaterial.SPECULARTEXTURE = Shader3D.propertyNameToID("u_SpecularTexture");
  19374. PBRSpecularMaterial.NORMALTEXTURE = Shader3D.propertyNameToID("u_NormalTexture");
  19375. PBRSpecularMaterial.PARALLAXTEXTURE = Shader3D.propertyNameToID("u_ParallaxTexture");
  19376. PBRSpecularMaterial.OCCLUSIONTEXTURE = Shader3D.propertyNameToID("u_OcclusionTexture");
  19377. PBRSpecularMaterial.EMISSIONTEXTURE = Shader3D.propertyNameToID("u_EmissionTexture");
  19378. PBRSpecularMaterial.ALBEDOCOLOR = Shader3D.propertyNameToID("u_AlbedoColor");
  19379. PBRSpecularMaterial.SPECULARCOLOR = Shader3D.propertyNameToID("u_SpecularColor");
  19380. PBRSpecularMaterial.EMISSIONCOLOR = Shader3D.propertyNameToID("u_EmissionColor");
  19381. PBRSpecularMaterial.SMOOTHNESS = Shader3D.propertyNameToID("u_smoothness");
  19382. PBRSpecularMaterial.SMOOTHNESSSCALE = Shader3D.propertyNameToID("u_smoothnessScale");
  19383. PBRSpecularMaterial.SMOOTHNESSSOURCE = -1;
  19384. PBRSpecularMaterial.OCCLUSIONSTRENGTH = Shader3D.propertyNameToID("u_occlusionStrength");
  19385. PBRSpecularMaterial.NORMALSCALE = Shader3D.propertyNameToID("u_normalScale");
  19386. PBRSpecularMaterial.PARALLAXSCALE = Shader3D.propertyNameToID("u_parallaxScale");
  19387. PBRSpecularMaterial.ENABLEEMISSION = -1;
  19388. PBRSpecularMaterial.ENABLEREFLECT = -1;
  19389. PBRSpecularMaterial.TILINGOFFSET = Shader3D.propertyNameToID("u_TilingOffset");
  19390. PBRSpecularMaterial.CULL = Shader3D.propertyNameToID("s_Cull");
  19391. PBRSpecularMaterial.BLEND = Shader3D.propertyNameToID("s_Blend");
  19392. PBRSpecularMaterial.BLEND_SRC = Shader3D.propertyNameToID("s_BlendSrc");
  19393. PBRSpecularMaterial.BLEND_DST = Shader3D.propertyNameToID("s_BlendDst");
  19394. PBRSpecularMaterial.DEPTH_TEST = Shader3D.propertyNameToID("s_DepthTest");
  19395. PBRSpecularMaterial.DEPTH_WRITE = Shader3D.propertyNameToID("s_DepthWrite");
  19396. PBRSpecularMaterial.shaderDefines = null;
  19397. class PBRStandardMaterial extends BaseMaterial {
  19398. constructor() {
  19399. super();
  19400. this.setShaderName("PBRStandard");
  19401. this._albedoColor = new Vector4(1.0, 1.0, 1.0, 1.0);
  19402. this._shaderValues.setVector(PBRStandardMaterial.ALBEDOCOLOR, new Vector4(1.0, 1.0, 1.0, 1.0));
  19403. this._emissionColor = new Vector4(0.0, 0.0, 0.0, 0.0);
  19404. this._shaderValues.setVector(PBRStandardMaterial.EMISSIONCOLOR, new Vector4(0.0, 0.0, 0.0, 0.0));
  19405. this._shaderValues.setNumber(PBRStandardMaterial.METALLIC, 0.0);
  19406. this._shaderValues.setNumber(PBRStandardMaterial.SMOOTHNESS, 0.5);
  19407. this._shaderValues.setNumber(PBRStandardMaterial.SMOOTHNESSSCALE, 1.0);
  19408. this._shaderValues.setNumber(PBRStandardMaterial.SMOOTHNESSSOURCE, 0);
  19409. this._shaderValues.setNumber(PBRStandardMaterial.OCCLUSIONSTRENGTH, 1.0);
  19410. this._shaderValues.setNumber(PBRStandardMaterial.NORMALSCALE, 1.0);
  19411. this._shaderValues.setNumber(PBRStandardMaterial.PARALLAXSCALE, 0.001);
  19412. this._shaderValues.setBool(PBRStandardMaterial.ENABLEEMISSION, false);
  19413. this._shaderValues.setBool(PBRStandardMaterial.ENABLEREFLECT, true);
  19414. this._shaderValues.setNumber(BaseMaterial.ALPHATESTVALUE, 0.5);
  19415. this._disablePublicDefineDatas.remove(Scene3DShaderDeclaration.SHADERDEFINE_REFLECTMAP);
  19416. this.renderMode = PBRStandardMaterial.RENDERMODE_OPAQUE;
  19417. }
  19418. static __initDefine__() {
  19419. PBRStandardMaterial.shaderDefines = new ShaderDefines(BaseMaterial.shaderDefines);
  19420. PBRStandardMaterial.SHADERDEFINE_ALBEDOTEXTURE = PBRStandardMaterial.shaderDefines.registerDefine("ALBEDOTEXTURE");
  19421. PBRStandardMaterial.SHADERDEFINE_METALLICGLOSSTEXTURE = PBRStandardMaterial.shaderDefines.registerDefine("METALLICGLOSSTEXTURE");
  19422. PBRStandardMaterial.SHADERDEFINE_SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA = PBRStandardMaterial.shaderDefines.registerDefine("SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA");
  19423. PBRStandardMaterial.SHADERDEFINE_NORMALTEXTURE = PBRStandardMaterial.shaderDefines.registerDefine("NORMALTEXTURE");
  19424. PBRStandardMaterial.SHADERDEFINE_PARALLAXTEXTURE = PBRStandardMaterial.shaderDefines.registerDefine("PARALLAXTEXTURE");
  19425. PBRStandardMaterial.SHADERDEFINE_OCCLUSIONTEXTURE = PBRStandardMaterial.shaderDefines.registerDefine("OCCLUSIONTEXTURE");
  19426. PBRStandardMaterial.SHADERDEFINE_EMISSION = PBRStandardMaterial.shaderDefines.registerDefine("EMISSION");
  19427. PBRStandardMaterial.SHADERDEFINE_EMISSIONTEXTURE = PBRStandardMaterial.shaderDefines.registerDefine("EMISSIONTEXTURE");
  19428. PBRStandardMaterial.SHADERDEFINE_REFLECTMAP = PBRStandardMaterial.shaderDefines.registerDefine("REFLECTMAP");
  19429. PBRStandardMaterial.SHADERDEFINE_TILINGOFFSET = PBRStandardMaterial.shaderDefines.registerDefine("TILINGOFFSET");
  19430. PBRStandardMaterial.SHADERDEFINE_ALPHAPREMULTIPLY = PBRStandardMaterial.shaderDefines.registerDefine("ALPHAPREMULTIPLY");
  19431. }
  19432. get _ColorR() {
  19433. return this._albedoColor.x;
  19434. }
  19435. set _ColorR(value) {
  19436. this._albedoColor.x = value;
  19437. this.albedoColor = this._albedoColor;
  19438. }
  19439. get _ColorG() {
  19440. return this._albedoColor.y;
  19441. }
  19442. set _ColorG(value) {
  19443. this._albedoColor.y = value;
  19444. this.albedoColor = this._albedoColor;
  19445. }
  19446. get _ColorB() {
  19447. return this._albedoColor.z;
  19448. }
  19449. set _ColorB(value) {
  19450. this._albedoColor.z = value;
  19451. this.albedoColor = this._albedoColor;
  19452. }
  19453. get _ColorA() {
  19454. return this._albedoColor.w;
  19455. }
  19456. set _ColorA(value) {
  19457. this._albedoColor.w = value;
  19458. this.albedoColor = this._albedoColor;
  19459. }
  19460. get _Metallic() {
  19461. return this._shaderValues.getNumber(PBRStandardMaterial.METALLIC);
  19462. }
  19463. set _Metallic(value) {
  19464. this._shaderValues.setNumber(PBRStandardMaterial.METALLIC, value);
  19465. }
  19466. get _Glossiness() {
  19467. return this._shaderValues.getNumber(PBRStandardMaterial.SMOOTHNESS);
  19468. }
  19469. set _Glossiness(value) {
  19470. this._shaderValues.setNumber(PBRStandardMaterial.SMOOTHNESS, value);
  19471. }
  19472. get _GlossMapScale() {
  19473. return this._shaderValues.getNumber(PBRStandardMaterial.SMOOTHNESSSCALE);
  19474. }
  19475. set _GlossMapScale(value) {
  19476. this._shaderValues.setNumber(PBRStandardMaterial.SMOOTHNESSSCALE, value);
  19477. }
  19478. get _BumpScale() {
  19479. return this._shaderValues.getNumber(PBRStandardMaterial.NORMALSCALE);
  19480. }
  19481. set _BumpScale(value) {
  19482. this._shaderValues.setNumber(PBRStandardMaterial.NORMALSCALE, value);
  19483. }
  19484. get _Parallax() {
  19485. return this._shaderValues.getNumber(PBRStandardMaterial.PARALLAXSCALE);
  19486. }
  19487. set _Parallax(value) {
  19488. this._shaderValues.setNumber(PBRStandardMaterial.PARALLAXSCALE, value);
  19489. }
  19490. get _OcclusionStrength() {
  19491. return this._shaderValues.getNumber(PBRStandardMaterial.OCCLUSIONSTRENGTH);
  19492. }
  19493. set _OcclusionStrength(value) {
  19494. this._shaderValues.setNumber(PBRStandardMaterial.OCCLUSIONSTRENGTH, value);
  19495. }
  19496. get _EmissionColorR() {
  19497. return this._emissionColor.x;
  19498. }
  19499. set _EmissionColorR(value) {
  19500. this._emissionColor.x = value;
  19501. this.emissionColor = this._emissionColor;
  19502. }
  19503. get _EmissionColorG() {
  19504. return this._emissionColor.y;
  19505. }
  19506. set _EmissionColorG(value) {
  19507. this._emissionColor.y = value;
  19508. this.emissionColor = this._emissionColor;
  19509. }
  19510. get _EmissionColorB() {
  19511. return this._emissionColor.z;
  19512. }
  19513. set _EmissionColorB(value) {
  19514. this._emissionColor.z = value;
  19515. this.emissionColor = this._emissionColor;
  19516. }
  19517. get _EmissionColorA() {
  19518. return this._emissionColor.w;
  19519. }
  19520. set _EmissionColorA(value) {
  19521. this._emissionColor.w = value;
  19522. this.emissionColor = this._emissionColor;
  19523. }
  19524. get _MainTex_STX() {
  19525. return this._shaderValues.getVector(PBRStandardMaterial.TILINGOFFSET).x;
  19526. }
  19527. set _MainTex_STX(x) {
  19528. var tilOff = this._shaderValues.getVector(PBRStandardMaterial.TILINGOFFSET);
  19529. tilOff.x = x;
  19530. this.tilingOffset = tilOff;
  19531. }
  19532. get _MainTex_STY() {
  19533. return this._shaderValues.getVector(PBRStandardMaterial.TILINGOFFSET).y;
  19534. }
  19535. set _MainTex_STY(y) {
  19536. var tilOff = this._shaderValues.getVector(PBRStandardMaterial.TILINGOFFSET);
  19537. tilOff.y = y;
  19538. this.tilingOffset = tilOff;
  19539. }
  19540. get _MainTex_STZ() {
  19541. return this._shaderValues.getVector(PBRStandardMaterial.TILINGOFFSET).z;
  19542. }
  19543. set _MainTex_STZ(z) {
  19544. var tilOff = this._shaderValues.getVector(PBRStandardMaterial.TILINGOFFSET);
  19545. tilOff.z = z;
  19546. this.tilingOffset = tilOff;
  19547. }
  19548. get _MainTex_STW() {
  19549. return this._shaderValues.getVector(PBRStandardMaterial.TILINGOFFSET).w;
  19550. }
  19551. set _MainTex_STW(w) {
  19552. var tilOff = this._shaderValues.getVector(PBRStandardMaterial.TILINGOFFSET);
  19553. tilOff.w = w;
  19554. this.tilingOffset = tilOff;
  19555. }
  19556. get _Cutoff() {
  19557. return this.alphaTestValue;
  19558. }
  19559. set _Cutoff(value) {
  19560. this.alphaTestValue = value;
  19561. }
  19562. get albedoColorR() {
  19563. return this._ColorR;
  19564. }
  19565. set albedoColorR(value) {
  19566. this._ColorR = value;
  19567. }
  19568. get albedoColorG() {
  19569. return this._ColorG;
  19570. }
  19571. set albedoColorG(value) {
  19572. this._ColorG = value;
  19573. }
  19574. get albedoColorB() {
  19575. return this._ColorB;
  19576. }
  19577. set albedoColorB(value) {
  19578. this._ColorB = value;
  19579. }
  19580. get albedoColorA() {
  19581. return this._ColorA;
  19582. }
  19583. set albedoColorA(value) {
  19584. this._ColorA = value;
  19585. }
  19586. get albedoColor() {
  19587. return this._albedoColor;
  19588. }
  19589. set albedoColor(value) {
  19590. this._albedoColor = value;
  19591. this._shaderValues.setVector(PBRStandardMaterial.ALBEDOCOLOR, value);
  19592. }
  19593. get albedoTexture() {
  19594. return this._shaderValues.getTexture(PBRStandardMaterial.ALBEDOTEXTURE);
  19595. }
  19596. set albedoTexture(value) {
  19597. if (value) {
  19598. this._shaderValues.addDefine(PBRStandardMaterial.SHADERDEFINE_ALBEDOTEXTURE);
  19599. }
  19600. else {
  19601. this._shaderValues.removeDefine(PBRStandardMaterial.SHADERDEFINE_ALBEDOTEXTURE);
  19602. }
  19603. this._shaderValues.setTexture(PBRStandardMaterial.ALBEDOTEXTURE, value);
  19604. }
  19605. get normalTexture() {
  19606. return this._shaderValues.getTexture(PBRStandardMaterial.NORMALTEXTURE);
  19607. }
  19608. set normalTexture(value) {
  19609. if (value) {
  19610. this._shaderValues.addDefine(PBRStandardMaterial.SHADERDEFINE_NORMALTEXTURE);
  19611. }
  19612. else {
  19613. this._shaderValues.removeDefine(PBRStandardMaterial.SHADERDEFINE_NORMALTEXTURE);
  19614. }
  19615. this._shaderValues.setTexture(PBRStandardMaterial.NORMALTEXTURE, value);
  19616. }
  19617. get normalTextureScale() {
  19618. return this._BumpScale;
  19619. }
  19620. set normalTextureScale(value) {
  19621. this._BumpScale = value;
  19622. }
  19623. get parallaxTexture() {
  19624. return this._shaderValues.getTexture(PBRStandardMaterial.PARALLAXTEXTURE);
  19625. }
  19626. set parallaxTexture(value) {
  19627. if (value) {
  19628. this._shaderValues.addDefine(PBRStandardMaterial.SHADERDEFINE_PARALLAXTEXTURE);
  19629. }
  19630. else {
  19631. this._shaderValues.removeDefine(PBRStandardMaterial.SHADERDEFINE_PARALLAXTEXTURE);
  19632. }
  19633. this._shaderValues.setTexture(PBRStandardMaterial.PARALLAXTEXTURE, value);
  19634. }
  19635. get parallaxTextureScale() {
  19636. return this._Parallax;
  19637. }
  19638. set parallaxTextureScale(value) {
  19639. this._Parallax = Math.max(0.005, Math.min(0.08, value));
  19640. }
  19641. get occlusionTexture() {
  19642. return this._shaderValues.getTexture(PBRStandardMaterial.OCCLUSIONTEXTURE);
  19643. }
  19644. set occlusionTexture(value) {
  19645. if (value) {
  19646. this._shaderValues.addDefine(PBRStandardMaterial.SHADERDEFINE_OCCLUSIONTEXTURE);
  19647. }
  19648. else {
  19649. this._shaderValues.removeDefine(PBRStandardMaterial.SHADERDEFINE_OCCLUSIONTEXTURE);
  19650. }
  19651. this._shaderValues.setTexture(PBRStandardMaterial.OCCLUSIONTEXTURE, value);
  19652. }
  19653. get occlusionTextureStrength() {
  19654. return this._OcclusionStrength;
  19655. }
  19656. set occlusionTextureStrength(value) {
  19657. this._OcclusionStrength = Math.max(0.0, Math.min(1.0, value));
  19658. }
  19659. get metallicGlossTexture() {
  19660. return this._shaderValues.getTexture(PBRStandardMaterial.METALLICGLOSSTEXTURE);
  19661. }
  19662. set metallicGlossTexture(value) {
  19663. if (value) {
  19664. this._shaderValues.addDefine(PBRStandardMaterial.SHADERDEFINE_METALLICGLOSSTEXTURE);
  19665. }
  19666. else {
  19667. this._shaderValues.removeDefine(PBRStandardMaterial.SHADERDEFINE_METALLICGLOSSTEXTURE);
  19668. }
  19669. this._shaderValues.setTexture(PBRStandardMaterial.METALLICGLOSSTEXTURE, value);
  19670. }
  19671. get metallic() {
  19672. return this._Metallic;
  19673. }
  19674. set metallic(value) {
  19675. this._Metallic = Math.max(0.0, Math.min(1.0, value));
  19676. }
  19677. get smoothness() {
  19678. return this._Glossiness;
  19679. }
  19680. set smoothness(value) {
  19681. this._Glossiness = Math.max(0.0, Math.min(1.0, value));
  19682. }
  19683. get smoothnessTextureScale() {
  19684. return this._GlossMapScale;
  19685. }
  19686. set smoothnessTextureScale(value) {
  19687. this._GlossMapScale = Math.max(0.0, Math.min(1.0, value));
  19688. }
  19689. get smoothnessSource() {
  19690. return this._shaderValues.getInt(PBRStandardMaterial.SMOOTHNESSSOURCE);
  19691. }
  19692. set smoothnessSource(value) {
  19693. if (value) {
  19694. this._shaderValues.addDefine(PBRStandardMaterial.SHADERDEFINE_SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA);
  19695. this._shaderValues.setInt(PBRStandardMaterial.SMOOTHNESSSOURCE, 1);
  19696. }
  19697. else {
  19698. this._shaderValues.removeDefine(PBRStandardMaterial.SHADERDEFINE_SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA);
  19699. this._shaderValues.setInt(PBRStandardMaterial.SMOOTHNESSSOURCE, 0);
  19700. }
  19701. }
  19702. get enableEmission() {
  19703. return this._shaderValues.getBool(PBRStandardMaterial.ENABLEEMISSION);
  19704. }
  19705. set enableEmission(value) {
  19706. if (value) {
  19707. this._shaderValues.addDefine(PBRStandardMaterial.SHADERDEFINE_EMISSION);
  19708. }
  19709. else {
  19710. this._shaderValues.removeDefine(PBRStandardMaterial.SHADERDEFINE_EMISSION);
  19711. }
  19712. this._shaderValues.setBool(PBRStandardMaterial.ENABLEEMISSION, value);
  19713. }
  19714. get emissionColorR() {
  19715. return this._EmissionColorR;
  19716. }
  19717. set emissionColorR(value) {
  19718. this._EmissionColorR = value;
  19719. }
  19720. get emissionColorG() {
  19721. return this._EmissionColorG;
  19722. }
  19723. set emissionColorG(value) {
  19724. this._EmissionColorG = value;
  19725. }
  19726. get emissionColorB() {
  19727. return this._EmissionColorB;
  19728. }
  19729. set emissionColorB(value) {
  19730. this._EmissionColorB = value;
  19731. }
  19732. get emissionColorA() {
  19733. return this._EmissionColorA;
  19734. }
  19735. set emissionColorA(value) {
  19736. this._EmissionColorA = value;
  19737. }
  19738. get emissionColor() {
  19739. return this._shaderValues.getVector(PBRStandardMaterial.EMISSIONCOLOR);
  19740. }
  19741. set emissionColor(value) {
  19742. this._shaderValues.setVector(PBRStandardMaterial.EMISSIONCOLOR, value);
  19743. }
  19744. get emissionTexture() {
  19745. return this._shaderValues.getTexture(PBRStandardMaterial.EMISSIONTEXTURE);
  19746. }
  19747. set emissionTexture(value) {
  19748. if (value) {
  19749. this._shaderValues.addDefine(PBRStandardMaterial.SHADERDEFINE_EMISSIONTEXTURE);
  19750. }
  19751. else {
  19752. this._shaderValues.removeDefine(PBRStandardMaterial.SHADERDEFINE_EMISSIONTEXTURE);
  19753. }
  19754. this._shaderValues.setTexture(PBRStandardMaterial.EMISSIONTEXTURE, value);
  19755. }
  19756. get enableReflection() {
  19757. return this._shaderValues.getBool(PBRStandardMaterial.ENABLEREFLECT);
  19758. }
  19759. set enableReflection(value) {
  19760. this._shaderValues.setBool(PBRStandardMaterial.ENABLEREFLECT, true);
  19761. if (value) {
  19762. this._disablePublicDefineDatas.remove(Scene3DShaderDeclaration.SHADERDEFINE_REFLECTMAP);
  19763. }
  19764. else {
  19765. this._disablePublicDefineDatas.add(Scene3DShaderDeclaration.SHADERDEFINE_REFLECTMAP);
  19766. }
  19767. }
  19768. get tilingOffsetX() {
  19769. return this._MainTex_STX;
  19770. }
  19771. set tilingOffsetX(x) {
  19772. this._MainTex_STX = x;
  19773. }
  19774. get tilingOffsetY() {
  19775. return this._MainTex_STY;
  19776. }
  19777. set tilingOffsetY(y) {
  19778. this._MainTex_STY = y;
  19779. }
  19780. get tilingOffsetZ() {
  19781. return this._MainTex_STZ;
  19782. }
  19783. set tilingOffsetZ(z) {
  19784. this._MainTex_STZ = z;
  19785. }
  19786. get tilingOffsetW() {
  19787. return this._MainTex_STW;
  19788. }
  19789. set tilingOffsetW(w) {
  19790. this._MainTex_STW = w;
  19791. }
  19792. get tilingOffset() {
  19793. return this._shaderValues.getVector(PBRStandardMaterial.TILINGOFFSET);
  19794. }
  19795. set tilingOffset(value) {
  19796. if (value) {
  19797. if (value.x != 1 || value.y != 1 || value.z != 0 || value.w != 0) {
  19798. this._shaderValues.addDefine(PBRStandardMaterial.SHADERDEFINE_TILINGOFFSET);
  19799. }
  19800. else {
  19801. this._shaderValues.removeDefine(PBRStandardMaterial.SHADERDEFINE_TILINGOFFSET);
  19802. }
  19803. }
  19804. else {
  19805. this._shaderValues.removeDefine(PBRStandardMaterial.SHADERDEFINE_TILINGOFFSET);
  19806. }
  19807. this._shaderValues.setVector(PBRStandardMaterial.TILINGOFFSET, value);
  19808. }
  19809. set renderMode(value) {
  19810. switch (value) {
  19811. case PBRStandardMaterial.RENDERMODE_OPAQUE:
  19812. this.alphaTest = false;
  19813. this.renderQueue = BaseMaterial.RENDERQUEUE_OPAQUE;
  19814. this.depthWrite = true;
  19815. this.cull = RenderState.CULL_BACK;
  19816. this.blend = RenderState.BLEND_DISABLE;
  19817. this.depthTest = RenderState.DEPTHTEST_LESS;
  19818. this._shaderValues.removeDefine(PBRStandardMaterial.SHADERDEFINE_ALPHAPREMULTIPLY);
  19819. break;
  19820. case PBRStandardMaterial.RENDERMODE_CUTOUT:
  19821. this.renderQueue = BaseMaterial.RENDERQUEUE_ALPHATEST;
  19822. this.alphaTest = true;
  19823. this.depthWrite = true;
  19824. this.cull = RenderState.CULL_BACK;
  19825. this.blend = RenderState.BLEND_DISABLE;
  19826. this.depthTest = RenderState.DEPTHTEST_LESS;
  19827. this._shaderValues.removeDefine(PBRStandardMaterial.SHADERDEFINE_ALPHAPREMULTIPLY);
  19828. break;
  19829. case PBRStandardMaterial.RENDERMODE_FADE:
  19830. this.renderQueue = BaseMaterial.RENDERQUEUE_TRANSPARENT;
  19831. this.alphaTest = false;
  19832. this.depthWrite = false;
  19833. this.cull = RenderState.CULL_BACK;
  19834. this.blend = RenderState.BLEND_ENABLE_ALL;
  19835. this.blendSrc = RenderState.BLENDPARAM_SRC_ALPHA;
  19836. this.blendDst = RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA;
  19837. this.depthTest = RenderState.DEPTHTEST_LESS;
  19838. this._shaderValues.removeDefine(PBRStandardMaterial.SHADERDEFINE_ALPHAPREMULTIPLY);
  19839. break;
  19840. break;
  19841. case PBRStandardMaterial.RENDERMODE_TRANSPARENT:
  19842. this.renderQueue = BaseMaterial.RENDERQUEUE_TRANSPARENT;
  19843. this.alphaTest = false;
  19844. this.depthWrite = false;
  19845. this.cull = RenderState.CULL_BACK;
  19846. this.blend = RenderState.BLEND_ENABLE_ALL;
  19847. this.blendSrc = RenderState.BLENDPARAM_ONE;
  19848. this.blendDst = RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA;
  19849. this.depthTest = RenderState.DEPTHTEST_LESS;
  19850. this._shaderValues.addDefine(PBRStandardMaterial.SHADERDEFINE_ALPHAPREMULTIPLY);
  19851. break;
  19852. default:
  19853. throw new Error("PBRSpecularMaterial : renderMode value error.");
  19854. }
  19855. }
  19856. set depthWrite(value) {
  19857. this._shaderValues.setBool(PBRStandardMaterial.DEPTH_WRITE, value);
  19858. }
  19859. get depthWrite() {
  19860. return this._shaderValues.getBool(PBRStandardMaterial.DEPTH_WRITE);
  19861. }
  19862. set cull(value) {
  19863. this._shaderValues.setInt(PBRStandardMaterial.CULL, value);
  19864. }
  19865. get cull() {
  19866. return this._shaderValues.getInt(PBRStandardMaterial.CULL);
  19867. }
  19868. set blend(value) {
  19869. this._shaderValues.setInt(PBRStandardMaterial.BLEND, value);
  19870. }
  19871. get blend() {
  19872. return this._shaderValues.getInt(PBRStandardMaterial.BLEND);
  19873. }
  19874. set blendSrc(value) {
  19875. this._shaderValues.setInt(PBRStandardMaterial.BLEND_SRC, value);
  19876. }
  19877. get blendSrc() {
  19878. return this._shaderValues.getInt(PBRStandardMaterial.BLEND_SRC);
  19879. }
  19880. set blendDst(value) {
  19881. this._shaderValues.setInt(PBRStandardMaterial.BLEND_DST, value);
  19882. }
  19883. get blendDst() {
  19884. return this._shaderValues.getInt(PBRStandardMaterial.BLEND_DST);
  19885. }
  19886. set depthTest(value) {
  19887. this._shaderValues.setInt(PBRStandardMaterial.DEPTH_TEST, value);
  19888. }
  19889. get depthTest() {
  19890. return this._shaderValues.getInt(PBRStandardMaterial.DEPTH_TEST);
  19891. }
  19892. clone() {
  19893. var dest = new PBRStandardMaterial();
  19894. this.cloneTo(dest);
  19895. return dest;
  19896. }
  19897. cloneTo(destObject) {
  19898. super.cloneTo(destObject);
  19899. var destMaterial = destObject;
  19900. this._albedoColor.cloneTo(destMaterial._albedoColor);
  19901. this._emissionColor.cloneTo(destMaterial._emissionColor);
  19902. }
  19903. }
  19904. PBRStandardMaterial.SmoothnessSource_MetallicGlossTexture_Alpha = 0;
  19905. PBRStandardMaterial.SmoothnessSource_AlbedoTexture_Alpha = 1;
  19906. PBRStandardMaterial.RENDERMODE_OPAQUE = 0;
  19907. PBRStandardMaterial.RENDERMODE_CUTOUT = 1;
  19908. PBRStandardMaterial.RENDERMODE_FADE = 2;
  19909. PBRStandardMaterial.RENDERMODE_TRANSPARENT = 3;
  19910. PBRStandardMaterial.ALBEDOTEXTURE = Shader3D.propertyNameToID("u_AlbedoTexture");
  19911. PBRStandardMaterial.METALLICGLOSSTEXTURE = Shader3D.propertyNameToID("u_MetallicGlossTexture");
  19912. PBRStandardMaterial.NORMALTEXTURE = Shader3D.propertyNameToID("u_NormalTexture");
  19913. PBRStandardMaterial.PARALLAXTEXTURE = Shader3D.propertyNameToID("u_ParallaxTexture");
  19914. PBRStandardMaterial.OCCLUSIONTEXTURE = Shader3D.propertyNameToID("u_OcclusionTexture");
  19915. PBRStandardMaterial.EMISSIONTEXTURE = Shader3D.propertyNameToID("u_EmissionTexture");
  19916. PBRStandardMaterial.ALBEDOCOLOR = Shader3D.propertyNameToID("u_AlbedoColor");
  19917. PBRStandardMaterial.EMISSIONCOLOR = Shader3D.propertyNameToID("u_EmissionColor");
  19918. PBRStandardMaterial.METALLIC = Shader3D.propertyNameToID("u_metallic");
  19919. PBRStandardMaterial.SMOOTHNESS = Shader3D.propertyNameToID("u_smoothness");
  19920. PBRStandardMaterial.SMOOTHNESSSCALE = Shader3D.propertyNameToID("u_smoothnessScale");
  19921. PBRStandardMaterial.SMOOTHNESSSOURCE = -1;
  19922. PBRStandardMaterial.OCCLUSIONSTRENGTH = Shader3D.propertyNameToID("u_occlusionStrength");
  19923. PBRStandardMaterial.NORMALSCALE = Shader3D.propertyNameToID("u_normalScale");
  19924. PBRStandardMaterial.PARALLAXSCALE = Shader3D.propertyNameToID("u_parallaxScale");
  19925. PBRStandardMaterial.ENABLEEMISSION = -1;
  19926. PBRStandardMaterial.ENABLEREFLECT = -1;
  19927. PBRStandardMaterial.TILINGOFFSET = Shader3D.propertyNameToID("u_TilingOffset");
  19928. PBRStandardMaterial.CULL = Shader3D.propertyNameToID("s_Cull");
  19929. PBRStandardMaterial.BLEND = Shader3D.propertyNameToID("s_Blend");
  19930. PBRStandardMaterial.BLEND_SRC = Shader3D.propertyNameToID("s_BlendSrc");
  19931. PBRStandardMaterial.BLEND_DST = Shader3D.propertyNameToID("s_BlendDst");
  19932. PBRStandardMaterial.DEPTH_TEST = Shader3D.propertyNameToID("s_DepthTest");
  19933. PBRStandardMaterial.DEPTH_WRITE = Shader3D.propertyNameToID("s_DepthWrite");
  19934. PBRStandardMaterial.shaderDefines = null;
  19935. class SkyProceduralMaterial extends BaseMaterial {
  19936. constructor() {
  19937. super();
  19938. this.setShaderName("SkyBoxProcedural");
  19939. this.sunDisk = SkyProceduralMaterial.SUN_HIGH_QUALITY;
  19940. this.sunSize = 0.04;
  19941. this.sunSizeConvergence = 5;
  19942. this.atmosphereThickness = 1.0;
  19943. this.skyTint = new Vector4(0.5, 0.5, 0.5, 1.0);
  19944. this.groundTint = new Vector4(0.369, 0.349, 0.341, 1.0);
  19945. this.exposure = 1.3;
  19946. }
  19947. static __initDefine__() {
  19948. SkyProceduralMaterial.shaderDefines = new ShaderDefines(BaseMaterial.shaderDefines);
  19949. SkyProceduralMaterial.SHADERDEFINE_SUN_HIGH_QUALITY = SkyProceduralMaterial.shaderDefines.registerDefine("SUN_HIGH_QUALITY");
  19950. SkyProceduralMaterial.SHADERDEFINE_SUN_SIMPLE = SkyProceduralMaterial.shaderDefines.registerDefine("SUN_SIMPLE");
  19951. }
  19952. get sunDisk() {
  19953. return this._sunDisk;
  19954. }
  19955. set sunDisk(value) {
  19956. switch (value) {
  19957. case SkyProceduralMaterial.SUN_HIGH_QUALITY:
  19958. this._shaderValues.removeDefine(SkyProceduralMaterial.SHADERDEFINE_SUN_SIMPLE);
  19959. this._shaderValues.addDefine(SkyProceduralMaterial.SHADERDEFINE_SUN_HIGH_QUALITY);
  19960. break;
  19961. case SkyProceduralMaterial.SUN_SIMPLE:
  19962. this._shaderValues.removeDefine(SkyProceduralMaterial.SHADERDEFINE_SUN_HIGH_QUALITY);
  19963. this._shaderValues.addDefine(SkyProceduralMaterial.SHADERDEFINE_SUN_SIMPLE);
  19964. break;
  19965. case SkyProceduralMaterial.SUN_NODE:
  19966. this._shaderValues.removeDefine(SkyProceduralMaterial.SHADERDEFINE_SUN_HIGH_QUALITY);
  19967. this._shaderValues.removeDefine(SkyProceduralMaterial.SHADERDEFINE_SUN_SIMPLE);
  19968. break;
  19969. default:
  19970. throw "SkyBoxProceduralMaterial: unknown sun value.";
  19971. }
  19972. this._sunDisk = value;
  19973. }
  19974. get sunSize() {
  19975. return this._shaderValues.getNumber(SkyProceduralMaterial.SUNSIZE);
  19976. }
  19977. set sunSize(value) {
  19978. value = Math.min(Math.max(0.0, value), 1.0);
  19979. this._shaderValues.setNumber(SkyProceduralMaterial.SUNSIZE, value);
  19980. }
  19981. get sunSizeConvergence() {
  19982. return this._shaderValues.getNumber(SkyProceduralMaterial.SUNSIZECONVERGENCE);
  19983. }
  19984. set sunSizeConvergence(value) {
  19985. value = Math.min(Math.max(0.0, value), 20.0);
  19986. this._shaderValues.setNumber(SkyProceduralMaterial.SUNSIZECONVERGENCE, value);
  19987. }
  19988. get atmosphereThickness() {
  19989. return this._shaderValues.getNumber(SkyProceduralMaterial.ATMOSPHERETHICKNESS);
  19990. }
  19991. set atmosphereThickness(value) {
  19992. value = Math.min(Math.max(0.0, value), 5.0);
  19993. this._shaderValues.setNumber(SkyProceduralMaterial.ATMOSPHERETHICKNESS, value);
  19994. }
  19995. get skyTint() {
  19996. return this._shaderValues.getVector(SkyProceduralMaterial.SKYTINT);
  19997. }
  19998. set skyTint(value) {
  19999. this._shaderValues.setVector(SkyProceduralMaterial.SKYTINT, value);
  20000. }
  20001. get groundTint() {
  20002. return this._shaderValues.getVector(SkyProceduralMaterial.GROUNDTINT);
  20003. }
  20004. set groundTint(value) {
  20005. this._shaderValues.setVector(SkyProceduralMaterial.GROUNDTINT, value);
  20006. }
  20007. get exposure() {
  20008. return this._shaderValues.getNumber(SkyProceduralMaterial.EXPOSURE);
  20009. }
  20010. set exposure(value) {
  20011. value = Math.min(Math.max(0.0, value), 8.0);
  20012. this._shaderValues.setNumber(SkyProceduralMaterial.EXPOSURE, value);
  20013. }
  20014. clone() {
  20015. var dest = new SkyProceduralMaterial();
  20016. this.cloneTo(dest);
  20017. return dest;
  20018. }
  20019. }
  20020. SkyProceduralMaterial.SUN_NODE = 0;
  20021. SkyProceduralMaterial.SUN_SIMPLE = 1;
  20022. SkyProceduralMaterial.SUN_HIGH_QUALITY = 2;
  20023. SkyProceduralMaterial.SUNSIZE = Shader3D.propertyNameToID("u_SunSize");
  20024. SkyProceduralMaterial.SUNSIZECONVERGENCE = Shader3D.propertyNameToID("u_SunSizeConvergence");
  20025. SkyProceduralMaterial.ATMOSPHERETHICKNESS = Shader3D.propertyNameToID("u_AtmosphereThickness");
  20026. SkyProceduralMaterial.SKYTINT = Shader3D.propertyNameToID("u_SkyTint");
  20027. SkyProceduralMaterial.GROUNDTINT = Shader3D.propertyNameToID("u_GroundTint");
  20028. SkyProceduralMaterial.EXPOSURE = Shader3D.propertyNameToID("u_Exposure");
  20029. SkyProceduralMaterial.shaderDefines = null;
  20030. class UnlitMaterial extends BaseMaterial {
  20031. constructor() {
  20032. super();
  20033. this._albedoColor = new Vector4(1.0, 1.0, 1.0, 1.0);
  20034. this._albedoIntensity = 1.0;
  20035. this._enableVertexColor = false;
  20036. this.setShaderName("Unlit");
  20037. this._shaderValues.setVector(UnlitMaterial.ALBEDOCOLOR, new Vector4(1.0, 1.0, 1.0, 1.0));
  20038. this.renderMode = UnlitMaterial.RENDERMODE_OPAQUE;
  20039. }
  20040. static __initDefine__() {
  20041. UnlitMaterial.shaderDefines = new ShaderDefines(BaseMaterial.shaderDefines);
  20042. UnlitMaterial.SHADERDEFINE_ALBEDOTEXTURE = UnlitMaterial.shaderDefines.registerDefine("ALBEDOTEXTURE");
  20043. UnlitMaterial.SHADERDEFINE_TILINGOFFSET = UnlitMaterial.shaderDefines.registerDefine("TILINGOFFSET");
  20044. UnlitMaterial.SHADERDEFINE_ENABLEVERTEXCOLOR = UnlitMaterial.shaderDefines.registerDefine("ENABLEVERTEXCOLOR");
  20045. }
  20046. get _ColorR() {
  20047. return this._albedoColor.x;
  20048. }
  20049. set _ColorR(value) {
  20050. this._albedoColor.x = value;
  20051. this.albedoColor = this._albedoColor;
  20052. }
  20053. get _ColorG() {
  20054. return this._albedoColor.y;
  20055. }
  20056. set _ColorG(value) {
  20057. this._albedoColor.y = value;
  20058. this.albedoColor = this._albedoColor;
  20059. }
  20060. get _ColorB() {
  20061. return this._albedoColor.z;
  20062. }
  20063. set _ColorB(value) {
  20064. this._albedoColor.z = value;
  20065. this.albedoColor = this._albedoColor;
  20066. }
  20067. get _ColorA() {
  20068. return this._albedoColor.w;
  20069. }
  20070. set _ColorA(value) {
  20071. this._albedoColor.w = value;
  20072. this.albedoColor = this._albedoColor;
  20073. }
  20074. get _AlbedoIntensity() {
  20075. return this._albedoIntensity;
  20076. }
  20077. set _AlbedoIntensity(value) {
  20078. if (this._albedoIntensity !== value) {
  20079. var finalAlbedo = this._shaderValues.getVector(UnlitMaterial.ALBEDOCOLOR);
  20080. Vector4.scale(this._albedoColor, value, finalAlbedo);
  20081. this._albedoIntensity = value;
  20082. this._shaderValues.setVector(UnlitMaterial.ALBEDOCOLOR, finalAlbedo);
  20083. }
  20084. }
  20085. get _MainTex_STX() {
  20086. return this._shaderValues.getVector(UnlitMaterial.TILINGOFFSET).x;
  20087. }
  20088. set _MainTex_STX(x) {
  20089. var tilOff = this._shaderValues.getVector(UnlitMaterial.TILINGOFFSET);
  20090. tilOff.x = x;
  20091. this.tilingOffset = tilOff;
  20092. }
  20093. get _MainTex_STY() {
  20094. return this._shaderValues.getVector(UnlitMaterial.TILINGOFFSET).y;
  20095. }
  20096. set _MainTex_STY(y) {
  20097. var tilOff = this._shaderValues.getVector(UnlitMaterial.TILINGOFFSET);
  20098. tilOff.y = y;
  20099. this.tilingOffset = tilOff;
  20100. }
  20101. get _MainTex_STZ() {
  20102. return this._shaderValues.getVector(UnlitMaterial.TILINGOFFSET).z;
  20103. }
  20104. set _MainTex_STZ(z) {
  20105. var tilOff = this._shaderValues.getVector(UnlitMaterial.TILINGOFFSET);
  20106. tilOff.z = z;
  20107. this.tilingOffset = tilOff;
  20108. }
  20109. get _MainTex_STW() {
  20110. return this._shaderValues.getVector(UnlitMaterial.TILINGOFFSET).w;
  20111. }
  20112. set _MainTex_STW(w) {
  20113. var tilOff = this._shaderValues.getVector(UnlitMaterial.TILINGOFFSET);
  20114. tilOff.w = w;
  20115. this.tilingOffset = tilOff;
  20116. }
  20117. get _Cutoff() {
  20118. return this.alphaTestValue;
  20119. }
  20120. set _Cutoff(value) {
  20121. this.alphaTestValue = value;
  20122. }
  20123. get albedoColorR() {
  20124. return this._ColorR;
  20125. }
  20126. set albedoColorR(value) {
  20127. this._ColorR = value;
  20128. }
  20129. get albedoColorG() {
  20130. return this._ColorG;
  20131. }
  20132. set albedoColorG(value) {
  20133. this._ColorG = value;
  20134. }
  20135. get albedoColorB() {
  20136. return this._ColorB;
  20137. }
  20138. set albedoColorB(value) {
  20139. this._ColorB = value;
  20140. }
  20141. get albedoColorA() {
  20142. return this._ColorA;
  20143. }
  20144. set albedoColorA(value) {
  20145. this._ColorA = value;
  20146. }
  20147. get albedoColor() {
  20148. return this._albedoColor;
  20149. }
  20150. set albedoColor(value) {
  20151. var finalAlbedo = this._shaderValues.getVector(UnlitMaterial.ALBEDOCOLOR);
  20152. Vector4.scale(value, this._albedoIntensity, finalAlbedo);
  20153. this._albedoColor = value;
  20154. this._shaderValues.setVector(UnlitMaterial.ALBEDOCOLOR, finalAlbedo);
  20155. }
  20156. get albedoIntensity() {
  20157. return this._albedoIntensity;
  20158. }
  20159. set albedoIntensity(value) {
  20160. this._AlbedoIntensity = value;
  20161. }
  20162. get albedoTexture() {
  20163. return this._shaderValues.getTexture(UnlitMaterial.ALBEDOTEXTURE);
  20164. }
  20165. set albedoTexture(value) {
  20166. if (value)
  20167. this._shaderValues.addDefine(UnlitMaterial.SHADERDEFINE_ALBEDOTEXTURE);
  20168. else
  20169. this._shaderValues.removeDefine(UnlitMaterial.SHADERDEFINE_ALBEDOTEXTURE);
  20170. this._shaderValues.setTexture(UnlitMaterial.ALBEDOTEXTURE, value);
  20171. }
  20172. get tilingOffsetX() {
  20173. return this._MainTex_STX;
  20174. }
  20175. set tilingOffsetX(x) {
  20176. this._MainTex_STX = x;
  20177. }
  20178. get tilingOffsetY() {
  20179. return this._MainTex_STY;
  20180. }
  20181. set tilingOffsetY(y) {
  20182. this._MainTex_STY = y;
  20183. }
  20184. get tilingOffsetZ() {
  20185. return this._MainTex_STZ;
  20186. }
  20187. set tilingOffsetZ(z) {
  20188. this._MainTex_STZ = z;
  20189. }
  20190. get tilingOffsetW() {
  20191. return this._MainTex_STW;
  20192. }
  20193. set tilingOffsetW(w) {
  20194. this._MainTex_STW = w;
  20195. }
  20196. get tilingOffset() {
  20197. return this._shaderValues.getVector(UnlitMaterial.TILINGOFFSET);
  20198. }
  20199. set tilingOffset(value) {
  20200. if (value) {
  20201. if (value.x != 1 || value.y != 1 || value.z != 0 || value.w != 0)
  20202. this._shaderValues.addDefine(UnlitMaterial.SHADERDEFINE_TILINGOFFSET);
  20203. else
  20204. this._shaderValues.removeDefine(UnlitMaterial.SHADERDEFINE_TILINGOFFSET);
  20205. }
  20206. else {
  20207. this._shaderValues.removeDefine(UnlitMaterial.SHADERDEFINE_TILINGOFFSET);
  20208. }
  20209. this._shaderValues.setVector(UnlitMaterial.TILINGOFFSET, value);
  20210. }
  20211. get enableVertexColor() {
  20212. return this._enableVertexColor;
  20213. }
  20214. set enableVertexColor(value) {
  20215. this._enableVertexColor = value;
  20216. if (value)
  20217. this._shaderValues.addDefine(UnlitMaterial.SHADERDEFINE_ENABLEVERTEXCOLOR);
  20218. else
  20219. this._shaderValues.removeDefine(UnlitMaterial.SHADERDEFINE_ENABLEVERTEXCOLOR);
  20220. }
  20221. set renderMode(value) {
  20222. switch (value) {
  20223. case UnlitMaterial.RENDERMODE_OPAQUE:
  20224. this.alphaTest = false;
  20225. this.renderQueue = BaseMaterial.RENDERQUEUE_OPAQUE;
  20226. this.depthWrite = true;
  20227. this.cull = RenderState.CULL_BACK;
  20228. this.blend = RenderState.BLEND_DISABLE;
  20229. this.depthTest = RenderState.DEPTHTEST_LESS;
  20230. break;
  20231. case UnlitMaterial.RENDERMODE_CUTOUT:
  20232. this.renderQueue = BaseMaterial.RENDERQUEUE_ALPHATEST;
  20233. this.alphaTest = true;
  20234. this.depthWrite = true;
  20235. this.cull = RenderState.CULL_BACK;
  20236. this.blend = RenderState.BLEND_DISABLE;
  20237. this.depthTest = RenderState.DEPTHTEST_LESS;
  20238. break;
  20239. case UnlitMaterial.RENDERMODE_TRANSPARENT:
  20240. this.renderQueue = BaseMaterial.RENDERQUEUE_TRANSPARENT;
  20241. this.alphaTest = false;
  20242. this.depthWrite = false;
  20243. this.cull = RenderState.CULL_BACK;
  20244. this.blend = RenderState.BLEND_ENABLE_ALL;
  20245. this.blendSrc = RenderState.BLENDPARAM_SRC_ALPHA;
  20246. this.blendDst = RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA;
  20247. this.depthTest = RenderState.DEPTHTEST_LESS;
  20248. break;
  20249. default:
  20250. throw new Error("UnlitMaterial : renderMode value error.");
  20251. }
  20252. }
  20253. set depthWrite(value) {
  20254. this._shaderValues.setBool(UnlitMaterial.DEPTH_WRITE, value);
  20255. }
  20256. get depthWrite() {
  20257. return this._shaderValues.getBool(UnlitMaterial.DEPTH_WRITE);
  20258. }
  20259. set cull(value) {
  20260. this._shaderValues.setInt(UnlitMaterial.CULL, value);
  20261. }
  20262. get cull() {
  20263. return this._shaderValues.getInt(UnlitMaterial.CULL);
  20264. }
  20265. set blend(value) {
  20266. this._shaderValues.setInt(UnlitMaterial.BLEND, value);
  20267. }
  20268. get blend() {
  20269. return this._shaderValues.getInt(UnlitMaterial.BLEND);
  20270. }
  20271. set blendSrc(value) {
  20272. this._shaderValues.setInt(UnlitMaterial.BLEND_SRC, value);
  20273. }
  20274. get blendSrc() {
  20275. return this._shaderValues.getInt(UnlitMaterial.BLEND_SRC);
  20276. }
  20277. set blendDst(value) {
  20278. this._shaderValues.setInt(UnlitMaterial.BLEND_DST, value);
  20279. }
  20280. get blendDst() {
  20281. return this._shaderValues.getInt(UnlitMaterial.BLEND_DST);
  20282. }
  20283. set depthTest(value) {
  20284. this._shaderValues.setInt(UnlitMaterial.DEPTH_TEST, value);
  20285. }
  20286. get depthTest() {
  20287. return this._shaderValues.getInt(UnlitMaterial.DEPTH_TEST);
  20288. }
  20289. clone() {
  20290. var dest = new UnlitMaterial();
  20291. this.cloneTo(dest);
  20292. return dest;
  20293. }
  20294. }
  20295. UnlitMaterial.RENDERMODE_OPAQUE = 0;
  20296. UnlitMaterial.RENDERMODE_CUTOUT = 1;
  20297. UnlitMaterial.RENDERMODE_TRANSPARENT = 2;
  20298. UnlitMaterial.RENDERMODE_ADDTIVE = 3;
  20299. UnlitMaterial.ALBEDOTEXTURE = Shader3D.propertyNameToID("u_AlbedoTexture");
  20300. UnlitMaterial.ALBEDOCOLOR = Shader3D.propertyNameToID("u_AlbedoColor");
  20301. UnlitMaterial.TILINGOFFSET = Shader3D.propertyNameToID("u_TilingOffset");
  20302. UnlitMaterial.CULL = Shader3D.propertyNameToID("s_Cull");
  20303. UnlitMaterial.BLEND = Shader3D.propertyNameToID("s_Blend");
  20304. UnlitMaterial.BLEND_SRC = Shader3D.propertyNameToID("s_BlendSrc");
  20305. UnlitMaterial.BLEND_DST = Shader3D.propertyNameToID("s_BlendDst");
  20306. UnlitMaterial.DEPTH_TEST = Shader3D.propertyNameToID("s_DepthTest");
  20307. UnlitMaterial.DEPTH_WRITE = Shader3D.propertyNameToID("s_DepthWrite");
  20308. UnlitMaterial.shaderDefines = null;
  20309. class WaterPrimaryMaterial extends BaseMaterial {
  20310. constructor() {
  20311. super();
  20312. this.setShaderName("WaterPrimary");
  20313. this._shaderValues.setVector(WaterPrimaryMaterial.HORIZONCOLOR, new Vector4(0.172, 0.463, 0.435, 0));
  20314. this._shaderValues.setNumber(WaterPrimaryMaterial.WAVESCALE, 0.15);
  20315. this._shaderValues.setVector(WaterPrimaryMaterial.WAVESPEED, new Vector4(19, 9, -16, -7));
  20316. }
  20317. static __initDefine__() {
  20318. WaterPrimaryMaterial.shaderDefines = new ShaderDefines(BaseMaterial.shaderDefines);
  20319. WaterPrimaryMaterial.SHADERDEFINE_MAINTEXTURE = WaterPrimaryMaterial.shaderDefines.registerDefine("MAINTEXTURE");
  20320. WaterPrimaryMaterial.SHADERDEFINE_NORMALTEXTURE = WaterPrimaryMaterial.shaderDefines.registerDefine("NORMALTEXTURE");
  20321. }
  20322. get horizonColor() {
  20323. return this._shaderValues.getVector(WaterPrimaryMaterial.HORIZONCOLOR);
  20324. }
  20325. set horizonColor(value) {
  20326. this._shaderValues.setVector(WaterPrimaryMaterial.HORIZONCOLOR, value);
  20327. }
  20328. get mainTexture() {
  20329. return this._shaderValues.getTexture(WaterPrimaryMaterial.MAINTEXTURE);
  20330. }
  20331. set mainTexture(value) {
  20332. if (value)
  20333. this._shaderValues.addDefine(WaterPrimaryMaterial.SHADERDEFINE_MAINTEXTURE);
  20334. else
  20335. this._shaderValues.removeDefine(WaterPrimaryMaterial.SHADERDEFINE_MAINTEXTURE);
  20336. this._shaderValues.setTexture(WaterPrimaryMaterial.MAINTEXTURE, value);
  20337. }
  20338. get normalTexture() {
  20339. return this._shaderValues.getTexture(WaterPrimaryMaterial.NORMALTEXTURE);
  20340. }
  20341. set normalTexture(value) {
  20342. if (value)
  20343. this._shaderValues.addDefine(WaterPrimaryMaterial.SHADERDEFINE_NORMALTEXTURE);
  20344. else
  20345. this._shaderValues.removeDefine(WaterPrimaryMaterial.SHADERDEFINE_NORMALTEXTURE);
  20346. this._shaderValues.setTexture(WaterPrimaryMaterial.NORMALTEXTURE, value);
  20347. }
  20348. get waveScale() {
  20349. return this._shaderValues.getNumber(WaterPrimaryMaterial.WAVESCALE);
  20350. }
  20351. set waveScale(value) {
  20352. this._shaderValues.setNumber(WaterPrimaryMaterial.WAVESCALE, value);
  20353. }
  20354. get waveSpeed() {
  20355. return this._shaderValues.getVector(WaterPrimaryMaterial.WAVESPEED);
  20356. }
  20357. set waveSpeed(value) {
  20358. this._shaderValues.setVector(WaterPrimaryMaterial.WAVESPEED, value);
  20359. }
  20360. clone() {
  20361. var dest = new WaterPrimaryMaterial();
  20362. this.cloneTo(dest);
  20363. return dest;
  20364. }
  20365. }
  20366. WaterPrimaryMaterial.HORIZONCOLOR = Shader3D.propertyNameToID("u_HorizonColor");
  20367. WaterPrimaryMaterial.MAINTEXTURE = Shader3D.propertyNameToID("u_MainTexture");
  20368. WaterPrimaryMaterial.NORMALTEXTURE = Shader3D.propertyNameToID("u_NormalTexture");
  20369. WaterPrimaryMaterial.WAVESCALE = Shader3D.propertyNameToID("u_WaveScale");
  20370. WaterPrimaryMaterial.WAVESPEED = Shader3D.propertyNameToID("u_WaveSpeed");
  20371. WaterPrimaryMaterial.shaderDefines = null;
  20372. class SkinnedMeshSprite3DShaderDeclaration {
  20373. }
  20374. class SkinnedMeshRenderer extends MeshRenderer {
  20375. constructor(owner) {
  20376. super(owner);
  20377. this._bones = [];
  20378. this._skinnedDataLoopMarks = [];
  20379. this._localBounds = new Bounds(Vector3._ZERO, Vector3._ZERO);
  20380. this._cacheAnimationNode = [];
  20381. }
  20382. get localBounds() {
  20383. return this._localBounds;
  20384. }
  20385. set localBounds(value) {
  20386. this._localBounds = value;
  20387. }
  20388. get rootBone() {
  20389. return this._cacheRootBone;
  20390. }
  20391. set rootBone(value) {
  20392. if (this._cacheRootBone != value) {
  20393. if (this._cacheRootBone)
  20394. this._cacheRootBone.transform.off(Laya.Event.TRANSFORM_CHANGED, this, this._onWorldMatNeedChange);
  20395. else
  20396. this._owner.transform.off(Laya.Event.TRANSFORM_CHANGED, this, this._onWorldMatNeedChange);
  20397. if (value)
  20398. value.transform.on(Laya.Event.TRANSFORM_CHANGED, this, this._onWorldMatNeedChange);
  20399. else
  20400. this._owner.transform.on(Laya.Event.TRANSFORM_CHANGED, this, this._onWorldMatNeedChange);
  20401. this._cacheRootBone = value;
  20402. this._onWorldMatNeedChange(Transform3D.TRANSFORM_WORLDPOSITION | Transform3D.TRANSFORM_WORLDQUATERNION | Transform3D.TRANSFORM_WORLDSCALE);
  20403. }
  20404. }
  20405. get bones() {
  20406. return this._bones;
  20407. }
  20408. _computeSkinnedData() {
  20409. if (this._cacheMesh && this._cacheAvatar || this._cacheMesh && !this._cacheAvatar) {
  20410. var bindPoses = this._cacheMesh._inverseBindPoses;
  20411. var meshBindPoseIndices = this._cacheMesh._bindPoseIndices;
  20412. var pathMarks = this._cacheMesh._skinDataPathMarks;
  20413. for (var i = 0, n = this._cacheMesh.subMeshCount; i < n; i++) {
  20414. var subMeshBoneIndices = this._cacheMesh.getSubMesh(i)._boneIndicesList;
  20415. var subData = this._skinnedData[i];
  20416. for (var j = 0, m = subMeshBoneIndices.length; j < m; j++) {
  20417. var boneIndices = subMeshBoneIndices[j];
  20418. this._computeSubSkinnedData(bindPoses, boneIndices, meshBindPoseIndices, subData[j], pathMarks);
  20419. }
  20420. }
  20421. }
  20422. }
  20423. _computeSubSkinnedData(bindPoses, boneIndices, meshBindPoseInices, data, pathMarks) {
  20424. for (var k = 0, q = boneIndices.length; k < q; k++) {
  20425. var index = boneIndices[k];
  20426. if (this._skinnedDataLoopMarks[index] === Laya.Stat.loopCount) {
  20427. var p = pathMarks[index];
  20428. var preData = this._skinnedData[p[0]][p[1]];
  20429. var srcIndex = p[2] * 16;
  20430. var dstIndex = k * 16;
  20431. for (var d = 0; d < 16; d++)
  20432. data[dstIndex + d] = preData[srcIndex + d];
  20433. }
  20434. else {
  20435. if (!this._cacheAvatar) {
  20436. var boneIndex = meshBindPoseInices[index];
  20437. Utils3D._mulMatrixArray(this._bones[boneIndex].transform.worldMatrix.elements, bindPoses[boneIndex], data, k * 16);
  20438. }
  20439. else {
  20440. Utils3D._mulMatrixArray(this._cacheAnimationNode[index].transform.getWorldMatrix(), bindPoses[meshBindPoseInices[index]], data, k * 16);
  20441. }
  20442. this._skinnedDataLoopMarks[index] = Laya.Stat.loopCount;
  20443. }
  20444. }
  20445. }
  20446. _onWorldMatNeedChange(flag) {
  20447. this._boundsChange = true;
  20448. if (this._octreeNode) {
  20449. if (this._cacheAvatar) {
  20450. if (this._indexInOctreeMotionList === -1)
  20451. this._octreeNode._octree.addMotionObject(this);
  20452. }
  20453. else {
  20454. flag &= Transform3D.TRANSFORM_WORLDPOSITION | Transform3D.TRANSFORM_WORLDQUATERNION | Transform3D.TRANSFORM_WORLDSCALE;
  20455. if (flag) {
  20456. if (this._indexInOctreeMotionList === -1)
  20457. this._octreeNode._octree.addMotionObject(this);
  20458. }
  20459. }
  20460. }
  20461. }
  20462. _createRenderElement() {
  20463. return new RenderElement();
  20464. }
  20465. _onMeshChange(value) {
  20466. super._onMeshChange(value);
  20467. this._cacheMesh = value;
  20468. var subMeshCount = value.subMeshCount;
  20469. this._skinnedData = [];
  20470. this._skinnedDataLoopMarks.length = value._bindPoseIndices.length;
  20471. for (var i = 0; i < subMeshCount; i++) {
  20472. var subBoneIndices = value.getSubMesh(i)._boneIndicesList;
  20473. var subCount = subBoneIndices.length;
  20474. var subData = this._skinnedData[i] = [];
  20475. for (var j = 0; j < subCount; j++)
  20476. subData[j] = new Float32Array(subBoneIndices[j].length * 16);
  20477. }
  20478. (this._cacheAvatar && value) && (this._getCacheAnimationNodes());
  20479. }
  20480. _setCacheAnimator(animator) {
  20481. this._cacheAnimator = animator;
  20482. this._shaderValues.addDefine(SkinnedMeshSprite3DShaderDeclaration.SHADERDEFINE_BONE);
  20483. this._setRootNode();
  20484. }
  20485. _calculateBoundingBox() {
  20486. if (!this._cacheAvatar) {
  20487. if (this._cacheRootBone)
  20488. this._localBounds._tranform(this._cacheRootBone.transform.worldMatrix, this._bounds);
  20489. else
  20490. this._localBounds._tranform(this._owner.transform.worldMatrix, this._bounds);
  20491. }
  20492. else {
  20493. if (this._cacheAnimator && this._rootBone) {
  20494. var worldMat = SkinnedMeshRenderer._tempMatrix4x4;
  20495. Utils3D.matrix4x4MultiplyMFM(this._cacheAnimator.owner.transform.worldMatrix, this._cacheRootAnimationNode.transform.getWorldMatrix(), worldMat);
  20496. this._localBounds._tranform(worldMat, this._bounds);
  20497. }
  20498. else {
  20499. super._calculateBoundingBox();
  20500. }
  20501. }
  20502. if (Laya.Render.supportWebGLPlusCulling) {
  20503. var min = this._bounds.getMin();
  20504. var max = this._bounds.getMax();
  20505. var buffer = FrustumCulling._cullingBuffer;
  20506. buffer[this._cullingBufferIndex + 1] = min.x;
  20507. buffer[this._cullingBufferIndex + 2] = min.y;
  20508. buffer[this._cullingBufferIndex + 3] = min.z;
  20509. buffer[this._cullingBufferIndex + 4] = max.x;
  20510. buffer[this._cullingBufferIndex + 5] = max.y;
  20511. buffer[this._cullingBufferIndex + 6] = max.z;
  20512. }
  20513. }
  20514. _renderUpdate(context, transform) {
  20515. if (this._cacheAnimator) {
  20516. this._computeSkinnedData();
  20517. if (!this._cacheAvatar) {
  20518. this._shaderValues.setMatrix4x4(Sprite3D.WORLDMATRIX, Matrix4x4.DEFAULT);
  20519. }
  20520. else {
  20521. var aniOwnerTrans = this._cacheAnimator.owner._transform;
  20522. this._shaderValues.setMatrix4x4(Sprite3D.WORLDMATRIX, aniOwnerTrans.worldMatrix);
  20523. }
  20524. }
  20525. else {
  20526. this._shaderValues.setMatrix4x4(Sprite3D.WORLDMATRIX, transform.worldMatrix);
  20527. }
  20528. }
  20529. _renderUpdateWithCamera(context, transform) {
  20530. var projectionView = context.projectionViewMatrix;
  20531. if (this._cacheAnimator) {
  20532. if (!this._cacheAvatar) {
  20533. this._shaderValues.setMatrix4x4(Sprite3D.MVPMATRIX, projectionView);
  20534. }
  20535. else {
  20536. var aniOwnerTrans = this._cacheAnimator.owner._transform;
  20537. Matrix4x4.multiply(projectionView, aniOwnerTrans.worldMatrix, this._projectionViewWorldMatrix);
  20538. this._shaderValues.setMatrix4x4(Sprite3D.MVPMATRIX, this._projectionViewWorldMatrix);
  20539. }
  20540. }
  20541. else {
  20542. Matrix4x4.multiply(projectionView, transform.worldMatrix, this._projectionViewWorldMatrix);
  20543. this._shaderValues.setMatrix4x4(Sprite3D.MVPMATRIX, this._projectionViewWorldMatrix);
  20544. }
  20545. }
  20546. _destroy() {
  20547. super._destroy();
  20548. if (!this._cacheAvatar) {
  20549. if (this._cacheRootBone)
  20550. (!this._cacheRootBone.destroyed) && (this._cacheRootBone.transform.off(Laya.Event.TRANSFORM_CHANGED, this, this._onWorldMatNeedChange));
  20551. else
  20552. (this._owner && !this._owner.destroyed) && (this._owner.transform.off(Laya.Event.TRANSFORM_CHANGED, this, this._onWorldMatNeedChange));
  20553. }
  20554. else {
  20555. if (this._cacheRootAnimationNode)
  20556. this._cacheRootAnimationNode.transform.off(Laya.Event.TRANSFORM_CHANGED, this, this._onWorldMatNeedChange);
  20557. }
  20558. }
  20559. get bounds() {
  20560. if (this._boundsChange || this._cacheAvatar) {
  20561. this._calculateBoundingBox();
  20562. this._boundsChange = false;
  20563. }
  20564. return this._bounds;
  20565. }
  20566. _setRootBone(name) {
  20567. this._rootBone = name;
  20568. this._setRootNode();
  20569. }
  20570. _setRootNode() {
  20571. var rootNode;
  20572. if (this._cacheAnimator && this._rootBone && this._cacheAvatar)
  20573. rootNode = this._cacheAnimator._avatarNodeMap[this._rootBone];
  20574. else
  20575. rootNode = null;
  20576. if (this._cacheRootAnimationNode != rootNode) {
  20577. this._onWorldMatNeedChange(Transform3D.TRANSFORM_WORLDPOSITION | Transform3D.TRANSFORM_WORLDQUATERNION | Transform3D.TRANSFORM_WORLDSCALE);
  20578. this._owner.transform.off(Laya.Event.TRANSFORM_CHANGED, this, this._onWorldMatNeedChange);
  20579. if (this._cacheRootAnimationNode)
  20580. this._cacheRootAnimationNode.transform.off(Laya.Event.TRANSFORM_CHANGED, this, this._onWorldMatNeedChange);
  20581. (rootNode) && (rootNode.transform.on(Laya.Event.TRANSFORM_CHANGED, this, this._onWorldMatNeedChange));
  20582. this._cacheRootAnimationNode = rootNode;
  20583. }
  20584. }
  20585. _getCacheAnimationNodes() {
  20586. var meshBoneNames = this._cacheMesh._boneNames;
  20587. var bindPoseIndices = this._cacheMesh._bindPoseIndices;
  20588. var innerBindPoseCount = bindPoseIndices.length;
  20589. if (!Laya.Render.supportWebGLPlusAnimation) {
  20590. this._cacheAnimationNode.length = innerBindPoseCount;
  20591. var nodeMap = this._cacheAnimator._avatarNodeMap;
  20592. for (var i = 0; i < innerBindPoseCount; i++) {
  20593. var node = nodeMap[meshBoneNames[bindPoseIndices[i]]];
  20594. this._cacheAnimationNode[i] = node;
  20595. }
  20596. }
  20597. else {
  20598. this._cacheAnimationNodeIndices = new Uint16Array(innerBindPoseCount);
  20599. var nodeMapC = this._cacheAnimator._avatarNodeMap;
  20600. for (i = 0; i < innerBindPoseCount; i++) {
  20601. var nodeC = nodeMapC[meshBoneNames[bindPoseIndices[i]]];
  20602. this._cacheAnimationNodeIndices[i] = nodeC._worldMatrixIndex;
  20603. }
  20604. }
  20605. }
  20606. _setCacheAvatar(value) {
  20607. if (this._cacheAvatar !== value) {
  20608. if (this._cacheMesh) {
  20609. this._cacheAvatar = value;
  20610. if (value) {
  20611. this._shaderValues.addDefine(SkinnedMeshSprite3DShaderDeclaration.SHADERDEFINE_BONE);
  20612. this._getCacheAnimationNodes();
  20613. }
  20614. }
  20615. else {
  20616. this._cacheAvatar = value;
  20617. }
  20618. this._setRootNode();
  20619. }
  20620. }
  20621. _computeSubSkinnedDataNative(worldMatrixs, cacheAnimationNodeIndices, inverseBindPosesBuffer, boneIndices, bindPoseInices, data) {
  20622. Laya.LayaGL.instance.computeSubSkinnedData(worldMatrixs, cacheAnimationNodeIndices, inverseBindPosesBuffer, boneIndices, bindPoseInices, data);
  20623. }
  20624. _computeSkinnedDataForNative() {
  20625. if (this._cacheMesh && this._cacheAvatar || this._cacheMesh && !this._cacheAvatar) {
  20626. var bindPoses = this._cacheMesh._inverseBindPoses;
  20627. var meshBindPoseIndices = this._cacheMesh._bindPoseIndices;
  20628. var pathMarks = this._cacheMesh._skinDataPathMarks;
  20629. for (var i = 0, n = this._cacheMesh.subMeshCount; i < n; i++) {
  20630. var subMeshBoneIndices = this._cacheMesh.getSubMesh(i)._boneIndicesList;
  20631. var subData = this._skinnedData[i];
  20632. for (var j = 0, m = subMeshBoneIndices.length; j < m; j++) {
  20633. var boneIndices = subMeshBoneIndices[j];
  20634. if (this._cacheAvatar && Laya.Render.supportWebGLPlusAnimation)
  20635. this._computeSubSkinnedDataNative(this._cacheAnimator._animationNodeWorldMatrixs, this._cacheAnimationNodeIndices, this._cacheMesh._inverseBindPosesBuffer, boneIndices, meshBindPoseIndices, subData[j]);
  20636. else
  20637. this._computeSubSkinnedData(bindPoses, boneIndices, meshBindPoseIndices, subData[j], pathMarks);
  20638. }
  20639. }
  20640. }
  20641. }
  20642. }
  20643. SkinnedMeshRenderer._tempMatrix4x4 = new Matrix4x4();
  20644. class SkinnedMeshSprite3D extends RenderableSprite3D {
  20645. constructor(mesh = null, name = null) {
  20646. super(name);
  20647. this._meshFilter = new MeshFilter(this);
  20648. this._render = new SkinnedMeshRenderer(this);
  20649. (mesh) && (this._meshFilter.sharedMesh = mesh);
  20650. }
  20651. static __init__() {
  20652. SkinnedMeshSprite3D.shaderDefines = new ShaderDefines(MeshSprite3D.shaderDefines);
  20653. SkinnedMeshSprite3DShaderDeclaration.SHADERDEFINE_BONE = SkinnedMeshSprite3D.shaderDefines.registerDefine("BONE");
  20654. }
  20655. get meshFilter() {
  20656. return this._meshFilter;
  20657. }
  20658. get skinnedMeshRenderer() {
  20659. return this._render;
  20660. }
  20661. _parse(data, spriteMap) {
  20662. super._parse(data, spriteMap);
  20663. var render = this.skinnedMeshRenderer;
  20664. var lightmapIndex = data.lightmapIndex;
  20665. (lightmapIndex != null) && (render.lightmapIndex = lightmapIndex);
  20666. var lightmapScaleOffsetArray = data.lightmapScaleOffset;
  20667. (lightmapScaleOffsetArray) && (render.lightmapScaleOffset = new Vector4(lightmapScaleOffsetArray[0], lightmapScaleOffsetArray[1], lightmapScaleOffsetArray[2], lightmapScaleOffsetArray[3]));
  20668. var meshPath;
  20669. meshPath = data.meshPath;
  20670. if (meshPath) {
  20671. var mesh = Laya.Loader.getRes(meshPath);
  20672. (mesh) && (this.meshFilter.sharedMesh = mesh);
  20673. }
  20674. var materials = data.materials;
  20675. if (materials) {
  20676. var sharedMaterials = render.sharedMaterials;
  20677. var materialCount = materials.length;
  20678. sharedMaterials.length = materialCount;
  20679. for (var i = 0; i < materialCount; i++) {
  20680. sharedMaterials[i] = Laya.Loader.getRes(materials[i].path);
  20681. }
  20682. render.sharedMaterials = sharedMaterials;
  20683. }
  20684. var boundBox = data.boundBox;
  20685. var min = boundBox.min;
  20686. var max = boundBox.max;
  20687. render.localBounds.setMin(new Vector3(min[0], min[1], min[2]));
  20688. render.localBounds.setMax(new Vector3(max[0], max[1], max[2]));
  20689. if (spriteMap) {
  20690. var rootBoneData = data.rootBone;
  20691. render.rootBone = spriteMap[rootBoneData];
  20692. var bonesData = data.bones;
  20693. var n;
  20694. for (i = 0, n = bonesData.length; i < n; i++)
  20695. render.bones.push(spriteMap[bonesData[i]]);
  20696. }
  20697. else {
  20698. (data.rootBone) && (render._setRootBone(data.rootBone));
  20699. }
  20700. }
  20701. _changeHierarchyAnimator(animator) {
  20702. super._changeHierarchyAnimator(animator);
  20703. this.skinnedMeshRenderer._setCacheAnimator(animator);
  20704. }
  20705. _changeAnimatorAvatar(avatar) {
  20706. this.skinnedMeshRenderer._setCacheAvatar(avatar);
  20707. }
  20708. _cloneTo(destObject, srcRoot, dstRoot) {
  20709. var meshSprite3D = destObject;
  20710. meshSprite3D.meshFilter.sharedMesh = this.meshFilter.sharedMesh;
  20711. var meshRender = this._render;
  20712. var destMeshRender = meshSprite3D._render;
  20713. destMeshRender.enable = meshRender.enable;
  20714. destMeshRender.sharedMaterials = meshRender.sharedMaterials;
  20715. destMeshRender.castShadow = meshRender.castShadow;
  20716. var lightmapScaleOffset = meshRender.lightmapScaleOffset;
  20717. lightmapScaleOffset && (destMeshRender.lightmapScaleOffset = lightmapScaleOffset.clone());
  20718. destMeshRender.receiveShadow = meshRender.receiveShadow;
  20719. destMeshRender.sortingFudge = meshRender.sortingFudge;
  20720. destMeshRender._rootBone = meshRender._rootBone;
  20721. var bones = meshRender.bones;
  20722. var destBones = destMeshRender.bones;
  20723. var bonesCount = bones.length;
  20724. destBones.length = bonesCount;
  20725. var rootBone = meshRender.rootBone;
  20726. if (rootBone) {
  20727. var pathes = Utils3D._getHierarchyPath(srcRoot, rootBone, SkinnedMeshSprite3D._tempArray0);
  20728. if (pathes)
  20729. destMeshRender.rootBone = Utils3D._getNodeByHierarchyPath(dstRoot, pathes);
  20730. else
  20731. destMeshRender.rootBone = rootBone;
  20732. }
  20733. for (var i = 0; i < bones.length; i++) {
  20734. pathes = Utils3D._getHierarchyPath(srcRoot, bones[i], SkinnedMeshSprite3D._tempArray0);
  20735. if (pathes)
  20736. destBones[i] = Utils3D._getNodeByHierarchyPath(dstRoot, pathes);
  20737. else
  20738. destBones[i] = bones[i];
  20739. }
  20740. var lbb = meshRender.localBounds;
  20741. (lbb) && (lbb.cloneTo(destMeshRender.localBounds));
  20742. super._cloneTo(destObject, srcRoot, dstRoot);
  20743. }
  20744. destroy(destroyChild = true) {
  20745. if (this.destroyed)
  20746. return;
  20747. super.destroy(destroyChild);
  20748. this._meshFilter.destroy();
  20749. }
  20750. _create() {
  20751. return new SkinnedMeshSprite3D();
  20752. }
  20753. }
  20754. SkinnedMeshSprite3D._tempArray0 = [];
  20755. SkinnedMeshSprite3D.BONES = Shader3D.propertyNameToID("u_Bones");
  20756. SkinnedMeshSprite3D.shaderDefines = null;
  20757. class TrailMaterial extends BaseMaterial {
  20758. constructor() {
  20759. super();
  20760. this.setShaderName("Trail");
  20761. this._color = new Vector4(1.0, 1.0, 1.0, 1.0);
  20762. this._shaderValues.setVector(TrailMaterial.TINTCOLOR, new Vector4(1.0, 1.0, 1.0, 1.0));
  20763. this.renderMode = TrailMaterial.RENDERMODE_ALPHABLENDED;
  20764. }
  20765. static __initDefine__() {
  20766. TrailMaterial.shaderDefines = new ShaderDefines(BaseMaterial.shaderDefines);
  20767. TrailMaterial.SHADERDEFINE_MAINTEXTURE = TrailMaterial.shaderDefines.registerDefine("MAINTEXTURE");
  20768. TrailMaterial.SHADERDEFINE_TILINGOFFSET = TrailMaterial.shaderDefines.registerDefine("TILINGOFFSET");
  20769. TrailMaterial.SHADERDEFINE_ADDTIVEFOG = TrailMaterial.shaderDefines.registerDefine("ADDTIVEFOG");
  20770. }
  20771. get _TintColorR() {
  20772. return this._color.x;
  20773. }
  20774. set _TintColorR(value) {
  20775. this._color.x = value;
  20776. this.color = this._color;
  20777. }
  20778. get _TintColorG() {
  20779. return this._color.y;
  20780. }
  20781. set _TintColorG(value) {
  20782. this._color.y = value;
  20783. this.color = this._color;
  20784. }
  20785. get _TintColorB() {
  20786. return this._color.z;
  20787. }
  20788. set _TintColorB(value) {
  20789. this._color.z = value;
  20790. this.color = this._color;
  20791. }
  20792. get _TintColorA() {
  20793. return this._color.w;
  20794. }
  20795. set _TintColorA(value) {
  20796. this._color.w = value;
  20797. this.color = this._color;
  20798. }
  20799. get _MainTex_STX() {
  20800. return this._shaderValues.getVector(TrailMaterial.TILINGOFFSET).x;
  20801. }
  20802. set _MainTex_STX(x) {
  20803. var tilOff = this._shaderValues.getVector(TrailMaterial.TILINGOFFSET);
  20804. tilOff.x = x;
  20805. this.tilingOffset = tilOff;
  20806. }
  20807. get _MainTex_STY() {
  20808. return this._shaderValues.getVector(TrailMaterial.TILINGOFFSET).y;
  20809. }
  20810. set _MainTex_STY(y) {
  20811. var tilOff = this._shaderValues.getVector(TrailMaterial.TILINGOFFSET);
  20812. tilOff.y = y;
  20813. this.tilingOffset = tilOff;
  20814. }
  20815. get _MainTex_STZ() {
  20816. return this._shaderValues.getVector(TrailMaterial.TILINGOFFSET).z;
  20817. }
  20818. set _MainTex_STZ(z) {
  20819. var tilOff = this._shaderValues.getVector(TrailMaterial.TILINGOFFSET);
  20820. tilOff.z = z;
  20821. this.tilingOffset = tilOff;
  20822. }
  20823. get _MainTex_STW() {
  20824. return this._shaderValues.getVector(TrailMaterial.TILINGOFFSET).w;
  20825. }
  20826. set _MainTex_STW(w) {
  20827. var tilOff = this._shaderValues.getVector(TrailMaterial.TILINGOFFSET);
  20828. tilOff.w = w;
  20829. this.tilingOffset = tilOff;
  20830. }
  20831. set renderMode(value) {
  20832. switch (value) {
  20833. case TrailMaterial.RENDERMODE_ADDTIVE:
  20834. this.renderQueue = BaseMaterial.RENDERQUEUE_TRANSPARENT;
  20835. this.alphaTest = false;
  20836. this.depthWrite = false;
  20837. this.cull = RenderState.CULL_NONE;
  20838. this.blend = RenderState.BLEND_ENABLE_ALL;
  20839. this.blendSrc = RenderState.BLENDPARAM_SRC_ALPHA;
  20840. this.blendDst = RenderState.BLENDPARAM_ONE;
  20841. this.depthTest = RenderState.DEPTHTEST_LESS;
  20842. this._shaderValues.addDefine(TrailMaterial.SHADERDEFINE_ADDTIVEFOG);
  20843. break;
  20844. case TrailMaterial.RENDERMODE_ALPHABLENDED:
  20845. this.renderQueue = BaseMaterial.RENDERQUEUE_TRANSPARENT;
  20846. this.alphaTest = false;
  20847. this.depthWrite = false;
  20848. this.cull = RenderState.CULL_NONE;
  20849. this.blend = RenderState.BLEND_ENABLE_ALL;
  20850. this.blendSrc = RenderState.BLENDPARAM_SRC_ALPHA;
  20851. this.blendDst = RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA;
  20852. this.depthTest = RenderState.DEPTHTEST_LESS;
  20853. this._shaderValues.removeDefine(TrailMaterial.SHADERDEFINE_ADDTIVEFOG);
  20854. break;
  20855. default:
  20856. throw new Error("TrailMaterial : renderMode value error.");
  20857. }
  20858. }
  20859. get colorR() {
  20860. return this._TintColorR;
  20861. }
  20862. set colorR(value) {
  20863. this._TintColorR = value;
  20864. }
  20865. get colorG() {
  20866. return this._TintColorG;
  20867. }
  20868. set colorG(value) {
  20869. this._TintColorG = value;
  20870. }
  20871. get colorB() {
  20872. return this._TintColorB;
  20873. }
  20874. set colorB(value) {
  20875. this._TintColorB = value;
  20876. }
  20877. get colorA() {
  20878. return this._TintColorA;
  20879. }
  20880. set colorA(value) {
  20881. this._TintColorA = value;
  20882. }
  20883. get color() {
  20884. return this._shaderValues.getVector(TrailMaterial.TINTCOLOR);
  20885. }
  20886. set color(value) {
  20887. this._shaderValues.setVector(TrailMaterial.TINTCOLOR, value);
  20888. }
  20889. get texture() {
  20890. return this._shaderValues.getTexture(TrailMaterial.MAINTEXTURE);
  20891. }
  20892. set texture(value) {
  20893. if (value)
  20894. this._shaderValues.addDefine(TrailMaterial.SHADERDEFINE_MAINTEXTURE);
  20895. else
  20896. this._shaderValues.removeDefine(TrailMaterial.SHADERDEFINE_MAINTEXTURE);
  20897. this._shaderValues.setTexture(TrailMaterial.MAINTEXTURE, value);
  20898. }
  20899. get tilingOffsetX() {
  20900. return this._MainTex_STX;
  20901. }
  20902. set tilingOffsetX(x) {
  20903. this._MainTex_STX = x;
  20904. }
  20905. get tilingOffsetY() {
  20906. return this._MainTex_STY;
  20907. }
  20908. set tilingOffsetY(y) {
  20909. this._MainTex_STY = y;
  20910. }
  20911. get tilingOffsetZ() {
  20912. return this._MainTex_STZ;
  20913. }
  20914. set tilingOffsetZ(z) {
  20915. this._MainTex_STZ = z;
  20916. }
  20917. get tilingOffsetW() {
  20918. return this._MainTex_STW;
  20919. }
  20920. set tilingOffsetW(w) {
  20921. this._MainTex_STW = w;
  20922. }
  20923. get tilingOffset() {
  20924. return this._shaderValues.getVector(TrailMaterial.TILINGOFFSET);
  20925. }
  20926. set tilingOffset(value) {
  20927. if (value) {
  20928. if (value.x != 1 || value.y != 1 || value.z != 0 || value.w != 0)
  20929. this._shaderValues.addDefine(TrailMaterial.SHADERDEFINE_TILINGOFFSET);
  20930. else
  20931. this._shaderValues.removeDefine(TrailMaterial.SHADERDEFINE_TILINGOFFSET);
  20932. }
  20933. else {
  20934. this._shaderValues.removeDefine(TrailMaterial.SHADERDEFINE_TILINGOFFSET);
  20935. }
  20936. this._shaderValues.setVector(TrailMaterial.TILINGOFFSET, value);
  20937. }
  20938. set depthWrite(value) {
  20939. this._shaderValues.setBool(TrailMaterial.DEPTH_WRITE, value);
  20940. }
  20941. get depthWrite() {
  20942. return this._shaderValues.getBool(TrailMaterial.DEPTH_WRITE);
  20943. }
  20944. set cull(value) {
  20945. this._shaderValues.setInt(TrailMaterial.CULL, value);
  20946. }
  20947. get cull() {
  20948. return this._shaderValues.getInt(TrailMaterial.CULL);
  20949. }
  20950. set blend(value) {
  20951. this._shaderValues.setInt(TrailMaterial.BLEND, value);
  20952. }
  20953. get blend() {
  20954. return this._shaderValues.getInt(TrailMaterial.BLEND);
  20955. }
  20956. set blendSrc(value) {
  20957. this._shaderValues.setInt(TrailMaterial.BLEND_SRC, value);
  20958. }
  20959. get blendSrc() {
  20960. return this._shaderValues.getInt(TrailMaterial.BLEND_SRC);
  20961. }
  20962. set blendDst(value) {
  20963. this._shaderValues.setInt(TrailMaterial.BLEND_DST, value);
  20964. }
  20965. get blendDst() {
  20966. return this._shaderValues.getInt(TrailMaterial.BLEND_DST);
  20967. }
  20968. set depthTest(value) {
  20969. this._shaderValues.setInt(TrailMaterial.DEPTH_TEST, value);
  20970. }
  20971. get depthTest() {
  20972. return this._shaderValues.getInt(TrailMaterial.DEPTH_TEST);
  20973. }
  20974. clone() {
  20975. var dest = new TrailMaterial();
  20976. this.cloneTo(dest);
  20977. return dest;
  20978. }
  20979. }
  20980. TrailMaterial.RENDERMODE_ALPHABLENDED = 0;
  20981. TrailMaterial.RENDERMODE_ADDTIVE = 1;
  20982. TrailMaterial.MAINTEXTURE = Shader3D.propertyNameToID("u_MainTexture");
  20983. TrailMaterial.TINTCOLOR = Shader3D.propertyNameToID("u_MainColor");
  20984. TrailMaterial.TILINGOFFSET = Shader3D.propertyNameToID("u_TilingOffset");
  20985. TrailMaterial.CULL = Shader3D.propertyNameToID("s_Cull");
  20986. TrailMaterial.BLEND = Shader3D.propertyNameToID("s_Blend");
  20987. TrailMaterial.BLEND_SRC = Shader3D.propertyNameToID("s_BlendSrc");
  20988. TrailMaterial.BLEND_DST = Shader3D.propertyNameToID("s_BlendDst");
  20989. TrailMaterial.DEPTH_TEST = Shader3D.propertyNameToID("s_DepthTest");
  20990. TrailMaterial.DEPTH_WRITE = Shader3D.propertyNameToID("s_DepthWrite");
  20991. TrailMaterial.shaderDefines = null;
  20992. class Keyframe {
  20993. constructor() {
  20994. }
  20995. cloneTo(destObject) {
  20996. var destKeyFrame = destObject;
  20997. destKeyFrame.time = this.time;
  20998. }
  20999. clone() {
  21000. var dest = new Keyframe();
  21001. this.cloneTo(dest);
  21002. return dest;
  21003. }
  21004. }
  21005. class FloatKeyframe extends Keyframe {
  21006. constructor() {
  21007. super();
  21008. }
  21009. cloneTo(destObject) {
  21010. super.cloneTo(destObject);
  21011. var destKeyFrame = destObject;
  21012. destKeyFrame.inTangent = this.inTangent;
  21013. destKeyFrame.outTangent = this.outTangent;
  21014. destKeyFrame.value = this.value;
  21015. }
  21016. }
  21017. if (window.conch && window.conchFloatKeyframe) {
  21018. FloatKeyframe = window.conchFloatKeyframe;
  21019. }
  21020. if (window.qq && window.qq.webglPlus) {
  21021. FloatKeyframe = window.qq.webglPlus.conchFloatKeyframe;
  21022. }
  21023. class TextureMode {
  21024. }
  21025. TextureMode.Stretch = 0;
  21026. TextureMode.Tile = 1;
  21027. (function (TrailAlignment) {
  21028. TrailAlignment[TrailAlignment["View"] = 0] = "View";
  21029. TrailAlignment[TrailAlignment["TransformZ"] = 1] = "TransformZ";
  21030. })(exports.TrailAlignment || (exports.TrailAlignment = {}));
  21031. class VertexTrail {
  21032. constructor() {
  21033. }
  21034. static get vertexDeclaration1() {
  21035. return VertexTrail._vertexDeclaration1;
  21036. }
  21037. static get vertexDeclaration2() {
  21038. return VertexTrail._vertexDeclaration2;
  21039. }
  21040. get vertexDeclaration() {
  21041. return VertexTrail._vertexDeclaration1;
  21042. }
  21043. static __init__() {
  21044. VertexTrail._vertexDeclaration1 = new VertexDeclaration(32, [new VertexElement(0, VertexElementFormat.Vector3, VertexTrail.TRAIL_POSITION0),
  21045. new VertexElement(12, VertexElementFormat.Vector3, VertexTrail.TRAIL_OFFSETVECTOR),
  21046. new VertexElement(24, VertexElementFormat.Single, VertexTrail.TRAIL_TIME0),
  21047. new VertexElement(28, VertexElementFormat.Single, VertexTrail.TRAIL_TEXTURECOORDINATE0Y)]);
  21048. VertexTrail._vertexDeclaration2 = new VertexDeclaration(20, [new VertexElement(0, VertexElementFormat.Single, VertexTrail.TRAIL_TEXTURECOORDINATE0X),
  21049. new VertexElement(4, VertexElementFormat.Color, VertexTrail.TRAIL_COLOR)]);
  21050. }
  21051. }
  21052. VertexTrail.TRAIL_POSITION0 = 0;
  21053. VertexTrail.TRAIL_OFFSETVECTOR = 1;
  21054. VertexTrail.TRAIL_TIME0 = 2;
  21055. VertexTrail.TRAIL_TEXTURECOORDINATE0Y = 3;
  21056. VertexTrail.TRAIL_TEXTURECOORDINATE0X = 4;
  21057. VertexTrail.TRAIL_COLOR = 5;
  21058. class TrailGeometry extends GeometryElement {
  21059. constructor(owner) {
  21060. super();
  21061. this._floatCountPerVertices1 = 8;
  21062. this._floatCountPerVertices2 = 5;
  21063. this._increaseSegementCount = 16;
  21064. this._activeIndex = 0;
  21065. this._endIndex = 0;
  21066. this._needAddFirstVertex = false;
  21067. this._isTempEndVertex = false;
  21068. this._vertices1 = null;
  21069. this._vertices2 = null;
  21070. this._lastFixedVertexPosition = new Vector3();
  21071. this._bufferState = new BufferState();
  21072. this.tmpColor = new Color();
  21073. this._disappearBoundsMode = false;
  21074. this._owner = owner;
  21075. this._segementCount = this._increaseSegementCount;
  21076. this._resizeData(this._segementCount, this._bufferState);
  21077. var bounds = this._owner._owner.trailRenderer.bounds;
  21078. var min = bounds.getMin();
  21079. var max = bounds.getMax();
  21080. min.setValue(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
  21081. max.setValue(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
  21082. bounds.setMin(min);
  21083. bounds.setMax(max);
  21084. Laya.Render.supportWebGLPlusCulling && this._calculateBoundingBoxForNative();
  21085. }
  21086. _resizeData(segementCount, bufferState) {
  21087. this._subBirthTime = new Float32Array(segementCount);
  21088. this._subDistance = new Float64Array(segementCount);
  21089. var gl = Laya.LayaGL.instance;
  21090. var vertexCount = segementCount * 2;
  21091. var vertexDeclaration1 = VertexTrail.vertexDeclaration1;
  21092. var vertexDeclaration2 = VertexTrail.vertexDeclaration2;
  21093. var vertexBuffers = [];
  21094. var vertexbuffer1Size = vertexCount * vertexDeclaration1.vertexStride;
  21095. var vertexbuffer2Size = vertexCount * vertexDeclaration2.vertexStride;
  21096. var memorySize = vertexbuffer1Size + vertexbuffer2Size;
  21097. this._vertices1 = new Float32Array(vertexCount * this._floatCountPerVertices1);
  21098. this._vertices2 = new Float32Array(vertexCount * this._floatCountPerVertices2);
  21099. this._vertexBuffer1 = new VertexBuffer3D(vertexbuffer1Size, gl.STATIC_DRAW, false);
  21100. this._vertexBuffer1.vertexDeclaration = vertexDeclaration1;
  21101. this._vertexBuffer2 = new VertexBuffer3D(vertexbuffer2Size, gl.DYNAMIC_DRAW, false);
  21102. this._vertexBuffer2.vertexDeclaration = vertexDeclaration2;
  21103. vertexBuffers.push(this._vertexBuffer1);
  21104. vertexBuffers.push(this._vertexBuffer2);
  21105. bufferState.bind();
  21106. bufferState.applyVertexBuffers(vertexBuffers);
  21107. bufferState.unBind();
  21108. Laya.Resource._addMemory(memorySize, memorySize);
  21109. }
  21110. _resetData() {
  21111. var count = this._endIndex - this._activeIndex;
  21112. var oldVertices1 = new Float32Array(this._vertices1.buffer, this._floatCountPerVertices1 * 2 * this._activeIndex * 4, this._floatCountPerVertices1 * 2 * count);
  21113. var oldVertices2 = new Float32Array(this._vertices2.buffer, this._floatCountPerVertices2 * 2 * this._activeIndex * 4, this._floatCountPerVertices2 * 2 * count);
  21114. var oldSubDistance = new Float64Array(this._subDistance.buffer, this._activeIndex * 8, count);
  21115. var oldSubBirthTime = new Float32Array(this._subBirthTime.buffer, this._activeIndex * 4, count);
  21116. if (count === this._segementCount) {
  21117. this._vertexBuffer1.destroy();
  21118. this._vertexBuffer2.destroy();
  21119. this._segementCount += this._increaseSegementCount;
  21120. this._resizeData(this._segementCount, this._bufferState);
  21121. }
  21122. this._vertices1.set(oldVertices1, 0);
  21123. this._vertices2.set(oldVertices2, 0);
  21124. this._subDistance.set(oldSubDistance, 0);
  21125. this._subBirthTime.set(oldSubBirthTime, 0);
  21126. this._endIndex = count;
  21127. this._activeIndex = 0;
  21128. this._vertexBuffer1.setData(this._vertices1.buffer, 0, this._floatCountPerVertices1 * 2 * this._activeIndex * 4, this._floatCountPerVertices1 * 2 * count * 4);
  21129. this._vertexBuffer2.setData(this._vertices2.buffer, 0, this._floatCountPerVertices2 * 2 * this._activeIndex * 4, this._floatCountPerVertices2 * 2 * count * 4);
  21130. }
  21131. _updateTrail(camera, lastPosition, position) {
  21132. if (!Vector3.equals(lastPosition, position)) {
  21133. if ((this._endIndex - this._activeIndex) === 0)
  21134. this._addTrailByFirstPosition(camera, position);
  21135. else
  21136. this._addTrailByNextPosition(camera, position);
  21137. }
  21138. }
  21139. _addTrailByFirstPosition(camera, position) {
  21140. (this._endIndex === this._segementCount) && (this._resetData());
  21141. this._subDistance[this._endIndex] = 0;
  21142. this._subBirthTime[this._endIndex] = this._owner._curtime;
  21143. this._endIndex++;
  21144. position.cloneTo(this._lastFixedVertexPosition);
  21145. this._needAddFirstVertex = true;
  21146. }
  21147. _addTrailByNextPosition(camera, position) {
  21148. var delVector3 = TrailGeometry._tempVector30;
  21149. var pointAtoBVector3 = TrailGeometry._tempVector31;
  21150. switch (this._owner.alignment) {
  21151. case exports.TrailAlignment.View:
  21152. var cameraMatrix = camera.viewMatrix;
  21153. Vector3.transformCoordinate(position, cameraMatrix, TrailGeometry._tempVector33);
  21154. Vector3.transformCoordinate(this._lastFixedVertexPosition, cameraMatrix, TrailGeometry._tempVector34);
  21155. Vector3.subtract(TrailGeometry._tempVector33, TrailGeometry._tempVector34, delVector3);
  21156. Vector3.cross(TrailGeometry._tempVector33, delVector3, pointAtoBVector3);
  21157. break;
  21158. case exports.TrailAlignment.TransformZ:
  21159. Vector3.subtract(position, this._lastFixedVertexPosition, delVector3);
  21160. var forward = TrailGeometry._tempVector32;
  21161. this._owner._owner.transform.localMatrix.getForward(forward);
  21162. Vector3.cross(delVector3, forward, pointAtoBVector3);
  21163. break;
  21164. }
  21165. Vector3.normalize(pointAtoBVector3, pointAtoBVector3);
  21166. Vector3.scale(pointAtoBVector3, this._owner.widthMultiplier / 2, pointAtoBVector3);
  21167. var delLength = Vector3.scalarLength(delVector3);
  21168. var tempEndIndex;
  21169. var offset;
  21170. if (this._needAddFirstVertex) {
  21171. this._updateVerticesByPositionData(position, pointAtoBVector3, this._endIndex - 1);
  21172. this._needAddFirstVertex = false;
  21173. }
  21174. if (delLength - this._owner.minVertexDistance >= MathUtils3D.zeroTolerance) {
  21175. if (this._isTempEndVertex) {
  21176. tempEndIndex = this._endIndex - 1;
  21177. offset = delLength - this._subDistance[tempEndIndex];
  21178. this._updateVerticesByPosition(position, pointAtoBVector3, delLength, tempEndIndex);
  21179. this._owner._totalLength += offset;
  21180. }
  21181. else {
  21182. (this._endIndex === this._segementCount) && (this._resetData());
  21183. this._updateVerticesByPosition(position, pointAtoBVector3, delLength, this._endIndex);
  21184. this._owner._totalLength += delLength;
  21185. this._endIndex++;
  21186. }
  21187. position.cloneTo(this._lastFixedVertexPosition);
  21188. this._isTempEndVertex = false;
  21189. }
  21190. else {
  21191. if (this._isTempEndVertex) {
  21192. tempEndIndex = this._endIndex - 1;
  21193. offset = delLength - this._subDistance[tempEndIndex];
  21194. this._updateVerticesByPosition(position, pointAtoBVector3, delLength, tempEndIndex);
  21195. this._owner._totalLength += offset;
  21196. }
  21197. else {
  21198. (this._endIndex === this._segementCount) && (this._resetData());
  21199. this._updateVerticesByPosition(position, pointAtoBVector3, delLength, this._endIndex);
  21200. this._owner._totalLength += delLength;
  21201. this._endIndex++;
  21202. }
  21203. this._isTempEndVertex = true;
  21204. }
  21205. }
  21206. _updateVerticesByPositionData(position, pointAtoBVector3, index) {
  21207. var vertexOffset = this._floatCountPerVertices1 * 2 * index;
  21208. var curtime = this._owner._curtime;
  21209. this._vertices1[vertexOffset] = position.x;
  21210. this._vertices1[vertexOffset + 1] = position.y;
  21211. this._vertices1[vertexOffset + 2] = position.z;
  21212. this._vertices1[vertexOffset + 3] = -pointAtoBVector3.x;
  21213. this._vertices1[vertexOffset + 4] = -pointAtoBVector3.y;
  21214. this._vertices1[vertexOffset + 5] = -pointAtoBVector3.z;
  21215. this._vertices1[vertexOffset + 6] = curtime;
  21216. this._vertices1[vertexOffset + 7] = 1.0;
  21217. this._vertices1[vertexOffset + 8] = position.x;
  21218. this._vertices1[vertexOffset + 9] = position.y;
  21219. this._vertices1[vertexOffset + 10] = position.z;
  21220. this._vertices1[vertexOffset + 11] = pointAtoBVector3.x;
  21221. this._vertices1[vertexOffset + 12] = pointAtoBVector3.y;
  21222. this._vertices1[vertexOffset + 13] = pointAtoBVector3.z;
  21223. this._vertices1[vertexOffset + 14] = curtime;
  21224. this._vertices1[vertexOffset + 15] = 0.0;
  21225. var bounds = this._owner._owner.trailRenderer.bounds;
  21226. var min = bounds.getMin();
  21227. var max = bounds.getMax();
  21228. var up = TrailGeometry._tempVector35;
  21229. var down = TrailGeometry._tempVector36;
  21230. var out = TrailGeometry._tempVector32;
  21231. Vector3.add(position, pointAtoBVector3, up);
  21232. Vector3.subtract(position, pointAtoBVector3, down);
  21233. Vector3.min(down, up, out);
  21234. Vector3.min(min, out, min);
  21235. bounds.setMin(min);
  21236. Vector3.max(up, down, out);
  21237. Vector3.max(max, out, max);
  21238. bounds.setMax(max);
  21239. Laya.Render.supportWebGLPlusCulling && this._calculateBoundingBoxForNative();
  21240. var floatCount = this._floatCountPerVertices1 * 2;
  21241. this._vertexBuffer1.setData(this._vertices1.buffer, vertexOffset * 4, vertexOffset * 4, floatCount * 4);
  21242. }
  21243. _updateVerticesByPosition(position, pointAtoBVector3, delDistance, index) {
  21244. this._updateVerticesByPositionData(position, pointAtoBVector3, index);
  21245. this._subDistance[index] = delDistance;
  21246. this._subBirthTime[index] = this._owner._curtime;
  21247. }
  21248. _updateVertexBufferUV() {
  21249. var bounds;
  21250. var min, max;
  21251. if (this._disappearBoundsMode) {
  21252. bounds = this._owner._owner.trailRenderer.bounds;
  21253. min = bounds.getMin();
  21254. max = bounds.getMax();
  21255. min.setValue(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
  21256. max.setValue(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
  21257. Laya.Render.supportWebGLPlusCulling && this._calculateBoundingBoxForNative();
  21258. }
  21259. var vertexCount = this._endIndex;
  21260. var curLength = 0;
  21261. var gradient = this._owner.colorGradient;
  21262. var startAlphaIndex = gradient.colorAlphaKeysCount - 1;
  21263. var startColorIndex = gradient.colorRGBKeysCount - 1;
  21264. var totalLength = this._owner._totalLength;
  21265. var stride = this._floatCountPerVertices2 * 2;
  21266. for (var i = this._activeIndex; i < vertexCount; i++) {
  21267. (i !== this._activeIndex) && (curLength += this._subDistance[i]);
  21268. var uvX;
  21269. var lerpFactor;
  21270. if (this._owner.textureMode == TextureMode.Stretch) {
  21271. uvX = 1.0 - curLength / totalLength;
  21272. lerpFactor = uvX;
  21273. }
  21274. else {
  21275. lerpFactor = 1.0 - curLength / totalLength;
  21276. uvX = 1.0 - (totalLength - curLength);
  21277. }
  21278. startColorIndex = gradient.evaluateColorRGB(lerpFactor, this.tmpColor, startColorIndex, true);
  21279. startAlphaIndex = gradient.evaluateColorAlpha(lerpFactor, this.tmpColor, startAlphaIndex, true);
  21280. var index = i * stride;
  21281. this._vertices2[index + 0] = uvX;
  21282. this._vertices2[index + 1] = this.tmpColor.r;
  21283. this._vertices2[index + 2] = this.tmpColor.g;
  21284. this._vertices2[index + 3] = this.tmpColor.b;
  21285. this._vertices2[index + 4] = this.tmpColor.a;
  21286. this._vertices2[index + 5] = uvX;
  21287. this._vertices2[index + 6] = this.tmpColor.r;
  21288. this._vertices2[index + 7] = this.tmpColor.g;
  21289. this._vertices2[index + 8] = this.tmpColor.b;
  21290. this._vertices2[index + 9] = this.tmpColor.a;
  21291. if (this._disappearBoundsMode) {
  21292. var posOffset = this._floatCountPerVertices1 * 2 * i;
  21293. var pos = TrailGeometry._tempVector32;
  21294. var up = TrailGeometry._tempVector33;
  21295. var side = TrailGeometry._tempVector34;
  21296. pos.setValue(this._vertices1[posOffset + 0], this._vertices1[posOffset + 1], this._vertices1[posOffset + 2]);
  21297. up.setValue(this._vertices1[posOffset + 3], this._vertices1[posOffset + 4], this._vertices1[posOffset + 5]);
  21298. Vector3.add(pos, up, side);
  21299. Vector3.min(side, min, min);
  21300. Vector3.max(side, max, max);
  21301. Vector3.subtract(pos, up, side);
  21302. Vector3.min(side, min, min);
  21303. Vector3.max(side, max, max);
  21304. }
  21305. }
  21306. if (this._disappearBoundsMode) {
  21307. bounds.setMin(min);
  21308. bounds.setMax(max);
  21309. this._disappearBoundsMode = false;
  21310. Laya.Render.supportWebGLPlusCulling && this._calculateBoundingBoxForNative();
  21311. }
  21312. var offset = this._activeIndex * stride;
  21313. this._vertexBuffer2.setData(this._vertices2.buffer, offset * 4, offset * 4, (vertexCount * stride - offset) * 4);
  21314. }
  21315. _updateDisappear() {
  21316. var count = this._endIndex;
  21317. for (var i = this._activeIndex; i < count; i++) {
  21318. if (this._owner._curtime - this._subBirthTime[i] >= this._owner.time + MathUtils3D.zeroTolerance) {
  21319. var nextIndex = i + 1;
  21320. if (nextIndex !== count)
  21321. this._owner._totalLength -= this._subDistance[nextIndex];
  21322. if (this._isTempEndVertex && (nextIndex === count - 1)) {
  21323. var offset = this._floatCountPerVertices1 * i * 2;
  21324. var fixedPos = this._lastFixedVertexPosition;
  21325. fixedPos.x = this._vertices1[0];
  21326. fixedPos.y = this._vertices1[1];
  21327. fixedPos.z = this._vertices1[2];
  21328. this._isTempEndVertex = false;
  21329. }
  21330. this._activeIndex++;
  21331. this._disappearBoundsMode = true;
  21332. }
  21333. else {
  21334. break;
  21335. }
  21336. }
  21337. }
  21338. _getType() {
  21339. return TrailGeometry._type;
  21340. }
  21341. _prepareRender(state) {
  21342. return this._endIndex - this._activeIndex > 1;
  21343. }
  21344. _render(state) {
  21345. this._bufferState.bind();
  21346. var gl = Laya.LayaGL.instance;
  21347. var start = this._activeIndex * 2;
  21348. var count = this._endIndex * 2 - start;
  21349. gl.drawArrays(gl.TRIANGLE_STRIP, start, count);
  21350. Laya.Stat.renderBatches++;
  21351. Laya.Stat.trianglesFaces += count - 2;
  21352. }
  21353. destroy() {
  21354. super.destroy();
  21355. var memorySize = this._vertexBuffer1._byteLength + this._vertexBuffer2._byteLength;
  21356. Laya.Resource._addMemory(-memorySize, -memorySize);
  21357. this._bufferState.destroy();
  21358. this._vertexBuffer1.destroy();
  21359. this._vertexBuffer2.destroy();
  21360. this._bufferState = null;
  21361. this._vertices1 = null;
  21362. this._vertexBuffer1 = null;
  21363. this._vertices2 = null;
  21364. this._vertexBuffer2 = null;
  21365. this._subBirthTime = null;
  21366. this._subDistance = null;
  21367. this._lastFixedVertexPosition = null;
  21368. this._disappearBoundsMode = false;
  21369. }
  21370. _calculateBoundingBoxForNative() {
  21371. var trail = this._owner._owner.trailRenderer;
  21372. var bounds = trail.bounds;
  21373. var min = bounds.getMin();
  21374. var max = bounds.getMax();
  21375. var buffer = FrustumCulling._cullingBuffer;
  21376. buffer[trail._cullingBufferIndex + 1] = min.x;
  21377. buffer[trail._cullingBufferIndex + 2] = min.y;
  21378. buffer[trail._cullingBufferIndex + 3] = min.z;
  21379. buffer[trail._cullingBufferIndex + 4] = max.x;
  21380. buffer[trail._cullingBufferIndex + 5] = max.y;
  21381. buffer[trail._cullingBufferIndex + 6] = max.z;
  21382. }
  21383. }
  21384. TrailGeometry.ALIGNMENT_VIEW = 0;
  21385. TrailGeometry.ALIGNMENT_TRANSFORM_Z = 1;
  21386. TrailGeometry._tempVector30 = new Vector3();
  21387. TrailGeometry._tempVector31 = new Vector3();
  21388. TrailGeometry._tempVector32 = new Vector3();
  21389. TrailGeometry._tempVector33 = new Vector3();
  21390. TrailGeometry._tempVector34 = new Vector3();
  21391. TrailGeometry._tempVector35 = new Vector3();
  21392. TrailGeometry._tempVector36 = new Vector3();
  21393. TrailGeometry._type = GeometryElement._typeCounter++;
  21394. class TrailFilter {
  21395. constructor(owner) {
  21396. this._totalLength = 0;
  21397. this._lastPosition = new Vector3();
  21398. this._curtime = 0;
  21399. this.alignment = TrailFilter.ALIGNMENT_VIEW;
  21400. this._owner = owner;
  21401. this._initDefaultData();
  21402. this.addRenderElement();
  21403. }
  21404. get time() {
  21405. return this._time;
  21406. }
  21407. set time(value) {
  21408. this._time = value;
  21409. this._owner._render._shaderValues.setNumber(TrailFilter.LIFETIME, value);
  21410. }
  21411. get minVertexDistance() {
  21412. return this._minVertexDistance;
  21413. }
  21414. set minVertexDistance(value) {
  21415. this._minVertexDistance = value;
  21416. }
  21417. get widthMultiplier() {
  21418. return this._widthMultiplier;
  21419. }
  21420. set widthMultiplier(value) {
  21421. this._widthMultiplier = value;
  21422. }
  21423. get widthCurve() {
  21424. return this._widthCurve;
  21425. }
  21426. set widthCurve(value) {
  21427. this._widthCurve = value;
  21428. var widthCurveFloatArray = new Float32Array(value.length * 4);
  21429. var i, j, index = 0;
  21430. for (i = 0, j = value.length; i < j; i++) {
  21431. widthCurveFloatArray[index++] = value[i].time;
  21432. widthCurveFloatArray[index++] = value[i].inTangent;
  21433. widthCurveFloatArray[index++] = value[i].outTangent;
  21434. widthCurveFloatArray[index++] = value[i].value;
  21435. }
  21436. this._owner._render._shaderValues.setBuffer(TrailFilter.WIDTHCURVE, widthCurveFloatArray);
  21437. this._owner._render._shaderValues.setInt(TrailFilter.WIDTHCURVEKEYLENGTH, value.length);
  21438. }
  21439. get colorGradient() {
  21440. return this._colorGradient;
  21441. }
  21442. set colorGradient(value) {
  21443. this._colorGradient = value;
  21444. }
  21445. get textureMode() {
  21446. return this._textureMode;
  21447. }
  21448. set textureMode(value) {
  21449. this._textureMode = value;
  21450. }
  21451. addRenderElement() {
  21452. var render = this._owner._render;
  21453. var elements = render._renderElements;
  21454. var material = render.sharedMaterials[0];
  21455. (material) || (material = TrailMaterial.defaultMaterial);
  21456. var element = new RenderElement();
  21457. element.setTransform(this._owner._transform);
  21458. element.render = render;
  21459. element.material = material;
  21460. this._trialGeometry = new TrailGeometry(this);
  21461. element.setGeometry(this._trialGeometry);
  21462. elements.push(element);
  21463. }
  21464. _update(state) {
  21465. var render = this._owner._render;
  21466. this._curtime += state.scene.timer._delta / 1000;
  21467. render._shaderValues.setNumber(TrailFilter.CURTIME, this._curtime);
  21468. var curPos = this._owner.transform.position;
  21469. var element = render._renderElements[0]._geometry;
  21470. element._updateDisappear();
  21471. element._updateTrail(state.camera, this._lastPosition, curPos);
  21472. element._updateVertexBufferUV();
  21473. curPos.cloneTo(this._lastPosition);
  21474. }
  21475. _initDefaultData() {
  21476. this.time = 5.0;
  21477. this.minVertexDistance = 0.1;
  21478. this.widthMultiplier = 1;
  21479. this.textureMode = TextureMode.Stretch;
  21480. var widthKeyFrames = [];
  21481. var widthKeyFrame1 = new FloatKeyframe();
  21482. widthKeyFrame1.time = 0;
  21483. widthKeyFrame1.inTangent = 0;
  21484. widthKeyFrame1.outTangent = 0;
  21485. widthKeyFrame1.value = 1;
  21486. widthKeyFrames.push(widthKeyFrame1);
  21487. var widthKeyFrame2 = new FloatKeyframe();
  21488. widthKeyFrame2.time = 1;
  21489. widthKeyFrame2.inTangent = 0;
  21490. widthKeyFrame2.outTangent = 0;
  21491. widthKeyFrame2.value = 1;
  21492. widthKeyFrames.push(widthKeyFrame2);
  21493. this.widthCurve = widthKeyFrames;
  21494. var gradient = new Gradient(2, 2);
  21495. gradient.mode = GradientMode.Blend;
  21496. gradient.addColorRGB(0, Color.WHITE);
  21497. gradient.addColorRGB(1, Color.WHITE);
  21498. gradient.addColorAlpha(0, 1);
  21499. gradient.addColorAlpha(1, 1);
  21500. this.colorGradient = gradient;
  21501. }
  21502. destroy() {
  21503. this._trialGeometry.destroy();
  21504. this._trialGeometry = null;
  21505. this._widthCurve = null;
  21506. this._colorGradient = null;
  21507. }
  21508. }
  21509. TrailFilter.CURTIME = Shader3D.propertyNameToID("u_CurTime");
  21510. TrailFilter.LIFETIME = Shader3D.propertyNameToID("u_LifeTime");
  21511. TrailFilter.WIDTHCURVE = Shader3D.propertyNameToID("u_WidthCurve");
  21512. TrailFilter.WIDTHCURVEKEYLENGTH = Shader3D.propertyNameToID("u_WidthCurveKeyLength");
  21513. TrailFilter.ALIGNMENT_VIEW = 0;
  21514. TrailFilter.ALIGNMENT_TRANSFORM_Z = 1;
  21515. class TrailRenderer extends BaseRender {
  21516. constructor(owner) {
  21517. super(owner);
  21518. this._projectionViewWorldMatrix = new Matrix4x4();
  21519. }
  21520. _calculateBoundingBox() {
  21521. }
  21522. _needRender(boundFrustum, context) {
  21523. this._owner.trailFilter._update(context);
  21524. if (boundFrustum)
  21525. return boundFrustum.intersects(this.bounds._getBoundBox());
  21526. else
  21527. return true;
  21528. }
  21529. _updateForNative(context) {
  21530. this._owner.trailFilter._update(context);
  21531. }
  21532. _renderUpdate(state, transform) {
  21533. super._renderUpdate(state, transform);
  21534. }
  21535. _renderUpdateWithCamera(context, transform) {
  21536. var projectionView = context.projectionViewMatrix;
  21537. if (transform) {
  21538. Matrix4x4.multiply(projectionView, transform.worldMatrix, this._projectionViewWorldMatrix);
  21539. this._shaderValues.setMatrix4x4(Sprite3D.MVPMATRIX, this._projectionViewWorldMatrix);
  21540. }
  21541. else {
  21542. this._shaderValues.setMatrix4x4(Sprite3D.MVPMATRIX, projectionView);
  21543. }
  21544. }
  21545. }
  21546. class TrailSprite3D extends RenderableSprite3D {
  21547. static __init__() {
  21548. }
  21549. get trailFilter() {
  21550. return this._geometryFilter;
  21551. }
  21552. get trailRenderer() {
  21553. return this._render;
  21554. }
  21555. constructor(name = null) {
  21556. super(name);
  21557. this._render = new TrailRenderer(this);
  21558. this._geometryFilter = new TrailFilter(this);
  21559. }
  21560. _parse(data, spriteMap) {
  21561. super._parse(data, spriteMap);
  21562. var render = this._render;
  21563. var filter = this._geometryFilter;
  21564. var i, j;
  21565. var materials = data.materials;
  21566. if (materials) {
  21567. var sharedMaterials = render.sharedMaterials;
  21568. var materialCount = materials.length;
  21569. sharedMaterials.length = materialCount;
  21570. for (i = 0; i < materialCount; i++)
  21571. sharedMaterials[i] = Laya.Loader.getRes(materials[i].path);
  21572. render.sharedMaterials = sharedMaterials;
  21573. }
  21574. filter.time = data.time;
  21575. filter.minVertexDistance = data.minVertexDistance;
  21576. filter.widthMultiplier = data.widthMultiplier;
  21577. filter.textureMode = data.textureMode;
  21578. (data.alignment != null) && (filter.alignment = data.alignment);
  21579. var widthCurve = [];
  21580. var widthCurveData = data.widthCurve;
  21581. for (i = 0, j = widthCurveData.length; i < j; i++) {
  21582. var trailkeyframe = new FloatKeyframe();
  21583. trailkeyframe.time = widthCurveData[i].time;
  21584. trailkeyframe.inTangent = widthCurveData[i].inTangent;
  21585. trailkeyframe.outTangent = widthCurveData[i].outTangent;
  21586. trailkeyframe.value = widthCurveData[i].value;
  21587. widthCurve.push(trailkeyframe);
  21588. }
  21589. filter.widthCurve = widthCurve;
  21590. var colorGradientData = data.colorGradient;
  21591. var colorKeys = colorGradientData.colorKeys;
  21592. var alphaKeys = colorGradientData.alphaKeys;
  21593. var colorGradient = new Gradient(colorKeys.length, alphaKeys.length);
  21594. colorGradient.mode = colorGradientData.mode;
  21595. for (i = 0, j = colorKeys.length; i < j; i++) {
  21596. var colorKey = colorKeys[i];
  21597. colorGradient.addColorRGB(colorKey.time, new Color(colorKey.value[0], colorKey.value[1], colorKey.value[2], 1.0));
  21598. }
  21599. for (i = 0, j = alphaKeys.length; i < j; i++) {
  21600. var alphaKey = alphaKeys[i];
  21601. colorGradient.addColorAlpha(alphaKey.time, alphaKey.value);
  21602. }
  21603. filter.colorGradient = colorGradient;
  21604. }
  21605. _onActive() {
  21606. super._onActive();
  21607. this._transform.position.cloneTo(this._geometryFilter._lastPosition);
  21608. }
  21609. _cloneTo(destObject, srcSprite, dstSprite) {
  21610. super._cloneTo(destObject, srcSprite, dstSprite);
  21611. var i, j;
  21612. var destTrailSprite3D = destObject;
  21613. var destTrailFilter = destTrailSprite3D.trailFilter;
  21614. destTrailFilter.time = this.trailFilter.time;
  21615. destTrailFilter.minVertexDistance = this.trailFilter.minVertexDistance;
  21616. destTrailFilter.widthMultiplier = this.trailFilter.widthMultiplier;
  21617. destTrailFilter.textureMode = this.trailFilter.textureMode;
  21618. var widthCurveData = this.trailFilter.widthCurve;
  21619. var widthCurve = [];
  21620. for (i = 0, j = widthCurveData.length; i < j; i++) {
  21621. var keyFrame = new FloatKeyframe();
  21622. widthCurveData[i].cloneTo(keyFrame);
  21623. widthCurve.push(keyFrame);
  21624. }
  21625. destTrailFilter.widthCurve = widthCurve;
  21626. var destColorGradient = new Gradient(this.trailFilter.colorGradient.maxColorRGBKeysCount, this.trailFilter.colorGradient.maxColorAlphaKeysCount);
  21627. this.trailFilter.colorGradient.cloneTo(destColorGradient);
  21628. destTrailFilter.colorGradient = destColorGradient;
  21629. var destTrailRender = destTrailSprite3D.trailRenderer;
  21630. destTrailRender.sharedMaterial = this.trailRenderer.sharedMaterial;
  21631. }
  21632. destroy(destroyChild = true) {
  21633. if (this.destroyed)
  21634. return;
  21635. super.destroy(destroyChild);
  21636. this._geometryFilter.destroy();
  21637. this._geometryFilter = null;
  21638. }
  21639. _create() {
  21640. return new TrailSprite3D();
  21641. }
  21642. }
  21643. class ShaderVariable {
  21644. constructor() {
  21645. this.textureID = -1;
  21646. }
  21647. }
  21648. class ShaderInstance extends Laya.Resource {
  21649. constructor(vs, ps, attributeMap, uniformMap, shaderPass) {
  21650. super();
  21651. this._stateParamsMap = [];
  21652. this._uploadMark = -1;
  21653. this._uploadRenderType = -1;
  21654. this._vs = vs;
  21655. this._ps = ps;
  21656. this._attributeMap = attributeMap;
  21657. this._uniformMap = uniformMap;
  21658. this._shaderPass = shaderPass;
  21659. this._create();
  21660. this.lock = true;
  21661. }
  21662. _create() {
  21663. var gl = Laya.LayaGL.instance;
  21664. this._program = gl.createProgram();
  21665. this._vshader = this._createShader(gl, this._vs, gl.VERTEX_SHADER);
  21666. this._pshader = this._createShader(gl, this._ps, gl.FRAGMENT_SHADER);
  21667. gl.attachShader(this._program, this._vshader);
  21668. gl.attachShader(this._program, this._pshader);
  21669. for (var k in this._attributeMap)
  21670. gl.bindAttribLocation(this._program, this._attributeMap[k], k);
  21671. gl.linkProgram(this._program);
  21672. if (!Laya.Render.isConchApp && Shader3D.debugMode && !gl.getProgramParameter(this._program, gl.LINK_STATUS))
  21673. throw gl.getProgramInfoLog(this._program);
  21674. var sceneParms = [];
  21675. var cameraParms = [];
  21676. var spriteParms = [];
  21677. var materialParms = [];
  21678. var customParms = [];
  21679. this._customUniformParamsMap = [];
  21680. var nUniformNum = gl.getProgramParameter(this._program, gl.ACTIVE_UNIFORMS);
  21681. Laya.WebGLContext.useProgram(gl, this._program);
  21682. this._curActTexIndex = 0;
  21683. var one, i, n;
  21684. for (i = 0; i < nUniformNum; i++) {
  21685. var uniformData = gl.getActiveUniform(this._program, i);
  21686. var uniName = uniformData.name;
  21687. one = new ShaderVariable();
  21688. one.location = gl.getUniformLocation(this._program, uniName);
  21689. if (uniName.indexOf('[0]') > 0) {
  21690. one.name = uniName = uniName.substr(0, uniName.length - 3);
  21691. one.isArray = true;
  21692. }
  21693. else {
  21694. one.name = uniName;
  21695. one.isArray = false;
  21696. }
  21697. one.type = uniformData.type;
  21698. this._addShaderUnifiormFun(one);
  21699. var uniformPeriod = this._uniformMap[uniName];
  21700. if (uniformPeriod != null) {
  21701. one.dataOffset = Shader3D.propertyNameToID(uniName);
  21702. switch (uniformPeriod) {
  21703. case Shader3D.PERIOD_CUSTOM:
  21704. customParms.push(one);
  21705. break;
  21706. case Shader3D.PERIOD_MATERIAL:
  21707. materialParms.push(one);
  21708. break;
  21709. case Shader3D.PERIOD_SPRITE:
  21710. spriteParms.push(one);
  21711. break;
  21712. case Shader3D.PERIOD_CAMERA:
  21713. cameraParms.push(one);
  21714. break;
  21715. case Shader3D.PERIOD_SCENE:
  21716. sceneParms.push(one);
  21717. break;
  21718. default:
  21719. throw new Error("Shader3D: period is unkonw.");
  21720. }
  21721. }
  21722. }
  21723. this._sceneUniformParamsMap = Laya.LayaGL.instance.createCommandEncoder(sceneParms.length * 4 * 5 + 4, 64, true);
  21724. for (i = 0, n = sceneParms.length; i < n; i++)
  21725. this._sceneUniformParamsMap.addShaderUniform(sceneParms[i]);
  21726. this._cameraUniformParamsMap = Laya.LayaGL.instance.createCommandEncoder(cameraParms.length * 4 * 5 + 4, 64, true);
  21727. for (i = 0, n = cameraParms.length; i < n; i++)
  21728. this._cameraUniformParamsMap.addShaderUniform(cameraParms[i]);
  21729. this._spriteUniformParamsMap = Laya.LayaGL.instance.createCommandEncoder(spriteParms.length * 4 * 5 + 4, 64, true);
  21730. for (i = 0, n = spriteParms.length; i < n; i++)
  21731. this._spriteUniformParamsMap.addShaderUniform(spriteParms[i]);
  21732. this._materialUniformParamsMap = Laya.LayaGL.instance.createCommandEncoder(materialParms.length * 4 * 5 + 4, 64, true);
  21733. for (i = 0, n = materialParms.length; i < n; i++)
  21734. this._materialUniformParamsMap.addShaderUniform(materialParms[i]);
  21735. this._customUniformParamsMap.length = customParms.length;
  21736. for (i = 0, n = customParms.length; i < n; i++) {
  21737. var custom = customParms[i];
  21738. this._customUniformParamsMap[custom.dataOffset] = custom;
  21739. }
  21740. var stateMap = this._shaderPass._stateMap;
  21741. for (var s in stateMap)
  21742. this._stateParamsMap[stateMap[s]] = Shader3D.propertyNameToID(s);
  21743. }
  21744. _getRenderState(shaderDatas, stateIndex) {
  21745. var stateID = this._stateParamsMap[stateIndex];
  21746. if (stateID == null)
  21747. return null;
  21748. else
  21749. return shaderDatas[stateID];
  21750. }
  21751. _disposeResource() {
  21752. Laya.LayaGL.instance.deleteShader(this._vshader);
  21753. Laya.LayaGL.instance.deleteShader(this._pshader);
  21754. Laya.LayaGL.instance.deleteProgram(this._program);
  21755. this._vshader = this._pshader = this._program = null;
  21756. this._setGPUMemory(0);
  21757. this._curActTexIndex = 0;
  21758. }
  21759. _addShaderUnifiormFun(one) {
  21760. var gl = Laya.LayaGL.instance;
  21761. one.caller = this;
  21762. var isArray = one.isArray;
  21763. switch (one.type) {
  21764. case gl.BOOL:
  21765. one.fun = this._uniform1i;
  21766. one.uploadedValue = new Array(1);
  21767. break;
  21768. case gl.INT:
  21769. one.fun = isArray ? this._uniform1iv : this._uniform1i;
  21770. one.uploadedValue = new Array(1);
  21771. break;
  21772. case gl.FLOAT:
  21773. one.fun = isArray ? this._uniform1fv : this._uniform1f;
  21774. one.uploadedValue = new Array(1);
  21775. break;
  21776. case gl.FLOAT_VEC2:
  21777. one.fun = isArray ? this._uniform_vec2v : this._uniform_vec2;
  21778. one.uploadedValue = new Array(2);
  21779. break;
  21780. case gl.FLOAT_VEC3:
  21781. one.fun = isArray ? this._uniform_vec3v : this._uniform_vec3;
  21782. one.uploadedValue = new Array(3);
  21783. break;
  21784. case gl.FLOAT_VEC4:
  21785. one.fun = isArray ? this._uniform_vec4v : this._uniform_vec4;
  21786. one.uploadedValue = new Array(4);
  21787. break;
  21788. case gl.FLOAT_MAT2:
  21789. one.fun = this._uniformMatrix2fv;
  21790. break;
  21791. case gl.FLOAT_MAT3:
  21792. one.fun = this._uniformMatrix3fv;
  21793. break;
  21794. case gl.FLOAT_MAT4:
  21795. one.fun = isArray ? this._uniformMatrix4fv : this._uniformMatrix4f;
  21796. break;
  21797. case gl.SAMPLER_2D:
  21798. gl.uniform1i(one.location, this._curActTexIndex);
  21799. one.textureID = Laya.WebGLContext._glTextureIDs[this._curActTexIndex++];
  21800. one.fun = this._uniform_sampler2D;
  21801. break;
  21802. case 0x8b5f:
  21803. gl.uniform1i(one.location, this._curActTexIndex);
  21804. one.textureID = Laya.WebGLContext._glTextureIDs[this._curActTexIndex++];
  21805. one.fun = this._uniform_sampler3D;
  21806. break;
  21807. case gl.SAMPLER_CUBE:
  21808. gl.uniform1i(one.location, this._curActTexIndex);
  21809. one.textureID = Laya.WebGLContext._glTextureIDs[this._curActTexIndex++];
  21810. one.fun = this._uniform_samplerCube;
  21811. break;
  21812. default:
  21813. throw new Error("compile shader err!");
  21814. break;
  21815. }
  21816. }
  21817. _createShader(gl, str, type) {
  21818. var shader = gl.createShader(type);
  21819. gl.shaderSource(shader, str);
  21820. gl.compileShader(shader);
  21821. if (Shader3D.debugMode && !gl.getShaderParameter(shader, gl.COMPILE_STATUS))
  21822. throw gl.getShaderInfoLog(shader);
  21823. return shader;
  21824. }
  21825. _uniform1f(one, value) {
  21826. var uploadedValue = one.uploadedValue;
  21827. if (uploadedValue[0] !== value) {
  21828. Laya.LayaGL.instance.uniform1f(one.location, uploadedValue[0] = value);
  21829. return 1;
  21830. }
  21831. return 0;
  21832. }
  21833. _uniform1fv(one, value) {
  21834. if (value.length < 4) {
  21835. var uploadedValue = one.uploadedValue;
  21836. if (uploadedValue[0] !== value[0] || uploadedValue[1] !== value[1] || uploadedValue[2] !== value[2] || uploadedValue[3] !== value[3]) {
  21837. Laya.LayaGL.instance.uniform1fv(one.location, value);
  21838. uploadedValue[0] = value[0];
  21839. uploadedValue[1] = value[1];
  21840. uploadedValue[2] = value[2];
  21841. uploadedValue[3] = value[3];
  21842. return 1;
  21843. }
  21844. return 0;
  21845. }
  21846. else {
  21847. Laya.LayaGL.instance.uniform1fv(one.location, value);
  21848. return 1;
  21849. }
  21850. }
  21851. _uniform_vec2(one, v) {
  21852. var uploadedValue = one.uploadedValue;
  21853. if (uploadedValue[0] !== v.x || uploadedValue[1] !== v.y) {
  21854. Laya.LayaGL.instance.uniform2f(one.location, uploadedValue[0] = v.x, uploadedValue[1] = v.y);
  21855. return 1;
  21856. }
  21857. return 0;
  21858. }
  21859. _uniform_vec2v(one, value) {
  21860. if (value.length < 2) {
  21861. var uploadedValue = one.uploadedValue;
  21862. if (uploadedValue[0] !== value[0] || uploadedValue[1] !== value[1] || uploadedValue[2] !== value[2] || uploadedValue[3] !== value[3]) {
  21863. Laya.LayaGL.instance.uniform2fv(one.location, value);
  21864. uploadedValue[0] = value[0];
  21865. uploadedValue[1] = value[1];
  21866. uploadedValue[2] = value[2];
  21867. uploadedValue[3] = value[3];
  21868. return 1;
  21869. }
  21870. return 0;
  21871. }
  21872. else {
  21873. Laya.LayaGL.instance.uniform2fv(one.location, value);
  21874. return 1;
  21875. }
  21876. }
  21877. _uniform_vec3(one, v) {
  21878. var uploadedValue = one.uploadedValue;
  21879. if (uploadedValue[0] !== v.x || uploadedValue[1] !== v.y || uploadedValue[2] !== v.z) {
  21880. Laya.LayaGL.instance.uniform3f(one.location, uploadedValue[0] = v.x, uploadedValue[1] = v.y, uploadedValue[2] = v.z);
  21881. return 1;
  21882. }
  21883. return 0;
  21884. }
  21885. _uniform_vec3v(one, v) {
  21886. Laya.LayaGL.instance.uniform3fv(one.location, v);
  21887. return 1;
  21888. }
  21889. _uniform_vec4(one, v) {
  21890. var uploadedValue = one.uploadedValue;
  21891. if (uploadedValue[0] !== v.x || uploadedValue[1] !== v.y || uploadedValue[2] !== v.z || uploadedValue[3] !== v.w) {
  21892. Laya.LayaGL.instance.uniform4f(one.location, uploadedValue[0] = v.x, uploadedValue[1] = v.y, uploadedValue[2] = v.z, uploadedValue[3] = v.w);
  21893. return 1;
  21894. }
  21895. return 0;
  21896. }
  21897. _uniform_vec4v(one, v) {
  21898. Laya.LayaGL.instance.uniform4fv(one.location, v);
  21899. return 1;
  21900. }
  21901. _uniformMatrix2fv(one, value) {
  21902. Laya.LayaGL.instance.uniformMatrix2fv(one.location, false, value);
  21903. return 1;
  21904. }
  21905. _uniformMatrix3fv(one, value) {
  21906. Laya.LayaGL.instance.uniformMatrix3fv(one.location, false, value);
  21907. return 1;
  21908. }
  21909. _uniformMatrix4f(one, m) {
  21910. var value = m.elements;
  21911. Laya.LayaGL.instance.uniformMatrix4fv(one.location, false, value);
  21912. return 1;
  21913. }
  21914. _uniformMatrix4fv(one, m) {
  21915. Laya.LayaGL.instance.uniformMatrix4fv(one.location, false, m);
  21916. return 1;
  21917. }
  21918. _uniform1i(one, value) {
  21919. var uploadedValue = one.uploadedValue;
  21920. if (uploadedValue[0] !== value) {
  21921. Laya.LayaGL.instance.uniform1i(one.location, uploadedValue[0] = value);
  21922. return 1;
  21923. }
  21924. return 0;
  21925. }
  21926. _uniform1iv(one, value) {
  21927. Laya.LayaGL.instance.uniform1iv(one.location, value);
  21928. return 1;
  21929. }
  21930. _uniform_ivec2(one, value) {
  21931. var uploadedValue = one.uploadedValue;
  21932. if (uploadedValue[0] !== value[0] || uploadedValue[1] !== value[1]) {
  21933. Laya.LayaGL.instance.uniform2i(one.location, uploadedValue[0] = value[0], uploadedValue[1] = value[1]);
  21934. return 1;
  21935. }
  21936. return 0;
  21937. }
  21938. _uniform_ivec2v(one, value) {
  21939. Laya.LayaGL.instance.uniform2iv(one.location, value);
  21940. return 1;
  21941. }
  21942. _uniform_vec3i(one, value) {
  21943. var uploadedValue = one.uploadedValue;
  21944. if (uploadedValue[0] !== value[0] || uploadedValue[1] !== value[1] || uploadedValue[2] !== value[2]) {
  21945. Laya.LayaGL.instance.uniform3i(one.location, uploadedValue[0] = value[0], uploadedValue[1] = value[1], uploadedValue[2] = value[2]);
  21946. return 1;
  21947. }
  21948. return 0;
  21949. }
  21950. _uniform_vec3vi(one, value) {
  21951. Laya.LayaGL.instance.uniform3iv(one.location, value);
  21952. return 1;
  21953. }
  21954. _uniform_vec4i(one, value) {
  21955. var uploadedValue = one.uploadedValue;
  21956. if (uploadedValue[0] !== value[0] || uploadedValue[1] !== value[1] || uploadedValue[2] !== value[2] || uploadedValue[3] !== value[3]) {
  21957. Laya.LayaGL.instance.uniform4i(one.location, uploadedValue[0] = value[0], uploadedValue[1] = value[1], uploadedValue[2] = value[2], uploadedValue[3] = value[3]);
  21958. return 1;
  21959. }
  21960. return 0;
  21961. }
  21962. _uniform_vec4vi(one, value) {
  21963. Laya.LayaGL.instance.uniform4iv(one.location, value);
  21964. return 1;
  21965. }
  21966. _uniform_sampler2D(one, texture) {
  21967. var value = texture._getSource() || texture.defaulteTexture._getSource();
  21968. var gl = Laya.LayaGL.instance;
  21969. Laya.WebGLContext.activeTexture(gl, one.textureID);
  21970. Laya.WebGLContext.bindTexture(gl, gl.TEXTURE_2D, value);
  21971. return 0;
  21972. }
  21973. _uniform_sampler3D(one, texture) {
  21974. var value = texture._getSource() || texture.defaulteTexture._getSource();
  21975. var gl = Laya.LayaGL.instance;
  21976. Laya.WebGLContext.activeTexture(gl, one.textureID);
  21977. Laya.WebGLContext.bindTexture(gl, WebGL2RenderingContext.TEXTURE_3D, value);
  21978. return 0;
  21979. }
  21980. _uniform_samplerCube(one, texture) {
  21981. var value = texture._getSource() || texture.defaulteTexture._getSource();
  21982. var gl = Laya.LayaGL.instance;
  21983. Laya.WebGLContext.activeTexture(gl, one.textureID);
  21984. Laya.WebGLContext.bindTexture(gl, gl.TEXTURE_CUBE_MAP, value);
  21985. return 0;
  21986. }
  21987. bind() {
  21988. return Laya.WebGLContext.useProgram(Laya.LayaGL.instance, this._program);
  21989. }
  21990. uploadUniforms(shaderUniform, shaderDatas, uploadUnTexture) {
  21991. Laya.Stat.shaderCall += Laya.LayaGLRunner.uploadShaderUniforms(Laya.LayaGL.instance, shaderUniform, shaderDatas, uploadUnTexture);
  21992. }
  21993. uploadRenderStateBlendDepth(shaderDatas) {
  21994. var gl = Laya.LayaGL.instance;
  21995. var renderState = this._shaderPass.renderState;
  21996. var datas = shaderDatas.getData();
  21997. var depthWrite = this._getRenderState(datas, Shader3D.RENDER_STATE_DEPTH_WRITE);
  21998. var depthTest = this._getRenderState(datas, Shader3D.RENDER_STATE_DEPTH_TEST);
  21999. var blend = this._getRenderState(datas, Shader3D.RENDER_STATE_BLEND);
  22000. depthWrite == null && (depthWrite = renderState.depthWrite);
  22001. depthTest == null && (depthTest = renderState.depthTest);
  22002. blend == null && (blend = renderState.blend);
  22003. Laya.WebGLContext.setDepthMask(gl, depthWrite);
  22004. if (depthTest === RenderState.DEPTHTEST_OFF)
  22005. Laya.WebGLContext.setDepthTest(gl, false);
  22006. else {
  22007. Laya.WebGLContext.setDepthTest(gl, true);
  22008. Laya.WebGLContext.setDepthFunc(gl, depthTest);
  22009. }
  22010. switch (blend) {
  22011. case RenderState.BLEND_DISABLE:
  22012. Laya.WebGLContext.setBlend(gl, false);
  22013. break;
  22014. case RenderState.BLEND_ENABLE_ALL:
  22015. Laya.WebGLContext.setBlend(gl, true);
  22016. var srcBlend = this._getRenderState(datas, Shader3D.RENDER_STATE_BLEND_SRC);
  22017. srcBlend == null && (srcBlend = renderState.srcBlend);
  22018. var dstBlend = this._getRenderState(datas, Shader3D.RENDER_STATE_BLEND_DST);
  22019. dstBlend == null && (dstBlend = renderState.dstBlend);
  22020. Laya.WebGLContext.setBlendFunc(gl, srcBlend, dstBlend);
  22021. break;
  22022. case RenderState.BLEND_ENABLE_SEPERATE:
  22023. Laya.WebGLContext.setBlend(gl, true);
  22024. var srcRGB = this._getRenderState(datas, Shader3D.RENDER_STATE_BLEND_SRC_RGB);
  22025. srcRGB == null && (srcRGB = renderState.srcBlendRGB);
  22026. var dstRGB = this._getRenderState(datas, Shader3D.RENDER_STATE_BLEND_DST_RGB);
  22027. dstRGB == null && (dstRGB = renderState.dstBlendRGB);
  22028. var srcAlpha = this._getRenderState(datas, Shader3D.RENDER_STATE_BLEND_SRC_ALPHA);
  22029. srcAlpha == null && (srcAlpha = renderState.srcBlendAlpha);
  22030. var dstAlpha = this._getRenderState(datas, Shader3D.RENDER_STATE_BLEND_DST_ALPHA);
  22031. dstAlpha == null && (dstAlpha = renderState.dstBlendAlpha);
  22032. Laya.WebGLContext.setBlendFuncSeperate(gl, srcRGB, dstRGB, srcAlpha, dstAlpha);
  22033. break;
  22034. }
  22035. }
  22036. uploadRenderStateFrontFace(shaderDatas, isTarget, invertFront) {
  22037. var gl = Laya.LayaGL.instance;
  22038. var renderState = this._shaderPass.renderState;
  22039. var datas = shaderDatas.getData();
  22040. var cull = this._getRenderState(datas, Shader3D.RENDER_STATE_CULL);
  22041. cull == null && (cull = renderState.cull);
  22042. var forntFace;
  22043. switch (cull) {
  22044. case RenderState.CULL_NONE:
  22045. Laya.WebGLContext.setCullFace(gl, false);
  22046. break;
  22047. case RenderState.CULL_FRONT:
  22048. Laya.WebGLContext.setCullFace(gl, true);
  22049. if (isTarget) {
  22050. if (invertFront)
  22051. forntFace = gl.CCW;
  22052. else
  22053. forntFace = gl.CW;
  22054. }
  22055. else {
  22056. if (invertFront)
  22057. forntFace = gl.CW;
  22058. else
  22059. forntFace = gl.CCW;
  22060. }
  22061. Laya.WebGLContext.setFrontFace(gl, forntFace);
  22062. break;
  22063. case RenderState.CULL_BACK:
  22064. Laya.WebGLContext.setCullFace(gl, true);
  22065. if (isTarget) {
  22066. if (invertFront)
  22067. forntFace = gl.CW;
  22068. else
  22069. forntFace = gl.CCW;
  22070. }
  22071. else {
  22072. if (invertFront)
  22073. forntFace = gl.CCW;
  22074. else
  22075. forntFace = gl.CW;
  22076. }
  22077. Laya.WebGLContext.setFrontFace(gl, forntFace);
  22078. break;
  22079. }
  22080. }
  22081. uploadCustomUniform(index, data) {
  22082. Laya.Stat.shaderCall += Laya.LayaGLRunner.uploadCustomUniform(Laya.LayaGL.instance, this._customUniformParamsMap, index, data);
  22083. }
  22084. _uniformMatrix2fvForNative(one, value) {
  22085. Laya.LayaGL.instance.uniformMatrix2fvEx(one.location, false, value);
  22086. return 1;
  22087. }
  22088. _uniformMatrix3fvForNative(one, value) {
  22089. Laya.LayaGL.instance.uniformMatrix3fvEx(one.location, false, value);
  22090. return 1;
  22091. }
  22092. _uniformMatrix4fvForNative(one, m) {
  22093. Laya.LayaGL.instance.uniformMatrix4fvEx(one.location, false, m);
  22094. return 1;
  22095. }
  22096. }
  22097. class ShaderPass extends Laya.ShaderCompile {
  22098. constructor(owner, vs, ps, stateMap) {
  22099. super(vs, ps, null);
  22100. this._renderState = new RenderState();
  22101. this._owner = owner;
  22102. this._cacheSharders = [];
  22103. this._publicValidDefine = 0;
  22104. this._spriteValidDefine = 0;
  22105. this._materialValidDefine = 0;
  22106. var publicDefineMap = this._owner._publicDefinesMap;
  22107. var spriteDefineMap = this._owner._spriteDefinesMap;
  22108. var materialDefineMap = this._owner._materialDefinesMap;
  22109. for (var k in this.defs) {
  22110. if (publicDefineMap[k] != null)
  22111. this._publicValidDefine |= publicDefineMap[k];
  22112. else if (spriteDefineMap[k] != null)
  22113. this._spriteValidDefine |= spriteDefineMap[k];
  22114. else if (materialDefineMap[k] != null)
  22115. this._materialValidDefine |= materialDefineMap[k];
  22116. }
  22117. this._stateMap = stateMap;
  22118. }
  22119. get renderState() {
  22120. return this._renderState;
  22121. }
  22122. _definesToNameDic(value, int2Name) {
  22123. var o = {};
  22124. var d = 1;
  22125. for (var i = 0; i < 32; i++) {
  22126. d = 1 << i;
  22127. if (d > value)
  22128. break;
  22129. if (value & d) {
  22130. var name = int2Name[d];
  22131. o[name] = "";
  22132. }
  22133. }
  22134. return o;
  22135. }
  22136. _compileToTree(parent, lines, start, includefiles, defs) {
  22137. var node, preNode;
  22138. var text, name, fname;
  22139. var ofs, words, noUseNode;
  22140. var i, n, j;
  22141. for (i = start; i < lines.length; i++) {
  22142. text = lines[i];
  22143. if (text.length < 1)
  22144. continue;
  22145. ofs = text.indexOf("//");
  22146. if (ofs === 0)
  22147. continue;
  22148. if (ofs >= 0)
  22149. text = text.substr(0, ofs);
  22150. node = noUseNode || new Laya.ShaderNode(includefiles);
  22151. noUseNode = null;
  22152. node.text = text;
  22153. if ((ofs = text.indexOf("#")) >= 0) {
  22154. name = "#";
  22155. for (j = ofs + 1, n = text.length; j < n; j++) {
  22156. var c = text.charAt(j);
  22157. if (c === ' ' || c === '\t' || c === '?')
  22158. break;
  22159. name += c;
  22160. }
  22161. node.name = name;
  22162. switch (name) {
  22163. case "#ifdef":
  22164. case "#ifndef":
  22165. node.setParent(parent);
  22166. parent = node;
  22167. if (defs) {
  22168. words = text.substr(j).split(Laya.ShaderCompile._splitToWordExps3);
  22169. for (j = 0; j < words.length; j++) {
  22170. text = words[j];
  22171. text.length && (defs[text] = true);
  22172. }
  22173. }
  22174. continue;
  22175. case "#if":
  22176. case "#elif":
  22177. node.setParent(parent);
  22178. parent = node;
  22179. if (defs) {
  22180. words = text.substr(j).split(Laya.ShaderCompile._splitToWordExps3);
  22181. for (j = 0; j < words.length; j++) {
  22182. text = words[j];
  22183. text.length && text != "defined" && (defs[text] = true);
  22184. }
  22185. }
  22186. continue;
  22187. case "#else":
  22188. parent = parent.parent;
  22189. preNode = parent.childs[parent.childs.length - 1];
  22190. node.setParent(parent);
  22191. parent = node;
  22192. continue;
  22193. case "#endif":
  22194. parent = parent.parent;
  22195. preNode = parent.childs[parent.childs.length - 1];
  22196. node.setParent(parent);
  22197. continue;
  22198. case "#include":
  22199. words = Laya.ShaderCompile.splitToWords(text, null);
  22200. var inlcudeFile = Laya.ShaderCompile.includes[words[1]];
  22201. if (!inlcudeFile) {
  22202. throw "ShaderCompile error no this include file:" + words[1];
  22203. }
  22204. if ((ofs = words[0].indexOf("?")) < 0) {
  22205. node.setParent(parent);
  22206. text = inlcudeFile.getWith(words[2] == 'with' ? words[3] : null);
  22207. this._compileToTree(node, text.split('\n'), 0, includefiles, defs);
  22208. node.text = "";
  22209. continue;
  22210. }
  22211. node.setCondition(words[0].substr(ofs + 1), Laya.ShaderCompile.IFDEF_YES);
  22212. node.text = inlcudeFile.getWith(words[2] == 'with' ? words[3] : null);
  22213. break;
  22214. case "#import":
  22215. words = Laya.ShaderCompile.splitToWords(text, null);
  22216. fname = words[1];
  22217. includefiles.push({ node: node, file: Laya.ShaderCompile.includes[fname], ofs: node.text.length });
  22218. continue;
  22219. }
  22220. }
  22221. else {
  22222. preNode = parent.childs[parent.childs.length - 1];
  22223. if (preNode && !preNode.name) {
  22224. includefiles.length > 0 && Laya.ShaderCompile.splitToWords(text, preNode);
  22225. noUseNode = node;
  22226. preNode.text += "\n" + text;
  22227. continue;
  22228. }
  22229. includefiles.length > 0 && Laya.ShaderCompile.splitToWords(text, node);
  22230. }
  22231. node.setParent(parent);
  22232. }
  22233. }
  22234. withCompile(publicDefine, spriteDefine, materialDefine) {
  22235. publicDefine &= this._publicValidDefine;
  22236. spriteDefine &= this._spriteValidDefine;
  22237. materialDefine &= this._materialValidDefine;
  22238. var shader;
  22239. var spriteDefShaders, materialDefShaders;
  22240. spriteDefShaders = this._cacheSharders[publicDefine];
  22241. if (spriteDefShaders) {
  22242. materialDefShaders = spriteDefShaders[spriteDefine];
  22243. if (materialDefShaders) {
  22244. shader = materialDefShaders[materialDefine];
  22245. if (shader)
  22246. return shader;
  22247. }
  22248. else {
  22249. materialDefShaders = spriteDefShaders[spriteDefine] = [];
  22250. }
  22251. }
  22252. else {
  22253. spriteDefShaders = this._cacheSharders[publicDefine] = [];
  22254. materialDefShaders = spriteDefShaders[spriteDefine] = [];
  22255. }
  22256. var publicDefGroup = this._definesToNameDic(publicDefine, this._owner._publicDefines);
  22257. var spriteDefGroup = this._definesToNameDic(spriteDefine, this._owner._spriteDefines);
  22258. var materialDefGroup = this._definesToNameDic(materialDefine, this._owner._materialDefines);
  22259. var key;
  22260. if (Shader3D.debugMode) {
  22261. var publicDefGroupStr = "";
  22262. for (key in publicDefGroup)
  22263. publicDefGroupStr += key + " ";
  22264. var spriteDefGroupStr = "";
  22265. for (key in spriteDefGroup)
  22266. spriteDefGroupStr += key + " ";
  22267. var materialDefGroupStr = "";
  22268. for (key in materialDefGroup)
  22269. materialDefGroupStr += key + " ";
  22270. if (!Laya.WebGL.shaderHighPrecision)
  22271. publicDefine += Shader3D.SHADERDEFINE_HIGHPRECISION;
  22272. 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");
  22273. }
  22274. var defMap = {};
  22275. var defineStr = "";
  22276. if (publicDefGroup) {
  22277. for (key in publicDefGroup) {
  22278. defineStr += "#define " + key + "\n";
  22279. defMap[key] = true;
  22280. }
  22281. }
  22282. if (spriteDefGroup) {
  22283. for (key in spriteDefGroup) {
  22284. defineStr += "#define " + key + "\n";
  22285. defMap[key] = true;
  22286. }
  22287. }
  22288. if (materialDefGroup) {
  22289. for (key in materialDefGroup) {
  22290. defineStr += "#define " + key + "\n";
  22291. defMap[key] = true;
  22292. }
  22293. }
  22294. var vs = this._VS.toscript(defMap, []);
  22295. var vsVersion = '';
  22296. if (vs[0].indexOf('#version') == 0) {
  22297. vsVersion = vs[0] + '\n';
  22298. vs.shift();
  22299. }
  22300. var ps = this._PS.toscript(defMap, []);
  22301. var psVersion = '';
  22302. if (ps[0].indexOf('#version') == 0) {
  22303. psVersion = ps[0] + '\n';
  22304. ps.shift();
  22305. }
  22306. 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);
  22307. materialDefShaders[materialDefine] = shader;
  22308. return shader;
  22309. }
  22310. }
  22311. class SubShader {
  22312. constructor(attributeMap, uniformMap, spriteDefines = null, materialDefines = null) {
  22313. this._flags = {};
  22314. this._passes = [];
  22315. this._publicDefines = [];
  22316. this._publicDefinesMap = {};
  22317. this._spriteDefines = [];
  22318. this._spriteDefinesMap = {};
  22319. this._materialDefines = [];
  22320. this._materialDefinesMap = {};
  22321. this._addDefines(this._publicDefines, this._publicDefinesMap, Shader3D._globleDefines);
  22322. (spriteDefines) && (this._addDefines(this._spriteDefines, this._spriteDefinesMap, spriteDefines.defines));
  22323. (materialDefines) && (this._addDefines(this._materialDefines, this._materialDefinesMap, materialDefines.defines));
  22324. this._attributeMap = attributeMap;
  22325. this._uniformMap = uniformMap;
  22326. }
  22327. _addDefines(defines, definesMap, supportDefines) {
  22328. for (var k in supportDefines) {
  22329. var name = supportDefines[k];
  22330. var i = parseInt(k);
  22331. defines[i] = name;
  22332. definesMap[name] = i;
  22333. }
  22334. }
  22335. getMaterialDefineByName(name) {
  22336. return this._materialDefinesMap[name];
  22337. }
  22338. setFlag(key, value) {
  22339. if (value)
  22340. this._flags[key] = value;
  22341. else
  22342. delete this._flags[key];
  22343. }
  22344. getFlag(key) {
  22345. return this._flags[key];
  22346. }
  22347. addShaderPass(vs, ps, stateMap = null) {
  22348. var shaderPass = new ShaderPass(this, vs, ps, stateMap);
  22349. this._passes.push(shaderPass);
  22350. return shaderPass;
  22351. }
  22352. }
  22353. 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";
  22354. 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}";
  22355. 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";
  22356. 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}";
  22357. 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";
  22358. 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}";
  22359. 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";
  22360. 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";
  22361. 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}";
  22362. 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";
  22363. 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}";
  22364. 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}";
  22365. 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";
  22366. 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}";
  22367. 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";
  22368. 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";
  22369. 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";
  22370. 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";
  22371. 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}";
  22372. 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}";
  22373. 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}";
  22374. 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}";
  22375. 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}";
  22376. 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}";
  22377. 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}";
  22378. 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}";
  22379. 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}";
  22380. 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}";
  22381. 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}";
  22382. 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}";
  22383. 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}";
  22384. 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}";
  22385. 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}";
  22386. 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}";
  22387. 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";
  22388. 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";
  22389. 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";
  22390. 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";
  22391. 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 ";
  22392. 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";
  22393. 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";
  22394. 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}";
  22395. 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";
  22396. 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}";
  22397. class ShaderInit3D {
  22398. constructor() {
  22399. }
  22400. static __init__() {
  22401. ShaderInit3D._rangeAttenTex = Utils3D._buildTexture2D(1024, 1, Laya.BaseTexture.FORMAT_ALPHA8, TextureGenerator.lightAttenTexture);
  22402. ShaderInit3D._rangeAttenTex.wrapModeU = Laya.BaseTexture.WARPMODE_CLAMP;
  22403. ShaderInit3D._rangeAttenTex.wrapModeV = Laya.BaseTexture.WARPMODE_CLAMP;
  22404. ShaderInit3D._rangeAttenTex.lock = true;
  22405. Shader3D.SHADERDEFINE_HIGHPRECISION = Shader3D.registerPublicDefine("HIGHPRECISION");
  22406. Shader3D.addInclude("Lighting.glsl", LightingGLSL);
  22407. Shader3D.addInclude("ShadowHelper.glsl", ShadowHelperGLSL);
  22408. Shader3D.addInclude("BRDF.glsl", BRDFGLSL);
  22409. Shader3D.addInclude("PBRUtils.glsl", PBRUtilsGLSL);
  22410. Shader3D.addInclude("PBRStandardLighting.glsl", PBRStandardLightingGLSL);
  22411. Shader3D.addInclude("PBRSpecularLighting.glsl", PBRSpecularLightingGLSL);
  22412. Shader3D.addInclude("Colors.glsl", ColorsGLSL);
  22413. Shader3D.addInclude("Sampling.glsl", SamplingGLSL);
  22414. Shader3D.addInclude("StdLib.glsl", StdLibGLSL);
  22415. var attributeMap = {
  22416. 'a_Position': VertexMesh.MESH_POSITION0,
  22417. 'a_Color': VertexMesh.MESH_COLOR0,
  22418. 'a_Normal': VertexMesh.MESH_NORMAL0,
  22419. 'a_Texcoord0': VertexMesh.MESH_TEXTURECOORDINATE0,
  22420. 'a_Texcoord1': VertexMesh.MESH_TEXTURECOORDINATE1,
  22421. 'a_BoneWeights': VertexMesh.MESH_BLENDWEIGHT0,
  22422. 'a_BoneIndices': VertexMesh.MESH_BLENDINDICES0,
  22423. 'a_Tangent0': VertexMesh.MESH_TANGENT0,
  22424. 'a_MvpMatrix': VertexMesh.MESH_MVPMATRIX_ROW0,
  22425. 'a_WorldMat': VertexMesh.MESH_WORLDMATRIX_ROW0
  22426. };
  22427. var uniformMap = {
  22428. 'u_Bones': Shader3D.PERIOD_CUSTOM,
  22429. 'u_DiffuseTexture': Shader3D.PERIOD_MATERIAL,
  22430. 'u_SpecularTexture': Shader3D.PERIOD_MATERIAL,
  22431. 'u_NormalTexture': Shader3D.PERIOD_MATERIAL,
  22432. 'u_AlphaTestValue': Shader3D.PERIOD_MATERIAL,
  22433. 'u_DiffuseColor': Shader3D.PERIOD_MATERIAL,
  22434. 'u_MaterialSpecular': Shader3D.PERIOD_MATERIAL,
  22435. 'u_Shininess': Shader3D.PERIOD_MATERIAL,
  22436. 'u_TilingOffset': Shader3D.PERIOD_MATERIAL,
  22437. 'u_WorldMat': Shader3D.PERIOD_SPRITE,
  22438. 'u_MvpMatrix': Shader3D.PERIOD_SPRITE,
  22439. 'u_LightmapScaleOffset': Shader3D.PERIOD_SPRITE,
  22440. 'u_LightMap': Shader3D.PERIOD_SPRITE,
  22441. 'u_CameraPos': Shader3D.PERIOD_CAMERA,
  22442. 'u_ReflectTexture': Shader3D.PERIOD_SCENE,
  22443. 'u_ReflectIntensity': Shader3D.PERIOD_SCENE,
  22444. 'u_FogStart': Shader3D.PERIOD_SCENE,
  22445. 'u_FogRange': Shader3D.PERIOD_SCENE,
  22446. 'u_FogColor': Shader3D.PERIOD_SCENE,
  22447. 'u_DirectionLight.Color': Shader3D.PERIOD_SCENE,
  22448. 'u_DirectionLight.Direction': Shader3D.PERIOD_SCENE,
  22449. 'u_PointLight.Position': Shader3D.PERIOD_SCENE,
  22450. 'u_PointLight.Range': Shader3D.PERIOD_SCENE,
  22451. 'u_PointLight.Color': Shader3D.PERIOD_SCENE,
  22452. 'u_SpotLight.Position': Shader3D.PERIOD_SCENE,
  22453. 'u_SpotLight.Direction': Shader3D.PERIOD_SCENE,
  22454. 'u_SpotLight.Range': Shader3D.PERIOD_SCENE,
  22455. 'u_SpotLight.Spot': Shader3D.PERIOD_SCENE,
  22456. 'u_SpotLight.Color': Shader3D.PERIOD_SCENE,
  22457. 'u_AmbientColor': Shader3D.PERIOD_SCENE,
  22458. 'u_shadowMap1': Shader3D.PERIOD_SCENE,
  22459. 'u_shadowMap2': Shader3D.PERIOD_SCENE,
  22460. 'u_shadowMap3': Shader3D.PERIOD_SCENE,
  22461. 'u_shadowPSSMDistance': Shader3D.PERIOD_SCENE,
  22462. 'u_lightShadowVP': Shader3D.PERIOD_SCENE,
  22463. 'u_shadowPCFoffset': Shader3D.PERIOD_SCENE
  22464. };
  22465. var stateMap = {
  22466. 's_Cull': Shader3D.RENDER_STATE_CULL,
  22467. 's_Blend': Shader3D.RENDER_STATE_BLEND,
  22468. 's_BlendSrc': Shader3D.RENDER_STATE_BLEND_SRC,
  22469. 's_BlendDst': Shader3D.RENDER_STATE_BLEND_DST,
  22470. 's_DepthTest': Shader3D.RENDER_STATE_DEPTH_TEST,
  22471. 's_DepthWrite': Shader3D.RENDER_STATE_DEPTH_WRITE
  22472. };
  22473. var shader = Shader3D.add("BLINNPHONG", null, null, true);
  22474. var subShader = new SubShader(attributeMap, uniformMap, SkinnedMeshSprite3D.shaderDefines, BlinnPhongMaterial.shaderDefines);
  22475. shader.addSubShader(subShader);
  22476. subShader.addShaderPass(MeshBlinnPhongVS, MeshBlinnPhongPS, stateMap);
  22477. attributeMap = {
  22478. 'a_Position': VertexMesh.MESH_POSITION0,
  22479. 'a_Color': VertexMesh.MESH_COLOR0
  22480. };
  22481. uniformMap = {
  22482. 'u_MvpMatrix': Shader3D.PERIOD_SPRITE,
  22483. 'u_Color': Shader3D.PERIOD_MATERIAL
  22484. };
  22485. stateMap = {
  22486. 's_Cull': Shader3D.RENDER_STATE_CULL,
  22487. 's_Blend': Shader3D.RENDER_STATE_BLEND,
  22488. 's_BlendSrc': Shader3D.RENDER_STATE_BLEND_SRC,
  22489. 's_BlendDst': Shader3D.RENDER_STATE_BLEND_DST,
  22490. 's_DepthTest': Shader3D.RENDER_STATE_DEPTH_TEST,
  22491. 's_DepthWrite': Shader3D.RENDER_STATE_DEPTH_WRITE
  22492. };
  22493. shader = Shader3D.add("LineShader");
  22494. subShader = new SubShader(attributeMap, uniformMap);
  22495. shader.addSubShader(subShader);
  22496. subShader.addShaderPass(lineVS, linePS, stateMap);
  22497. attributeMap = {
  22498. 'a_Position': VertexMesh.MESH_POSITION0,
  22499. 'a_Normal': VertexMesh.MESH_NORMAL0,
  22500. 'a_Tangent0': VertexMesh.MESH_TANGENT0,
  22501. 'a_Texcoord0': VertexMesh.MESH_TEXTURECOORDINATE0,
  22502. 'a_BoneWeights': VertexMesh.MESH_BLENDWEIGHT0,
  22503. 'a_BoneIndices': VertexMesh.MESH_BLENDINDICES0,
  22504. 'a_MvpMatrix': VertexMesh.MESH_MVPMATRIX_ROW0,
  22505. 'a_WorldMat': VertexMesh.MESH_WORLDMATRIX_ROW0
  22506. };
  22507. uniformMap = {
  22508. 'u_Bones': Shader3D.PERIOD_CUSTOM,
  22509. 'u_MvpMatrix': Shader3D.PERIOD_SPRITE,
  22510. 'u_WorldMat': Shader3D.PERIOD_SPRITE,
  22511. 'u_CameraPos': Shader3D.PERIOD_CAMERA,
  22512. 'u_AlphaTestValue': Shader3D.PERIOD_MATERIAL,
  22513. 'u_AlbedoColor': Shader3D.PERIOD_MATERIAL,
  22514. 'u_EmissionColor': Shader3D.PERIOD_MATERIAL,
  22515. 'u_AlbedoTexture': Shader3D.PERIOD_MATERIAL,
  22516. 'u_NormalTexture': Shader3D.PERIOD_MATERIAL,
  22517. 'u_ParallaxTexture': Shader3D.PERIOD_MATERIAL,
  22518. 'u_MetallicGlossTexture': Shader3D.PERIOD_MATERIAL,
  22519. 'u_OcclusionTexture': Shader3D.PERIOD_MATERIAL,
  22520. 'u_EmissionTexture': Shader3D.PERIOD_MATERIAL,
  22521. 'u_metallic': Shader3D.PERIOD_MATERIAL,
  22522. 'u_smoothness': Shader3D.PERIOD_MATERIAL,
  22523. 'u_smoothnessScale': Shader3D.PERIOD_MATERIAL,
  22524. 'u_occlusionStrength': Shader3D.PERIOD_MATERIAL,
  22525. 'u_normalScale': Shader3D.PERIOD_MATERIAL,
  22526. 'u_parallaxScale': Shader3D.PERIOD_MATERIAL,
  22527. 'u_TilingOffset': Shader3D.PERIOD_MATERIAL,
  22528. 'u_DirectionLight.Direction': Shader3D.PERIOD_SCENE,
  22529. 'u_DirectionLight.Color': Shader3D.PERIOD_SCENE,
  22530. 'u_PointLightMatrix': Shader3D.PERIOD_SCENE,
  22531. 'u_PointLight.Position': Shader3D.PERIOD_SCENE,
  22532. 'u_PointLight.Range': Shader3D.PERIOD_SCENE,
  22533. 'u_PointLight.Color': Shader3D.PERIOD_SCENE,
  22534. 'u_SpotLight.Position': Shader3D.PERIOD_SCENE,
  22535. 'u_SpotLight.Direction': Shader3D.PERIOD_SCENE,
  22536. 'u_SpotLight.Range': Shader3D.PERIOD_SCENE,
  22537. 'u_SpotLight.SpotAngle': Shader3D.PERIOD_SCENE,
  22538. 'u_SpotLight.Color': Shader3D.PERIOD_SCENE,
  22539. 'u_RangeTexture': Shader3D.PERIOD_SCENE,
  22540. 'u_ReflectTexture': Shader3D.PERIOD_SCENE,
  22541. 'u_ReflectIntensity': Shader3D.PERIOD_SCENE,
  22542. 'u_AmbientColor': Shader3D.PERIOD_SCENE,
  22543. 'u_shadowMap1': Shader3D.PERIOD_SCENE,
  22544. 'u_shadowMap2': Shader3D.PERIOD_SCENE,
  22545. 'u_shadowMap3': Shader3D.PERIOD_SCENE,
  22546. 'u_shadowPSSMDistance': Shader3D.PERIOD_SCENE,
  22547. 'u_lightShadowVP': Shader3D.PERIOD_SCENE,
  22548. 'u_shadowPCFoffset': Shader3D.PERIOD_SCENE,
  22549. 'u_FogStart': Shader3D.PERIOD_SCENE,
  22550. 'u_FogRange': Shader3D.PERIOD_SCENE,
  22551. 'u_FogColor': Shader3D.PERIOD_SCENE
  22552. };
  22553. stateMap = {
  22554. 's_Cull': Shader3D.RENDER_STATE_CULL,
  22555. 's_Blend': Shader3D.RENDER_STATE_BLEND,
  22556. 's_BlendSrc': Shader3D.RENDER_STATE_BLEND_SRC,
  22557. 's_BlendDst': Shader3D.RENDER_STATE_BLEND_DST,
  22558. 's_DepthTest': Shader3D.RENDER_STATE_DEPTH_TEST,
  22559. 's_DepthWrite': Shader3D.RENDER_STATE_DEPTH_WRITE
  22560. };
  22561. shader = Shader3D.add("PBRStandard", null, null, true);
  22562. subShader = new SubShader(attributeMap, uniformMap, SkinnedMeshSprite3D.shaderDefines, PBRStandardMaterial.shaderDefines);
  22563. shader.addSubShader(subShader);
  22564. subShader.addShaderPass(PBRStandardVS, PBRStandardPS, stateMap);
  22565. attributeMap = {
  22566. 'a_Position': VertexMesh.MESH_POSITION0,
  22567. 'a_Normal': VertexMesh.MESH_NORMAL0,
  22568. 'a_Tangent0': VertexMesh.MESH_TANGENT0,
  22569. 'a_Texcoord0': VertexMesh.MESH_TEXTURECOORDINATE0,
  22570. 'a_BoneWeights': VertexMesh.MESH_BLENDWEIGHT0,
  22571. 'a_BoneIndices': VertexMesh.MESH_BLENDINDICES0,
  22572. 'a_MvpMatrix': VertexMesh.MESH_MVPMATRIX_ROW0,
  22573. 'a_WorldMat': VertexMesh.MESH_WORLDMATRIX_ROW0
  22574. };
  22575. uniformMap = {
  22576. 'u_Bones': Shader3D.PERIOD_CUSTOM,
  22577. 'u_MvpMatrix': Shader3D.PERIOD_SPRITE,
  22578. 'u_WorldMat': Shader3D.PERIOD_SPRITE,
  22579. 'u_CameraPos': Shader3D.PERIOD_CAMERA,
  22580. 'u_AlphaTestValue': Shader3D.PERIOD_MATERIAL,
  22581. 'u_AlbedoColor': Shader3D.PERIOD_MATERIAL,
  22582. 'u_SpecularColor': Shader3D.PERIOD_MATERIAL,
  22583. 'u_EmissionColor': Shader3D.PERIOD_MATERIAL,
  22584. 'u_AlbedoTexture': Shader3D.PERIOD_MATERIAL,
  22585. 'u_NormalTexture': Shader3D.PERIOD_MATERIAL,
  22586. 'u_ParallaxTexture': Shader3D.PERIOD_MATERIAL,
  22587. 'u_SpecularTexture': Shader3D.PERIOD_MATERIAL,
  22588. 'u_OcclusionTexture': Shader3D.PERIOD_MATERIAL,
  22589. 'u_EmissionTexture': Shader3D.PERIOD_MATERIAL,
  22590. 'u_smoothness': Shader3D.PERIOD_MATERIAL,
  22591. 'u_smoothnessScale': Shader3D.PERIOD_MATERIAL,
  22592. 'u_occlusionStrength': Shader3D.PERIOD_MATERIAL,
  22593. 'u_normalScale': Shader3D.PERIOD_MATERIAL,
  22594. 'u_parallaxScale': Shader3D.PERIOD_MATERIAL,
  22595. 'u_TilingOffset': Shader3D.PERIOD_MATERIAL,
  22596. 'u_DirectionLight.Direction': Shader3D.PERIOD_SCENE,
  22597. 'u_DirectionLight.Color': Shader3D.PERIOD_SCENE,
  22598. 'u_PointLightMatrix': Shader3D.PERIOD_SCENE,
  22599. 'u_PointLight.Position': Shader3D.PERIOD_SCENE,
  22600. 'u_PointLight.Range': Shader3D.PERIOD_SCENE,
  22601. 'u_PointLight.Color': Shader3D.PERIOD_SCENE,
  22602. 'u_SpotLight.Position': Shader3D.PERIOD_SCENE,
  22603. 'u_SpotLight.Direction': Shader3D.PERIOD_SCENE,
  22604. 'u_SpotLight.Range': Shader3D.PERIOD_SCENE,
  22605. 'u_SpotLight.SpotAngle': Shader3D.PERIOD_SCENE,
  22606. 'u_SpotLight.Color': Shader3D.PERIOD_SCENE,
  22607. 'u_RangeTexture': Shader3D.PERIOD_SCENE,
  22608. 'u_ReflectTexture': Shader3D.PERIOD_SCENE,
  22609. 'u_ReflectIntensity': Shader3D.PERIOD_SCENE,
  22610. 'u_AmbientColor': Shader3D.PERIOD_SCENE,
  22611. 'u_shadowMap1': Shader3D.PERIOD_SCENE,
  22612. 'u_shadowMap2': Shader3D.PERIOD_SCENE,
  22613. 'u_shadowMap3': Shader3D.PERIOD_SCENE,
  22614. 'u_shadowPSSMDistance': Shader3D.PERIOD_SCENE,
  22615. 'u_lightShadowVP': Shader3D.PERIOD_SCENE,
  22616. 'u_shadowPCFoffset': Shader3D.PERIOD_SCENE,
  22617. 'u_FogStart': Shader3D.PERIOD_SCENE,
  22618. 'u_FogRange': Shader3D.PERIOD_SCENE,
  22619. 'u_FogColor': Shader3D.PERIOD_SCENE
  22620. };
  22621. stateMap = {
  22622. 's_Cull': Shader3D.RENDER_STATE_CULL,
  22623. 's_Blend': Shader3D.RENDER_STATE_BLEND,
  22624. 's_BlendSrc': Shader3D.RENDER_STATE_BLEND_SRC,
  22625. 's_BlendDst': Shader3D.RENDER_STATE_BLEND_DST,
  22626. 's_DepthTest': Shader3D.RENDER_STATE_DEPTH_TEST,
  22627. 's_DepthWrite': Shader3D.RENDER_STATE_DEPTH_WRITE
  22628. };
  22629. shader = Shader3D.add("PBRSpecular", null, null, true);
  22630. subShader = new SubShader(attributeMap, uniformMap, SkinnedMeshSprite3D.shaderDefines, PBRSpecularMaterial.shaderDefines);
  22631. shader.addSubShader(subShader);
  22632. subShader.addShaderPass(PBRSpecularVS, PBRSpecularPS, stateMap);
  22633. attributeMap = {
  22634. 'a_Position': VertexMesh.MESH_POSITION0,
  22635. 'a_Color': VertexMesh.MESH_COLOR0,
  22636. 'a_Texcoord0': VertexMesh.MESH_TEXTURECOORDINATE0,
  22637. 'a_BoneWeights': VertexMesh.MESH_BLENDWEIGHT0,
  22638. 'a_BoneIndices': VertexMesh.MESH_BLENDINDICES0,
  22639. 'a_MvpMatrix': VertexMesh.MESH_MVPMATRIX_ROW0
  22640. };
  22641. uniformMap = {
  22642. 'u_Bones': Shader3D.PERIOD_CUSTOM,
  22643. 'u_AlbedoTexture': Shader3D.PERIOD_MATERIAL,
  22644. 'u_AlbedoColor': Shader3D.PERIOD_MATERIAL,
  22645. 'u_TilingOffset': Shader3D.PERIOD_MATERIAL,
  22646. 'u_AlphaTestValue': Shader3D.PERIOD_MATERIAL,
  22647. 'u_MvpMatrix': Shader3D.PERIOD_SPRITE,
  22648. 'u_FogStart': Shader3D.PERIOD_SCENE,
  22649. 'u_FogRange': Shader3D.PERIOD_SCENE,
  22650. 'u_FogColor': Shader3D.PERIOD_SCENE
  22651. };
  22652. stateMap = {
  22653. 's_Cull': Shader3D.RENDER_STATE_CULL,
  22654. 's_Blend': Shader3D.RENDER_STATE_BLEND,
  22655. 's_BlendSrc': Shader3D.RENDER_STATE_BLEND_SRC,
  22656. 's_BlendDst': Shader3D.RENDER_STATE_BLEND_DST,
  22657. 's_DepthTest': Shader3D.RENDER_STATE_DEPTH_TEST,
  22658. 's_DepthWrite': Shader3D.RENDER_STATE_DEPTH_WRITE
  22659. };
  22660. shader = Shader3D.add("Unlit", null, null, true);
  22661. subShader = new SubShader(attributeMap, uniformMap, SkinnedMeshSprite3D.shaderDefines, UnlitMaterial.shaderDefines);
  22662. shader.addSubShader(subShader);
  22663. subShader.addShaderPass(UnlitVS, UnlitPS, stateMap);
  22664. attributeMap = {
  22665. 'a_Position': VertexMesh.MESH_POSITION0,
  22666. 'a_Texcoord0': VertexMesh.MESH_TEXTURECOORDINATE0,
  22667. 'a_BoneWeights': VertexMesh.MESH_BLENDWEIGHT0,
  22668. 'a_BoneIndices': VertexMesh.MESH_BLENDINDICES0,
  22669. 'a_MvpMatrix': VertexMesh.MESH_MVPMATRIX_ROW0
  22670. };
  22671. uniformMap = {
  22672. 'u_Bones': Shader3D.PERIOD_CUSTOM,
  22673. 'u_AlbedoTexture': Shader3D.PERIOD_MATERIAL,
  22674. 'u_AlbedoColor': Shader3D.PERIOD_MATERIAL,
  22675. 'u_TilingOffset': Shader3D.PERIOD_MATERIAL,
  22676. 'u_AlphaTestValue': Shader3D.PERIOD_MATERIAL,
  22677. 'u_MvpMatrix': Shader3D.PERIOD_SPRITE,
  22678. 'u_FogStart': Shader3D.PERIOD_SCENE,
  22679. 'u_FogRange': Shader3D.PERIOD_SCENE,
  22680. 'u_FogColor': Shader3D.PERIOD_SCENE
  22681. };
  22682. stateMap = {
  22683. 's_Cull': Shader3D.RENDER_STATE_CULL,
  22684. 's_Blend': Shader3D.RENDER_STATE_BLEND,
  22685. 's_BlendSrc': Shader3D.RENDER_STATE_BLEND_SRC,
  22686. 's_BlendDst': Shader3D.RENDER_STATE_BLEND_DST,
  22687. 's_DepthTest': Shader3D.RENDER_STATE_DEPTH_TEST,
  22688. 's_DepthWrite': Shader3D.RENDER_STATE_DEPTH_WRITE
  22689. };
  22690. shader = Shader3D.add("Effect", null, null, true);
  22691. subShader = new SubShader(attributeMap, uniformMap, SkinnedMeshSprite3D.shaderDefines, EffectMaterial.shaderDefines);
  22692. shader.addSubShader(subShader);
  22693. subShader.addShaderPass(EffectVS, EffectPS, stateMap);
  22694. attributeMap = {
  22695. 'a_CornerTextureCoordinate': VertexShuriKenParticle.PARTICLE_CORNERTEXTURECOORDINATE0,
  22696. 'a_MeshPosition': VertexShuriKenParticle.PARTICLE_POSITION0,
  22697. 'a_MeshColor': VertexShuriKenParticle.PARTICLE_COLOR0,
  22698. 'a_MeshTextureCoordinate': VertexShuriKenParticle.PARTICLE_TEXTURECOORDINATE0,
  22699. 'a_ShapePositionStartLifeTime': VertexShuriKenParticle.PARTICLE_SHAPEPOSITIONSTARTLIFETIME,
  22700. 'a_DirectionTime': VertexShuriKenParticle.PARTICLE_DIRECTIONTIME,
  22701. 'a_StartColor': VertexShuriKenParticle.PARTICLE_STARTCOLOR0,
  22702. 'a_EndColor': VertexShuriKenParticle.PARTICLE_ENDCOLOR0,
  22703. 'a_StartSize': VertexShuriKenParticle.PARTICLE_STARTSIZE,
  22704. 'a_StartRotation0': VertexShuriKenParticle.PARTICLE_STARTROTATION,
  22705. 'a_StartSpeed': VertexShuriKenParticle.PARTICLE_STARTSPEED,
  22706. 'a_Random0': VertexShuriKenParticle.PARTICLE_RANDOM0,
  22707. 'a_Random1': VertexShuriKenParticle.PARTICLE_RANDOM1,
  22708. 'a_SimulationWorldPostion': VertexShuriKenParticle.PARTICLE_SIMULATIONWORLDPOSTION,
  22709. 'a_SimulationWorldRotation': VertexShuriKenParticle.PARTICLE_SIMULATIONWORLDROTATION
  22710. };
  22711. uniformMap = {
  22712. 'u_Tintcolor': Shader3D.PERIOD_MATERIAL,
  22713. 'u_TilingOffset': Shader3D.PERIOD_MATERIAL,
  22714. 'u_texture': Shader3D.PERIOD_MATERIAL,
  22715. 'u_WorldPosition': Shader3D.PERIOD_SPRITE,
  22716. 'u_WorldRotation': Shader3D.PERIOD_SPRITE,
  22717. 'u_PositionScale': Shader3D.PERIOD_SPRITE,
  22718. 'u_SizeScale': Shader3D.PERIOD_SPRITE,
  22719. 'u_ScalingMode': Shader3D.PERIOD_SPRITE,
  22720. 'u_Gravity': Shader3D.PERIOD_SPRITE,
  22721. 'u_ThreeDStartRotation': Shader3D.PERIOD_SPRITE,
  22722. 'u_StretchedBillboardLengthScale': Shader3D.PERIOD_SPRITE,
  22723. 'u_StretchedBillboardSpeedScale': Shader3D.PERIOD_SPRITE,
  22724. 'u_SimulationSpace': Shader3D.PERIOD_SPRITE,
  22725. 'u_CurrentTime': Shader3D.PERIOD_SPRITE,
  22726. 'u_ColorOverLifeGradientAlphas': Shader3D.PERIOD_SPRITE,
  22727. 'u_ColorOverLifeGradientColors': Shader3D.PERIOD_SPRITE,
  22728. 'u_MaxColorOverLifeGradientAlphas': Shader3D.PERIOD_SPRITE,
  22729. 'u_MaxColorOverLifeGradientColors': Shader3D.PERIOD_SPRITE,
  22730. 'u_VOLVelocityConst': Shader3D.PERIOD_SPRITE,
  22731. 'u_VOLVelocityGradientX': Shader3D.PERIOD_SPRITE,
  22732. 'u_VOLVelocityGradientY': Shader3D.PERIOD_SPRITE,
  22733. 'u_VOLVelocityGradientZ': Shader3D.PERIOD_SPRITE,
  22734. 'u_VOLVelocityConstMax': Shader3D.PERIOD_SPRITE,
  22735. 'u_VOLVelocityGradientMaxX': Shader3D.PERIOD_SPRITE,
  22736. 'u_VOLVelocityGradientMaxY': Shader3D.PERIOD_SPRITE,
  22737. 'u_VOLVelocityGradientMaxZ': Shader3D.PERIOD_SPRITE,
  22738. 'u_VOLSpaceType': Shader3D.PERIOD_SPRITE,
  22739. 'u_SOLSizeGradient': Shader3D.PERIOD_SPRITE,
  22740. 'u_SOLSizeGradientX': Shader3D.PERIOD_SPRITE,
  22741. 'u_SOLSizeGradientY': Shader3D.PERIOD_SPRITE,
  22742. 'u_SOLSizeGradientZ': Shader3D.PERIOD_SPRITE,
  22743. 'u_SOLSizeGradientMax': Shader3D.PERIOD_SPRITE,
  22744. 'u_SOLSizeGradientMaxX': Shader3D.PERIOD_SPRITE,
  22745. 'u_SOLSizeGradientMaxY': Shader3D.PERIOD_SPRITE,
  22746. 'u_SOLSizeGradientMaxZ': Shader3D.PERIOD_SPRITE,
  22747. 'u_ROLAngularVelocityConst': Shader3D.PERIOD_SPRITE,
  22748. 'u_ROLAngularVelocityConstSeprarate': Shader3D.PERIOD_SPRITE,
  22749. 'u_ROLAngularVelocityGradient': Shader3D.PERIOD_SPRITE,
  22750. 'u_ROLAngularVelocityGradientX': Shader3D.PERIOD_SPRITE,
  22751. 'u_ROLAngularVelocityGradientY': Shader3D.PERIOD_SPRITE,
  22752. 'u_ROLAngularVelocityGradientZ': Shader3D.PERIOD_SPRITE,
  22753. 'u_ROLAngularVelocityConstMax': Shader3D.PERIOD_SPRITE,
  22754. 'u_ROLAngularVelocityConstMaxSeprarate': Shader3D.PERIOD_SPRITE,
  22755. 'u_ROLAngularVelocityGradientMax': Shader3D.PERIOD_SPRITE,
  22756. 'u_ROLAngularVelocityGradientMaxX': Shader3D.PERIOD_SPRITE,
  22757. 'u_ROLAngularVelocityGradientMaxY': Shader3D.PERIOD_SPRITE,
  22758. 'u_ROLAngularVelocityGradientMaxZ': Shader3D.PERIOD_SPRITE,
  22759. 'u_ROLAngularVelocityGradientMaxW': Shader3D.PERIOD_SPRITE,
  22760. 'u_TSACycles': Shader3D.PERIOD_SPRITE,
  22761. 'u_TSASubUVLength': Shader3D.PERIOD_SPRITE,
  22762. 'u_TSAGradientUVs': Shader3D.PERIOD_SPRITE,
  22763. 'u_TSAMaxGradientUVs': Shader3D.PERIOD_SPRITE,
  22764. 'u_CameraPos': Shader3D.PERIOD_CAMERA,
  22765. 'u_CameraDirection': Shader3D.PERIOD_CAMERA,
  22766. 'u_CameraUp': Shader3D.PERIOD_CAMERA,
  22767. 'u_View': Shader3D.PERIOD_CAMERA,
  22768. 'u_Projection': Shader3D.PERIOD_CAMERA,
  22769. 'u_FogStart': Shader3D.PERIOD_SCENE,
  22770. 'u_FogRange': Shader3D.PERIOD_SCENE,
  22771. 'u_FogColor': Shader3D.PERIOD_SCENE
  22772. };
  22773. stateMap = {
  22774. 's_Cull': Shader3D.RENDER_STATE_CULL,
  22775. 's_Blend': Shader3D.RENDER_STATE_BLEND,
  22776. 's_BlendSrc': Shader3D.RENDER_STATE_BLEND_SRC,
  22777. 's_BlendDst': Shader3D.RENDER_STATE_BLEND_DST,
  22778. 's_DepthTest': Shader3D.RENDER_STATE_DEPTH_TEST,
  22779. 's_DepthWrite': Shader3D.RENDER_STATE_DEPTH_WRITE
  22780. };
  22781. shader = Shader3D.add("PARTICLESHURIKEN");
  22782. subShader = new SubShader(attributeMap, uniformMap, ShuriKenParticle3D.shaderDefines, ShurikenParticleMaterial.shaderDefines);
  22783. shader.addSubShader(subShader);
  22784. subShader.addShaderPass(ParticleShuriKenVS, ParticleShuriKenPS, stateMap);
  22785. attributeMap = {
  22786. 'a_Position': VertexMesh.MESH_POSITION0
  22787. };
  22788. uniformMap = {
  22789. 'u_TintColor': Shader3D.PERIOD_MATERIAL,
  22790. 'u_Exposure': Shader3D.PERIOD_MATERIAL,
  22791. 'u_Rotation': Shader3D.PERIOD_MATERIAL,
  22792. 'u_CubeTexture': Shader3D.PERIOD_MATERIAL,
  22793. 'u_ViewProjection': Shader3D.PERIOD_CAMERA
  22794. };
  22795. shader = Shader3D.add("SkyBox");
  22796. subShader = new SubShader(attributeMap, uniformMap);
  22797. shader.addSubShader(subShader);
  22798. subShader.addShaderPass(SkyBoxVS, SkyBoxPS);
  22799. attributeMap = {
  22800. 'a_Position': VertexMesh.MESH_POSITION0
  22801. };
  22802. uniformMap = {
  22803. 'u_SunSize': Shader3D.PERIOD_MATERIAL,
  22804. 'u_SunSizeConvergence': Shader3D.PERIOD_MATERIAL,
  22805. 'u_AtmosphereThickness': Shader3D.PERIOD_MATERIAL,
  22806. 'u_SkyTint': Shader3D.PERIOD_MATERIAL,
  22807. 'u_GroundTint': Shader3D.PERIOD_MATERIAL,
  22808. 'u_Exposure': Shader3D.PERIOD_MATERIAL,
  22809. 'u_ViewProjection': Shader3D.PERIOD_CAMERA,
  22810. 'u_DirectionLight.Direction': Shader3D.PERIOD_SCENE,
  22811. 'u_DirectionLight.Color': Shader3D.PERIOD_SCENE
  22812. };
  22813. shader = Shader3D.add("SkyBoxProcedural");
  22814. subShader = new SubShader(attributeMap, uniformMap, null, SkyProceduralMaterial.shaderDefines);
  22815. shader.addSubShader(subShader);
  22816. subShader.addShaderPass(SkyBoxProceduralVS, SkyBoxProceduralPS);
  22817. attributeMap = {
  22818. 'a_Position': VertexMesh.MESH_POSITION0,
  22819. 'a_Normal': VertexMesh.MESH_NORMAL0,
  22820. 'a_Texcoord0': VertexMesh.MESH_TEXTURECOORDINATE0
  22821. };
  22822. uniformMap = {
  22823. 'u_MvpMatrix': Shader3D.PERIOD_SPRITE,
  22824. 'u_WorldMat': Shader3D.PERIOD_SPRITE,
  22825. 'u_CameraPos': Shader3D.PERIOD_CAMERA,
  22826. 'u_LightmapScaleOffset': Shader3D.PERIOD_SPRITE,
  22827. 'u_LightMap': Shader3D.PERIOD_SPRITE,
  22828. 'u_SplatAlphaTexture': Shader3D.PERIOD_MATERIAL,
  22829. 'u_DiffuseTexture1': Shader3D.PERIOD_MATERIAL,
  22830. 'u_DiffuseTexture2': Shader3D.PERIOD_MATERIAL,
  22831. 'u_DiffuseTexture3': Shader3D.PERIOD_MATERIAL,
  22832. 'u_DiffuseTexture4': Shader3D.PERIOD_MATERIAL,
  22833. 'u_DiffuseTexture5': Shader3D.PERIOD_MATERIAL,
  22834. 'u_DiffuseScaleOffset1': Shader3D.PERIOD_MATERIAL,
  22835. 'u_DiffuseScaleOffset2': Shader3D.PERIOD_MATERIAL,
  22836. 'u_DiffuseScaleOffset3': Shader3D.PERIOD_MATERIAL,
  22837. 'u_DiffuseScaleOffset4': Shader3D.PERIOD_MATERIAL,
  22838. 'u_DiffuseScaleOffset5': Shader3D.PERIOD_MATERIAL,
  22839. 'u_FogStart': Shader3D.PERIOD_SCENE,
  22840. 'u_FogRange': Shader3D.PERIOD_SCENE,
  22841. 'u_FogColor': Shader3D.PERIOD_SCENE,
  22842. 'u_DirectionLight.Direction': Shader3D.PERIOD_SCENE,
  22843. 'u_DirectionLight.Color': Shader3D.PERIOD_SCENE,
  22844. 'u_PointLight.Position': Shader3D.PERIOD_SCENE,
  22845. 'u_PointLight.Range': Shader3D.PERIOD_SCENE,
  22846. 'u_PointLight.Attenuation': Shader3D.PERIOD_SCENE,
  22847. 'u_PointLight.Color': Shader3D.PERIOD_SCENE,
  22848. 'u_SpotLight.Position': Shader3D.PERIOD_SCENE,
  22849. 'u_SpotLight.Direction': Shader3D.PERIOD_SCENE,
  22850. 'u_SpotLight.Range': Shader3D.PERIOD_SCENE,
  22851. 'u_SpotLight.Spot': Shader3D.PERIOD_SCENE,
  22852. 'u_SpotLight.Color': Shader3D.PERIOD_SCENE,
  22853. 'u_AmbientColor': Shader3D.PERIOD_SCENE,
  22854. 'u_shadowMap1': Shader3D.PERIOD_SCENE,
  22855. 'u_shadowMap2': Shader3D.PERIOD_SCENE,
  22856. 'u_shadowMap3': Shader3D.PERIOD_SCENE,
  22857. 'u_shadowPSSMDistance': Shader3D.PERIOD_SCENE,
  22858. 'u_lightShadowVP': Shader3D.PERIOD_SCENE,
  22859. 'u_shadowPCFoffset': Shader3D.PERIOD_SCENE
  22860. };
  22861. stateMap = {
  22862. 's_Cull': Shader3D.RENDER_STATE_CULL,
  22863. 's_Blend': Shader3D.RENDER_STATE_BLEND,
  22864. 's_BlendSrc': Shader3D.RENDER_STATE_BLEND_SRC,
  22865. 's_BlendDst': Shader3D.RENDER_STATE_BLEND_DST,
  22866. 's_DepthTest': Shader3D.RENDER_STATE_DEPTH_TEST,
  22867. 's_DepthWrite': Shader3D.RENDER_STATE_DEPTH_WRITE
  22868. };
  22869. shader = Shader3D.add("ExtendTerrain");
  22870. subShader = new SubShader(attributeMap, uniformMap, RenderableSprite3D.shaderDefines, ExtendTerrainMaterial.shaderDefines);
  22871. shader.addSubShader(subShader);
  22872. subShader.addShaderPass(extendTerrainVS, extendTerrainPS, stateMap);
  22873. attributeMap = {
  22874. 'a_Position': VertexTrail.TRAIL_POSITION0,
  22875. 'a_OffsetVector': VertexTrail.TRAIL_OFFSETVECTOR,
  22876. 'a_Texcoord0X': VertexTrail.TRAIL_TEXTURECOORDINATE0X,
  22877. 'a_Texcoord0Y': VertexTrail.TRAIL_TEXTURECOORDINATE0Y,
  22878. 'a_BirthTime': VertexTrail.TRAIL_TIME0,
  22879. 'a_Color': VertexTrail.TRAIL_COLOR
  22880. };
  22881. uniformMap = {
  22882. 'u_MvpMatrix': Shader3D.PERIOD_SPRITE,
  22883. 'u_View': Shader3D.PERIOD_CAMERA,
  22884. 'u_Projection': Shader3D.PERIOD_CAMERA,
  22885. 'u_TilingOffset': Shader3D.PERIOD_MATERIAL,
  22886. 'u_MainTexture': Shader3D.PERIOD_MATERIAL,
  22887. 'u_MainColor': Shader3D.PERIOD_MATERIAL,
  22888. 'u_CurTime': Shader3D.PERIOD_SPRITE,
  22889. 'u_LifeTime': Shader3D.PERIOD_SPRITE,
  22890. 'u_WidthCurve': Shader3D.PERIOD_SPRITE,
  22891. 'u_WidthCurveKeyLength': Shader3D.PERIOD_SPRITE,
  22892. 'u_GradientColorkey': Shader3D.PERIOD_SPRITE,
  22893. 'u_GradientAlphakey': Shader3D.PERIOD_SPRITE
  22894. };
  22895. stateMap = {
  22896. 's_Cull': Shader3D.RENDER_STATE_CULL,
  22897. 's_Blend': Shader3D.RENDER_STATE_BLEND,
  22898. 's_BlendSrc': Shader3D.RENDER_STATE_BLEND_SRC,
  22899. 's_BlendDst': Shader3D.RENDER_STATE_BLEND_DST,
  22900. 's_DepthTest': Shader3D.RENDER_STATE_DEPTH_TEST,
  22901. 's_DepthWrite': Shader3D.RENDER_STATE_DEPTH_WRITE
  22902. };
  22903. shader = Shader3D.add("Trail");
  22904. subShader = new SubShader(attributeMap, uniformMap, TrailSprite3D.shaderDefines, TrailMaterial.shaderDefines);
  22905. shader.addSubShader(subShader);
  22906. subShader.addShaderPass(TrailVS, TrailPS, stateMap);
  22907. attributeMap = {
  22908. 'a_Position': VertexMesh.MESH_POSITION0,
  22909. 'a_Normal': VertexMesh.MESH_NORMAL0,
  22910. 'a_Tangent0': VertexMesh.MESH_TANGENT0
  22911. };
  22912. uniformMap = {
  22913. 'u_MvpMatrix': Shader3D.PERIOD_SPRITE,
  22914. 'u_WorldMat': Shader3D.PERIOD_SPRITE,
  22915. 'u_CameraPos': Shader3D.PERIOD_CAMERA,
  22916. 'u_Time': Shader3D.PERIOD_SCENE,
  22917. 'u_MainTexture': Shader3D.PERIOD_MATERIAL,
  22918. 'u_NormalTexture': Shader3D.PERIOD_MATERIAL,
  22919. 'u_HorizonColor': Shader3D.PERIOD_MATERIAL,
  22920. 'u_WaveScale': Shader3D.PERIOD_MATERIAL,
  22921. 'u_WaveSpeed': Shader3D.PERIOD_MATERIAL
  22922. };
  22923. shader = Shader3D.add("WaterPrimary");
  22924. subShader = new SubShader(attributeMap, uniformMap, null, WaterPrimaryMaterial.shaderDefines);
  22925. shader.addSubShader(subShader);
  22926. subShader.addShaderPass(WaterPrimaryVS, WaterPrimaryPS);
  22927. attributeMap = {
  22928. 'a_PositionTexcoord': VertexMesh.MESH_POSITION0
  22929. };
  22930. uniformMap = {
  22931. 'u_MainTex': Shader3D.PERIOD_MATERIAL
  22932. };
  22933. shader = Shader3D.add("BlitScreen");
  22934. subShader = new SubShader(attributeMap, uniformMap, null, null);
  22935. shader.addSubShader(subShader);
  22936. var shaderPass = subShader.addShaderPass(BlitScreenVS, BlitScreenPS);
  22937. var renderState = shaderPass.renderState;
  22938. renderState.depthTest = RenderState.DEPTHTEST_ALWAYS;
  22939. renderState.depthWrite = false;
  22940. renderState.cull = RenderState.CULL_NONE;
  22941. renderState.blend = RenderState.BLEND_DISABLE;
  22942. attributeMap = {
  22943. 'a_PositionTexcoord': VertexMesh.MESH_POSITION0
  22944. };
  22945. uniformMap = {
  22946. 'u_MainTex': Shader3D.PERIOD_MATERIAL,
  22947. 'u_BloomTex': Shader3D.PERIOD_MATERIAL,
  22948. 'u_AutoExposureTex': Shader3D.PERIOD_MATERIAL,
  22949. 'u_MainTex_TexelSize': Shader3D.PERIOD_MATERIAL,
  22950. 'u_SampleScale': Shader3D.PERIOD_MATERIAL,
  22951. 'u_Threshold': Shader3D.PERIOD_MATERIAL,
  22952. 'u_Params': Shader3D.PERIOD_MATERIAL
  22953. };
  22954. shader = Shader3D.add("PostProcessBloom", attributeMap, uniformMap);
  22955. subShader = new SubShader(null, null, null, null);
  22956. shader.addSubShader(subShader);
  22957. shaderPass = subShader.addShaderPass(BloomVS, BloomPrefilter13PS);
  22958. renderState = shaderPass.renderState;
  22959. renderState.depthTest = RenderState.DEPTHTEST_ALWAYS;
  22960. renderState.depthWrite = false;
  22961. renderState.cull = RenderState.CULL_NONE;
  22962. renderState.blend = RenderState.BLEND_DISABLE;
  22963. subShader = new SubShader(null, null, null, null);
  22964. shader.addSubShader(subShader);
  22965. shaderPass = subShader.addShaderPass(BloomVS, BloomPrefilter4PS);
  22966. renderState = shaderPass.renderState;
  22967. renderState.depthTest = RenderState.DEPTHTEST_ALWAYS;
  22968. renderState.depthWrite = false;
  22969. renderState.cull = RenderState.CULL_NONE;
  22970. renderState.blend = RenderState.BLEND_DISABLE;
  22971. subShader = new SubShader(null, null, null, null);
  22972. shader.addSubShader(subShader);
  22973. shaderPass = subShader.addShaderPass(BloomVS, BloomDownsample13PS);
  22974. renderState = shaderPass.renderState;
  22975. renderState.depthTest = RenderState.DEPTHTEST_ALWAYS;
  22976. renderState.depthWrite = false;
  22977. renderState.cull = RenderState.CULL_NONE;
  22978. renderState.blend = RenderState.BLEND_DISABLE;
  22979. subShader = new SubShader(null, null, null, null);
  22980. shader.addSubShader(subShader);
  22981. shaderPass = subShader.addShaderPass(BloomVS, BloomDownsample4PS);
  22982. renderState = shaderPass.renderState;
  22983. renderState.depthTest = RenderState.DEPTHTEST_ALWAYS;
  22984. renderState.depthWrite = false;
  22985. renderState.cull = RenderState.CULL_NONE;
  22986. renderState.blend = RenderState.BLEND_DISABLE;
  22987. subShader = new SubShader(null, null, null, null);
  22988. shader.addSubShader(subShader);
  22989. shaderPass = subShader.addShaderPass(BloomVS, BloomUpsampleTentPS);
  22990. renderState = shaderPass.renderState;
  22991. renderState.depthTest = RenderState.DEPTHTEST_ALWAYS;
  22992. renderState.depthWrite = false;
  22993. renderState.cull = RenderState.CULL_NONE;
  22994. renderState.blend = RenderState.BLEND_DISABLE;
  22995. subShader = new SubShader(null, null, null, null);
  22996. shader.addSubShader(subShader);
  22997. shaderPass = subShader.addShaderPass(BloomVS, BloomUpsampleBoxPS);
  22998. renderState = shaderPass.renderState;
  22999. renderState.depthTest = RenderState.DEPTHTEST_ALWAYS;
  23000. renderState.depthWrite = false;
  23001. renderState.cull = RenderState.CULL_NONE;
  23002. renderState.blend = RenderState.BLEND_DISABLE;
  23003. attributeMap = {
  23004. 'a_PositionTexcoord': VertexMesh.MESH_POSITION0
  23005. };
  23006. uniformMap = {
  23007. 'u_MainTex': Shader3D.PERIOD_MATERIAL,
  23008. 'u_BloomTex': Shader3D.PERIOD_MATERIAL,
  23009. 'u_AutoExposureTex': Shader3D.PERIOD_MATERIAL,
  23010. 'u_Bloom_DirtTileOffset': Shader3D.PERIOD_MATERIAL,
  23011. 'u_Bloom_DirtTex': Shader3D.PERIOD_MATERIAL,
  23012. 'u_BloomTex_TexelSize': Shader3D.PERIOD_MATERIAL,
  23013. 'u_Bloom_Settings': Shader3D.PERIOD_MATERIAL,
  23014. 'u_Bloom_Color': Shader3D.PERIOD_MATERIAL
  23015. };
  23016. shader = Shader3D.add("PostProcessComposite", attributeMap, uniformMap);
  23017. subShader = new SubShader(null, null, null, PostProcess.shaderDefines);
  23018. shader.addSubShader(subShader);
  23019. shaderPass = subShader.addShaderPass(CompositeVS, CompositePS);
  23020. renderState = shaderPass.renderState;
  23021. renderState.depthTest = RenderState.DEPTHTEST_ALWAYS;
  23022. renderState.depthWrite = false;
  23023. renderState.cull = RenderState.CULL_NONE;
  23024. renderState.blend = RenderState.BLEND_DISABLE;
  23025. }
  23026. }
  23027. class PixelLineMaterial extends BaseMaterial {
  23028. constructor() {
  23029. super();
  23030. this.setShaderName("LineShader");
  23031. this._shaderValues.setVector(PixelLineMaterial.COLOR, new Vector4(1.0, 1.0, 1.0, 1.0));
  23032. }
  23033. static __initDefine__() {
  23034. PixelLineMaterial.shaderDefines = new ShaderDefines(BaseMaterial.shaderDefines);
  23035. }
  23036. get color() {
  23037. return this._shaderValues.getVector(PixelLineMaterial.COLOR);
  23038. }
  23039. set color(value) {
  23040. this._shaderValues.setVector(PixelLineMaterial.COLOR, value);
  23041. }
  23042. set depthWrite(value) {
  23043. this._shaderValues.setBool(PixelLineMaterial.DEPTH_WRITE, value);
  23044. }
  23045. get depthWrite() {
  23046. return this._shaderValues.getBool(PixelLineMaterial.DEPTH_WRITE);
  23047. }
  23048. set cull(value) {
  23049. this._shaderValues.setInt(PixelLineMaterial.CULL, value);
  23050. }
  23051. get cull() {
  23052. return this._shaderValues.getInt(PixelLineMaterial.CULL);
  23053. }
  23054. set blend(value) {
  23055. this._shaderValues.setInt(PixelLineMaterial.BLEND, value);
  23056. }
  23057. get blend() {
  23058. return this._shaderValues.getInt(PixelLineMaterial.BLEND);
  23059. }
  23060. set blendSrc(value) {
  23061. this._shaderValues.setInt(PixelLineMaterial.BLEND_SRC, value);
  23062. }
  23063. get blendSrc() {
  23064. return this._shaderValues.getInt(PixelLineMaterial.BLEND_SRC);
  23065. }
  23066. set blendDst(value) {
  23067. this._shaderValues.setInt(PixelLineMaterial.BLEND_DST, value);
  23068. }
  23069. get blendDst() {
  23070. return this._shaderValues.getInt(PixelLineMaterial.BLEND_DST);
  23071. }
  23072. set depthTest(value) {
  23073. this._shaderValues.setInt(PixelLineMaterial.DEPTH_TEST, value);
  23074. }
  23075. get depthTest() {
  23076. return this._shaderValues.getInt(PixelLineMaterial.DEPTH_TEST);
  23077. }
  23078. clone() {
  23079. var dest = new PixelLineMaterial();
  23080. this.cloneTo(dest);
  23081. return dest;
  23082. }
  23083. }
  23084. PixelLineMaterial.COLOR = Shader3D.propertyNameToID("u_Color");
  23085. PixelLineMaterial.shaderDefines = null;
  23086. PixelLineMaterial.CULL = Shader3D.propertyNameToID("s_Cull");
  23087. PixelLineMaterial.BLEND = Shader3D.propertyNameToID("s_Blend");
  23088. PixelLineMaterial.BLEND_SRC = Shader3D.propertyNameToID("s_BlendSrc");
  23089. PixelLineMaterial.BLEND_DST = Shader3D.propertyNameToID("s_BlendDst");
  23090. PixelLineMaterial.DEPTH_TEST = Shader3D.propertyNameToID("s_DepthTest");
  23091. PixelLineMaterial.DEPTH_WRITE = Shader3D.propertyNameToID("s_DepthWrite");
  23092. class PixelLineVertex {
  23093. static get vertexDeclaration() {
  23094. return PixelLineVertex._vertexDeclaration;
  23095. }
  23096. static __init__() {
  23097. PixelLineVertex._vertexDeclaration = new VertexDeclaration(28, [new VertexElement(0, VertexElementFormat.Vector3, VertexMesh.MESH_POSITION0),
  23098. new VertexElement(12, VertexElementFormat.Vector4, VertexMesh.MESH_COLOR0)]);
  23099. }
  23100. get vertexDeclaration() {
  23101. return PixelLineVertex._vertexDeclaration;
  23102. }
  23103. constructor() {
  23104. }
  23105. }
  23106. class PixelLineFilter extends GeometryElement {
  23107. constructor(owner, maxLineCount) {
  23108. super();
  23109. this._floatCountPerVertices = 7;
  23110. this._minUpdate = Number.MAX_VALUE;
  23111. this._maxUpdate = Number.MIN_VALUE;
  23112. this._bufferState = new BufferState();
  23113. this._maxLineCount = 0;
  23114. this._lineCount = 0;
  23115. var pointCount = maxLineCount * 2;
  23116. this._owner = owner;
  23117. this._maxLineCount = maxLineCount;
  23118. this._vertices = new Float32Array(pointCount * this._floatCountPerVertices);
  23119. this._vertexBuffer = new VertexBuffer3D(PixelLineVertex.vertexDeclaration.vertexStride * pointCount, Laya.LayaGL.instance.STATIC_DRAW, false);
  23120. this._vertexBuffer.vertexDeclaration = PixelLineVertex.vertexDeclaration;
  23121. this._bufferState.bind();
  23122. this._bufferState.applyVertexBuffer(this._vertexBuffer);
  23123. this._bufferState.unBind();
  23124. }
  23125. _getType() {
  23126. return PixelLineFilter._type;
  23127. }
  23128. _resizeLineData(maxCount) {
  23129. var pointCount = maxCount * 2;
  23130. var lastVertices = this._vertices;
  23131. this._vertexBuffer.destroy();
  23132. this._maxLineCount = maxCount;
  23133. var vertexCount = pointCount * this._floatCountPerVertices;
  23134. this._vertices = new Float32Array(vertexCount);
  23135. this._vertexBuffer = new VertexBuffer3D(PixelLineVertex.vertexDeclaration.vertexStride * pointCount, Laya.LayaGL.instance.STATIC_DRAW, false);
  23136. this._vertexBuffer.vertexDeclaration = PixelLineVertex.vertexDeclaration;
  23137. if (vertexCount < lastVertices.length) {
  23138. this._vertices.set(new Float32Array(lastVertices.buffer, 0, vertexCount));
  23139. this._vertexBuffer.setData(this._vertices.buffer, 0, 0, vertexCount * 4);
  23140. }
  23141. else {
  23142. this._vertices.set(lastVertices);
  23143. this._vertexBuffer.setData(this._vertices.buffer, 0, 0, lastVertices.length * 4);
  23144. }
  23145. this._bufferState.bind();
  23146. this._bufferState.applyVertexBuffer(this._vertexBuffer);
  23147. this._bufferState.unBind();
  23148. }
  23149. _updateLineVertices(offset, startPosition, endPosition, startColor, endColor) {
  23150. if (startPosition) {
  23151. this._vertices[offset + 0] = startPosition.x;
  23152. this._vertices[offset + 1] = startPosition.y;
  23153. this._vertices[offset + 2] = startPosition.z;
  23154. }
  23155. if (startColor) {
  23156. this._vertices[offset + 3] = startColor.r;
  23157. this._vertices[offset + 4] = startColor.g;
  23158. this._vertices[offset + 5] = startColor.b;
  23159. this._vertices[offset + 6] = startColor.a;
  23160. }
  23161. if (endPosition) {
  23162. this._vertices[offset + 7] = endPosition.x;
  23163. this._vertices[offset + 8] = endPosition.y;
  23164. this._vertices[offset + 9] = endPosition.z;
  23165. }
  23166. if (endColor) {
  23167. this._vertices[offset + 10] = endColor.r;
  23168. this._vertices[offset + 11] = endColor.g;
  23169. this._vertices[offset + 12] = endColor.b;
  23170. this._vertices[offset + 13] = endColor.a;
  23171. }
  23172. this._minUpdate = Math.min(this._minUpdate, offset);
  23173. this._maxUpdate = Math.max(this._maxUpdate, offset + this._floatCountPerVertices * 2);
  23174. }
  23175. _removeLineData(index) {
  23176. var floatCount = this._floatCountPerVertices * 2;
  23177. var nextIndex = index + 1;
  23178. var offset = index * floatCount;
  23179. var rightPartVertices = new Float32Array(this._vertices.buffer, nextIndex * floatCount * 4, (this._lineCount - nextIndex) * floatCount);
  23180. this._vertices.set(rightPartVertices, offset);
  23181. this._minUpdate = Math.min(this._minUpdate, offset);
  23182. this._maxUpdate = Math.max(this._maxUpdate, offset + rightPartVertices.length);
  23183. this._lineCount--;
  23184. }
  23185. _updateLineData(index, startPosition, endPosition, startColor, endColor) {
  23186. var floatCount = this._floatCountPerVertices * 2;
  23187. var offset = index * floatCount;
  23188. this._updateLineVertices(offset, startPosition, endPosition, startColor, endColor);
  23189. }
  23190. _updateLineDatas(index, data) {
  23191. var floatCount = this._floatCountPerVertices * 2;
  23192. var count = data.length;
  23193. for (var i = 0; i < count; i++) {
  23194. var line = data[i];
  23195. this._updateLineVertices((index + i) * floatCount, line.startPosition, line.endPosition, line.startColor, line.endColor);
  23196. }
  23197. }
  23198. _getLineData(index, out) {
  23199. var startPosition = out.startPosition;
  23200. var startColor = out.startColor;
  23201. var endPosition = out.endPosition;
  23202. var endColor = out.endColor;
  23203. var vertices = this._vertices;
  23204. var offset = index * this._floatCountPerVertices * 2;
  23205. startPosition.x = vertices[offset + 0];
  23206. startPosition.y = vertices[offset + 1];
  23207. startPosition.z = vertices[offset + 2];
  23208. startColor.r = vertices[offset + 3];
  23209. startColor.g = vertices[offset + 4];
  23210. startColor.b = vertices[offset + 5];
  23211. startColor.a = vertices[offset + 6];
  23212. endPosition.x = vertices[offset + 7];
  23213. endPosition.y = vertices[offset + 8];
  23214. endPosition.z = vertices[offset + 9];
  23215. endColor.r = vertices[offset + 10];
  23216. endColor.g = vertices[offset + 11];
  23217. endColor.b = vertices[offset + 12];
  23218. endColor.a = vertices[offset + 13];
  23219. }
  23220. _prepareRender(state) {
  23221. return true;
  23222. }
  23223. _render(state) {
  23224. if (this._minUpdate !== Number.MAX_VALUE && this._maxUpdate !== Number.MIN_VALUE) {
  23225. this._vertexBuffer.setData(this._vertices.buffer, this._minUpdate * 4, this._minUpdate * 4, (this._maxUpdate - this._minUpdate) * 4);
  23226. this._minUpdate = Number.MAX_VALUE;
  23227. this._maxUpdate = Number.MIN_VALUE;
  23228. }
  23229. if (this._lineCount > 0) {
  23230. this._bufferState.bind();
  23231. var gl = Laya.LayaGL.instance;
  23232. gl.drawArrays(gl.LINES, 0, this._lineCount * 2);
  23233. Laya.Stat.renderBatches++;
  23234. }
  23235. }
  23236. destroy() {
  23237. if (this._destroyed)
  23238. return;
  23239. super.destroy();
  23240. this._bufferState.destroy();
  23241. this._vertexBuffer.destroy();
  23242. this._bufferState = null;
  23243. this._vertexBuffer = null;
  23244. this._vertices = null;
  23245. }
  23246. }
  23247. PixelLineFilter._type = GeometryElement._typeCounter++;
  23248. class PixelLineRenderer extends BaseRender {
  23249. constructor(owner) {
  23250. super(owner);
  23251. this._projectionViewWorldMatrix = new Matrix4x4();
  23252. this._supportOctree = false;
  23253. }
  23254. _calculateBoundingBox() {
  23255. var min = this._bounds.getMin();
  23256. min.x = -Number.MAX_VALUE;
  23257. min.y = -Number.MAX_VALUE;
  23258. min.z = -Number.MAX_VALUE;
  23259. this._bounds.setMin(min);
  23260. var max = this._bounds.getMax();
  23261. max.x = Number.MAX_VALUE;
  23262. max.y = Number.MAX_VALUE;
  23263. max.z = Number.MAX_VALUE;
  23264. this._bounds.setMax(max);
  23265. if (Laya.Render.supportWebGLPlusCulling) {
  23266. var min = this._bounds.getMin();
  23267. var max = this._bounds.getMax();
  23268. var buffer = FrustumCulling._cullingBuffer;
  23269. buffer[this._cullingBufferIndex + 1] = min.x;
  23270. buffer[this._cullingBufferIndex + 2] = min.y;
  23271. buffer[this._cullingBufferIndex + 3] = min.z;
  23272. buffer[this._cullingBufferIndex + 4] = max.x;
  23273. buffer[this._cullingBufferIndex + 5] = max.y;
  23274. buffer[this._cullingBufferIndex + 6] = max.z;
  23275. }
  23276. }
  23277. _renderUpdateWithCamera(context, transform) {
  23278. var projectionView = context.projectionViewMatrix;
  23279. var sv = this._shaderValues;
  23280. if (transform) {
  23281. var worldMat = transform.worldMatrix;
  23282. sv.setMatrix4x4(Sprite3D.WORLDMATRIX, worldMat);
  23283. Matrix4x4.multiply(projectionView, worldMat, this._projectionViewWorldMatrix);
  23284. sv.setMatrix4x4(Sprite3D.MVPMATRIX, this._projectionViewWorldMatrix);
  23285. }
  23286. else {
  23287. sv.setMatrix4x4(Sprite3D.WORLDMATRIX, Matrix4x4.DEFAULT);
  23288. sv.setMatrix4x4(Sprite3D.MVPMATRIX, projectionView);
  23289. }
  23290. }
  23291. }
  23292. class PixelLineSprite3D extends RenderableSprite3D {
  23293. get maxLineCount() {
  23294. return this._geometryFilter._maxLineCount;
  23295. }
  23296. set maxLineCount(value) {
  23297. this._geometryFilter._resizeLineData(value);
  23298. this._geometryFilter._lineCount = Math.min(this._geometryFilter._lineCount, value);
  23299. }
  23300. get lineCount() {
  23301. return this._geometryFilter._lineCount;
  23302. }
  23303. set lineCount(value) {
  23304. if (value > this.maxLineCount)
  23305. throw "PixelLineSprite3D: lineCount can't large than maxLineCount";
  23306. else
  23307. this._geometryFilter._lineCount = value;
  23308. }
  23309. get pixelLineRenderer() {
  23310. return this._render;
  23311. }
  23312. constructor(maxCount = 2, name = null) {
  23313. super(name);
  23314. this._geometryFilter = new PixelLineFilter(this, maxCount);
  23315. this._render = new PixelLineRenderer(this);
  23316. this._changeRenderObjects(this._render, 0, PixelLineMaterial.defaultMaterial);
  23317. }
  23318. _changeRenderObjects(sender, index, material) {
  23319. var renderObjects = this._render._renderElements;
  23320. (material) || (material = PixelLineMaterial.defaultMaterial);
  23321. var renderElement = renderObjects[index];
  23322. (renderElement) || (renderElement = renderObjects[index] = new RenderElement());
  23323. renderElement.setTransform(this._transform);
  23324. renderElement.setGeometry(this._geometryFilter);
  23325. renderElement.render = this._render;
  23326. renderElement.material = material;
  23327. }
  23328. addLine(startPosition, endPosition, startColor, endColor) {
  23329. if (this._geometryFilter._lineCount !== this._geometryFilter._maxLineCount)
  23330. this._geometryFilter._updateLineData(this._geometryFilter._lineCount++, startPosition, endPosition, startColor, endColor);
  23331. else
  23332. throw "PixelLineSprite3D: lineCount has equal with maxLineCount.";
  23333. }
  23334. addLines(lines) {
  23335. var lineCount = this._geometryFilter._lineCount;
  23336. var addCount = lines.length;
  23337. if (lineCount + addCount > this._geometryFilter._maxLineCount) {
  23338. throw "PixelLineSprite3D: lineCount plus lines count must less than maxLineCount.";
  23339. }
  23340. else {
  23341. this._geometryFilter._updateLineDatas(lineCount, lines);
  23342. this._geometryFilter._lineCount += addCount;
  23343. }
  23344. }
  23345. removeLine(index) {
  23346. if (index < this._geometryFilter._lineCount)
  23347. this._geometryFilter._removeLineData(index);
  23348. else
  23349. throw "PixelLineSprite3D: index must less than lineCount.";
  23350. }
  23351. setLine(index, startPosition, endPosition, startColor, endColor) {
  23352. if (index < this._geometryFilter._lineCount)
  23353. this._geometryFilter._updateLineData(index, startPosition, endPosition, startColor, endColor);
  23354. else
  23355. throw "PixelLineSprite3D: index must less than lineCount.";
  23356. }
  23357. getLine(index, out) {
  23358. if (index < this.lineCount)
  23359. this._geometryFilter._getLineData(index, out);
  23360. else
  23361. throw "PixelLineSprite3D: index must less than lineCount.";
  23362. }
  23363. clear() {
  23364. this._geometryFilter._lineCount = 0;
  23365. }
  23366. _create() {
  23367. return new PixelLineSprite3D();
  23368. }
  23369. }
  23370. class RenderQueue {
  23371. constructor(isTransparent = false) {
  23372. this.isTransparent = false;
  23373. this.elements = new SingletonList();
  23374. this.lastTransparentRenderElement = null;
  23375. this.lastTransparentBatched = false;
  23376. this.isTransparent = isTransparent;
  23377. }
  23378. _compare(left, right) {
  23379. var renderQueue = left.material.renderQueue - right.material.renderQueue;
  23380. if (renderQueue === 0) {
  23381. var sort = this.isTransparent ? right.render._distanceForSort - left.render._distanceForSort : left.render._distanceForSort - right.render._distanceForSort;
  23382. return sort + right.render.sortingFudge - left.render.sortingFudge;
  23383. }
  23384. else {
  23385. return renderQueue;
  23386. }
  23387. }
  23388. _partitionRenderObject(left, right) {
  23389. var elements = this.elements.elements;
  23390. var pivot = elements[Math.floor((right + left) / 2)];
  23391. while (left <= right) {
  23392. while (this._compare(elements[left], pivot) < 0)
  23393. left++;
  23394. while (this._compare(elements[right], pivot) > 0)
  23395. right--;
  23396. if (left < right) {
  23397. var temp = elements[left];
  23398. elements[left] = elements[right];
  23399. elements[right] = temp;
  23400. left++;
  23401. right--;
  23402. }
  23403. else if (left === right) {
  23404. left++;
  23405. break;
  23406. }
  23407. }
  23408. return left;
  23409. }
  23410. _quickSort(left, right) {
  23411. if (this.elements.length > 1) {
  23412. var index = this._partitionRenderObject(left, right);
  23413. var leftIndex = index - 1;
  23414. if (left < leftIndex)
  23415. this._quickSort(left, leftIndex);
  23416. if (index < right)
  23417. this._quickSort(index, right);
  23418. }
  23419. }
  23420. _render(context, isTarget) {
  23421. var elements = this.elements.elements;
  23422. for (var i = 0, n = this.elements.length; i < n; i++)
  23423. elements[i]._render(context, isTarget);
  23424. }
  23425. clear() {
  23426. this.elements.length = 0;
  23427. this.lastTransparentRenderElement = null;
  23428. this.lastTransparentBatched = false;
  23429. }
  23430. }
  23431. class BoundsOctreeNode {
  23432. constructor(octree, parent, baseLength, center) {
  23433. this._bounds = new BoundBox(new Vector3(), new Vector3());
  23434. this._objects = [];
  23435. this._isContaion = false;
  23436. this.center = new Vector3();
  23437. this.baseLength = 0.0;
  23438. this._setValues(octree, parent, baseLength, center);
  23439. }
  23440. static _encapsulates(outerBound, innerBound) {
  23441. return CollisionUtils.boxContainsBox(outerBound, innerBound) == ContainmentType.Contains;
  23442. }
  23443. _setValues(octree, parent, baseLength, center) {
  23444. this._octree = octree;
  23445. this._parent = parent;
  23446. this.baseLength = baseLength;
  23447. center.cloneTo(this.center);
  23448. var min = this._bounds.min;
  23449. var max = this._bounds.max;
  23450. var halfSize = (octree._looseness * baseLength) / 2;
  23451. min.setValue(center.x - halfSize, center.y - halfSize, center.z - halfSize);
  23452. max.setValue(center.x + halfSize, center.y + halfSize, center.z + halfSize);
  23453. }
  23454. _getChildBound(index) {
  23455. if (this._children != null && this._children[index]) {
  23456. return this._children[index]._bounds;
  23457. }
  23458. else {
  23459. var quarter = this.baseLength / 4;
  23460. var halfChildSize = ((this.baseLength / 2) * this._octree._looseness) / 2;
  23461. var bounds = BoundsOctreeNode._tempBoundBox;
  23462. var min = bounds.min;
  23463. var max = bounds.max;
  23464. switch (index) {
  23465. case 0:
  23466. min.x = this.center.x - quarter - halfChildSize;
  23467. min.y = this.center.y + quarter - halfChildSize;
  23468. min.z = this.center.z - quarter - halfChildSize;
  23469. max.x = this.center.x - quarter + halfChildSize;
  23470. max.y = this.center.y + quarter + halfChildSize;
  23471. max.z = this.center.z - quarter + halfChildSize;
  23472. break;
  23473. case 1:
  23474. min.x = this.center.x + quarter - halfChildSize;
  23475. min.y = this.center.y + quarter - halfChildSize;
  23476. min.z = this.center.z - quarter - halfChildSize;
  23477. max.x = this.center.x + quarter + halfChildSize;
  23478. max.y = this.center.y + quarter + halfChildSize;
  23479. max.z = this.center.z - quarter + halfChildSize;
  23480. break;
  23481. case 2:
  23482. min.x = this.center.x - quarter - halfChildSize;
  23483. min.y = this.center.y + quarter - halfChildSize;
  23484. min.z = this.center.z + quarter - halfChildSize;
  23485. max.x = this.center.x - quarter + halfChildSize;
  23486. max.y = this.center.y + quarter + halfChildSize;
  23487. max.z = this.center.z + quarter + halfChildSize;
  23488. break;
  23489. case 3:
  23490. min.x = this.center.x + quarter - halfChildSize;
  23491. min.y = this.center.y + quarter - halfChildSize;
  23492. min.z = this.center.z + quarter - halfChildSize;
  23493. max.x = this.center.x + quarter + halfChildSize;
  23494. max.y = this.center.y + quarter + halfChildSize;
  23495. max.z = this.center.z + quarter + halfChildSize;
  23496. break;
  23497. case 4:
  23498. min.x = this.center.x - quarter - halfChildSize;
  23499. min.y = this.center.y - quarter - halfChildSize;
  23500. min.z = this.center.z - quarter - halfChildSize;
  23501. max.x = this.center.x - quarter + halfChildSize;
  23502. max.y = this.center.y - quarter + halfChildSize;
  23503. max.z = this.center.z - quarter + halfChildSize;
  23504. break;
  23505. case 5:
  23506. min.x = this.center.x + quarter - halfChildSize;
  23507. min.y = this.center.y - quarter - halfChildSize;
  23508. min.z = this.center.z - quarter - halfChildSize;
  23509. max.x = this.center.x + quarter + halfChildSize;
  23510. max.y = this.center.y - quarter + halfChildSize;
  23511. max.z = this.center.z - quarter + halfChildSize;
  23512. break;
  23513. case 6:
  23514. min.x = this.center.x - quarter - halfChildSize;
  23515. min.y = this.center.y - quarter - halfChildSize;
  23516. min.z = this.center.z + quarter - halfChildSize;
  23517. max.x = this.center.x - quarter + halfChildSize;
  23518. max.y = this.center.y - quarter + halfChildSize;
  23519. max.z = this.center.z + quarter + halfChildSize;
  23520. break;
  23521. case 7:
  23522. min.x = this.center.x + quarter - halfChildSize;
  23523. min.y = this.center.y - quarter - halfChildSize;
  23524. min.z = this.center.z + quarter - halfChildSize;
  23525. max.x = this.center.x + quarter + halfChildSize;
  23526. max.y = this.center.y - quarter + halfChildSize;
  23527. max.z = this.center.z + quarter + halfChildSize;
  23528. break;
  23529. default:
  23530. }
  23531. return bounds;
  23532. }
  23533. }
  23534. _getChildCenter(index) {
  23535. if (this._children != null) {
  23536. return this._children[index].center;
  23537. }
  23538. else {
  23539. var quarter = this.baseLength / 4;
  23540. var childCenter = BoundsOctreeNode._tempVector30;
  23541. switch (index) {
  23542. case 0:
  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 1:
  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 2:
  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 3:
  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 4:
  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 5:
  23568. childCenter.x = this.center.x + quarter;
  23569. childCenter.y = this.center.y - quarter;
  23570. childCenter.z = this.center.z - quarter;
  23571. break;
  23572. case 6:
  23573. childCenter.x = this.center.x - quarter;
  23574. childCenter.y = this.center.y - quarter;
  23575. childCenter.z = this.center.z + quarter;
  23576. break;
  23577. case 7:
  23578. childCenter.x = this.center.x + quarter;
  23579. childCenter.y = this.center.y - quarter;
  23580. childCenter.z = this.center.z + quarter;
  23581. break;
  23582. default:
  23583. }
  23584. return childCenter;
  23585. }
  23586. }
  23587. _getChild(index) {
  23588. var quarter = this.baseLength / 4;
  23589. this._children || (this._children = []);
  23590. switch (index) {
  23591. case 0:
  23592. 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)));
  23593. case 1:
  23594. 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)));
  23595. case 2:
  23596. 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)));
  23597. case 3:
  23598. 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)));
  23599. case 4:
  23600. 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)));
  23601. case 5:
  23602. 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)));
  23603. case 6:
  23604. 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)));
  23605. case 7:
  23606. 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)));
  23607. default:
  23608. throw "BoundsOctreeNode: unknown index.";
  23609. }
  23610. }
  23611. _shouldMerge() {
  23612. var objectCount = this._objects.length;
  23613. for (var i = 0; i < 8; i++) {
  23614. var child = this._children[i];
  23615. if (child) {
  23616. if (child._children != null)
  23617. return false;
  23618. objectCount += child._objects.length;
  23619. }
  23620. }
  23621. return objectCount <= BoundsOctreeNode._NUM_OBJECTS_ALLOWED;
  23622. }
  23623. _mergeChildren() {
  23624. for (var i = 0; i < 8; i++) {
  23625. var child = this._children[i];
  23626. if (child) {
  23627. child._parent = null;
  23628. var childObjects = child._objects;
  23629. for (var j = childObjects.length - 1; j >= 0; j--) {
  23630. var childObject = childObjects[j];
  23631. this._objects.push(childObject);
  23632. childObject._setOctreeNode(this);
  23633. }
  23634. }
  23635. }
  23636. this._children = null;
  23637. }
  23638. _merge() {
  23639. if (this._children === null) {
  23640. var parent = this._parent;
  23641. if (parent && parent._shouldMerge()) {
  23642. parent._mergeChildren();
  23643. parent._merge();
  23644. }
  23645. }
  23646. }
  23647. _checkAddNode(object) {
  23648. if (this._children == null) {
  23649. if (this._objects.length < BoundsOctreeNode._NUM_OBJECTS_ALLOWED || (this.baseLength / 2) < this._octree._minSize) {
  23650. return this;
  23651. }
  23652. for (var i = this._objects.length - 1; i >= 0; i--) {
  23653. var existObject = this._objects[i];
  23654. var fitChildIndex = this._bestFitChild(existObject.bounds.getCenter());
  23655. if (BoundsOctreeNode._encapsulates(this._getChildBound(fitChildIndex), existObject.bounds._getBoundBox())) {
  23656. this._objects.splice(this._objects.indexOf(existObject), 1);
  23657. this._getChild(fitChildIndex)._add(existObject);
  23658. }
  23659. }
  23660. }
  23661. var newFitChildIndex = this._bestFitChild(object.bounds.getCenter());
  23662. if (BoundsOctreeNode._encapsulates(this._getChildBound(newFitChildIndex), object.bounds._getBoundBox()))
  23663. return this._getChild(newFitChildIndex)._checkAddNode(object);
  23664. else
  23665. return this;
  23666. }
  23667. _add(object) {
  23668. var addNode = this._checkAddNode(object);
  23669. addNode._objects.push(object);
  23670. object._setOctreeNode(addNode);
  23671. }
  23672. _remove(object) {
  23673. var index = this._objects.indexOf(object);
  23674. this._objects.splice(index, 1);
  23675. object._setOctreeNode(null);
  23676. this._merge();
  23677. }
  23678. _addUp(object) {
  23679. if ((CollisionUtils.boxContainsBox(this._bounds, object.bounds._getBoundBox()) === ContainmentType.Contains)) {
  23680. this._add(object);
  23681. return true;
  23682. }
  23683. else {
  23684. if (this._parent)
  23685. return this._parent._addUp(object);
  23686. else
  23687. return false;
  23688. }
  23689. }
  23690. _getCollidingWithFrustum(context, frustum, testVisible, camPos, customShader, replacementTag) {
  23691. if (testVisible) {
  23692. var type = frustum.containsBoundBox(this._bounds);
  23693. Laya.Stat.octreeNodeCulling++;
  23694. if (type === ContainmentType.Disjoint)
  23695. return;
  23696. testVisible = (type === ContainmentType.Intersects);
  23697. }
  23698. this._isContaion = !testVisible;
  23699. var camera = context.camera;
  23700. var scene = context.scene;
  23701. for (var i = 0, n = this._objects.length; i < n; i++) {
  23702. var render = this._objects[i];
  23703. if (camera._isLayerVisible(render._owner.layer) && render._enable) {
  23704. if (testVisible) {
  23705. Laya.Stat.frustumCulling++;
  23706. if (!render._needRender(frustum, context))
  23707. continue;
  23708. }
  23709. render._distanceForSort = Vector3.distance(render.bounds.getCenter(), camPos);
  23710. var elements = render._renderElements;
  23711. for (var j = 0, m = elements.length; j < m; j++) {
  23712. var element = elements[j];
  23713. element._update(scene, context, customShader, replacementTag);
  23714. }
  23715. }
  23716. }
  23717. if (this._children != null) {
  23718. for (i = 0; i < 8; i++) {
  23719. var child = this._children[i];
  23720. child && child._getCollidingWithFrustum(context, frustum, testVisible, camPos, customShader, replacementTag);
  23721. }
  23722. }
  23723. }
  23724. _getCollidingWithBoundBox(checkBound, testVisible, result) {
  23725. if (testVisible) {
  23726. var type = CollisionUtils.boxContainsBox(this._bounds, checkBound);
  23727. if (type === ContainmentType.Disjoint)
  23728. return;
  23729. testVisible = (type === ContainmentType.Intersects);
  23730. }
  23731. if (testVisible) {
  23732. for (var i = 0, n = this._objects.length; i < n; i++) {
  23733. var object = this._objects[i];
  23734. if (CollisionUtils.intersectsBoxAndBox(object.bounds._getBoundBox(), checkBound)) {
  23735. result.push(object);
  23736. }
  23737. }
  23738. }
  23739. if (this._children != null) {
  23740. for (i = 0; i < 8; i++) {
  23741. var child = this._children[i];
  23742. child._getCollidingWithBoundBox(checkBound, testVisible, result);
  23743. }
  23744. }
  23745. }
  23746. _bestFitChild(boundCenter) {
  23747. return (boundCenter.x <= this.center.x ? 0 : 1) + (boundCenter.y >= this.center.y ? 0 : 4) + (boundCenter.z <= this.center.z ? 0 : 2);
  23748. }
  23749. _update(object) {
  23750. if (CollisionUtils.boxContainsBox(this._bounds, object.bounds._getBoundBox()) === ContainmentType.Contains) {
  23751. var addNode = this._checkAddNode(object);
  23752. if (addNode !== object._getOctreeNode()) {
  23753. addNode._objects.push(object);
  23754. object._setOctreeNode(addNode);
  23755. var index = this._objects.indexOf(object);
  23756. this._objects.splice(index, 1);
  23757. this._merge();
  23758. }
  23759. return true;
  23760. }
  23761. else {
  23762. if (this._parent) {
  23763. var sucess = this._parent._addUp(object);
  23764. if (sucess) {
  23765. index = this._objects.indexOf(object);
  23766. this._objects.splice(index, 1);
  23767. this._merge();
  23768. }
  23769. return sucess;
  23770. }
  23771. else {
  23772. return false;
  23773. }
  23774. }
  23775. }
  23776. add(object) {
  23777. if (!BoundsOctreeNode._encapsulates(this._bounds, object.bounds._getBoundBox()))
  23778. return false;
  23779. this._add(object);
  23780. return true;
  23781. }
  23782. remove(object) {
  23783. if (object._getOctreeNode() !== this)
  23784. return false;
  23785. this._remove(object);
  23786. return true;
  23787. }
  23788. update(object) {
  23789. if (object._getOctreeNode() !== this)
  23790. return false;
  23791. return this._update(object);
  23792. }
  23793. shrinkIfPossible(minLength) {
  23794. if (this.baseLength < minLength * 2)
  23795. return this;
  23796. var bestFit = -1;
  23797. for (var i = 0, n = this._objects.length; i < n; i++) {
  23798. var object = this._objects[i];
  23799. var newBestFit = this._bestFitChild(object.bounds.getCenter());
  23800. if (i == 0 || newBestFit == bestFit) {
  23801. var childBounds = this._getChildBound(newBestFit);
  23802. if (BoundsOctreeNode._encapsulates(childBounds, object.bounds._getBoundBox()))
  23803. (i == 0) && (bestFit = newBestFit);
  23804. else
  23805. return this;
  23806. }
  23807. else {
  23808. return this;
  23809. }
  23810. }
  23811. if (this._children != null) {
  23812. var childHadContent = false;
  23813. for (i = 0, n = this._children.length; i < n; i++) {
  23814. var child = this._children[i];
  23815. if (child && child.hasAnyObjects()) {
  23816. if (childHadContent)
  23817. return this;
  23818. if (bestFit >= 0 && bestFit != i)
  23819. return this;
  23820. childHadContent = true;
  23821. bestFit = i;
  23822. }
  23823. }
  23824. }
  23825. else {
  23826. if (bestFit != -1) {
  23827. var childCenter = this._getChildCenter(bestFit);
  23828. this._setValues(this._octree, null, this.baseLength / 2, childCenter);
  23829. }
  23830. return this;
  23831. }
  23832. if (bestFit != -1) {
  23833. var newRoot = this._children[bestFit];
  23834. newRoot._parent = null;
  23835. return newRoot;
  23836. }
  23837. else {
  23838. return this;
  23839. }
  23840. }
  23841. hasAnyObjects() {
  23842. if (this._objects.length > 0)
  23843. return true;
  23844. if (this._children != null) {
  23845. for (var i = 0; i < 8; i++) {
  23846. var child = this._children[i];
  23847. if (child && child.hasAnyObjects())
  23848. return true;
  23849. }
  23850. }
  23851. return false;
  23852. }
  23853. getCollidingWithBoundBox(checkBound, result) {
  23854. this._getCollidingWithBoundBox(checkBound, true, result);
  23855. }
  23856. getCollidingWithRay(ray, result, maxDistance = Number.MAX_VALUE) {
  23857. var distance = CollisionUtils.intersectsRayAndBoxRD(ray, this._bounds);
  23858. if (distance == -1 || distance > maxDistance)
  23859. return;
  23860. for (var i = 0, n = this._objects.length; i < n; i++) {
  23861. var object = this._objects[i];
  23862. distance = CollisionUtils.intersectsRayAndBoxRD(ray, object.bounds._getBoundBox());
  23863. if (distance !== -1 && distance <= maxDistance)
  23864. result.push(object);
  23865. }
  23866. if (this._children != null) {
  23867. for (i = 0; i < 8; i++) {
  23868. var child = this._children[i];
  23869. child.getCollidingWithRay(ray, result, maxDistance);
  23870. }
  23871. }
  23872. }
  23873. getCollidingWithFrustum(context, customShader, replacementTag) {
  23874. var cameraPos = context.camera.transform.position;
  23875. var boundFrustum = context.camera.boundFrustum;
  23876. this._getCollidingWithFrustum(context, boundFrustum, true, cameraPos, customShader, replacementTag);
  23877. }
  23878. isCollidingWithBoundBox(checkBound) {
  23879. if (!(CollisionUtils.intersectsBoxAndBox(this._bounds, checkBound)))
  23880. return false;
  23881. for (var i = 0, n = this._objects.length; i < n; i++) {
  23882. var object = this._objects[i];
  23883. if (CollisionUtils.intersectsBoxAndBox(object.bounds._getBoundBox(), checkBound))
  23884. return true;
  23885. }
  23886. if (this._children != null) {
  23887. for (i = 0; i < 8; i++) {
  23888. var child = this._children[i];
  23889. if (child.isCollidingWithBoundBox(checkBound))
  23890. return true;
  23891. }
  23892. }
  23893. return false;
  23894. }
  23895. isCollidingWithRay(ray, maxDistance = Number.MAX_VALUE) {
  23896. var distance = CollisionUtils.intersectsRayAndBoxRD(ray, this._bounds);
  23897. if (distance == -1 || distance > maxDistance)
  23898. return false;
  23899. for (var i = 0, n = this._objects.length; i < n; i++) {
  23900. var object = this._objects[i];
  23901. distance = CollisionUtils.intersectsRayAndBoxRD(ray, object.bounds._getBoundBox());
  23902. if (distance !== -1 && distance <= maxDistance)
  23903. return true;
  23904. }
  23905. if (this._children != null) {
  23906. for (i = 0; i < 8; i++) {
  23907. var child = this._children[i];
  23908. if (child.isCollidingWithRay(ray, maxDistance))
  23909. return true;
  23910. }
  23911. }
  23912. return false;
  23913. }
  23914. getBound() {
  23915. return this._bounds;
  23916. }
  23917. drawAllBounds(debugLine, currentDepth, maxDepth) {
  23918. if (this._children === null && this._objects.length == 0)
  23919. return;
  23920. currentDepth++;
  23921. var color = BoundsOctreeNode._tempColor0;
  23922. if (this._isContaion) {
  23923. color.r = 0.0;
  23924. color.g = 0.0;
  23925. color.b = 1.0;
  23926. }
  23927. else {
  23928. var tint = maxDepth ? currentDepth / maxDepth : 0;
  23929. color.r = 1.0 - tint;
  23930. color.g = tint;
  23931. color.b = 0.0;
  23932. }
  23933. color.a = 0.3;
  23934. Utils3D._drawBound(debugLine, this._bounds, color);
  23935. if (this._children != null) {
  23936. for (var i = 0; i < 8; i++) {
  23937. var child = this._children[i];
  23938. child && child.drawAllBounds(debugLine, currentDepth, maxDepth);
  23939. }
  23940. }
  23941. }
  23942. drawAllObjects(debugLine, currentDepth, maxDepth) {
  23943. currentDepth++;
  23944. var color = BoundsOctreeNode._tempColor0;
  23945. if (this._isContaion) {
  23946. color.r = 0.0;
  23947. color.g = 0.0;
  23948. color.b = 1.0;
  23949. }
  23950. else {
  23951. var tint = maxDepth ? currentDepth / maxDepth : 0;
  23952. color.r = 1.0 - tint;
  23953. color.g = tint;
  23954. color.b = 0.0;
  23955. }
  23956. color.a = 1.0;
  23957. for (var i = 0, n = this._objects.length; i < n; i++)
  23958. Utils3D._drawBound(debugLine, this._objects[i].bounds._getBoundBox(), color);
  23959. if (this._children != null) {
  23960. for (i = 0; i < 8; i++) {
  23961. var child = this._children[i];
  23962. child && child.drawAllObjects(debugLine, currentDepth, maxDepth);
  23963. }
  23964. }
  23965. }
  23966. }
  23967. BoundsOctreeNode._tempVector3 = new Vector3();
  23968. BoundsOctreeNode._tempVector30 = new Vector3();
  23969. BoundsOctreeNode._tempVector31 = new Vector3();
  23970. BoundsOctreeNode._tempColor0 = new Color();
  23971. BoundsOctreeNode._tempBoundBox = new BoundBox(new Vector3(), new Vector3());
  23972. BoundsOctreeNode._NUM_OBJECTS_ALLOWED = 8;
  23973. class OctreeMotionList extends SingletonList {
  23974. constructor() {
  23975. super();
  23976. }
  23977. add(element) {
  23978. var index = element._getIndexInMotionList();
  23979. if (index !== -1)
  23980. throw "OctreeMotionList:element has in PhysicsUpdateList.";
  23981. this._add(element);
  23982. element._setIndexInMotionList(this.length++);
  23983. }
  23984. remove(element) {
  23985. var index = element._getIndexInMotionList();
  23986. this.length--;
  23987. if (index !== this.length) {
  23988. var end = this.elements[this.length];
  23989. this.elements[index] = end;
  23990. end._setIndexInMotionList(index);
  23991. }
  23992. element._setIndexInMotionList(-1);
  23993. }
  23994. }
  23995. class BoundsOctree {
  23996. constructor(initialWorldSize, initialWorldPos, minNodeSize, looseness) {
  23997. this._motionObjects = new OctreeMotionList();
  23998. this.count = 0;
  23999. if (minNodeSize > initialWorldSize) {
  24000. console.warn("Minimum node size must be at least as big as the initial world size. Was: " + minNodeSize + " Adjusted to: " + initialWorldSize);
  24001. minNodeSize = initialWorldSize;
  24002. }
  24003. this._initialSize = initialWorldSize;
  24004. this._minSize = minNodeSize;
  24005. this._looseness = Math.min(Math.max(looseness, 1.0), 2.0);
  24006. this._rootNode = new BoundsOctreeNode(this, null, initialWorldSize, initialWorldPos);
  24007. }
  24008. _getMaxDepth(node, depth) {
  24009. depth++;
  24010. var children = node._children;
  24011. if (children != null) {
  24012. var curDepth = depth;
  24013. for (var i = 0, n = children.length; i < n; i++) {
  24014. var child = children[i];
  24015. child && (depth = Math.max(this._getMaxDepth(child, curDepth), depth));
  24016. }
  24017. }
  24018. return depth;
  24019. }
  24020. _grow(growObjectCenter) {
  24021. var xDirection = growObjectCenter.x >= 0 ? 1 : -1;
  24022. var yDirection = growObjectCenter.y >= 0 ? 1 : -1;
  24023. var zDirection = growObjectCenter.z >= 0 ? 1 : -1;
  24024. var oldRoot = this._rootNode;
  24025. var half = this._rootNode.baseLength / 2;
  24026. var newLength = this._rootNode.baseLength * 2;
  24027. var rootCenter = this._rootNode.center;
  24028. var newCenter = new Vector3(rootCenter.x + xDirection * half, rootCenter.y + yDirection * half, rootCenter.z + zDirection * half);
  24029. this._rootNode = new BoundsOctreeNode(this, null, newLength, newCenter);
  24030. if (oldRoot.hasAnyObjects()) {
  24031. var rootPos = this._rootNode._bestFitChild(oldRoot.center);
  24032. var children = [];
  24033. for (var i = 0; i < 8; i++) {
  24034. if (i == rootPos) {
  24035. oldRoot._parent = this._rootNode;
  24036. children[i] = oldRoot;
  24037. }
  24038. }
  24039. this._rootNode._children = children;
  24040. }
  24041. }
  24042. add(object) {
  24043. var count = 0;
  24044. while (!this._rootNode.add(object)) {
  24045. var growCenter = BoundsOctree._tempVector30;
  24046. Vector3.subtract(object.bounds.getCenter(), this._rootNode.center, growCenter);
  24047. this._grow(growCenter);
  24048. if (++count > 20) {
  24049. throw "Aborted Add operation as it seemed to be going on forever (" + (count - 1) + ") attempts at growing the octree.";
  24050. }
  24051. }
  24052. this.count++;
  24053. }
  24054. remove(object) {
  24055. var removed = object._getOctreeNode().remove(object);
  24056. if (removed) {
  24057. this.count--;
  24058. }
  24059. return removed;
  24060. }
  24061. update(object) {
  24062. var count = 0;
  24063. var octreeNode = object._getOctreeNode();
  24064. if (octreeNode) {
  24065. while (!octreeNode._update(object)) {
  24066. var growCenter = BoundsOctree._tempVector30;
  24067. Vector3.subtract(object.bounds.getCenter(), this._rootNode.center, growCenter);
  24068. this._grow(growCenter);
  24069. if (++count > 20) {
  24070. throw "Aborted Add operation as it seemed to be going on forever (" + (count - 1) + ") attempts at growing the octree.";
  24071. }
  24072. }
  24073. return true;
  24074. }
  24075. else {
  24076. return false;
  24077. }
  24078. }
  24079. shrinkRootIfPossible() {
  24080. this._rootNode = this._rootNode.shrinkIfPossible(this._initialSize);
  24081. }
  24082. addMotionObject(object) {
  24083. this._motionObjects.add(object);
  24084. }
  24085. removeMotionObject(object) {
  24086. this._motionObjects.remove(object);
  24087. }
  24088. updateMotionObjects() {
  24089. var elements = this._motionObjects.elements;
  24090. for (var i = 0, n = this._motionObjects.length; i < n; i++) {
  24091. var object = elements[i];
  24092. this.update(object);
  24093. object._setIndexInMotionList(-1);
  24094. }
  24095. this._motionObjects.length = 0;
  24096. }
  24097. isCollidingWithBoundBox(checkBounds) {
  24098. return this._rootNode.isCollidingWithBoundBox(checkBounds);
  24099. }
  24100. isCollidingWithRay(ray, maxDistance = Number.MAX_VALUE) {
  24101. return this._rootNode.isCollidingWithRay(ray, maxDistance);
  24102. }
  24103. getCollidingWithBoundBox(checkBound, result) {
  24104. this._rootNode.getCollidingWithBoundBox(checkBound, result);
  24105. }
  24106. getCollidingWithRay(ray, result, maxDistance = Number.MAX_VALUE) {
  24107. this._rootNode.getCollidingWithRay(ray, result, maxDistance);
  24108. }
  24109. getCollidingWithFrustum(context, shader, replacementTag) {
  24110. this._rootNode.getCollidingWithFrustum(context, shader, replacementTag);
  24111. }
  24112. getMaxBounds() {
  24113. return this._rootNode.getBound();
  24114. }
  24115. drawAllBounds(pixelLine) {
  24116. var maxDepth = this._getMaxDepth(this._rootNode, -1);
  24117. this._rootNode.drawAllBounds(pixelLine, -1, maxDepth);
  24118. }
  24119. drawAllObjects(pixelLine) {
  24120. var maxDepth = this._getMaxDepth(this._rootNode, -1);
  24121. this._rootNode.drawAllObjects(pixelLine, -1, maxDepth);
  24122. }
  24123. }
  24124. BoundsOctree._tempVector30 = new Vector3();
  24125. class Scene3D extends Laya.Sprite {
  24126. constructor() {
  24127. super();
  24128. this._lights = [];
  24129. this._lightmaps = [];
  24130. this._skyRenderer = new SkyRenderer();
  24131. this._reflectionMode = 1;
  24132. this._enableLightCount = 3;
  24133. this._input = new Input3D();
  24134. this._timer = Laya.ILaya.timer;
  24135. this._collsionTestList = [];
  24136. this._renders = new SimpleSingletonList();
  24137. this._opaqueQueue = new RenderQueue(false);
  24138. this._transparentQueue = new RenderQueue(true);
  24139. this._cameraPool = [];
  24140. this._animatorPool = new SimpleSingletonList();
  24141. this._scriptPool = new Array();
  24142. this._tempScriptPool = new Array();
  24143. this._needClearScriptPool = false;
  24144. this._castShadowRenders = new CastShadowList();
  24145. this.currentCreationLayer = Math.pow(2, 0);
  24146. this.enableLight = true;
  24147. this._key = new Laya.SubmitKey();
  24148. this._time = 0;
  24149. this._pickIdToSprite = new Object();
  24150. if (Physics3D._enbalePhysics)
  24151. this._physicsSimulation = new PhysicsSimulation(Scene3D.physicsSettings);
  24152. this._shaderValues = new ShaderData(null);
  24153. this.parallelSplitShadowMaps = [];
  24154. this.enableFog = false;
  24155. this.fogStart = 300;
  24156. this.fogRange = 1000;
  24157. this.fogColor = new Vector3(0.7, 0.7, 0.7);
  24158. this.ambientColor = new Vector3(0.212, 0.227, 0.259);
  24159. this.reflectionIntensity = 1.0;
  24160. (Laya.WebGL.shaderHighPrecision) && (this._shaderValues.addDefine(Shader3D.SHADERDEFINE_HIGHPRECISION));
  24161. if (Laya.Render.supportWebGLPlusCulling) {
  24162. this._cullingBufferIndices = new Int32Array(1024);
  24163. this._cullingBufferResult = new Int32Array(1024);
  24164. }
  24165. this._shaderValues.setTexture(Scene3D.RANGEATTENUATIONTEXTURE, ShaderInit3D._rangeAttenTex);
  24166. this._scene = this;
  24167. this._input.__init__(Laya.Render.canvas, this);
  24168. if (Scene3D.octreeCulling) {
  24169. this._octree = new BoundsOctree(Scene3D.octreeInitialSize, Scene3D.octreeInitialCenter, Scene3D.octreeMinNodeSize, Scene3D.octreeLooseness);
  24170. }
  24171. if (FrustumCulling.debugFrustumCulling) {
  24172. this._debugTool = new PixelLineSprite3D();
  24173. var lineMaterial = new PixelLineMaterial();
  24174. lineMaterial.renderQueue = BaseMaterial.RENDERQUEUE_TRANSPARENT;
  24175. lineMaterial.alphaTest = false;
  24176. lineMaterial.depthWrite = false;
  24177. lineMaterial.cull = RenderState.CULL_BACK;
  24178. lineMaterial.blend = RenderState.BLEND_ENABLE_ALL;
  24179. lineMaterial.blendSrc = RenderState.BLENDPARAM_SRC_ALPHA;
  24180. lineMaterial.blendDst = RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA;
  24181. lineMaterial.depthTest = RenderState.DEPTHTEST_LESS;
  24182. this._debugTool.pixelLineRenderer.sharedMaterial = lineMaterial;
  24183. }
  24184. }
  24185. static __init__() {
  24186. Scene3DShaderDeclaration.SHADERDEFINE_FOG = Shader3D.registerPublicDefine("FOG");
  24187. Scene3DShaderDeclaration.SHADERDEFINE_DIRECTIONLIGHT = Shader3D.registerPublicDefine("DIRECTIONLIGHT");
  24188. Scene3DShaderDeclaration.SHADERDEFINE_POINTLIGHT = Shader3D.registerPublicDefine("POINTLIGHT");
  24189. Scene3DShaderDeclaration.SHADERDEFINE_SPOTLIGHT = Shader3D.registerPublicDefine("SPOTLIGHT");
  24190. Scene3DShaderDeclaration.SHADERDEFINE_CAST_SHADOW = Shader3D.registerPublicDefine("CASTSHADOW");
  24191. Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PSSM1 = Shader3D.registerPublicDefine("SHADOWMAP_PSSM1");
  24192. Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PSSM2 = Shader3D.registerPublicDefine("SHADOWMAP_PSSM2");
  24193. Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PSSM3 = Shader3D.registerPublicDefine("SHADOWMAP_PSSM3");
  24194. Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PCF_NO = Shader3D.registerPublicDefine("SHADOWMAP_PCF_NO");
  24195. Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PCF1 = Shader3D.registerPublicDefine("SHADOWMAP_PCF1");
  24196. Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PCF2 = Shader3D.registerPublicDefine("SHADOWMAP_PCF2");
  24197. Scene3DShaderDeclaration.SHADERDEFINE_SHADOW_PCF3 = Shader3D.registerPublicDefine("SHADOWMAP_PCF3");
  24198. Scene3DShaderDeclaration.SHADERDEFINE_REFLECTMAP = Shader3D.registerPublicDefine("REFLECTMAP");
  24199. }
  24200. static load(url, complete) {
  24201. Laya.ILaya.loader.create(url, complete, null, Scene3D.HIERARCHY);
  24202. }
  24203. _allotPickColorByID(id, pickColor) {
  24204. var pickColorR = Math.floor(id / (255 * 255));
  24205. id -= pickColorR * 255 * 255;
  24206. var pickColorG = Math.floor(id / 255);
  24207. id -= pickColorG * 255;
  24208. var pickColorB = id;
  24209. pickColor.x = pickColorR / 255;
  24210. pickColor.y = pickColorG / 255;
  24211. pickColor.z = pickColorB / 255;
  24212. pickColor.w = 1.0;
  24213. }
  24214. _searchIDByPickColor(pickColor) {
  24215. var id = pickColor.x * 255 * 255 + pickColor.y * 255 + pickColor.z;
  24216. return id;
  24217. }
  24218. get url() {
  24219. return this._url;
  24220. }
  24221. get enableFog() {
  24222. return this._enableFog;
  24223. }
  24224. set enableFog(value) {
  24225. if (this._enableFog !== value) {
  24226. this._enableFog = value;
  24227. if (value) {
  24228. this._shaderValues.addDefine(Scene3DShaderDeclaration.SHADERDEFINE_FOG);
  24229. }
  24230. else
  24231. this._shaderValues.removeDefine(Scene3DShaderDeclaration.SHADERDEFINE_FOG);
  24232. }
  24233. }
  24234. get fogColor() {
  24235. return this._shaderValues.getVector3(Scene3D.FOGCOLOR);
  24236. }
  24237. set fogColor(value) {
  24238. this._shaderValues.setVector3(Scene3D.FOGCOLOR, value);
  24239. }
  24240. get fogStart() {
  24241. return this._shaderValues.getNumber(Scene3D.FOGSTART);
  24242. }
  24243. set fogStart(value) {
  24244. this._shaderValues.setNumber(Scene3D.FOGSTART, value);
  24245. }
  24246. get fogRange() {
  24247. return this._shaderValues.getNumber(Scene3D.FOGRANGE);
  24248. }
  24249. set fogRange(value) {
  24250. this._shaderValues.setNumber(Scene3D.FOGRANGE, value);
  24251. }
  24252. get ambientColor() {
  24253. return this._shaderValues.getVector3(Scene3D.AMBIENTCOLOR);
  24254. }
  24255. set ambientColor(value) {
  24256. this._shaderValues.setVector3(Scene3D.AMBIENTCOLOR, value);
  24257. }
  24258. get skyRenderer() {
  24259. return this._skyRenderer;
  24260. }
  24261. get customReflection() {
  24262. return this._shaderValues.getTexture(Scene3D.REFLECTIONTEXTURE);
  24263. }
  24264. set customReflection(value) {
  24265. this._shaderValues.setTexture(Scene3D.REFLECTIONTEXTURE, value);
  24266. if (value)
  24267. this._shaderValues.addDefine(Scene3DShaderDeclaration.SHADERDEFINE_REFLECTMAP);
  24268. else
  24269. this._shaderValues.removeDefine(Scene3DShaderDeclaration.SHADERDEFINE_REFLECTMAP);
  24270. }
  24271. get reflectionIntensity() {
  24272. return this._shaderValues.getNumber(Scene3D.REFLETIONINTENSITY);
  24273. }
  24274. set reflectionIntensity(value) {
  24275. value = Math.max(Math.min(value, 1.0), 0.0);
  24276. this._shaderValues.setNumber(Scene3D.REFLETIONINTENSITY, value);
  24277. }
  24278. get physicsSimulation() {
  24279. return this._physicsSimulation;
  24280. }
  24281. get reflectionMode() {
  24282. return this._reflectionMode;
  24283. }
  24284. set reflectionMode(value) {
  24285. this._reflectionMode = value;
  24286. }
  24287. get timer() {
  24288. return this._timer;
  24289. }
  24290. set timer(value) {
  24291. this._timer = value;
  24292. }
  24293. get input() {
  24294. return this._input;
  24295. }
  24296. _setLightmapToChildNode(sprite) {
  24297. if (sprite instanceof RenderableSprite3D)
  24298. sprite._render._applyLightMapParams();
  24299. var children = sprite._children;
  24300. for (var i = 0, n = children.length; i < n; i++)
  24301. this._setLightmapToChildNode(children[i]);
  24302. }
  24303. _update() {
  24304. var delta = this.timer._delta / 1000;
  24305. this._time += delta;
  24306. this._shaderValues.setNumber(Scene3D.TIME, this._time);
  24307. var simulation = this._physicsSimulation;
  24308. if (Physics3D._enbalePhysics && !PhysicsSimulation.disableSimulation) {
  24309. simulation._updatePhysicsTransformFromRender();
  24310. PhysicsComponent._addUpdateList = false;
  24311. simulation._simulate(delta);
  24312. simulation._updateCharacters();
  24313. PhysicsComponent._addUpdateList = true;
  24314. simulation._updateCollisions();
  24315. simulation._eventScripts();
  24316. }
  24317. this._input._update();
  24318. this._clearScript();
  24319. this._updateScript();
  24320. Animator._update(this);
  24321. this._lateUpdateScript();
  24322. }
  24323. _binarySearchIndexInCameraPool(camera) {
  24324. var start = 0;
  24325. var end = this._cameraPool.length - 1;
  24326. var mid;
  24327. while (start <= end) {
  24328. mid = Math.floor((start + end) / 2);
  24329. var midValue = this._cameraPool[mid]._renderingOrder;
  24330. if (midValue == camera._renderingOrder)
  24331. return mid;
  24332. else if (midValue > camera._renderingOrder)
  24333. end = mid - 1;
  24334. else
  24335. start = mid + 1;
  24336. }
  24337. return start;
  24338. }
  24339. onEnable() {
  24340. this._input._onCanvasEvent(Laya.Render.canvas);
  24341. }
  24342. onDisable() {
  24343. this._input._offCanvasEvent(Laya.Render.canvas);
  24344. }
  24345. _setCreateURL(url) {
  24346. this._url = Laya.URL.formatURL(url);
  24347. }
  24348. _getGroup() {
  24349. return this._group;
  24350. }
  24351. _setGroup(value) {
  24352. this._group = value;
  24353. }
  24354. _clearScript() {
  24355. if (this._needClearScriptPool) {
  24356. var scripts = this._scriptPool;
  24357. for (var i = 0, n = scripts.length; i < n; i++) {
  24358. var script = scripts[i];
  24359. if (script) {
  24360. script._indexInPool = this._tempScriptPool.length;
  24361. this._tempScriptPool.push(script);
  24362. }
  24363. }
  24364. this._scriptPool = this._tempScriptPool;
  24365. scripts.length = 0;
  24366. this._tempScriptPool = scripts;
  24367. this._needClearScriptPool = false;
  24368. }
  24369. }
  24370. _updateScript() {
  24371. var scripts = this._scriptPool;
  24372. for (var i = 0, n = scripts.length; i < n; i++) {
  24373. var script = scripts[i];
  24374. (script && script.enabled) && (script.onUpdate());
  24375. }
  24376. }
  24377. _lateUpdateScript() {
  24378. var scripts = this._scriptPool;
  24379. for (var i = 0, n = scripts.length; i < n; i++) {
  24380. var script = scripts[i];
  24381. (script && script.enabled) && (script.onLateUpdate());
  24382. }
  24383. }
  24384. _addScript(script) {
  24385. var scripts = this._scriptPool;
  24386. script._indexInPool = scripts.length;
  24387. scripts.push(script);
  24388. }
  24389. _removeScript(script) {
  24390. this._scriptPool[script._indexInPool] = null;
  24391. script._indexInPool = -1;
  24392. this._needClearScriptPool = true;
  24393. }
  24394. _preRenderScript() {
  24395. var scripts = this._scriptPool;
  24396. for (var i = 0, n = scripts.length; i < n; i++) {
  24397. var script = scripts[i];
  24398. (script && script.enabled) && (script.onPreRender());
  24399. }
  24400. }
  24401. _postRenderScript() {
  24402. var scripts = this._scriptPool;
  24403. for (var i = 0, n = scripts.length; i < n; i++) {
  24404. var script = scripts[i];
  24405. (script && script.enabled) && (script.onPostRender());
  24406. }
  24407. }
  24408. _prepareSceneToRender() {
  24409. var lightCount = this._lights.length;
  24410. if (lightCount > 0) {
  24411. var renderLightCount = 0;
  24412. for (var i = 0; i < lightCount; i++) {
  24413. if (!this._lights[i]._prepareToScene())
  24414. continue;
  24415. renderLightCount++;
  24416. if (renderLightCount >= this._enableLightCount)
  24417. break;
  24418. }
  24419. }
  24420. }
  24421. _addCamera(camera) {
  24422. var index = this._binarySearchIndexInCameraPool(camera);
  24423. var order = camera._renderingOrder;
  24424. var count = this._cameraPool.length;
  24425. while (index < count && this._cameraPool[index]._renderingOrder <= order)
  24426. index++;
  24427. this._cameraPool.splice(index, 0, camera);
  24428. }
  24429. _removeCamera(camera) {
  24430. this._cameraPool.splice(this._cameraPool.indexOf(camera), 1);
  24431. }
  24432. _preCulling(context, camera, shader, replacementTag) {
  24433. FrustumCulling.renderObjectCulling(camera, this, context, this._renders, shader, replacementTag);
  24434. }
  24435. _clear(gl, state) {
  24436. var viewport = state.viewport;
  24437. var camera = state.camera;
  24438. var renderTexture = camera._renderTexture || camera._offScreenRenderTexture;
  24439. var vpW = viewport.width;
  24440. var vpH = viewport.height;
  24441. var vpX = viewport.x;
  24442. var vpY = camera._getCanvasHeight() - viewport.y - vpH;
  24443. gl.viewport(vpX, vpY, vpW, vpH);
  24444. var flag;
  24445. var clearFlag = camera.clearFlag;
  24446. if (clearFlag === BaseCamera.CLEARFLAG_SKY && !(camera.skyRenderer._isAvailable() || this._skyRenderer._isAvailable()))
  24447. clearFlag = BaseCamera.CLEARFLAG_SOLIDCOLOR;
  24448. switch (clearFlag) {
  24449. case BaseCamera.CLEARFLAG_SOLIDCOLOR:
  24450. var clearColor = camera.clearColor;
  24451. gl.enable(gl.SCISSOR_TEST);
  24452. gl.scissor(vpX, vpY, vpW, vpH);
  24453. if (clearColor)
  24454. gl.clearColor(clearColor.x, clearColor.y, clearColor.z, clearColor.w);
  24455. else
  24456. gl.clearColor(0, 0, 0, 0);
  24457. if (renderTexture) {
  24458. flag = gl.COLOR_BUFFER_BIT;
  24459. switch (renderTexture.depthStencilFormat) {
  24460. case Laya.BaseTexture.FORMAT_DEPTH_16:
  24461. flag |= gl.DEPTH_BUFFER_BIT;
  24462. break;
  24463. case Laya.BaseTexture.FORMAT_STENCIL_8:
  24464. flag |= gl.STENCIL_BUFFER_BIT;
  24465. break;
  24466. case Laya.BaseTexture.FORMAT_DEPTHSTENCIL_16_8:
  24467. flag |= gl.DEPTH_BUFFER_BIT;
  24468. flag |= gl.STENCIL_BUFFER_BIT;
  24469. break;
  24470. }
  24471. }
  24472. else {
  24473. flag = gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT;
  24474. }
  24475. Laya.WebGLContext.setDepthMask(gl, true);
  24476. gl.clear(flag);
  24477. gl.disable(gl.SCISSOR_TEST);
  24478. break;
  24479. case BaseCamera.CLEARFLAG_SKY:
  24480. case BaseCamera.CLEARFLAG_DEPTHONLY:
  24481. gl.enable(gl.SCISSOR_TEST);
  24482. gl.scissor(vpX, vpY, vpW, vpH);
  24483. if (renderTexture) {
  24484. switch (renderTexture.depthStencilFormat) {
  24485. case Laya.BaseTexture.FORMAT_DEPTH_16:
  24486. flag = gl.DEPTH_BUFFER_BIT;
  24487. break;
  24488. case Laya.BaseTexture.FORMAT_STENCIL_8:
  24489. flag = gl.STENCIL_BUFFER_BIT;
  24490. break;
  24491. case Laya.BaseTexture.FORMAT_DEPTHSTENCIL_16_8:
  24492. flag = gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT;
  24493. break;
  24494. }
  24495. }
  24496. else {
  24497. flag = gl.DEPTH_BUFFER_BIT;
  24498. }
  24499. Laya.WebGLContext.setDepthMask(gl, true);
  24500. gl.clear(flag);
  24501. gl.disable(gl.SCISSOR_TEST);
  24502. break;
  24503. case BaseCamera.CLEARFLAG_NONE:
  24504. break;
  24505. default:
  24506. throw new Error("BaseScene:camera clearFlag invalid.");
  24507. }
  24508. }
  24509. _renderScene(context) {
  24510. var camera = context.camera;
  24511. var renderTar = camera._renderTexture || camera._offScreenRenderTexture;
  24512. renderTar ? this._opaqueQueue._render(context, true) : this._opaqueQueue._render(context, false);
  24513. if (camera.clearFlag === BaseCamera.CLEARFLAG_SKY) {
  24514. if (camera.skyRenderer._isAvailable())
  24515. camera.skyRenderer._render(context);
  24516. else if (this._skyRenderer._isAvailable())
  24517. this._skyRenderer._render(context);
  24518. }
  24519. renderTar ? this._transparentQueue._render(context, true) : this._transparentQueue._render(context, false);
  24520. if (FrustumCulling.debugFrustumCulling) {
  24521. var renderElements = this._debugTool._render._renderElements;
  24522. for (var i = 0, n = renderElements.length; i < n; i++) {
  24523. renderElements[i]._update(this, context, null, null);
  24524. renderElements[i]._render(context, false);
  24525. }
  24526. }
  24527. }
  24528. _parse(data, spriteMap) {
  24529. var lightMapsData = data.lightmaps;
  24530. if (lightMapsData) {
  24531. var lightMapCount = lightMapsData.length;
  24532. var lightmaps = [];
  24533. for (var i = 0; i < lightMapCount; i++)
  24534. lightmaps[i] = Laya.Loader.getRes(lightMapsData[i].path);
  24535. this.setlightmaps(lightmaps);
  24536. }
  24537. var ambientColorData = data.ambientColor;
  24538. if (ambientColorData) {
  24539. var ambCol = this.ambientColor;
  24540. ambCol.fromArray(ambientColorData);
  24541. this.ambientColor = ambCol;
  24542. }
  24543. var skyData = data.sky;
  24544. if (skyData) {
  24545. this._skyRenderer.material = Laya.Loader.getRes(skyData.material.path);
  24546. switch (skyData.mesh) {
  24547. case "SkyBox":
  24548. this._skyRenderer.mesh = SkyBox.instance;
  24549. break;
  24550. case "SkyDome":
  24551. this._skyRenderer.mesh = SkyDome.instance;
  24552. break;
  24553. default:
  24554. this.skyRenderer.mesh = SkyBox.instance;
  24555. }
  24556. }
  24557. var reflectionTextureData = data.reflectionTexture;
  24558. reflectionTextureData && (this.customReflection = Laya.Loader.getRes(reflectionTextureData));
  24559. this.enableFog = data.enableFog;
  24560. this.fogStart = data.fogStart;
  24561. this.fogRange = data.fogRange;
  24562. var fogColorData = data.fogColor;
  24563. if (fogColorData) {
  24564. var fogCol = this.fogColor;
  24565. fogCol.fromArray(fogColorData);
  24566. this.fogColor = fogCol;
  24567. }
  24568. }
  24569. _onActive() {
  24570. super._onActive();
  24571. Laya.ILaya.stage._scene3Ds.push(this);
  24572. }
  24573. _onInActive() {
  24574. super._onInActive();
  24575. var scenes = Laya.ILaya.stage._scene3Ds;
  24576. scenes.splice(scenes.indexOf(this), 1);
  24577. }
  24578. _addLight(light) {
  24579. if (this._lights.indexOf(light) < 0)
  24580. this._lights.push(light);
  24581. }
  24582. _removeLight(light) {
  24583. var index = this._lights.indexOf(light);
  24584. index >= 0 && (this._lights.splice(index, 1));
  24585. }
  24586. _addRenderObject(render) {
  24587. if (this._octree && render._supportOctree) {
  24588. this._octree.add(render);
  24589. }
  24590. else {
  24591. this._renders.add(render);
  24592. if (Laya.Render.supportWebGLPlusCulling) {
  24593. var indexInList = render._getIndexInList();
  24594. var length = this._cullingBufferIndices.length;
  24595. if (indexInList >= length) {
  24596. var tempIndices = this._cullingBufferIndices;
  24597. var tempResult = this._cullingBufferResult;
  24598. this._cullingBufferIndices = new Int32Array(length + 1024);
  24599. this._cullingBufferResult = new Int32Array(length + 1024);
  24600. this._cullingBufferIndices.set(tempIndices, 0);
  24601. this._cullingBufferResult.set(tempResult, 0);
  24602. }
  24603. this._cullingBufferIndices[indexInList] = render._cullingBufferIndex;
  24604. }
  24605. }
  24606. }
  24607. _removeRenderObject(render) {
  24608. if (this._octree && render._supportOctree) {
  24609. this._octree.remove(render);
  24610. }
  24611. else {
  24612. var endRender;
  24613. if (Laya.Render.supportWebGLPlusCulling) {
  24614. endRender = this._renders.elements[this._renders.length - 1];
  24615. }
  24616. this._renders.remove(render);
  24617. if (Laya.Render.supportWebGLPlusCulling) {
  24618. this._cullingBufferIndices[endRender._getIndexInList()] = endRender._cullingBufferIndex;
  24619. }
  24620. }
  24621. }
  24622. _addShadowCastRenderObject(render) {
  24623. if (this._octree) ;
  24624. else {
  24625. this._castShadowRenders.add(render);
  24626. }
  24627. }
  24628. _removeShadowCastRenderObject(render) {
  24629. if (this._octree) ;
  24630. else {
  24631. this._castShadowRenders.remove(render);
  24632. }
  24633. }
  24634. _getRenderQueue(index) {
  24635. if (index <= 2500)
  24636. return this._opaqueQueue;
  24637. else
  24638. return this._transparentQueue;
  24639. }
  24640. setlightmaps(value) {
  24641. var maps = this._lightmaps;
  24642. for (var i = 0, n = maps.length; i < n; i++)
  24643. maps[i]._removeReference();
  24644. if (value) {
  24645. var count = value.length;
  24646. maps.length = count;
  24647. for (i = 0; i < count; i++) {
  24648. var lightMap = value[i];
  24649. lightMap._addReference();
  24650. maps[i] = lightMap;
  24651. }
  24652. }
  24653. else {
  24654. throw new Error("Scene3D: value value can't be null.");
  24655. }
  24656. for (i = 0, n = this._children.length; i < n; i++)
  24657. this._setLightmapToChildNode(this._children[i]);
  24658. }
  24659. getlightmaps() {
  24660. return this._lightmaps.slice();
  24661. }
  24662. destroy(destroyChild = true) {
  24663. if (this.destroyed)
  24664. return;
  24665. super.destroy(destroyChild);
  24666. this._skyRenderer.destroy();
  24667. this._skyRenderer = null;
  24668. this._lights = null;
  24669. this._lightmaps = null;
  24670. this._renderTargetTexture = null;
  24671. this._shaderValues = null;
  24672. this._renders = null;
  24673. this._castShadowRenders = null;
  24674. this._cameraPool = null;
  24675. this._octree = null;
  24676. this.parallelSplitShadowMaps = null;
  24677. this._physicsSimulation && this._physicsSimulation._destroy();
  24678. Laya.Loader.clearRes(this.url);
  24679. }
  24680. render(ctx, x, y) {
  24681. ctx._curSubmit = Laya.SubmitBase.RENDERBASE;
  24682. this._children.length > 0 && ctx.addRenderObject(this);
  24683. }
  24684. renderSubmit() {
  24685. var gl = Laya.LayaGL.instance;
  24686. this._prepareSceneToRender();
  24687. var i, n, n1;
  24688. for (i = 0, n = this._cameraPool.length, n1 = n - 1; i < n; i++) {
  24689. if (Laya.Render.supportWebGLPlusRendering)
  24690. ShaderData.setRuntimeValueMode((i == n1) ? true : false);
  24691. var camera = this._cameraPool[i];
  24692. camera.enableRender && camera.render();
  24693. }
  24694. Laya.Context.set2DRenderConfig();
  24695. return 1;
  24696. }
  24697. getRenderType() {
  24698. return 0;
  24699. }
  24700. releaseRender() {
  24701. }
  24702. reUse(context, pos) {
  24703. return 0;
  24704. }
  24705. }
  24706. Scene3D.HIERARCHY = "HIERARCHY";
  24707. Scene3D.physicsSettings = new PhysicsSettings();
  24708. Scene3D.octreeCulling = false;
  24709. Scene3D.octreeInitialSize = 64.0;
  24710. Scene3D.octreeInitialCenter = new Vector3(0, 0, 0);
  24711. Scene3D.octreeMinNodeSize = 2.0;
  24712. Scene3D.octreeLooseness = 1.25;
  24713. Scene3D.REFLECTIONMODE_SKYBOX = 0;
  24714. Scene3D.REFLECTIONMODE_CUSTOM = 1;
  24715. Scene3D.FOGCOLOR = Shader3D.propertyNameToID("u_FogColor");
  24716. Scene3D.FOGSTART = Shader3D.propertyNameToID("u_FogStart");
  24717. Scene3D.FOGRANGE = Shader3D.propertyNameToID("u_FogRange");
  24718. Scene3D.LIGHTDIRECTION = Shader3D.propertyNameToID("u_DirectionLight.Direction");
  24719. Scene3D.LIGHTDIRCOLOR = Shader3D.propertyNameToID("u_DirectionLight.Color");
  24720. Scene3D.POINTLIGHTPOS = Shader3D.propertyNameToID("u_PointLight.Position");
  24721. Scene3D.POINTLIGHTRANGE = Shader3D.propertyNameToID("u_PointLight.Range");
  24722. Scene3D.POINTLIGHTATTENUATION = Shader3D.propertyNameToID("u_PointLight.Attenuation");
  24723. Scene3D.POINTLIGHTCOLOR = Shader3D.propertyNameToID("u_PointLight.Color");
  24724. Scene3D.SPOTLIGHTPOS = Shader3D.propertyNameToID("u_SpotLight.Position");
  24725. Scene3D.SPOTLIGHTDIRECTION = Shader3D.propertyNameToID("u_SpotLight.Direction");
  24726. Scene3D.SPOTLIGHTSPOTANGLE = Shader3D.propertyNameToID("u_SpotLight.Spot");
  24727. Scene3D.SPOTLIGHTRANGE = Shader3D.propertyNameToID("u_SpotLight.Range");
  24728. Scene3D.SPOTLIGHTCOLOR = Shader3D.propertyNameToID("u_SpotLight.Color");
  24729. Scene3D.SHADOWDISTANCE = Shader3D.propertyNameToID("u_shadowPSSMDistance");
  24730. Scene3D.SHADOWLIGHTVIEWPROJECT = Shader3D.propertyNameToID("u_lightShadowVP");
  24731. Scene3D.SHADOWMAPPCFOFFSET = Shader3D.propertyNameToID("u_shadowPCFoffset");
  24732. Scene3D.SHADOWMAPTEXTURE1 = Shader3D.propertyNameToID("u_shadowMap1");
  24733. Scene3D.SHADOWMAPTEXTURE2 = Shader3D.propertyNameToID("u_shadowMap2");
  24734. Scene3D.SHADOWMAPTEXTURE3 = Shader3D.propertyNameToID("u_shadowMap3");
  24735. Scene3D.AMBIENTCOLOR = Shader3D.propertyNameToID("u_AmbientColor");
  24736. Scene3D.REFLECTIONTEXTURE = Shader3D.propertyNameToID("u_ReflectTexture");
  24737. Scene3D.REFLETIONINTENSITY = Shader3D.propertyNameToID("u_ReflectIntensity");
  24738. Scene3D.TIME = Shader3D.propertyNameToID("u_Time");
  24739. Scene3D.ANGLEATTENUATIONTEXTURE = Shader3D.propertyNameToID("u_AngleTexture");
  24740. Scene3D.RANGEATTENUATIONTEXTURE = Shader3D.propertyNameToID("u_RangeTexture");
  24741. Scene3D.POINTLIGHTMATRIX = Shader3D.propertyNameToID("u_PointLightMatrix");
  24742. Scene3D.SPOTLIGHTMATRIX = Shader3D.propertyNameToID("u_SpotLightMatrix");
  24743. class Scene3DUtils {
  24744. static _createSprite3DInstance(nodeData, spriteMap, outBatchSprites) {
  24745. var node;
  24746. switch (nodeData.type) {
  24747. case "Scene3D":
  24748. node = new Scene3D();
  24749. break;
  24750. case "Sprite3D":
  24751. node = new Sprite3D();
  24752. break;
  24753. case "MeshSprite3D":
  24754. node = new MeshSprite3D();
  24755. (outBatchSprites) && (outBatchSprites.push(node));
  24756. break;
  24757. case "SkinnedMeshSprite3D":
  24758. node = new SkinnedMeshSprite3D();
  24759. break;
  24760. case "ShuriKenParticle3D":
  24761. node = new ShuriKenParticle3D();
  24762. break;
  24763. case "Camera":
  24764. node = new Camera();
  24765. break;
  24766. case "DirectionLight":
  24767. node = new DirectionLight();
  24768. break;
  24769. case "PointLight":
  24770. node = new PointLight();
  24771. break;
  24772. case "SpotLight":
  24773. node = new SpotLight();
  24774. break;
  24775. case "TrailSprite3D":
  24776. node = new TrailSprite3D();
  24777. break;
  24778. default:
  24779. throw new Error("Utils3D:unidentified class type in (.lh) file.");
  24780. }
  24781. var childData = nodeData.child;
  24782. if (childData) {
  24783. for (var i = 0, n = childData.length; i < n; i++) {
  24784. var child = Scene3DUtils._createSprite3DInstance(childData[i], spriteMap, outBatchSprites);
  24785. node.addChild(child);
  24786. }
  24787. }
  24788. spriteMap[nodeData.instanceID] = node;
  24789. return node;
  24790. }
  24791. static _createComponentInstance(nodeData, spriteMap) {
  24792. var node = spriteMap[nodeData.instanceID];
  24793. node._parse(nodeData.props, spriteMap);
  24794. var childData = nodeData.child;
  24795. if (childData) {
  24796. for (var i = 0, n = childData.length; i < n; i++)
  24797. Scene3DUtils._createComponentInstance(childData[i], spriteMap);
  24798. }
  24799. var componentsData = nodeData.components;
  24800. if (componentsData) {
  24801. for (var j = 0, m = componentsData.length; j < m; j++) {
  24802. var data = componentsData[j];
  24803. var clas = Laya.ClassUtils.getRegClass(data.type);
  24804. if (clas) {
  24805. var component = node.addComponent(clas);
  24806. component._parse(data);
  24807. }
  24808. else {
  24809. console.warn("Unkown component type.");
  24810. }
  24811. }
  24812. }
  24813. }
  24814. static _createNodeByJson02(nodeData, outBatchSprites) {
  24815. var spriteMap = {};
  24816. var node = Scene3DUtils._createSprite3DInstance(nodeData, spriteMap, outBatchSprites);
  24817. Scene3DUtils._createComponentInstance(nodeData, spriteMap);
  24818. return node;
  24819. }
  24820. static _parse(data, propertyParams = null, constructParams = null) {
  24821. var json = data.data;
  24822. var outBatchSprits = [];
  24823. var sprite;
  24824. switch (data.version) {
  24825. case "LAYAHIERARCHY:02":
  24826. sprite = Scene3DUtils._createNodeByJson02(json, outBatchSprits);
  24827. break;
  24828. default:
  24829. sprite = Scene3DUtils._createNodeByJson(json, outBatchSprits);
  24830. }
  24831. StaticBatchManager.combine(sprite, outBatchSprits);
  24832. return sprite;
  24833. }
  24834. static _parseScene(data, propertyParams = null, constructParams = null) {
  24835. var json = data.data;
  24836. var outBatchSprits = [];
  24837. var scene;
  24838. switch (data.version) {
  24839. case "LAYASCENE3D:02":
  24840. scene = Scene3DUtils._createNodeByJson02(json, outBatchSprits);
  24841. break;
  24842. default:
  24843. scene = Scene3DUtils._createNodeByJson(json, outBatchSprits);
  24844. }
  24845. StaticBatchManager.combine(null, outBatchSprits);
  24846. return scene;
  24847. }
  24848. static _createNodeByJson(nodeData, outBatchSprites) {
  24849. var node;
  24850. switch (nodeData.type) {
  24851. case "Scene3D":
  24852. node = new Scene3D();
  24853. break;
  24854. case "Sprite3D":
  24855. node = new Sprite3D();
  24856. break;
  24857. case "MeshSprite3D":
  24858. node = new MeshSprite3D();
  24859. (outBatchSprites) && (outBatchSprites.push(node));
  24860. break;
  24861. case "SkinnedMeshSprite3D":
  24862. node = new SkinnedMeshSprite3D();
  24863. break;
  24864. case "ShuriKenParticle3D":
  24865. node = new ShuriKenParticle3D();
  24866. break;
  24867. case "Camera":
  24868. node = new Camera();
  24869. break;
  24870. case "DirectionLight":
  24871. node = new DirectionLight();
  24872. break;
  24873. case "PointLight":
  24874. node = new PointLight();
  24875. break;
  24876. case "SpotLight":
  24877. node = new SpotLight();
  24878. break;
  24879. case "TrailSprite3D":
  24880. node = new TrailSprite3D();
  24881. break;
  24882. default:
  24883. throw new Error("Utils3D:unidentified class type in (.lh) file.");
  24884. }
  24885. var childData = nodeData.child;
  24886. if (childData) {
  24887. for (var i = 0, n = childData.length; i < n; i++) {
  24888. var child = Scene3DUtils._createNodeByJson(childData[i], outBatchSprites);
  24889. node.addChild(child);
  24890. }
  24891. }
  24892. var componentsData = nodeData.components;
  24893. if (componentsData) {
  24894. for (var j = 0, m = componentsData.length; j < m; j++) {
  24895. var data = componentsData[j];
  24896. var clas = Laya.ClassUtils.getRegClass(data.type);
  24897. if (clas) {
  24898. var component = node.addComponent(clas);
  24899. component._parse(data);
  24900. }
  24901. else {
  24902. console.warn("Unkown component type.");
  24903. }
  24904. }
  24905. }
  24906. node._parse(nodeData.props, null);
  24907. return node;
  24908. }
  24909. }
  24910. class KeyframeNode {
  24911. constructor() {
  24912. this._ownerPath = [];
  24913. this._propertys = [];
  24914. this._keyFrames = [];
  24915. }
  24916. get ownerPathCount() {
  24917. return this._ownerPath.length;
  24918. }
  24919. get propertyCount() {
  24920. return this._propertys.length;
  24921. }
  24922. get keyFramesCount() {
  24923. return this._keyFrames.length;
  24924. }
  24925. _setOwnerPathCount(value) {
  24926. this._ownerPath.length = value;
  24927. }
  24928. _setOwnerPathByIndex(index, value) {
  24929. this._ownerPath[index] = value;
  24930. }
  24931. _joinOwnerPath(sep) {
  24932. return this._ownerPath.join(sep);
  24933. }
  24934. _setPropertyCount(value) {
  24935. this._propertys.length = value;
  24936. }
  24937. _setPropertyByIndex(index, value) {
  24938. this._propertys[index] = value;
  24939. }
  24940. _joinProperty(sep) {
  24941. return this._propertys.join(sep);
  24942. }
  24943. _setKeyframeCount(value) {
  24944. this._keyFrames.length = value;
  24945. }
  24946. _setKeyframeByIndex(index, value) {
  24947. this._keyFrames[index] = value;
  24948. }
  24949. getOwnerPathByIndex(index) {
  24950. return this._ownerPath[index];
  24951. }
  24952. getPropertyByIndex(index) {
  24953. return this._propertys[index];
  24954. }
  24955. getKeyframeByIndex(index) {
  24956. return this._keyFrames[index];
  24957. }
  24958. }
  24959. if (window.conch && window.conchKeyframeNode) {
  24960. KeyframeNode = window.conchKeyframeNode;
  24961. }
  24962. if (window.qq && window.qq.webglPlus) {
  24963. KeyframeNode = window.qq.webglPlus.conchKeyframeNode;
  24964. }
  24965. class AnimationEvent {
  24966. constructor() {
  24967. }
  24968. }
  24969. class QuaternionKeyframe extends Keyframe {
  24970. constructor() {
  24971. super();
  24972. this.inTangent = new Vector4();
  24973. this.outTangent = new Vector4();
  24974. this.value = new Quaternion();
  24975. }
  24976. cloneTo(dest) {
  24977. super.cloneTo(dest);
  24978. var destKeyFarme = dest;
  24979. this.inTangent.cloneTo(destKeyFarme.inTangent);
  24980. this.outTangent.cloneTo(destKeyFarme.outTangent);
  24981. this.value.cloneTo(destKeyFarme.value);
  24982. }
  24983. }
  24984. if (window.conch && window.conchFloatArrayKeyframe) {
  24985. QuaternionKeyframe = window.conchFloatArrayKeyframe;
  24986. }
  24987. if (window.qq && window.qq.webglPlus) {
  24988. QuaternionKeyframe = window.qq.webglPlus.conchFloatArrayKeyframe;
  24989. }
  24990. class Vector3Keyframe extends Keyframe {
  24991. constructor() {
  24992. super();
  24993. this.inTangent = new Vector3();
  24994. this.outTangent = new Vector3();
  24995. this.value = new Vector3();
  24996. }
  24997. cloneTo(dest) {
  24998. super.cloneTo(dest);
  24999. var destKeyFarme = dest;
  25000. this.inTangent.cloneTo(destKeyFarme.inTangent);
  25001. this.outTangent.cloneTo(destKeyFarme.outTangent);
  25002. this.value.cloneTo(destKeyFarme.value);
  25003. }
  25004. }
  25005. if (window.conch && window.conchFloatArrayKeyframe) {
  25006. Vector3Keyframe = window.conchFloatArrayKeyframe;
  25007. }
  25008. if (window.qq && window.qq.webglPlus) {
  25009. Vector3Keyframe = window.qq.webglPlus.conchFloatArrayKeyframe;
  25010. }
  25011. class ConchVector4 {
  25012. constructor(x = 0, y = 0, z = 0, w = 0) {
  25013. var v = this.elements = new Float32Array(4);
  25014. v[0] = x;
  25015. v[1] = y;
  25016. v[2] = z;
  25017. v[3] = w;
  25018. }
  25019. get x() {
  25020. return this.elements[0];
  25021. }
  25022. set x(value) {
  25023. this.elements[0] = value;
  25024. }
  25025. get y() {
  25026. return this.elements[1];
  25027. }
  25028. set y(value) {
  25029. this.elements[1] = value;
  25030. }
  25031. get z() {
  25032. return this.elements[2];
  25033. }
  25034. set z(value) {
  25035. this.elements[2] = value;
  25036. }
  25037. get w() {
  25038. return this.elements[3];
  25039. }
  25040. set w(value) {
  25041. this.elements[3] = value;
  25042. }
  25043. fromArray(array, offset = 0) {
  25044. this.elements[0] = array[offset + 0];
  25045. this.elements[1] = array[offset + 1];
  25046. this.elements[2] = array[offset + 2];
  25047. this.elements[3] = array[offset + 3];
  25048. }
  25049. cloneTo(destObject) {
  25050. var destVector4 = destObject;
  25051. var destE = destVector4.elements;
  25052. var s = this.elements;
  25053. destE[0] = s[0];
  25054. destE[1] = s[1];
  25055. destE[2] = s[2];
  25056. destE[3] = s[3];
  25057. }
  25058. clone() {
  25059. var destVector4 = new ConchVector4();
  25060. this.cloneTo(destVector4);
  25061. return destVector4;
  25062. }
  25063. static lerp(a, b, t, out) {
  25064. var e = out.elements;
  25065. var f = a.elements;
  25066. var g = b.elements;
  25067. var ax = f[0], ay = f[1], az = f[2], aw = f[3];
  25068. e[0] = ax + t * (g[0] - ax);
  25069. e[1] = ay + t * (g[1] - ay);
  25070. e[2] = az + t * (g[2] - az);
  25071. e[3] = aw + t * (g[3] - aw);
  25072. }
  25073. static transformByM4x4(vector4, m4x4, out) {
  25074. var ve = vector4.elements;
  25075. var vx = ve[0];
  25076. var vy = ve[1];
  25077. var vz = ve[2];
  25078. var vw = ve[3];
  25079. var me = m4x4.elements;
  25080. var oe = out.elements;
  25081. oe[0] = vx * me[0] + vy * me[4] + vz * me[8] + vw * me[12];
  25082. oe[1] = vx * me[1] + vy * me[5] + vz * me[9] + vw * me[13];
  25083. oe[2] = vx * me[2] + vy * me[6] + vz * me[10] + vw * me[14];
  25084. oe[3] = vx * me[3] + vy * me[7] + vz * me[11] + vw * me[15];
  25085. }
  25086. static equals(a, b) {
  25087. var ae = a.elements;
  25088. var be = b.elements;
  25089. 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]));
  25090. }
  25091. length() {
  25092. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
  25093. }
  25094. lengthSquared() {
  25095. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  25096. }
  25097. static normalize(s, out) {
  25098. var se = s.elements;
  25099. var oe = out.elements;
  25100. var len = s.length();
  25101. if (len > 0) {
  25102. oe[0] = se[0] * len;
  25103. oe[1] = se[1] * len;
  25104. oe[2] = se[2] * len;
  25105. oe[3] = se[3] * len;
  25106. }
  25107. }
  25108. static add(a, b, out) {
  25109. var oe = out.elements;
  25110. var ae = a.elements;
  25111. var be = b.elements;
  25112. oe[0] = ae[0] + be[0];
  25113. oe[1] = ae[1] + be[1];
  25114. oe[2] = ae[2] + be[2];
  25115. oe[3] = ae[3] + be[3];
  25116. }
  25117. static subtract(a, b, out) {
  25118. var oe = out.elements;
  25119. var ae = a.elements;
  25120. var be = b.elements;
  25121. oe[0] = ae[0] - be[0];
  25122. oe[1] = ae[1] - be[1];
  25123. oe[2] = ae[2] - be[2];
  25124. oe[3] = ae[3] - be[3];
  25125. }
  25126. static multiply(a, b, out) {
  25127. var oe = out.elements;
  25128. var ae = a.elements;
  25129. var be = b.elements;
  25130. oe[0] = ae[0] * be[0];
  25131. oe[1] = ae[1] * be[1];
  25132. oe[2] = ae[2] * be[2];
  25133. oe[3] = ae[3] * be[3];
  25134. }
  25135. static scale(a, b, out) {
  25136. var oe = out.elements;
  25137. var ae = a.elements;
  25138. oe[0] = ae[0] * b;
  25139. oe[1] = ae[1] * b;
  25140. oe[2] = ae[2] * b;
  25141. oe[3] = ae[3] * b;
  25142. }
  25143. static Clamp(value, min, max, out) {
  25144. var valuee = value.elements;
  25145. var x = valuee[0];
  25146. var y = valuee[1];
  25147. var z = valuee[2];
  25148. var w = valuee[3];
  25149. var mine = min.elements;
  25150. var mineX = mine[0];
  25151. var mineY = mine[1];
  25152. var mineZ = mine[2];
  25153. var mineW = mine[3];
  25154. var maxe = max.elements;
  25155. var maxeX = maxe[0];
  25156. var maxeY = maxe[1];
  25157. var maxeZ = maxe[2];
  25158. var maxeW = maxe[3];
  25159. var oute = out.elements;
  25160. x = (x > maxeX) ? maxeX : x;
  25161. x = (x < mineX) ? mineX : x;
  25162. y = (y > maxeY) ? maxeY : y;
  25163. y = (y < mineY) ? mineY : y;
  25164. z = (z > maxeZ) ? maxeZ : z;
  25165. z = (z < mineZ) ? mineZ : z;
  25166. w = (w > maxeW) ? maxeW : w;
  25167. w = (w < mineW) ? mineW : w;
  25168. oute[0] = x;
  25169. oute[1] = y;
  25170. oute[2] = z;
  25171. oute[3] = w;
  25172. }
  25173. static distanceSquared(value1, value2) {
  25174. var value1e = value1.elements;
  25175. var value2e = value2.elements;
  25176. var x = value1e[0] - value2e[0];
  25177. var y = value1e[1] - value2e[1];
  25178. var z = value1e[2] - value2e[2];
  25179. var w = value1e[3] - value2e[3];
  25180. return (x * x) + (y * y) + (z * z) + (w * w);
  25181. }
  25182. static distance(value1, value2) {
  25183. var value1e = value1.elements;
  25184. var value2e = value2.elements;
  25185. var x = value1e[0] - value2e[0];
  25186. var y = value1e[1] - value2e[1];
  25187. var z = value1e[2] - value2e[2];
  25188. var w = value1e[3] - value2e[3];
  25189. return Math.sqrt((x * x) + (y * y) + (z * z) + (w * w));
  25190. }
  25191. static dot(a, b) {
  25192. var ae = a.elements;
  25193. var be = b.elements;
  25194. var r = (ae[0] * be[0]) + (ae[1] * be[1]) + (ae[2] * be[2]) + (ae[3] * be[3]);
  25195. return r;
  25196. }
  25197. static min(a, b, out) {
  25198. var e = out.elements;
  25199. var f = a.elements;
  25200. var g = b.elements;
  25201. e[0] = Math.min(f[0], g[0]);
  25202. e[1] = Math.min(f[1], g[1]);
  25203. e[2] = Math.min(f[2], g[2]);
  25204. e[3] = Math.min(f[3], g[3]);
  25205. }
  25206. static max(a, b, out) {
  25207. var e = out.elements;
  25208. var f = a.elements;
  25209. var g = b.elements;
  25210. e[0] = Math.max(f[0], g[0]);
  25211. e[1] = Math.max(f[1], g[1]);
  25212. e[2] = Math.max(f[2], g[2]);
  25213. e[3] = Math.max(f[3], g[3]);
  25214. }
  25215. }
  25216. ConchVector4.ZERO = new ConchVector4();
  25217. ConchVector4.ONE = new ConchVector4(1.0, 1.0, 1.0, 1.0);
  25218. ConchVector4.UnitX = new ConchVector4(1.0, 0.0, 0.0, 0.0);
  25219. ConchVector4.UnitY = new ConchVector4(0.0, 1.0, 0.0, 0.0);
  25220. ConchVector4.UnitZ = new ConchVector4(0.0, 0.0, 1.0, 0.0);
  25221. ConchVector4.UnitW = new ConchVector4(0.0, 0.0, 0.0, 1.0);
  25222. class ConchVector3 {
  25223. constructor(x = 0, y = 0, z = 0, nativeElements = null) {
  25224. var v;
  25225. if (nativeElements) {
  25226. v = nativeElements;
  25227. }
  25228. else {
  25229. v = new Float32Array(3);
  25230. }
  25231. this.elements = v;
  25232. v[0] = x;
  25233. v[1] = y;
  25234. v[2] = z;
  25235. }
  25236. static distanceSquared(value1, value2) {
  25237. var value1e = value1.elements;
  25238. var value2e = value2.elements;
  25239. var x = value1e[0] - value2e[0];
  25240. var y = value1e[1] - value2e[1];
  25241. var z = value1e[2] - value2e[2];
  25242. return (x * x) + (y * y) + (z * z);
  25243. }
  25244. static distance(value1, value2) {
  25245. var value1e = value1.elements;
  25246. var value2e = value2.elements;
  25247. var x = value1e[0] - value2e[0];
  25248. var y = value1e[1] - value2e[1];
  25249. var z = value1e[2] - value2e[2];
  25250. return Math.sqrt((x * x) + (y * y) + (z * z));
  25251. }
  25252. static min(a, b, out) {
  25253. var e = out.elements;
  25254. var f = a.elements;
  25255. var g = b.elements;
  25256. e[0] = Math.min(f[0], g[0]);
  25257. e[1] = Math.min(f[1], g[1]);
  25258. e[2] = Math.min(f[2], g[2]);
  25259. }
  25260. static max(a, b, out) {
  25261. var e = out.elements;
  25262. var f = a.elements;
  25263. var g = b.elements;
  25264. e[0] = Math.max(f[0], g[0]);
  25265. e[1] = Math.max(f[1], g[1]);
  25266. e[2] = Math.max(f[2], g[2]);
  25267. }
  25268. static transformQuat(source, rotation, out) {
  25269. var destination = out.elements;
  25270. var se = source.elements;
  25271. var re = rotation.elements;
  25272. 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;
  25273. destination[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy;
  25274. destination[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz;
  25275. destination[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx;
  25276. }
  25277. static scalarLength(a) {
  25278. var f = a.elements;
  25279. var x = f[0], y = f[1], z = f[2];
  25280. return Math.sqrt(x * x + y * y + z * z);
  25281. }
  25282. static scalarLengthSquared(a) {
  25283. var f = a.elements;
  25284. var x = f[0], y = f[1], z = f[2];
  25285. return x * x + y * y + z * z;
  25286. }
  25287. static normalize(s, out) {
  25288. var se = s.elements;
  25289. var oe = out.elements;
  25290. var x = se[0], y = se[1], z = se[2];
  25291. var len = x * x + y * y + z * z;
  25292. if (len > 0) {
  25293. len = 1 / Math.sqrt(len);
  25294. oe[0] = se[0] * len;
  25295. oe[1] = se[1] * len;
  25296. oe[2] = se[2] * len;
  25297. }
  25298. }
  25299. static multiply(a, b, out) {
  25300. var e = out.elements;
  25301. var f = a.elements;
  25302. var g = b.elements;
  25303. e[0] = f[0] * g[0];
  25304. e[1] = f[1] * g[1];
  25305. e[2] = f[2] * g[2];
  25306. }
  25307. static scale(a, b, out) {
  25308. var e = out.elements;
  25309. var f = a.elements;
  25310. e[0] = f[0] * b;
  25311. e[1] = f[1] * b;
  25312. e[2] = f[2] * b;
  25313. }
  25314. static lerp(a, b, t, out) {
  25315. var e = out.elements;
  25316. var f = a.elements;
  25317. var g = b.elements;
  25318. var ax = f[0], ay = f[1], az = f[2];
  25319. e[0] = ax + t * (g[0] - ax);
  25320. e[1] = ay + t * (g[1] - ay);
  25321. e[2] = az + t * (g[2] - az);
  25322. }
  25323. static transformV3ToV3(vector, transform, result) {
  25324. var intermediate = ConchVector3._tempVector4;
  25325. ConchVector3.transformV3ToV4(vector, transform, intermediate);
  25326. var intermediateElem = intermediate.elements;
  25327. var resultElem = result.elements;
  25328. resultElem[0] = intermediateElem[0];
  25329. resultElem[1] = intermediateElem[1];
  25330. resultElem[2] = intermediateElem[2];
  25331. }
  25332. static transformV3ToV4(vector, transform, result) {
  25333. var vectorElem = vector.elements;
  25334. var vectorX = vectorElem[0];
  25335. var vectorY = vectorElem[1];
  25336. var vectorZ = vectorElem[2];
  25337. var transformElem = transform.elements;
  25338. var resultElem = result.elements;
  25339. resultElem[0] = (vectorX * transformElem[0]) + (vectorY * transformElem[4]) + (vectorZ * transformElem[8]) + transformElem[12];
  25340. resultElem[1] = (vectorX * transformElem[1]) + (vectorY * transformElem[5]) + (vectorZ * transformElem[9]) + transformElem[13];
  25341. resultElem[2] = (vectorX * transformElem[2]) + (vectorY * transformElem[6]) + (vectorZ * transformElem[10]) + transformElem[14];
  25342. resultElem[3] = (vectorX * transformElem[3]) + (vectorY * transformElem[7]) + (vectorZ * transformElem[11]) + transformElem[15];
  25343. }
  25344. static TransformNormal(normal, transform, result) {
  25345. var normalElem = normal.elements;
  25346. var normalX = normalElem[0];
  25347. var normalY = normalElem[1];
  25348. var normalZ = normalElem[2];
  25349. var transformElem = transform.elements;
  25350. var resultElem = result.elements;
  25351. resultElem[0] = (normalX * transformElem[0]) + (normalY * transformElem[4]) + (normalZ * transformElem[8]);
  25352. resultElem[1] = (normalX * transformElem[1]) + (normalY * transformElem[5]) + (normalZ * transformElem[9]);
  25353. resultElem[2] = (normalX * transformElem[2]) + (normalY * transformElem[6]) + (normalZ * transformElem[10]);
  25354. }
  25355. static transformCoordinate(coordinate, transform, result) {
  25356. var coordinateElem = coordinate.elements;
  25357. var coordinateX = coordinateElem[0];
  25358. var coordinateY = coordinateElem[1];
  25359. var coordinateZ = coordinateElem[2];
  25360. var transformElem = transform.elements;
  25361. var w = ((coordinateX * transformElem[3]) + (coordinateY * transformElem[7]) + (coordinateZ * transformElem[11]) + transformElem[15]);
  25362. var resultElem = result.elements;
  25363. resultElem[0] = (coordinateX * transformElem[0]) + (coordinateY * transformElem[4]) + (coordinateZ * transformElem[8]) + transformElem[12] / w;
  25364. resultElem[1] = (coordinateX * transformElem[1]) + (coordinateY * transformElem[5]) + (coordinateZ * transformElem[9]) + transformElem[13] / w;
  25365. resultElem[2] = (coordinateX * transformElem[2]) + (coordinateY * transformElem[6]) + (coordinateZ * transformElem[10]) + transformElem[14] / w;
  25366. }
  25367. static Clamp(value, min, max, out) {
  25368. var valuee = value.elements;
  25369. var x = valuee[0];
  25370. var y = valuee[1];
  25371. var z = valuee[2];
  25372. var mine = min.elements;
  25373. var mineX = mine[0];
  25374. var mineY = mine[1];
  25375. var mineZ = mine[2];
  25376. var maxe = max.elements;
  25377. var maxeX = maxe[0];
  25378. var maxeY = maxe[1];
  25379. var maxeZ = maxe[2];
  25380. var oute = out.elements;
  25381. x = (x > maxeX) ? maxeX : x;
  25382. x = (x < mineX) ? mineX : x;
  25383. y = (y > maxeY) ? maxeY : y;
  25384. y = (y < mineY) ? mineY : y;
  25385. z = (z > maxeZ) ? maxeZ : z;
  25386. z = (z < mineZ) ? mineZ : z;
  25387. oute[0] = x;
  25388. oute[1] = y;
  25389. oute[2] = z;
  25390. }
  25391. static add(a, b, out) {
  25392. var e = out.elements;
  25393. var f = a.elements;
  25394. var g = b.elements;
  25395. e[0] = f[0] + g[0];
  25396. e[1] = f[1] + g[1];
  25397. e[2] = f[2] + g[2];
  25398. }
  25399. static subtract(a, b, o) {
  25400. var oe = o.elements;
  25401. var ae = a.elements;
  25402. var be = b.elements;
  25403. oe[0] = ae[0] - be[0];
  25404. oe[1] = ae[1] - be[1];
  25405. oe[2] = ae[2] - be[2];
  25406. }
  25407. static cross(a, b, o) {
  25408. var ae = a.elements;
  25409. var be = b.elements;
  25410. var oe = o.elements;
  25411. var ax = ae[0], ay = ae[1], az = ae[2], bx = be[0], by = be[1], bz = be[2];
  25412. oe[0] = ay * bz - az * by;
  25413. oe[1] = az * bx - ax * bz;
  25414. oe[2] = ax * by - ay * bx;
  25415. }
  25416. static dot(a, b) {
  25417. var ae = a.elements;
  25418. var be = b.elements;
  25419. var r = (ae[0] * be[0]) + (ae[1] * be[1]) + (ae[2] * be[2]);
  25420. return r;
  25421. }
  25422. static equals(a, b) {
  25423. var ae = a.elements;
  25424. var be = b.elements;
  25425. return MathUtils3D.nearEqual(ae[0], be[0]) && MathUtils3D.nearEqual(ae[1], be[1]) && MathUtils3D.nearEqual(ae[2], be[2]);
  25426. }
  25427. get x() {
  25428. return this.elements[0];
  25429. }
  25430. set x(value) {
  25431. this.elements[0] = value;
  25432. }
  25433. get y() {
  25434. return this.elements[1];
  25435. }
  25436. set y(value) {
  25437. this.elements[1] = value;
  25438. }
  25439. get z() {
  25440. return this.elements[2];
  25441. }
  25442. set z(value) {
  25443. this.elements[2] = value;
  25444. }
  25445. setValue(x, y, z) {
  25446. this.elements[0] = x;
  25447. this.elements[1] = y;
  25448. this.elements[2] = z;
  25449. }
  25450. fromArray(array, offset = 0) {
  25451. this.elements[0] = array[offset + 0];
  25452. this.elements[1] = array[offset + 1];
  25453. this.elements[2] = array[offset + 2];
  25454. }
  25455. cloneTo(destObject) {
  25456. var destVector3 = destObject;
  25457. var destE = destVector3.elements;
  25458. var s = this.elements;
  25459. destE[0] = s[0];
  25460. destE[1] = s[1];
  25461. destE[2] = s[2];
  25462. }
  25463. clone() {
  25464. var destVector3 = new ConchVector3();
  25465. this.cloneTo(destVector3);
  25466. return destVector3;
  25467. }
  25468. toDefault() {
  25469. this.elements[0] = 0;
  25470. this.elements[1] = 0;
  25471. this.elements[2] = 0;
  25472. }
  25473. }
  25474. ConchVector3._tempVector4 = new ConchVector4();
  25475. ConchVector3.ZERO = new ConchVector3(0.0, 0.0, 0.0);
  25476. ConchVector3.ONE = new ConchVector3(1.0, 1.0, 1.0);
  25477. ConchVector3.NegativeUnitX = new ConchVector3(-1, 0, 0);
  25478. ConchVector3.UnitX = new ConchVector3(1, 0, 0);
  25479. ConchVector3.UnitY = new ConchVector3(0, 1, 0);
  25480. ConchVector3.UnitZ = new ConchVector3(0, 0, 1);
  25481. ConchVector3.ForwardRH = new ConchVector3(0, 0, -1);
  25482. ConchVector3.ForwardLH = new ConchVector3(0, 0, 1);
  25483. ConchVector3.Up = new ConchVector3(0, 1, 0);
  25484. ConchVector3.NAN = new ConchVector3(NaN, NaN, NaN);
  25485. class ConchQuaternion {
  25486. constructor(x = 0, y = 0, z = 0, w = 1, nativeElements = null) {
  25487. var v;
  25488. if (nativeElements) {
  25489. v = nativeElements;
  25490. }
  25491. else {
  25492. v = new Float32Array(4);
  25493. }
  25494. v[0] = x;
  25495. v[1] = y;
  25496. v[2] = z;
  25497. v[3] = w;
  25498. this.elements = v;
  25499. }
  25500. static _dotArray(l, r) {
  25501. return l[0] * r[0] + l[1] * r[1] + l[2] * r[2] + l[3] * r[3];
  25502. }
  25503. static _normalizeArray(f, o) {
  25504. var x = f[0], y = f[1], z = f[2], w = f[3];
  25505. var len = x * x + y * y + z * z + w * w;
  25506. if (len > 0) {
  25507. len = 1 / Math.sqrt(len);
  25508. o[0] = x * len;
  25509. o[1] = y * len;
  25510. o[2] = z * len;
  25511. o[3] = w * len;
  25512. }
  25513. }
  25514. static _lerpArray(l, r, amount, o) {
  25515. var inverse = 1.0 - amount;
  25516. if (ConchQuaternion._dotArray(l, r) >= 0) {
  25517. o[0] = (inverse * l[0]) + (amount * r[0]);
  25518. o[1] = (inverse * l[1]) + (amount * r[1]);
  25519. o[2] = (inverse * l[2]) + (amount * r[2]);
  25520. o[3] = (inverse * l[3]) + (amount * r[3]);
  25521. }
  25522. else {
  25523. o[0] = (inverse * l[0]) - (amount * r[0]);
  25524. o[1] = (inverse * l[1]) - (amount * r[1]);
  25525. o[2] = (inverse * l[2]) - (amount * r[2]);
  25526. o[3] = (inverse * l[3]) - (amount * r[3]);
  25527. }
  25528. ConchQuaternion._normalizeArray(o, o);
  25529. }
  25530. static createFromYawPitchRoll(yaw, pitch, roll, out) {
  25531. var halfRoll = roll * 0.5;
  25532. var halfPitch = pitch * 0.5;
  25533. var halfYaw = yaw * 0.5;
  25534. var sinRoll = Math.sin(halfRoll);
  25535. var cosRoll = Math.cos(halfRoll);
  25536. var sinPitch = Math.sin(halfPitch);
  25537. var cosPitch = Math.cos(halfPitch);
  25538. var sinYaw = Math.sin(halfYaw);
  25539. var cosYaw = Math.cos(halfYaw);
  25540. var oe = out.elements;
  25541. oe[0] = (cosYaw * sinPitch * cosRoll) + (sinYaw * cosPitch * sinRoll);
  25542. oe[1] = (sinYaw * cosPitch * cosRoll) - (cosYaw * sinPitch * sinRoll);
  25543. oe[2] = (cosYaw * cosPitch * sinRoll) - (sinYaw * sinPitch * cosRoll);
  25544. oe[3] = (cosYaw * cosPitch * cosRoll) + (sinYaw * sinPitch * sinRoll);
  25545. }
  25546. static multiply(left, right, out) {
  25547. var le = left.elements;
  25548. var re = right.elements;
  25549. var oe = out.elements;
  25550. var lx = le[0];
  25551. var ly = le[1];
  25552. var lz = le[2];
  25553. var lw = le[3];
  25554. var rx = re[0];
  25555. var ry = re[1];
  25556. var rz = re[2];
  25557. var rw = re[3];
  25558. var a = (ly * rz - lz * ry);
  25559. var b = (lz * rx - lx * rz);
  25560. var c = (lx * ry - ly * rx);
  25561. var d = (lx * rx + ly * ry + lz * rz);
  25562. oe[0] = (lx * rw + rx * lw) + a;
  25563. oe[1] = (ly * rw + ry * lw) + b;
  25564. oe[2] = (lz * rw + rz * lw) + c;
  25565. oe[3] = lw * rw - d;
  25566. }
  25567. static arcTanAngle(x, y) {
  25568. if (x == 0) {
  25569. if (y == 1)
  25570. return Math.PI / 2;
  25571. return -Math.PI / 2;
  25572. }
  25573. if (x > 0)
  25574. return Math.atan(y / x);
  25575. if (x < 0) {
  25576. if (y > 0)
  25577. return Math.atan(y / x) + Math.PI;
  25578. return Math.atan(y / x) - Math.PI;
  25579. }
  25580. return 0;
  25581. }
  25582. static angleTo(from, location, angle) {
  25583. ConchVector3.subtract(location, from, ConchQuaternion.TEMPVector30);
  25584. ConchVector3.normalize(ConchQuaternion.TEMPVector30, ConchQuaternion.TEMPVector30);
  25585. angle.elements[0] = Math.asin(ConchQuaternion.TEMPVector30.y);
  25586. angle.elements[1] = ConchQuaternion.arcTanAngle(-ConchQuaternion.TEMPVector30.z, -ConchQuaternion.TEMPVector30.x);
  25587. }
  25588. static createFromAxisAngle(axis, rad, out) {
  25589. var e = out.elements;
  25590. var f = axis.elements;
  25591. rad = rad * 0.5;
  25592. var s = Math.sin(rad);
  25593. e[0] = s * f[0];
  25594. e[1] = s * f[1];
  25595. e[2] = s * f[2];
  25596. e[3] = Math.cos(rad);
  25597. }
  25598. static createFromMatrix3x3(sou, out) {
  25599. var e = out.elements;
  25600. var f = sou.elements;
  25601. var fTrace = f[0] + f[4] + f[8];
  25602. var fRoot;
  25603. if (fTrace > 0.0) {
  25604. fRoot = Math.sqrt(fTrace + 1.0);
  25605. e[3] = 0.5 * fRoot;
  25606. fRoot = 0.5 / fRoot;
  25607. e[0] = (f[5] - f[7]) * fRoot;
  25608. e[1] = (f[6] - f[2]) * fRoot;
  25609. e[2] = (f[1] - f[3]) * fRoot;
  25610. }
  25611. else {
  25612. var i = 0;
  25613. if (f[4] > f[0])
  25614. i = 1;
  25615. if (f[8] > f[i * 3 + i])
  25616. i = 2;
  25617. var j = (i + 1) % 3;
  25618. var k = (i + 2) % 3;
  25619. fRoot = Math.sqrt(f[i * 3 + i] - f[j * 3 + j] - f[k * 3 + k] + 1.0);
  25620. e[i] = 0.5 * fRoot;
  25621. fRoot = 0.5 / fRoot;
  25622. e[3] = (f[j * 3 + k] - f[k * 3 + j]) * fRoot;
  25623. e[j] = (f[j * 3 + i] + f[i * 3 + j]) * fRoot;
  25624. e[k] = (f[k * 3 + i] + f[i * 3 + k]) * fRoot;
  25625. }
  25626. return;
  25627. }
  25628. static createFromMatrix4x4(mat, out) {
  25629. var me = mat.elements;
  25630. var oe = out.elements;
  25631. var sqrt;
  25632. var half;
  25633. var scale = me[0] + me[5] + me[10];
  25634. if (scale > 0.0) {
  25635. sqrt = Math.sqrt(scale + 1.0);
  25636. oe[3] = sqrt * 0.5;
  25637. sqrt = 0.5 / sqrt;
  25638. oe[0] = (me[6] - me[9]) * sqrt;
  25639. oe[1] = (me[8] - me[2]) * sqrt;
  25640. oe[2] = (me[1] - me[4]) * sqrt;
  25641. }
  25642. else if ((me[0] >= me[5]) && (me[0] >= me[10])) {
  25643. sqrt = Math.sqrt(1.0 + me[0] - me[5] - me[10]);
  25644. half = 0.5 / sqrt;
  25645. oe[0] = 0.5 * sqrt;
  25646. oe[1] = (me[1] + me[4]) * half;
  25647. oe[2] = (me[2] + me[8]) * half;
  25648. oe[3] = (me[6] - me[9]) * half;
  25649. }
  25650. else if (me[5] > me[10]) {
  25651. sqrt = Math.sqrt(1.0 + me[5] - me[0] - me[10]);
  25652. half = 0.5 / sqrt;
  25653. oe[0] = (me[4] + me[1]) * half;
  25654. oe[1] = 0.5 * sqrt;
  25655. oe[2] = (me[9] + me[6]) * half;
  25656. oe[3] = (me[8] - me[2]) * half;
  25657. }
  25658. else {
  25659. sqrt = Math.sqrt(1.0 + me[10] - me[0] - me[5]);
  25660. half = 0.5 / sqrt;
  25661. oe[0] = (me[8] + me[2]) * half;
  25662. oe[1] = (me[9] + me[6]) * half;
  25663. oe[2] = 0.5 * sqrt;
  25664. oe[3] = (me[1] - me[4]) * half;
  25665. }
  25666. }
  25667. static slerp(left, right, t, out) {
  25668. var a = left.elements;
  25669. var b = right.elements;
  25670. var oe = out.elements;
  25671. 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];
  25672. var omega, cosom, sinom, scale0, scale1;
  25673. cosom = ax * bx + ay * by + az * bz + aw * bw;
  25674. if (cosom < 0.0) {
  25675. cosom = -cosom;
  25676. bx = -bx;
  25677. by = -by;
  25678. bz = -bz;
  25679. bw = -bw;
  25680. }
  25681. if ((1.0 - cosom) > 0.000001) {
  25682. omega = Math.acos(cosom);
  25683. sinom = Math.sin(omega);
  25684. scale0 = Math.sin((1.0 - t) * omega) / sinom;
  25685. scale1 = Math.sin(t * omega) / sinom;
  25686. }
  25687. else {
  25688. scale0 = 1.0 - t;
  25689. scale1 = t;
  25690. }
  25691. oe[0] = scale0 * ax + scale1 * bx;
  25692. oe[1] = scale0 * ay + scale1 * by;
  25693. oe[2] = scale0 * az + scale1 * bz;
  25694. oe[3] = scale0 * aw + scale1 * bw;
  25695. return oe;
  25696. }
  25697. static lerp(left, right, amount, out) {
  25698. ConchQuaternion._lerpArray(left.elements, right.elements, amount, out.elements);
  25699. }
  25700. static add(left, right, out) {
  25701. var e = out.elements;
  25702. var f = left.elements;
  25703. var g = right.elements;
  25704. e[0] = f[0] + g[0];
  25705. e[1] = f[1] + g[1];
  25706. e[2] = f[2] + g[2];
  25707. e[3] = f[3] + g[3];
  25708. }
  25709. static dot(left, right) {
  25710. return ConchQuaternion._dotArray(left.elements, right.elements);
  25711. }
  25712. get x() {
  25713. return this.elements[0];
  25714. }
  25715. set x(value) {
  25716. this.elements[0] = value;
  25717. }
  25718. get y() {
  25719. return this.elements[1];
  25720. }
  25721. set y(value) {
  25722. this.elements[1] = value;
  25723. }
  25724. get z() {
  25725. return this.elements[2];
  25726. }
  25727. set z(value) {
  25728. this.elements[2] = value;
  25729. }
  25730. get w() {
  25731. return this.elements[3];
  25732. }
  25733. set w(value) {
  25734. this.elements[3] = value;
  25735. }
  25736. scaling(scaling, out) {
  25737. var e = out.elements;
  25738. var f = this.elements;
  25739. e[0] = f[0] * scaling;
  25740. e[1] = f[1] * scaling;
  25741. e[2] = f[2] * scaling;
  25742. e[3] = f[3] * scaling;
  25743. }
  25744. normalize(out) {
  25745. ConchQuaternion._normalizeArray(this.elements, out.elements);
  25746. }
  25747. length() {
  25748. var f = this.elements;
  25749. var x = f[0], y = f[1], z = f[2], w = f[3];
  25750. return Math.sqrt(x * x + y * y + z * z + w * w);
  25751. }
  25752. rotateX(rad, out) {
  25753. var e = out.elements;
  25754. var f = this.elements;
  25755. rad *= 0.5;
  25756. var ax = f[0], ay = f[1], az = f[2], aw = f[3];
  25757. var bx = Math.sin(rad), bw = Math.cos(rad);
  25758. e[0] = ax * bw + aw * bx;
  25759. e[1] = ay * bw + az * bx;
  25760. e[2] = az * bw - ay * bx;
  25761. e[3] = aw * bw - ax * bx;
  25762. }
  25763. rotateY(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], by = Math.sin(rad), bw = Math.cos(rad);
  25768. e[0] = ax * bw - az * by;
  25769. e[1] = ay * bw + aw * by;
  25770. e[2] = az * bw + ax * by;
  25771. e[3] = aw * bw - ay * by;
  25772. }
  25773. rotateZ(rad, out) {
  25774. var e = out.elements;
  25775. var f = this.elements;
  25776. rad *= 0.5;
  25777. var ax = f[0], ay = f[1], az = f[2], aw = f[3], bz = Math.sin(rad), bw = Math.cos(rad);
  25778. e[0] = ax * bw + ay * bz;
  25779. e[1] = ay * bw - ax * bz;
  25780. e[2] = az * bw + aw * bz;
  25781. e[3] = aw * bw - az * bz;
  25782. }
  25783. getYawPitchRoll(out) {
  25784. ConchVector3.transformQuat(ConchVector3.ForwardRH, this, ConchQuaternion.TEMPVector31);
  25785. ConchVector3.transformQuat(ConchVector3.Up, this, ConchQuaternion.TEMPVector32);
  25786. var upe = ConchQuaternion.TEMPVector32.elements;
  25787. ConchQuaternion.angleTo(ConchVector3.ZERO, ConchQuaternion.TEMPVector31, ConchQuaternion.TEMPVector33);
  25788. var anglee = ConchQuaternion.TEMPVector33.elements;
  25789. if (anglee[0] == Math.PI / 2) {
  25790. anglee[1] = ConchQuaternion.arcTanAngle(upe[2], upe[0]);
  25791. anglee[2] = 0;
  25792. }
  25793. else if (anglee[0] == -Math.PI / 2) {
  25794. anglee[1] = ConchQuaternion.arcTanAngle(-upe[2], -upe[0]);
  25795. anglee[2] = 0;
  25796. }
  25797. else {
  25798. Matrix4x4.createRotationY(-anglee[1], ConchQuaternion.TEMPMatrix0);
  25799. Matrix4x4.createRotationX(-anglee[0], ConchQuaternion.TEMPMatrix1);
  25800. ConchVector3.transformCoordinate(ConchQuaternion.TEMPVector32, ConchQuaternion.TEMPMatrix0, ConchQuaternion.TEMPVector32);
  25801. ConchVector3.transformCoordinate(ConchQuaternion.TEMPVector32, ConchQuaternion.TEMPMatrix1, ConchQuaternion.TEMPVector32);
  25802. anglee[2] = ConchQuaternion.arcTanAngle(upe[1], -upe[0]);
  25803. }
  25804. if (anglee[1] <= -Math.PI)
  25805. anglee[1] = Math.PI;
  25806. if (anglee[2] <= -Math.PI)
  25807. anglee[2] = Math.PI;
  25808. if (anglee[1] >= Math.PI && anglee[2] >= Math.PI) {
  25809. anglee[1] = 0;
  25810. anglee[2] = 0;
  25811. anglee[0] = Math.PI - anglee[0];
  25812. }
  25813. var oe = out.elements;
  25814. oe[0] = anglee[1];
  25815. oe[1] = anglee[0];
  25816. oe[2] = anglee[2];
  25817. }
  25818. invert(out) {
  25819. var e = out.elements;
  25820. var f = this.elements;
  25821. var a0 = f[0], a1 = f[1], a2 = f[2], a3 = f[3];
  25822. var dot = a0 * a0 + a1 * a1 + a2 * a2 + a3 * a3;
  25823. var invDot = dot ? 1.0 / dot : 0;
  25824. e[0] = -a0 * invDot;
  25825. e[1] = -a1 * invDot;
  25826. e[2] = -a2 * invDot;
  25827. e[3] = a3 * invDot;
  25828. }
  25829. identity() {
  25830. var e = this.elements;
  25831. e[0] = 0;
  25832. e[1] = 0;
  25833. e[2] = 0;
  25834. e[3] = 1;
  25835. }
  25836. fromArray(array, offset = 0) {
  25837. this.elements[0] = array[offset + 0];
  25838. this.elements[1] = array[offset + 1];
  25839. this.elements[2] = array[offset + 2];
  25840. this.elements[3] = array[offset + 3];
  25841. }
  25842. cloneTo(destObject) {
  25843. var i, s, d;
  25844. s = this.elements;
  25845. d = destObject.elements;
  25846. if (s === d) {
  25847. return;
  25848. }
  25849. for (i = 0; i < 4; ++i) {
  25850. d[i] = s[i];
  25851. }
  25852. }
  25853. clone() {
  25854. var dest = new ConchQuaternion();
  25855. this.cloneTo(dest);
  25856. return dest;
  25857. }
  25858. equals(b) {
  25859. var ae = this.elements;
  25860. var be = b.elements;
  25861. 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]);
  25862. }
  25863. static rotationLookAt(forward, up, out) {
  25864. ConchQuaternion.lookAt(ConchVector3.ZERO, forward, up, out);
  25865. }
  25866. static lookAt(eye, target, up, out) {
  25867. Matrix3x3.lookAt(eye, target, up, ConchQuaternion._tempMatrix3x3);
  25868. ConchQuaternion.rotationMatrix(ConchQuaternion._tempMatrix3x3, out);
  25869. }
  25870. lengthSquared() {
  25871. var x = this.elements[0];
  25872. var y = this.elements[1];
  25873. var z = this.elements[2];
  25874. var w = this.elements[3];
  25875. return (x * x) + (y * y) + (z * z) + (w * w);
  25876. }
  25877. static invert(value, out) {
  25878. var vE = value.elements;
  25879. var oE = out.elements;
  25880. var lengthSq = value.lengthSquared();
  25881. if (!MathUtils3D.isZero(lengthSq)) {
  25882. lengthSq = 1.0 / lengthSq;
  25883. oE[0] = -vE[0] * lengthSq;
  25884. oE[1] = -vE[1] * lengthSq;
  25885. oE[2] = -vE[2] * lengthSq;
  25886. oE[3] = vE[3] * lengthSq;
  25887. }
  25888. }
  25889. static rotationMatrix(matrix3x3, out) {
  25890. var me = matrix3x3.elements;
  25891. var m11 = me[0];
  25892. var m12 = me[1];
  25893. var m13 = me[2];
  25894. var m21 = me[3];
  25895. var m22 = me[4];
  25896. var m23 = me[5];
  25897. var m31 = me[6];
  25898. var m32 = me[7];
  25899. var m33 = me[8];
  25900. var oe = out.elements;
  25901. var sqrt, half;
  25902. var scale = m11 + m22 + m33;
  25903. if (scale > 0) {
  25904. sqrt = Math.sqrt(scale + 1);
  25905. oe[3] = sqrt * 0.5;
  25906. sqrt = 0.5 / sqrt;
  25907. oe[0] = (m23 - m32) * sqrt;
  25908. oe[1] = (m31 - m13) * sqrt;
  25909. oe[2] = (m12 - m21) * sqrt;
  25910. }
  25911. else if ((m11 >= m22) && (m11 >= m33)) {
  25912. sqrt = Math.sqrt(1 + m11 - m22 - m33);
  25913. half = 0.5 / sqrt;
  25914. oe[0] = 0.5 * sqrt;
  25915. oe[1] = (m12 + m21) * half;
  25916. oe[2] = (m13 + m31) * half;
  25917. oe[3] = (m23 - m32) * half;
  25918. }
  25919. else if (m22 > m33) {
  25920. sqrt = Math.sqrt(1 + m22 - m11 - m33);
  25921. half = 0.5 / sqrt;
  25922. oe[0] = (m21 + m12) * half;
  25923. oe[1] = 0.5 * sqrt;
  25924. oe[2] = (m32 + m23) * half;
  25925. oe[3] = (m31 - m13) * half;
  25926. }
  25927. else {
  25928. sqrt = Math.sqrt(1 + m33 - m11 - m22);
  25929. half = 0.5 / sqrt;
  25930. oe[0] = (m31 + m13) * half;
  25931. oe[1] = (m32 + m23) * half;
  25932. oe[2] = 0.5 * sqrt;
  25933. oe[3] = (m12 - m21) * half;
  25934. }
  25935. }
  25936. }
  25937. ConchQuaternion.TEMPVector30 = new ConchVector3();
  25938. ConchQuaternion.TEMPVector31 = new ConchVector3();
  25939. ConchQuaternion.TEMPVector32 = new ConchVector3();
  25940. ConchQuaternion.TEMPVector33 = new ConchVector3();
  25941. ConchQuaternion.TEMPMatrix0 = new Matrix4x4();
  25942. ConchQuaternion.TEMPMatrix1 = new Matrix4x4();
  25943. ConchQuaternion._tempMatrix3x3 = new Matrix3x3();
  25944. ConchQuaternion.DEFAULT = new ConchQuaternion();
  25945. ConchQuaternion.NAN = new ConchQuaternion(NaN, NaN, NaN, NaN);
  25946. class AnimationClipParser03 {
  25947. static READ_DATA() {
  25948. AnimationClipParser03._DATA.offset = AnimationClipParser03._reader.getUint32();
  25949. AnimationClipParser03._DATA.size = AnimationClipParser03._reader.getUint32();
  25950. }
  25951. static READ_BLOCK() {
  25952. var count = AnimationClipParser03._BLOCK.count = AnimationClipParser03._reader.getUint16();
  25953. var blockStarts = AnimationClipParser03._BLOCK.blockStarts = [];
  25954. var blockLengths = AnimationClipParser03._BLOCK.blockLengths = [];
  25955. for (var i = 0; i < count; i++) {
  25956. blockStarts.push(AnimationClipParser03._reader.getUint32());
  25957. blockLengths.push(AnimationClipParser03._reader.getUint32());
  25958. }
  25959. }
  25960. static READ_STRINGS() {
  25961. var offset = AnimationClipParser03._reader.getUint32();
  25962. var count = AnimationClipParser03._reader.getUint16();
  25963. var prePos = AnimationClipParser03._reader.pos;
  25964. AnimationClipParser03._reader.pos = offset + AnimationClipParser03._DATA.offset;
  25965. for (var i = 0; i < count; i++)
  25966. AnimationClipParser03._strings[i] = AnimationClipParser03._reader.readUTFString();
  25967. AnimationClipParser03._reader.pos = prePos;
  25968. }
  25969. static parse(clip, reader) {
  25970. AnimationClipParser03._animationClip = clip;
  25971. AnimationClipParser03._reader = reader;
  25972. var arrayBuffer = reader.__getBuffer();
  25973. AnimationClipParser03.READ_DATA();
  25974. AnimationClipParser03.READ_BLOCK();
  25975. AnimationClipParser03.READ_STRINGS();
  25976. for (var i = 0, n = AnimationClipParser03._BLOCK.count; i < n; i++) {
  25977. var index = reader.getUint16();
  25978. var blockName = AnimationClipParser03._strings[index];
  25979. var fn = AnimationClipParser03["READ_" + blockName];
  25980. if (fn == null)
  25981. throw new Error("model file err,no this function:" + index + " " + blockName);
  25982. else
  25983. fn.call(null);
  25984. }
  25985. }
  25986. static READ_ANIMATIONS() {
  25987. var i, j;
  25988. var node;
  25989. var reader = AnimationClipParser03._reader;
  25990. var buffer = reader.__getBuffer();
  25991. var startTimeTypes = [];
  25992. var startTimeTypeCount = reader.getUint16();
  25993. startTimeTypes.length = startTimeTypeCount;
  25994. for (i = 0; i < startTimeTypeCount; i++)
  25995. startTimeTypes[i] = reader.getFloat32();
  25996. var clip = AnimationClipParser03._animationClip;
  25997. clip.name = AnimationClipParser03._strings[reader.getUint16()];
  25998. var clipDur = clip._duration = reader.getFloat32();
  25999. clip.islooping = !!reader.getByte();
  26000. clip._frameRate = reader.getInt16();
  26001. var nodeCount = reader.getInt16();
  26002. var nodes = clip._nodes;
  26003. nodes.count = nodeCount;
  26004. var nodesMap = clip._nodesMap = {};
  26005. var nodesDic = clip._nodesDic = {};
  26006. for (i = 0; i < nodeCount; i++) {
  26007. node = new KeyframeNode();
  26008. nodes.setNodeByIndex(i, node);
  26009. node._indexInList = i;
  26010. var type = node.type = reader.getUint8();
  26011. var pathLength = reader.getUint16();
  26012. node._setOwnerPathCount(pathLength);
  26013. for (j = 0; j < pathLength; j++)
  26014. node._setOwnerPathByIndex(j, AnimationClipParser03._strings[reader.getUint16()]);
  26015. var nodePath = node._joinOwnerPath("/");
  26016. var mapArray = nodesMap[nodePath];
  26017. (mapArray) || (nodesMap[nodePath] = mapArray = []);
  26018. mapArray.push(node);
  26019. node.propertyOwner = AnimationClipParser03._strings[reader.getUint16()];
  26020. var propertyLength = reader.getUint16();
  26021. node._setPropertyCount(propertyLength);
  26022. for (j = 0; j < propertyLength; j++)
  26023. node._setPropertyByIndex(j, AnimationClipParser03._strings[reader.getUint16()]);
  26024. var fullPath = nodePath + "." + node.propertyOwner + "." + node._joinProperty(".");
  26025. nodesDic[fullPath] = node;
  26026. node.fullPath = fullPath;
  26027. var keyframeCount = reader.getUint16();
  26028. node._setKeyframeCount(keyframeCount);
  26029. var startTime;
  26030. switch (type) {
  26031. case 0:
  26032. break;
  26033. case 1:
  26034. case 3:
  26035. case 4:
  26036. node.data = Laya.Render.supportWebGLPlusAnimation ? new ConchVector3 : new Vector3();
  26037. break;
  26038. case 2:
  26039. node.data = Laya.Render.supportWebGLPlusAnimation ? new ConchQuaternion : new Quaternion();
  26040. break;
  26041. default:
  26042. throw "AnimationClipParser03:unknown type.";
  26043. }
  26044. for (j = 0; j < keyframeCount; j++) {
  26045. switch (type) {
  26046. case 0:
  26047. var floatKeyframe = new FloatKeyframe();
  26048. node._setKeyframeByIndex(j, floatKeyframe);
  26049. startTime = floatKeyframe.time = startTimeTypes[reader.getUint16()];
  26050. floatKeyframe.inTangent = reader.getFloat32();
  26051. floatKeyframe.outTangent = reader.getFloat32();
  26052. floatKeyframe.value = reader.getFloat32();
  26053. break;
  26054. case 1:
  26055. case 3:
  26056. case 4:
  26057. var floatArrayKeyframe = new Vector3Keyframe();
  26058. node._setKeyframeByIndex(j, floatArrayKeyframe);
  26059. startTime = floatArrayKeyframe.time = startTimeTypes[reader.getUint16()];
  26060. if (Laya.Render.supportWebGLPlusAnimation) {
  26061. var data = floatArrayKeyframe.data = new Float32Array(3 * 3);
  26062. for (var k = 0; k < 3; k++)
  26063. data[k] = reader.getFloat32();
  26064. for (k = 0; k < 3; k++)
  26065. data[3 + k] = reader.getFloat32();
  26066. for (k = 0; k < 3; k++)
  26067. data[6 + k] = reader.getFloat32();
  26068. }
  26069. else {
  26070. var inTangent = floatArrayKeyframe.inTangent;
  26071. var outTangent = floatArrayKeyframe.outTangent;
  26072. var value = floatArrayKeyframe.value;
  26073. inTangent.x = reader.getFloat32();
  26074. inTangent.y = reader.getFloat32();
  26075. inTangent.z = reader.getFloat32();
  26076. outTangent.x = reader.getFloat32();
  26077. outTangent.y = reader.getFloat32();
  26078. outTangent.z = reader.getFloat32();
  26079. value.x = reader.getFloat32();
  26080. value.y = reader.getFloat32();
  26081. value.z = reader.getFloat32();
  26082. }
  26083. break;
  26084. case 2:
  26085. var quaArrayKeyframe = new QuaternionKeyframe();
  26086. node._setKeyframeByIndex(j, quaArrayKeyframe);
  26087. startTime = quaArrayKeyframe.time = startTimeTypes[reader.getUint16()];
  26088. if (Laya.Render.supportWebGLPlusAnimation) {
  26089. data = quaArrayKeyframe.data = new Float32Array(3 * 4);
  26090. for (k = 0; k < 4; k++)
  26091. data[k] = reader.getFloat32();
  26092. for (k = 0; k < 4; k++)
  26093. data[4 + k] = reader.getFloat32();
  26094. for (k = 0; k < 4; k++)
  26095. data[8 + k] = reader.getFloat32();
  26096. }
  26097. else {
  26098. var inTangentQua = quaArrayKeyframe.inTangent;
  26099. var outTangentQua = quaArrayKeyframe.outTangent;
  26100. var valueQua = quaArrayKeyframe.value;
  26101. inTangentQua.x = reader.getFloat32();
  26102. inTangentQua.y = reader.getFloat32();
  26103. inTangentQua.z = reader.getFloat32();
  26104. inTangentQua.w = reader.getFloat32();
  26105. outTangentQua.x = reader.getFloat32();
  26106. outTangentQua.y = reader.getFloat32();
  26107. outTangentQua.z = reader.getFloat32();
  26108. outTangentQua.w = reader.getFloat32();
  26109. valueQua.x = reader.getFloat32();
  26110. valueQua.y = reader.getFloat32();
  26111. valueQua.z = reader.getFloat32();
  26112. valueQua.w = reader.getFloat32();
  26113. }
  26114. break;
  26115. default:
  26116. throw "AnimationClipParser03:unknown type.";
  26117. }
  26118. }
  26119. }
  26120. var eventCount = reader.getUint16();
  26121. for (i = 0; i < eventCount; i++) {
  26122. var event = new AnimationEvent();
  26123. event.time = Math.min(clipDur, reader.getFloat32());
  26124. event.eventName = AnimationClipParser03._strings[reader.getUint16()];
  26125. var params;
  26126. var paramCount = reader.getUint16();
  26127. (paramCount > 0) && (event.params = params = []);
  26128. for (j = 0; j < paramCount; j++) {
  26129. var eventType = reader.getByte();
  26130. switch (eventType) {
  26131. case 0:
  26132. params.push(!!reader.getByte());
  26133. break;
  26134. case 1:
  26135. params.push(reader.getInt32());
  26136. break;
  26137. case 2:
  26138. params.push(reader.getFloat32());
  26139. break;
  26140. case 3:
  26141. params.push(AnimationClipParser03._strings[reader.getUint16()]);
  26142. break;
  26143. default:
  26144. throw new Error("unknown type.");
  26145. }
  26146. }
  26147. clip.addEvent(event);
  26148. }
  26149. }
  26150. }
  26151. AnimationClipParser03._strings = [];
  26152. AnimationClipParser03._BLOCK = { count: 0 };
  26153. AnimationClipParser03._DATA = { offset: 0, size: 0 };
  26154. class HalfFloatUtils {
  26155. static __init__() {
  26156. for (var i = 0; i < 256; ++i) {
  26157. var e = i - 127;
  26158. if (e < -27) {
  26159. HalfFloatUtils._baseTable[i | 0x000] = 0x0000;
  26160. HalfFloatUtils._baseTable[i | 0x100] = 0x8000;
  26161. HalfFloatUtils._shiftTable[i | 0x000] = 24;
  26162. HalfFloatUtils._shiftTable[i | 0x100] = 24;
  26163. }
  26164. else if (e < -14) {
  26165. HalfFloatUtils._baseTable[i | 0x000] = 0x0400 >> (-e - 14);
  26166. HalfFloatUtils._baseTable[i | 0x100] = (0x0400 >> (-e - 14)) | 0x8000;
  26167. HalfFloatUtils._shiftTable[i | 0x000] = -e - 1;
  26168. HalfFloatUtils._shiftTable[i | 0x100] = -e - 1;
  26169. }
  26170. else if (e <= 15) {
  26171. HalfFloatUtils._baseTable[i | 0x000] = (e + 15) << 10;
  26172. HalfFloatUtils._baseTable[i | 0x100] = ((e + 15) << 10) | 0x8000;
  26173. HalfFloatUtils._shiftTable[i | 0x000] = 13;
  26174. HalfFloatUtils._shiftTable[i | 0x100] = 13;
  26175. }
  26176. else if (e < 128) {
  26177. HalfFloatUtils._baseTable[i | 0x000] = 0x7c00;
  26178. HalfFloatUtils._baseTable[i | 0x100] = 0xfc00;
  26179. HalfFloatUtils._shiftTable[i | 0x000] = 24;
  26180. HalfFloatUtils._shiftTable[i | 0x100] = 24;
  26181. }
  26182. else {
  26183. HalfFloatUtils._baseTable[i | 0x000] = 0x7c00;
  26184. HalfFloatUtils._baseTable[i | 0x100] = 0xfc00;
  26185. HalfFloatUtils._shiftTable[i | 0x000] = 13;
  26186. HalfFloatUtils._shiftTable[i | 0x100] = 13;
  26187. }
  26188. }
  26189. HalfFloatUtils._mantissaTable[0] = 0;
  26190. for (i = 1; i < 1024; ++i) {
  26191. var m = i << 13;
  26192. e = 0;
  26193. while ((m & 0x00800000) === 0) {
  26194. e -= 0x00800000;
  26195. m <<= 1;
  26196. }
  26197. m &= ~0x00800000;
  26198. e += 0x38800000;
  26199. HalfFloatUtils._mantissaTable[i] = m | e;
  26200. }
  26201. for (i = 1024; i < 2048; ++i) {
  26202. HalfFloatUtils._mantissaTable[i] = 0x38000000 + ((i - 1024) << 13);
  26203. }
  26204. HalfFloatUtils._exponentTable[0] = 0;
  26205. for (i = 1; i < 31; ++i) {
  26206. HalfFloatUtils._exponentTable[i] = i << 23;
  26207. }
  26208. HalfFloatUtils._exponentTable[31] = 0x47800000;
  26209. HalfFloatUtils._exponentTable[32] = 0x80000000;
  26210. for (i = 33; i < 63; ++i) {
  26211. HalfFloatUtils._exponentTable[i] = 0x80000000 + ((i - 32) << 23);
  26212. }
  26213. HalfFloatUtils._exponentTable[63] = 0xc7800000;
  26214. HalfFloatUtils._offsetTable[0] = 0;
  26215. for (i = 1; i < 64; ++i) {
  26216. if (i === 32) {
  26217. HalfFloatUtils._offsetTable[i] = 0;
  26218. }
  26219. else {
  26220. HalfFloatUtils._offsetTable[i] = 1024;
  26221. }
  26222. }
  26223. }
  26224. static roundToFloat16Bits(num) {
  26225. HalfFloatUtils._floatView[0] = num;
  26226. var f = HalfFloatUtils._uint32View[0];
  26227. var e = (f >> 23) & 0x1ff;
  26228. return HalfFloatUtils._baseTable[e] + ((f & 0x007fffff) >> HalfFloatUtils._shiftTable[e]);
  26229. }
  26230. static convertToNumber(float16bits) {
  26231. var m = float16bits >> 10;
  26232. HalfFloatUtils._uint32View[0] = HalfFloatUtils._mantissaTable[HalfFloatUtils._offsetTable[m] + (float16bits & 0x3ff)] + HalfFloatUtils._exponentTable[m];
  26233. return HalfFloatUtils._floatView[0];
  26234. }
  26235. }
  26236. HalfFloatUtils._buffer = new ArrayBuffer(4);
  26237. HalfFloatUtils._floatView = new Float32Array(HalfFloatUtils._buffer);
  26238. HalfFloatUtils._uint32View = new Uint32Array(HalfFloatUtils._buffer);
  26239. HalfFloatUtils._baseTable = new Uint32Array(512);
  26240. HalfFloatUtils._shiftTable = new Uint32Array(512);
  26241. HalfFloatUtils._mantissaTable = new Uint32Array(2048);
  26242. HalfFloatUtils._exponentTable = new Uint32Array(64);
  26243. HalfFloatUtils._offsetTable = new Uint32Array(64);
  26244. class AnimationClipParser04 {
  26245. static READ_DATA() {
  26246. AnimationClipParser04._DATA.offset = AnimationClipParser04._reader.getUint32();
  26247. AnimationClipParser04._DATA.size = AnimationClipParser04._reader.getUint32();
  26248. }
  26249. static READ_BLOCK() {
  26250. var count = AnimationClipParser04._BLOCK.count = AnimationClipParser04._reader.getUint16();
  26251. var blockStarts = AnimationClipParser04._BLOCK.blockStarts = [];
  26252. var blockLengths = AnimationClipParser04._BLOCK.blockLengths = [];
  26253. for (var i = 0; i < count; i++) {
  26254. blockStarts.push(AnimationClipParser04._reader.getUint32());
  26255. blockLengths.push(AnimationClipParser04._reader.getUint32());
  26256. }
  26257. }
  26258. static READ_STRINGS() {
  26259. var offset = AnimationClipParser04._reader.getUint32();
  26260. var count = AnimationClipParser04._reader.getUint16();
  26261. var prePos = AnimationClipParser04._reader.pos;
  26262. AnimationClipParser04._reader.pos = offset + AnimationClipParser04._DATA.offset;
  26263. for (var i = 0; i < count; i++)
  26264. AnimationClipParser04._strings[i] = AnimationClipParser04._reader.readUTFString();
  26265. AnimationClipParser04._reader.pos = prePos;
  26266. }
  26267. static parse(clip, reader, version) {
  26268. AnimationClipParser04._animationClip = clip;
  26269. AnimationClipParser04._reader = reader;
  26270. AnimationClipParser04._version = version;
  26271. AnimationClipParser04.READ_DATA();
  26272. AnimationClipParser04.READ_BLOCK();
  26273. AnimationClipParser04.READ_STRINGS();
  26274. for (var i = 0, n = AnimationClipParser04._BLOCK.count; i < n; i++) {
  26275. var index = reader.getUint16();
  26276. var blockName = AnimationClipParser04._strings[index];
  26277. var fn = AnimationClipParser04["READ_" + blockName];
  26278. if (fn == null)
  26279. throw new Error("model file err,no this function:" + index + " " + blockName);
  26280. else
  26281. fn.call(null);
  26282. }
  26283. AnimationClipParser04._version = null;
  26284. AnimationClipParser04._reader = null;
  26285. AnimationClipParser04._animationClip = null;
  26286. }
  26287. static READ_ANIMATIONS() {
  26288. var i, j;
  26289. var node;
  26290. var reader = AnimationClipParser04._reader;
  26291. var buffer = reader.__getBuffer();
  26292. var startTimeTypes = [];
  26293. var startTimeTypeCount = reader.getUint16();
  26294. startTimeTypes.length = startTimeTypeCount;
  26295. for (i = 0; i < startTimeTypeCount; i++)
  26296. startTimeTypes[i] = reader.getFloat32();
  26297. var clip = AnimationClipParser04._animationClip;
  26298. clip.name = AnimationClipParser04._strings[reader.getUint16()];
  26299. var clipDur = clip._duration = reader.getFloat32();
  26300. clip.islooping = !!reader.getByte();
  26301. clip._frameRate = reader.getInt16();
  26302. var nodeCount = reader.getInt16();
  26303. var nodes = clip._nodes;
  26304. nodes.count = nodeCount;
  26305. var nodesMap = clip._nodesMap = {};
  26306. var nodesDic = clip._nodesDic = {};
  26307. for (i = 0; i < nodeCount; i++) {
  26308. node = new KeyframeNode();
  26309. nodes.setNodeByIndex(i, node);
  26310. node._indexInList = i;
  26311. var type = node.type = reader.getUint8();
  26312. var pathLength = reader.getUint16();
  26313. node._setOwnerPathCount(pathLength);
  26314. for (j = 0; j < pathLength; j++)
  26315. node._setOwnerPathByIndex(j, AnimationClipParser04._strings[reader.getUint16()]);
  26316. var nodePath = node._joinOwnerPath("/");
  26317. var mapArray = nodesMap[nodePath];
  26318. (mapArray) || (nodesMap[nodePath] = mapArray = []);
  26319. mapArray.push(node);
  26320. node.propertyOwner = AnimationClipParser04._strings[reader.getUint16()];
  26321. var propertyLength = reader.getUint16();
  26322. node._setPropertyCount(propertyLength);
  26323. for (j = 0; j < propertyLength; j++)
  26324. node._setPropertyByIndex(j, AnimationClipParser04._strings[reader.getUint16()]);
  26325. var fullPath = nodePath + "." + node.propertyOwner + "." + node._joinProperty(".");
  26326. nodesDic[fullPath] = node;
  26327. node.fullPath = fullPath;
  26328. var keyframeCount = reader.getUint16();
  26329. node._setKeyframeCount(keyframeCount);
  26330. var startTime;
  26331. switch (type) {
  26332. case 0:
  26333. break;
  26334. case 1:
  26335. case 3:
  26336. case 4:
  26337. node.data = Laya.Render.supportWebGLPlusAnimation ? new ConchVector3 : new Vector3();
  26338. break;
  26339. case 2:
  26340. node.data = Laya.Render.supportWebGLPlusAnimation ? new ConchQuaternion : new Quaternion();
  26341. break;
  26342. default:
  26343. throw "AnimationClipParser04:unknown type.";
  26344. }
  26345. switch (AnimationClipParser04._version) {
  26346. case "LAYAANIMATION:04":
  26347. for (j = 0; j < keyframeCount; j++) {
  26348. switch (type) {
  26349. case 0:
  26350. var floatKeyframe = new FloatKeyframe();
  26351. node._setKeyframeByIndex(j, floatKeyframe);
  26352. startTime = floatKeyframe.time = startTimeTypes[reader.getUint16()];
  26353. floatKeyframe.inTangent = reader.getFloat32();
  26354. floatKeyframe.outTangent = reader.getFloat32();
  26355. floatKeyframe.value = reader.getFloat32();
  26356. break;
  26357. case 1:
  26358. case 3:
  26359. case 4:
  26360. var floatArrayKeyframe = new Vector3Keyframe();
  26361. node._setKeyframeByIndex(j, floatArrayKeyframe);
  26362. startTime = floatArrayKeyframe.time = startTimeTypes[reader.getUint16()];
  26363. if (Laya.Render.supportWebGLPlusAnimation) {
  26364. var data = floatArrayKeyframe.data = new Float32Array(3 * 3);
  26365. for (var k = 0; k < 3; k++)
  26366. data[k] = reader.getFloat32();
  26367. for (k = 0; k < 3; k++)
  26368. data[3 + k] = reader.getFloat32();
  26369. for (k = 0; k < 3; k++)
  26370. data[6 + k] = reader.getFloat32();
  26371. }
  26372. else {
  26373. var inTangent = floatArrayKeyframe.inTangent;
  26374. var outTangent = floatArrayKeyframe.outTangent;
  26375. var value = floatArrayKeyframe.value;
  26376. inTangent.x = reader.getFloat32();
  26377. inTangent.y = reader.getFloat32();
  26378. inTangent.z = reader.getFloat32();
  26379. outTangent.x = reader.getFloat32();
  26380. outTangent.y = reader.getFloat32();
  26381. outTangent.z = reader.getFloat32();
  26382. value.x = reader.getFloat32();
  26383. value.y = reader.getFloat32();
  26384. value.z = reader.getFloat32();
  26385. }
  26386. break;
  26387. case 2:
  26388. var quaternionKeyframe = new QuaternionKeyframe();
  26389. node._setKeyframeByIndex(j, quaternionKeyframe);
  26390. startTime = quaternionKeyframe.time = startTimeTypes[reader.getUint16()];
  26391. if (Laya.Render.supportWebGLPlusAnimation) {
  26392. data = quaternionKeyframe.data = new Float32Array(3 * 4);
  26393. for (k = 0; k < 4; k++)
  26394. data[k] = reader.getFloat32();
  26395. for (k = 0; k < 4; k++)
  26396. data[4 + k] = reader.getFloat32();
  26397. for (k = 0; k < 4; k++)
  26398. data[8 + k] = reader.getFloat32();
  26399. }
  26400. else {
  26401. var inTangentQua = quaternionKeyframe.inTangent;
  26402. var outTangentQua = quaternionKeyframe.outTangent;
  26403. var valueQua = quaternionKeyframe.value;
  26404. inTangentQua.x = reader.getFloat32();
  26405. inTangentQua.y = reader.getFloat32();
  26406. inTangentQua.z = reader.getFloat32();
  26407. inTangentQua.w = reader.getFloat32();
  26408. outTangentQua.x = reader.getFloat32();
  26409. outTangentQua.y = reader.getFloat32();
  26410. outTangentQua.z = reader.getFloat32();
  26411. outTangentQua.w = reader.getFloat32();
  26412. valueQua.x = reader.getFloat32();
  26413. valueQua.y = reader.getFloat32();
  26414. valueQua.z = reader.getFloat32();
  26415. valueQua.w = reader.getFloat32();
  26416. }
  26417. break;
  26418. default:
  26419. throw "AnimationClipParser04:unknown type.";
  26420. }
  26421. }
  26422. break;
  26423. case "LAYAANIMATION:COMPRESSION_04":
  26424. for (j = 0; j < keyframeCount; j++) {
  26425. switch (type) {
  26426. case 0:
  26427. floatKeyframe = new FloatKeyframe();
  26428. node._setKeyframeByIndex(j, floatKeyframe);
  26429. startTime = floatKeyframe.time = startTimeTypes[reader.getUint16()];
  26430. floatKeyframe.inTangent = HalfFloatUtils.convertToNumber(reader.getUint16());
  26431. floatKeyframe.outTangent = HalfFloatUtils.convertToNumber(reader.getUint16());
  26432. floatKeyframe.value = HalfFloatUtils.convertToNumber(reader.getUint16());
  26433. break;
  26434. case 1:
  26435. case 3:
  26436. case 4:
  26437. floatArrayKeyframe = new Vector3Keyframe();
  26438. node._setKeyframeByIndex(j, floatArrayKeyframe);
  26439. startTime = floatArrayKeyframe.time = startTimeTypes[reader.getUint16()];
  26440. if (Laya.Render.supportWebGLPlusAnimation) {
  26441. data = floatArrayKeyframe.data = new Float32Array(3 * 3);
  26442. for (k = 0; k < 3; k++)
  26443. data[k] = HalfFloatUtils.convertToNumber(reader.getUint16());
  26444. for (k = 0; k < 3; k++)
  26445. data[3 + k] = HalfFloatUtils.convertToNumber(reader.getUint16());
  26446. for (k = 0; k < 3; k++)
  26447. data[6 + k] = HalfFloatUtils.convertToNumber(reader.getUint16());
  26448. }
  26449. else {
  26450. inTangent = floatArrayKeyframe.inTangent;
  26451. outTangent = floatArrayKeyframe.outTangent;
  26452. value = floatArrayKeyframe.value;
  26453. inTangent.x = HalfFloatUtils.convertToNumber(reader.getUint16());
  26454. inTangent.y = HalfFloatUtils.convertToNumber(reader.getUint16());
  26455. inTangent.z = HalfFloatUtils.convertToNumber(reader.getUint16());
  26456. outTangent.x = HalfFloatUtils.convertToNumber(reader.getUint16());
  26457. outTangent.y = HalfFloatUtils.convertToNumber(reader.getUint16());
  26458. outTangent.z = HalfFloatUtils.convertToNumber(reader.getUint16());
  26459. value.x = HalfFloatUtils.convertToNumber(reader.getUint16());
  26460. value.y = HalfFloatUtils.convertToNumber(reader.getUint16());
  26461. value.z = HalfFloatUtils.convertToNumber(reader.getUint16());
  26462. }
  26463. break;
  26464. case 2:
  26465. quaternionKeyframe = new QuaternionKeyframe();
  26466. node._setKeyframeByIndex(j, quaternionKeyframe);
  26467. startTime = quaternionKeyframe.time = startTimeTypes[reader.getUint16()];
  26468. if (Laya.Render.supportWebGLPlusAnimation) {
  26469. data = quaternionKeyframe.data = new Float32Array(3 * 4);
  26470. for (k = 0; k < 4; k++)
  26471. data[k] = HalfFloatUtils.convertToNumber(reader.getUint16());
  26472. for (k = 0; k < 4; k++)
  26473. data[4 + k] = HalfFloatUtils.convertToNumber(reader.getUint16());
  26474. for (k = 0; k < 4; k++)
  26475. data[8 + k] = HalfFloatUtils.convertToNumber(reader.getUint16());
  26476. }
  26477. else {
  26478. inTangentQua = quaternionKeyframe.inTangent;
  26479. outTangentQua = quaternionKeyframe.outTangent;
  26480. valueQua = quaternionKeyframe.value;
  26481. inTangentQua.x = HalfFloatUtils.convertToNumber(reader.getUint16());
  26482. inTangentQua.y = HalfFloatUtils.convertToNumber(reader.getUint16());
  26483. inTangentQua.z = HalfFloatUtils.convertToNumber(reader.getUint16());
  26484. inTangentQua.w = HalfFloatUtils.convertToNumber(reader.getUint16());
  26485. outTangentQua.x = HalfFloatUtils.convertToNumber(reader.getUint16());
  26486. outTangentQua.y = HalfFloatUtils.convertToNumber(reader.getUint16());
  26487. outTangentQua.z = HalfFloatUtils.convertToNumber(reader.getUint16());
  26488. outTangentQua.w = HalfFloatUtils.convertToNumber(reader.getUint16());
  26489. valueQua.x = HalfFloatUtils.convertToNumber(reader.getUint16());
  26490. valueQua.y = HalfFloatUtils.convertToNumber(reader.getUint16());
  26491. valueQua.z = HalfFloatUtils.convertToNumber(reader.getUint16());
  26492. valueQua.w = HalfFloatUtils.convertToNumber(reader.getUint16());
  26493. }
  26494. break;
  26495. default:
  26496. throw "AnimationClipParser04:unknown type.";
  26497. }
  26498. }
  26499. break;
  26500. }
  26501. }
  26502. var eventCount = reader.getUint16();
  26503. for (i = 0; i < eventCount; i++) {
  26504. var event = new AnimationEvent();
  26505. event.time = Math.min(clipDur, reader.getFloat32());
  26506. event.eventName = AnimationClipParser04._strings[reader.getUint16()];
  26507. var params;
  26508. var paramCount = reader.getUint16();
  26509. (paramCount > 0) && (event.params = params = []);
  26510. for (j = 0; j < paramCount; j++) {
  26511. var eventType = reader.getByte();
  26512. switch (eventType) {
  26513. case 0:
  26514. params.push(!!reader.getByte());
  26515. break;
  26516. case 1:
  26517. params.push(reader.getInt32());
  26518. break;
  26519. case 2:
  26520. params.push(reader.getFloat32());
  26521. break;
  26522. case 3:
  26523. params.push(AnimationClipParser04._strings[reader.getUint16()]);
  26524. break;
  26525. default:
  26526. throw new Error("unknown type.");
  26527. }
  26528. }
  26529. clip.addEvent(event);
  26530. }
  26531. }
  26532. }
  26533. AnimationClipParser04._strings = [];
  26534. AnimationClipParser04._BLOCK = { count: 0 };
  26535. AnimationClipParser04._DATA = { offset: 0, size: 0 };
  26536. class KeyframeNodeList {
  26537. constructor() {
  26538. this._nodes = [];
  26539. }
  26540. get count() {
  26541. return this._nodes.length;
  26542. }
  26543. set count(value) {
  26544. this._nodes.length = value;
  26545. }
  26546. getNodeByIndex(index) {
  26547. return this._nodes[index];
  26548. }
  26549. setNodeByIndex(index, node) {
  26550. this._nodes[index] = node;
  26551. }
  26552. }
  26553. if (window.conch && window.conchKeyframeNodeList) {
  26554. KeyframeNodeList = window.conchKeyframeNodeList;
  26555. }
  26556. if (window.qq && window.qq.webglPlus) {
  26557. KeyframeNodeList = window.qq.webglPlus.conchKeyframeNodeList;
  26558. }
  26559. class AnimationClip extends Laya.Resource {
  26560. constructor() {
  26561. super();
  26562. this._nodes = new KeyframeNodeList();
  26563. this._animationEvents = [];
  26564. }
  26565. static _parse(data, propertyParams = null, constructParams = null) {
  26566. var clip = new AnimationClip();
  26567. var reader = new Laya.Byte(data);
  26568. var version = reader.readUTFString();
  26569. switch (version) {
  26570. case "LAYAANIMATION:03":
  26571. AnimationClipParser03.parse(clip, reader);
  26572. break;
  26573. case "LAYAANIMATION:04":
  26574. case "LAYAANIMATION:COMPRESSION_04":
  26575. AnimationClipParser04.parse(clip, reader, version);
  26576. break;
  26577. default:
  26578. throw "unknown animationClip version.";
  26579. }
  26580. return clip;
  26581. }
  26582. static load(url, complete) {
  26583. Laya.ILaya.loader.create(url, complete, null, AnimationClip.ANIMATIONCLIP);
  26584. }
  26585. duration() {
  26586. return this._duration;
  26587. }
  26588. _hermiteInterpolate(frame, nextFrame, t, dur) {
  26589. var t0 = frame.outTangent, t1 = nextFrame.inTangent;
  26590. if (Number.isFinite(t0) && Number.isFinite(t1)) {
  26591. var t2 = t * t;
  26592. var t3 = t2 * t;
  26593. var a = 2.0 * t3 - 3.0 * t2 + 1.0;
  26594. var b = t3 - 2.0 * t2 + t;
  26595. var c = t3 - t2;
  26596. var d = -2.0 * t3 + 3.0 * t2;
  26597. return a * frame.value + b * t0 * dur + c * t1 * dur + d * nextFrame.value;
  26598. }
  26599. else
  26600. return frame.value;
  26601. }
  26602. _hermiteInterpolateVector3(frame, nextFrame, t, dur, out) {
  26603. var p0 = frame.value;
  26604. var tan0 = frame.outTangent;
  26605. var p1 = nextFrame.value;
  26606. var tan1 = nextFrame.inTangent;
  26607. var t2 = t * t;
  26608. var t3 = t2 * t;
  26609. var a = 2.0 * t3 - 3.0 * t2 + 1.0;
  26610. var b = t3 - 2.0 * t2 + t;
  26611. var c = t3 - t2;
  26612. var d = -2.0 * t3 + 3.0 * t2;
  26613. var t0 = tan0.x, t1 = tan1.x;
  26614. if (Number.isFinite(t0) && Number.isFinite(t1))
  26615. out.x = a * p0.x + b * t0 * dur + c * t1 * dur + d * p1.x;
  26616. else
  26617. out.x = p0.x;
  26618. t0 = tan0.y, t1 = tan1.y;
  26619. if (Number.isFinite(t0) && Number.isFinite(t1))
  26620. out.y = a * p0.y + b * t0 * dur + c * t1 * dur + d * p1.y;
  26621. else
  26622. out.y = p0.y;
  26623. t0 = tan0.z, t1 = tan1.z;
  26624. if (Number.isFinite(t0) && Number.isFinite(t1))
  26625. out.z = a * p0.z + b * t0 * dur + c * t1 * dur + d * p1.z;
  26626. else
  26627. out.z = p0.z;
  26628. }
  26629. _hermiteInterpolateQuaternion(frame, nextFrame, t, dur, out) {
  26630. var p0 = frame.value;
  26631. var tan0 = frame.outTangent;
  26632. var p1 = nextFrame.value;
  26633. var tan1 = nextFrame.inTangent;
  26634. var t2 = t * t;
  26635. var t3 = t2 * t;
  26636. var a = 2.0 * t3 - 3.0 * t2 + 1.0;
  26637. var b = t3 - 2.0 * t2 + t;
  26638. var c = t3 - t2;
  26639. var d = -2.0 * t3 + 3.0 * t2;
  26640. var t0 = tan0.x, t1 = tan1.x;
  26641. if (Number.isFinite(t0) && Number.isFinite(t1))
  26642. out.x = a * p0.x + b * t0 * dur + c * t1 * dur + d * p1.x;
  26643. else
  26644. out.x = p0.x;
  26645. t0 = tan0.y, t1 = tan1.y;
  26646. if (Number.isFinite(t0) && Number.isFinite(t1))
  26647. out.y = a * p0.y + b * t0 * dur + c * t1 * dur + d * p1.y;
  26648. else
  26649. out.y = p0.y;
  26650. t0 = tan0.z, t1 = tan1.z;
  26651. if (Number.isFinite(t0) && Number.isFinite(t1))
  26652. out.z = a * p0.z + b * t0 * dur + c * t1 * dur + d * p1.z;
  26653. else
  26654. out.z = p0.z;
  26655. t0 = tan0.w, t1 = tan1.w;
  26656. if (Number.isFinite(t0) && Number.isFinite(t1))
  26657. out.w = a * p0.w + b * t0 * dur + c * t1 * dur + d * p1.w;
  26658. else
  26659. out.w = p0.w;
  26660. }
  26661. _evaluateClipDatasRealTime(nodes, playCurTime, realTimeCurrentFrameIndexes, addtive, frontPlay) {
  26662. for (var i = 0, n = nodes.count; i < n; i++) {
  26663. var node = nodes.getNodeByIndex(i);
  26664. var type = node.type;
  26665. var nextFrameIndex;
  26666. var keyFrames = node._keyFrames;
  26667. var keyFramesCount = keyFrames.length;
  26668. var frameIndex = realTimeCurrentFrameIndexes[i];
  26669. if (frontPlay) {
  26670. if ((frameIndex !== -1) && (playCurTime < keyFrames[frameIndex].time)) {
  26671. frameIndex = -1;
  26672. realTimeCurrentFrameIndexes[i] = frameIndex;
  26673. }
  26674. nextFrameIndex = frameIndex + 1;
  26675. while (nextFrameIndex < keyFramesCount) {
  26676. if (keyFrames[nextFrameIndex].time > playCurTime)
  26677. break;
  26678. frameIndex++;
  26679. nextFrameIndex++;
  26680. realTimeCurrentFrameIndexes[i] = frameIndex;
  26681. }
  26682. }
  26683. else {
  26684. nextFrameIndex = frameIndex + 1;
  26685. if ((nextFrameIndex !== keyFramesCount) && (playCurTime > keyFrames[nextFrameIndex].time)) {
  26686. frameIndex = keyFramesCount - 1;
  26687. realTimeCurrentFrameIndexes[i] = frameIndex;
  26688. }
  26689. nextFrameIndex = frameIndex + 1;
  26690. while (frameIndex > -1) {
  26691. if (keyFrames[frameIndex].time < playCurTime)
  26692. break;
  26693. frameIndex--;
  26694. nextFrameIndex--;
  26695. realTimeCurrentFrameIndexes[i] = frameIndex;
  26696. }
  26697. }
  26698. var isEnd = nextFrameIndex === keyFramesCount;
  26699. switch (type) {
  26700. case 0:
  26701. if (frameIndex !== -1) {
  26702. var frame = keyFrames[frameIndex];
  26703. if (isEnd) {
  26704. node.data = frame.value;
  26705. }
  26706. else {
  26707. var nextFarme = keyFrames[nextFrameIndex];
  26708. var d = nextFarme.time - frame.time;
  26709. var t;
  26710. if (d !== 0)
  26711. t = (playCurTime - frame.time) / d;
  26712. else
  26713. t = 0;
  26714. node.data = this._hermiteInterpolate(frame, nextFarme, t, d);
  26715. }
  26716. }
  26717. else {
  26718. node.data = keyFrames[0].value;
  26719. }
  26720. if (addtive)
  26721. node.data -= keyFrames[0].value;
  26722. break;
  26723. case 1:
  26724. case 4:
  26725. var clipData = node.data;
  26726. this._evaluateFrameNodeVector3DatasRealTime(keyFrames, frameIndex, isEnd, playCurTime, clipData);
  26727. if (addtive) {
  26728. var firstFrameValue = keyFrames[0].value;
  26729. clipData.x -= firstFrameValue.x;
  26730. clipData.y -= firstFrameValue.y;
  26731. clipData.z -= firstFrameValue.z;
  26732. }
  26733. break;
  26734. case 2:
  26735. var clipQuat = node.data;
  26736. this._evaluateFrameNodeQuaternionDatasRealTime(keyFrames, frameIndex, isEnd, playCurTime, clipQuat);
  26737. if (addtive) {
  26738. var tempQuat = AnimationClip._tempQuaternion0;
  26739. var firstFrameValueQua = keyFrames[0].value;
  26740. Utils3D.quaternionConjugate(firstFrameValueQua, tempQuat);
  26741. Quaternion.multiply(tempQuat, clipQuat, clipQuat);
  26742. }
  26743. break;
  26744. case 3:
  26745. clipData = node.data;
  26746. this._evaluateFrameNodeVector3DatasRealTime(keyFrames, frameIndex, isEnd, playCurTime, clipData);
  26747. if (addtive) {
  26748. firstFrameValue = keyFrames[0].value;
  26749. clipData.x /= firstFrameValue.x;
  26750. clipData.y /= firstFrameValue.y;
  26751. clipData.z /= firstFrameValue.z;
  26752. }
  26753. break;
  26754. default:
  26755. throw "AnimationClip:unknown node type.";
  26756. }
  26757. }
  26758. }
  26759. _evaluateClipDatasRealTimeForNative(nodes, playCurTime, realTimeCurrentFrameIndexes, addtive) {
  26760. Laya.LayaGL.instance.evaluateClipDatasRealTime(nodes._nativeObj, playCurTime, realTimeCurrentFrameIndexes, addtive);
  26761. }
  26762. _evaluateFrameNodeVector3DatasRealTime(keyFrames, frameIndex, isEnd, playCurTime, outDatas) {
  26763. if (frameIndex !== -1) {
  26764. var frame = keyFrames[frameIndex];
  26765. if (isEnd) {
  26766. var frameData = frame.value;
  26767. outDatas.x = frameData.x;
  26768. outDatas.y = frameData.y;
  26769. outDatas.z = frameData.z;
  26770. }
  26771. else {
  26772. var nextKeyFrame = keyFrames[frameIndex + 1];
  26773. var t;
  26774. var startTime = frame.time;
  26775. var d = nextKeyFrame.time - startTime;
  26776. if (d !== 0)
  26777. t = (playCurTime - startTime) / d;
  26778. else
  26779. t = 0;
  26780. this._hermiteInterpolateVector3(frame, nextKeyFrame, t, d, outDatas);
  26781. }
  26782. }
  26783. else {
  26784. var firstFrameDatas = keyFrames[0].value;
  26785. outDatas.x = firstFrameDatas.x;
  26786. outDatas.y = firstFrameDatas.y;
  26787. outDatas.z = firstFrameDatas.z;
  26788. }
  26789. }
  26790. _evaluateFrameNodeQuaternionDatasRealTime(keyFrames, frameIndex, isEnd, playCurTime, outDatas) {
  26791. if (frameIndex !== -1) {
  26792. var frame = keyFrames[frameIndex];
  26793. if (isEnd) {
  26794. var frameData = frame.value;
  26795. outDatas.x = frameData.x;
  26796. outDatas.y = frameData.y;
  26797. outDatas.z = frameData.z;
  26798. outDatas.w = frameData.w;
  26799. }
  26800. else {
  26801. var nextKeyFrame = keyFrames[frameIndex + 1];
  26802. var t;
  26803. var startTime = frame.time;
  26804. var d = nextKeyFrame.time - startTime;
  26805. if (d !== 0)
  26806. t = (playCurTime - startTime) / d;
  26807. else
  26808. t = 0;
  26809. this._hermiteInterpolateQuaternion(frame, nextKeyFrame, t, d, outDatas);
  26810. }
  26811. }
  26812. else {
  26813. var firstFrameDatas = keyFrames[0].value;
  26814. outDatas.x = firstFrameDatas.x;
  26815. outDatas.y = firstFrameDatas.y;
  26816. outDatas.z = firstFrameDatas.z;
  26817. outDatas.w = firstFrameDatas.w;
  26818. }
  26819. }
  26820. _binarySearchEventIndex(time) {
  26821. var start = 0;
  26822. var end = this._animationEvents.length - 1;
  26823. var mid;
  26824. while (start <= end) {
  26825. mid = Math.floor((start + end) / 2);
  26826. var midValue = this._animationEvents[mid].time;
  26827. if (midValue == time)
  26828. return mid;
  26829. else if (midValue > time)
  26830. end = mid - 1;
  26831. else
  26832. start = mid + 1;
  26833. }
  26834. return start;
  26835. }
  26836. addEvent(event) {
  26837. var index = this._binarySearchEventIndex(event.time);
  26838. this._animationEvents.splice(index, 0, event);
  26839. }
  26840. _disposeResource() {
  26841. this._nodes = null;
  26842. this._nodesMap = null;
  26843. }
  26844. }
  26845. AnimationClip.ANIMATIONCLIP = "ANIMATIONCLIP";
  26846. AnimationClip._tempQuaternion0 = new Quaternion();
  26847. class AnimationTransform3D extends Laya.EventDispatcher {
  26848. constructor(owner, localPosition = null, localRotation = null, localScale = null, worldMatrix = null) {
  26849. super();
  26850. this._owner = owner;
  26851. this._children = [];
  26852. this._localMatrix = new Float32Array(16);
  26853. if (Laya.Render.supportWebGLPlusAnimation) {
  26854. this._localPosition = new ConchVector3(0, 0, 0, localPosition);
  26855. this._localRotation = new ConchQuaternion(0, 0, 0, 1, localRotation);
  26856. this._localScale = new ConchVector3(0, 0, 0, localScale);
  26857. this._worldMatrix = worldMatrix;
  26858. }
  26859. else {
  26860. this._localPosition = new Vector3();
  26861. this._localRotation = new Quaternion();
  26862. this._localScale = new Vector3();
  26863. this._worldMatrix = new Float32Array(16);
  26864. }
  26865. this._localQuaternionUpdate = false;
  26866. this._locaEulerlUpdate = false;
  26867. this._localUpdate = false;
  26868. this._worldUpdate = true;
  26869. }
  26870. _getlocalMatrix() {
  26871. if (this._localUpdate) {
  26872. Utils3D._createAffineTransformationArray(this._localPosition, this._localRotation, this._localScale, this._localMatrix);
  26873. this._localUpdate = false;
  26874. }
  26875. return this._localMatrix;
  26876. }
  26877. _onWorldTransform() {
  26878. if (!this._worldUpdate) {
  26879. this._worldUpdate = true;
  26880. this.event(Laya.Event.TRANSFORM_CHANGED);
  26881. for (var i = 0, n = this._children.length; i < n; i++)
  26882. this._children[i]._onWorldTransform();
  26883. }
  26884. }
  26885. get localPosition() {
  26886. return this._localPosition;
  26887. }
  26888. set localPosition(value) {
  26889. this._localPosition = value;
  26890. this._localUpdate = true;
  26891. this._onWorldTransform();
  26892. }
  26893. get localRotation() {
  26894. if (this._localQuaternionUpdate) {
  26895. var euler = this._localRotationEuler;
  26896. Quaternion.createFromYawPitchRoll(euler.y / AnimationTransform3D._angleToRandin, euler.x / AnimationTransform3D._angleToRandin, euler.z / AnimationTransform3D._angleToRandin, this._localRotation);
  26897. this._localQuaternionUpdate = false;
  26898. }
  26899. return this._localRotation;
  26900. }
  26901. set localRotation(value) {
  26902. this._localRotation = value;
  26903. this._locaEulerlUpdate = true;
  26904. this._localQuaternionUpdate = false;
  26905. this._localUpdate = true;
  26906. this._onWorldTransform();
  26907. }
  26908. get localScale() {
  26909. return this._localScale;
  26910. }
  26911. set localScale(value) {
  26912. this._localScale = value;
  26913. this._localUpdate = true;
  26914. this._onWorldTransform();
  26915. }
  26916. get localRotationEuler() {
  26917. if (this._locaEulerlUpdate) {
  26918. this._localRotation.getYawPitchRoll(AnimationTransform3D._tempVector3);
  26919. var euler = AnimationTransform3D._tempVector3;
  26920. var localRotationEuler = this._localRotationEuler;
  26921. localRotationEuler.x = euler.y * AnimationTransform3D._angleToRandin;
  26922. localRotationEuler.y = euler.x * AnimationTransform3D._angleToRandin;
  26923. localRotationEuler.z = euler.z * AnimationTransform3D._angleToRandin;
  26924. this._locaEulerlUpdate = false;
  26925. }
  26926. return this._localRotationEuler;
  26927. }
  26928. set localRotationEuler(value) {
  26929. this._localRotationEuler = value;
  26930. this._locaEulerlUpdate = false;
  26931. this._localQuaternionUpdate = true;
  26932. this._localUpdate = true;
  26933. this._onWorldTransform();
  26934. }
  26935. getWorldMatrix() {
  26936. if (!Laya.Render.supportWebGLPlusAnimation && this._worldUpdate) {
  26937. if (this._parent != null) {
  26938. Utils3D.matrix4x4MultiplyFFF(this._parent.getWorldMatrix(), this._getlocalMatrix(), this._worldMatrix);
  26939. }
  26940. else {
  26941. var e = this._worldMatrix;
  26942. 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;
  26943. e[0] = e[5] = e[10] = e[15] = 1;
  26944. }
  26945. this._worldUpdate = false;
  26946. }
  26947. if (Laya.Render.supportWebGLPlusAnimation && this._worldUpdate) {
  26948. this._worldUpdate = false;
  26949. }
  26950. return this._worldMatrix;
  26951. }
  26952. setParent(value) {
  26953. if (this._parent !== value) {
  26954. if (this._parent) {
  26955. var parentChilds = this._parent._children;
  26956. var index = parentChilds.indexOf(this);
  26957. parentChilds.splice(index, 1);
  26958. }
  26959. if (value) {
  26960. value._children.push(this);
  26961. (value) && (this._onWorldTransform());
  26962. }
  26963. this._parent = value;
  26964. }
  26965. }
  26966. }
  26967. AnimationTransform3D._tempVector3 = new Vector3();
  26968. AnimationTransform3D._angleToRandin = 180 / Math.PI;
  26969. class AnimationNode {
  26970. constructor(localPosition = null, localRotation = null, localScale = null, worldMatrix = null) {
  26971. this._children = [];
  26972. this.transform = new AnimationTransform3D(this, localPosition, localRotation, localScale, worldMatrix);
  26973. }
  26974. addChild(child) {
  26975. child._parent = this;
  26976. child.transform.setParent(this.transform);
  26977. this._children.push(child);
  26978. }
  26979. removeChild(child) {
  26980. var index = this._children.indexOf(child);
  26981. (index !== -1) && (this._children.splice(index, 1));
  26982. }
  26983. getChildByName(name) {
  26984. for (var i = 0, n = this._children.length; i < n; i++) {
  26985. var child = this._children[i];
  26986. if (child.name === name)
  26987. return child;
  26988. }
  26989. return null;
  26990. }
  26991. getChildByIndex(index) {
  26992. return this._children[index];
  26993. }
  26994. getChildCount() {
  26995. return this._children.length;
  26996. }
  26997. cloneTo(destObject) {
  26998. var destNode = destObject;
  26999. destNode.name = this.name;
  27000. for (var i = 0, n = this._children.length; i < n; i++) {
  27001. var child = this._children[i];
  27002. var destChild = child.clone();
  27003. destNode.addChild(destChild);
  27004. var transform = child.transform;
  27005. var destTransform = destChild.transform;
  27006. var destLocalPosition = destTransform.localPosition;
  27007. var destLocalRotation = destTransform.localRotation;
  27008. var destLocalScale = destTransform.localScale;
  27009. transform.localPosition.cloneTo(destLocalPosition);
  27010. transform.localRotation.cloneTo(destLocalRotation);
  27011. transform.localScale.cloneTo(destLocalScale);
  27012. destTransform.localPosition = destLocalPosition;
  27013. destTransform.localRotation = destLocalRotation;
  27014. destTransform.localScale = destLocalScale;
  27015. }
  27016. }
  27017. clone() {
  27018. var dest = new AnimationNode();
  27019. this.cloneTo(dest);
  27020. return dest;
  27021. }
  27022. _cloneNative(localPositions, localRotations, localScales, animationNodeWorldMatrixs, animationNodeParentIndices, parentIndex, avatar) {
  27023. var curID = avatar._nativeCurCloneCount;
  27024. animationNodeParentIndices[curID] = parentIndex;
  27025. var localPosition = new Float32Array(localPositions.buffer, curID * 3 * 4, 3);
  27026. var localRotation = new Float32Array(localRotations.buffer, curID * 4 * 4, 4);
  27027. var localScale = new Float32Array(localScales.buffer, curID * 3 * 4, 3);
  27028. var worldMatrix = new Float32Array(animationNodeWorldMatrixs.buffer, curID * 16 * 4, 16);
  27029. var dest = new AnimationNode(localPosition, localRotation, localScale, worldMatrix);
  27030. dest._worldMatrixIndex = curID;
  27031. this._cloneToNative(dest, localPositions, localRotations, localScales, animationNodeWorldMatrixs, animationNodeParentIndices, curID, avatar);
  27032. return dest;
  27033. }
  27034. _cloneToNative(destObject, localPositions, localRotations, localScales, animationNodeWorldMatrixs, animationNodeParentIndices, parentIndex, avatar) {
  27035. var destNode = destObject;
  27036. destNode.name = this.name;
  27037. for (var i = 0, n = this._children.length; i < n; i++) {
  27038. var child = this._children[i];
  27039. avatar._nativeCurCloneCount++;
  27040. var destChild = child._cloneNative(localPositions, localRotations, localScales, animationNodeWorldMatrixs, animationNodeParentIndices, parentIndex, avatar);
  27041. destNode.addChild(destChild);
  27042. var transform = child.transform;
  27043. var destTransform = destChild.transform;
  27044. var destLocalPosition = destTransform.localPosition;
  27045. var destLocalRotation = destTransform.localRotation;
  27046. var destLocalScale = destTransform.localScale;
  27047. transform.localPosition.cloneTo(destLocalPosition);
  27048. transform.localRotation.cloneTo(destLocalRotation);
  27049. transform.localScale.cloneTo(destLocalScale);
  27050. destTransform.localPosition = destLocalPosition;
  27051. destTransform.localRotation = destLocalRotation;
  27052. destTransform.localScale = destLocalScale;
  27053. }
  27054. }
  27055. }
  27056. class Avatar extends Laya.Resource {
  27057. constructor() {
  27058. super();
  27059. this._nativeNodeCount = 0;
  27060. this._nativeCurCloneCount = 0;
  27061. }
  27062. static _parse(data, propertyParams = null, constructParams = null) {
  27063. var avatar = new Avatar();
  27064. avatar._rootNode = new AnimationNode(new Float32Array(3), new Float32Array(4), new Float32Array(3), new Float32Array(16));
  27065. if (Laya.Render.supportWebGLPlusAnimation)
  27066. avatar._nativeNodeCount++;
  27067. if (data.version) {
  27068. var rootNode = data.rootNode;
  27069. (rootNode) && (avatar._parseNode(rootNode, avatar._rootNode));
  27070. }
  27071. return avatar;
  27072. }
  27073. static load(url, complete) {
  27074. Laya.ILaya.loader.create(url, complete, null, Avatar.AVATAR);
  27075. }
  27076. _initCloneToAnimator(destNode, destAnimator) {
  27077. destAnimator._avatarNodeMap[destNode.name] = destNode;
  27078. for (var i = 0, n = destNode.getChildCount(); i < n; i++)
  27079. this._initCloneToAnimator(destNode.getChildByIndex(i), destAnimator);
  27080. }
  27081. _parseNode(nodaData, node) {
  27082. var name = nodaData.props.name;
  27083. node.name = name;
  27084. var props = nodaData.props;
  27085. var transform = node.transform;
  27086. var pos = transform.localPosition;
  27087. var rot = transform.localRotation;
  27088. var sca = transform.localScale;
  27089. pos.fromArray(props.translate);
  27090. rot.fromArray(props.rotation);
  27091. sca.fromArray(props.scale);
  27092. transform.localPosition = pos;
  27093. transform.localRotation = rot;
  27094. transform.localScale = sca;
  27095. var childrenData = nodaData.child;
  27096. for (var j = 0, n = childrenData.length; j < n; j++) {
  27097. var childData = childrenData[j];
  27098. var childBone = new AnimationNode(new Float32Array(3), new Float32Array(4), new Float32Array(3), new Float32Array(16));
  27099. node.addChild(childBone);
  27100. if (Laya.Render.supportWebGLPlusAnimation)
  27101. this._nativeNodeCount++;
  27102. this._parseNode(childData, childBone);
  27103. }
  27104. }
  27105. _cloneDatasToAnimator(destAnimator) {
  27106. var destRoot;
  27107. destRoot = this._rootNode.clone();
  27108. var transform = this._rootNode.transform;
  27109. var destTransform = destRoot.transform;
  27110. var destPosition = destTransform.localPosition;
  27111. var destRotation = destTransform.localRotation;
  27112. var destScale = destTransform.localScale;
  27113. transform.localPosition.cloneTo(destPosition);
  27114. transform.localRotation.cloneTo(destRotation);
  27115. transform.localScale.cloneTo(destScale);
  27116. destTransform.localPosition = destPosition;
  27117. destTransform.localRotation = destRotation;
  27118. destTransform.localScale = destScale;
  27119. destAnimator._avatarNodeMap = {};
  27120. this._initCloneToAnimator(destRoot, destAnimator);
  27121. }
  27122. cloneTo(destObject) {
  27123. var destAvatar = destObject;
  27124. var destRoot = this._rootNode.clone();
  27125. destAvatar._rootNode = destRoot;
  27126. }
  27127. clone() {
  27128. var dest = new Avatar();
  27129. this.cloneTo(dest);
  27130. return dest;
  27131. }
  27132. _cloneDatasToAnimatorNative(destAnimator) {
  27133. var animationNodeLocalPositions = new Float32Array(this._nativeNodeCount * 3);
  27134. var animationNodeLocalRotations = new Float32Array(this._nativeNodeCount * 4);
  27135. var animationNodeLocalScales = new Float32Array(this._nativeNodeCount * 3);
  27136. var animationNodeWorldMatrixs = new Float32Array(this._nativeNodeCount * 16);
  27137. var animationNodeParentIndices = new Int16Array(this._nativeNodeCount);
  27138. destAnimator._animationNodeLocalPositions = animationNodeLocalPositions;
  27139. destAnimator._animationNodeLocalRotations = animationNodeLocalRotations;
  27140. destAnimator._animationNodeLocalScales = animationNodeLocalScales;
  27141. destAnimator._animationNodeWorldMatrixs = animationNodeWorldMatrixs;
  27142. destAnimator._animationNodeParentIndices = animationNodeParentIndices;
  27143. this._nativeCurCloneCount = 0;
  27144. var destRoot = this._rootNode._cloneNative(animationNodeLocalPositions, animationNodeLocalRotations, animationNodeLocalScales, animationNodeWorldMatrixs, animationNodeParentIndices, -1, this);
  27145. var transform = this._rootNode.transform;
  27146. var destTransform = destRoot.transform;
  27147. var destPosition = destTransform.localPosition;
  27148. var destRotation = destTransform.localRotation;
  27149. var destScale = destTransform.localScale;
  27150. transform.localPosition.cloneTo(destPosition);
  27151. transform.localRotation.cloneTo(destRotation);
  27152. transform.localScale.cloneTo(destScale);
  27153. destTransform.localPosition = destPosition;
  27154. destTransform.localRotation = destRotation;
  27155. destTransform.localScale = destScale;
  27156. destAnimator._avatarNodeMap = {};
  27157. this._initCloneToAnimator(destRoot, destAnimator);
  27158. }
  27159. }
  27160. Avatar.AVATAR = "AVATAR";
  27161. class SkyBoxMaterial extends BaseMaterial {
  27162. constructor() {
  27163. super();
  27164. this.setShaderName("SkyBox");
  27165. this.tintColor = new Vector4(0.5, 0.5, 0.5, 0.5);
  27166. this.exposure = 1.0;
  27167. this.rotation = 0;
  27168. }
  27169. static __initDefine__() {
  27170. }
  27171. get tintColor() {
  27172. return this._shaderValues.getVector(SkyBoxMaterial.TINTCOLOR);
  27173. }
  27174. set tintColor(value) {
  27175. this._shaderValues.setVector(SkyBoxMaterial.TINTCOLOR, value);
  27176. }
  27177. get exposure() {
  27178. return this._shaderValues.getNumber(SkyBoxMaterial.EXPOSURE);
  27179. }
  27180. set exposure(value) {
  27181. this._shaderValues.setNumber(SkyBoxMaterial.EXPOSURE, value);
  27182. }
  27183. get rotation() {
  27184. return this._shaderValues.getNumber(SkyBoxMaterial.ROTATION);
  27185. }
  27186. set rotation(value) {
  27187. this._shaderValues.setNumber(SkyBoxMaterial.ROTATION, value);
  27188. }
  27189. get textureCube() {
  27190. return this._shaderValues.getTexture(SkyBoxMaterial.TEXTURECUBE);
  27191. }
  27192. set textureCube(value) {
  27193. this._shaderValues.setTexture(SkyBoxMaterial.TEXTURECUBE, value);
  27194. }
  27195. clone() {
  27196. var dest = new SkyBoxMaterial();
  27197. this.cloneTo(dest);
  27198. return dest;
  27199. }
  27200. }
  27201. SkyBoxMaterial.TINTCOLOR = Shader3D.propertyNameToID("u_TintColor");
  27202. SkyBoxMaterial.EXPOSURE = Shader3D.propertyNameToID("u_Exposure");
  27203. SkyBoxMaterial.ROTATION = Shader3D.propertyNameToID("u_Rotation");
  27204. SkyBoxMaterial.TEXTURECUBE = Shader3D.propertyNameToID("u_CubeTexture");
  27205. class SubMesh extends GeometryElement {
  27206. constructor(mesh) {
  27207. super();
  27208. this._id = ++SubMesh._uniqueIDCounter;
  27209. this._mesh = mesh;
  27210. this._boneIndicesList = [];
  27211. this._subIndexBufferStart = [];
  27212. this._subIndexBufferCount = [];
  27213. }
  27214. get indexCount() {
  27215. return this._indexCount;
  27216. }
  27217. _setIndexRange(indexStart, indexCount) {
  27218. this._indexStart = indexStart;
  27219. this._indexCount = indexCount;
  27220. this._indices = new Uint16Array(this._indexBuffer.getData().buffer, indexStart * 2, indexCount);
  27221. }
  27222. _getType() {
  27223. return SubMesh._type;
  27224. }
  27225. _prepareRender(state) {
  27226. this._mesh._uploadVerticesData();
  27227. return true;
  27228. }
  27229. _render(state) {
  27230. var gl = Laya.LayaGL.instance;
  27231. this._mesh._bufferState.bind();
  27232. var skinnedDatas = state.renderElement.render._skinnedData;
  27233. if (skinnedDatas) {
  27234. var subSkinnedDatas = skinnedDatas[this._indexInMesh];
  27235. var boneIndicesListCount = this._boneIndicesList.length;
  27236. for (var i = 0; i < boneIndicesListCount; i++) {
  27237. state.shader.uploadCustomUniform(SkinnedMeshSprite3D.BONES, subSkinnedDatas[i]);
  27238. gl.drawElements(gl.TRIANGLES, this._subIndexBufferCount[i], gl.UNSIGNED_SHORT, this._subIndexBufferStart[i] * 2);
  27239. }
  27240. }
  27241. else {
  27242. gl.drawElements(gl.TRIANGLES, this._indexCount, gl.UNSIGNED_SHORT, this._indexStart * 2);
  27243. }
  27244. Laya.Stat.trianglesFaces += this._indexCount / 3;
  27245. Laya.Stat.renderBatches++;
  27246. }
  27247. getIndices() {
  27248. if (this._mesh._isReadable)
  27249. return this._indices.slice();
  27250. else
  27251. throw "SubMesh:can't get indices on subMesh,mesh's isReadable must be true.";
  27252. }
  27253. setIndices(indices) {
  27254. this._indexBuffer.setData(indices, this._indexStart, 0, this._indexCount);
  27255. }
  27256. destroy() {
  27257. if (this._destroyed)
  27258. return;
  27259. super.destroy();
  27260. this._indexBuffer.destroy();
  27261. this._indexBuffer = null;
  27262. this._mesh = null;
  27263. this._boneIndicesList = null;
  27264. this._subIndexBufferStart = null;
  27265. this._subIndexBufferCount = null;
  27266. this._skinAnimationDatas = null;
  27267. }
  27268. }
  27269. SubMesh._uniqueIDCounter = 0;
  27270. SubMesh._type = GeometryElement._typeCounter++;
  27271. class LoadModelV04 {
  27272. static parse(readData, version, mesh, subMeshes) {
  27273. LoadModelV04._mesh = mesh;
  27274. LoadModelV04._subMeshes = subMeshes;
  27275. LoadModelV04._version = version;
  27276. LoadModelV04._readData = readData;
  27277. LoadModelV04.READ_DATA();
  27278. LoadModelV04.READ_BLOCK();
  27279. LoadModelV04.READ_STRINGS();
  27280. for (var i = 0, n = LoadModelV04._BLOCK.count; i < n; i++) {
  27281. LoadModelV04._readData.pos = LoadModelV04._BLOCK.blockStarts[i];
  27282. var index = LoadModelV04._readData.getUint16();
  27283. var blockName = LoadModelV04._strings[index];
  27284. var fn = LoadModelV04["READ_" + blockName];
  27285. if (fn == null)
  27286. throw new Error("model file err,no this function:" + index + " " + blockName);
  27287. else
  27288. fn.call(null);
  27289. }
  27290. LoadModelV04._mesh._bindPoseIndices = new Uint16Array(LoadModelV04._bindPoseIndices);
  27291. LoadModelV04._bindPoseIndices.length = 0;
  27292. LoadModelV04._strings.length = 0;
  27293. LoadModelV04._readData = null;
  27294. LoadModelV04._version = null;
  27295. LoadModelV04._mesh = null;
  27296. LoadModelV04._subMeshes = null;
  27297. }
  27298. static _readString() {
  27299. return LoadModelV04._strings[LoadModelV04._readData.getUint16()];
  27300. }
  27301. static READ_DATA() {
  27302. LoadModelV04._DATA.offset = LoadModelV04._readData.getUint32();
  27303. LoadModelV04._DATA.size = LoadModelV04._readData.getUint32();
  27304. }
  27305. static READ_BLOCK() {
  27306. var count = LoadModelV04._BLOCK.count = LoadModelV04._readData.getUint16();
  27307. var blockStarts = LoadModelV04._BLOCK.blockStarts = [];
  27308. var blockLengths = LoadModelV04._BLOCK.blockLengths = [];
  27309. for (var i = 0; i < count; i++) {
  27310. blockStarts.push(LoadModelV04._readData.getUint32());
  27311. blockLengths.push(LoadModelV04._readData.getUint32());
  27312. }
  27313. }
  27314. static READ_STRINGS() {
  27315. var offset = LoadModelV04._readData.getUint32();
  27316. var count = LoadModelV04._readData.getUint16();
  27317. var prePos = LoadModelV04._readData.pos;
  27318. LoadModelV04._readData.pos = offset + LoadModelV04._DATA.offset;
  27319. for (var i = 0; i < count; i++)
  27320. LoadModelV04._strings[i] = LoadModelV04._readData.readUTFString();
  27321. LoadModelV04._readData.pos = prePos;
  27322. }
  27323. static READ_MESH() {
  27324. var gl = Laya.LayaGL.instance;
  27325. var name = LoadModelV04._readString();
  27326. var arrayBuffer = LoadModelV04._readData.__getBuffer();
  27327. var i;
  27328. var memorySize = 0;
  27329. var vertexBufferCount = LoadModelV04._readData.getInt16();
  27330. var offset = LoadModelV04._DATA.offset;
  27331. for (i = 0; i < vertexBufferCount; i++) {
  27332. var vbStart = offset + LoadModelV04._readData.getUint32();
  27333. var vbLength = LoadModelV04._readData.getUint32();
  27334. var vbArrayBuffer = arrayBuffer.slice(vbStart, vbStart + vbLength);
  27335. var vbDatas = new Float32Array(vbArrayBuffer);
  27336. var bufferAttribute = LoadModelV04._readString();
  27337. var vertexDeclaration;
  27338. switch (LoadModelV04._version) {
  27339. case "LAYAMODEL:0301":
  27340. case "LAYAMODEL:0400":
  27341. vertexDeclaration = VertexMesh.getVertexDeclaration(bufferAttribute);
  27342. break;
  27343. case "LAYAMODEL:0401":
  27344. vertexDeclaration = VertexMesh.getVertexDeclaration(bufferAttribute, false);
  27345. break;
  27346. default:
  27347. throw new Error("LoadModelV03: unknown version.");
  27348. }
  27349. if (!vertexDeclaration)
  27350. throw new Error("LoadModelV03: unknown vertexDeclaration.");
  27351. var vertexBuffer = new VertexBuffer3D(vbDatas.length * 4, gl.STATIC_DRAW, true);
  27352. vertexBuffer.vertexDeclaration = vertexDeclaration;
  27353. vertexBuffer.setData(vbDatas.buffer);
  27354. LoadModelV04._mesh._vertexBuffer = vertexBuffer;
  27355. LoadModelV04._mesh._vertexCount += vertexBuffer.vertexCount;
  27356. memorySize += vbDatas.length * 4;
  27357. }
  27358. var ibStart = offset + LoadModelV04._readData.getUint32();
  27359. var ibLength = LoadModelV04._readData.getUint32();
  27360. var ibDatas = new Uint16Array(arrayBuffer.slice(ibStart, ibStart + ibLength));
  27361. var indexBuffer = new IndexBuffer3D(IndexBuffer3D.INDEXTYPE_USHORT, ibLength / 2, gl.STATIC_DRAW, true);
  27362. indexBuffer.setData(ibDatas);
  27363. LoadModelV04._mesh._indexBuffer = indexBuffer;
  27364. memorySize += indexBuffer.indexCount * 2;
  27365. LoadModelV04._mesh._setBuffer(LoadModelV04._mesh._vertexBuffer, indexBuffer);
  27366. LoadModelV04._mesh._setCPUMemory(memorySize);
  27367. LoadModelV04._mesh._setGPUMemory(memorySize);
  27368. var boneNames = LoadModelV04._mesh._boneNames = [];
  27369. var boneCount = LoadModelV04._readData.getUint16();
  27370. boneNames.length = boneCount;
  27371. for (i = 0; i < boneCount; i++)
  27372. boneNames[i] = LoadModelV04._strings[LoadModelV04._readData.getUint16()];
  27373. LoadModelV04._readData.pos += 8;
  27374. var bindPoseDataStart = LoadModelV04._readData.getUint32();
  27375. var bindPoseDataLength = LoadModelV04._readData.getUint32();
  27376. var bindPoseDatas = new Float32Array(arrayBuffer.slice(offset + bindPoseDataStart, offset + bindPoseDataStart + bindPoseDataLength));
  27377. var bindPoseFloatCount = bindPoseDatas.length;
  27378. var bindPoseBuffer = LoadModelV04._mesh._inverseBindPosesBuffer = new ArrayBuffer(bindPoseFloatCount * 4);
  27379. LoadModelV04._mesh._inverseBindPoses = [];
  27380. for (i = 0; i < bindPoseFloatCount; i += 16) {
  27381. 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));
  27382. LoadModelV04._mesh._inverseBindPoses[i / 16] = inverseGlobalBindPose;
  27383. }
  27384. return true;
  27385. }
  27386. static READ_SUBMESH() {
  27387. var arrayBuffer = LoadModelV04._readData.__getBuffer();
  27388. var subMesh = new SubMesh(LoadModelV04._mesh);
  27389. LoadModelV04._readData.getInt16();
  27390. LoadModelV04._readData.getUint32();
  27391. LoadModelV04._readData.getUint32();
  27392. var ibStart = LoadModelV04._readData.getUint32();
  27393. var ibCount = LoadModelV04._readData.getUint32();
  27394. var indexBuffer = LoadModelV04._mesh._indexBuffer;
  27395. subMesh._indexBuffer = indexBuffer;
  27396. subMesh._setIndexRange(ibStart, ibCount);
  27397. var vertexBuffer = LoadModelV04._mesh._vertexBuffer;
  27398. subMesh._vertexBuffer = vertexBuffer;
  27399. var offset = LoadModelV04._DATA.offset;
  27400. var subIndexBufferStart = subMesh._subIndexBufferStart;
  27401. var subIndexBufferCount = subMesh._subIndexBufferCount;
  27402. var boneIndicesList = subMesh._boneIndicesList;
  27403. var drawCount = LoadModelV04._readData.getUint16();
  27404. subIndexBufferStart.length = drawCount;
  27405. subIndexBufferCount.length = drawCount;
  27406. boneIndicesList.length = drawCount;
  27407. var pathMarks = LoadModelV04._mesh._skinDataPathMarks;
  27408. var bindPoseIndices = LoadModelV04._bindPoseIndices;
  27409. var subMeshIndex = LoadModelV04._subMeshes.length;
  27410. for (var i = 0; i < drawCount; i++) {
  27411. subIndexBufferStart[i] = LoadModelV04._readData.getUint32();
  27412. subIndexBufferCount[i] = LoadModelV04._readData.getUint32();
  27413. var boneDicofs = LoadModelV04._readData.getUint32();
  27414. var boneDicCount = LoadModelV04._readData.getUint32();
  27415. var boneIndices = boneIndicesList[i] = new Uint16Array(arrayBuffer.slice(offset + boneDicofs, offset + boneDicofs + boneDicCount));
  27416. for (var j = 0, m = boneIndices.length; j < m; j++) {
  27417. var index = boneIndices[j];
  27418. var combineIndex = bindPoseIndices.indexOf(index);
  27419. if (combineIndex === -1) {
  27420. boneIndices[j] = bindPoseIndices.length;
  27421. bindPoseIndices.push(index);
  27422. pathMarks.push([subMeshIndex, i, j]);
  27423. }
  27424. else {
  27425. boneIndices[j] = combineIndex;
  27426. }
  27427. }
  27428. }
  27429. LoadModelV04._subMeshes.push(subMesh);
  27430. return true;
  27431. }
  27432. }
  27433. LoadModelV04._BLOCK = { count: 0 };
  27434. LoadModelV04._DATA = { offset: 0, size: 0 };
  27435. LoadModelV04._strings = [];
  27436. LoadModelV04._bindPoseIndices = [];
  27437. class LoadModelV05 {
  27438. static parse(readData, version, mesh, subMeshes) {
  27439. LoadModelV05._mesh = mesh;
  27440. LoadModelV05._subMeshes = subMeshes;
  27441. LoadModelV05._version = version;
  27442. LoadModelV05._readData = readData;
  27443. LoadModelV05.READ_DATA();
  27444. LoadModelV05.READ_BLOCK();
  27445. LoadModelV05.READ_STRINGS();
  27446. for (var i = 0, n = LoadModelV05._BLOCK.count; i < n; i++) {
  27447. LoadModelV05._readData.pos = LoadModelV05._BLOCK.blockStarts[i];
  27448. var index = LoadModelV05._readData.getUint16();
  27449. var blockName = LoadModelV05._strings[index];
  27450. var fn = LoadModelV05["READ_" + blockName];
  27451. if (fn == null)
  27452. throw new Error("model file err,no this function:" + index + " " + blockName);
  27453. else
  27454. fn.call(null);
  27455. }
  27456. LoadModelV05._mesh._bindPoseIndices = new Uint16Array(LoadModelV05._bindPoseIndices);
  27457. LoadModelV05._bindPoseIndices.length = 0;
  27458. LoadModelV05._strings.length = 0;
  27459. LoadModelV05._readData = null;
  27460. LoadModelV05._version = null;
  27461. LoadModelV05._mesh = null;
  27462. LoadModelV05._subMeshes = null;
  27463. }
  27464. static _readString() {
  27465. return LoadModelV05._strings[LoadModelV05._readData.getUint16()];
  27466. }
  27467. static READ_DATA() {
  27468. LoadModelV05._DATA.offset = LoadModelV05._readData.getUint32();
  27469. LoadModelV05._DATA.size = LoadModelV05._readData.getUint32();
  27470. }
  27471. static READ_BLOCK() {
  27472. var count = LoadModelV05._BLOCK.count = LoadModelV05._readData.getUint16();
  27473. var blockStarts = LoadModelV05._BLOCK.blockStarts = [];
  27474. var blockLengths = LoadModelV05._BLOCK.blockLengths = [];
  27475. for (var i = 0; i < count; i++) {
  27476. blockStarts.push(LoadModelV05._readData.getUint32());
  27477. blockLengths.push(LoadModelV05._readData.getUint32());
  27478. }
  27479. }
  27480. static READ_STRINGS() {
  27481. var offset = LoadModelV05._readData.getUint32();
  27482. var count = LoadModelV05._readData.getUint16();
  27483. var prePos = LoadModelV05._readData.pos;
  27484. LoadModelV05._readData.pos = offset + LoadModelV05._DATA.offset;
  27485. for (var i = 0; i < count; i++)
  27486. LoadModelV05._strings[i] = LoadModelV05._readData.readUTFString();
  27487. LoadModelV05._readData.pos = prePos;
  27488. }
  27489. static READ_MESH() {
  27490. var gl = Laya.LayaGL.instance;
  27491. var i;
  27492. var memorySize = 0;
  27493. var name = LoadModelV05._readString();
  27494. var arrayBuffer = LoadModelV05._readData.__getBuffer();
  27495. var vertexBufferCount = LoadModelV05._readData.getInt16();
  27496. var offset = LoadModelV05._DATA.offset;
  27497. for (i = 0; i < vertexBufferCount; i++) {
  27498. var vbStart = offset + LoadModelV05._readData.getUint32();
  27499. var vertexCount = LoadModelV05._readData.getUint32();
  27500. var vertexFlag = LoadModelV05._readString();
  27501. var vertexDeclaration = VertexMesh.getVertexDeclaration(vertexFlag, false);
  27502. var vertexStride = vertexDeclaration.vertexStride;
  27503. var vertexData;
  27504. var floatData;
  27505. var uint8Data;
  27506. var subVertexFlags = vertexFlag.split(",");
  27507. var subVertexCount = subVertexFlags.length;
  27508. switch (LoadModelV05._version) {
  27509. case "LAYAMODEL:05":
  27510. vertexData = arrayBuffer.slice(vbStart, vbStart + vertexCount * vertexStride);
  27511. floatData = new Float32Array(vertexData);
  27512. uint8Data = new Uint8Array(vertexData);
  27513. break;
  27514. case "LAYAMODEL:COMPRESSION_05":
  27515. vertexData = new ArrayBuffer(vertexStride * vertexCount);
  27516. floatData = new Float32Array(vertexData);
  27517. uint8Data = new Uint8Array(vertexData);
  27518. var lastPosition = LoadModelV05._readData.pos;
  27519. LoadModelV05._readData.pos = vbStart;
  27520. for (var j = 0; j < vertexCount; j++) {
  27521. var subOffset;
  27522. var verOffset = j * vertexStride;
  27523. for (var k = 0; k < subVertexCount; k++) {
  27524. switch (subVertexFlags[k]) {
  27525. case "POSITION":
  27526. subOffset = verOffset / 4;
  27527. floatData[subOffset] = HalfFloatUtils.convertToNumber(LoadModelV05._readData.getUint16());
  27528. floatData[subOffset + 1] = HalfFloatUtils.convertToNumber(LoadModelV05._readData.getUint16());
  27529. floatData[subOffset + 2] = HalfFloatUtils.convertToNumber(LoadModelV05._readData.getUint16());
  27530. verOffset += 12;
  27531. break;
  27532. case "NORMAL":
  27533. subOffset = verOffset / 4;
  27534. floatData[subOffset] = LoadModelV05._readData.getUint8() / 127.5 - 1;
  27535. floatData[subOffset + 1] = LoadModelV05._readData.getUint8() / 127.5 - 1;
  27536. floatData[subOffset + 2] = LoadModelV05._readData.getUint8() / 127.5 - 1;
  27537. verOffset += 12;
  27538. break;
  27539. case "COLOR":
  27540. subOffset = verOffset / 4;
  27541. floatData[subOffset] = LoadModelV05._readData.getUint8() / 255;
  27542. floatData[subOffset + 1] = LoadModelV05._readData.getUint8() / 255;
  27543. floatData[subOffset + 2] = LoadModelV05._readData.getUint8() / 255;
  27544. floatData[subOffset + 3] = LoadModelV05._readData.getUint8() / 255;
  27545. verOffset += 16;
  27546. break;
  27547. case "UV":
  27548. subOffset = verOffset / 4;
  27549. floatData[subOffset] = HalfFloatUtils.convertToNumber(LoadModelV05._readData.getUint16());
  27550. floatData[subOffset + 1] = HalfFloatUtils.convertToNumber(LoadModelV05._readData.getUint16());
  27551. verOffset += 8;
  27552. break;
  27553. case "UV1":
  27554. subOffset = verOffset / 4;
  27555. floatData[subOffset] = HalfFloatUtils.convertToNumber(LoadModelV05._readData.getUint16());
  27556. floatData[subOffset + 1] = HalfFloatUtils.convertToNumber(LoadModelV05._readData.getUint16());
  27557. verOffset += 8;
  27558. break;
  27559. case "BLENDWEIGHT":
  27560. subOffset = verOffset / 4;
  27561. floatData[subOffset] = LoadModelV05._readData.getUint8() / 255;
  27562. floatData[subOffset + 1] = LoadModelV05._readData.getUint8() / 255;
  27563. floatData[subOffset + 2] = LoadModelV05._readData.getUint8() / 255;
  27564. floatData[subOffset + 3] = LoadModelV05._readData.getUint8() / 255;
  27565. verOffset += 16;
  27566. break;
  27567. case "BLENDINDICES":
  27568. uint8Data[verOffset] = LoadModelV05._readData.getUint8();
  27569. uint8Data[verOffset + 1] = LoadModelV05._readData.getUint8();
  27570. uint8Data[verOffset + 2] = LoadModelV05._readData.getUint8();
  27571. uint8Data[verOffset + 3] = LoadModelV05._readData.getUint8();
  27572. verOffset += 4;
  27573. break;
  27574. case "TANGENT":
  27575. subOffset = verOffset / 4;
  27576. floatData[subOffset] = LoadModelV05._readData.getUint8() / 127.5 - 1;
  27577. floatData[subOffset + 1] = LoadModelV05._readData.getUint8() / 127.5 - 1;
  27578. floatData[subOffset + 2] = LoadModelV05._readData.getUint8() / 127.5 - 1;
  27579. floatData[subOffset + 3] = LoadModelV05._readData.getUint8() / 127.5 - 1;
  27580. verOffset += 16;
  27581. break;
  27582. }
  27583. }
  27584. }
  27585. LoadModelV05._readData.pos = lastPosition;
  27586. break;
  27587. }
  27588. var vertexBuffer = new VertexBuffer3D(vertexData.byteLength, gl.STATIC_DRAW, true);
  27589. vertexBuffer.vertexDeclaration = vertexDeclaration;
  27590. vertexBuffer.setData(vertexData);
  27591. LoadModelV05._mesh._vertexBuffer = vertexBuffer;
  27592. LoadModelV05._mesh._vertexCount += vertexBuffer.vertexCount;
  27593. memorySize += floatData.length * 4;
  27594. }
  27595. var ibStart = offset + LoadModelV05._readData.getUint32();
  27596. var ibLength = LoadModelV05._readData.getUint32();
  27597. var ibDatas = new Uint16Array(arrayBuffer.slice(ibStart, ibStart + ibLength));
  27598. var indexBuffer = new IndexBuffer3D(IndexBuffer3D.INDEXTYPE_USHORT, ibLength / 2, gl.STATIC_DRAW, true);
  27599. indexBuffer.setData(ibDatas);
  27600. LoadModelV05._mesh._indexBuffer = indexBuffer;
  27601. LoadModelV05._mesh._setBuffer(LoadModelV05._mesh._vertexBuffer, indexBuffer);
  27602. memorySize += indexBuffer.indexCount * 2;
  27603. LoadModelV05._mesh._setCPUMemory(memorySize);
  27604. LoadModelV05._mesh._setGPUMemory(memorySize);
  27605. var boneNames = LoadModelV05._mesh._boneNames = [];
  27606. var boneCount = LoadModelV05._readData.getUint16();
  27607. boneNames.length = boneCount;
  27608. for (i = 0; i < boneCount; i++)
  27609. boneNames[i] = LoadModelV05._strings[LoadModelV05._readData.getUint16()];
  27610. var bindPoseDataStart = LoadModelV05._readData.getUint32();
  27611. var bindPoseDataLength = LoadModelV05._readData.getUint32();
  27612. var bindPoseDatas = new Float32Array(arrayBuffer.slice(offset + bindPoseDataStart, offset + bindPoseDataStart + bindPoseDataLength));
  27613. var bindPoseFloatCount = bindPoseDatas.length;
  27614. var bindPoseBuffer = LoadModelV05._mesh._inverseBindPosesBuffer = new ArrayBuffer(bindPoseFloatCount * 4);
  27615. LoadModelV05._mesh._inverseBindPoses = [];
  27616. for (i = 0; i < bindPoseFloatCount; i += 16) {
  27617. 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));
  27618. LoadModelV05._mesh._inverseBindPoses[i / 16] = inverseGlobalBindPose;
  27619. }
  27620. return true;
  27621. }
  27622. static READ_SUBMESH() {
  27623. var arrayBuffer = LoadModelV05._readData.__getBuffer();
  27624. var subMesh = new SubMesh(LoadModelV05._mesh);
  27625. LoadModelV05._readData.getInt16();
  27626. var ibStart = LoadModelV05._readData.getUint32();
  27627. var ibCount = LoadModelV05._readData.getUint32();
  27628. var indexBuffer = LoadModelV05._mesh._indexBuffer;
  27629. subMesh._indexBuffer = indexBuffer;
  27630. subMesh._setIndexRange(ibStart, ibCount);
  27631. var vertexBuffer = LoadModelV05._mesh._vertexBuffer;
  27632. subMesh._vertexBuffer = vertexBuffer;
  27633. var offset = LoadModelV05._DATA.offset;
  27634. var subIndexBufferStart = subMesh._subIndexBufferStart;
  27635. var subIndexBufferCount = subMesh._subIndexBufferCount;
  27636. var boneIndicesList = subMesh._boneIndicesList;
  27637. var drawCount = LoadModelV05._readData.getUint16();
  27638. subIndexBufferStart.length = drawCount;
  27639. subIndexBufferCount.length = drawCount;
  27640. boneIndicesList.length = drawCount;
  27641. var pathMarks = LoadModelV05._mesh._skinDataPathMarks;
  27642. var bindPoseIndices = LoadModelV05._bindPoseIndices;
  27643. var subMeshIndex = LoadModelV05._subMeshes.length;
  27644. for (var i = 0; i < drawCount; i++) {
  27645. subIndexBufferStart[i] = LoadModelV05._readData.getUint32();
  27646. subIndexBufferCount[i] = LoadModelV05._readData.getUint32();
  27647. var boneDicofs = LoadModelV05._readData.getUint32();
  27648. var boneDicCount = LoadModelV05._readData.getUint32();
  27649. var boneIndices = boneIndicesList[i] = new Uint16Array(arrayBuffer.slice(offset + boneDicofs, offset + boneDicofs + boneDicCount));
  27650. for (var j = 0, m = boneIndices.length; j < m; j++) {
  27651. var index = boneIndices[j];
  27652. var combineIndex = bindPoseIndices.indexOf(index);
  27653. if (combineIndex === -1) {
  27654. boneIndices[j] = bindPoseIndices.length;
  27655. bindPoseIndices.push(index);
  27656. pathMarks.push([subMeshIndex, i, j]);
  27657. }
  27658. else {
  27659. boneIndices[j] = combineIndex;
  27660. }
  27661. }
  27662. }
  27663. LoadModelV05._subMeshes.push(subMesh);
  27664. return true;
  27665. }
  27666. }
  27667. LoadModelV05._BLOCK = { count: 0 };
  27668. LoadModelV05._DATA = { offset: 0, size: 0 };
  27669. LoadModelV05._strings = [];
  27670. LoadModelV05._bindPoseIndices = [];
  27671. class MeshReader {
  27672. constructor() {
  27673. }
  27674. static read(data, mesh, subMeshes) {
  27675. var readData = new Laya.Byte(data);
  27676. readData.pos = 0;
  27677. var version = readData.readUTFString();
  27678. switch (version) {
  27679. case "LAYAMODEL:0301":
  27680. case "LAYAMODEL:0400":
  27681. case "LAYAMODEL:0401":
  27682. LoadModelV04.parse(readData, version, mesh, subMeshes);
  27683. break;
  27684. case "LAYAMODEL:05":
  27685. case "LAYAMODEL:COMPRESSION_05":
  27686. LoadModelV05.parse(readData, version, mesh, subMeshes);
  27687. break;
  27688. default:
  27689. throw new Error("MeshReader: unknown mesh version.");
  27690. }
  27691. mesh._setSubMeshes(subMeshes);
  27692. }
  27693. }
  27694. class Mesh extends Laya.Resource {
  27695. constructor(isReadable = true) {
  27696. super();
  27697. this._tempVector30 = new Vector3();
  27698. this._tempVector31 = new Vector3();
  27699. this._tempVector32 = new Vector3();
  27700. this._minVerticesUpdate = -1;
  27701. this._maxVerticesUpdate = -1;
  27702. this._needUpdateBounds = true;
  27703. this._bounds = new Bounds(new Vector3(), new Vector3());
  27704. this._bufferState = new BufferState();
  27705. this._instanceBufferState = new BufferState();
  27706. this._vertexBuffer = null;
  27707. this._indexBuffer = null;
  27708. this._vertexCount = 0;
  27709. this._isReadable = isReadable;
  27710. this._subMeshes = [];
  27711. this._skinDataPathMarks = [];
  27712. }
  27713. static __init__() {
  27714. var physics3D = Physics3D._physics3D;
  27715. if (physics3D) {
  27716. Mesh._nativeTempVector30 = new physics3D.btVector3(0, 0, 0);
  27717. Mesh._nativeTempVector31 = new physics3D.btVector3(0, 0, 0);
  27718. Mesh._nativeTempVector32 = new physics3D.btVector3(0, 0, 0);
  27719. }
  27720. }
  27721. static _parse(data, propertyParams = null, constructParams = null) {
  27722. var mesh = new Mesh();
  27723. MeshReader.read(data, mesh, mesh._subMeshes);
  27724. return mesh;
  27725. }
  27726. static load(url, complete) {
  27727. Laya.ILaya.loader.create(url, complete, null, Mesh.MESH);
  27728. }
  27729. get inverseAbsoluteBindPoses() {
  27730. return this._inverseBindPoses;
  27731. }
  27732. get vertexCount() {
  27733. return this._vertexCount;
  27734. }
  27735. get indexCount() {
  27736. return this._indexBuffer.indexCount;
  27737. }
  27738. get subMeshCount() {
  27739. return this._subMeshes.length;
  27740. }
  27741. get bounds() {
  27742. return this._bounds;
  27743. }
  27744. set bounds(value) {
  27745. if (this._bounds !== value)
  27746. value.cloneTo(this._bounds);
  27747. }
  27748. _getPositionElement(vertexBuffer) {
  27749. var vertexElements = vertexBuffer.vertexDeclaration._vertexElements;
  27750. for (var i = 0, n = vertexElements.length; i < n; i++) {
  27751. var vertexElement = vertexElements[i];
  27752. if (vertexElement._elementFormat === VertexElementFormat.Vector3 && vertexElement._elementUsage === VertexMesh.MESH_POSITION0)
  27753. return vertexElement;
  27754. }
  27755. return null;
  27756. }
  27757. _getVerticeElementData(data, elementUsage) {
  27758. data.length = this._vertexCount;
  27759. var verDec = this._vertexBuffer.vertexDeclaration;
  27760. var element = verDec.getVertexElementByUsage(elementUsage);
  27761. if (element) {
  27762. var uint8Vertices = this._vertexBuffer.getUint8Data();
  27763. var floatVertices = this._vertexBuffer.getFloat32Data();
  27764. var uint8VerStr = verDec.vertexStride;
  27765. var floatVerStr = uint8VerStr / 4;
  27766. var uint8EleOffset = element._offset;
  27767. var floatEleOffset = uint8EleOffset / 4;
  27768. switch (elementUsage) {
  27769. case VertexMesh.MESH_TEXTURECOORDINATE0:
  27770. case VertexMesh.MESH_TEXTURECOORDINATE1:
  27771. for (var i = 0; i < this._vertexCount; i++) {
  27772. var offset = floatVerStr * i + floatEleOffset;
  27773. data[i] = new Vector2(floatVertices[offset], floatVertices[offset + 1]);
  27774. }
  27775. break;
  27776. case VertexMesh.MESH_POSITION0:
  27777. case VertexMesh.MESH_NORMAL0:
  27778. for (var i = 0; i < this._vertexCount; i++) {
  27779. var offset = floatVerStr * i + floatEleOffset;
  27780. data[i] = new Vector3(floatVertices[offset], floatVertices[offset + 1], floatVertices[offset + 2]);
  27781. }
  27782. break;
  27783. case VertexMesh.MESH_TANGENT0:
  27784. case VertexMesh.MESH_BLENDWEIGHT0:
  27785. for (var i = 0; i < this._vertexCount; i++) {
  27786. var offset = floatVerStr * i + floatEleOffset;
  27787. data[i] = new Vector4(floatVertices[offset], floatVertices[offset + 1], floatVertices[offset + 2], floatVertices[offset + 3]);
  27788. }
  27789. break;
  27790. case VertexMesh.MESH_COLOR0:
  27791. for (var i = 0; i < this._vertexCount; i++) {
  27792. var offset = floatVerStr * i + floatEleOffset;
  27793. data[i] = new Color(floatVertices[offset], floatVertices[offset + 1], floatVertices[offset + 2], floatVertices[offset + 3]);
  27794. }
  27795. break;
  27796. case VertexMesh.MESH_BLENDINDICES0:
  27797. for (var i = 0; i < this._vertexCount; i++) {
  27798. var offset = uint8VerStr * i + uint8EleOffset;
  27799. data[i] = new Vector4(uint8Vertices[offset], uint8Vertices[offset + 1], uint8Vertices[offset + 2], uint8Vertices[offset + 3]);
  27800. }
  27801. break;
  27802. default:
  27803. throw "Mesh:Unknown elementUsage.";
  27804. }
  27805. }
  27806. }
  27807. _setVerticeElementData(data, elementUsage) {
  27808. var verDec = this._vertexBuffer.vertexDeclaration;
  27809. var element = verDec.getVertexElementByUsage(elementUsage);
  27810. if (element) {
  27811. var uint8Vertices = this._vertexBuffer.getUint8Data();
  27812. var floatVertices = this._vertexBuffer.getFloat32Data();
  27813. var uint8VerStr = verDec.vertexStride;
  27814. var float8VerStr = uint8VerStr / 4;
  27815. var uint8EleOffset = element._offset;
  27816. var floatEleOffset = uint8EleOffset / 4;
  27817. switch (elementUsage) {
  27818. case VertexMesh.MESH_TEXTURECOORDINATE0:
  27819. case VertexMesh.MESH_TEXTURECOORDINATE1:
  27820. for (var i = 0, n = data.length; i < n; i++) {
  27821. var offset = float8VerStr * i + floatEleOffset;
  27822. var vec2 = data[i];
  27823. floatVertices[offset] = vec2.x;
  27824. floatVertices[offset + 1] = vec2.y;
  27825. }
  27826. break;
  27827. case VertexMesh.MESH_POSITION0:
  27828. case VertexMesh.MESH_NORMAL0:
  27829. for (var i = 0, n = data.length; i < n; i++) {
  27830. var offset = float8VerStr * i + floatEleOffset;
  27831. var vec3 = data[i];
  27832. floatVertices[offset] = vec3.x;
  27833. floatVertices[offset + 1] = vec3.y;
  27834. floatVertices[offset + 2] = vec3.z;
  27835. }
  27836. break;
  27837. case VertexMesh.MESH_TANGENT0:
  27838. case VertexMesh.MESH_BLENDWEIGHT0:
  27839. for (var i = 0, n = data.length; i < n; i++) {
  27840. var offset = float8VerStr * i + floatEleOffset;
  27841. var vec4 = data[i];
  27842. floatVertices[offset] = vec4.x;
  27843. floatVertices[offset + 1] = vec4.y;
  27844. floatVertices[offset + 2] = vec4.z;
  27845. floatVertices[offset + 3] = vec4.w;
  27846. }
  27847. break;
  27848. case VertexMesh.MESH_COLOR0:
  27849. for (var i = 0, n = data.length; i < n; i++) {
  27850. var offset = float8VerStr * i + floatEleOffset;
  27851. var cor = data[i];
  27852. floatVertices[offset] = cor.r;
  27853. floatVertices[offset + 1] = cor.g;
  27854. floatVertices[offset + 2] = cor.b;
  27855. floatVertices[offset + 2] = cor.a;
  27856. }
  27857. break;
  27858. case VertexMesh.MESH_BLENDINDICES0:
  27859. for (var i = 0, n = data.length; i < n; i++) {
  27860. var offset = uint8VerStr * i + uint8EleOffset;
  27861. var vec4 = data[i];
  27862. uint8Vertices[offset] = vec4.x;
  27863. uint8Vertices[offset + 1] = vec4.y;
  27864. uint8Vertices[offset + 2] = vec4.z;
  27865. uint8Vertices[offset + 3] = vec4.w;
  27866. }
  27867. break;
  27868. default:
  27869. throw "Mesh:Unknown elementUsage.";
  27870. }
  27871. }
  27872. else {
  27873. console.warn("Mesh: the mesh don't have this VertexElement.");
  27874. }
  27875. }
  27876. _disposeResource() {
  27877. for (var i = 0, n = this._subMeshes.length; i < n; i++)
  27878. this._subMeshes[i].destroy();
  27879. this._nativeTriangleMesh && window.Physics3D.destroy(this._nativeTriangleMesh);
  27880. this._vertexBuffer.destroy();
  27881. this._indexBuffer.destroy();
  27882. this._setCPUMemory(0);
  27883. this._setGPUMemory(0);
  27884. this._bufferState.destroy();
  27885. this._instanceBufferState.destroy();
  27886. this._bufferState = null;
  27887. this._instanceBufferState = null;
  27888. this._vertexBuffer = null;
  27889. this._indexBuffer = null;
  27890. this._subMeshes = null;
  27891. this._nativeTriangleMesh = null;
  27892. this._indexBuffer = null;
  27893. this._boneNames = null;
  27894. this._inverseBindPoses = null;
  27895. }
  27896. _setSubMeshes(subMeshes) {
  27897. this._subMeshes = subMeshes;
  27898. for (var i = 0, n = subMeshes.length; i < n; i++)
  27899. subMeshes[i]._indexInMesh = i;
  27900. this.calculateBounds();
  27901. }
  27902. _setBuffer(vertexBuffer, indexBuffer) {
  27903. var bufferState = this._bufferState;
  27904. bufferState.bind();
  27905. bufferState.applyVertexBuffer(vertexBuffer);
  27906. bufferState.applyIndexBuffer(indexBuffer);
  27907. bufferState.unBind();
  27908. var instanceBufferState = this._instanceBufferState;
  27909. instanceBufferState.bind();
  27910. instanceBufferState.applyVertexBuffer(vertexBuffer);
  27911. instanceBufferState.applyInstanceVertexBuffer(SubMeshInstanceBatch.instance.instanceWorldMatrixBuffer);
  27912. instanceBufferState.applyInstanceVertexBuffer(SubMeshInstanceBatch.instance.instanceMVPMatrixBuffer);
  27913. instanceBufferState.applyIndexBuffer(indexBuffer);
  27914. instanceBufferState.unBind();
  27915. }
  27916. _getPhysicMesh() {
  27917. if (!this._nativeTriangleMesh) {
  27918. var physics3D = window.Physics3D;
  27919. var triangleMesh = new physics3D.btTriangleMesh();
  27920. var nativePositio0 = Mesh._nativeTempVector30;
  27921. var nativePositio1 = Mesh._nativeTempVector31;
  27922. var nativePositio2 = Mesh._nativeTempVector32;
  27923. var position0 = this._tempVector30;
  27924. var position1 = this._tempVector31;
  27925. var position2 = this._tempVector32;
  27926. var vertexBuffer = this._vertexBuffer;
  27927. var positionElement = this._getPositionElement(vertexBuffer);
  27928. var verticesData = vertexBuffer.getFloat32Data();
  27929. var floatCount = vertexBuffer.vertexDeclaration.vertexStride / 4;
  27930. var posOffset = positionElement._offset / 4;
  27931. var indices = this._indexBuffer.getData();
  27932. for (var i = 0, n = indices.length; i < n; i += 3) {
  27933. var p0Index = indices[i] * floatCount + posOffset;
  27934. var p1Index = indices[i + 1] * floatCount + posOffset;
  27935. var p2Index = indices[i + 2] * floatCount + posOffset;
  27936. position0.setValue(verticesData[p0Index], verticesData[p0Index + 1], verticesData[p0Index + 2]);
  27937. position1.setValue(verticesData[p1Index], verticesData[p1Index + 1], verticesData[p1Index + 2]);
  27938. position2.setValue(verticesData[p2Index], verticesData[p2Index + 1], verticesData[p2Index + 2]);
  27939. Utils3D._convertToBulletVec3(position0, nativePositio0, true);
  27940. Utils3D._convertToBulletVec3(position1, nativePositio1, true);
  27941. Utils3D._convertToBulletVec3(position2, nativePositio2, true);
  27942. triangleMesh.addTriangle(nativePositio0, nativePositio1, nativePositio2, true);
  27943. }
  27944. this._nativeTriangleMesh = triangleMesh;
  27945. }
  27946. return this._nativeTriangleMesh;
  27947. }
  27948. _uploadVerticesData() {
  27949. var min = this._minVerticesUpdate;
  27950. var max = this._maxVerticesUpdate;
  27951. if (min !== -1 && max !== -1) {
  27952. var offset = min * 4;
  27953. this._vertexBuffer.setData(this._vertexBuffer.getUint8Data().buffer, offset, offset, (max - min) * 4);
  27954. this._minVerticesUpdate = -1;
  27955. this._maxVerticesUpdate = -1;
  27956. }
  27957. }
  27958. getSubMesh(index) {
  27959. return this._subMeshes[index];
  27960. }
  27961. getPositions(positions) {
  27962. if (this._isReadable)
  27963. this._getVerticeElementData(positions, VertexMesh.MESH_POSITION0);
  27964. else
  27965. throw "Mesh:can't get positions on mesh,isReadable must be true.";
  27966. }
  27967. setPositions(positions) {
  27968. if (this._isReadable) {
  27969. this._setVerticeElementData(positions, VertexMesh.MESH_POSITION0);
  27970. this._needUpdateBounds = true;
  27971. }
  27972. else {
  27973. throw "Mesh:setPosition() need isReadable must be true or use setVertices().";
  27974. }
  27975. }
  27976. getColors(colors) {
  27977. if (this._isReadable)
  27978. this._getVerticeElementData(colors, VertexMesh.MESH_COLOR0);
  27979. else
  27980. throw "Mesh:can't get colors on mesh,isReadable must be true.";
  27981. }
  27982. setColors(colors) {
  27983. if (this._isReadable)
  27984. this._setVerticeElementData(colors, VertexMesh.MESH_COLOR0);
  27985. else
  27986. throw "Mesh:setColors() need isReadable must be true or use setVertices().";
  27987. }
  27988. getUVs(uvs, channel = 0) {
  27989. if (this._isReadable) {
  27990. switch (channel) {
  27991. case 0:
  27992. this._getVerticeElementData(uvs, VertexMesh.MESH_TEXTURECOORDINATE0);
  27993. break;
  27994. case 1:
  27995. this._getVerticeElementData(uvs, VertexMesh.MESH_TEXTURECOORDINATE1);
  27996. break;
  27997. default:
  27998. throw "Mesh:Invalid channel.";
  27999. }
  28000. }
  28001. else {
  28002. throw "Mesh:can't get uvs on mesh,isReadable must be true.";
  28003. }
  28004. }
  28005. setUVs(uvs, channel = 0) {
  28006. if (this._isReadable) {
  28007. switch (channel) {
  28008. case 0:
  28009. this._setVerticeElementData(uvs, VertexMesh.MESH_TEXTURECOORDINATE0);
  28010. break;
  28011. case 1:
  28012. this._setVerticeElementData(uvs, VertexMesh.MESH_TEXTURECOORDINATE1);
  28013. break;
  28014. default:
  28015. throw "Mesh:Invalid channel.";
  28016. }
  28017. }
  28018. else {
  28019. throw "Mesh:setUVs() need isReadable must be true or use setVertices().";
  28020. }
  28021. }
  28022. getNormals(normals) {
  28023. if (this._isReadable)
  28024. this._getVerticeElementData(normals, VertexMesh.MESH_NORMAL0);
  28025. else
  28026. throw "Mesh:can't get colors on mesh,isReadable must be true.";
  28027. }
  28028. setNormals(normals) {
  28029. if (this._isReadable)
  28030. this._setVerticeElementData(normals, VertexMesh.MESH_NORMAL0);
  28031. else
  28032. throw "Mesh:setNormals() need must be true or use setVertices().";
  28033. }
  28034. getTangents(tangents) {
  28035. if (this._isReadable)
  28036. this._getVerticeElementData(tangents, VertexMesh.MESH_TANGENT0);
  28037. else
  28038. throw "Mesh:can't get colors on mesh,isReadable must be true.";
  28039. }
  28040. setTangents(tangents) {
  28041. if (this._isReadable)
  28042. this._setVerticeElementData(tangents, VertexMesh.MESH_TANGENT0);
  28043. else
  28044. throw "Mesh:setTangents() need isReadable must be true or use setVertices().";
  28045. }
  28046. getBoneWeights(boneWeights) {
  28047. if (this._isReadable)
  28048. this._getVerticeElementData(boneWeights, VertexMesh.MESH_BLENDWEIGHT0);
  28049. else
  28050. throw "Mesh:can't get boneWeights on mesh,isReadable must be true.";
  28051. }
  28052. setBoneWeights(boneWeights) {
  28053. if (this._isReadable)
  28054. this._setVerticeElementData(boneWeights, VertexMesh.MESH_BLENDWEIGHT0);
  28055. else
  28056. throw "Mesh:setBoneWeights() need isReadable must be true or use setVertices().";
  28057. }
  28058. getBoneIndices(boneIndices) {
  28059. if (this._isReadable)
  28060. this._getVerticeElementData(boneIndices, VertexMesh.MESH_BLENDINDICES0);
  28061. else
  28062. throw "Mesh:can't get boneIndices on mesh,isReadable must be true.";
  28063. }
  28064. setBoneIndices(boneIndices) {
  28065. if (this._isReadable)
  28066. this._setVerticeElementData(boneIndices, VertexMesh.MESH_BLENDINDICES0);
  28067. else
  28068. throw "Mesh:setBoneIndices() need isReadable must be true or use setVertices().";
  28069. }
  28070. markAsUnreadbale() {
  28071. this._uploadVerticesData();
  28072. this._vertexBuffer.markAsUnreadbale();
  28073. this._isReadable = false;
  28074. }
  28075. getVertexDeclaration() {
  28076. return this._vertexBuffer._vertexDeclaration;
  28077. }
  28078. getVertices() {
  28079. if (this._isReadable)
  28080. return this._vertexBuffer.getUint8Data().buffer.slice(0);
  28081. else
  28082. throw "Mesh:can't get vertices on mesh,isReadable must be true.";
  28083. }
  28084. setVertices(vertices) {
  28085. this._vertexBuffer.setData(vertices);
  28086. this._needUpdateBounds = true;
  28087. }
  28088. getIndices() {
  28089. if (this._isReadable)
  28090. return this._indexBuffer.getData().slice();
  28091. else
  28092. throw "Mesh:can't get indices on subMesh,mesh's isReadable must be true.";
  28093. }
  28094. setIndices(indices) {
  28095. this._indexBuffer.setData(indices);
  28096. }
  28097. calculateBounds() {
  28098. if (this._isReadable) {
  28099. if (this._needUpdateBounds) {
  28100. var min = this._tempVector30;
  28101. var max = this._tempVector31;
  28102. min.x = min.y = min.z = Number.MAX_VALUE;
  28103. max.x = max.y = max.z = -Number.MAX_VALUE;
  28104. var vertexBuffer = this._vertexBuffer;
  28105. var positionElement = this._getPositionElement(vertexBuffer);
  28106. var verticesData = vertexBuffer.getFloat32Data();
  28107. var floatCount = vertexBuffer.vertexDeclaration.vertexStride / 4;
  28108. var posOffset = positionElement._offset / 4;
  28109. for (var j = 0, m = verticesData.length; j < m; j += floatCount) {
  28110. var ofset = j + posOffset;
  28111. var pX = verticesData[ofset];
  28112. var pY = verticesData[ofset + 1];
  28113. var pZ = verticesData[ofset + 2];
  28114. min.x = Math.min(min.x, pX);
  28115. min.y = Math.min(min.y, pY);
  28116. min.z = Math.min(min.z, pZ);
  28117. max.x = Math.max(max.x, pX);
  28118. max.y = Math.max(max.y, pY);
  28119. max.z = Math.max(max.z, pZ);
  28120. }
  28121. this._bounds.setMin(min);
  28122. this._bounds.setMax(max);
  28123. this._needUpdateBounds = false;
  28124. }
  28125. }
  28126. else {
  28127. throw "Mesh:can't calculate bounds on subMesh,mesh's isReadable must be true.";
  28128. }
  28129. }
  28130. cloneTo(destObject) {
  28131. var destMesh = destObject;
  28132. var vb = this._vertexBuffer;
  28133. var destVB = new VertexBuffer3D(vb._byteLength, vb.bufferUsage, vb.canRead);
  28134. destVB.vertexDeclaration = vb.vertexDeclaration;
  28135. destVB.setData(vb.getUint8Data().slice().buffer);
  28136. destMesh._vertexBuffer = destVB;
  28137. destMesh._vertexCount += destVB.vertexCount;
  28138. var ib = this._indexBuffer;
  28139. var destIB = new IndexBuffer3D(IndexBuffer3D.INDEXTYPE_USHORT, ib.indexCount, ib.bufferUsage, ib.canRead);
  28140. destIB.setData(ib.getData().slice());
  28141. destMesh._indexBuffer = destIB;
  28142. destMesh._setBuffer(destMesh._vertexBuffer, destIB);
  28143. destMesh._setCPUMemory(this.cpuMemory);
  28144. destMesh._setGPUMemory(this.gpuMemory);
  28145. var i;
  28146. var boneNames = this._boneNames;
  28147. var destBoneNames = destMesh._boneNames = [];
  28148. for (i = 0; i < boneNames.length; i++)
  28149. destBoneNames[i] = boneNames[i];
  28150. var inverseBindPoses = this._inverseBindPoses;
  28151. var destInverseBindPoses = destMesh._inverseBindPoses = [];
  28152. for (i = 0; i < inverseBindPoses.length; i++)
  28153. destInverseBindPoses[i] = inverseBindPoses[i];
  28154. destMesh._bindPoseIndices = new Uint16Array(this._bindPoseIndices);
  28155. for (i = 0; i < this._skinDataPathMarks.length; i++)
  28156. destMesh._skinDataPathMarks[i] = this._skinDataPathMarks[i].slice();
  28157. for (i = 0; i < this.subMeshCount; i++) {
  28158. var subMesh = this._subMeshes[i];
  28159. var subIndexBufferStart = subMesh._subIndexBufferStart;
  28160. var subIndexBufferCount = subMesh._subIndexBufferCount;
  28161. var boneIndicesList = subMesh._boneIndicesList;
  28162. var destSubmesh = new SubMesh(destMesh);
  28163. destSubmesh._subIndexBufferStart.length = subIndexBufferStart.length;
  28164. destSubmesh._subIndexBufferCount.length = subIndexBufferCount.length;
  28165. destSubmesh._boneIndicesList.length = boneIndicesList.length;
  28166. for (var j = 0; j < subIndexBufferStart.length; j++)
  28167. destSubmesh._subIndexBufferStart[j] = subIndexBufferStart[j];
  28168. for (j = 0; j < subIndexBufferCount.length; j++)
  28169. destSubmesh._subIndexBufferCount[j] = subIndexBufferCount[j];
  28170. for (j = 0; j < boneIndicesList.length; j++)
  28171. destSubmesh._boneIndicesList[j] = new Uint16Array(boneIndicesList[j]);
  28172. destSubmesh._indexBuffer = destIB;
  28173. destSubmesh._indexStart = subMesh._indexStart;
  28174. destSubmesh._indexCount = subMesh._indexCount;
  28175. destSubmesh._indices = new Uint16Array(destIB.getData().buffer, subMesh._indexStart * 2, subMesh._indexCount);
  28176. var vertexBuffer = destMesh._vertexBuffer;
  28177. destSubmesh._vertexBuffer = vertexBuffer;
  28178. destMesh._subMeshes.push(destSubmesh);
  28179. }
  28180. destMesh._setSubMeshes(destMesh._subMeshes);
  28181. }
  28182. clone() {
  28183. var dest = new Mesh();
  28184. this.cloneTo(dest);
  28185. return dest;
  28186. }
  28187. }
  28188. Mesh.MESH = "MESH";
  28189. class TextureCube extends Laya.BaseTexture {
  28190. constructor(size, format = Laya.BaseTexture.FORMAT_R8G8B8, mipmap = false) {
  28191. super(format, mipmap);
  28192. this._glTextureType = Laya.LayaGL.instance.TEXTURE_CUBE_MAP;
  28193. this._width = size;
  28194. this._height = size;
  28195. var gl = Laya.LayaGL.instance;
  28196. this._setWarpMode(gl.TEXTURE_WRAP_S, this._wrapModeU);
  28197. this._setWarpMode(gl.TEXTURE_WRAP_T, this._wrapModeV);
  28198. this._setFilterMode(this._filterMode);
  28199. this._setAnisotropy(this._anisoLevel);
  28200. if (this._mipmap) {
  28201. this._mipmapCount = Math.ceil(Math.log2(size));
  28202. for (var i = 0; i < this._mipmapCount; i++)
  28203. this._setPixels([], i, Math.max(size >> i, 1), Math.max(size >> i, 1));
  28204. this._setGPUMemory(size * size * 4 * (1 + 1 / 3) * 6);
  28205. }
  28206. else {
  28207. this._mipmapCount = 1;
  28208. this._setGPUMemory(size * size * 4 * 6);
  28209. }
  28210. }
  28211. static __init__() {
  28212. var pixels = new Uint8Array(3);
  28213. pixels[0] = 128;
  28214. pixels[1] = 128;
  28215. pixels[2] = 128;
  28216. TextureCube.grayTexture = new TextureCube(1, Laya.BaseTexture.FORMAT_R8G8B8, false);
  28217. TextureCube.grayTexture.setSixSidePixels([pixels, pixels, pixels, pixels, pixels, pixels]);
  28218. TextureCube.grayTexture.lock = true;
  28219. }
  28220. static _parse(data, propertyParams = null, constructParams = null) {
  28221. var texture = constructParams ? new TextureCube(0, constructParams[0], constructParams[1]) : new TextureCube(0);
  28222. texture.setSixSideImageSources(data);
  28223. return texture;
  28224. }
  28225. static load(url, complete) {
  28226. Laya.ILaya.loader.create(url, complete, null, TextureCube.TEXTURECUBE);
  28227. }
  28228. get defaulteTexture() {
  28229. return TextureCube.grayTexture;
  28230. }
  28231. _setPixels(pixels, miplevel, width, height) {
  28232. var gl = Laya.LayaGL.instance;
  28233. var glFormat = this._getGLFormat();
  28234. Laya.WebGLContext.bindTexture(gl, this._glTextureType, this._glTexture);
  28235. if (this.format === Laya.BaseTexture.FORMAT_R8G8B8) {
  28236. gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
  28237. gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Z, miplevel, glFormat, width, height, 0, glFormat, gl.UNSIGNED_BYTE, pixels[0]);
  28238. gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, miplevel, glFormat, width, height, 0, glFormat, gl.UNSIGNED_BYTE, pixels[1]);
  28239. gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X, miplevel, glFormat, width, height, 0, glFormat, gl.UNSIGNED_BYTE, pixels[2]);
  28240. gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_X, miplevel, glFormat, width, height, 0, glFormat, gl.UNSIGNED_BYTE, pixels[3]);
  28241. gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Y, miplevel, glFormat, width, height, 0, glFormat, gl.UNSIGNED_BYTE, pixels[4]);
  28242. gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, miplevel, glFormat, width, height, 0, glFormat, gl.UNSIGNED_BYTE, pixels[5]);
  28243. gl.pixelStorei(gl.UNPACK_ALIGNMENT, 4);
  28244. }
  28245. else {
  28246. gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Z, miplevel, glFormat, width, height, 0, glFormat, gl.UNSIGNED_BYTE, pixels[0]);
  28247. gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, miplevel, glFormat, width, height, 0, glFormat, gl.UNSIGNED_BYTE, pixels[1]);
  28248. gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X, miplevel, glFormat, width, height, 0, glFormat, gl.UNSIGNED_BYTE, pixels[2]);
  28249. gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_X, miplevel, glFormat, width, height, 0, glFormat, gl.UNSIGNED_BYTE, pixels[3]);
  28250. gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Y, miplevel, glFormat, width, height, 0, glFormat, gl.UNSIGNED_BYTE, pixels[4]);
  28251. gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, miplevel, glFormat, width, height, 0, glFormat, gl.UNSIGNED_BYTE, pixels[5]);
  28252. }
  28253. }
  28254. setSixSideImageSources(source, premultiplyAlpha = false) {
  28255. var width;
  28256. var height;
  28257. for (var i = 0; i < 6; i++) {
  28258. var img = source[i];
  28259. if (!img) {
  28260. console.log("TextureCube: image Source can't be null.");
  28261. return;
  28262. }
  28263. var nextWidth = img.width;
  28264. var nextHeight = img.height;
  28265. if (i > 0) {
  28266. if (width !== nextWidth) {
  28267. console.log("TextureCube: each side image's width and height must same.");
  28268. return;
  28269. }
  28270. }
  28271. width = nextWidth;
  28272. height = nextHeight;
  28273. if (width !== height) {
  28274. console.log("TextureCube: each side image's width and height must same.");
  28275. return;
  28276. }
  28277. }
  28278. this._width = width;
  28279. this._height = height;
  28280. var gl = Laya.LayaGL.instance;
  28281. Laya.WebGLContext.bindTexture(gl, this._glTextureType, this._glTexture);
  28282. var glFormat = this._getGLFormat();
  28283. if (!Laya.Render.isConchApp) {
  28284. (premultiplyAlpha) && (gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true));
  28285. gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Z, 0, glFormat, glFormat, gl.UNSIGNED_BYTE, source[0]);
  28286. gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, glFormat, glFormat, gl.UNSIGNED_BYTE, source[1]);
  28287. gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X, 0, glFormat, glFormat, gl.UNSIGNED_BYTE, source[2]);
  28288. gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_X, 0, glFormat, glFormat, gl.UNSIGNED_BYTE, source[3]);
  28289. gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Y, 0, glFormat, glFormat, gl.UNSIGNED_BYTE, source[4]);
  28290. gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, glFormat, glFormat, gl.UNSIGNED_BYTE, source[5]);
  28291. (premultiplyAlpha) && (gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false));
  28292. }
  28293. else {
  28294. if (premultiplyAlpha == true) {
  28295. for (var j = 0; j < 6; j++)
  28296. source[j].setPremultiplyAlpha(premultiplyAlpha);
  28297. }
  28298. gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Z, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source[0]);
  28299. gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source[1]);
  28300. gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source[2]);
  28301. gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_X, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source[3]);
  28302. gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Y, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source[4]);
  28303. gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source[5]);
  28304. }
  28305. if (this._mipmap && this._isPot(width) && this._isPot(height)) {
  28306. gl.generateMipmap(this._glTextureType);
  28307. this._setGPUMemory(width * height * 4 * (1 + 1 / 3) * 6);
  28308. }
  28309. else {
  28310. this._setGPUMemory(width * height * 4 * 6);
  28311. }
  28312. this._setWarpMode(gl.TEXTURE_WRAP_S, this._wrapModeU);
  28313. this._setWarpMode(gl.TEXTURE_WRAP_T, this._wrapModeV);
  28314. this._setFilterMode(this._filterMode);
  28315. this._readyed = true;
  28316. this._activeResource();
  28317. }
  28318. setSixSidePixels(pixels, miplevel = 0) {
  28319. if (!pixels)
  28320. throw new Error("TextureCube:pixels can't be null.");
  28321. var width = Math.max(this._width >> miplevel, 1);
  28322. var height = Math.max(this._height >> miplevel, 1);
  28323. var pixelsCount = width * height * this._getFormatByteCount();
  28324. if (pixels[0].length < pixelsCount)
  28325. throw "TextureCube:pixels length should at least " + pixelsCount + ".";
  28326. this._setPixels(pixels, miplevel, width, height);
  28327. if (miplevel === 0) {
  28328. var gl = Laya.LayaGL.instance;
  28329. this._setWarpMode(gl.TEXTURE_WRAP_S, this._wrapModeU);
  28330. this._setWarpMode(gl.TEXTURE_WRAP_T, this._wrapModeV);
  28331. }
  28332. this._readyed = true;
  28333. this._activeResource();
  28334. }
  28335. _recoverResource() {
  28336. }
  28337. }
  28338. TextureCube.TEXTURECUBE = "TEXTURECUBE";
  28339. class PhysicsTriggerComponent extends PhysicsComponent {
  28340. constructor(collisionGroup, canCollideWith) {
  28341. super(collisionGroup, canCollideWith);
  28342. this._isTrigger = false;
  28343. }
  28344. get isTrigger() {
  28345. return this._isTrigger;
  28346. }
  28347. set isTrigger(value) {
  28348. this._isTrigger = value;
  28349. if (this._nativeColliderObject) {
  28350. var flags = this._nativeColliderObject.getCollisionFlags();
  28351. if (value) {
  28352. if ((flags & PhysicsComponent.COLLISIONFLAGS_NO_CONTACT_RESPONSE) === 0)
  28353. this._nativeColliderObject.setCollisionFlags(flags | PhysicsComponent.COLLISIONFLAGS_NO_CONTACT_RESPONSE);
  28354. }
  28355. else {
  28356. if ((flags & PhysicsComponent.COLLISIONFLAGS_NO_CONTACT_RESPONSE) !== 0)
  28357. this._nativeColliderObject.setCollisionFlags(flags ^ PhysicsComponent.COLLISIONFLAGS_NO_CONTACT_RESPONSE);
  28358. }
  28359. }
  28360. }
  28361. _onAdded() {
  28362. super._onAdded();
  28363. this.isTrigger = this._isTrigger;
  28364. }
  28365. _cloneTo(dest) {
  28366. super._cloneTo(dest);
  28367. dest.isTrigger = this._isTrigger;
  28368. }
  28369. }
  28370. class PhysicsCollider extends PhysicsTriggerComponent {
  28371. constructor(collisionGroup = Physics3DUtils.COLLISIONFILTERGROUP_DEFAULTFILTER, canCollideWith = Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER) {
  28372. super(collisionGroup, canCollideWith);
  28373. this._enableProcessCollisions = false;
  28374. }
  28375. _addToSimulation() {
  28376. this._simulation._addPhysicsCollider(this, this._collisionGroup, this._canCollideWith);
  28377. }
  28378. _removeFromSimulation() {
  28379. this._simulation._removePhysicsCollider(this);
  28380. }
  28381. _onTransformChanged(flag) {
  28382. flag &= Transform3D.TRANSFORM_WORLDPOSITION | Transform3D.TRANSFORM_WORLDQUATERNION | Transform3D.TRANSFORM_WORLDSCALE;
  28383. if (flag) {
  28384. this._transformFlag |= flag;
  28385. if (this._isValid() && this._inPhysicUpdateListIndex === -1)
  28386. this._simulation._physicsUpdateList.add(this);
  28387. }
  28388. }
  28389. _parse(data) {
  28390. (data.friction != null) && (this.friction = data.friction);
  28391. (data.rollingFriction != null) && (this.rollingFriction = data.rollingFriction);
  28392. (data.restitution != null) && (this.restitution = data.restitution);
  28393. (data.isTrigger != null) && (this.isTrigger = data.isTrigger);
  28394. super._parse(data);
  28395. this._parseShape(data.shapes);
  28396. }
  28397. _onAdded() {
  28398. var physics3D = Physics3D._physics3D;
  28399. var btColObj = new physics3D.btCollisionObject();
  28400. btColObj.setUserIndex(this.id);
  28401. btColObj.forceActivationState(PhysicsComponent.ACTIVATIONSTATE_DISABLE_SIMULATION);
  28402. var flags = btColObj.getCollisionFlags();
  28403. if (this.owner.isStatic) {
  28404. if ((flags & PhysicsComponent.COLLISIONFLAGS_KINEMATIC_OBJECT) > 0)
  28405. flags = flags ^ PhysicsComponent.COLLISIONFLAGS_KINEMATIC_OBJECT;
  28406. flags = flags | PhysicsComponent.COLLISIONFLAGS_STATIC_OBJECT;
  28407. }
  28408. else {
  28409. if ((flags & PhysicsComponent.COLLISIONFLAGS_STATIC_OBJECT) > 0)
  28410. flags = flags ^ PhysicsComponent.COLLISIONFLAGS_STATIC_OBJECT;
  28411. flags = flags | PhysicsComponent.COLLISIONFLAGS_KINEMATIC_OBJECT;
  28412. }
  28413. btColObj.setCollisionFlags(flags);
  28414. this._nativeColliderObject = btColObj;
  28415. super._onAdded();
  28416. }
  28417. }
  28418. class CharacterController extends PhysicsComponent {
  28419. constructor(stepheight = 0.1, upAxis = null, collisionGroup = Physics3DUtils.COLLISIONFILTERGROUP_DEFAULTFILTER, canCollideWith = Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER) {
  28420. super(collisionGroup, canCollideWith);
  28421. this._upAxis = new Vector3(0, 1, 0);
  28422. this._maxSlope = 45.0;
  28423. this._jumpSpeed = 10.0;
  28424. this._fallSpeed = 55.0;
  28425. this._gravity = new Vector3(0, -9.8 * 3, 0);
  28426. this._nativeKinematicCharacter = null;
  28427. this._stepHeight = stepheight;
  28428. (upAxis) && (this._upAxis = upAxis);
  28429. }
  28430. static __init__() {
  28431. CharacterController._nativeTempVector30 = new Physics3D._physics3D.btVector3(0, 0, 0);
  28432. }
  28433. get fallSpeed() {
  28434. return this._fallSpeed;
  28435. }
  28436. set fallSpeed(value) {
  28437. this._fallSpeed = value;
  28438. this._nativeKinematicCharacter.setFallSpeed(value);
  28439. }
  28440. get jumpSpeed() {
  28441. return this._jumpSpeed;
  28442. }
  28443. set jumpSpeed(value) {
  28444. this._jumpSpeed = value;
  28445. this._nativeKinematicCharacter.setJumpSpeed(value);
  28446. }
  28447. get gravity() {
  28448. return this._gravity;
  28449. }
  28450. set gravity(value) {
  28451. this._gravity = value;
  28452. var nativeGravity = CharacterController._nativeTempVector30;
  28453. nativeGravity.setValue(-value.x, value.y, value.z);
  28454. this._nativeKinematicCharacter.setGravity(nativeGravity);
  28455. }
  28456. get maxSlope() {
  28457. return this._maxSlope;
  28458. }
  28459. set maxSlope(value) {
  28460. this._maxSlope = value;
  28461. this._nativeKinematicCharacter.setMaxSlope((value / 180) * Math.PI);
  28462. }
  28463. get isGrounded() {
  28464. return this._nativeKinematicCharacter.onGround();
  28465. }
  28466. get stepHeight() {
  28467. return this._stepHeight;
  28468. }
  28469. set stepHeight(value) {
  28470. this._stepHeight = value;
  28471. this._constructCharacter();
  28472. }
  28473. get upAxis() {
  28474. return this._upAxis;
  28475. }
  28476. set upAxis(value) {
  28477. this._upAxis = value;
  28478. this._constructCharacter();
  28479. }
  28480. _constructCharacter() {
  28481. var physics3D = Physics3D._physics3D;
  28482. if (this._nativeKinematicCharacter)
  28483. physics3D.destroy(this._nativeKinematicCharacter);
  28484. var nativeUpAxis = CharacterController._nativeTempVector30;
  28485. nativeUpAxis.setValue(this._upAxis.x, this._upAxis.y, this._upAxis.z);
  28486. this._nativeKinematicCharacter = new physics3D.btKinematicCharacterController(this._nativeColliderObject, this._colliderShape._nativeShape, this._stepHeight, nativeUpAxis);
  28487. this.fallSpeed = this._fallSpeed;
  28488. this.maxSlope = this._maxSlope;
  28489. this.jumpSpeed = this._jumpSpeed;
  28490. this.gravity = this._gravity;
  28491. }
  28492. _onShapeChange(colShape) {
  28493. super._onShapeChange(colShape);
  28494. this._constructCharacter();
  28495. }
  28496. _onAdded() {
  28497. var physics3D = Physics3D._physics3D;
  28498. var ghostObject = new physics3D.btPairCachingGhostObject();
  28499. ghostObject.setUserIndex(this.id);
  28500. ghostObject.setCollisionFlags(PhysicsComponent.COLLISIONFLAGS_CHARACTER_OBJECT);
  28501. this._nativeColliderObject = ghostObject;
  28502. if (this._colliderShape)
  28503. this._constructCharacter();
  28504. super._onAdded();
  28505. }
  28506. _addToSimulation() {
  28507. this._simulation._characters.push(this);
  28508. this._simulation._addCharacter(this, this._collisionGroup, this._canCollideWith);
  28509. }
  28510. _removeFromSimulation() {
  28511. this._simulation._removeCharacter(this);
  28512. var characters = this._simulation._characters;
  28513. characters.splice(characters.indexOf(this), 1);
  28514. }
  28515. _cloneTo(dest) {
  28516. super._cloneTo(dest);
  28517. var destCharacterController = dest;
  28518. destCharacterController.stepHeight = this._stepHeight;
  28519. destCharacterController.upAxis = this._upAxis;
  28520. destCharacterController.maxSlope = this._maxSlope;
  28521. destCharacterController.jumpSpeed = this._jumpSpeed;
  28522. destCharacterController.fallSpeed = this._fallSpeed;
  28523. destCharacterController.gravity = this._gravity;
  28524. }
  28525. _onDestroy() {
  28526. Physics3D._physics3D.destroy(this._nativeKinematicCharacter);
  28527. super._onDestroy();
  28528. this._nativeKinematicCharacter = null;
  28529. }
  28530. move(movement) {
  28531. var nativeMovement = CharacterController._nativeVector30;
  28532. nativeMovement.setValue(-movement.x, movement.y, movement.z);
  28533. this._nativeKinematicCharacter.setWalkDirection(nativeMovement);
  28534. }
  28535. jump(velocity = null) {
  28536. if (velocity) {
  28537. var nativeVelocity = CharacterController._nativeVector30;
  28538. Utils3D._convertToBulletVec3(velocity, nativeVelocity, true);
  28539. this._nativeKinematicCharacter.jump(nativeVelocity);
  28540. }
  28541. else {
  28542. this._nativeKinematicCharacter.jump();
  28543. }
  28544. }
  28545. }
  28546. CharacterController.UPAXIS_X = 0;
  28547. CharacterController.UPAXIS_Y = 1;
  28548. CharacterController.UPAXIS_Z = 2;
  28549. class Rigidbody3D extends PhysicsTriggerComponent {
  28550. constructor(collisionGroup = Physics3DUtils.COLLISIONFILTERGROUP_DEFAULTFILTER, canCollideWith = Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER) {
  28551. super(collisionGroup, canCollideWith);
  28552. this._isKinematic = false;
  28553. this._mass = 1.0;
  28554. this._gravity = new Vector3(0, -10, 0);
  28555. this._angularDamping = 0.0;
  28556. this._linearDamping = 0.0;
  28557. this._overrideGravity = false;
  28558. this._totalTorque = new Vector3(0, 0, 0);
  28559. this._totalForce = new Vector3(0, 0, 0);
  28560. this._linearVelocity = new Vector3();
  28561. this._angularVelocity = new Vector3();
  28562. this._linearFactor = new Vector3(1, 1, 1);
  28563. this._angularFactor = new Vector3(1, 1, 1);
  28564. this._detectCollisions = true;
  28565. }
  28566. static __init__() {
  28567. Rigidbody3D._nativeTempVector30 = new Physics3D._physics3D.btVector3(0, 0, 0);
  28568. Rigidbody3D._nativeTempVector31 = new Physics3D._physics3D.btVector3(0, 0, 0);
  28569. Rigidbody3D._nativeVector3Zero = new Physics3D._physics3D.btVector3(0, 0, 0);
  28570. Rigidbody3D._nativeInertia = new Physics3D._physics3D.btVector3(0, 0, 0);
  28571. Rigidbody3D._nativeImpulse = new Physics3D._physics3D.btVector3(0, 0, 0);
  28572. Rigidbody3D._nativeImpulseOffset = new Physics3D._physics3D.btVector3(0, 0, 0);
  28573. Rigidbody3D._nativeGravity = new Physics3D._physics3D.btVector3(0, 0, 0);
  28574. }
  28575. get mass() {
  28576. return this._mass;
  28577. }
  28578. set mass(value) {
  28579. value = Math.max(value, 1e-07);
  28580. this._mass = value;
  28581. (this._isKinematic) || (this._updateMass(value));
  28582. }
  28583. get isKinematic() {
  28584. return this._isKinematic;
  28585. }
  28586. set isKinematic(value) {
  28587. this._isKinematic = value;
  28588. var canInSimulation = !!(this._simulation && this._enabled && this._colliderShape);
  28589. canInSimulation && this._removeFromSimulation();
  28590. var natColObj = this._nativeColliderObject;
  28591. var flags = natColObj.getCollisionFlags();
  28592. if (value) {
  28593. flags = flags | PhysicsComponent.COLLISIONFLAGS_KINEMATIC_OBJECT;
  28594. natColObj.setCollisionFlags(flags);
  28595. this._nativeColliderObject.forceActivationState(PhysicsComponent.ACTIVATIONSTATE_DISABLE_DEACTIVATION);
  28596. this._enableProcessCollisions = false;
  28597. this._updateMass(0);
  28598. }
  28599. else {
  28600. if ((flags & PhysicsComponent.COLLISIONFLAGS_KINEMATIC_OBJECT) > 0)
  28601. flags = flags ^ PhysicsComponent.COLLISIONFLAGS_KINEMATIC_OBJECT;
  28602. natColObj.setCollisionFlags(flags);
  28603. this._nativeColliderObject.setActivationState(PhysicsComponent.ACTIVATIONSTATE_ACTIVE_TAG);
  28604. this._enableProcessCollisions = true;
  28605. this._updateMass(this._mass);
  28606. }
  28607. var nativeZero = Rigidbody3D._nativeVector3Zero;
  28608. natColObj.setInterpolationLinearVelocity(nativeZero);
  28609. natColObj.setLinearVelocity(nativeZero);
  28610. natColObj.setInterpolationAngularVelocity(nativeZero);
  28611. natColObj.setAngularVelocity(nativeZero);
  28612. canInSimulation && this._addToSimulation();
  28613. }
  28614. get linearDamping() {
  28615. return this._linearDamping;
  28616. }
  28617. set linearDamping(value) {
  28618. this._linearDamping = value;
  28619. if (this._nativeColliderObject)
  28620. this._nativeColliderObject.setDamping(value, this._angularDamping);
  28621. }
  28622. get angularDamping() {
  28623. return this._angularDamping;
  28624. }
  28625. set angularDamping(value) {
  28626. this._angularDamping = value;
  28627. if (this._nativeColliderObject)
  28628. this._nativeColliderObject.setDamping(this._linearDamping, value);
  28629. }
  28630. get overrideGravity() {
  28631. return this._overrideGravity;
  28632. }
  28633. set overrideGravity(value) {
  28634. this._overrideGravity = value;
  28635. if (this._nativeColliderObject) {
  28636. var flag = this._nativeColliderObject.getFlags();
  28637. if (value) {
  28638. if ((flag & Rigidbody3D._BT_DISABLE_WORLD_GRAVITY) === 0)
  28639. this._nativeColliderObject.setFlags(flag | Rigidbody3D._BT_DISABLE_WORLD_GRAVITY);
  28640. }
  28641. else {
  28642. if ((flag & Rigidbody3D._BT_DISABLE_WORLD_GRAVITY) > 0)
  28643. this._nativeColliderObject.setFlags(flag ^ Rigidbody3D._BT_DISABLE_WORLD_GRAVITY);
  28644. }
  28645. }
  28646. }
  28647. get gravity() {
  28648. return this._gravity;
  28649. }
  28650. set gravity(value) {
  28651. this._gravity = value;
  28652. Rigidbody3D._nativeGravity.setValue(-value.x, value.y, value.z);
  28653. this._nativeColliderObject.setGravity(Rigidbody3D._nativeGravity);
  28654. }
  28655. get totalForce() {
  28656. if (this._nativeColliderObject) {
  28657. var nativeTotalForce = this._nativeColliderObject.getTotalForce();
  28658. Utils3D._convertToLayaVec3(nativeTotalForce, this._totalForce, true);
  28659. return this._totalForce;
  28660. }
  28661. return null;
  28662. }
  28663. get linearFactor() {
  28664. if (this._nativeColliderObject)
  28665. return this._linearFactor;
  28666. return null;
  28667. }
  28668. set linearFactor(value) {
  28669. this._linearFactor = value;
  28670. if (this._nativeColliderObject) {
  28671. var nativeValue = Rigidbody3D._nativeTempVector30;
  28672. Utils3D._convertToBulletVec3(value, nativeValue, false);
  28673. this._nativeColliderObject.setLinearFactor(nativeValue);
  28674. }
  28675. }
  28676. get linearVelocity() {
  28677. if (this._nativeColliderObject)
  28678. Utils3D._convertToLayaVec3(this._nativeColliderObject.getLinearVelocity(), this._linearVelocity, true);
  28679. return this._linearVelocity;
  28680. }
  28681. set linearVelocity(value) {
  28682. this._linearVelocity = value;
  28683. if (this._nativeColliderObject) {
  28684. var nativeValue = Rigidbody3D._nativeTempVector30;
  28685. Utils3D._convertToBulletVec3(value, nativeValue, true);
  28686. (this.isSleeping) && (this.wakeUp());
  28687. this._nativeColliderObject.setLinearVelocity(nativeValue);
  28688. }
  28689. }
  28690. get angularFactor() {
  28691. if (this._nativeColliderObject)
  28692. return this._angularFactor;
  28693. return null;
  28694. }
  28695. set angularFactor(value) {
  28696. this._angularFactor = value;
  28697. if (this._nativeColliderObject) {
  28698. var nativeValue = Rigidbody3D._nativeTempVector30;
  28699. Utils3D._convertToBulletVec3(value, nativeValue, false);
  28700. this._nativeColliderObject.setAngularFactor(nativeValue);
  28701. }
  28702. }
  28703. get angularVelocity() {
  28704. if (this._nativeColliderObject)
  28705. Utils3D._convertToLayaVec3(this._nativeColliderObject.getAngularVelocity(), this._angularVelocity, true);
  28706. return this._angularVelocity;
  28707. }
  28708. set angularVelocity(value) {
  28709. this._angularVelocity = value;
  28710. if (this._nativeColliderObject) {
  28711. var nativeValue = Rigidbody3D._nativeTempVector30;
  28712. Utils3D._convertToBulletVec3(value, nativeValue, true);
  28713. (this.isSleeping) && (this.wakeUp());
  28714. this._nativeColliderObject.setAngularVelocity(nativeValue);
  28715. }
  28716. }
  28717. get totalTorque() {
  28718. if (this._nativeColliderObject) {
  28719. var nativeTotalTorque = this._nativeColliderObject.getTotalTorque();
  28720. Utils3D._convertToLayaVec3(nativeTotalTorque, this._totalTorque, true);
  28721. return this._totalTorque;
  28722. }
  28723. return null;
  28724. }
  28725. get detectCollisions() {
  28726. return this._detectCollisions;
  28727. }
  28728. set detectCollisions(value) {
  28729. if (this._detectCollisions !== value) {
  28730. this._detectCollisions = value;
  28731. if (this._colliderShape && this._enabled && this._simulation) {
  28732. this._simulation._removeRigidBody(this);
  28733. this._simulation._addRigidBody(this, this._collisionGroup, value ? this._canCollideWith : 0);
  28734. }
  28735. }
  28736. }
  28737. get isSleeping() {
  28738. if (this._nativeColliderObject)
  28739. return this._nativeColliderObject.getActivationState() === PhysicsComponent.ACTIVATIONSTATE_ISLAND_SLEEPING;
  28740. return false;
  28741. }
  28742. get sleepLinearVelocity() {
  28743. return this._nativeColliderObject.getLinearSleepingThreshold();
  28744. }
  28745. set sleepLinearVelocity(value) {
  28746. this._nativeColliderObject.setSleepingThresholds(value, this._nativeColliderObject.getAngularSleepingThreshold());
  28747. }
  28748. get sleepAngularVelocity() {
  28749. return this._nativeColliderObject.getAngularSleepingThreshold();
  28750. }
  28751. set sleepAngularVelocity(value) {
  28752. this._nativeColliderObject.setSleepingThresholds(this._nativeColliderObject.getLinearSleepingThreshold(), value);
  28753. }
  28754. _updateMass(mass) {
  28755. if (this._nativeColliderObject && this._colliderShape) {
  28756. this._colliderShape._nativeShape.calculateLocalInertia(mass, Rigidbody3D._nativeInertia);
  28757. this._nativeColliderObject.setMassProps(mass, Rigidbody3D._nativeInertia);
  28758. this._nativeColliderObject.updateInertiaTensor();
  28759. }
  28760. }
  28761. _delegateMotionStateGetWorldTransform(worldTransPointer) {
  28762. }
  28763. _delegateMotionStateSetWorldTransform(worldTransPointer) {
  28764. var rigidBody = this._rigidbody;
  28765. rigidBody._simulation._updatedRigidbodies++;
  28766. var physics3D = Physics3D._physics3D;
  28767. var worldTrans = physics3D.wrapPointer(worldTransPointer, physics3D.btTransform);
  28768. rigidBody._updateTransformComponent(worldTrans);
  28769. }
  28770. _delegateMotionStateGetWorldTransformNative(ridgidBody3D, worldTransPointer) {
  28771. }
  28772. _delegateMotionStateSetWorldTransformNative(rigidBody3D, worldTransPointer) {
  28773. var rigidBody = rigidBody3D;
  28774. rigidBody._simulation._updatedRigidbodies++;
  28775. var physics3D = Physics3D._physics3D;
  28776. var worldTrans = physics3D.wrapPointer(worldTransPointer, physics3D.btTransform);
  28777. rigidBody._updateTransformComponent(worldTrans);
  28778. }
  28779. _onScaleChange(scale) {
  28780. super._onScaleChange(scale);
  28781. this._updateMass(this._isKinematic ? 0 : this._mass);
  28782. }
  28783. _delegateMotionStateClear() {
  28784. this._rigidbody = null;
  28785. }
  28786. _onAdded() {
  28787. var physics3D = Physics3D._physics3D;
  28788. var motionState = new physics3D.LayaMotionState();
  28789. var isConchApp = (window.conch != null);
  28790. if (isConchApp && physics3D.LayaMotionState.prototype.setRigidbody) {
  28791. motionState.setRigidbody(this);
  28792. motionState.setNativeGetWorldTransform(this._delegateMotionStateGetWorldTransformNative);
  28793. motionState.setNativeSetWorldTransform(this._delegateMotionStateSetWorldTransformNative);
  28794. }
  28795. else {
  28796. motionState.getWorldTransform = this._delegateMotionStateGetWorldTransform;
  28797. motionState.setWorldTransform = this._delegateMotionStateSetWorldTransform;
  28798. }
  28799. motionState.clear = this._delegateMotionStateClear;
  28800. motionState._rigidbody = this;
  28801. this._nativeMotionState = motionState;
  28802. var constructInfo = new physics3D.btRigidBodyConstructionInfo(0.0, motionState, null, Rigidbody3D._nativeVector3Zero);
  28803. var btRigid = new physics3D.btRigidBody(constructInfo);
  28804. btRigid.setUserIndex(this.id);
  28805. this._nativeColliderObject = btRigid;
  28806. super._onAdded();
  28807. this.mass = this._mass;
  28808. this.linearFactor = this._linearFactor;
  28809. this.angularFactor = this._angularFactor;
  28810. this.linearDamping = this._linearDamping;
  28811. this.angularDamping = this._angularDamping;
  28812. this.overrideGravity = this._overrideGravity;
  28813. this.gravity = this._gravity;
  28814. this.isKinematic = this._isKinematic;
  28815. physics3D.destroy(constructInfo);
  28816. }
  28817. _onShapeChange(colShape) {
  28818. super._onShapeChange(colShape);
  28819. if (this._isKinematic) {
  28820. this._updateMass(0);
  28821. }
  28822. else {
  28823. this._nativeColliderObject.setCenterOfMassTransform(this._nativeColliderObject.getWorldTransform());
  28824. this._updateMass(this._mass);
  28825. }
  28826. }
  28827. _parse(data) {
  28828. (data.friction != null) && (this.friction = data.friction);
  28829. (data.rollingFriction != null) && (this.rollingFriction = data.rollingFriction);
  28830. (data.restitution != null) && (this.restitution = data.restitution);
  28831. (data.isTrigger != null) && (this.isTrigger = data.isTrigger);
  28832. (data.mass != null) && (this.mass = data.mass);
  28833. (data.isKinematic != null) && (this.isKinematic = data.isKinematic);
  28834. (data.linearDamping != null) && (this.linearDamping = data.linearDamping);
  28835. (data.angularDamping != null) && (this.angularDamping = data.angularDamping);
  28836. (data.overrideGravity != null) && (this.overrideGravity = data.overrideGravity);
  28837. if (data.gravity) {
  28838. this.gravity.fromArray(data.gravity);
  28839. this.gravity = this.gravity;
  28840. }
  28841. super._parse(data);
  28842. this._parseShape(data.shapes);
  28843. }
  28844. _onDestroy() {
  28845. var physics3D = Physics3D._physics3D;
  28846. this._nativeMotionState.clear();
  28847. physics3D.destroy(this._nativeMotionState);
  28848. super._onDestroy();
  28849. this._nativeMotionState = null;
  28850. this._gravity = null;
  28851. this._totalTorque = null;
  28852. this._linearVelocity = null;
  28853. this._angularVelocity = null;
  28854. this._linearFactor = null;
  28855. this._angularFactor = null;
  28856. }
  28857. _addToSimulation() {
  28858. this._simulation._addRigidBody(this, this._collisionGroup, this._detectCollisions ? this._canCollideWith : 0);
  28859. }
  28860. _removeFromSimulation() {
  28861. this._simulation._removeRigidBody(this);
  28862. }
  28863. _cloneTo(dest) {
  28864. super._cloneTo(dest);
  28865. var destRigidbody3D = dest;
  28866. destRigidbody3D.isKinematic = this._isKinematic;
  28867. destRigidbody3D.mass = this._mass;
  28868. destRigidbody3D.gravity = this._gravity;
  28869. destRigidbody3D.angularDamping = this._angularDamping;
  28870. destRigidbody3D.linearDamping = this._linearDamping;
  28871. destRigidbody3D.overrideGravity = this._overrideGravity;
  28872. destRigidbody3D.linearVelocity = this._linearVelocity;
  28873. destRigidbody3D.angularVelocity = this._angularVelocity;
  28874. destRigidbody3D.linearFactor = this._linearFactor;
  28875. destRigidbody3D.angularFactor = this._angularFactor;
  28876. destRigidbody3D.detectCollisions = this._detectCollisions;
  28877. }
  28878. applyForce(force, localOffset = null) {
  28879. if (this._nativeColliderObject == null)
  28880. throw "Attempted to call a Physics function that is avaliable only when the Entity has been already added to the Scene.";
  28881. var nativeForce = Rigidbody3D._nativeTempVector30;
  28882. nativeForce.setValue(-force.x, force.y, force.z);
  28883. if (localOffset) {
  28884. var nativeOffset = Rigidbody3D._nativeTempVector31;
  28885. nativeOffset.setValue(-localOffset.x, localOffset.y, localOffset.z);
  28886. this._nativeColliderObject.applyForce(nativeForce, nativeOffset);
  28887. }
  28888. else {
  28889. this._nativeColliderObject.applyCentralForce(nativeForce);
  28890. }
  28891. }
  28892. applyTorque(torque) {
  28893. if (this._nativeColliderObject == null)
  28894. throw "Attempted to call a Physics function that is avaliable only when the Entity has been already added to the Scene.";
  28895. var nativeTorque = Rigidbody3D._nativeTempVector30;
  28896. nativeTorque.setValue(-torque.x, torque.y, torque.z);
  28897. this._nativeColliderObject.applyTorque(nativeTorque);
  28898. }
  28899. applyImpulse(impulse, localOffset = null) {
  28900. if (this._nativeColliderObject == null)
  28901. throw "Attempted to call a Physics function that is avaliable only when the Entity has been already added to the Scene.";
  28902. Rigidbody3D._nativeImpulse.setValue(-impulse.x, impulse.y, impulse.z);
  28903. if (localOffset) {
  28904. Rigidbody3D._nativeImpulseOffset.setValue(-localOffset.x, localOffset.y, localOffset.z);
  28905. this._nativeColliderObject.applyImpulse(Rigidbody3D._nativeImpulse, Rigidbody3D._nativeImpulseOffset);
  28906. }
  28907. else {
  28908. this._nativeColliderObject.applyCentralImpulse(Rigidbody3D._nativeImpulse);
  28909. }
  28910. }
  28911. applyTorqueImpulse(torqueImpulse) {
  28912. if (this._nativeColliderObject == null)
  28913. throw "Attempted to call a Physics function that is avaliable only when the Entity has been already added to the Scene.";
  28914. var nativeTorqueImpulse = Rigidbody3D._nativeTempVector30;
  28915. nativeTorqueImpulse.setValue(-torqueImpulse.x, torqueImpulse.y, torqueImpulse.z);
  28916. this._nativeColliderObject.applyTorqueImpulse(nativeTorqueImpulse);
  28917. }
  28918. wakeUp() {
  28919. this._nativeColliderObject && (this._nativeColliderObject.activate(false));
  28920. }
  28921. clearForces() {
  28922. var rigidBody = this._nativeColliderObject;
  28923. if (rigidBody == null)
  28924. throw "Attempted to call a Physics function that is avaliable only when the Entity has been already added to the Scene.";
  28925. rigidBody.clearForces();
  28926. var nativeZero = Rigidbody3D._nativeVector3Zero;
  28927. rigidBody.setInterpolationLinearVelocity(nativeZero);
  28928. rigidBody.setLinearVelocity(nativeZero);
  28929. rigidBody.setInterpolationAngularVelocity(nativeZero);
  28930. rigidBody.setAngularVelocity(nativeZero);
  28931. }
  28932. }
  28933. Rigidbody3D.TYPE_STATIC = 0;
  28934. Rigidbody3D.TYPE_DYNAMIC = 1;
  28935. Rigidbody3D.TYPE_KINEMATIC = 2;
  28936. Rigidbody3D._BT_DISABLE_WORLD_GRAVITY = 1;
  28937. Rigidbody3D._BT_ENABLE_GYROPSCOPIC_FORCE = 2;
  28938. class StaticPlaneColliderShape extends ColliderShape {
  28939. static __init__() {
  28940. StaticPlaneColliderShape._nativeNormal = new Physics3D._physics3D.btVector3(0, 0, 0);
  28941. }
  28942. constructor(normal, offset) {
  28943. super();
  28944. this._normal = normal;
  28945. this._offset = offset;
  28946. this._type = ColliderShape.SHAPETYPES_STATICPLANE;
  28947. StaticPlaneColliderShape._nativeNormal.setValue(-normal.x, normal.y, normal.z);
  28948. this._nativeShape = new Physics3D._physics3D.btStaticPlaneShape(StaticPlaneColliderShape._nativeNormal, offset);
  28949. }
  28950. clone() {
  28951. var dest = new StaticPlaneColliderShape(this._normal, this._offset);
  28952. this.cloneTo(dest);
  28953. return dest;
  28954. }
  28955. }
  28956. class PrimitiveMesh {
  28957. static __init__() {
  28958. }
  28959. static _createMesh(vertexDeclaration, vertices, indices) {
  28960. var gl = Laya.LayaGL.instance;
  28961. var mesh = new Mesh();
  28962. var subMesh = new SubMesh(mesh);
  28963. var vertexBuffer = new VertexBuffer3D(vertices.length * 4, gl.STATIC_DRAW, true);
  28964. vertexBuffer.vertexDeclaration = vertexDeclaration;
  28965. vertexBuffer.setData(vertices.buffer);
  28966. mesh._vertexBuffer = vertexBuffer;
  28967. mesh._vertexCount += vertexBuffer.vertexCount;
  28968. var indexBuffer = new IndexBuffer3D(IndexBuffer3D.INDEXTYPE_USHORT, indices.length, gl.STATIC_DRAW, true);
  28969. indexBuffer.setData(indices);
  28970. mesh._indexBuffer = indexBuffer;
  28971. var vertexBuffers = [];
  28972. vertexBuffers[0] = vertexBuffer;
  28973. mesh._setBuffer(vertexBuffer, indexBuffer);
  28974. subMesh._vertexBuffer = vertexBuffer;
  28975. subMesh._indexBuffer = indexBuffer;
  28976. subMesh._setIndexRange(0, indexBuffer.indexCount);
  28977. var subIndexBufferStart = subMesh._subIndexBufferStart;
  28978. var subIndexBufferCount = subMesh._subIndexBufferCount;
  28979. var boneIndicesList = subMesh._boneIndicesList;
  28980. subIndexBufferStart.length = 1;
  28981. subIndexBufferCount.length = 1;
  28982. boneIndicesList.length = 1;
  28983. subIndexBufferStart[0] = 0;
  28984. subIndexBufferCount[0] = indexBuffer.indexCount;
  28985. var subMeshes = [];
  28986. subMeshes.push(subMesh);
  28987. mesh._setSubMeshes(subMeshes);
  28988. var memorySize = vertexBuffer._byteLength + indexBuffer._byteLength;
  28989. mesh._setCPUMemory(memorySize);
  28990. mesh._setGPUMemory(memorySize);
  28991. return mesh;
  28992. }
  28993. static createBox(long = 1, height = 1, width = 1) {
  28994. var vertexDeclaration = VertexMesh.getVertexDeclaration("POSITION,NORMAL,UV");
  28995. var halfLong = long / 2;
  28996. var halfHeight = height / 2;
  28997. var halfWidth = width / 2;
  28998. var vertices = new Float32Array([
  28999. -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,
  29000. -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,
  29001. -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,
  29002. 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,
  29003. -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,
  29004. -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
  29005. ]);
  29006. var indices = new Uint16Array([
  29007. 0, 1, 2, 2, 3, 0,
  29008. 4, 7, 6, 6, 5, 4,
  29009. 8, 9, 10, 10, 11, 8,
  29010. 12, 15, 14, 14, 13, 12,
  29011. 16, 17, 18, 18, 19, 16,
  29012. 20, 23, 22, 22, 21, 20
  29013. ]);
  29014. return PrimitiveMesh._createMesh(vertexDeclaration, vertices, indices);
  29015. }
  29016. static createCapsule(radius = 0.5, height = 2, stacks = 16, slices = 32) {
  29017. var vertexCount = (stacks + 1) * (slices + 1) * 2 + (slices + 1) * 2;
  29018. var indexCount = (3 * stacks * (slices + 1)) * 2 * 2 + 2 * slices * 3;
  29019. var vertexDeclaration = VertexMesh.getVertexDeclaration("POSITION,NORMAL,UV");
  29020. var vertexFloatStride = vertexDeclaration.vertexStride / 4;
  29021. var vertices = new Float32Array(vertexCount * vertexFloatStride);
  29022. var indices = new Uint16Array(indexCount);
  29023. var stackAngle = (Math.PI / 2.0) / stacks;
  29024. var sliceAngle = (Math.PI * 2.0) / slices;
  29025. var hcHeight = height / 2 - radius;
  29026. var posX = 0;
  29027. var posY = 0;
  29028. var posZ = 0;
  29029. var vc = 0;
  29030. var ic = 0;
  29031. var verticeCount = 0;
  29032. var stack, slice;
  29033. for (stack = 0; stack <= stacks; stack++) {
  29034. for (slice = 0; slice <= slices; slice++) {
  29035. posX = radius * Math.cos(stack * stackAngle) * Math.cos(slice * sliceAngle + Math.PI);
  29036. posY = radius * Math.sin(stack * stackAngle);
  29037. posZ = radius * Math.cos(stack * stackAngle) * Math.sin(slice * sliceAngle + Math.PI);
  29038. vertices[vc++] = posX;
  29039. vertices[vc++] = posY + hcHeight;
  29040. vertices[vc++] = posZ;
  29041. vertices[vc++] = posX;
  29042. vertices[vc++] = posY;
  29043. vertices[vc++] = posZ;
  29044. vertices[vc++] = 1 - slice / slices;
  29045. vertices[vc++] = (1 - stack / stacks) * ((Math.PI * radius / 2) / (height + Math.PI * radius));
  29046. if (stack < stacks) {
  29047. indices[ic++] = (stack * (slices + 1)) + slice + (slices + 1);
  29048. indices[ic++] = (stack * (slices + 1)) + slice;
  29049. indices[ic++] = (stack * (slices + 1)) + slice + 1;
  29050. indices[ic++] = (stack * (slices + 1)) + slice + (slices);
  29051. indices[ic++] = (stack * (slices + 1)) + slice;
  29052. indices[ic++] = (stack * (slices + 1)) + slice + (slices + 1);
  29053. }
  29054. }
  29055. }
  29056. verticeCount += (stacks + 1) * (slices + 1);
  29057. for (stack = 0; stack <= stacks; stack++) {
  29058. for (slice = 0; slice <= slices; slice++) {
  29059. posX = radius * Math.cos(stack * stackAngle) * Math.cos(slice * sliceAngle + Math.PI);
  29060. posY = radius * Math.sin(-stack * stackAngle);
  29061. posZ = radius * Math.cos(stack * stackAngle) * Math.sin(slice * sliceAngle + Math.PI);
  29062. vertices[vc++] = posX;
  29063. vertices[vc++] = posY - hcHeight;
  29064. vertices[vc++] = posZ;
  29065. vertices[vc++] = posX;
  29066. vertices[vc++] = posY;
  29067. vertices[vc++] = posZ;
  29068. vertices[vc++] = 1 - slice / slices;
  29069. vertices[vc++] = ((stack / stacks) * (Math.PI * radius / 2) + (height + Math.PI * radius / 2)) / (height + Math.PI * radius);
  29070. if (stack < stacks) {
  29071. indices[ic++] = verticeCount + (stack * (slices + 1)) + slice;
  29072. indices[ic++] = verticeCount + (stack * (slices + 1)) + slice + (slices + 1);
  29073. indices[ic++] = verticeCount + (stack * (slices + 1)) + slice + 1;
  29074. indices[ic++] = verticeCount + (stack * (slices + 1)) + slice;
  29075. indices[ic++] = verticeCount + (stack * (slices + 1)) + slice + (slices);
  29076. indices[ic++] = verticeCount + (stack * (slices + 1)) + slice + (slices + 1);
  29077. }
  29078. }
  29079. }
  29080. verticeCount += (stacks + 1) * (slices + 1);
  29081. for (slice = 0; slice <= slices; slice++) {
  29082. posX = radius * Math.cos(slice * sliceAngle + Math.PI);
  29083. posY = hcHeight;
  29084. posZ = radius * Math.sin(slice * sliceAngle + Math.PI);
  29085. vertices[vc++] = posX;
  29086. vertices[vc + (slices + 1) * 8 - 1] = posX;
  29087. vertices[vc++] = posY;
  29088. vertices[vc + (slices + 1) * 8 - 1] = -posY;
  29089. vertices[vc++] = posZ;
  29090. vertices[vc + (slices + 1) * 8 - 1] = posZ;
  29091. vertices[vc++] = posX;
  29092. vertices[vc + (slices + 1) * 8 - 1] = posX;
  29093. vertices[vc++] = 0;
  29094. vertices[vc + (slices + 1) * 8 - 1] = 0;
  29095. vertices[vc++] = posZ;
  29096. vertices[vc + (slices + 1) * 8 - 1] = posZ;
  29097. vertices[vc++] = 1 - slice * 1 / slices;
  29098. vertices[vc + (slices + 1) * 8 - 1] = 1 - slice * 1 / slices;
  29099. vertices[vc++] = (Math.PI * radius / 2) / (height + Math.PI * radius);
  29100. vertices[vc + (slices + 1) * 8 - 1] = (Math.PI * radius / 2 + height) / (height + Math.PI * radius);
  29101. }
  29102. for (slice = 0; slice < slices; slice++) {
  29103. indices[ic++] = slice + verticeCount + (slices + 1);
  29104. indices[ic++] = slice + verticeCount + 1;
  29105. indices[ic++] = slice + verticeCount;
  29106. indices[ic++] = slice + verticeCount + (slices + 1);
  29107. indices[ic++] = slice + verticeCount + (slices + 1) + 1;
  29108. indices[ic++] = slice + verticeCount + 1;
  29109. }
  29110. verticeCount += 2 * (slices + 1);
  29111. return PrimitiveMesh._createMesh(vertexDeclaration, vertices, indices);
  29112. }
  29113. static createCone(radius = 0.5, height = 1, slices = 32) {
  29114. var vertexCount = (slices + 1 + 1) + (slices + 1) * 2;
  29115. var indexCount = 6 * slices + 3 * slices;
  29116. var vertexDeclaration = VertexMesh.getVertexDeclaration("POSITION,NORMAL,UV");
  29117. var vertexFloatStride = vertexDeclaration.vertexStride / 4;
  29118. var vertices = new Float32Array(vertexCount * vertexFloatStride);
  29119. var indices = new Uint16Array(indexCount);
  29120. var sliceAngle = (Math.PI * 2.0) / slices;
  29121. var halfHeight = height / 2;
  29122. var curAngle = 0;
  29123. var verticeCount = 0;
  29124. var posX = 0;
  29125. var posY = 0;
  29126. var posZ = 0;
  29127. var normal = new Vector3();
  29128. var downV3 = new Vector3(0, -1, 0);
  29129. var upPoint = new Vector3(0, halfHeight, 0);
  29130. var downPoint = new Vector3();
  29131. var v3 = new Vector3();
  29132. var q4 = new Quaternion();
  29133. var rotateAxis = new Vector3();
  29134. var rotateRadius;
  29135. var vc = 0;
  29136. var ic = 0;
  29137. for (var rv = 0; rv <= slices; rv++) {
  29138. curAngle = rv * sliceAngle;
  29139. posX = Math.cos(curAngle + Math.PI) * radius;
  29140. posY = halfHeight;
  29141. posZ = Math.sin(curAngle + Math.PI) * radius;
  29142. vertices[vc++] = 0;
  29143. vertices[vc + (slices + 1) * 8 - 1] = posX;
  29144. vertices[vc++] = posY;
  29145. vertices[vc + (slices + 1) * 8 - 1] = -posY;
  29146. vertices[vc++] = 0;
  29147. vertices[vc + (slices + 1) * 8 - 1] = posZ;
  29148. normal.x = posX;
  29149. normal.y = 0;
  29150. normal.z = posZ;
  29151. downPoint.x = posX;
  29152. downPoint.y = -posY;
  29153. downPoint.z = posZ;
  29154. Vector3.subtract(downPoint, upPoint, v3);
  29155. Vector3.normalize(v3, v3);
  29156. rotateRadius = Math.acos(Vector3.dot(downV3, v3));
  29157. Vector3.cross(downV3, v3, rotateAxis);
  29158. Vector3.normalize(rotateAxis, rotateAxis);
  29159. Quaternion.createFromAxisAngle(rotateAxis, rotateRadius, q4);
  29160. Vector3.normalize(normal, normal);
  29161. Vector3.transformQuat(normal, q4, normal);
  29162. Vector3.normalize(normal, normal);
  29163. vertices[vc++] = normal.x;
  29164. vertices[vc + (slices + 1) * 8 - 1] = normal.x;
  29165. vertices[vc++] = normal.y;
  29166. vertices[vc + (slices + 1) * 8 - 1] = normal.y;
  29167. vertices[vc++] = normal.z;
  29168. vertices[vc + (slices + 1) * 8 - 1] = normal.z;
  29169. vertices[vc++] = 1 - rv * 1 / slices;
  29170. vertices[vc + (slices + 1) * 8 - 1] = 1 - rv * 1 / slices;
  29171. vertices[vc++] = 0;
  29172. vertices[vc + (slices + 1) * 8 - 1] = 1;
  29173. }
  29174. vc += (slices + 1) * 8;
  29175. for (var ri = 0; ri < slices; ri++) {
  29176. indices[ic++] = ri + verticeCount + (slices + 1);
  29177. indices[ic++] = ri + verticeCount + 1;
  29178. indices[ic++] = ri + verticeCount;
  29179. indices[ic++] = ri + verticeCount + (slices + 1);
  29180. indices[ic++] = ri + verticeCount + (slices + 1) + 1;
  29181. indices[ic++] = ri + verticeCount + 1;
  29182. }
  29183. verticeCount += 2 * (slices + 1);
  29184. for (var bv = 0; bv <= slices; bv++) {
  29185. if (bv === 0) {
  29186. vertices[vc++] = 0;
  29187. vertices[vc++] = -halfHeight;
  29188. vertices[vc++] = 0;
  29189. vertices[vc++] = 0;
  29190. vertices[vc++] = -1;
  29191. vertices[vc++] = 0;
  29192. vertices[vc++] = 0.5;
  29193. vertices[vc++] = 0.5;
  29194. }
  29195. curAngle = bv * sliceAngle;
  29196. posX = Math.cos(curAngle + Math.PI) * radius;
  29197. posY = -halfHeight;
  29198. posZ = Math.sin(curAngle + Math.PI) * radius;
  29199. vertices[vc++] = posX;
  29200. vertices[vc++] = posY;
  29201. vertices[vc++] = posZ;
  29202. vertices[vc++] = 0;
  29203. vertices[vc++] = -1;
  29204. vertices[vc++] = 0;
  29205. vertices[vc++] = 0.5 + Math.cos(curAngle) * 0.5;
  29206. vertices[vc++] = 0.5 + Math.sin(curAngle) * 0.5;
  29207. }
  29208. for (var bi = 0; bi < slices; bi++) {
  29209. indices[ic++] = 0 + verticeCount;
  29210. indices[ic++] = bi + 2 + verticeCount;
  29211. indices[ic++] = bi + 1 + verticeCount;
  29212. }
  29213. verticeCount += slices + 1 + 1;
  29214. return PrimitiveMesh._createMesh(vertexDeclaration, vertices, indices);
  29215. }
  29216. static createCylinder(radius = 0.5, height = 2, slices = 32) {
  29217. var vertexCount = (slices + 1 + 1) + (slices + 1) * 2 + (slices + 1 + 1);
  29218. var indexCount = 3 * slices + 6 * slices + 3 * slices;
  29219. var vertexDeclaration = VertexMesh.getVertexDeclaration("POSITION,NORMAL,UV");
  29220. var vertexFloatStride = vertexDeclaration.vertexStride / 4;
  29221. var vertices = new Float32Array(vertexCount * vertexFloatStride);
  29222. var indices = new Uint16Array(indexCount);
  29223. var sliceAngle = (Math.PI * 2.0) / slices;
  29224. var halfHeight = height / 2;
  29225. var curAngle = 0;
  29226. var verticeCount = 0;
  29227. var posX = 0;
  29228. var posY = 0;
  29229. var posZ = 0;
  29230. var vc = 0;
  29231. var ic = 0;
  29232. for (var tv = 0; tv <= slices; tv++) {
  29233. if (tv === 0) {
  29234. vertices[vc++] = 0;
  29235. vertices[vc++] = halfHeight;
  29236. vertices[vc++] = 0;
  29237. vertices[vc++] = 0;
  29238. vertices[vc++] = 1;
  29239. vertices[vc++] = 0;
  29240. vertices[vc++] = 0.5;
  29241. vertices[vc++] = 0.5;
  29242. }
  29243. curAngle = tv * sliceAngle;
  29244. posX = Math.cos(curAngle) * radius;
  29245. posY = halfHeight;
  29246. posZ = Math.sin(curAngle) * radius;
  29247. vertices[vc++] = posX;
  29248. vertices[vc++] = posY;
  29249. vertices[vc++] = posZ;
  29250. vertices[vc++] = 0;
  29251. vertices[vc++] = 1;
  29252. vertices[vc++] = 0;
  29253. vertices[vc++] = 0.5 + Math.cos(curAngle) * 0.5;
  29254. vertices[vc++] = 0.5 + Math.sin(curAngle) * 0.5;
  29255. }
  29256. for (var ti = 0; ti < slices; ti++) {
  29257. indices[ic++] = 0;
  29258. indices[ic++] = ti + 1;
  29259. indices[ic++] = ti + 2;
  29260. }
  29261. verticeCount += slices + 1 + 1;
  29262. for (var rv = 0; rv <= slices; rv++) {
  29263. curAngle = rv * sliceAngle;
  29264. posX = Math.cos(curAngle + Math.PI) * radius;
  29265. posY = halfHeight;
  29266. posZ = Math.sin(curAngle + Math.PI) * radius;
  29267. vertices[vc++] = posX;
  29268. vertices[vc + (slices + 1) * 8 - 1] = posX;
  29269. vertices[vc++] = posY;
  29270. vertices[vc + (slices + 1) * 8 - 1] = -posY;
  29271. vertices[vc++] = posZ;
  29272. vertices[vc + (slices + 1) * 8 - 1] = posZ;
  29273. vertices[vc++] = posX;
  29274. vertices[vc + (slices + 1) * 8 - 1] = posX;
  29275. vertices[vc++] = 0;
  29276. vertices[vc + (slices + 1) * 8 - 1] = 0;
  29277. vertices[vc++] = posZ;
  29278. vertices[vc + (slices + 1) * 8 - 1] = posZ;
  29279. vertices[vc++] = 1 - rv * 1 / slices;
  29280. vertices[vc + (slices + 1) * 8 - 1] = 1 - rv * 1 / slices;
  29281. vertices[vc++] = 0;
  29282. vertices[vc + (slices + 1) * 8 - 1] = 1;
  29283. }
  29284. vc += (slices + 1) * 8;
  29285. for (var ri = 0; ri < slices; ri++) {
  29286. indices[ic++] = ri + verticeCount + (slices + 1);
  29287. indices[ic++] = ri + verticeCount + 1;
  29288. indices[ic++] = ri + verticeCount;
  29289. indices[ic++] = ri + verticeCount + (slices + 1);
  29290. indices[ic++] = ri + verticeCount + (slices + 1) + 1;
  29291. indices[ic++] = ri + verticeCount + 1;
  29292. }
  29293. verticeCount += 2 * (slices + 1);
  29294. for (var bv = 0; bv <= slices; bv++) {
  29295. if (bv === 0) {
  29296. vertices[vc++] = 0;
  29297. vertices[vc++] = -halfHeight;
  29298. vertices[vc++] = 0;
  29299. vertices[vc++] = 0;
  29300. vertices[vc++] = -1;
  29301. vertices[vc++] = 0;
  29302. vertices[vc++] = 0.5;
  29303. vertices[vc++] = 0.5;
  29304. }
  29305. curAngle = bv * sliceAngle;
  29306. posX = Math.cos(curAngle + Math.PI) * radius;
  29307. posY = -halfHeight;
  29308. posZ = Math.sin(curAngle + Math.PI) * radius;
  29309. vertices[vc++] = posX;
  29310. vertices[vc++] = posY;
  29311. vertices[vc++] = posZ;
  29312. vertices[vc++] = 0;
  29313. vertices[vc++] = -1;
  29314. vertices[vc++] = 0;
  29315. vertices[vc++] = 0.5 + Math.cos(curAngle) * 0.5;
  29316. vertices[vc++] = 0.5 + Math.sin(curAngle) * 0.5;
  29317. }
  29318. for (var bi = 0; bi < slices; bi++) {
  29319. indices[ic++] = 0 + verticeCount;
  29320. indices[ic++] = bi + 2 + verticeCount;
  29321. indices[ic++] = bi + 1 + verticeCount;
  29322. }
  29323. verticeCount += slices + 1 + 1;
  29324. return PrimitiveMesh._createMesh(vertexDeclaration, vertices, indices);
  29325. }
  29326. static createPlane(long = 10, width = 10, stacks = 10, slices = 10) {
  29327. var vertexCount = (stacks + 1) * (slices + 1);
  29328. var indexCount = stacks * slices * 2 * 3;
  29329. var indices = new Uint16Array(indexCount);
  29330. var vertexDeclaration = VertexMesh.getVertexDeclaration("POSITION,NORMAL,UV");
  29331. var vertexFloatStride = vertexDeclaration.vertexStride / 4;
  29332. var vertices = new Float32Array(vertexCount * vertexFloatStride);
  29333. var halfLong = long / 2;
  29334. var halfWidth = width / 2;
  29335. var stacksLong = long / stacks;
  29336. var slicesWidth = width / slices;
  29337. var verticeCount = 0;
  29338. for (var i = 0; i <= slices; i++) {
  29339. for (var j = 0; j <= stacks; j++) {
  29340. vertices[verticeCount++] = j * stacksLong - halfLong;
  29341. vertices[verticeCount++] = 0;
  29342. vertices[verticeCount++] = i * slicesWidth - halfWidth;
  29343. vertices[verticeCount++] = 0;
  29344. vertices[verticeCount++] = 1;
  29345. vertices[verticeCount++] = 0;
  29346. vertices[verticeCount++] = j * 1 / stacks;
  29347. vertices[verticeCount++] = i * 1 / slices;
  29348. }
  29349. }
  29350. var indiceIndex = 0;
  29351. for (i = 0; i < slices; i++) {
  29352. for (j = 0; j < stacks; j++) {
  29353. indices[indiceIndex++] = (i + 1) * (stacks + 1) + j;
  29354. indices[indiceIndex++] = i * (stacks + 1) + j;
  29355. indices[indiceIndex++] = (i + 1) * (stacks + 1) + j + 1;
  29356. indices[indiceIndex++] = i * (stacks + 1) + j;
  29357. indices[indiceIndex++] = i * (stacks + 1) + j + 1;
  29358. indices[indiceIndex++] = (i + 1) * (stacks + 1) + j + 1;
  29359. }
  29360. }
  29361. return PrimitiveMesh._createMesh(vertexDeclaration, vertices, indices);
  29362. }
  29363. static createQuad(long = 1, width = 1) {
  29364. var vertexDeclaration = VertexMesh.getVertexDeclaration("POSITION,NORMAL,UV");
  29365. var vertexFloatStride = vertexDeclaration.vertexStride / 4;
  29366. var halfLong = long / 2;
  29367. var halfWidth = width / 2;
  29368. 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]);
  29369. var indices = new Uint16Array([0, 1, 2, 3, 2, 1]);
  29370. return PrimitiveMesh._createMesh(vertexDeclaration, vertices, indices);
  29371. }
  29372. static createSphere(radius = 0.5, stacks = 32, slices = 32) {
  29373. var vertexCount = (stacks + 1) * (slices + 1);
  29374. var indexCount = (3 * stacks * (slices + 1)) * 2;
  29375. var indices = new Uint16Array(indexCount);
  29376. var vertexDeclaration = VertexMesh.getVertexDeclaration("POSITION,NORMAL,UV");
  29377. var vertexFloatStride = vertexDeclaration.vertexStride / 4;
  29378. var vertices = new Float32Array(vertexCount * vertexFloatStride);
  29379. var stackAngle = Math.PI / stacks;
  29380. var sliceAngle = (Math.PI * 2.0) / slices;
  29381. var vertexIndex = 0;
  29382. vertexCount = 0;
  29383. indexCount = 0;
  29384. for (var stack = 0; stack < (stacks + 1); stack++) {
  29385. var r = Math.sin(stack * stackAngle);
  29386. var y = Math.cos(stack * stackAngle);
  29387. for (var slice = 0; slice < (slices + 1); slice++) {
  29388. var x = r * Math.sin(slice * sliceAngle + Math.PI * 1 / 2);
  29389. var z = r * Math.cos(slice * sliceAngle + Math.PI * 1 / 2);
  29390. vertices[vertexCount + 0] = x * radius;
  29391. vertices[vertexCount + 1] = y * radius;
  29392. vertices[vertexCount + 2] = z * radius;
  29393. vertices[vertexCount + 3] = x;
  29394. vertices[vertexCount + 4] = y;
  29395. vertices[vertexCount + 5] = z;
  29396. vertices[vertexCount + 6] = slice / slices;
  29397. vertices[vertexCount + 7] = stack / stacks;
  29398. vertexCount += vertexFloatStride;
  29399. if (stack != (stacks - 1)) {
  29400. indices[indexCount++] = vertexIndex + (slices + 1);
  29401. indices[indexCount++] = vertexIndex;
  29402. indices[indexCount++] = vertexIndex + 1;
  29403. indices[indexCount++] = vertexIndex + (slices);
  29404. indices[indexCount++] = vertexIndex;
  29405. indices[indexCount++] = vertexIndex + (slices + 1);
  29406. vertexIndex++;
  29407. }
  29408. }
  29409. }
  29410. return PrimitiveMesh._createMesh(vertexDeclaration, vertices, indices);
  29411. }
  29412. }
  29413. class VertexPositionTerrain {
  29414. constructor(position, normal, textureCoord0, textureCoord1) {
  29415. this._position = position;
  29416. this._normal = normal;
  29417. this._textureCoord0 = textureCoord0;
  29418. this._textureCoord1 = textureCoord1;
  29419. }
  29420. static __init__() {
  29421. VertexPositionTerrain._vertexDeclaration = new VertexDeclaration(40, [new VertexElement(0, VertexElementFormat.Vector3, VertexPositionTerrain.TERRAIN_POSITION0),
  29422. new VertexElement(12, VertexElementFormat.Vector3, VertexPositionTerrain.TERRAIN_NORMAL0),
  29423. new VertexElement(24, VertexElementFormat.Vector2, VertexPositionTerrain.TERRAIN_TEXTURECOORDINATE0),
  29424. new VertexElement(32, VertexElementFormat.Vector2, VertexPositionTerrain.TERRAIN_TEXTURECOORDINATE1)]);
  29425. }
  29426. static get vertexDeclaration() {
  29427. return VertexPositionTerrain._vertexDeclaration;
  29428. }
  29429. get position() {
  29430. return this._position;
  29431. }
  29432. get normal() {
  29433. return this._normal;
  29434. }
  29435. get textureCoord0() {
  29436. return this._textureCoord0;
  29437. }
  29438. get textureCoord1() {
  29439. return this._textureCoord1;
  29440. }
  29441. get vertexDeclaration() {
  29442. return VertexPositionTerrain._vertexDeclaration;
  29443. }
  29444. }
  29445. VertexPositionTerrain.TERRAIN_POSITION0 = 0;
  29446. VertexPositionTerrain.TERRAIN_NORMAL0 = 1;
  29447. VertexPositionTerrain.TERRAIN_TEXTURECOORDINATE0 = 2;
  29448. VertexPositionTerrain.TERRAIN_TEXTURECOORDINATE1 = 3;
  29449. class Laya3D {
  29450. constructor() {
  29451. }
  29452. static get enbalePhysics() {
  29453. return Physics3D._enbalePhysics;
  29454. }
  29455. static _cancelLoadByUrl(url) {
  29456. Laya.Laya.loader.cancelLoadByUrl(url);
  29457. Laya3D._innerFirstLevelLoaderManager.cancelLoadByUrl(url);
  29458. Laya3D._innerSecondLevelLoaderManager.cancelLoadByUrl(url);
  29459. Laya3D._innerThirdLevelLoaderManager.cancelLoadByUrl(url);
  29460. Laya3D._innerFourthLevelLoaderManager.cancelLoadByUrl(url);
  29461. }
  29462. static _changeWebGLSize(width, height) {
  29463. Laya.WebGL.onStageResize(width, height);
  29464. RenderContext3D.clientWidth = width;
  29465. RenderContext3D.clientHeight = height;
  29466. }
  29467. static __init__(width, height, config) {
  29468. Laya.Config.isAntialias = config.isAntialias;
  29469. Laya.Config.isAlpha = config.isAlpha;
  29470. Laya.Config.premultipliedAlpha = config.premultipliedAlpha;
  29471. Laya.Config.isStencil = config.isStencil;
  29472. if (!Laya.WebGL.enable()) {
  29473. alert("Laya3D init error,must support webGL!");
  29474. return;
  29475. }
  29476. Laya.RunDriver.changeWebGLSize = Laya3D._changeWebGLSize;
  29477. Laya.Render.is3DMode = true;
  29478. Laya.Laya.init(width, height);
  29479. if (!Laya.Render.supportWebGLPlusRendering) {
  29480. Laya.LayaGL.instance = Laya.WebGLContext.mainContext;
  29481. Laya.LayaGL.instance.createCommandEncoder = function (reserveSize = 128, adjustSize = 64, isSyncToRenderThread = false) {
  29482. return new Laya.CommandEncoder(this, reserveSize, adjustSize, isSyncToRenderThread);
  29483. };
  29484. }
  29485. ILaya3D.Scene3D = Scene3D;
  29486. ILaya3D.MeshRenderStaticBatchManager = MeshRenderStaticBatchManager;
  29487. ILaya3D.MeshRenderDynamicBatchManager = MeshRenderDynamicBatchManager;
  29488. ILaya3D.SubMeshDynamicBatch = SubMeshDynamicBatch;
  29489. ILaya3D.Laya3D = Laya3D;
  29490. ILaya3D.Matrix4x4 = Matrix4x4;
  29491. Laya3D.enableNative3D();
  29492. VertexElementFormat.__init__();
  29493. VertexMesh.__init__();
  29494. VertexShurikenParticleBillboard.__init__();
  29495. VertexShurikenParticleMesh.__init__();
  29496. VertexPositionTexture0.__init__();
  29497. VertexTrail.__init__();
  29498. VertexPositionTerrain.__init__();
  29499. PixelLineVertex.__init__();
  29500. SubMeshInstanceBatch.__init__();
  29501. SubMeshDynamicBatch.__init__();
  29502. Physics3D._physics3D = window.Physics3D;
  29503. if (Physics3D._physics3D) {
  29504. StaticPlaneColliderShape.__init__();
  29505. ColliderShape.__init__();
  29506. CompoundColliderShape.__init__();
  29507. PhysicsComponent.__init__();
  29508. PhysicsSimulation.__init__();
  29509. BoxColliderShape.__init__();
  29510. CylinderColliderShape.__init__();
  29511. CharacterController.__init__();
  29512. Rigidbody3D.__init__();
  29513. }
  29514. Mesh.__init__();
  29515. PrimitiveMesh.__init__();
  29516. Sprite3D.__init__();
  29517. RenderableSprite3D.__init__();
  29518. MeshSprite3D.__init__();
  29519. SkinnedMeshSprite3D.__init__();
  29520. ShuriKenParticle3D.__init__();
  29521. TrailSprite3D.__init__();
  29522. PostProcess.__init__();
  29523. Scene3D.__init__();
  29524. MeshRenderStaticBatchManager.__init__();
  29525. BaseMaterial.__initDefine__();
  29526. BlinnPhongMaterial.__initDefine__();
  29527. PBRStandardMaterial.__initDefine__();
  29528. PBRSpecularMaterial.__initDefine__();
  29529. SkyProceduralMaterial.__initDefine__();
  29530. UnlitMaterial.__initDefine__();
  29531. TrailMaterial.__initDefine__();
  29532. EffectMaterial.__initDefine__();
  29533. WaterPrimaryMaterial.__initDefine__();
  29534. ShurikenParticleMaterial.__initDefine__();
  29535. ExtendTerrainMaterial.__initDefine__();
  29536. PixelLineMaterial.__initDefine__();
  29537. SkyBoxMaterial.__initDefine__();
  29538. ShaderInit3D.__init__();
  29539. Command.__init__();
  29540. Laya.ClassUtils.regClass("Laya.EffectMaterial", EffectMaterial);
  29541. Laya.ClassUtils.regClass("Laya.UnlitMaterial", UnlitMaterial);
  29542. Laya.ClassUtils.regClass("Laya.BlinnPhongMaterial", BlinnPhongMaterial);
  29543. Laya.ClassUtils.regClass("Laya.SkyProceduralMaterial", SkyProceduralMaterial);
  29544. Laya.ClassUtils.regClass("Laya.PBRStandardMaterial", PBRStandardMaterial);
  29545. Laya.ClassUtils.regClass("Laya.PBRSpecularMaterial", PBRSpecularMaterial);
  29546. Laya.ClassUtils.regClass("Laya.SkyBoxMaterial", SkyBoxMaterial);
  29547. Laya.ClassUtils.regClass("Laya.WaterPrimaryMaterial", WaterPrimaryMaterial);
  29548. Laya.ClassUtils.regClass("Laya.ExtendTerrainMaterial", ExtendTerrainMaterial);
  29549. Laya.ClassUtils.regClass("Laya.ShurikenParticleMaterial", ShurikenParticleMaterial);
  29550. Laya.ClassUtils.regClass("Laya.TrailMaterial", TrailMaterial);
  29551. Laya.ClassUtils.regClass("Laya.PhysicsCollider", PhysicsCollider);
  29552. Laya.ClassUtils.regClass("Laya.Rigidbody3D", Rigidbody3D);
  29553. Laya.ClassUtils.regClass("Laya.CharacterController", CharacterController);
  29554. Laya.ClassUtils.regClass("Laya.Animator", Animator);
  29555. Laya.ClassUtils.regClass("PhysicsCollider", PhysicsCollider);
  29556. Laya.ClassUtils.regClass("CharacterController", CharacterController);
  29557. Laya.ClassUtils.regClass("Animator", Animator);
  29558. Laya.ClassUtils.regClass("Rigidbody3D", Rigidbody3D);
  29559. PixelLineMaterial.defaultMaterial = new PixelLineMaterial();
  29560. BlinnPhongMaterial.defaultMaterial = new BlinnPhongMaterial();
  29561. EffectMaterial.defaultMaterial = new EffectMaterial();
  29562. PBRStandardMaterial.defaultMaterial = new PBRStandardMaterial();
  29563. PBRSpecularMaterial.defaultMaterial = new PBRSpecularMaterial();
  29564. UnlitMaterial.defaultMaterial = new UnlitMaterial();
  29565. ShurikenParticleMaterial.defaultMaterial = new ShurikenParticleMaterial();
  29566. TrailMaterial.defaultMaterial = new TrailMaterial();
  29567. SkyProceduralMaterial.defaultMaterial = new SkyProceduralMaterial();
  29568. SkyBoxMaterial.defaultMaterial = new SkyBoxMaterial();
  29569. WaterPrimaryMaterial.defaultMaterial = new WaterPrimaryMaterial();
  29570. PixelLineMaterial.defaultMaterial.lock = true;
  29571. BlinnPhongMaterial.defaultMaterial.lock = true;
  29572. EffectMaterial.defaultMaterial.lock = true;
  29573. PBRStandardMaterial.defaultMaterial.lock = true;
  29574. PBRSpecularMaterial.defaultMaterial.lock = true;
  29575. UnlitMaterial.defaultMaterial.lock = true;
  29576. ShurikenParticleMaterial.defaultMaterial.lock = true;
  29577. TrailMaterial.defaultMaterial.lock = true;
  29578. SkyProceduralMaterial.defaultMaterial.lock = true;
  29579. SkyBoxMaterial.defaultMaterial.lock = true;
  29580. WaterPrimaryMaterial.defaultMaterial.lock = true;
  29581. Laya.Texture2D.__init__();
  29582. TextureCube.__init__();
  29583. SkyBox.__init__();
  29584. SkyDome.__init__();
  29585. ScreenQuad.__init__();
  29586. ScreenTriangle.__init__();
  29587. FrustumCulling.__init__();
  29588. HalfFloatUtils.__init__();
  29589. var createMap = Laya.LoaderManager.createMap;
  29590. createMap["lh"] = [Laya3D.HIERARCHY, Scene3DUtils._parse];
  29591. createMap["ls"] = [Laya3D.HIERARCHY, Scene3DUtils._parseScene];
  29592. createMap["lm"] = [Laya3D.MESH, Mesh._parse];
  29593. createMap["lmat"] = [Laya3D.MATERIAL, BaseMaterial._parse];
  29594. createMap["ltc"] = [Laya3D.TEXTURECUBE, TextureCube._parse];
  29595. createMap["jpg"] = [Laya3D.TEXTURE2D, Laya.Texture2D._parse];
  29596. createMap["jpeg"] = [Laya3D.TEXTURE2D, Laya.Texture2D._parse];
  29597. createMap["bmp"] = [Laya3D.TEXTURE2D, Laya.Texture2D._parse];
  29598. createMap["gif"] = [Laya3D.TEXTURE2D, Laya.Texture2D._parse];
  29599. createMap["png"] = [Laya3D.TEXTURE2D, Laya.Texture2D._parse];
  29600. createMap["dds"] = [Laya3D.TEXTURE2D, Laya.Texture2D._parse];
  29601. createMap["ktx"] = [Laya3D.TEXTURE2D, Laya.Texture2D._parse];
  29602. createMap["pvr"] = [Laya3D.TEXTURE2D, Laya.Texture2D._parse];
  29603. createMap["lani"] = [Laya3D.ANIMATIONCLIP, AnimationClip._parse];
  29604. createMap["lav"] = [Laya3D.AVATAR, Avatar._parse];
  29605. var parserMap = Laya.Loader.parserMap;
  29606. parserMap[Laya3D.HIERARCHY] = Laya3D._loadHierarchy;
  29607. parserMap[Laya3D.MESH] = Laya3D._loadMesh;
  29608. parserMap[Laya3D.MATERIAL] = Laya3D._loadMaterial;
  29609. parserMap[Laya3D.TEXTURECUBE] = Laya3D._loadTextureCube;
  29610. parserMap[Laya3D.TEXTURE2D] = Laya3D._loadTexture2D;
  29611. parserMap[Laya3D.ANIMATIONCLIP] = Laya3D._loadAnimationClip;
  29612. parserMap[Laya3D.AVATAR] = Laya3D._loadAvatar;
  29613. Laya3D._innerFirstLevelLoaderManager.on(Laya.Event.ERROR, null, Laya3D._eventLoadManagerError);
  29614. Laya3D._innerSecondLevelLoaderManager.on(Laya.Event.ERROR, null, Laya3D._eventLoadManagerError);
  29615. Laya3D._innerThirdLevelLoaderManager.on(Laya.Event.ERROR, null, Laya3D._eventLoadManagerError);
  29616. Laya3D._innerFourthLevelLoaderManager.on(Laya.Event.ERROR, null, Laya3D._eventLoadManagerError);
  29617. }
  29618. static enableNative3D() {
  29619. var shaderData = ShaderData;
  29620. var shader3D = ShaderInstance;
  29621. var skinnedMeshRender = SkinnedMeshRenderer;
  29622. var avatar = Avatar;
  29623. var frustumCulling = FrustumCulling;
  29624. if (Laya.Render.supportWebGLPlusRendering) {
  29625. shaderData.prototype._initData = shaderData.prototype._initDataForNative;
  29626. shaderData.prototype.setBool = shaderData.prototype.setBoolForNative;
  29627. shaderData.prototype.getBool = shaderData.prototype.getBoolForNative;
  29628. shaderData.prototype.setInt = shaderData.prototype.setIntForNative;
  29629. shaderData.prototype.getInt = shaderData.prototype.getIntForNative;
  29630. shaderData.prototype.setNumber = shaderData.prototype.setNumberForNative;
  29631. shaderData.prototype.getNumber = shaderData.prototype.getNumberForNative;
  29632. shaderData.prototype.setVector = shaderData.prototype.setVectorForNative;
  29633. shaderData.prototype.getVector = shaderData.prototype.getVectorForNative;
  29634. shaderData.prototype.setVector2 = shaderData.prototype.setVector2ForNative;
  29635. shaderData.prototype.getVector2 = shaderData.prototype.getVector2ForNative;
  29636. shaderData.prototype.setVector3 = shaderData.prototype.setVector3ForNative;
  29637. shaderData.prototype.getVector3 = shaderData.prototype.getVector3ForNative;
  29638. shaderData.prototype.setQuaternion = shaderData.prototype.setQuaternionForNative;
  29639. shaderData.prototype.getQuaternion = shaderData.prototype.getQuaternionForNative;
  29640. shaderData.prototype.setMatrix4x4 = shaderData.prototype.setMatrix4x4ForNative;
  29641. shaderData.prototype.getMatrix4x4 = shaderData.prototype.getMatrix4x4ForNative;
  29642. shaderData.prototype.setBuffer = shaderData.prototype.setBufferForNative;
  29643. shaderData.prototype.getBuffer = shaderData.prototype.getBufferForNative;
  29644. shaderData.prototype.setTexture = shaderData.prototype.setTextureForNative;
  29645. shaderData.prototype.getTexture = shaderData.prototype.getTextureForNative;
  29646. shaderData.prototype.setAttribute = shaderData.prototype.setAttributeForNative;
  29647. shaderData.prototype.getAttribute = shaderData.prototype.getAttributeForNative;
  29648. shaderData.prototype.cloneTo = shaderData.prototype.cloneToForNative;
  29649. shaderData.prototype.getData = shaderData.prototype.getDataForNative;
  29650. shader3D.prototype._uniformMatrix2fv = shader3D.prototype._uniformMatrix2fvForNative;
  29651. shader3D.prototype._uniformMatrix3fv = shader3D.prototype._uniformMatrix3fvForNative;
  29652. shader3D.prototype._uniformMatrix4fv = shader3D.prototype._uniformMatrix4fvForNative;
  29653. Laya.LayaGLRunner.uploadShaderUniforms = Laya.LayaGLRunner.uploadShaderUniformsForNative;
  29654. }
  29655. if (Laya.Render.supportWebGLPlusCulling) {
  29656. frustumCulling.renderObjectCulling = FrustumCulling.renderObjectCullingNative;
  29657. }
  29658. if (Laya.Render.supportWebGLPlusAnimation) {
  29659. avatar.prototype._cloneDatasToAnimator = avatar.prototype._cloneDatasToAnimatorNative;
  29660. var animationClip = AnimationClip;
  29661. animationClip.prototype._evaluateClipDatasRealTime = animationClip.prototype._evaluateClipDatasRealTimeForNative;
  29662. skinnedMeshRender.prototype._computeSkinnedData = skinnedMeshRender.prototype._computeSkinnedDataForNative;
  29663. }
  29664. if (Laya.Render.isConchApp) {
  29665. Laya.WebGL.shaderHighPrecision = false;
  29666. var gl = Laya.LayaGL.instance;
  29667. var precisionFormat = gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.HIGH_FLOAT);
  29668. precisionFormat.precision ? Laya.WebGL.shaderHighPrecision = true : Laya.WebGL.shaderHighPrecision = false;
  29669. }
  29670. }
  29671. static formatRelativePath(base, value) {
  29672. var path;
  29673. path = base + value;
  29674. var char1 = value.charAt(0);
  29675. if (char1 === ".") {
  29676. var parts = path.split("/");
  29677. for (var i = 0, len = parts.length; i < len; i++) {
  29678. if (parts[i] == '..') {
  29679. var index = i - 1;
  29680. if (index > 0 && parts[index] !== '..') {
  29681. parts.splice(index, 2);
  29682. i -= 2;
  29683. }
  29684. }
  29685. }
  29686. path = parts.join('/');
  29687. }
  29688. return path;
  29689. }
  29690. static _endLoad(loader, content = null, subResous = null) {
  29691. if (subResous) {
  29692. for (var i = 0, n = subResous.length; i < n; i++) {
  29693. var resou = Laya.Loader.getRes(subResous[i]);
  29694. (resou) && (resou._removeReference());
  29695. }
  29696. }
  29697. loader.endLoad(content);
  29698. }
  29699. static _eventLoadManagerError(msg) {
  29700. Laya.Laya.loader.event(Laya.Event.ERROR, msg);
  29701. }
  29702. static _addHierarchyInnerUrls(urls, urlMap, urlVersion, hierarchyBasePath, path, type, constructParams = null, propertyParams = null) {
  29703. var formatUrl = Laya3D.formatRelativePath(hierarchyBasePath, path);
  29704. (urlVersion) && (formatUrl = formatUrl + urlVersion);
  29705. urls.push({ url: formatUrl, type: type, constructParams: constructParams, propertyParams: propertyParams });
  29706. urlMap.push(formatUrl);
  29707. return formatUrl;
  29708. }
  29709. static _getSprite3DHierarchyInnerUrls(node, firstLevelUrls, secondLevelUrls, thirdLevelUrls, fourthLelUrls, subUrls, urlVersion, hierarchyBasePath) {
  29710. var i, n;
  29711. var props = node.props;
  29712. switch (node.type) {
  29713. case "Scene3D":
  29714. var lightmaps = props.lightmaps;
  29715. for (i = 0, n = lightmaps.length; i < n; i++) {
  29716. var lightMap = lightmaps[i];
  29717. lightMap.path = Laya3D._addHierarchyInnerUrls(fourthLelUrls, subUrls, urlVersion, hierarchyBasePath, lightMap.path, Laya3D.TEXTURE2D, lightMap.constructParams, lightMap.propertyParams);
  29718. }
  29719. var reflectionTextureData = props.reflectionTexture;
  29720. (reflectionTextureData) && (props.reflectionTexture = Laya3D._addHierarchyInnerUrls(thirdLevelUrls, subUrls, urlVersion, hierarchyBasePath, reflectionTextureData, Laya3D.TEXTURECUBE));
  29721. if (props.sky) {
  29722. var skyboxMaterial = props.sky.material;
  29723. (skyboxMaterial) && (skyboxMaterial.path = Laya3D._addHierarchyInnerUrls(secondLevelUrls, subUrls, urlVersion, hierarchyBasePath, skyboxMaterial.path, Laya3D.MATERIAL));
  29724. }
  29725. break;
  29726. case "Camera":
  29727. var skyboxMatData = props.skyboxMaterial;
  29728. (skyboxMatData) && (skyboxMatData.path = Laya3D._addHierarchyInnerUrls(secondLevelUrls, subUrls, urlVersion, hierarchyBasePath, skyboxMatData.path, Laya3D.MATERIAL));
  29729. break;
  29730. case "TrailSprite3D":
  29731. case "MeshSprite3D":
  29732. case "SkinnedMeshSprite3D":
  29733. var meshPath = props.meshPath;
  29734. (meshPath) && (props.meshPath = Laya3D._addHierarchyInnerUrls(firstLevelUrls, subUrls, urlVersion, hierarchyBasePath, meshPath, Laya3D.MESH));
  29735. var materials = props.materials;
  29736. if (materials)
  29737. for (i = 0, n = materials.length; i < n; i++)
  29738. materials[i].path = Laya3D._addHierarchyInnerUrls(secondLevelUrls, subUrls, urlVersion, hierarchyBasePath, materials[i].path, Laya3D.MATERIAL);
  29739. break;
  29740. case "ShuriKenParticle3D":
  29741. var parMeshPath = props.meshPath;
  29742. (parMeshPath) && (props.meshPath = Laya3D._addHierarchyInnerUrls(firstLevelUrls, subUrls, urlVersion, hierarchyBasePath, parMeshPath, Laya3D.MESH));
  29743. props.material.path = Laya3D._addHierarchyInnerUrls(secondLevelUrls, subUrls, urlVersion, hierarchyBasePath, props.material.path, Laya3D.MATERIAL);
  29744. break;
  29745. case "Terrain":
  29746. Laya3D._addHierarchyInnerUrls(fourthLelUrls, subUrls, urlVersion, hierarchyBasePath, props.dataPath, Laya3D.TERRAINRES);
  29747. break;
  29748. }
  29749. var components = node.components;
  29750. if (components) {
  29751. for (var k = 0, p = components.length; k < p; k++) {
  29752. var component = components[k];
  29753. switch (component.type) {
  29754. case "Animator":
  29755. var avatarPath = component.avatarPath;
  29756. var avatarData = component.avatar;
  29757. (avatarData) && (avatarData.path = Laya3D._addHierarchyInnerUrls(fourthLelUrls, subUrls, urlVersion, hierarchyBasePath, avatarData.path, Laya3D.AVATAR));
  29758. var clipPaths = component.clipPaths;
  29759. if (!clipPaths) {
  29760. var layersData = component.layers;
  29761. for (i = 0; i < layersData.length; i++) {
  29762. var states = layersData[i].states;
  29763. for (var j = 0, m = states.length; j < m; j++) {
  29764. var clipPath = states[j].clipPath;
  29765. (clipPath) && (states[j].clipPath = Laya3D._addHierarchyInnerUrls(fourthLelUrls, subUrls, urlVersion, hierarchyBasePath, clipPath, Laya3D.ANIMATIONCLIP));
  29766. }
  29767. }
  29768. }
  29769. else {
  29770. for (i = 0, n = clipPaths.length; i < n; i++)
  29771. clipPaths[i] = Laya3D._addHierarchyInnerUrls(fourthLelUrls, subUrls, urlVersion, hierarchyBasePath, clipPaths[i], Laya3D.ANIMATIONCLIP);
  29772. }
  29773. break;
  29774. case "PhysicsCollider":
  29775. case "Rigidbody3D":
  29776. case "CharacterController":
  29777. var shapes = component.shapes;
  29778. for (i = 0; i < shapes.length; i++) {
  29779. var shape = shapes[i];
  29780. if (shape.type === "MeshColliderShape") {
  29781. var mesh = shape.mesh;
  29782. (mesh) && (shape.mesh = Laya3D._addHierarchyInnerUrls(firstLevelUrls, subUrls, urlVersion, hierarchyBasePath, mesh, Laya3D.MESH));
  29783. }
  29784. }
  29785. break;
  29786. }
  29787. }
  29788. }
  29789. var children = node.child;
  29790. for (i = 0, n = children.length; i < n; i++)
  29791. Laya3D._getSprite3DHierarchyInnerUrls(children[i], firstLevelUrls, secondLevelUrls, thirdLevelUrls, fourthLelUrls, subUrls, urlVersion, hierarchyBasePath);
  29792. }
  29793. static _loadHierarchy(loader) {
  29794. loader.on(Laya.Event.LOADED, null, Laya3D._onHierarchylhLoaded, [loader]);
  29795. loader.load(loader.url, Laya.Loader.JSON, false, null, true);
  29796. }
  29797. static _onHierarchylhLoaded(loader, lhData) {
  29798. var url = loader.url;
  29799. var urlVersion = Utils3D.getURLVerion(url);
  29800. var hierarchyBasePath = Laya.URL.getPath(url);
  29801. var firstLevUrls = [];
  29802. var secondLevUrls = [];
  29803. var thirdLevUrls = [];
  29804. var forthLevUrls = [];
  29805. var subUrls = [];
  29806. Laya3D._getSprite3DHierarchyInnerUrls(lhData.data, firstLevUrls, secondLevUrls, thirdLevUrls, forthLevUrls, subUrls, urlVersion, hierarchyBasePath);
  29807. var urlCount = firstLevUrls.length + secondLevUrls.length + forthLevUrls.length;
  29808. var totalProcessCount = urlCount + 1;
  29809. var weight = 1 / totalProcessCount;
  29810. Laya3D._onProcessChange(loader, 0, weight, 1.0);
  29811. if (forthLevUrls.length > 0) {
  29812. var processCeil = urlCount / totalProcessCount;
  29813. var processHandler = Laya.Handler.create(null, Laya3D._onProcessChange, [loader, weight, processCeil], false);
  29814. 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);
  29815. }
  29816. else {
  29817. Laya3D._onHierarchyInnerForthLevResouLoaded(loader, null, lhData, subUrls, firstLevUrls, secondLevUrls, thirdLevUrls, weight, processCeil);
  29818. }
  29819. }
  29820. static _onHierarchyInnerForthLevResouLoaded(loader, processHandler, lhData, subUrls, firstLevUrls, secondLevUrls, thirdLevUrls, processOffset, processCeil) {
  29821. (processHandler) && (processHandler.recover());
  29822. if (thirdLevUrls.length > 0) {
  29823. var process = Laya.Handler.create(null, Laya3D._onProcessChange, [loader, processOffset, processCeil], false);
  29824. 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);
  29825. }
  29826. else {
  29827. Laya3D._onHierarchyInnerThirdLevResouLoaded(loader, null, lhData, subUrls, firstLevUrls, secondLevUrls, processOffset, processCeil);
  29828. }
  29829. }
  29830. static _onHierarchyInnerThirdLevResouLoaded(loader, processHandler, lhData, subUrls, firstLevUrls, secondLevUrls, processOffset, processCeil) {
  29831. (processHandler) && (processHandler.recover());
  29832. if (secondLevUrls.length > 0) {
  29833. var process = Laya.Handler.create(null, Laya3D._onProcessChange, [loader, processOffset, processCeil], false);
  29834. 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);
  29835. }
  29836. else {
  29837. Laya3D._onHierarchyInnerSecondLevResouLoaded(loader, null, lhData, subUrls, firstLevUrls, processOffset, processCeil);
  29838. }
  29839. }
  29840. static _onHierarchyInnerSecondLevResouLoaded(loader, processHandler, lhData, subUrls, firstLevUrls, processOffset, processCeil) {
  29841. (processHandler) && (processHandler.recover());
  29842. if (firstLevUrls.length > 0) {
  29843. var process = Laya.Handler.create(null, Laya3D._onProcessChange, [loader, processOffset, processCeil], false);
  29844. Laya3D._innerFirstLevelLoaderManager._create(firstLevUrls, false, Laya.Handler.create(null, Laya3D._onHierarchyInnerFirstLevResouLoaded, [loader, process, lhData, subUrls]), processHandler, null, null, null, 1, true);
  29845. }
  29846. else {
  29847. Laya3D._onHierarchyInnerFirstLevResouLoaded(loader, null, lhData, subUrls);
  29848. }
  29849. }
  29850. static _onHierarchyInnerFirstLevResouLoaded(loader, processHandler, lhData, subUrls) {
  29851. (processHandler) && (processHandler.recover());
  29852. loader._cache = loader._createCache;
  29853. var item = lhData.data.type === "Scene3D" ? Scene3DUtils._parseScene(lhData, loader._propertyParams, loader._constructParams) : Scene3DUtils._parse(lhData, loader._propertyParams, loader._constructParams);
  29854. Laya3D._endLoad(loader, item, subUrls);
  29855. }
  29856. static _loadMesh(loader) {
  29857. loader.on(Laya.Event.LOADED, null, Laya3D._onMeshLmLoaded, [loader]);
  29858. loader.load(loader.url, Laya.Loader.BUFFER, false, null, true);
  29859. }
  29860. static _onMeshLmLoaded(loader, lmData) {
  29861. loader._cache = loader._createCache;
  29862. var mesh = Mesh._parse(lmData, loader._propertyParams, loader._constructParams);
  29863. Laya3D._endLoad(loader, mesh);
  29864. }
  29865. static _loadMaterial(loader) {
  29866. loader.on(Laya.Event.LOADED, null, Laya3D._onMaterilLmatLoaded, [loader]);
  29867. loader.load(loader.url, Laya.Loader.JSON, false, null, true);
  29868. }
  29869. static _onMaterilLmatLoaded(loader, lmatData) {
  29870. var url = loader.url;
  29871. var urlVersion = Utils3D.getURLVerion(url);
  29872. var materialBasePath = Laya.URL.getPath(url);
  29873. var urls = [];
  29874. var subUrls = [];
  29875. var customProps = lmatData.customProps;
  29876. var formatSubUrl;
  29877. var version = lmatData.version;
  29878. switch (version) {
  29879. case "LAYAMATERIAL:01":
  29880. case "LAYAMATERIAL:02":
  29881. var i, n;
  29882. var textures = lmatData.props.textures;
  29883. if (textures) {
  29884. for (i = 0, n = textures.length; i < n; i++) {
  29885. var tex2D = textures[i];
  29886. var tex2DPath = tex2D.path;
  29887. if (tex2DPath) {
  29888. formatSubUrl = Laya3D.formatRelativePath(materialBasePath, tex2DPath);
  29889. (urlVersion) && (formatSubUrl = formatSubUrl + urlVersion);
  29890. urls.push({ url: formatSubUrl, constructParams: tex2D.constructParams, propertyParams: tex2D.propertyParams });
  29891. subUrls.push(formatSubUrl);
  29892. tex2D.path = formatSubUrl;
  29893. }
  29894. }
  29895. }
  29896. break;
  29897. default:
  29898. throw new Error("Laya3D:unkonwn version.");
  29899. }
  29900. var urlCount = urls.length;
  29901. var totalProcessCount = urlCount + 1;
  29902. var lmatWeight = 1 / totalProcessCount;
  29903. Laya3D._onProcessChange(loader, 0, lmatWeight, 1.0);
  29904. if (urlCount > 0) {
  29905. var processHandler = Laya.Handler.create(null, Laya3D._onProcessChange, [loader, lmatWeight, urlCount / totalProcessCount], false);
  29906. Laya3D._innerFourthLevelLoaderManager._create(urls, false, Laya.Handler.create(null, Laya3D._onMateialTexturesLoaded, [loader, processHandler, lmatData, subUrls]), processHandler, null, null, null, 1, true);
  29907. }
  29908. else {
  29909. Laya3D._onMateialTexturesLoaded(loader, null, lmatData, null);
  29910. }
  29911. }
  29912. static _onMateialTexturesLoaded(loader, processHandler, lmatData, subUrls) {
  29913. loader._cache = loader._createCache;
  29914. var mat = BaseMaterial._parse(lmatData, loader._propertyParams, loader._constructParams);
  29915. Laya3D._endLoad(loader, mat, subUrls);
  29916. (processHandler) && (processHandler.recover());
  29917. }
  29918. static _loadAvatar(loader) {
  29919. loader.on(Laya.Event.LOADED, null, function (data) {
  29920. loader._cache = loader._createCache;
  29921. var avatar = Avatar._parse(data, loader._propertyParams, loader._constructParams);
  29922. Laya3D._endLoad(loader, avatar);
  29923. });
  29924. loader.load(loader.url, Laya.Loader.JSON, false, null, true);
  29925. }
  29926. static _loadAnimationClip(loader) {
  29927. loader.on(Laya.Event.LOADED, null, function (data) {
  29928. loader._cache = loader._createCache;
  29929. var clip = AnimationClip._parse(data, loader._propertyParams, loader._constructParams);
  29930. Laya3D._endLoad(loader, clip);
  29931. });
  29932. loader.load(loader.url, Laya.Loader.BUFFER, false, null, true);
  29933. }
  29934. static _loadTexture2D(loader) {
  29935. var url = loader.url;
  29936. var index = url.lastIndexOf('.') + 1;
  29937. var verIndex = url.indexOf('?');
  29938. var endIndex = verIndex == -1 ? url.length : verIndex;
  29939. var ext = url.substr(index, endIndex - index);
  29940. var type;
  29941. switch (ext) {
  29942. case "jpg":
  29943. case "jpeg":
  29944. case "bmp":
  29945. case "gif":
  29946. case "png":
  29947. type = "nativeimage";
  29948. break;
  29949. case "dds":
  29950. case "ktx":
  29951. case "pvr":
  29952. type = Laya.Loader.BUFFER;
  29953. break;
  29954. }
  29955. loader.on(Laya.Event.LOADED, null, function (image) {
  29956. loader._cache = loader._createCache;
  29957. var tex = Laya.Texture2D._parse(image, loader._propertyParams, loader._constructParams);
  29958. Laya3D._endLoad(loader, tex);
  29959. });
  29960. loader.load(loader.url, type, false, null, true);
  29961. }
  29962. static _loadTextureCube(loader) {
  29963. loader.on(Laya.Event.LOADED, null, Laya3D._onTextureCubeLtcLoaded, [loader]);
  29964. loader.load(loader.url, Laya.Loader.JSON, false, null, true);
  29965. }
  29966. static _onTextureCubeLtcLoaded(loader, ltcData) {
  29967. var ltcBasePath = Laya.URL.getPath(loader.url);
  29968. 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)];
  29969. var ltcWeight = 1.0 / 7.0;
  29970. Laya3D._onProcessChange(loader, 0, ltcWeight, 1.0);
  29971. var processHandler = Laya.Handler.create(null, Laya3D._onProcessChange, [loader, ltcWeight, 6 / 7], false);
  29972. Laya3D._innerFourthLevelLoaderManager.load(urls, Laya.Handler.create(null, Laya3D._onTextureCubeImagesLoaded, [loader, urls, processHandler]), processHandler, "nativeimage");
  29973. }
  29974. static _onTextureCubeImagesLoaded(loader, urls, processHandler) {
  29975. var images = new Array(6);
  29976. for (var i = 0; i < 6; i++)
  29977. images[i] = Laya.Loader.getRes(urls[i]);
  29978. loader._cache = loader._createCache;
  29979. var tex = TextureCube._parse(images, loader._propertyParams, loader._constructParams);
  29980. processHandler.recover();
  29981. for (i = 0; i < 6; i++)
  29982. Laya.Loader.clearRes(urls[i]);
  29983. Laya3D._endLoad(loader, tex);
  29984. }
  29985. static _onProcessChange(loader, offset, weight, process) {
  29986. process = offset + process * weight;
  29987. (process < 1.0) && (loader.event(Laya.Event.PROGRESS, process));
  29988. }
  29989. static init(width, height, config = null, compolete = null) {
  29990. if (Laya3D._isInit)
  29991. return;
  29992. Laya3D._isInit = true;
  29993. config = config || Config3D._default;
  29994. config.cloneTo(Laya3D._config);
  29995. FrustumCulling.debugFrustumCulling = config.debugFrustumCulling;
  29996. Laya3D._editerEnvironment = Laya3D._config._editerEnvironment;
  29997. Scene3D.octreeCulling = config.octreeCulling;
  29998. Scene3D.octreeInitialSize = config.octreeInitialSize;
  29999. Scene3D.octreeInitialCenter = config.octreeInitialCenter;
  30000. Scene3D.octreeMinNodeSize = config.octreeMinNodeSize;
  30001. Scene3D.octreeLooseness = config.octreeLooseness;
  30002. var physics3D = window.Physics3D;
  30003. if (physics3D == null) {
  30004. Physics3D._enbalePhysics = false;
  30005. Laya3D.__init__(width, height, Laya3D._config);
  30006. compolete && compolete.run();
  30007. }
  30008. else {
  30009. Physics3D._enbalePhysics = true;
  30010. physics3D(Laya3D._config.defaultPhysicsMemory * 1024 * 1024).then(function () {
  30011. Laya3D.__init__(width, height, Laya3D._config);
  30012. compolete && compolete.run();
  30013. });
  30014. }
  30015. }
  30016. }
  30017. Laya3D.HIERARCHY = "HIERARCHY";
  30018. Laya3D.MESH = "MESH";
  30019. Laya3D.MATERIAL = "MATERIAL";
  30020. Laya3D.TEXTURE2D = "TEXTURE2D";
  30021. Laya3D.TEXTURECUBE = "TEXTURECUBE";
  30022. Laya3D.ANIMATIONCLIP = "ANIMATIONCLIP";
  30023. Laya3D.AVATAR = "AVATAR";
  30024. Laya3D.TERRAINHEIGHTDATA = "TERRAINHEIGHTDATA";
  30025. Laya3D.TERRAINRES = "TERRAIN";
  30026. Laya3D._innerFirstLevelLoaderManager = new Laya.LoaderManager();
  30027. Laya3D._innerSecondLevelLoaderManager = new Laya.LoaderManager();
  30028. Laya3D._innerThirdLevelLoaderManager = new Laya.LoaderManager();
  30029. Laya3D._innerFourthLevelLoaderManager = new Laya.LoaderManager();
  30030. Laya3D._isInit = false;
  30031. Laya3D._editerEnvironment = false;
  30032. Laya3D._config = new Config3D();
  30033. Laya3D.physicsSettings = new PhysicsSettings();
  30034. window.Laya3D = Laya3D;
  30035. class AnimatorStateScript {
  30036. constructor() {
  30037. }
  30038. onStateEnter() {
  30039. }
  30040. onStateUpdate() {
  30041. }
  30042. onStateExit() {
  30043. }
  30044. }
  30045. class Script3D extends Laya.Component {
  30046. constructor() {
  30047. super(...arguments);
  30048. this._indexInPool = -1;
  30049. }
  30050. get isSingleton() {
  30051. return false;
  30052. }
  30053. _checkProcessTriggers() {
  30054. var prototype = Script3D.prototype;
  30055. if (this.onTriggerEnter !== prototype.onTriggerEnter)
  30056. return true;
  30057. if (this.onTriggerStay !== prototype.onTriggerStay)
  30058. return true;
  30059. if (this.onTriggerExit !== prototype.onTriggerExit)
  30060. return true;
  30061. return false;
  30062. }
  30063. _checkProcessCollisions() {
  30064. var prototype = Script3D.prototype;
  30065. if (this.onCollisionEnter !== prototype.onCollisionEnter)
  30066. return true;
  30067. if (this.onCollisionStay !== prototype.onCollisionStay)
  30068. return true;
  30069. if (this.onCollisionExit !== prototype.onCollisionExit)
  30070. return true;
  30071. return false;
  30072. }
  30073. _onAwake() {
  30074. this.onAwake();
  30075. if (this.onStart !== Script3D.prototype.onStart)
  30076. Laya.Laya.startTimer.callLater(this, this.onStart);
  30077. }
  30078. _onEnable() {
  30079. this.owner._scene._addScript(this);
  30080. var proto = Script3D.prototype;
  30081. if (this.onKeyDown !== proto.onKeyDown) {
  30082. Laya.Laya.stage.on(Laya.Event.KEY_DOWN, this, this.onKeyDown);
  30083. }
  30084. if (this.onKeyPress !== proto.onKeyPress) {
  30085. Laya.Laya.stage.on(Laya.Event.KEY_PRESS, this, this.onKeyUp);
  30086. }
  30087. if (this.onKeyUp !== proto.onKeyUp) {
  30088. Laya.Laya.stage.on(Laya.Event.KEY_UP, this, this.onKeyUp);
  30089. }
  30090. }
  30091. _onDisable() {
  30092. this.owner._scene._removeScript(this);
  30093. this.owner.offAllCaller(this);
  30094. Laya.Laya.stage.offAllCaller(this);
  30095. }
  30096. _isScript() {
  30097. return true;
  30098. }
  30099. _onAdded() {
  30100. var sprite = this.owner;
  30101. var scripts = sprite._scripts;
  30102. scripts || (sprite._scripts = scripts = []);
  30103. scripts.push(this);
  30104. if (!sprite._needProcessCollisions)
  30105. sprite._needProcessCollisions = this._checkProcessCollisions();
  30106. if (!sprite._needProcessTriggers)
  30107. sprite._needProcessTriggers = this._checkProcessTriggers();
  30108. }
  30109. _onDestroy() {
  30110. var scripts = this.owner._scripts;
  30111. scripts.splice(scripts.indexOf(this), 1);
  30112. var sprite = this.owner;
  30113. sprite._needProcessTriggers = false;
  30114. for (var i = 0, n = scripts.length; i < n; i++) {
  30115. if (scripts[i]._checkProcessTriggers()) {
  30116. sprite._needProcessTriggers = true;
  30117. break;
  30118. }
  30119. }
  30120. sprite._needProcessCollisions = false;
  30121. for (i = 0, n = scripts.length; i < n; i++) {
  30122. if (scripts[i]._checkProcessCollisions()) {
  30123. sprite._needProcessCollisions = true;
  30124. break;
  30125. }
  30126. }
  30127. this.onDestroy();
  30128. }
  30129. onAwake() {
  30130. }
  30131. onEnable() {
  30132. }
  30133. onStart() {
  30134. }
  30135. onTriggerEnter(other) {
  30136. }
  30137. onTriggerStay(other) {
  30138. }
  30139. onTriggerExit(other) {
  30140. }
  30141. onCollisionEnter(collision) {
  30142. }
  30143. onCollisionStay(collision) {
  30144. }
  30145. onCollisionExit(collision) {
  30146. }
  30147. onMouseDown() {
  30148. }
  30149. onMouseDrag() {
  30150. }
  30151. onMouseClick() {
  30152. }
  30153. onMouseUp() {
  30154. }
  30155. onMouseEnter() {
  30156. }
  30157. onMouseOver() {
  30158. }
  30159. onMouseOut() {
  30160. }
  30161. onKeyDown(e) {
  30162. }
  30163. onKeyPress(e) {
  30164. }
  30165. onKeyUp(e) {
  30166. }
  30167. onUpdate() {
  30168. }
  30169. onLateUpdate() {
  30170. }
  30171. onPreRender() {
  30172. }
  30173. onPostRender() {
  30174. }
  30175. onDisable() {
  30176. }
  30177. onDestroy() {
  30178. }
  30179. }
  30180. class HeightMap {
  30181. constructor(width, height, minHeight, maxHeight) {
  30182. this._datas = [];
  30183. this._w = width;
  30184. this._h = height;
  30185. this._minHeight = minHeight;
  30186. this._maxHeight = maxHeight;
  30187. }
  30188. static creatFromMesh(mesh, width, height, outCellSize) {
  30189. var vertices = [];
  30190. var indexs = [];
  30191. var submesheCount = mesh.subMeshCount;
  30192. for (var i = 0; i < submesheCount; i++) {
  30193. var subMesh = mesh.getSubMesh(i);
  30194. var vertexBuffer = subMesh._vertexBuffer;
  30195. var verts = vertexBuffer.getFloat32Data();
  30196. var subMeshVertices = [];
  30197. for (var j = 0; j < verts.length; j += vertexBuffer.vertexDeclaration.vertexStride / 4) {
  30198. var position = new Vector3(verts[j + 0], verts[j + 1], verts[j + 2]);
  30199. subMeshVertices.push(position);
  30200. }
  30201. vertices.push(subMeshVertices);
  30202. var ib = subMesh._indexBuffer;
  30203. indexs.push(ib.getData());
  30204. }
  30205. var bounds = mesh.bounds;
  30206. var minX = bounds.getMin().x;
  30207. var minZ = bounds.getMin().z;
  30208. var maxX = bounds.getMax().x;
  30209. var maxZ = bounds.getMax().z;
  30210. var minY = bounds.getMin().y;
  30211. var maxY = bounds.getMax().y;
  30212. var widthSize = maxX - minX;
  30213. var heightSize = maxZ - minZ;
  30214. var cellWidth = outCellSize.x = widthSize / (width - 1);
  30215. var cellHeight = outCellSize.y = heightSize / (height - 1);
  30216. var heightMap = new HeightMap(width, height, minY, maxY);
  30217. var ray = HeightMap._tempRay;
  30218. var rayDir = ray.direction;
  30219. rayDir.x = 0;
  30220. rayDir.y = -1;
  30221. rayDir.z = 0;
  30222. const heightOffset = 0.1;
  30223. var rayY = maxY + heightOffset;
  30224. ray.origin.y = rayY;
  30225. for (var h = 0; h < height; h++) {
  30226. var posZ = minZ + h * cellHeight;
  30227. heightMap._datas[h] = [];
  30228. for (var w = 0; w < width; w++) {
  30229. var posX = minX + w * cellWidth;
  30230. var rayOri = ray.origin;
  30231. rayOri.x = posX;
  30232. rayOri.z = posZ;
  30233. var closestIntersection = HeightMap._getPosition(ray, vertices, indexs);
  30234. heightMap._datas[h][w] = (closestIntersection === Number.MAX_VALUE) ? NaN : rayY - closestIntersection;
  30235. }
  30236. }
  30237. return heightMap;
  30238. }
  30239. static createFromImage(texture, minHeight, maxHeight) {
  30240. var textureWidth = texture.width;
  30241. var textureHeight = texture.height;
  30242. var heightMap = new HeightMap(textureWidth, textureHeight, minHeight, maxHeight);
  30243. var compressionRatio = (maxHeight - minHeight) / 254;
  30244. var pixelsInfo = texture.getPixels();
  30245. var index = 0;
  30246. for (var h = 0; h < textureHeight; h++) {
  30247. var colDatas = heightMap._datas[h] = [];
  30248. for (var w = 0; w < textureWidth; w++) {
  30249. var r = pixelsInfo[index++];
  30250. var g = pixelsInfo[index++];
  30251. var b = pixelsInfo[index++];
  30252. var a = pixelsInfo[index++];
  30253. if (r == 255 && g == 255 && b == 255 && a == 255)
  30254. colDatas[w] = NaN;
  30255. else {
  30256. colDatas[w] = (r + g + b) / 3 * compressionRatio + minHeight;
  30257. }
  30258. }
  30259. }
  30260. return heightMap;
  30261. }
  30262. static _getPosition(ray, vertices, indexs) {
  30263. var closestIntersection = Number.MAX_VALUE;
  30264. for (var i = 0; i < vertices.length; i++) {
  30265. var subMeshVertices = vertices[i];
  30266. var subMeshIndexes = indexs[i];
  30267. for (var j = 0; j < subMeshIndexes.length; j += 3) {
  30268. var vertex1 = subMeshVertices[subMeshIndexes[j + 0]];
  30269. var vertex2 = subMeshVertices[subMeshIndexes[j + 1]];
  30270. var vertex3 = subMeshVertices[subMeshIndexes[j + 2]];
  30271. var intersection = Picker.rayIntersectsTriangle(ray, vertex1, vertex2, vertex3);
  30272. if (!isNaN(intersection) && intersection < closestIntersection) {
  30273. closestIntersection = intersection;
  30274. }
  30275. }
  30276. }
  30277. return closestIntersection;
  30278. }
  30279. get width() {
  30280. return this._w;
  30281. }
  30282. get height() {
  30283. return this._h;
  30284. }
  30285. get maxHeight() {
  30286. return this._maxHeight;
  30287. }
  30288. get minHeight() {
  30289. return this._minHeight;
  30290. }
  30291. _inBounds(row, col) {
  30292. return row >= 0 && row < this._h && col >= 0 && col < this._w;
  30293. }
  30294. getHeight(row, col) {
  30295. if (this._inBounds(row, col))
  30296. return this._datas[row][col];
  30297. else
  30298. return NaN;
  30299. }
  30300. }
  30301. HeightMap._tempRay = new Ray(new Vector3(), new Vector3());
  30302. class MeshTerrainSprite3D extends MeshSprite3D {
  30303. constructor(mesh, heightMap, name = null) {
  30304. super(mesh, name);
  30305. this._heightMap = heightMap;
  30306. this._cellSize = new Vector2();
  30307. }
  30308. static createFromMesh(mesh, heightMapWidth, heightMapHeight, name = null) {
  30309. var meshTerrainSprite3D = new MeshTerrainSprite3D(mesh, null, name);
  30310. meshTerrainSprite3D._initCreateFromMesh(heightMapWidth, heightMapHeight);
  30311. return meshTerrainSprite3D;
  30312. }
  30313. static createFromMeshAndHeightMap(mesh, texture, minHeight, maxHeight, name = null) {
  30314. var meshTerrainSprite3D = new MeshTerrainSprite3D(mesh, null, name);
  30315. meshTerrainSprite3D._initCreateFromMeshHeightMap(texture, minHeight, maxHeight);
  30316. return meshTerrainSprite3D;
  30317. }
  30318. get minX() {
  30319. var worldMat = this.transform.worldMatrix;
  30320. var worldMatE = worldMat.elements;
  30321. return this._minX * this._getScaleX() + worldMatE[12];
  30322. }
  30323. get minZ() {
  30324. var worldMat = this.transform.worldMatrix;
  30325. var worldMatE = worldMat.elements;
  30326. return this._minZ * this._getScaleZ() + worldMatE[14];
  30327. }
  30328. get width() {
  30329. return (this._heightMap.width - 1) * this._cellSize.x * this._getScaleX();
  30330. }
  30331. get depth() {
  30332. return (this._heightMap.height - 1) * this._cellSize.y * this._getScaleZ();
  30333. }
  30334. _disableRotation() {
  30335. var rotation = this.transform.rotation;
  30336. rotation.x = 0;
  30337. rotation.y = 0;
  30338. rotation.z = 0;
  30339. rotation.w = 1;
  30340. this.transform.rotation = rotation;
  30341. }
  30342. _getScaleX() {
  30343. var worldMat = this.transform.worldMatrix;
  30344. var worldMatE = worldMat.elements;
  30345. var m11 = worldMatE[0];
  30346. var m12 = worldMatE[1];
  30347. var m13 = worldMatE[2];
  30348. return Math.sqrt((m11 * m11) + (m12 * m12) + (m13 * m13));
  30349. }
  30350. _getScaleZ() {
  30351. var worldMat = this.transform.worldMatrix;
  30352. var worldMatE = worldMat.elements;
  30353. var m31 = worldMatE[8];
  30354. var m32 = worldMatE[9];
  30355. var m33 = worldMatE[10];
  30356. return Math.sqrt((m31 * m31) + (m32 * m32) + (m33 * m33));
  30357. }
  30358. _initCreateFromMesh(heightMapWidth, heightMapHeight) {
  30359. this._heightMap = HeightMap.creatFromMesh(this.meshFilter.sharedMesh, heightMapWidth, heightMapHeight, this._cellSize);
  30360. var boundingBox = this.meshFilter.sharedMesh.bounds;
  30361. var min = boundingBox.getMin();
  30362. var max = boundingBox.getMax();
  30363. this._minX = min.x;
  30364. this._minZ = min.z;
  30365. }
  30366. _initCreateFromMeshHeightMap(texture, minHeight, maxHeight) {
  30367. var boundingBox = this.meshFilter.sharedMesh.bounds;
  30368. this._heightMap = HeightMap.createFromImage(texture, minHeight, maxHeight);
  30369. this._computeCellSize(boundingBox);
  30370. var min = boundingBox.getMin();
  30371. var max = boundingBox.getMax();
  30372. this._minX = min.x;
  30373. this._minZ = min.z;
  30374. }
  30375. _computeCellSize(boundingBox) {
  30376. var min = boundingBox.getMin();
  30377. var max = boundingBox.getMax();
  30378. var minX = min.x;
  30379. var minZ = min.z;
  30380. var maxX = max.x;
  30381. var maxZ = max.z;
  30382. var widthSize = maxX - minX;
  30383. var heightSize = maxZ - minZ;
  30384. this._cellSize.x = widthSize / (this._heightMap.width - 1);
  30385. this._cellSize.y = heightSize / (this._heightMap.height - 1);
  30386. }
  30387. _update(state) {
  30388. this._disableRotation();
  30389. }
  30390. getHeight(x, z) {
  30391. MeshTerrainSprite3D._tempVector3.x = x;
  30392. MeshTerrainSprite3D._tempVector3.y = 0;
  30393. MeshTerrainSprite3D._tempVector3.z = z;
  30394. this._disableRotation();
  30395. var worldMat = this.transform.worldMatrix;
  30396. worldMat.invert(MeshTerrainSprite3D._tempMatrix4x4);
  30397. Vector3.transformCoordinate(MeshTerrainSprite3D._tempVector3, MeshTerrainSprite3D._tempMatrix4x4, MeshTerrainSprite3D._tempVector3);
  30398. x = MeshTerrainSprite3D._tempVector3.x;
  30399. z = MeshTerrainSprite3D._tempVector3.z;
  30400. var c = (x - this._minX) / this._cellSize.x;
  30401. var d = (z - this._minZ) / this._cellSize.y;
  30402. var row = Math.floor(d);
  30403. var col = Math.floor(c);
  30404. var s = c - col;
  30405. var t = d - row;
  30406. var uy;
  30407. var vy;
  30408. var worldMatE = worldMat.elements;
  30409. var m21 = worldMatE[4];
  30410. var m22 = worldMatE[5];
  30411. var m23 = worldMatE[6];
  30412. var scaleY = Math.sqrt((m21 * m21) + (m22 * m22) + (m23 * m23));
  30413. var translateY = worldMatE[13];
  30414. var h01 = this._heightMap.getHeight(row, col + 1);
  30415. var h10 = this._heightMap.getHeight((row + 1), col);
  30416. if (isNaN(h01) || isNaN(h10))
  30417. return NaN;
  30418. if (s + t <= 1.0) {
  30419. var h00 = this._heightMap.getHeight(row, col);
  30420. if (isNaN(h00))
  30421. return NaN;
  30422. uy = h01 - h00;
  30423. vy = h10 - h00;
  30424. return (h00 + s * uy + t * vy) * scaleY + translateY;
  30425. }
  30426. else {
  30427. var h11 = this._heightMap.getHeight((row + 1), col + 1);
  30428. if (isNaN(h11))
  30429. return NaN;
  30430. uy = h10 - h11;
  30431. vy = h01 - h11;
  30432. return (h11 + (1.0 - s) * uy + (1.0 - t) * vy) * scaleY + translateY;
  30433. }
  30434. }
  30435. }
  30436. MeshTerrainSprite3D._tempVector3 = new Vector3();
  30437. MeshTerrainSprite3D._tempMatrix4x4 = new Matrix4x4();
  30438. class GradientDataVector2 {
  30439. constructor() {
  30440. this._currentLength = 0;
  30441. this._elements = new Float32Array(12);
  30442. }
  30443. get gradientCount() {
  30444. return this._currentLength / 3;
  30445. }
  30446. add(key, value) {
  30447. if (this._currentLength < 8) {
  30448. if ((this._currentLength === 6) && ((key !== 1))) {
  30449. key = 1;
  30450. console.log("GradientDataVector2 warning:the forth key is be force set to 1.");
  30451. }
  30452. this._elements[this._currentLength++] = key;
  30453. this._elements[this._currentLength++] = value.x;
  30454. this._elements[this._currentLength++] = value.y;
  30455. }
  30456. else {
  30457. console.log("GradientDataVector2 warning:data count must lessEqual than 4");
  30458. }
  30459. }
  30460. cloneTo(destObject) {
  30461. var destGradientDataVector2 = destObject;
  30462. destGradientDataVector2._currentLength = this._currentLength;
  30463. var destElements = destGradientDataVector2._elements;
  30464. for (var i = 0, n = this._elements.length; i < n; i++) {
  30465. destElements[i] = this._elements[i];
  30466. }
  30467. }
  30468. clone() {
  30469. var destGradientDataVector2 = new GradientDataVector2();
  30470. this.cloneTo(destGradientDataVector2);
  30471. return destGradientDataVector2;
  30472. }
  30473. }
  30474. class PixelLineData {
  30475. constructor() {
  30476. this.startPosition = new Vector3();
  30477. this.endPosition = new Vector3();
  30478. this.startColor = new Color();
  30479. this.endColor = new Color();
  30480. }
  30481. cloneTo(destObject) {
  30482. this.startPosition.cloneTo(destObject.startPosition);
  30483. this.endPosition.cloneTo(destObject.endPosition);
  30484. this.startColor.cloneTo(destObject.startColor);
  30485. this.endColor.cloneTo(destObject.endColor);
  30486. }
  30487. }
  30488. class PostProcessEffect {
  30489. constructor() {
  30490. }
  30491. render(context) {
  30492. }
  30493. }
  30494. class BloomEffect extends PostProcessEffect {
  30495. constructor() {
  30496. super();
  30497. this._shader = null;
  30498. this._shaderData = new ShaderData();
  30499. this._linearColor = new Color();
  30500. this._bloomTextureTexelSize = new Vector4();
  30501. this._shaderThreshold = new Vector4();
  30502. this._shaderParams = new Vector4();
  30503. this._pyramid = null;
  30504. this._intensity = 0.0;
  30505. this._threshold = 1.0;
  30506. this._softKnee = 0.5;
  30507. this._diffusion = 7.0;
  30508. this._anamorphicRatio = 0.0;
  30509. this._dirtIntensity = 0.0;
  30510. this._shaderSetting = new Vector4();
  30511. this._dirtTileOffset = new Vector4();
  30512. this.clamp = 65472.0;
  30513. this.color = new Color(1.0, 1.0, 1.0, 1.0);
  30514. this.fastMode = false;
  30515. this.dirtTexture = null;
  30516. this._shader = Shader3D.find("PostProcessBloom");
  30517. this._pyramid = new Array(BloomEffect.MAXPYRAMIDSIZE * 2);
  30518. }
  30519. get intensity() {
  30520. return this._intensity;
  30521. }
  30522. set intensity(value) {
  30523. this._intensity = Math.max(value, 0.0);
  30524. }
  30525. get threshold() {
  30526. return this._threshold;
  30527. }
  30528. set threshold(value) {
  30529. this._threshold = Math.max(value, 0.0);
  30530. }
  30531. get softKnee() {
  30532. return this._softKnee;
  30533. }
  30534. set softKnee(value) {
  30535. this._softKnee = Math.min(Math.max(value, 0.0), 1.0);
  30536. }
  30537. get diffusion() {
  30538. return this._diffusion;
  30539. }
  30540. set diffusion(value) {
  30541. this._diffusion = Math.min(Math.max(value, 1), 10);
  30542. }
  30543. get anamorphicRatio() {
  30544. return this._anamorphicRatio;
  30545. }
  30546. set anamorphicRatio(value) {
  30547. this._anamorphicRatio = Math.min(Math.max(value, -1.0), 1.0);
  30548. }
  30549. get dirtIntensity() {
  30550. return this._dirtIntensity;
  30551. }
  30552. set dirtIntensity(value) {
  30553. this._dirtIntensity = Math.max(value, 0.0);
  30554. }
  30555. render(context) {
  30556. var cmd = context.command;
  30557. var viewport = context.camera.viewport;
  30558. this._shaderData.setTexture(BloomEffect.SHADERVALUE_AUTOEXPOSURETEX, Laya.Texture2D.whiteTexture);
  30559. var ratio = this._anamorphicRatio;
  30560. var rw = ratio < 0 ? -ratio : 0;
  30561. var rh = ratio > 0 ? ratio : 0;
  30562. var tw = Math.floor(viewport.width / (2 - rw));
  30563. var th = Math.floor(viewport.height / (2 - rh));
  30564. var s = Math.max(tw, th);
  30565. var logs;
  30566. logs = Math.log2(s) + this._diffusion - 10;
  30567. var logsInt = Math.floor(logs);
  30568. var iterations = Math.min(Math.max(logsInt, 1), BloomEffect.MAXPYRAMIDSIZE);
  30569. var sampleScale = 0.5 + logs - logsInt;
  30570. this._shaderData.setNumber(BloomEffect.SHADERVALUE_SAMPLESCALE, sampleScale);
  30571. var lthresh = Color.gammaToLinearSpace(this.threshold);
  30572. var knee = lthresh * this._softKnee + 1e-5;
  30573. this._shaderThreshold.setValue(lthresh, lthresh - knee, knee * 2, 0.25 / knee);
  30574. this._shaderData.setVector(BloomEffect.SHADERVALUE_THRESHOLD, this._shaderThreshold);
  30575. var lclamp = Color.gammaToLinearSpace(this.clamp);
  30576. this._shaderParams.setValue(lclamp, 0, 0, 0);
  30577. this._shaderData.setVector(BloomEffect.SHADERVALUE_PARAMS, this._shaderParams);
  30578. var qualityOffset = this.fastMode ? 1 : 0;
  30579. var lastDownTexture = context.source;
  30580. for (var i = 0; i < iterations; i++) {
  30581. var downIndex = i * 2;
  30582. var upIndex = downIndex + 1;
  30583. var subShader = i == 0 ? BloomEffect.SUBSHADER_PREFILTER13 + qualityOffset : BloomEffect.SUBSHADER_DOWNSAMPLE13 + qualityOffset;
  30584. var mipDownTexture = RenderTexture.createFromPool(tw, th, Laya.BaseTexture.FORMAT_R8G8B8, Laya.BaseTexture.FORMAT_DEPTHSTENCIL_NONE, Laya.BaseTexture.FILTERMODE_BILINEAR);
  30585. this._pyramid[downIndex] = mipDownTexture;
  30586. if (i !== iterations - 1) {
  30587. var mipUpTexture = RenderTexture.createFromPool(tw, th, Laya.BaseTexture.FORMAT_R8G8B8, Laya.BaseTexture.FORMAT_DEPTHSTENCIL_NONE, Laya.BaseTexture.FILTERMODE_BILINEAR);
  30588. this._pyramid[upIndex] = mipUpTexture;
  30589. }
  30590. cmd.blitScreenTriangle(lastDownTexture, mipDownTexture, this._shader, this._shaderData, subShader);
  30591. lastDownTexture = mipDownTexture;
  30592. tw = Math.max(Math.floor(tw / 2), 1);
  30593. th = Math.max(Math.floor(th / 2), 1);
  30594. }
  30595. var lastUpTexture = this._pyramid[(iterations - 1) * 2];
  30596. for (i = iterations - 2; i >= 0; i--) {
  30597. downIndex = i * 2;
  30598. upIndex = downIndex + 1;
  30599. mipDownTexture = this._pyramid[downIndex];
  30600. mipUpTexture = this._pyramid[upIndex];
  30601. cmd.setShaderDataTexture(this._shaderData, BloomEffect.SHADERVALUE_BLOOMTEX, mipDownTexture);
  30602. cmd.blitScreenTriangle(lastUpTexture, mipUpTexture, this._shader, this._shaderData, BloomEffect.SUBSHADER_UPSAMPLETENT + qualityOffset);
  30603. lastUpTexture = mipUpTexture;
  30604. }
  30605. var linearColor = this._linearColor;
  30606. this.color.toLinear(linearColor);
  30607. var intensity = Math.pow(2, this._intensity / 10.0) - 1.0;
  30608. var shaderSettings = this._shaderSetting;
  30609. this._shaderSetting.setValue(sampleScale, intensity, this._dirtIntensity, iterations);
  30610. var dirtTexture = this.dirtTexture ? this.dirtTexture : Laya.Texture2D.blackTexture;
  30611. var dirtRatio = dirtTexture.width / dirtTexture.height;
  30612. var screenRatio = viewport.width / viewport.height;
  30613. var dirtTileOffset = this._dirtTileOffset;
  30614. if (dirtRatio > screenRatio)
  30615. dirtTileOffset.setValue(screenRatio / dirtRatio, 1.0, (1.0 - dirtTileOffset.x) * 0.5, 0.0);
  30616. else if (dirtRatio < screenRatio)
  30617. dirtTileOffset.setValue(1.0, dirtRatio / screenRatio, 0.0, (1.0 - dirtTileOffset.y) * 0.5);
  30618. var compositeShaderData = context.compositeShaderData;
  30619. if (this.fastMode)
  30620. compositeShaderData.addDefine(PostProcess.SHADERDEFINE_BLOOM_LOW);
  30621. else
  30622. compositeShaderData.addDefine(PostProcess.SHADERDEFINE_BLOOM);
  30623. this._bloomTextureTexelSize.setValue(1.0 / lastUpTexture.width, 1.0 / lastUpTexture.height, lastUpTexture.width, lastUpTexture.height);
  30624. compositeShaderData.setVector(PostProcess.SHADERVALUE_BLOOM_DIRTTILEOFFSET, dirtTileOffset);
  30625. compositeShaderData.setVector(PostProcess.SHADERVALUE_BLOOM_SETTINGS, shaderSettings);
  30626. compositeShaderData.setVector(PostProcess.SHADERVALUE_BLOOM_COLOR, new Vector4(linearColor.r, linearColor.g, linearColor.b, linearColor.a));
  30627. compositeShaderData.setTexture(PostProcess.SHADERVALUE_BLOOM_DIRTTEX, dirtTexture);
  30628. compositeShaderData.setTexture(PostProcess.SHADERVALUE_BLOOMTEX, lastUpTexture);
  30629. compositeShaderData.setVector(PostProcess.SHADERVALUE_BLOOMTEX_TEXELSIZE, this._bloomTextureTexelSize);
  30630. for (i = 0; i < iterations; i++) {
  30631. downIndex = i * 2;
  30632. upIndex = downIndex + 1;
  30633. RenderTexture.recoverToPool(this._pyramid[downIndex]);
  30634. (i !== 0 && i !== iterations - 1) && (RenderTexture.recoverToPool(this._pyramid[upIndex]));
  30635. }
  30636. context.deferredReleaseTextures.push(lastUpTexture);
  30637. }
  30638. }
  30639. BloomEffect.SHADERVALUE_MAINTEX = Shader3D.propertyNameToID("u_MainTex");
  30640. BloomEffect.SHADERVALUE_AUTOEXPOSURETEX = Shader3D.propertyNameToID("u_AutoExposureTex");
  30641. BloomEffect.SHADERVALUE_SAMPLESCALE = Shader3D.propertyNameToID("u_SampleScale");
  30642. BloomEffect.SHADERVALUE_THRESHOLD = Shader3D.propertyNameToID("u_Threshold");
  30643. BloomEffect.SHADERVALUE_PARAMS = Shader3D.propertyNameToID("u_Params");
  30644. BloomEffect.SHADERVALUE_BLOOMTEX = Shader3D.propertyNameToID("u_BloomTex");
  30645. BloomEffect.SUBSHADER_PREFILTER13 = 0;
  30646. BloomEffect.SUBSHADER_PREFILTER4 = 1;
  30647. BloomEffect.SUBSHADER_DOWNSAMPLE13 = 2;
  30648. BloomEffect.SUBSHADER_DOWNSAMPLE4 = 3;
  30649. BloomEffect.SUBSHADER_UPSAMPLETENT = 4;
  30650. BloomEffect.SUBSHADER_UPSAMPLEBOX = 5;
  30651. BloomEffect.MAXPYRAMIDSIZE = 16;
  30652. class SceneManager {
  30653. constructor() {
  30654. }
  30655. }
  30656. class RandX {
  30657. constructor(seed) {
  30658. if (!(seed instanceof Array) || seed.length !== 4)
  30659. throw new Error('Rand:Seed must be an array with 4 numbers');
  30660. this._state0U = seed[0] | 0;
  30661. this._state0L = seed[1] | 0;
  30662. this._state1U = seed[2] | 0;
  30663. this._state1L = seed[3] | 0;
  30664. }
  30665. randomint() {
  30666. var s1U = this._state0U, s1L = this._state0L;
  30667. var s0U = this._state1U, s0L = this._state1L;
  30668. var sumL = (s0L >>> 0) + (s1L >>> 0);
  30669. var resU = (s0U + s1U + (sumL / 2 >>> 31)) >>> 0;
  30670. var resL = sumL >>> 0;
  30671. this._state0U = s0U;
  30672. this._state0L = s0L;
  30673. var t1U = 0, t1L = 0;
  30674. var t2U = 0, t2L = 0;
  30675. var a1 = 23;
  30676. var m1 = 0xFFFFFFFF << (32 - a1);
  30677. t1U = (s1U << a1) | ((s1L & m1) >>> (32 - a1));
  30678. t1L = s1L << a1;
  30679. s1U = s1U ^ t1U;
  30680. s1L = s1L ^ t1L;
  30681. t1U = s1U ^ s0U;
  30682. t1L = s1L ^ s0L;
  30683. var a2 = 18;
  30684. var m2 = 0xFFFFFFFF >>> (32 - a2);
  30685. t2U = s1U >>> a2;
  30686. t2L = (s1L >>> a2) | ((s1U & m2) << (32 - a2));
  30687. t1U = t1U ^ t2U;
  30688. t1L = t1L ^ t2L;
  30689. var a3 = 5;
  30690. var m3 = 0xFFFFFFFF >>> (32 - a3);
  30691. t2U = s0U >>> a3;
  30692. t2L = (s0L >>> a3) | ((s0U & m3) << (32 - a3));
  30693. t1U = t1U ^ t2U;
  30694. t1L = t1L ^ t2L;
  30695. this._state1U = t1U;
  30696. this._state1L = t1L;
  30697. return [resU, resL];
  30698. }
  30699. random() {
  30700. var t2 = this.randomint();
  30701. var t2U = t2[0];
  30702. var t2L = t2[1];
  30703. var eU = 0x3FF << (52 - 32);
  30704. var eL = 0;
  30705. var a1 = 12;
  30706. var m1 = 0xFFFFFFFF >>> (32 - a1);
  30707. var sU = t2U >>> a1;
  30708. var sL = (t2L >>> a1) | ((t2U & m1) << (32 - a1));
  30709. var xU = eU | sU;
  30710. var xL = eL | sL;
  30711. RandX._CONVERTION_BUFFER.setUint32(0, xU, false);
  30712. RandX._CONVERTION_BUFFER.setUint32(4, xL, false);
  30713. var d = RandX._CONVERTION_BUFFER.getFloat64(0, false);
  30714. return d - 1;
  30715. }
  30716. }
  30717. RandX._CONVERTION_BUFFER = new DataView(new ArrayBuffer(8));
  30718. RandX.defaultRand = new RandX([0, Date.now() / 65536, 0, Date.now() % 65536]);
  30719. class Constraint3D {
  30720. constructor() {
  30721. }
  30722. }
  30723. class ConstraintComponent extends Laya.Component {
  30724. constructor() {
  30725. super();
  30726. this._feedbackEnabled = false;
  30727. }
  30728. get enabled() {
  30729. return super.enabled;
  30730. }
  30731. set enabled(value) {
  30732. this._nativeConstraint.IsEnabled = value;
  30733. super.enabled = value;
  30734. }
  30735. get breakingImpulseThreshold() {
  30736. return this._breakingImpulseThreshold;
  30737. }
  30738. set breakingImpulseThreshold(value) {
  30739. this._nativeConstraint.BreakingImpulseThreshold = value;
  30740. this._breakingImpulseThreshold = value;
  30741. }
  30742. get appliedImpulse() {
  30743. if (!this._feedbackEnabled) {
  30744. this._nativeConstraint.EnableFeedback(true);
  30745. this._feedbackEnabled = true;
  30746. }
  30747. return this._nativeConstraint.AppliedImpulse;
  30748. }
  30749. get connectedBody() {
  30750. return this._connectedBody;
  30751. }
  30752. set connectedBody(value) {
  30753. this._connectedBody = value;
  30754. }
  30755. _onDestroy() {
  30756. var physics3D = Physics3D._physics3D;
  30757. physics3D.destroy(this._nativeConstraint);
  30758. this._nativeConstraint = null;
  30759. }
  30760. }
  30761. class Point2PointConstraint {
  30762. constructor() {
  30763. this._pivotInA = new Vector3();
  30764. this._pivotInB = new Vector3();
  30765. }
  30766. get pivotInA() {
  30767. return this._pivotInA;
  30768. }
  30769. set pivotInA(value) {
  30770. this._pivotInA = value;
  30771. }
  30772. get pivotInB() {
  30773. return this._pivotInB;
  30774. }
  30775. set pivotInB(value) {
  30776. this._pivotInB = value;
  30777. }
  30778. get damping() {
  30779. return this._damping;
  30780. }
  30781. set damping(value) {
  30782. this._damping = value;
  30783. }
  30784. get impulseClamp() {
  30785. return this._impulseClamp;
  30786. }
  30787. set impulseClamp(value) {
  30788. this._impulseClamp = value;
  30789. }
  30790. get tau() {
  30791. return this._tau;
  30792. }
  30793. set tau(value) {
  30794. this._tau = value;
  30795. }
  30796. }
  30797. class HeightfieldColliderShape {
  30798. constructor() {
  30799. }
  30800. }
  30801. class TextMesh {
  30802. get text() {
  30803. return this._text;
  30804. }
  30805. set text(value) {
  30806. this._text = value;
  30807. }
  30808. get fontSize() {
  30809. return this._fontSize;
  30810. }
  30811. set fontSize(value) {
  30812. this._fontSize = value;
  30813. }
  30814. get color() {
  30815. return this._color;
  30816. }
  30817. set color(value) {
  30818. this._color = value;
  30819. }
  30820. constructor() {
  30821. }
  30822. _createVertexBuffer(charCount) {
  30823. }
  30824. _resizeVertexBuffer(charCount) {
  30825. }
  30826. _addChar() {
  30827. }
  30828. }
  30829. class Size {
  30830. constructor(width, height) {
  30831. this._width = 0;
  30832. this._height = 0;
  30833. this._width = width;
  30834. this._height = height;
  30835. }
  30836. static get fullScreen() {
  30837. return new Size(-1, -1);
  30838. }
  30839. get width() {
  30840. if (this._width === -1)
  30841. return RenderContext3D.clientWidth;
  30842. return this._width;
  30843. }
  30844. get height() {
  30845. if (this._height === -1)
  30846. return RenderContext3D.clientHeight;
  30847. return this._height;
  30848. }
  30849. }
  30850. exports.AnimationClip = AnimationClip;
  30851. exports.AnimationClipParser03 = AnimationClipParser03;
  30852. exports.AnimationClipParser04 = AnimationClipParser04;
  30853. exports.AnimationEvent = AnimationEvent;
  30854. exports.AnimationNode = AnimationNode;
  30855. exports.AnimationTransform3D = AnimationTransform3D;
  30856. exports.Animator = Animator;
  30857. exports.AnimatorControllerLayer = AnimatorControllerLayer;
  30858. exports.AnimatorPlayState = AnimatorPlayState;
  30859. exports.AnimatorState = AnimatorState;
  30860. exports.AnimatorStateScript = AnimatorStateScript;
  30861. exports.Avatar = Avatar;
  30862. exports.BaseCamera = BaseCamera;
  30863. exports.BaseMaterial = BaseMaterial;
  30864. exports.BaseRender = BaseRender;
  30865. exports.BaseShape = BaseShape;
  30866. exports.BatchMark = BatchMark;
  30867. exports.BlinnPhongMaterial = BlinnPhongMaterial;
  30868. exports.BlitScreenQuadCMD = BlitScreenQuadCMD;
  30869. exports.BloomEffect = BloomEffect;
  30870. exports.BoundBox = BoundBox;
  30871. exports.BoundFrustum = BoundFrustum;
  30872. exports.BoundSphere = BoundSphere;
  30873. exports.Bounds = Bounds;
  30874. exports.BoundsOctree = BoundsOctree;
  30875. exports.BoundsOctreeNode = BoundsOctreeNode;
  30876. exports.BoxColliderShape = BoxColliderShape;
  30877. exports.BoxShape = BoxShape;
  30878. exports.BufferState = BufferState;
  30879. exports.Burst = Burst;
  30880. exports.Camera = Camera;
  30881. exports.CapsuleColliderShape = CapsuleColliderShape;
  30882. exports.CastShadowList = CastShadowList;
  30883. exports.CharacterController = CharacterController;
  30884. exports.CircleShape = CircleShape;
  30885. exports.ColliderShape = ColliderShape;
  30886. exports.Collision = Collision;
  30887. exports.CollisionTool = CollisionTool;
  30888. exports.CollisionUtils = CollisionUtils;
  30889. exports.Color = Color;
  30890. exports.ColorOverLifetime = ColorOverLifetime;
  30891. exports.Command = Command;
  30892. exports.CommandBuffer = CommandBuffer;
  30893. exports.CompoundColliderShape = CompoundColliderShape;
  30894. exports.ConchQuaternion = ConchQuaternion;
  30895. exports.ConchVector3 = ConchVector3;
  30896. exports.ConchVector4 = ConchVector4;
  30897. exports.ConeColliderShape = ConeColliderShape;
  30898. exports.ConeShape = ConeShape;
  30899. exports.Config3D = Config3D;
  30900. exports.Constraint3D = Constraint3D;
  30901. exports.ConstraintComponent = ConstraintComponent;
  30902. exports.ContactPoint = ContactPoint;
  30903. exports.ContainmentType = ContainmentType;
  30904. exports.CylinderColliderShape = CylinderColliderShape;
  30905. exports.DefineDatas = DefineDatas;
  30906. exports.DirectionLight = DirectionLight;
  30907. exports.DynamicBatchManager = DynamicBatchManager;
  30908. exports.EffectMaterial = EffectMaterial;
  30909. exports.Emission = Emission;
  30910. exports.ExtendTerrainMaterial = ExtendTerrainMaterial;
  30911. exports.FloatKeyframe = FloatKeyframe;
  30912. exports.FrameOverTime = FrameOverTime;
  30913. exports.FrustumCulling = FrustumCulling;
  30914. exports.GeometryElement = GeometryElement;
  30915. exports.Gradient = Gradient;
  30916. exports.GradientAngularVelocity = GradientAngularVelocity;
  30917. exports.GradientColor = GradientColor;
  30918. exports.GradientDataInt = GradientDataInt;
  30919. exports.GradientDataNumber = GradientDataNumber;
  30920. exports.GradientDataVector2 = GradientDataVector2;
  30921. exports.GradientMode = GradientMode;
  30922. exports.GradientSize = GradientSize;
  30923. exports.GradientVelocity = GradientVelocity;
  30924. exports.HalfFloatUtils = HalfFloatUtils;
  30925. exports.HeightMap = HeightMap;
  30926. exports.HeightfieldColliderShape = HeightfieldColliderShape;
  30927. exports.HemisphereShape = HemisphereShape;
  30928. exports.HitResult = HitResult;
  30929. exports.ILaya3D = ILaya3D;
  30930. exports.IndexBuffer3D = IndexBuffer3D;
  30931. exports.Input3D = Input3D;
  30932. exports.Keyframe = Keyframe;
  30933. exports.KeyframeNode = KeyframeNode;
  30934. exports.KeyframeNodeList = KeyframeNodeList;
  30935. exports.KeyframeNodeOwner = KeyframeNodeOwner;
  30936. exports.Laya3D = Laya3D;
  30937. exports.LightSprite = LightSprite;
  30938. exports.LoadModelV04 = LoadModelV04;
  30939. exports.LoadModelV05 = LoadModelV05;
  30940. exports.MathUtils3D = MathUtils3D;
  30941. exports.Matrix3x3 = Matrix3x3;
  30942. exports.Matrix4x4 = Matrix4x4;
  30943. exports.Mesh = Mesh;
  30944. exports.MeshColliderShape = MeshColliderShape;
  30945. exports.MeshFilter = MeshFilter;
  30946. exports.MeshReader = MeshReader;
  30947. exports.MeshRenderDynamicBatchManager = MeshRenderDynamicBatchManager;
  30948. exports.MeshRenderStaticBatchManager = MeshRenderStaticBatchManager;
  30949. exports.MeshRenderer = MeshRenderer;
  30950. exports.MeshSprite3D = MeshSprite3D;
  30951. exports.MeshSprite3DShaderDeclaration = MeshSprite3DShaderDeclaration;
  30952. exports.MeshTerrainSprite3D = MeshTerrainSprite3D;
  30953. exports.MouseTouch = MouseTouch;
  30954. exports.OctreeMotionList = OctreeMotionList;
  30955. exports.PBRSpecularMaterial = PBRSpecularMaterial;
  30956. exports.PBRStandardMaterial = PBRStandardMaterial;
  30957. exports.ParallelSplitShadowMap = ParallelSplitShadowMap;
  30958. exports.Physics3D = Physics3D;
  30959. exports.Physics3DUtils = Physics3DUtils;
  30960. exports.PhysicsCollider = PhysicsCollider;
  30961. exports.PhysicsComponent = PhysicsComponent;
  30962. exports.PhysicsSettings = PhysicsSettings;
  30963. exports.PhysicsSimulation = PhysicsSimulation;
  30964. exports.PhysicsTriggerComponent = PhysicsTriggerComponent;
  30965. exports.PhysicsUpdateList = PhysicsUpdateList;
  30966. exports.Picker = Picker;
  30967. exports.PixelLineData = PixelLineData;
  30968. exports.PixelLineFilter = PixelLineFilter;
  30969. exports.PixelLineMaterial = PixelLineMaterial;
  30970. exports.PixelLineRenderer = PixelLineRenderer;
  30971. exports.PixelLineSprite3D = PixelLineSprite3D;
  30972. exports.PixelLineVertex = PixelLineVertex;
  30973. exports.Plane = Plane;
  30974. exports.Point2PointConstraint = Point2PointConstraint;
  30975. exports.PointLight = PointLight;
  30976. exports.PostProcess = PostProcess;
  30977. exports.PostProcessEffect = PostProcessEffect;
  30978. exports.PostProcessRenderContext = PostProcessRenderContext;
  30979. exports.PrimitiveMesh = PrimitiveMesh;
  30980. exports.Quaternion = Quaternion;
  30981. exports.QuaternionKeyframe = QuaternionKeyframe;
  30982. exports.Rand = Rand;
  30983. exports.RandX = RandX;
  30984. exports.Ray = Ray;
  30985. exports.RenderContext3D = RenderContext3D;
  30986. exports.RenderElement = RenderElement;
  30987. exports.RenderQueue = RenderQueue;
  30988. exports.RenderState = RenderState;
  30989. exports.RenderTexture = RenderTexture;
  30990. exports.RenderableSprite3D = RenderableSprite3D;
  30991. exports.Rigidbody3D = Rigidbody3D;
  30992. exports.RotationOverLifetime = RotationOverLifetime;
  30993. exports.Scene3D = Scene3D;
  30994. exports.Scene3DShaderDeclaration = Scene3DShaderDeclaration;
  30995. exports.Scene3DUtils = Scene3DUtils;
  30996. exports.SceneManager = SceneManager;
  30997. exports.ScreenQuad = ScreenQuad;
  30998. exports.ScreenTriangle = ScreenTriangle;
  30999. exports.Script3D = Script3D;
  31000. exports.SetRenderTargetCMD = SetRenderTargetCMD;
  31001. exports.SetShaderDataTextureCMD = SetShaderDataTextureCMD;
  31002. exports.Shader3D = Shader3D;
  31003. exports.ShaderData = ShaderData;
  31004. exports.ShaderDefines = ShaderDefines;
  31005. exports.ShaderInit3D = ShaderInit3D;
  31006. exports.ShaderInstance = ShaderInstance;
  31007. exports.ShaderPass = ShaderPass;
  31008. exports.ShaderVariable = ShaderVariable;
  31009. exports.ShapeUtils = ShapeUtils;
  31010. exports.ShuriKenParticle3D = ShuriKenParticle3D;
  31011. exports.ShuriKenParticle3DShaderDeclaration = ShuriKenParticle3DShaderDeclaration;
  31012. exports.ShurikenParticleData = ShurikenParticleData;
  31013. exports.ShurikenParticleMaterial = ShurikenParticleMaterial;
  31014. exports.ShurikenParticleRenderer = ShurikenParticleRenderer;
  31015. exports.ShurikenParticleSystem = ShurikenParticleSystem;
  31016. exports.SimpleSingletonList = SimpleSingletonList;
  31017. exports.SingletonList = SingletonList;
  31018. exports.Size = Size;
  31019. exports.SizeOverLifetime = SizeOverLifetime;
  31020. exports.SkinnedMeshRenderer = SkinnedMeshRenderer;
  31021. exports.SkinnedMeshSprite3D = SkinnedMeshSprite3D;
  31022. exports.SkinnedMeshSprite3DShaderDeclaration = SkinnedMeshSprite3DShaderDeclaration;
  31023. exports.SkyBox = SkyBox;
  31024. exports.SkyBoxMaterial = SkyBoxMaterial;
  31025. exports.SkyDome = SkyDome;
  31026. exports.SkyMesh = SkyMesh;
  31027. exports.SkyProceduralMaterial = SkyProceduralMaterial;
  31028. exports.SkyRenderer = SkyRenderer;
  31029. exports.SphereColliderShape = SphereColliderShape;
  31030. exports.SphereShape = SphereShape;
  31031. exports.SpotLight = SpotLight;
  31032. exports.Sprite3D = Sprite3D;
  31033. exports.StartFrame = StartFrame;
  31034. exports.StaticBatchManager = StaticBatchManager;
  31035. exports.StaticPlaneColliderShape = StaticPlaneColliderShape;
  31036. exports.SubMesh = SubMesh;
  31037. exports.SubMeshDynamicBatch = SubMeshDynamicBatch;
  31038. exports.SubMeshInstanceBatch = SubMeshInstanceBatch;
  31039. exports.SubMeshRenderElement = SubMeshRenderElement;
  31040. exports.SubMeshStaticBatch = SubMeshStaticBatch;
  31041. exports.SubShader = SubShader;
  31042. exports.TextMesh = TextMesh;
  31043. exports.TextureCube = TextureCube;
  31044. exports.TextureGenerator = TextureGenerator;
  31045. exports.TextureMode = TextureMode;
  31046. exports.TextureSheetAnimation = TextureSheetAnimation;
  31047. exports.Touch = Touch;
  31048. exports.TrailFilter = TrailFilter;
  31049. exports.TrailGeometry = TrailGeometry;
  31050. exports.TrailMaterial = TrailMaterial;
  31051. exports.TrailRenderer = TrailRenderer;
  31052. exports.TrailSprite3D = TrailSprite3D;
  31053. exports.Transform3D = Transform3D;
  31054. exports.UnlitMaterial = UnlitMaterial;
  31055. exports.Utils3D = Utils3D;
  31056. exports.Vector2 = Vector2;
  31057. exports.Vector3 = Vector3;
  31058. exports.Vector3Keyframe = Vector3Keyframe;
  31059. exports.Vector4 = Vector4;
  31060. exports.VelocityOverLifetime = VelocityOverLifetime;
  31061. exports.VertexBuffer3D = VertexBuffer3D;
  31062. exports.VertexDeclaration = VertexDeclaration;
  31063. exports.VertexElement = VertexElement;
  31064. exports.VertexElementFormat = VertexElementFormat;
  31065. exports.VertexMesh = VertexMesh;
  31066. exports.VertexPositionTerrain = VertexPositionTerrain;
  31067. exports.VertexPositionTexture0 = VertexPositionTexture0;
  31068. exports.VertexShuriKenParticle = VertexShuriKenParticle;
  31069. exports.VertexShurikenParticleBillboard = VertexShurikenParticleBillboard;
  31070. exports.VertexShurikenParticleMesh = VertexShurikenParticleMesh;
  31071. exports.VertexTrail = VertexTrail;
  31072. exports.Viewport = Viewport;
  31073. exports.WaterPrimaryMaterial = WaterPrimaryMaterial;
  31074. }(window.Laya = window.Laya|| {}, Laya));