123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694 |
- (function(window,document,Laya){
- var __un=Laya.un,__uns=Laya.uns,__static=Laya.static,__class=Laya.class,__getset=Laya.getset,__newvec=Laya.__newvec;
- var BaseTexture=laya.resource.BaseTexture,Browser=laya.utils.Browser,Buffer=laya.webgl.utils.Buffer;
- var BufferStateBase=laya.webgl.BufferStateBase,Byte=laya.utils.Byte,ClassUtils=laya.utils.ClassUtils,CommandEncoder=laya.layagl.CommandEncoder;
- var Component=laya.components.Component,Config=Laya.Config,Context=laya.resource.Context,Event=laya.events.Event;
- var EventDispatcher=laya.events.EventDispatcher,Handler=laya.utils.Handler,InlcudeFile=laya.webgl.utils.InlcudeFile;
- var LayaGL=laya.layagl.LayaGL,LayaGLRunner=laya.layagl.LayaGLRunner,Loader=laya.net.Loader,LoaderManager=laya.net.LoaderManager;
- var MathUtil=laya.maths.MathUtil,Node=laya.display.Node,Point=laya.maths.Point,Render=laya.renders.Render;
- var RenderTexture2D=laya.resource.RenderTexture2D,Resource=laya.resource.Resource,RunDriver=laya.utils.RunDriver;
- var Shader=laya.webgl.shader.Shader,ShaderCompile=laya.webgl.utils.ShaderCompile,ShaderNode=laya.webgl.utils.ShaderNode;
- var Sprite=laya.display.Sprite,Stat=laya.utils.Stat,Submit=laya.webgl.submit.Submit,SubmitKey=laya.webgl.submit.SubmitKey;
- var Texture2D=laya.resource.Texture2D,Timer=laya.utils.Timer,URL=laya.net.URL,WebGL=laya.webgl.WebGL,WebGLContext=laya.webgl.WebGLContext;
- Laya.interface('laya.d3.core.IClone');
- Laya.interface('laya.d3.graphics.IVertex');
- Laya.interface('laya.d3.core.scene.IOctreeObject');
- /**
- *<code>Quaternion</code> 类用于创建四元数。
- */
- //class laya.d3.math.Native.ConchQuaternion
- var ConchQuaternion=(function(){
- function ConchQuaternion(x,y,z,w,nativeElements){
- /**四元数元素数组*/
- //this.elements=null;
- (x===void 0)&& (x=0);
- (y===void 0)&& (y=0);
- (z===void 0)&& (z=0);
- (w===void 0)&& (w=1);
- var v;
- if (nativeElements){
- v=nativeElements;
- }else {
- v=new Float32Array(4);
- }
- v[0]=x;
- v[1]=y;
- v[2]=z;
- v[3]=w;
- this.elements=v;
- }
- __class(ConchQuaternion,'laya.d3.math.Native.ConchQuaternion');
- var __proto=ConchQuaternion.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *根据缩放值缩放四元数
- *@param scale 缩放值
- *@param out 输出四元数
- */
- __proto.scaling=function(scaling,out){
- var e=out.elements;
- var f=this.elements;
- e[0]=f[0] *scaling;
- e[1]=f[1] *scaling;
- e[2]=f[2] *scaling;
- e[3]=f[3] *scaling;
- }
- /**
- *归一化四元数
- *@param out 输出四元数
- */
- __proto.normalize=function(out){
- ConchQuaternion._normalizeArray(this.elements,out.elements);
- }
- /**
- *计算四元数的长度
- *@return 长度
- */
- __proto.length=function(){
- var f=this.elements;
- var x=f[0],y=f[1],z=f[2],w=f[3];
- return Math.sqrt(x *x+y *y+z *z+w *w);
- }
- /**
- *根据绕X轴的角度旋转四元数
- *@param rad 角度
- *@param out 输出四元数
- */
- __proto.rotateX=function(rad,out){
- var e=out.elements;
- var f=this.elements;
- rad *=0.5;
- var ax=f[0],ay=f[1],az=f[2],aw=f[3];
- var bx=Math.sin(rad),bw=Math.cos(rad);
- e[0]=ax *bw+aw *bx;
- e[1]=ay *bw+az *bx;
- e[2]=az *bw-ay *bx;
- e[3]=aw *bw-ax *bx;
- }
- /**
- *根据绕Y轴的制定角度旋转四元数
- *@param rad 角度
- *@param out 输出四元数
- */
- __proto.rotateY=function(rad,out){
- var e=out.elements;
- var f=this.elements;
- rad *=0.5;
- var ax=f[0],ay=f[1],az=f[2],aw=f[3],by=Math.sin(rad),bw=Math.cos(rad);
- e[0]=ax *bw-az *by;
- e[1]=ay *bw+aw *by;
- e[2]=az *bw+ax *by;
- e[3]=aw *bw-ay *by;
- }
- /**
- *根据绕Z轴的制定角度旋转四元数
- *@param rad 角度
- *@param out 输出四元数
- */
- __proto.rotateZ=function(rad,out){
- var e=out.elements;
- var f=this.elements;
- rad *=0.5;
- var ax=f[0],ay=f[1],az=f[2],aw=f[3],bz=Math.sin(rad),bw=Math.cos(rad);
- e[0]=ax *bw+ay *bz;
- e[1]=ay *bw-ax *bz;
- e[2]=az *bw+aw *bz;
- e[3]=aw *bw-az *bz;
- }
- /**
- *分解四元数到欧拉角(顺序为Yaw、Pitch、Roll),参考自http://xboxforums.create.msdn.com/forums/p/4574/23988.aspx#23988,问题绕X轴翻转超过±90度时有,会产生瞬间反转
- *@param quaternion 源四元数
- *@param out 欧拉角值
- */
- __proto.getYawPitchRoll=function(out){
- ConchVector3.transformQuat(ConchVector3.ForwardRH,this,ConchQuaternion.TEMPVector31);
- ConchVector3.transformQuat(ConchVector3.Up,this,ConchQuaternion.TEMPVector32);
- var upe=ConchQuaternion.TEMPVector32.elements;
- ConchQuaternion.angleTo(ConchVector3.ZERO,ConchQuaternion.TEMPVector31,ConchQuaternion.TEMPVector33);
- var anglee=ConchQuaternion.TEMPVector33.elements;
- if (anglee[0]==Math.PI / 2){
- anglee[1]=ConchQuaternion.arcTanAngle(upe[2],upe[0]);
- anglee[2]=0;
- }else if (anglee[0]==-Math.PI / 2){
- anglee[1]=ConchQuaternion.arcTanAngle(-upe[2],-upe[0]);
- anglee[2]=0;
- }else {
- Matrix4x4.createRotationY(-anglee[1],ConchQuaternion.TEMPMatrix0);
- Matrix4x4.createRotationX(-anglee[0],ConchQuaternion.TEMPMatrix1);
- ConchVector3.transformCoordinate(ConchQuaternion.TEMPVector32,ConchQuaternion.TEMPMatrix0,ConchQuaternion.TEMPVector32);
- ConchVector3.transformCoordinate(ConchQuaternion.TEMPVector32,ConchQuaternion.TEMPMatrix1,ConchQuaternion.TEMPVector32);
- anglee[2]=ConchQuaternion.arcTanAngle(upe[1],-upe[0]);
- }
- if (anglee[1] <=-Math.PI)
- anglee[1]=Math.PI;
- if (anglee[2] <=-Math.PI)
- anglee[2]=Math.PI;
- if (anglee[1] >=Math.PI && anglee[2] >=Math.PI){
- anglee[1]=0;
- anglee[2]=0;
- anglee[0]=Math.PI-anglee[0];
- };
- var oe=out.elements;
- oe[0]=anglee[1];
- oe[1]=anglee[0];
- oe[2]=anglee[2];
- }
- /**
- *求四元数的逆
- *@param out 输出四元数
- */
- __proto.invert=function(out){
- var e=out.elements;
- var f=this.elements;
- var a0=f[0],a1=f[1],a2=f[2],a3=f[3];
- var dot=a0 *a0+a1 *a1+a2 *a2+a3 *a3;
- var invDot=dot ? 1.0 / dot :0;
- e[0]=-a0 *invDot;
- e[1]=-a1 *invDot;
- e[2]=-a2 *invDot;
- e[3]=a3 *invDot;
- }
- /**
- *设置四元数为单位算数
- *@param out 输出四元数
- */
- __proto.identity=function(){
- var e=this.elements;
- e[0]=0;
- e[1]=0;
- e[2]=0;
- e[3]=1;
- }
- /**
- *从Array数组拷贝值。
- *@param array 数组。
- *@param offset 数组偏移。
- */
- __proto.fromArray=function(array,offset){
- (offset===void 0)&& (offset=0);
- this.elements[0]=array[offset+0];
- this.elements[1]=array[offset+1];
- this.elements[2]=array[offset+2];
- this.elements[3]=array[offset+3];
- }
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var i,s,d;
- s=this.elements;
- d=destObject.elements;
- if (s===d){
- return;
- }
- for (i=0;i < 4;++i){
- d[i]=s[i];
- }
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var dest=/*__JS__ */new this.constructor();
- this.cloneTo(dest);
- return dest;
- }
- __proto.equals=function(b){
- var ae=this.elements;
- var be=b.elements;
- 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]);
- }
- /**
- *计算长度的平方。
- *@return 长度的平方。
- */
- __proto.lengthSquared=function(){
- var x=this.elements[0];
- var y=this.elements[1];
- var z=this.elements[2];
- var w=this.elements[3];
- return (x *x)+(y *y)+(z *z)+(w *w);
- }
- /**
- *设置四元数的x值
- */
- /**
- *获取四元数的x值
- */
- __getset(0,__proto,'x',function(){
- return this.elements[0];
- },function(value){
- this.elements[0]=value;
- });
- /**
- *设置四元数的y值
- */
- /**
- *获取四元数的y值
- */
- __getset(0,__proto,'y',function(){
- return this.elements[1];
- },function(value){
- this.elements[1]=value;
- });
- /**
- *设置四元数的z值
- */
- /**
- *获取四元数的z值
- */
- __getset(0,__proto,'z',function(){
- return this.elements[2];
- },function(value){
- this.elements[2]=value;
- });
- /**
- *设置四元数的w值
- */
- /**
- *获取四元数的w值
- */
- __getset(0,__proto,'w',function(){
- return this.elements[3];
- },function(value){
- this.elements[3]=value;
- });
- ConchQuaternion._dotArray=function(l,r){
- return l[0] *r[0]+l[1] *r[1]+l[2] *r[2]+l[3] *r[3];
- }
- ConchQuaternion._normalizeArray=function(f,o){
- var x=f[0],y=f[1],z=f[2],w=f[3];
- var len=x *x+y *y+z *z+w *w;
- if (len > 0){
- len=1 / Math.sqrt(len);
- o[0]=x *len;
- o[1]=y *len;
- o[2]=z *len;
- o[3]=w *len;
- }
- }
- ConchQuaternion._lerpArray=function(l,r,amount,o){
- var inverse=1.0-amount;
- if (ConchQuaternion._dotArray(l,r)>=0){
- o[0]=(inverse *l[0])+(amount *r[0]);
- o[1]=(inverse *l[1])+(amount *r[1]);
- o[2]=(inverse *l[2])+(amount *r[2]);
- o[3]=(inverse *l[3])+(amount *r[3]);
- }else {
- o[0]=(inverse *l[0])-(amount *r[0]);
- o[1]=(inverse *l[1])-(amount *r[1]);
- o[2]=(inverse *l[2])-(amount *r[2]);
- o[3]=(inverse *l[3])-(amount *r[3]);
- }
- ConchQuaternion._normalizeArray(o,o);
- }
- ConchQuaternion.createFromYawPitchRoll=function(yaw,pitch,roll,out){
- var halfRoll=roll *0.5;
- var halfPitch=pitch *0.5;
- var halfYaw=yaw *0.5;
- var sinRoll=Math.sin(halfRoll);
- var cosRoll=Math.cos(halfRoll);
- var sinPitch=Math.sin(halfPitch);
- var cosPitch=Math.cos(halfPitch);
- var sinYaw=Math.sin(halfYaw);
- var cosYaw=Math.cos(halfYaw);
- var oe=out.elements;
- oe[0]=(cosYaw *sinPitch *cosRoll)+(sinYaw *cosPitch *sinRoll);
- oe[1]=(sinYaw *cosPitch *cosRoll)-(cosYaw *sinPitch *sinRoll);
- oe[2]=(cosYaw *cosPitch *sinRoll)-(sinYaw *sinPitch *cosRoll);
- oe[3]=(cosYaw *cosPitch *cosRoll)+(sinYaw *sinPitch *sinRoll);
- }
- ConchQuaternion.multiply=function(left,right,out){
- var le=left.elements;
- var re=right.elements;
- var oe=out.elements;
- var lx=le[0];
- var ly=le[1];
- var lz=le[2];
- var lw=le[3];
- var rx=re[0];
- var ry=re[1];
- var rz=re[2];
- var rw=re[3];
- var a=(ly *rz-lz *ry);
- var b=(lz *rx-lx *rz);
- var c=(lx *ry-ly *rx);
- var d=(lx *rx+ly *ry+lz *rz);
- oe[0]=(lx *rw+rx *lw)+a;
- oe[1]=(ly *rw+ry *lw)+b;
- oe[2]=(lz *rw+rz *lw)+c;
- oe[3]=lw *rw-d;
- }
- ConchQuaternion.arcTanAngle=function(x,y){
- if (x==0){
- if (y==1)
- return Math.PI / 2;
- return-Math.PI / 2;
- }
- if (x > 0)
- return Math.atan(y / x);
- if (x < 0){
- if (y > 0)
- return Math.atan(y / x)+Math.PI;
- return Math.atan(y / x)-Math.PI;
- }
- return 0;
- }
- ConchQuaternion.angleTo=function(from,location,angle){
- ConchVector3.subtract(location,from,ConchQuaternion.TEMPVector30);
- ConchVector3.normalize(ConchQuaternion.TEMPVector30,ConchQuaternion.TEMPVector30);
- angle.elements[0]=Math.asin(ConchQuaternion.TEMPVector30.y);
- angle.elements[1]=ConchQuaternion.arcTanAngle(-ConchQuaternion.TEMPVector30.z,-ConchQuaternion.TEMPVector30.x);
- }
- ConchQuaternion.createFromAxisAngle=function(axis,rad,out){
- var e=out.elements;
- var f=axis.elements;
- rad=rad *0.5;
- var s=Math.sin(rad);
- e[0]=s *f[0];
- e[1]=s *f[1];
- e[2]=s *f[2];
- e[3]=Math.cos(rad);
- }
- ConchQuaternion.createFromMatrix3x3=function(sou,out){
- var e=out.elements;
- var f=sou.elements;
- var fTrace=f[0]+f[4]+f[8];
- var fRoot;
- if (fTrace > 0.0){
- fRoot=Math.sqrt(fTrace+1.0);
- e[3]=0.5 *fRoot;
- fRoot=0.5 / fRoot;
- e[0]=(f[5]-f[7])*fRoot;
- e[1]=(f[6]-f[2])*fRoot;
- e[2]=(f[1]-f[3])*fRoot;
- }else {
- var i=0;
- if (f[4] > f[0])
- i=1;
- if (f[8] > f[i *3+i])
- i=2;
- var j=(i+1)% 3;
- var k=(i+2)% 3;
- fRoot=Math.sqrt(f[i *3+i]-f[j *3+j]-f[k *3+k]+1.0);
- e[i]=0.5 *fRoot;
- fRoot=0.5 / fRoot;
- e[3]=(f[j *3+k]-f[k *3+j])*fRoot;
- e[j]=(f[j *3+i]+f[i *3+j])*fRoot;
- e[k]=(f[k *3+i]+f[i *3+k])*fRoot;
- }
- return;
- }
- ConchQuaternion.createFromMatrix4x4=function(mat,out){
- var me=mat.elements;
- var oe=out.elements;
- var sqrt;
- var half;
- var scale=me[0]+me[5]+me[10];
- if (scale > 0.0){
- sqrt=Math.sqrt(scale+1.0);
- oe[3]=sqrt *0.5;
- sqrt=0.5 / sqrt;
- oe[0]=(me[6]-me[9])*sqrt;
- oe[1]=(me[8]-me[2])*sqrt;
- oe[2]=(me[1]-me[4])*sqrt;
- }else if ((me[0] >=me[5])&& (me[0] >=me[10])){
- sqrt=Math.sqrt(1.0+me[0]-me[5]-me[10]);
- half=0.5 / sqrt;
- oe[0]=0.5 *sqrt;
- oe[1]=(me[1]+me[4])*half;
- oe[2]=(me[2]+me[8])*half;
- oe[3]=(me[6]-me[9])*half;
- }else if (me[5] > me[10]){
- sqrt=Math.sqrt(1.0+me[5]-me[0]-me[10]);
- half=0.5 / sqrt;
- oe[0]=(me[4]+me[1])*half;
- oe[1]=0.5 *sqrt;
- oe[2]=(me[9]+me[6])*half;
- oe[3]=(me[8]-me[2])*half;
- }else {
- sqrt=Math.sqrt(1.0+me[10]-me[0]-me[5]);
- half=0.5 / sqrt;
- oe[0]=(me[8]+me[2])*half;
- oe[1]=(me[9]+me[6])*half;
- oe[2]=0.5 *sqrt;
- oe[3]=(me[1]-me[4])*half;
- }
- }
- ConchQuaternion.slerp=function(left,right,t,out){
- var a=left.elements;
- var b=right.elements;
- var oe=out.elements;
- 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];
- var omega,cosom,sinom,scale0,scale1;
- cosom=ax *bx+ay *by+az *bz+aw *bw;
- if (cosom < 0.0){
- cosom=-cosom;
- bx=-bx;
- by=-by;
- bz=-bz;
- bw=-bw;
- }
- if ((1.0-cosom)> 0.000001){
- omega=Math.acos(cosom);
- sinom=Math.sin(omega);
- scale0=Math.sin((1.0-t)*omega)/ sinom;
- scale1=Math.sin(t *omega)/ sinom;
- }else {
- scale0=1.0-t;
- scale1=t;
- }
- oe[0]=scale0 *ax+scale1 *bx;
- oe[1]=scale0 *ay+scale1 *by;
- oe[2]=scale0 *az+scale1 *bz;
- oe[3]=scale0 *aw+scale1 *bw;
- return oe;
- }
- ConchQuaternion.lerp=function(left,right,amount,out){
- ConchQuaternion._lerpArray(left.elements,right.elements,amount,out.elements);
- }
- ConchQuaternion.add=function(left,right,out){
- var e=out.elements;
- var f=left.elements;
- var g=right.elements;
- e[0]=f[0]+g[0];
- e[1]=f[1]+g[1];
- e[2]=f[2]+g[2];
- e[3]=f[3]+g[3];
- }
- ConchQuaternion.dot=function(left,right){
- return ConchQuaternion._dotArray(left.elements,right.elements);
- }
- ConchQuaternion.rotationLookAt=function(forward,up,out){
- ConchQuaternion.lookAt(ConchVector3.ZERO,forward,up,out);
- }
- ConchQuaternion.lookAt=function(eye,target,up,out){
- Matrix3x3.lookAt(eye,target,up,ConchQuaternion._tempMatrix3x3);
- ConchQuaternion.rotationMatrix(ConchQuaternion._tempMatrix3x3,out);
- }
- ConchQuaternion.invert=function(value,out){
- var vE=value.elements;
- var oE=out.elements;
- var lengthSq=value.lengthSquared();
- if (!MathUtils3D.isZero(lengthSq)){
- lengthSq=1.0 / lengthSq;
- oE[0]=-vE[0] *lengthSq;
- oE[1]=-vE[1] *lengthSq;
- oE[2]=-vE[2] *lengthSq;
- oE[3]=vE[3] *lengthSq;
- }
- }
- ConchQuaternion.rotationMatrix=function(matrix3x3,out){
- var me=matrix3x3.elements;
- var m11=me[0];
- var m12=me[1];
- var m13=me[2];
- var m21=me[3];
- var m22=me[4];
- var m23=me[5];
- var m31=me[6];
- var m32=me[7];
- var m33=me[8];
- var oe=out.elements;
- var sqrt=NaN,half=NaN;
- var scale=m11+m22+m33;
- if (scale > 0){
- sqrt=Math.sqrt(scale+1);
- oe[3]=sqrt *0.5;
- sqrt=0.5 / sqrt;
- oe[0]=(m23-m32)*sqrt;
- oe[1]=(m31-m13)*sqrt;
- oe[2]=(m12-m21)*sqrt;
- }else if ((m11 >=m22)&& (m11 >=m33)){
- sqrt=Math.sqrt(1+m11-m22-m33);
- half=0.5 / sqrt;
- oe[0]=0.5 *sqrt;
- oe[1]=(m12+m21)*half;
- oe[2]=(m13+m31)*half;
- oe[3]=(m23-m32)*half;
- }else if (m22 > m33){
- sqrt=Math.sqrt(1+m22-m11-m33);
- half=0.5 / sqrt;
- oe[0]=(m21+m12)*half;
- oe[1]=0.5 *sqrt;
- oe[2]=(m32+m23)*half;
- oe[3]=(m31-m13)*half;
- }else {
- sqrt=Math.sqrt(1+m33-m11-m22);
- half=0.5 / sqrt;
- oe[0]=(m31+m13)*half;
- oe[1]=(m32+m23)*half;
- oe[2]=0.5 *sqrt;
- oe[3]=(m12-m21)*half;
- }
- }
- ConchQuaternion.DEFAULT=new ConchQuaternion();
- __static(ConchQuaternion,
- ['TEMPVector30',function(){return this.TEMPVector30=new ConchVector3();},'TEMPVector31',function(){return this.TEMPVector31=new ConchVector3();},'TEMPVector32',function(){return this.TEMPVector32=new ConchVector3();},'TEMPVector33',function(){return this.TEMPVector33=new ConchVector3();},'TEMPMatrix0',function(){return this.TEMPMatrix0=new Matrix4x4();},'TEMPMatrix1',function(){return this.TEMPMatrix1=new Matrix4x4();},'_tempMatrix3x3',function(){return this._tempMatrix3x3=new Matrix3x3();},'NAN',function(){return this.NAN=new ConchQuaternion(NaN,NaN,NaN,NaN);}
- ]);
- return ConchQuaternion;
- })()
- /**
- *<code>Vector4</code> 类用于创建四维向量。
- */
- //class laya.d3.math.Native.ConchVector4
- var ConchVector4=(function(){
- function ConchVector4(x,y,z,w){
- /**[只读]向量元素集合。*/
- this.elements=null;
- (x===void 0)&& (x=0);
- (y===void 0)&& (y=0);
- (z===void 0)&& (z=0);
- (w===void 0)&& (w=0);
- var v=this.elements=new Float32Array(4);
- v[0]=x;
- v[1]=y;
- v[2]=z;
- v[3]=w;
- }
- __class(ConchVector4,'laya.d3.math.Native.ConchVector4');
- var __proto=ConchVector4.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *从Array数组拷贝值。
- *@param array 数组。
- *@param offset 数组偏移。
- */
- __proto.fromArray=function(array,offset){
- (offset===void 0)&& (offset=0);
- this.elements[0]=array[offset+0];
- this.elements[1]=array[offset+1];
- this.elements[2]=array[offset+2];
- this.elements[3]=array[offset+3];
- }
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var destVector4=destObject;
- var destE=destVector4.elements;
- var s=this.elements;
- destE[0]=s[0];
- destE[1]=s[1];
- destE[2]=s[2];
- destE[3]=s[3];
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var destVector4=/*__JS__ */new this.constructor();
- this.cloneTo(destVector4);
- return destVector4;
- }
- /**
- *求四维向量的长度。
- *@return 长度。
- */
- __proto.length=function(){
- return Math.sqrt(this.x *this.x+this.y *this.y+this.z *this.z+this.w *this.w);
- }
- /**
- *求四维向量长度的平方。
- *@return 长度的平方。
- */
- __proto.lengthSquared=function(){
- return this.x *this.x+this.y *this.y+this.z *this.z+this.w *this.w;
- }
- /**
- *设置X轴坐标。
- *@param value X轴坐标。
- */
- /**
- *获取X轴坐标。
- *@return X轴坐标。
- */
- __getset(0,__proto,'x',function(){
- return this.elements[0];
- },function(value){
- this.elements[0]=value;
- });
- /**
- *设置Y轴坐标。
- *@param value Y轴坐标。
- */
- /**
- *获取Y轴坐标。
- *@return Y轴坐标。
- */
- __getset(0,__proto,'y',function(){
- return this.elements[1];
- },function(value){
- this.elements[1]=value;
- });
- /**
- *设置Z轴坐标。
- *@param value Z轴坐标。
- */
- /**
- *获取Z轴坐标。
- *@return Z轴坐标。
- */
- __getset(0,__proto,'z',function(){
- return this.elements[2];
- },function(value){
- this.elements[2]=value;
- });
- /**
- *设置W轴坐标。
- *@param value W轴坐标。
- */
- /**
- *获取W轴坐标。
- *@return W轴坐标。
- */
- __getset(0,__proto,'w',function(){
- return this.elements[3];
- },function(value){
- this.elements[3]=value;
- });
- ConchVector4.lerp=function(a,b,t,out){
- var e=out.elements;
- var f=a.elements;
- var g=b.elements;
- var ax=f[0],ay=f[1],az=f[2],aw=f[3];
- e[0]=ax+t *(g[0]-ax);
- e[1]=ay+t *(g[1]-ay);
- e[2]=az+t *(g[2]-az);
- e[3]=aw+t *(g[3]-aw);
- }
- ConchVector4.transformByM4x4=function(vector4,m4x4,out){
- var ve=vector4.elements;
- var vx=ve[0];
- var vy=ve[1];
- var vz=ve[2];
- var vw=ve[3];
- var me=m4x4.elements;
- var oe=out.elements;
- oe[0]=vx *me[0]+vy *me[4]+vz *me[8]+vw *me[12];
- oe[1]=vx *me[1]+vy *me[5]+vz *me[9]+vw *me[13];
- oe[2]=vx *me[2]+vy *me[6]+vz *me[10]+vw *me[14];
- oe[3]=vx *me[3]+vy *me[7]+vz *me[11]+vw *me[15];
- }
- ConchVector4.equals=function(a,b){
- var ae=a.elements;
- var be=b.elements;
- 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]));
- }
- ConchVector4.normalize=function(s,out){
- var se=s.elements;
- var oe=out.elements;
- var len=/*if err,please use iflash.method.xmlLength()*/s.length();
- if (len > 0){
- oe[0]=se[0] *len;
- oe[1]=se[1] *len;
- oe[2]=se[2] *len;
- oe[3]=se[3] *len;
- }
- }
- ConchVector4.add=function(a,b,out){
- var oe=out.elements;
- var ae=a.elements;
- var be=b.elements;
- oe[0]=ae[0]+be[0];
- oe[1]=ae[1]+be[1];
- oe[2]=ae[2]+be[2];
- oe[3]=ae[3]+be[3];
- }
- ConchVector4.subtract=function(a,b,out){
- var oe=out.elements;
- var ae=a.elements;
- var be=b.elements;
- oe[0]=ae[0]-be[0];
- oe[1]=ae[1]-be[1];
- oe[2]=ae[2]-be[2];
- oe[3]=ae[3]-be[3];
- }
- ConchVector4.multiply=function(a,b,out){
- var oe=out.elements;
- var ae=a.elements;
- var be=b.elements;
- oe[0]=ae[0] *be[0];
- oe[1]=ae[1] *be[1];
- oe[2]=ae[2] *be[2];
- oe[3]=ae[3] *be[3];
- }
- ConchVector4.scale=function(a,b,out){
- var oe=out.elements;
- var ae=a.elements;
- oe[0]=ae[0] *b;
- oe[1]=ae[1] *b;
- oe[2]=ae[2] *b;
- oe[3]=ae[3] *b;
- }
- ConchVector4.Clamp=function(value,min,max,out){
- var valuee=value.elements;
- var x=valuee[0];
- var y=valuee[1];
- var z=valuee[2];
- var w=valuee[3];
- var mine=min.elements;
- var mineX=mine[0];
- var mineY=mine[1];
- var mineZ=mine[2];
- var mineW=mine[3];
- var maxe=max.elements;
- var maxeX=maxe[0];
- var maxeY=maxe[1];
- var maxeZ=maxe[2];
- var maxeW=maxe[3];
- var oute=out.elements;
- x=(x > maxeX)? maxeX :x;
- x=(x < mineX)? mineX :x;
- y=(y > maxeY)? maxeY :y;
- y=(y < mineY)? mineY :y;
- z=(z > maxeZ)? maxeZ :z;
- z=(z < mineZ)? mineZ :z;
- w=(w > maxeW)? maxeW :w;
- w=(w < mineW)? mineW :w;
- oute[0]=x;
- oute[1]=y;
- oute[2]=z;
- oute[3]=w;
- }
- ConchVector4.distanceSquared=function(value1,value2){
- var value1e=value1.elements;
- var value2e=value2.elements;
- var x=value1e[0]-value2e[0];
- var y=value1e[1]-value2e[1];
- var z=value1e[2]-value2e[2];
- var w=value1e[3]-value2e[3];
- return (x *x)+(y *y)+(z *z)+(w *w);
- }
- ConchVector4.distance=function(value1,value2){
- var value1e=value1.elements;
- var value2e=value2.elements;
- var x=value1e[0]-value2e[0];
- var y=value1e[1]-value2e[1];
- var z=value1e[2]-value2e[2];
- var w=value1e[3]-value2e[3];
- return Math.sqrt((x *x)+(y *y)+(z *z)+(w *w));
- }
- ConchVector4.dot=function(a,b){
- var ae=a.elements;
- var be=b.elements;
- var r=(ae[0] *be[0])+(ae[1] *be[1])+(ae[2] *be[2])+(ae[3] *be[3]);
- return r;
- }
- ConchVector4.min=function(a,b,out){
- var e=out.elements;
- var f=a.elements;
- var g=b.elements
- e[0]=Math.min(f[0],g[0]);
- e[1]=Math.min(f[1],g[1]);
- e[2]=Math.min(f[2],g[2]);
- e[3]=Math.min(f[3],g[3]);
- }
- ConchVector4.max=function(a,b,out){
- var e=out.elements;
- var f=a.elements;
- var g=b.elements
- e[0]=Math.max(f[0],g[0]);
- e[1]=Math.max(f[1],g[1]);
- e[2]=Math.max(f[2],g[2]);
- e[3]=Math.max(f[3],g[3]);
- }
- __static(ConchVector4,
- ['ZERO',function(){return this.ZERO=new ConchVector4();},'ONE',function(){return this.ONE=new ConchVector4(1.0,1.0,1.0,1.0);},'UnitX',function(){return this.UnitX=new ConchVector4(1.0,0.0,0.0,0.0);},'UnitY',function(){return this.UnitY=new ConchVector4(0.0,1.0,0.0,0.0);},'UnitZ',function(){return this.UnitZ=new ConchVector4(0.0,0.0,1.0,0.0);},'UnitW',function(){return this.UnitW=new ConchVector4(0.0,0.0,0.0,1.0);}
- ]);
- return ConchVector4;
- })()
- /**
- *<code>Vector3</code> 类用于创建三维向量。
- */
- //class laya.d3.math.Native.ConchVector3
- var ConchVector3=(function(){
- function ConchVector3(x,y,z,nativeElements){
- /**[只读]向量元素集合。*/
- this.elements=null;
- (x===void 0)&& (x=0);
- (y===void 0)&& (y=0);
- (z===void 0)&& (z=0);
- var v;
- if (nativeElements){
- v=nativeElements;
- }else {
- v=new Float32Array(3);
- }
- this.elements=v;
- v[0]=x;
- v[1]=y;
- v[2]=z;
- }
- __class(ConchVector3,'laya.d3.math.Native.ConchVector3');
- var __proto=ConchVector3.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *设置xyz值。
- *@param x X值。
- *@param y Y值。
- *@param z Z值。
- */
- __proto.setValue=function(x,y,z){
- this.elements[0]=x;
- this.elements[1]=y;
- this.elements[2]=z;
- }
- /**
- *从Array数组拷贝值。
- *@param array 数组。
- *@param offset 数组偏移。
- */
- __proto.fromArray=function(array,offset){
- (offset===void 0)&& (offset=0);
- this.elements[0]=array[offset+0];
- this.elements[1]=array[offset+1];
- this.elements[2]=array[offset+2];
- }
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var destVector3=destObject;
- var destE=destVector3.elements;
- var s=this.elements;
- destE[0]=s[0];
- destE[1]=s[1];
- destE[2]=s[2];
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var destVector3=/*__JS__ */new this.constructor();
- this.cloneTo(destVector3);
- return destVector3;
- }
- __proto.toDefault=function(){
- this.elements[0]=0;
- this.elements[1]=0;
- this.elements[2]=0;
- }
- /**
- *设置X轴坐标。
- *@param value X轴坐标。
- */
- /**
- *获取X轴坐标。
- *@return X轴坐标。
- */
- __getset(0,__proto,'x',function(){
- return this.elements[0];
- },function(value){
- this.elements[0]=value;
- });
- /**
- *设置Y轴坐标。
- *@param value Y轴坐标。
- */
- /**
- *获取Y轴坐标。
- *@return Y轴坐标。
- */
- __getset(0,__proto,'y',function(){
- return this.elements[1];
- },function(value){
- this.elements[1]=value;
- });
- /**
- *设置Z轴坐标。
- *@param value Z轴坐标。
- */
- /**
- *获取Z轴坐标。
- *@return Z轴坐标。
- */
- __getset(0,__proto,'z',function(){
- return this.elements[2];
- },function(value){
- this.elements[2]=value;
- });
- ConchVector3.distanceSquared=function(value1,value2){
- var value1e=value1.elements;
- var value2e=value2.elements;
- var x=value1e[0]-value2e[0];
- var y=value1e[1]-value2e[1];
- var z=value1e[2]-value2e[2];
- return (x *x)+(y *y)+(z *z);
- }
- ConchVector3.distance=function(value1,value2){
- var value1e=value1.elements;
- var value2e=value2.elements;
- var x=value1e[0]-value2e[0];
- var y=value1e[1]-value2e[1];
- var z=value1e[2]-value2e[2];
- return Math.sqrt((x *x)+(y *y)+(z *z));
- }
- ConchVector3.min=function(a,b,out){
- var e=out.elements;
- var f=a.elements;
- var g=b.elements
- e[0]=Math.min(f[0],g[0]);
- e[1]=Math.min(f[1],g[1]);
- e[2]=Math.min(f[2],g[2]);
- }
- ConchVector3.max=function(a,b,out){
- var e=out.elements;
- var f=a.elements;
- var g=b.elements
- e[0]=Math.max(f[0],g[0]);
- e[1]=Math.max(f[1],g[1]);
- e[2]=Math.max(f[2],g[2]);
- }
- ConchVector3.transformQuat=function(source,rotation,out){
- var destination=out.elements;
- var se=source.elements;
- var re=rotation.elements;
- 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;
- destination[0]=ix *qw+iw *-qx+iy *-qz-iz *-qy;
- destination[1]=iy *qw+iw *-qy+iz *-qx-ix *-qz;
- destination[2]=iz *qw+iw *-qz+ix *-qy-iy *-qx;
- }
- ConchVector3.scalarLength=function(a){
- var f=a.elements;
- var x=f[0],y=f[1],z=f[2];
- return Math.sqrt(x *x+y *y+z *z);
- }
- ConchVector3.scalarLengthSquared=function(a){
- var f=a.elements;
- var x=f[0],y=f[1],z=f[2];
- return x *x+y *y+z *z;
- }
- ConchVector3.normalize=function(s,out){
- var se=s.elements;
- var oe=out.elements;
- var x=se[0],y=se[1],z=se[2];
- var len=x *x+y *y+z *z;
- if (len > 0){
- len=1 / Math.sqrt(len);
- oe[0]=se[0] *len;
- oe[1]=se[1] *len;
- oe[2]=se[2] *len;
- }
- }
- ConchVector3.multiply=function(a,b,out){
- var e=out.elements;
- var f=a.elements;
- var g=b.elements
- e[0]=f[0] *g[0];
- e[1]=f[1] *g[1];
- e[2]=f[2] *g[2];
- }
- ConchVector3.scale=function(a,b,out){
- var e=out.elements;
- var f=a.elements;
- e[0]=f[0] *b;
- e[1]=f[1] *b;
- e[2]=f[2] *b;
- }
- ConchVector3.lerp=function(a,b,t,out){
- var e=out.elements;
- var f=a.elements;
- var g=b.elements;
- var ax=f[0],ay=f[1],az=f[2];
- e[0]=ax+t *(g[0]-ax);
- e[1]=ay+t *(g[1]-ay);
- e[2]=az+t *(g[2]-az);
- }
- ConchVector3.transformV3ToV3=function(vector,transform,result){
- var intermediate=ConchVector3._tempVector4;
- ConchVector3.transformV3ToV4(vector,transform,intermediate);
- var intermediateElem=intermediate.elements;
- var resultElem=result.elements;
- resultElem[0]=intermediateElem[0];
- resultElem[1]=intermediateElem[1];
- resultElem[2]=intermediateElem[2];
- }
- ConchVector3.transformV3ToV4=function(vector,transform,result){
- var vectorElem=vector.elements;
- var vectorX=vectorElem[0];
- var vectorY=vectorElem[1];
- var vectorZ=vectorElem[2];
- var transformElem=transform.elements;
- var resultElem=result.elements;
- resultElem[0]=(vectorX *transformElem[0])+(vectorY *transformElem[4])+(vectorZ *transformElem[8])+transformElem[12];
- resultElem[1]=(vectorX *transformElem[1])+(vectorY *transformElem[5])+(vectorZ *transformElem[9])+transformElem[13];
- resultElem[2]=(vectorX *transformElem[2])+(vectorY *transformElem[6])+(vectorZ *transformElem[10])+transformElem[14];
- resultElem[3]=(vectorX *transformElem[3])+(vectorY *transformElem[7])+(vectorZ *transformElem[11])+transformElem[15];
- }
- ConchVector3.TransformNormal=function(normal,transform,result){
- var normalElem=normal.elements;
- var normalX=normalElem[0];
- var normalY=normalElem[1];
- var normalZ=normalElem[2];
- var transformElem=transform.elements;
- var resultElem=result.elements;
- resultElem[0]=(normalX *transformElem[0])+(normalY *transformElem[4])+(normalZ *transformElem[8]);
- resultElem[1]=(normalX *transformElem[1])+(normalY *transformElem[5])+(normalZ *transformElem[9]);
- resultElem[2]=(normalX *transformElem[2])+(normalY *transformElem[6])+(normalZ *transformElem[10]);
- }
- ConchVector3.transformCoordinate=function(coordinate,transform,result){
- var coordinateElem=coordinate.elements;
- var coordinateX=coordinateElem[0];
- var coordinateY=coordinateElem[1];
- var coordinateZ=coordinateElem[2];
- var transformElem=transform.elements;
- var w=((coordinateX *transformElem[3])+(coordinateY *transformElem[7])+(coordinateZ *transformElem[11])+transformElem[15]);
- var resultElem=result.elements;
- resultElem[0]=(coordinateX *transformElem[0])+(coordinateY *transformElem[4])+(coordinateZ *transformElem[8])+transformElem[12] / w;
- resultElem[1]=(coordinateX *transformElem[1])+(coordinateY *transformElem[5])+(coordinateZ *transformElem[9])+transformElem[13] / w;
- resultElem[2]=(coordinateX *transformElem[2])+(coordinateY *transformElem[6])+(coordinateZ *transformElem[10])+transformElem[14] / w;
- }
- ConchVector3.Clamp=function(value,min,max,out){
- var valuee=value.elements;
- var x=valuee[0];
- var y=valuee[1];
- var z=valuee[2];
- var mine=min.elements;
- var mineX=mine[0];
- var mineY=mine[1];
- var mineZ=mine[2];
- var maxe=max.elements;
- var maxeX=maxe[0];
- var maxeY=maxe[1];
- var maxeZ=maxe[2];
- var oute=out.elements;
- x=(x > maxeX)? maxeX :x;
- x=(x < mineX)? mineX :x;
- y=(y > maxeY)? maxeY :y;
- y=(y < mineY)? mineY :y;
- z=(z > maxeZ)? maxeZ :z;
- z=(z < mineZ)? mineZ :z;
- oute[0]=x;
- oute[1]=y;
- oute[2]=z;
- }
- ConchVector3.add=function(a,b,out){
- var e=out.elements;
- var f=a.elements;
- var g=b.elements
- e[0]=f[0]+g[0];
- e[1]=f[1]+g[1];
- e[2]=f[2]+g[2];
- }
- ConchVector3.subtract=function(a,b,o){
- var oe=o.elements;
- var ae=a.elements;
- var be=b.elements;
- oe[0]=ae[0]-be[0];
- oe[1]=ae[1]-be[1];
- oe[2]=ae[2]-be[2];
- }
- ConchVector3.cross=function(a,b,o){
- var ae=a.elements;
- var be=b.elements;
- var oe=o.elements;
- var ax=ae[0],ay=ae[1],az=ae[2],bx=be[0],by=be[1],bz=be[2];
- oe[0]=ay *bz-az *by;
- oe[1]=az *bx-ax *bz;
- oe[2]=ax *by-ay *bx;
- }
- ConchVector3.dot=function(a,b){
- var ae=a.elements;
- var be=b.elements;
- var r=(ae[0] *be[0])+(ae[1] *be[1])+(ae[2] *be[2]);
- return r;
- }
- ConchVector3.equals=function(a,b){
- var ae=a.elements;
- var be=b.elements;
- return MathUtils3D.nearEqual(ae[0],be[0])&& MathUtils3D.nearEqual(ae[1],be[1])&& MathUtils3D.nearEqual(ae[2],be[2]);
- }
- ConchVector3.ZERO=new ConchVector3(0.0,0.0,0.0);
- ConchVector3.ONE=new ConchVector3(1.0,1.0,1.0);
- ConchVector3.NegativeUnitX=new ConchVector3(-1,0,0);
- ConchVector3.UnitX=new ConchVector3(1,0,0);
- ConchVector3.UnitY=new ConchVector3(0,1,0);
- ConchVector3.UnitZ=new ConchVector3(0,0,1);
- ConchVector3.ForwardRH=new ConchVector3(0,0,-1);
- ConchVector3.ForwardLH=new ConchVector3(0,0,1);
- ConchVector3.Up=new ConchVector3(0,1,0);
- ConchVector3.NAN=new ConchVector3(NaN,NaN,NaN);
- __static(ConchVector3,
- ['_tempVector4',function(){return this._tempVector4=new ConchVector4();}
- ]);
- return ConchVector3;
- })()
- /**
- *<code>ColorOverLifetime</code> 类用于粒子的生命周期颜色。
- */
- //class laya.d3.core.particleShuriKen.module.ColorOverLifetime
- var ColorOverLifetime=(function(){
- function ColorOverLifetime(color){
- /**@private */
- this._color=null;
- /**是否启用。*/
- this.enbale=false;
- this._color=color;
- }
- __class(ColorOverLifetime,'laya.d3.core.particleShuriKen.module.ColorOverLifetime');
- var __proto=ColorOverLifetime.prototype;
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var destColorOverLifetime=destObject;
- this._color.cloneTo(destColorOverLifetime._color);
- destColorOverLifetime.enbale=this.enbale;
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var destColor;
- switch (this._color.type){
- case 0:
- destColor=GradientColor.createByConstant(this._color.constant.clone());
- break ;
- case 1:
- destColor=GradientColor.createByGradient(this._color.gradient.clone());
- break ;
- case 2:
- destColor=GradientColor.createByRandomTwoConstant(this._color.constantMin.clone(),this._color.constantMax.clone());
- break ;
- case 3:
- destColor=GradientColor.createByRandomTwoGradient(this._color.gradientMin.clone(),this._color.gradientMax.clone());
- break ;
- };
- var destColorOverLifetime=/*__JS__ */new this.constructor(destColor);
- destColorOverLifetime.enbale=this.enbale;
- return destColorOverLifetime;
- }
- /**
- *获取颜色。
- */
- __getset(0,__proto,'color',function(){
- return this._color;
- });
- return ColorOverLifetime;
- })()
- /**
- *<code>BaseShape</code> 类用于粒子形状。
- */
- //class laya.d3.core.particleShuriKen.module.shape.BaseShape
- var BaseShape=(function(){
- function BaseShape(){
- /**是否启用。*/
- this.enable=false;
- /**随机方向。*/
- this.randomDirection=false;
- }
- __class(BaseShape,'laya.d3.core.particleShuriKen.module.shape.BaseShape');
- var __proto=BaseShape.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**@private */
- __proto._getShapeBoundBox=function(boundBox){
- throw new Error("BaseShape: must override it.");
- }
- /**@private */
- __proto._getSpeedBoundBox=function(boundBox){
- throw new Error("BaseShape: must override it.");
- }
- /**
- *用于生成粒子初始位置和方向。
- *@param position 粒子位置。
- *@param direction 粒子方向。
- */
- __proto.generatePositionAndDirection=function(position,direction,rand,randomSeeds){
- throw new Error("BaseShape: must override it.");
- }
- /**
- *@private
- */
- __proto._calculateProceduralBounds=function(boundBox,emitterPosScale,minMaxBounds){
- this._getShapeBoundBox(boundBox);
- var min=boundBox.min;
- var max=boundBox.max;
- Vector3.multiply(min,emitterPosScale,min);
- Vector3.multiply(max,emitterPosScale,max);
- var speedBounds=new BoundBox(new Vector3(),new Vector3());
- if (this.randomDirection){
- speedBounds.min=new Vector3(-1,-1,-1);
- speedBounds.max=new Vector3(1,1,1);
- }
- else{
- this._getSpeedBoundBox(speedBounds);
- };
- var maxSpeedBound=new BoundBox(new Vector3(),new Vector3());
- var maxSpeedMin=maxSpeedBound.min;
- var maxSpeedMax=maxSpeedBound.max;
- Vector3.scale(speedBounds.min,minMaxBounds.y,maxSpeedMin);
- Vector3.scale(speedBounds.max,minMaxBounds.y,maxSpeedMax);
- Vector3.add(boundBox.min,maxSpeedMin,maxSpeedMin);
- Vector3.add(boundBox.max,maxSpeedMax,maxSpeedMax);
- Vector3.min(boundBox.min,maxSpeedMin,boundBox.min);
- Vector3.max(boundBox.max,maxSpeedMin,boundBox.max);
- var minSpeedBound=new BoundBox(new Vector3(),new Vector3());
- var minSpeedMin=minSpeedBound.min;
- var minSpeedMax=minSpeedBound.max;
- Vector3.scale(speedBounds.min,minMaxBounds.x,minSpeedMin);
- Vector3.scale(speedBounds.max,minMaxBounds.x,minSpeedMax);
- Vector3.min(minSpeedBound.min,minSpeedMax,maxSpeedMin);
- Vector3.max(minSpeedBound.min,minSpeedMax,maxSpeedMax);
- Vector3.min(boundBox.min,maxSpeedMin,boundBox.min);
- Vector3.max(boundBox.max,maxSpeedMin,boundBox.max);
- }
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var destShape=destObject;
- destShape.enable=this.enable;
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var destShape=/*__JS__ */new this.constructor();
- this.cloneTo(destShape);
- return destShape;
- }
- return BaseShape;
- })()
- /**
- *<code>ColliderShape</code> 类用于创建形状碰撞器的父类,该类为抽象类。
- */
- //class laya.d3.physics.shape.ColliderShape
- var ColliderShape=(function(){
- function ColliderShape(){
- /**@private */
- //this._nativeShape=null;
- /**@private */
- //this._type=0;
- /**@private */
- this._attatched=false;
- /**@private */
- this._indexInCompound=-1;
- /**@private */
- this._compoundParent=null;
- /**@private */
- this._attatchedCollisionObject=null;
- /**@private */
- this._referenceCount=0;
- this.needsCustomCollisionCallback=false;
- this._scale=new Vector3(1,1,1);
- this._centerMatrix=new Matrix4x4();
- this._localOffset=new Vector3(0,0,0);
- this._localRotation=new Quaternion(0,0,0,1);
- }
- __class(ColliderShape,'laya.d3.physics.shape.ColliderShape');
- var __proto=ColliderShape.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *@private
- */
- __proto._setScale=function(value){
- if (this._compoundParent){
- this.updateLocalTransformations();
- }else {
- ColliderShape._nativeScale.setValue(value.x,value.y,value.z);
- this._nativeShape.setLocalScaling(ColliderShape._nativeScale);
- }
- }
- /**
- *@private
- */
- __proto._addReference=function(){
- this._referenceCount++;
- }
- /**
- *@private
- */
- __proto._removeReference=function(){
- this._referenceCount--;
- }
- /**
- *更新本地偏移,如果修改LocalOffset或LocalRotation需要调用。
- */
- __proto.updateLocalTransformations=function(){
- if (this._compoundParent){
- var offset=ColliderShape._tempVector30;
- Vector3.multiply(this.localOffset,this._scale,offset);
- ColliderShape._createAffineTransformation(offset,this.localRotation,this._centerMatrix.elements);
- }else {
- ColliderShape._createAffineTransformation(this.localOffset,this.localRotation,this._centerMatrix.elements);
- }
- }
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var destColliderShape=destObject;
- this._localOffset.cloneTo(destColliderShape.localOffset);
- this._localRotation.cloneTo(destColliderShape.localRotation);
- destColliderShape.localOffset=destColliderShape.localOffset;
- destColliderShape.localRotation=destColliderShape.localRotation;
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- return null;
- }
- /**
- *@private
- */
- __proto.destroy=function(){
- if (this._nativeShape){
- Laya3D._physics3D.destroy(this._nativeShape);
- this._nativeShape=null;
- }
- }
- /**
- *获取碰撞类型。
- *@return 碰撞类型。
- */
- __getset(0,__proto,'type',function(){
- return this._type;
- });
- /**
- *设置Shape的本地偏移。
- *@param Shape的本地偏移。
- */
- /**
- *获取Shape的本地偏移。
- *@return Shape的本地偏移。
- */
- __getset(0,__proto,'localOffset',function(){
- return this._localOffset;
- },function(value){
- this._localOffset=value;
- if (this._compoundParent)
- this._compoundParent._updateChildTransform(this);
- });
- /**
- *设置Shape的本地旋转。
- *@param Shape的本地旋转。
- */
- /**
- *获取Shape的本地旋转。
- *@return Shape的本地旋转。
- */
- __getset(0,__proto,'localRotation',function(){
- return this._localRotation;
- },function(value){
- this._localRotation=value;
- if (this._compoundParent)
- this._compoundParent._updateChildTransform(this);
- });
- ColliderShape._creatShape=function(shapeData){
- var colliderShape;
- switch (shapeData.type){
- case "BoxColliderShape":;
- var sizeData=shapeData.size;
- colliderShape=sizeData ? new BoxColliderShape(sizeData[0],sizeData[1],sizeData[2]):new BoxColliderShape();
- break ;
- case "SphereColliderShape":
- colliderShape=new SphereColliderShape(shapeData.radius);
- break ;
- case "CapsuleColliderShape":
- colliderShape=new CapsuleColliderShape(shapeData.radius,shapeData.height,shapeData.orientation);
- break ;
- case "MeshColliderShape":;
- var meshCollider=new MeshColliderShape();
- shapeData.mesh && (meshCollider.mesh=Loader.getRes(shapeData.mesh));
- colliderShape=meshCollider;
- break ;
- case "ConeColliderShape":
- colliderShape=new ConeColliderShape(shapeData.radius,shapeData.height,shapeData.orientation);
- break ;
- case "CylinderColliderShape":
- colliderShape=new CylinderColliderShape(shapeData.radius,shapeData.height,shapeData.orientation);
- break ;
- default :
- throw "unknown shape type.";
- }
- if (shapeData.center){
- var localOffset=colliderShape.localOffset;
- localOffset.fromArray(shapeData.center);
- colliderShape.localOffset=localOffset;
- }
- return colliderShape;
- }
- ColliderShape._createAffineTransformation=function(trans,rot,outE){
- var x=rot.x,y=rot.y,z=rot.z,w=rot.w,x2=x+x,y2=y+y,z2=z+z;
- var xx=x *x2,xy=x *y2,xz=x *z2,yy=y *y2,yz=y *z2,zz=z *z2;
- var wx=w *x2,wy=w *y2,wz=w *z2;
- outE[0]=(1-(yy+zz));
- outE[1]=(xy+wz);
- outE[2]=(xz-wy);
- outE[3]=0;
- outE[4]=(xy-wz);
- outE[5]=(1-(xx+zz));
- outE[6]=(yz+wx);
- outE[7]=0;
- outE[8]=(xz+wy);
- outE[9]=(yz-wx);
- outE[10]=(1-(xx+yy));
- outE[11]=0;
- outE[12]=trans.x;
- outE[13]=trans.y;
- outE[14]=trans.z;
- outE[15]=1;
- }
- ColliderShape.SHAPEORIENTATION_UPX=0;
- ColliderShape.SHAPEORIENTATION_UPY=1;
- ColliderShape.SHAPEORIENTATION_UPZ=2;
- ColliderShape.SHAPETYPES_BOX=0;
- ColliderShape.SHAPETYPES_SPHERE=1;
- ColliderShape.SHAPETYPES_CYLINDER=2;
- ColliderShape.SHAPETYPES_CAPSULE=3;
- ColliderShape.SHAPETYPES_CONVEXHULL=4;
- ColliderShape.SHAPETYPES_COMPOUND=5;
- ColliderShape.SHAPETYPES_STATICPLANE=6;
- ColliderShape.SHAPETYPES_CONE=7;
- __static(ColliderShape,
- ['_tempVector30',function(){return this._tempVector30=new Vector3();},'_nativeScale',function(){return this._nativeScale=new Laya3D._physics3D.btVector3(1,1,1);},'_nativeVector30',function(){return this._nativeVector30=new Laya3D._physics3D.btVector3(0,0,0);},'_nativQuaternion0',function(){return this._nativQuaternion0=new Laya3D._physics3D.btQuaternion(0,0,0,1);},'_nativeTransform0',function(){return this._nativeTransform0=new Laya3D._physics3D.btTransform();}
- ]);
- return ColliderShape;
- })()
- /**
- *<code>Laya3D</code> 类用于初始化3D设置。
- */
- //class Laya3D
- var Laya3D=(function(){
- /**
- *创建一个 <code>Laya3D</code> 实例。
- */
- function Laya3D(){}
- __class(Laya3D,'Laya3D');
- /**
- *获取是否可以启用物理。
- *@param 是否启用物理。
- */
- __getset(1,Laya3D,'enbalePhysics',function(){
- return Laya3D._enbalePhysics;
- });
- Laya3D._cancelLoadByUrl=function(url){
- Laya.loader.cancelLoadByUrl(url);
- Laya3D._innerFirstLevelLoaderManager.cancelLoadByUrl(url);
- Laya3D._innerSecondLevelLoaderManager.cancelLoadByUrl(url);
- Laya3D._innerThirdLevelLoaderManager.cancelLoadByUrl(url);
- Laya3D._innerFourthLevelLoaderManager.cancelLoadByUrl(url);
- }
- Laya3D._changeWebGLSize=function(width,height){
- WebGL.onStageResize(width,height);
- RenderContext3D.clientWidth=width;
- RenderContext3D.clientHeight=height;
- }
- Laya3D.__init__=function(width,height,config){
- Config.isAntialias=config.isAntialias;
- Config.isAlpha=config.isAlpha;
- Config.premultipliedAlpha=config.premultipliedAlpha;
- Config.isStencil=config.isStencil;
- if (!WebGL.enable()){
- alert("Laya3D init error,must support webGL!");
- return;
- }
- RunDriver.changeWebGLSize=Laya3D._changeWebGLSize;
- Render.is3DMode=true;
- Laya.init(width,height);
- if (!Render.supportWebGLPlusRendering){
- LayaGL.instance=WebGL.mainContext;
- LayaGL.instance.createCommandEncoder=function (reserveSize,adjustSize,isSyncToRenderThread){
- (reserveSize===void 0)&& (reserveSize=128);
- (adjustSize===void 0)&& (adjustSize=64);
- (isSyncToRenderThread===void 0)&& (isSyncToRenderThread=false);
- return new CommandEncoder(this,reserveSize,adjustSize,isSyncToRenderThread);
- }
- }
- Laya3D.enableNative3D();
- Sprite3D.__init__();
- RenderableSprite3D.__init__();
- MeshSprite3D.__init__();
- SkinnedMeshSprite3D.__init__();
- ShuriKenParticle3D.__init__();
- BaseMaterial.__init__();
- BlinnPhongMaterial.__init__();
- PBRStandardMaterial.__init__();
- PBRSpecularMaterial.__init__();
- SkyProceduralMaterial.__init__();
- UnlitMaterial.__init__();
- TrailSprite3D.__init__();
- TrailMaterial.__init__();
- EffectMaterial.__init__();
- WaterPrimaryMaterial.__init__();
- ShurikenParticleMaterial.__init__();
- TerrainMaterial.__init__();
- ExtendTerrainMaterial.__init__();
- ShaderInit3D.__init__();
- PixelLineMaterial.defaultMaterial.lock=true;
- BlinnPhongMaterial.defaultMaterial.lock=true;
- EffectMaterial.defaultMaterial.lock=true;
- PBRStandardMaterial.defaultMaterial.lock=true;
- PBRSpecularMaterial.defaultMaterial.lock=true;
- UnlitMaterial.defaultMaterial.lock=true;
- ShurikenParticleMaterial.defaultMaterial.lock=true;
- TrailMaterial.defaultMaterial.lock=true;
- SkyProceduralMaterial.defaultMaterial.lock=true;
- SkyBoxMaterial.defaultMaterial.lock=true;
- WaterPrimaryMaterial.defaultMaterial.lock=true;
- Texture2D.__init__();
- TextureCube.__init__();
- SkyBox.__init__();
- SkyDome.__init__();
- ScreenQuad.__init__();
- PostProcess.__init__();
- FrustumCulling.__init__();
- HalfFloatUtils.__init__();
- var createMap=LoaderManager.createMap;
- createMap["lh"]=[ /*CLASS CONST:Laya3D.HIERARCHY*/"HIERARCHY",Sprite3D._parse];
- createMap["ls"]=[ /*CLASS CONST:Laya3D.HIERARCHY*/"HIERARCHY",Scene3D._parse];
- createMap["lm"]=[ /*CLASS CONST:Laya3D.MESH*/"MESH",Mesh._parse];
- createMap["lmat"]=[ /*CLASS CONST:Laya3D.MATERIAL*/"MATERIAL",BaseMaterial._parse];
- createMap["ltc"]=[ /*CLASS CONST:Laya3D.TEXTURECUBE*/"TEXTURECUBE",TextureCube._parse];
- createMap["jpg"]=[ /*CLASS CONST:Laya3D.TEXTURE2D*/"TEXTURE2D",Texture2D._parse];
- createMap["jpeg"]=[ /*CLASS CONST:Laya3D.TEXTURE2D*/"TEXTURE2D",Texture2D._parse];
- createMap["bmp"]=[ /*CLASS CONST:Laya3D.TEXTURE2D*/"TEXTURE2D",Texture2D._parse];
- createMap["gif"]=[ /*CLASS CONST:Laya3D.TEXTURE2D*/"TEXTURE2D",Texture2D._parse];
- createMap["png"]=[ /*CLASS CONST:Laya3D.TEXTURE2D*/"TEXTURE2D",Texture2D._parse];
- createMap["dds"]=[ /*CLASS CONST:Laya3D.TEXTURE2D*/"TEXTURE2D",Texture2D._parse];
- createMap["ktx"]=[ /*CLASS CONST:Laya3D.TEXTURE2D*/"TEXTURE2D",Texture2D._parse];
- createMap["pvr"]=[ /*CLASS CONST:Laya3D.TEXTURE2D*/"TEXTURE2D",Texture2D._parse];
- createMap["lani"]=[ /*CLASS CONST:Laya3D.ANIMATIONCLIP*/"ANIMATIONCLIP",AnimationClip._parse];
- createMap["lav"]=[ /*CLASS CONST:Laya3D.AVATAR*/"AVATAR",Avatar._parse];
- createMap["thdata"]=[ /*CLASS CONST:Laya3D.TERRAINHEIGHTDATA*/"TERRAINHEIGHTDATA",TerrainHeightData._pharse];
- var parserMap=Loader.parserMap;
- parserMap[ /*CLASS CONST:Laya3D.HIERARCHY*/"HIERARCHY"]=Laya3D._loadHierarchy;
- parserMap[ /*CLASS CONST:Laya3D.MESH*/"MESH"]=Laya3D._loadMesh;
- parserMap[ /*CLASS CONST:Laya3D.MATERIAL*/"MATERIAL"]=Laya3D._loadMaterial;
- parserMap[ /*CLASS CONST:Laya3D.TEXTURECUBE*/"TEXTURECUBE"]=Laya3D._loadTextureCube;
- parserMap[ /*CLASS CONST:Laya3D.TEXTURE2D*/"TEXTURE2D"]=Laya3D._loadTexture2D;
- parserMap[ /*CLASS CONST:Laya3D.ANIMATIONCLIP*/"ANIMATIONCLIP"]=Laya3D._loadAnimationClip;
- parserMap[ /*CLASS CONST:Laya3D.AVATAR*/"AVATAR"]=Laya3D._loadAvatar;
- Laya3D._innerFirstLevelLoaderManager.on(/*laya.events.Event.ERROR*/"error",null,Laya3D._eventLoadManagerError);
- Laya3D._innerSecondLevelLoaderManager.on(/*laya.events.Event.ERROR*/"error",null,Laya3D._eventLoadManagerError);
- Laya3D._innerThirdLevelLoaderManager.on(/*laya.events.Event.ERROR*/"error",null,Laya3D._eventLoadManagerError);
- Laya3D._innerFourthLevelLoaderManager.on(/*laya.events.Event.ERROR*/"error",null,Laya3D._eventLoadManagerError);
- }
- Laya3D.enableNative3D=function(){
- if (Render.isConchApp){
- /*__JS__ */LayaGL=window.LayaGLContext;
- var shaderData=ShaderData;
- var shader3D=ShaderInstance;
- var skinnedMeshRender=SkinnedMeshRenderer;
- var avatar=Avatar;
- var frustumCulling=FrustumCulling;
- var meshRender=MeshRenderer;
- if (Render.supportWebGLPlusRendering){
- shaderData.prototype._initData=shaderData.prototype._initDataForNative;
- shaderData.prototype.setBool=shaderData.prototype.setBoolForNative;
- shaderData.prototype.getBool=shaderData.prototype.getBoolForNative;
- shaderData.prototype.setInt=shaderData.prototype.setIntForNative;
- shaderData.prototype.getInt=shaderData.prototype.getIntForNative;
- shaderData.prototype.setNumber=shaderData.prototype.setNumberForNative;
- shaderData.prototype.getNumber=shaderData.prototype.getNumberForNative;
- shaderData.prototype.setVector=shaderData.prototype.setVectorForNative;
- shaderData.prototype.getVector=shaderData.prototype.getVectorForNative;
- shaderData.prototype.setVector2=shaderData.prototype.setVector2ForNative;
- shaderData.prototype.getVector2=shaderData.prototype.getVector2ForNative;
- shaderData.prototype.setVector3=shaderData.prototype.setVector3ForNative;
- shaderData.prototype.getVector3=shaderData.prototype.getVector3ForNative;
- shaderData.prototype.setQuaternion=shaderData.prototype.setQuaternionForNative;
- shaderData.prototype.getQuaternion=shaderData.prototype.getQuaternionForNative;
- shaderData.prototype.setMatrix4x4=shaderData.prototype.setMatrix4x4ForNative;
- shaderData.prototype.getMatrix4x4=shaderData.prototype.getMatrix4x4ForNative;
- shaderData.prototype.setBuffer=shaderData.prototype.setBufferForNative;
- shaderData.prototype.getBuffer=shaderData.prototype.getBufferForNative;
- shaderData.prototype.setTexture=shaderData.prototype.setTextureForNative;
- shaderData.prototype.getTexture=shaderData.prototype.getTextureForNative;
- shaderData.prototype.setAttribute=shaderData.prototype.setAttributeForNative;
- shaderData.prototype.getAttribute=shaderData.prototype.getAttributeForNative;
- shaderData.prototype.cloneTo=shaderData.prototype.cloneToForNative;
- shaderData.prototype.getData=shaderData.prototype.getDataForNative;
- shader3D.prototype._uniformMatrix2fv=shader3D.prototype._uniformMatrix2fvForNative;
- shader3D.prototype._uniformMatrix3fv=shader3D.prototype._uniformMatrix3fvForNative;
- shader3D.prototype._uniformMatrix4fv=shader3D.prototype._uniformMatrix4fvForNative;
- meshRender.prototype._renderUpdateWithCamera=meshRender.prototype._renderUpdateWithCameraForNative;
- }
- if (Render.supportWebGLPlusCulling){
- frustumCulling.renderObjectCulling=FrustumCulling.renderObjectCullingNative;
- }
- if (Render.supportWebGLPlusAnimation){
- avatar.prototype._cloneDatasToAnimator=avatar.prototype._cloneDatasToAnimatorNative;
- /*__JS__ */FloatKeyframe=window.conchFloatKeyframe;
- /*__JS__ */Vector3Keyframe=window.conchFloatArrayKeyframe;
- /*__JS__ */QuaternionKeyframe=window.conchFloatArrayKeyframe;
- /*__JS__ */KeyframeNode=window.conchKeyframeNode;
- /*__JS__ */KeyframeNodeList=window.conchKeyframeNodeList;
- var animationClip=AnimationClip;
- animationClip.prototype._evaluateClipDatasRealTime=animationClip.prototype._evaluateClipDatasRealTimeForNative;
- }
- }
- WebGL.shaderHighPrecision=false;
- var precisionFormat=LayaGL.instance.getShaderPrecisionFormat(/*laya.webgl.WebGLContext.FRAGMENT_SHADER*/0x8B30,/*laya.webgl.WebGLContext.HIGH_FLOAT*/0x8DF2);
- precisionFormat.precision ? WebGL.shaderHighPrecision=true :WebGL.shaderHighPrecision=false;
- }
- Laya3D.formatRelativePath=function(base,value){
- var path;
- path=base+value;
- var char1=value.charAt(0);
- if (char1==="."){
- var parts=path.split("/");
- for (var i=0,len=parts.length;i < len;i++){
- if (parts[i]=='..'){
- var index=i-1;
- if (index > 0 && parts[index]!=='..'){
- parts.splice(index,2);
- i-=2;
- }
- }
- }
- path=parts.join('/');
- }
- return path;
- }
- Laya3D._endLoad=function(loader,content,subResous){
- if (subResous){
- for (var i=0,n=subResous.length;i < n;i++){
- var resou=Loader.getRes(subResous[i]);
- (resou)&& (resou._removeReference());
- }
- }
- loader.endLoad(content);
- }
- Laya3D._eventLoadManagerError=function(msg){
- Laya.loader.event(/*laya.events.Event.ERROR*/"error",msg);
- }
- Laya3D._addHierarchyInnerUrls=function(urls,urlMap,urlVersion,hierarchyBasePath,path,type,constructParams,propertyParams){
- var formatUrl=Laya3D.formatRelativePath(hierarchyBasePath,path);
- (urlVersion)&& (formatUrl=formatUrl+urlVersion);
- urls.push({url:formatUrl,type:type,constructParams:constructParams,propertyParams:propertyParams});
- urlMap.push(formatUrl);
- return formatUrl;
- }
- Laya3D._getSprite3DHierarchyInnerUrls=function(node,firstLevelUrls,secondLevelUrls,thirdLevelUrls,fourthLelUrls,subUrls,urlVersion,hierarchyBasePath){
- var i=0,n=0;
- var props=node.props;
- switch (node.type){
- case "Scene3D":;
- var lightmaps=props.lightmaps;
- for (i=0,n=lightmaps.length;i < n;i++){
- var lightMap=lightmaps[i];
- lightMap.path=Laya3D._addHierarchyInnerUrls(fourthLelUrls,subUrls,urlVersion,hierarchyBasePath,lightMap.path,/*CLASS CONST:Laya3D.TEXTURE2D*/"TEXTURE2D",lightMap.constructParams,lightMap.propertyParams);
- };
- var reflectionTextureData=props.reflectionTexture;
- (reflectionTextureData)&& (props.reflectionTexture=Laya3D._addHierarchyInnerUrls(thirdLevelUrls,subUrls,urlVersion,hierarchyBasePath,reflectionTextureData,/*CLASS CONST:Laya3D.TEXTURECUBE*/"TEXTURECUBE"));
- if (props.sky){
- var skyboxMaterial=props.sky.material;
- (skyboxMaterial)&& (skyboxMaterial.path=Laya3D._addHierarchyInnerUrls(secondLevelUrls,subUrls,urlVersion,hierarchyBasePath,skyboxMaterial.path,/*CLASS CONST:Laya3D.MATERIAL*/"MATERIAL"));
- }
- break ;
- case "Camera":;
- var skyboxMatData=props.skyboxMaterial;
- (skyboxMatData)&& (skyboxMatData.path=Laya3D._addHierarchyInnerUrls(secondLevelUrls,subUrls,urlVersion,hierarchyBasePath,skyboxMatData.path,/*CLASS CONST:Laya3D.MATERIAL*/"MATERIAL"));
- break ;
- case "TrailSprite3D":
- case "MeshSprite3D":
- case "SkinnedMeshSprite3D":;
- var meshPath=props.meshPath;
- (meshPath)&& (props.meshPath=Laya3D._addHierarchyInnerUrls(firstLevelUrls,subUrls,urlVersion,hierarchyBasePath,meshPath,/*CLASS CONST:Laya3D.MESH*/"MESH"));
- var materials=props.materials;
- if (materials)
- for (i=0,n=materials.length;i < n;i++)
- materials[i].path=Laya3D._addHierarchyInnerUrls(secondLevelUrls,subUrls,urlVersion,hierarchyBasePath,materials[i].path,/*CLASS CONST:Laya3D.MATERIAL*/"MATERIAL");
- break ;
- case "ShuriKenParticle3D":;
- var parMeshPath=props.meshPath;
- (parMeshPath)&& (props.meshPath=Laya3D._addHierarchyInnerUrls(firstLevelUrls,subUrls,urlVersion,hierarchyBasePath,parMeshPath,/*CLASS CONST:Laya3D.MESH*/"MESH"));
- props.material.path=Laya3D._addHierarchyInnerUrls(secondLevelUrls,subUrls,urlVersion,hierarchyBasePath,props.material.path,/*CLASS CONST:Laya3D.MATERIAL*/"MATERIAL");
- break ;
- case "Terrain":
- Laya3D._addHierarchyInnerUrls(fourthLelUrls,subUrls,urlVersion,hierarchyBasePath,props.dataPath,"TERRAIN");
- break ;
- };
- var components=node.components;
- if (components){
- for (var k=0,p=components.length;k < p;k++){
- var component=components[k];
- switch (component.type){
- case "Animator":;
- var avatarPath=component.avatarPath;
- var avatarData=component.avatar;
- (avatarData)&& (avatarData.path=Laya3D._addHierarchyInnerUrls(fourthLelUrls,subUrls,urlVersion,hierarchyBasePath,avatarData.path,"AVATAR"));
- var clipPaths=component.clipPaths;
- if (!clipPaths){
- var layersData=component.layers;
- for (i=0;i < layersData.length;i++){
- var states=layersData[i].states;
- for (var j=0,m=states.length;j < m;j++){
- var clipPath=states[j].clipPath;
- (clipPath)&& (states[j].clipPath=Laya3D._addHierarchyInnerUrls(fourthLelUrls,subUrls,urlVersion,hierarchyBasePath,clipPath,"ANIMATIONCLIP"));
- }
- }
- }else {
- for (i=0,n=clipPaths.length;i < n;i++)
- clipPaths[i]=Laya3D._addHierarchyInnerUrls(fourthLelUrls,subUrls,urlVersion,hierarchyBasePath,clipPaths[i],"ANIMATIONCLIP");
- }
- break ;
- case "PhysicsCollider":
- case "Rigidbody3D":
- case "CharacterController":;
- var shapes=component.shapes;
- for (i=0;i < shapes.length;i++){
- var shape=shapes[i];
- if (shape.type==="MeshColliderShape"){
- var mesh=shape.mesh;
- (mesh)&& (shape.mesh=Laya3D._addHierarchyInnerUrls(firstLevelUrls,subUrls,urlVersion,hierarchyBasePath,mesh,/*CLASS CONST:Laya3D.MESH*/"MESH"));
- }
- }
- break ;
- }
- }
- };
- var children=node.child;
- for (i=0,n=children.length;i < n;i++)
- Laya3D._getSprite3DHierarchyInnerUrls(children[i],firstLevelUrls,secondLevelUrls,thirdLevelUrls,fourthLelUrls,subUrls,urlVersion,hierarchyBasePath);
- }
- Laya3D._loadHierarchy=function(loader){
- loader.on(/*laya.events.Event.LOADED*/"loaded",null,Laya3D._onHierarchylhLoaded,[loader]);
- loader.load(loader.url,/*laya.net.Loader.JSON*/"json",false,null,true);
- }
- Laya3D._onHierarchylhLoaded=function(loader,lhData){
- var url=loader.url;
- var urlVersion=Utils3D.getURLVerion(url);
- var hierarchyBasePath=URL.getPath(url);
- var firstLevUrls=[];
- var secondLevUrls=[];
- var thirdLevUrls=[];
- var forthLevUrls=[];
- var subUrls=[];
- Laya3D._getSprite3DHierarchyInnerUrls(lhData.data,firstLevUrls,secondLevUrls,thirdLevUrls,forthLevUrls,subUrls,urlVersion,hierarchyBasePath);
- var urlCount=firstLevUrls.length+secondLevUrls.length+forthLevUrls.length;
- var totalProcessCount=urlCount+1;
- var weight=1 / totalProcessCount;
- Laya3D._onProcessChange(loader,0,weight,1.0);
- if (forthLevUrls.length > 0){
- var processCeil=urlCount / totalProcessCount;
- var processHandler=Handler.create(null,Laya3D._onProcessChange,[loader,weight,processCeil],false);
- Laya3D._innerFourthLevelLoaderManager._create(forthLevUrls,false,Handler.create(null,Laya3D._onHierarchyInnerForthLevResouLoaded,[loader,processHandler,lhData,subUrls,firstLevUrls,secondLevUrls,thirdLevUrls,weight+processCeil *forthLevUrls.length,processCeil]),processHandler,null,null,null,1,true);
- }else {
- Laya3D._onHierarchyInnerForthLevResouLoaded(loader,null,lhData,subUrls,firstLevUrls,secondLevUrls,thirdLevUrls,weight,processCeil);
- }
- }
- Laya3D._onHierarchyInnerForthLevResouLoaded=function(loader,processHandler,lhData,subUrls,firstLevUrls,secondLevUrls,thirdLevUrls,processOffset,processCeil){
- (processHandler)&& (processHandler.recover());
- if (thirdLevUrls.length > 0){
- var process=Handler.create(null,Laya3D._onProcessChange,[loader,processOffset,processCeil],false);
- Laya3D._innerThirdLevelLoaderManager._create(thirdLevUrls,false,Handler.create(null,Laya3D._onHierarchyInnerThirdLevResouLoaded,[loader,process,lhData,subUrls,firstLevUrls,secondLevUrls,processOffset+processCeil *secondLevUrls.length,processCeil]),processHandler,null,null,null,1,true);
- }else {
- Laya3D._onHierarchyInnerThirdLevResouLoaded(loader,null,lhData,subUrls,firstLevUrls,secondLevUrls,processOffset,processCeil);
- }
- }
- Laya3D._onHierarchyInnerThirdLevResouLoaded=function(loader,processHandler,lhData,subUrls,firstLevUrls,secondLevUrls,processOffset,processCeil){
- (processHandler)&& (processHandler.recover());
- if (secondLevUrls.length > 0){
- var process=Handler.create(null,Laya3D._onProcessChange,[loader,processOffset,processCeil],false);
- Laya3D._innerSecondLevelLoaderManager._create(secondLevUrls,false,Handler.create(null,Laya3D._onHierarchyInnerSecondLevResouLoaded,[loader,process,lhData,subUrls,firstLevUrls,processOffset+processCeil *secondLevUrls.length,processCeil]),processHandler,null,null,null,1,true);
- }else {
- Laya3D._onHierarchyInnerSecondLevResouLoaded(loader,null,lhData,subUrls,firstLevUrls,processOffset,processCeil);
- }
- }
- Laya3D._onHierarchyInnerSecondLevResouLoaded=function(loader,processHandler,lhData,subUrls,firstLevUrls,processOffset,processCeil){
- (processHandler)&& (processHandler.recover());
- if (firstLevUrls.length > 0){
- var process=Handler.create(null,Laya3D._onProcessChange,[loader,processOffset,processCeil],false);
- Laya3D._innerFirstLevelLoaderManager._create(firstLevUrls,false,Handler.create(null,Laya3D._onHierarchyInnerFirstLevResouLoaded,[loader,process,lhData,subUrls]),processHandler,null,null,null,1,true);
- }else {
- Laya3D._onHierarchyInnerFirstLevResouLoaded(loader,null,lhData,subUrls);
- }
- }
- Laya3D._onHierarchyInnerFirstLevResouLoaded=function(loader,processHandler,lhData,subUrls){
- (processHandler)&& (processHandler.recover());
- loader._cache=loader._createCache;
- var item=lhData.data.type==="Scene3D" ? Scene3D._parse(lhData,loader._propertyParams,loader._constructParams):Sprite3D._parse(lhData,loader._propertyParams,loader._constructParams);
- Laya3D._endLoad(loader,item,subUrls);
- }
- Laya3D._loadMesh=function(loader){
- loader.on(/*laya.events.Event.LOADED*/"loaded",null,Laya3D._onMeshLmLoaded,[loader]);
- loader.load(loader.url,/*laya.net.Loader.BUFFER*/"arraybuffer",false,null,true);
- }
- Laya3D._onMeshLmLoaded=function(loader,lmData){
- loader._cache=loader._createCache;
- var mesh=Mesh._parse(lmData,loader._propertyParams,loader._constructParams);
- Laya3D._endLoad(loader,mesh);
- }
- Laya3D._loadMaterial=function(loader){
- loader.on(/*laya.events.Event.LOADED*/"loaded",null,Laya3D._onMaterilLmatLoaded,[loader]);
- loader.load(loader.url,/*laya.net.Loader.JSON*/"json",false,null,true);
- }
- Laya3D._onMaterilLmatLoaded=function(loader,lmatData){
- var url=loader.url;
- var urlVersion=Utils3D.getURLVerion(url);
- var materialBasePath=URL.getPath(url);
- var urls=[];
- var subUrls=[];
- var customProps=lmatData.customProps;
- var formatSubUrl;
- var version=lmatData.version;
- switch (version){
- case "LAYAMATERIAL:01":
- case "LAYAMATERIAL:02":;
- var i=0,n=0;
- var textures=lmatData.props.textures;
- if (textures){
- for (i=0,n=textures.length;i < n;i++){
- var tex2D=textures[i];
- var tex2DPath=tex2D.path;
- if (tex2DPath){
- formatSubUrl=Laya3D.formatRelativePath(materialBasePath,tex2DPath);
- (urlVersion)&& (formatSubUrl=formatSubUrl+urlVersion);
- urls.push({url:formatSubUrl,constructParams:tex2D.constructParams,propertyParams:tex2D.propertyParams});
- subUrls.push(formatSubUrl);
- tex2D.path=formatSubUrl;
- }
- }
- }
- break ;
- default :
- throw new Error("Laya3D:unkonwn version.");
- };
- var urlCount=urls.length;
- var totalProcessCount=urlCount+1;
- var lmatWeight=1 / totalProcessCount;
- Laya3D._onProcessChange(loader,0,lmatWeight,1.0);
- if (urlCount > 0){
- var processHandler=Handler.create(null,Laya3D._onProcessChange,[loader,lmatWeight,urlCount / totalProcessCount],false);
- Laya3D._innerFourthLevelLoaderManager._create(urls,false,Handler.create(null,Laya3D._onMateialTexturesLoaded,[loader,processHandler,lmatData,subUrls]),processHandler,null,null,null,1,true);
- }else {
- Laya3D._onMateialTexturesLoaded(loader,null,lmatData,null);
- }
- }
- Laya3D._onMateialTexturesLoaded=function(loader,processHandler,lmatData,subUrls){
- loader._cache=loader._createCache;
- var mat=BaseMaterial._parse(lmatData,loader._propertyParams,loader._constructParams);
- Laya3D._endLoad(loader,mat,subUrls);
- (processHandler)&& (processHandler.recover());
- }
- Laya3D._loadAvatar=function(loader){
- loader.on(/*laya.events.Event.LOADED*/"loaded",null,function(data){
- loader._cache=loader._createCache;
- var avatar=Avatar._parse(data,loader._propertyParams,loader._constructParams);
- Laya3D._endLoad(loader,avatar);
- });
- loader.load(loader.url,/*laya.net.Loader.JSON*/"json",false,null,true);
- }
- Laya3D._loadAnimationClip=function(loader){
- loader.on(/*laya.events.Event.LOADED*/"loaded",null,function(data){
- loader._cache=loader._createCache;
- var clip=AnimationClip._parse(data,loader._propertyParams,loader._constructParams);
- Laya3D._endLoad(loader,clip);
- });
- loader.load(loader.url,/*laya.net.Loader.BUFFER*/"arraybuffer",false,null,true);
- }
- Laya3D._loadTexture2D=function(loader){
- var url=loader.url;
- var index=url.lastIndexOf('.')+1;
- var verIndex=url.indexOf('?');
- var endIndex=verIndex==-1 ? url.length :verIndex;
- var ext=url.substr(index,endIndex-index);
- var type;
- switch (ext){
- case "jpg":
- case "jpeg":
- case "bmp":
- case "gif":
- case "png":
- type="nativeimage";
- break ;
- case "dds":
- case "ktx":
- case "pvr":
- type=/*laya.net.Loader.BUFFER*/"arraybuffer";
- break ;
- }
- loader.on(/*laya.events.Event.LOADED*/"loaded",null,function(image){
- loader._cache=loader._createCache;
- var tex=Texture2D._parse(image,loader._propertyParams,loader._constructParams);
- Laya3D._endLoad(loader,tex);
- });
- loader.load(loader.url,type,false,null,true);
- }
- Laya3D._loadTextureCube=function(loader){
- loader.on(/*laya.events.Event.LOADED*/"loaded",null,Laya3D._onTextureCubeLtcLoaded,[loader]);
- loader.load(loader.url,/*laya.net.Loader.JSON*/"json",false,null,true);
- }
- Laya3D._onTextureCubeLtcLoaded=function(loader,ltcData){
- var ltcBasePath=URL.getPath(loader.url);
- 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)];
- var ltcWeight=1.0 / 7.0;
- Laya3D._onProcessChange(loader,0,ltcWeight,1.0);
- var processHandler=Handler.create(null,Laya3D._onProcessChange,[loader,ltcWeight,6 / 7],false);
- Laya3D._innerFourthLevelLoaderManager.load(urls,Handler.create(null,Laya3D._onTextureCubeImagesLoaded,[loader,urls,processHandler]),processHandler,"nativeimage");
- }
- Laya3D._onTextureCubeImagesLoaded=function(loader,urls,processHandler){
- var images=new Array(6);
- for (var i=0;i < 6;i++)
- images[i]=Loader.getRes(urls[i]);
- loader._cache=loader._createCache;
- var tex=TextureCube._parse(images,loader._propertyParams,loader._constructParams);
- processHandler.recover();
- for (i=0;i < 6;i++)
- Loader.clearRes(urls[i]);
- Laya3D._endLoad(loader,tex);
- }
- Laya3D._onProcessChange=function(loader,offset,weight,process){
- process=offset+process *weight;
- (process < 1.0)&& (loader.event(/*laya.events.Event.PROGRESS*/"progress",process));
- }
- Laya3D.init=function(width,height,config,compolete){
- if (Laya3D._isInit)
- return;
- Laya3D._isInit=true;
- config=config || Config3D._default;
- config.cloneTo(Laya3D._config);
- Laya3D._editerEnvironment=Laya3D._config._editerEnvironment;
- var physics3D=window.Physics3D;
- if (physics3D==null){
- Laya3D._enbalePhysics=false;
- Laya3D.__init__(width,height,Laya3D._config);
- compolete && compolete.run();
- }else {
- Laya3D._enbalePhysics=true;
- physics3D(Laya3D._config.defaultPhysicsMemory *1024 *1024).then(function(){
- Laya3D.__init__(width,height,Laya3D._config);
- compolete && compolete.run();
- });
- }
- }
- Laya3D.HIERARCHY="HIERARCHY";
- Laya3D.MESH="MESH";
- Laya3D.MATERIAL="MATERIAL";
- Laya3D.TEXTURE2D="TEXTURE2D";
- Laya3D.TEXTURECUBE="TEXTURECUBE";
- Laya3D.ANIMATIONCLIP="ANIMATIONCLIP";
- Laya3D.AVATAR="AVATAR";
- Laya3D.TERRAINHEIGHTDATA="TERRAINHEIGHTDATA";
- Laya3D.TERRAINRES="TERRAIN";
- Laya3D._isInit=false;
- Laya3D._enbalePhysics=false;
- Laya3D._editerEnvironment=false;
- __static(Laya3D,
- ['_innerFirstLevelLoaderManager',function(){return this._innerFirstLevelLoaderManager=new LoaderManager();},'_innerSecondLevelLoaderManager',function(){return this._innerSecondLevelLoaderManager=new LoaderManager();},'_innerThirdLevelLoaderManager',function(){return this._innerThirdLevelLoaderManager=new LoaderManager();},'_innerFourthLevelLoaderManager',function(){return this._innerFourthLevelLoaderManager=new LoaderManager();},'_physics3D',function(){return this._physics3D=window.Physics3D;},'_config',function(){return this._config=new Config3D();},'physicsSettings',function(){return this.physicsSettings=new PhysicsSettings();}
- ]);
- return Laya3D;
- })()
- /**
- *<code>FrameOverTime</code> 类用于创建时间帧。
- */
- //class laya.d3.core.particleShuriKen.module.FrameOverTime
- var FrameOverTime=(function(){
- function FrameOverTime(){
- /**@private */
- this._type=0;
- /**@private */
- this._constant=0;
- /**@private */
- this._overTime=null;
- /**@private */
- this._constantMin=0;
- /**@private */
- this._constantMax=0;
- /**@private */
- this._overTimeMin=null;
- /**@private */
- this._overTimeMax=null;
- }
- __class(FrameOverTime,'laya.d3.core.particleShuriKen.module.FrameOverTime');
- var __proto=FrameOverTime.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var destFrameOverTime=destObject;
- destFrameOverTime._type=this._type;
- destFrameOverTime._constant=this._constant;
- this._overTime.cloneTo(destFrameOverTime._overTime);
- destFrameOverTime._constantMin=this._constantMin;
- destFrameOverTime._constantMax=this._constantMax;
- this._overTimeMin.cloneTo(destFrameOverTime._overTimeMin);
- this._overTimeMax.cloneTo(destFrameOverTime._overTimeMax);
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var destFrameOverTime=/*__JS__ */new this.constructor();
- this.cloneTo(destFrameOverTime);
- return destFrameOverTime;
- }
- /**
- *时间帧。
- */
- __getset(0,__proto,'frameOverTimeData',function(){
- return this._overTime;
- });
- /**
- *固定帧。
- */
- __getset(0,__proto,'constant',function(){
- return this._constant;
- });
- /**
- *生命周期旋转类型,0常量模式,1曲线模式,2随机双常量模式,3随机双曲线模式。
- */
- __getset(0,__proto,'type',function(){
- return this._type;
- });
- /**
- *最小时间帧。
- */
- __getset(0,__proto,'frameOverTimeDataMin',function(){
- return this._overTimeMin;
- });
- /**
- *最小固定帧。
- */
- __getset(0,__proto,'constantMin',function(){
- return this._constantMin;
- });
- /**
- *最大时间帧。
- */
- __getset(0,__proto,'frameOverTimeDataMax',function(){
- return this._overTimeMax;
- });
- /**
- *最大固定帧。
- */
- __getset(0,__proto,'constantMax',function(){
- return this._constantMax;
- });
- FrameOverTime.createByConstant=function(constant){
- var rotationOverLifetime=new FrameOverTime();
- rotationOverLifetime._type=0;
- rotationOverLifetime._constant=constant;
- return rotationOverLifetime;
- }
- FrameOverTime.createByOverTime=function(overTime){
- var rotationOverLifetime=new FrameOverTime();
- rotationOverLifetime._type=1;
- rotationOverLifetime._overTime=overTime;
- return rotationOverLifetime;
- }
- FrameOverTime.createByRandomTwoConstant=function(constantMin,constantMax){
- var rotationOverLifetime=new FrameOverTime();
- rotationOverLifetime._type=2;
- rotationOverLifetime._constantMin=constantMin;
- rotationOverLifetime._constantMax=constantMax;
- return rotationOverLifetime;
- }
- FrameOverTime.createByRandomTwoOverTime=function(gradientFrameMin,gradientFrameMax){
- var rotationOverLifetime=new FrameOverTime();
- rotationOverLifetime._type=3;
- rotationOverLifetime._overTimeMin=gradientFrameMin;
- rotationOverLifetime._overTimeMax=gradientFrameMax;
- return rotationOverLifetime;
- }
- return FrameOverTime;
- })()
- /**
- *<code>RenderState</code> 类用于控制渲染状态。
- */
- //class laya.d3.core.material.RenderState
- var RenderState=(function(){
- function RenderState(){
- /**渲染剔除状态。*/
- this.cull=0;
- /**透明混合。*/
- this.blend=0;
- /**源混合参数,在blend为BLEND_ENABLE_ALL时生效。*/
- this.srcBlend=0;
- /**目标混合参数,在blend为BLEND_ENABLE_ALL时生效。*/
- this.dstBlend=0;
- /**RGB源混合参数,在blend为BLEND_ENABLE_SEPERATE时生效。*/
- this.srcBlendRGB=0;
- /**RGB目标混合参数,在blend为BLEND_ENABLE_SEPERATE时生效。*/
- this.dstBlendRGB=0;
- /**Alpha源混合参数,在blend为BLEND_ENABLE_SEPERATE时生效。*/
- this.srcBlendAlpha=0;
- /**Alpha目标混合参数,在blend为BLEND_ENABLE_SEPERATE时生效。*/
- this.dstBlendAlpha=0;
- /**混合常量颜色。*/
- this.blendConstColor=null;
- /**混合方程。*/
- this.blendEquation=0;
- /**RGB混合方程。*/
- this.blendEquationRGB=0;
- /**Alpha混合方程。*/
- this.blendEquationAlpha=0;
- /**深度测试函数。*/
- this.depthTest=0;
- /**是否深度写入。*/
- this.depthWrite=false;
- this.cull=2;
- this.blend=0;
- this.srcBlend=1;
- this.dstBlend=0;
- this.srcBlendRGB=1;
- this.dstBlendRGB=0;
- this.srcBlendAlpha=1;
- this.dstBlendAlpha=0;
- this.blendConstColor=new Vector4(1,1,1,1);
- this.blendEquation=0;
- this.blendEquationRGB=0;
- this.blendEquationAlpha=0;
- this.depthTest=0x0203;
- this.depthWrite=true;
- }
- __class(RenderState,'laya.d3.core.material.RenderState');
- var __proto=RenderState.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(dest){
- var destState=dest;
- destState.cull=this.cull;
- destState.blend=this.blend;
- destState.srcBlend=this.srcBlend;
- destState.dstBlend=this.dstBlend;
- destState.srcBlendRGB=this.srcBlendRGB;
- destState.dstBlendRGB=this.dstBlendRGB;
- destState.srcBlendAlpha=this.srcBlendAlpha;
- destState.dstBlendAlpha=this.dstBlendAlpha;
- this.blendConstColor.cloneTo(destState.blendConstColor);
- destState.blendEquation=this.blendEquation;
- destState.blendEquationRGB=this.blendEquationRGB;
- destState.blendEquationAlpha=this.blendEquationAlpha;
- destState.depthTest=this.depthTest;
- destState.depthWrite=this.depthWrite;
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var dest=/*__JS__ */new this.constructor();
- this.cloneTo(dest);
- return dest;
- }
- RenderState.CULL_NONE=0;
- RenderState.CULL_FRONT=1;
- RenderState.CULL_BACK=2;
- RenderState.BLEND_DISABLE=0;
- RenderState.BLEND_ENABLE_ALL=1;
- RenderState.BLEND_ENABLE_SEPERATE=2;
- RenderState.BLENDPARAM_ZERO=0;
- RenderState.BLENDPARAM_ONE=1;
- RenderState.BLENDPARAM_SRC_COLOR=0x0300;
- RenderState.BLENDPARAM_ONE_MINUS_SRC_COLOR=0x0301;
- RenderState.BLENDPARAM_DST_COLOR=0x0306;
- RenderState.BLENDPARAM_ONE_MINUS_DST_COLOR=0x0307;
- RenderState.BLENDPARAM_SRC_ALPHA=0x0302;
- RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA=0x0303;
- RenderState.BLENDPARAM_DST_ALPHA=0x0304;
- RenderState.BLENDPARAM_ONE_MINUS_DST_ALPHA=0x0305;
- RenderState.BLENDPARAM_SRC_ALPHA_SATURATE=0x0308;
- RenderState.BLENDEQUATION_ADD=0;
- RenderState.BLENDEQUATION_SUBTRACT=1;
- RenderState.BLENDEQUATION_REVERSE_SUBTRACT=2;
- RenderState.DEPTHTEST_OFF=0;
- RenderState.DEPTHTEST_NEVER=0x0200;
- RenderState.DEPTHTEST_LESS=0x0201;
- RenderState.DEPTHTEST_EQUAL=0x0202;
- RenderState.DEPTHTEST_LEQUAL=0x0203;
- RenderState.DEPTHTEST_GREATER=0x0204;
- RenderState.DEPTHTEST_NOTEQUAL=0x0205;
- RenderState.DEPTHTEST_GEQUAL=0x0206;
- RenderState.DEPTHTEST_ALWAYS=0x0207;
- return RenderState;
- })()
- /**
- *<code>Ray</code> 类用于创建射线。
- */
- //class laya.d3.math.Ray
- var Ray=(function(){
- function Ray(origin,direction){
- /**原点*/
- this.origin=null;
- /**方向*/
- this.direction=null;
- this.origin=origin;
- this.direction=direction;
- }
- __class(Ray,'laya.d3.math.Ray');
- return Ray;
- })()
- /**
- *<code>ContactPoint</code> 类用于创建物理碰撞信息。
- */
- //class laya.d3.physics.ContactPoint
- var ContactPoint=(function(){
- function ContactPoint(){
- /**@private */
- this._idCounter=0;
- /**@private */
- //this._id=0;
- /**碰撞器A。*/
- this.colliderA=null;
- /**碰撞器B。*/
- this.colliderB=null;
- /**距离。*/
- this.distance=0;
- this.normal=new Vector3();
- this.positionOnA=new Vector3();
- this.positionOnB=new Vector3();
- this._id=++this._idCounter;
- }
- __class(ContactPoint,'laya.d3.physics.ContactPoint');
- return ContactPoint;
- })()
- /**
- *<code>StaticBatchManager</code> 类用于静态批处理管理的父类。
- */
- //class laya.d3.graphics.StaticBatchManager
- var StaticBatchManager=(function(){
- function StaticBatchManager(){
- /**@private */
- //this._batchRenderElementPool=null;
- /**@private */
- //this._batchRenderElementPoolIndex=0;
- /**@private */
- //this._initBatchSprites=null;
- /**@private */
- //this._staticBatches=null;
- this._initBatchSprites=[];
- this._staticBatches={};
- this._batchRenderElementPoolIndex=0;
- this._batchRenderElementPool=[];
- }
- __class(StaticBatchManager,'laya.d3.graphics.StaticBatchManager');
- var __proto=StaticBatchManager.prototype;
- /**
- *@private
- */
- __proto._partition=function(items,left,right){
- var pivot=items[Math.floor((right+left)/ 2)];
- while (left <=right){
- while (this._compare(items[left],pivot)< 0)
- left++;
- while (this._compare(items[right],pivot)> 0)
- right--;
- if (left < right){
- var temp=items[left];
- items[left]=items[right];
- items[right]=temp;
- left++;
- right--;
- }else if (left===right){
- left++;
- break ;
- }
- }
- return left;
- }
- /**
- *@private
- */
- __proto._quickSort=function(items,left,right){
- if (items.length > 1){
- var index=this._partition(items,left,right);
- var leftIndex=index-1;
- if (left < leftIndex)
- this._quickSort(items,left,leftIndex);
- if (index < right)
- this._quickSort(items,index,right);
- }
- }
- /**
- *@private
- */
- __proto._compare=function(left,right){
- throw "StaticBatch:must override this function.";
- }
- /**
- *@private
- */
- __proto._initStaticBatchs=function(rootSprite){
- throw "StaticBatch:must override this function.";
- }
- /**
- *@private
- */
- __proto._getBatchRenderElementFromPool=function(){
- throw "StaticBatch:must override this function.";
- }
- /**
- *@private
- */
- __proto._addBatchSprite=function(renderableSprite3D){
- this._initBatchSprites.push(renderableSprite3D);
- }
- /**
- *@private
- */
- __proto._clear=function(){
- this._batchRenderElementPoolIndex=0;
- }
- /**
- *@private
- */
- __proto._garbageCollection=function(){
- throw "StaticBatchManager: must override it.";
- }
- /**
- *@private
- */
- __proto.dispose=function(){
- this._staticBatches=null;
- }
- StaticBatchManager._registerManager=function(manager){
- StaticBatchManager._managers.push(manager);
- }
- StaticBatchManager._addToStaticBatchQueue=function(sprite3D,renderableSprite3D){
- if ((sprite3D instanceof laya.d3.core.RenderableSprite3D )&& sprite3D.isStatic)
- renderableSprite3D.push(sprite3D);
- for (var i=0,n=sprite3D.numChildren;i < n;i++)
- StaticBatchManager._addToStaticBatchQueue(sprite3D._children [i],renderableSprite3D);
- }
- StaticBatchManager.combine=function(staticBatchRoot,renderableSprite3Ds){
- if (!renderableSprite3Ds){
- renderableSprite3Ds=[];
- if (staticBatchRoot)
- StaticBatchManager._addToStaticBatchQueue(staticBatchRoot,renderableSprite3Ds);
- };
- var batchSpritesCount=renderableSprite3Ds.length;
- if (batchSpritesCount > 0){
- for (var i=0;i < batchSpritesCount;i++){
- var renderableSprite3D=renderableSprite3Ds[i];
- (renderableSprite3D.isStatic)&& (renderableSprite3D._addToInitStaticBatchManager());
- }
- for (var k=0,m=StaticBatchManager._managers.length;k < m;k++){
- var manager=StaticBatchManager._managers[k];
- manager._initStaticBatchs(staticBatchRoot);
- }
- }
- }
- StaticBatchManager._managers=[];
- return StaticBatchManager;
- })()
- /**
- *@private
- *<code>Command</code> 类用于创建指令。
- */
- //class laya.d3.core.render.command.Command
- var Command=(function(){
- /**
- *创建一个 <code>Command</code> 实例。
- */
- function Command(){}
- __class(Command,'laya.d3.core.render.command.Command');
- var __proto=Command.prototype;
- /**
- *@private
- */
- __proto.run=function(){}
- /**
- *@private
- */
- __proto.recover=function(){}
- return Command;
- })()
- /**
- *<code>RenderContext3D</code> 类用于实现渲染状态。
- */
- //class laya.d3.core.render.RenderContext3D
- var RenderContext3D=(function(){
- function RenderContext3D(){
- /**@private */
- //this._batchIndexStart=0;
- /**@private */
- //this._batchIndexEnd=0;
- /**@private */
- //this.viewMatrix=null;
- /**@private */
- //this.projectionMatrix=null;
- /**@private */
- //this.projectionViewMatrix=null;
- /**@private */
- //this.viewport=null;
- /**@private */
- //this.scene=null;
- /**@private */
- //this.camera=null;
- /**@private */
- //this.renderElement=null;
- /**@private */
- //this.shader=null;
- }
- __class(RenderContext3D,'laya.d3.core.render.RenderContext3D');
- RenderContext3D.clientWidth=0;
- RenderContext3D.clientHeight=0;
- __static(RenderContext3D,
- ['_instance',function(){return this._instance=new RenderContext3D();}
- ]);
- return RenderContext3D;
- })()
- /**
- *...
- *@author ...
- */
- //class laya.d3.core.GradientMode
- var GradientMode=(function(){
- function GradientMode(){}
- __class(GradientMode,'laya.d3.core.GradientMode');
- GradientMode.Blend=0;
- GradientMode.Fixed=1;
- return GradientMode;
- })()
- /**
- *<code>SingletonList</code> 类用于实现单例队列。
- */
- //class laya.d3.component.SingletonList
- var SingletonList=(function(){
- function SingletonList(){
- /**@private [只读]*/
- this.length=0;
- this.elements=[];
- }
- __class(SingletonList,'laya.d3.component.SingletonList');
- var __proto=SingletonList.prototype;
- /**
- *@private
- */
- __proto._add=function(element){
- if (this.length===this.elements.length)
- this.elements.push(element);
- else
- this.elements[this.length]=element;
- }
- return SingletonList;
- })()
- /**
- *@private
- *<code>DynamicBatchManager</code> 类用于管理动态批处理。
- */
- //class laya.d3.graphics.DynamicBatchManager
- var DynamicBatchManager=(function(){
- function DynamicBatchManager(){
- /**@private */
- //this._batchRenderElementPool=null;
- /**@private */
- //this._batchRenderElementPoolIndex=0;
- this._batchRenderElementPool=[];
- }
- __class(DynamicBatchManager,'laya.d3.graphics.DynamicBatchManager');
- var __proto=DynamicBatchManager.prototype;
- /**
- *@private
- */
- __proto._clear=function(){
- this._batchRenderElementPoolIndex=0;
- }
- /**
- *@private
- */
- __proto._getBatchRenderElementFromPool=function(){
- throw "StaticBatch:must override this function.";
- }
- /**
- *@private
- */
- __proto.dispose=function(){}
- DynamicBatchManager._registerManager=function(manager){
- DynamicBatchManager._managers.push(manager);
- }
- DynamicBatchManager._managers=[];
- return DynamicBatchManager;
- })()
- /**
- *<code>Point2PointConstraint</code> 类用于创建物理组件的父类。
- */
- //class laya.d3.physics.constraints.Point2PointConstraint
- var Point2PointConstraint=(function(){
- function Point2PointConstraint(){
- /**@private */
- this._damping=NaN;
- /**@private */
- this._impulseClamp=NaN;
- /**@private */
- this._tau=NaN;
- this._pivotInA=new Vector3();
- this._pivotInB=new Vector3();
- }
- __class(Point2PointConstraint,'laya.d3.physics.constraints.Point2PointConstraint');
- var __proto=Point2PointConstraint.prototype;
- __getset(0,__proto,'pivotInA',function(){
- return this._pivotInA;
- },function(value){
- this._pivotInA=value;
- });
- __getset(0,__proto,'pivotInB',function(){
- return this._pivotInB;
- },function(value){
- this._pivotInB=value;
- });
- __getset(0,__proto,'damping',function(){
- return this._damping;
- },function(value){
- this._damping=value;
- });
- __getset(0,__proto,'impulseClamp',function(){
- return this._impulseClamp;
- },function(value){
- this._impulseClamp=value;
- });
- __getset(0,__proto,'tau',function(){
- return this._tau;
- },function(value){
- this._tau=value;
- });
- return Point2PointConstraint;
- })()
- /**
- *@private
- *<code>GeometryElement</code> 类用于实现几何体元素,该类为抽象类。
- */
- //class laya.d3.core.GeometryElement
- var GeometryElement=(function(){
- function GeometryElement(){
- /**@private */
- //this._destroyed=false;
- this._destroyed=false;
- }
- __class(GeometryElement,'laya.d3.core.GeometryElement');
- var __proto=GeometryElement.prototype;
- Laya.imps(__proto,{"laya.resource.IDestroy":true})
- /**
- *获取几何体类型。
- */
- __proto._getType=function(){
- throw "GeometryElement:must override it.";
- }
- /**
- *@private
- *@return 是否需要渲染。
- */
- __proto._prepareRender=function(state){
- return true;
- }
- /**
- *@private
- */
- __proto._render=function(state){
- throw "GeometryElement:must override it.";
- }
- /**
- *销毁。
- */
- __proto.destroy=function(){
- if (this._destroyed)
- return;
- this._destroyed=true;
- }
- /**
- *获取是否销毁。
- *@return 是否销毁。
- */
- __getset(0,__proto,'destroyed',function(){
- return this._destroyed;
- });
- GeometryElement._typeCounter=0;
- return GeometryElement;
- })()
- /**
- *<code>VertexPositionNormalTexture</code> 类用于创建位置、纹理顶点结构。
- */
- //class laya.d3.graphics.Vertex.VertexPositionTexture0
- var VertexPositionTexture0=(function(){
- function VertexPositionTexture0(position,textureCoordinate0){
- this._position=null;
- this._textureCoordinate0=null;
- this._position=position;
- this._textureCoordinate0=textureCoordinate0;
- }
- __class(VertexPositionTexture0,'laya.d3.graphics.Vertex.VertexPositionTexture0');
- var __proto=VertexPositionTexture0.prototype;
- Laya.imps(__proto,{"laya.d3.graphics.IVertex":true})
- __getset(0,__proto,'position',function(){
- return this._position;
- });
- __getset(0,__proto,'textureCoordinate0',function(){
- return this._textureCoordinate0;
- });
- __getset(0,__proto,'vertexDeclaration',function(){
- return VertexPositionTexture0._vertexDeclaration;
- });
- __getset(1,VertexPositionTexture0,'vertexDeclaration',function(){
- return VertexPositionTexture0._vertexDeclaration;
- });
- __static(VertexPositionTexture0,
- ['_vertexDeclaration',function(){return this._vertexDeclaration=new VertexDeclaration(20,[
- new VertexElement(0,/*laya.d3.graphics.VertexElementFormat.Vector3*/"vector3",/*laya.d3.graphics.Vertex.VertexMesh.MESH_POSITION0*/0),
- new VertexElement(12,/*laya.d3.graphics.VertexElementFormat.Vector2*/"vector2",/*laya.d3.graphics.Vertex.VertexMesh.MESH_TEXTURECOORDINATE0*/2)]);}
- ]);
- return VertexPositionTexture0;
- })()
- /**
- *<code>MathUtils</code> 类用于创建数学工具。
- */
- //class laya.d3.math.MathUtils3D
- var MathUtils3D=(function(){
- /**
- *创建一个 <code>MathUtils</code> 实例。
- */
- function MathUtils3D(){}
- __class(MathUtils3D,'laya.d3.math.MathUtils3D');
- MathUtils3D.isZero=function(v){
- return Math.abs(v)< MathUtils3D.zeroTolerance;
- }
- MathUtils3D.nearEqual=function(n1,n2){
- if (MathUtils3D.isZero(n1-n2))
- return true;
- return false;
- }
- MathUtils3D.fastInvSqrt=function(value){
- if (MathUtils3D.isZero(value))
- return value;
- return 1.0 / Math.sqrt(value);
- }
- __static(MathUtils3D,
- ['zeroTolerance',function(){return this.zeroTolerance=1e-6;},'MaxValue',function(){return this.MaxValue=3.40282347e+38;},'MinValue',function(){return this.MinValue=-3.40282347e+38;}
- ]);
- return MathUtils3D;
- })()
- /**
- *<code>GradientColor</code> 类用于创建渐变颜色。
- */
- //class laya.d3.core.particleShuriKen.module.GradientColor
- var GradientColor=(function(){
- function GradientColor(){
- /**@private */
- this._type=0;
- /**@private */
- this._constant=null;
- /**@private */
- this._constantMin=null;
- /**@private */
- this._constantMax=null;
- /**@private */
- this._gradient=null;
- /**@private */
- this._gradientMin=null;
- /**@private */
- this._gradientMax=null;
- }
- __class(GradientColor,'laya.d3.core.particleShuriKen.module.GradientColor');
- var __proto=GradientColor.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var destGradientColor=destObject;
- destGradientColor._type=this._type;
- this._constant.cloneTo(destGradientColor._constant);
- this._constantMin.cloneTo(destGradientColor._constantMin);
- this._constantMax.cloneTo(destGradientColor._constantMax);
- this._gradient.cloneTo(destGradientColor._gradient);
- this._gradientMin.cloneTo(destGradientColor._gradientMin);
- this._gradientMax.cloneTo(destGradientColor._gradientMax);
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var destGradientColor=/*__JS__ */new this.constructor();
- this.cloneTo(destGradientColor);
- return destGradientColor;
- }
- /**
- *渐变颜色。
- */
- __getset(0,__proto,'gradient',function(){
- return this._gradient;
- });
- /**
- *固定颜色。
- */
- __getset(0,__proto,'constant',function(){
- return this._constant;
- });
- /**
- *生命周期颜色类型,0为固定颜色模式,1渐变模式,2为随机双固定颜色模式,3随机双渐变模式。
- */
- __getset(0,__proto,'type',function(){
- return this._type;
- });
- /**
- *最小渐变颜色。
- */
- __getset(0,__proto,'gradientMin',function(){
- return this._gradientMin;
- });
- /**
- *最小固定颜色。
- */
- __getset(0,__proto,'constantMin',function(){
- return this._constantMin;
- });
- /**
- *最大渐变颜色。
- */
- __getset(0,__proto,'gradientMax',function(){
- return this._gradientMax;
- });
- /**
- *最大固定颜色。
- */
- __getset(0,__proto,'constantMax',function(){
- return this._constantMax;
- });
- GradientColor.createByConstant=function(constant){
- var gradientColor=new GradientColor();
- gradientColor._type=0;
- gradientColor._constant=constant;
- return gradientColor;
- }
- GradientColor.createByGradient=function(gradient){
- var gradientColor=new GradientColor();
- gradientColor._type=1;
- gradientColor._gradient=gradient;
- return gradientColor;
- }
- GradientColor.createByRandomTwoConstant=function(minConstant,maxConstant){
- var gradientColor=new GradientColor();
- gradientColor._type=2;
- gradientColor._constantMin=minConstant;
- gradientColor._constantMax=maxConstant;
- return gradientColor;
- }
- GradientColor.createByRandomTwoGradient=function(minGradient,maxGradient){
- var gradientColor=new GradientColor();
- gradientColor._type=3;
- gradientColor._gradientMin=minGradient;
- gradientColor._gradientMax=maxGradient;
- return gradientColor;
- }
- return GradientColor;
- })()
- //class laya.d3.utils.Size
- var Size=(function(){
- function Size(width,height){
- this._width=0;
- this._height=0;
- this._width=width;
- this._height=height;
- }
- __class(Size,'laya.d3.utils.Size');
- var __proto=Size.prototype;
- __getset(0,__proto,'width',function(){
- if (this._width===-1)
- return RenderContext3D.clientWidth;
- return this._width;
- });
- __getset(0,__proto,'height',function(){
- if (this._height===-1)
- return RenderContext3D.clientHeight;
- return this._height;
- });
- __getset(1,Size,'fullScreen',function(){
- return new Size(-1,-1);
- });
- return Size;
- })()
- /**
- *<code>PhysicsSettings</code> 类用于创建物理配置信息。
- */
- //class laya.d3.physics.PhysicsSettings
- var PhysicsSettings=(function(){
- function PhysicsSettings(){
- /**标志集合。*/
- this.flags=0;
- /**物理引擎在一帧中用于补偿减速的最大次数。*/
- this.maxSubSteps=1;
- /**物理模拟器帧的间隔时间。*/
- this.fixedTimeStep=1.0 / 60.0;
- }
- __class(PhysicsSettings,'laya.d3.physics.PhysicsSettings');
- return PhysicsSettings;
- })()
- /**
- *<code>Plane</code> 类用于创建平面。
- */
- //class laya.d3.math.Plane
- var Plane=(function(){
- function Plane(normal,d){
- /**平面的向量*/
- this.normal=null;
- /**平面到坐标系原点的距离*/
- this.distance=NaN;
- (d===void 0)&& (d=0);
- this.normal=normal;
- this.distance=d;
- }
- __class(Plane,'laya.d3.math.Plane');
- var __proto=Plane.prototype;
- /**
- *更改平面法线向量的系数,使之成单位长度。
- */
- __proto.normalize=function(){
- var normalEX=this.normal.x;
- var normalEY=this.normal.y;
- var normalEZ=this.normal.z;
- var magnitude=1 / Math.sqrt(normalEX *normalEX+normalEY *normalEY+normalEZ *normalEZ);
- this.normal.x=normalEX *magnitude;
- this.normal.y=normalEY *magnitude;
- this.normal.z=normalEZ *magnitude;
- this.distance *=magnitude;
- }
- Plane.createPlaneBy3P=function(point1,point2,point3){
- var x1=point2.x-point1.x;
- var y1=point2.y-point1.y;
- var z1=point2.z-point1.z;
- var x2=point3.x-point1.x;
- var y2=point3.y-point1.y;
- var z2=point3.z-point1.z;
- var yz=(y1 *z2)-(z1 *y2);
- var xz=(z1 *x2)-(x1 *z2);
- var xy=(x1 *y2)-(y1 *x2);
- var invPyth=1 / (Math.sqrt((yz *yz)+(xz *xz)+(xy *xy)));
- var x=yz *invPyth;
- var y=xz *invPyth;
- var z=xy *invPyth;
- Plane._TEMPVec3.x=x;
- Plane._TEMPVec3.y=y;
- Plane._TEMPVec3.z=z;
- var d=-((x *point1.x)+(y *point1.y)+(z *point1.z));
- var plane=new Plane(Plane._TEMPVec3,d);
- return plane;
- }
- Plane.PlaneIntersectionType_Back=0;
- Plane.PlaneIntersectionType_Front=1;
- Plane.PlaneIntersectionType_Intersecting=2;
- __static(Plane,
- ['_TEMPVec3',function(){return this._TEMPVec3=new Vector3();}
- ]);
- return Plane;
- })()
- /**
- *<code>MaterialInfo</code> 类用于描述地形材质信息。
- */
- //class laya.d3.terrain.unit.MaterialInfo
- var MaterialInfo=(function(){
- function MaterialInfo(){
- this.ambientColor=null;
- this.diffuseColor=null;
- this.specularColor=null;
- }
- __class(MaterialInfo,'laya.d3.terrain.unit.MaterialInfo');
- return MaterialInfo;
- })()
- /**
- *<code>Gradient</code> 类用于创建颜色渐变。
- */
- //class laya.d3.core.Gradient
- var Gradient=(function(){
- function Gradient(maxColorRGBKeyCount,maxColorAlphaKeyCount){
- /**@private */
- this._mode=0;
- /**@private */
- this._maxColorRGBKeysCount=0;
- /**@private */
- this._maxColorAlphaKeysCount=0;
- /**@private */
- this._colorRGBKeysCount=0;
- /**@private */
- this._colorAlphaKeysCount=0;
- /**@private */
- this._alphaElements=null;
- /**@private */
- this._rgbElements=null;
- this._maxColorRGBKeysCount=maxColorRGBKeyCount;
- this._maxColorAlphaKeysCount=maxColorAlphaKeyCount;
- this._rgbElements=new Float32Array(maxColorRGBKeyCount *4);
- this._alphaElements=new Float32Array(maxColorAlphaKeyCount *2);
- }
- __class(Gradient,'laya.d3.core.Gradient');
- var __proto=Gradient.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *增加颜色RGB帧。
- *@param key 生命周期,范围为0到1。
- *@param value RGB值。
- */
- __proto.addColorRGB=function(key,value){
- if (this._colorRGBKeysCount < this._maxColorRGBKeysCount){
- var offset=this._colorRGBKeysCount *4;
- this._rgbElements[offset]=key;
- this._rgbElements[offset+1]=value.r;
- this._rgbElements[offset+2]=value.g;
- this._rgbElements[offset+3]=value.b;
- this._colorRGBKeysCount++;
- }else {
- console.warn("Gradient:warning:data count must lessEqual than "+this._maxColorRGBKeysCount);
- }
- }
- /**
- *增加颜色Alpha帧。
- *@param key 生命周期,范围为0到1。
- *@param value Alpha值。
- */
- __proto.addColorAlpha=function(key,value){
- if (this._colorAlphaKeysCount < this._maxColorAlphaKeysCount){
- var offset=this._colorAlphaKeysCount *2;
- this._alphaElements[offset]=key;
- this._alphaElements[offset+1]=value;
- this._colorAlphaKeysCount++;
- }else {
- console.warn("Gradient:warning:data count must lessEqual than "+this._maxColorAlphaKeysCount);
- }
- }
- /**
- *更新颜色RGB帧。
- *@param index 索引。
- *@param key 生命周期,范围为0到1。
- *@param value RGB值。
- */
- __proto.updateColorRGB=function(index,key,value){
- if (index < this._colorRGBKeysCount){
- var offset=index *4;
- this._rgbElements[offset]=key;
- this._rgbElements[offset+1]=value.r;
- this._rgbElements[offset+2]=value.g;
- this._rgbElements[offset+3]=value.b;
- }else {
- console.warn("Gradient:warning:index must lessEqual than colorRGBKeysCount:"+this._colorRGBKeysCount);
- }
- }
- /**
- *更新颜色Alpha帧。
- *@param index 索引。
- *@param key 生命周期,范围为0到1。
- *@param value Alpha值。
- */
- __proto.updateColorAlpha=function(index,key,value){
- if (index < this._colorAlphaKeysCount){
- var offset=index *2;
- this._alphaElements[offset]=key;
- this._alphaElements[offset+1]=value;
- }else {
- console.warn("Gradient:warning:index must lessEqual than colorAlphaKeysCount:"+this._colorAlphaKeysCount);
- }
- }
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var destGradientDataColor=destObject;
- var i=0,n=0;
- destGradientDataColor._colorAlphaKeysCount=this._colorAlphaKeysCount;
- var destAlphaElements=destGradientDataColor._alphaElements;
- destAlphaElements.length=this._alphaElements.length;
- for (i=0,n=this._alphaElements.length;i < n;i++)
- destAlphaElements[i]=this._alphaElements[i];
- destGradientDataColor._colorRGBKeysCount=this._colorRGBKeysCount;
- var destRGBElements=destGradientDataColor._rgbElements;
- destRGBElements.length=this._rgbElements.length;
- for (i=0,n=this._rgbElements.length;i < n;i++)
- destRGBElements[i]=this._rgbElements[i];
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var destGradientDataColor=new Gradient(this._maxColorRGBKeysCount,this._maxColorAlphaKeysCount);
- this.cloneTo(destGradientDataColor);
- return destGradientDataColor;
- }
- /**
- *获取颜色RGB数量。
- *@return 颜色RGB数量。
- */
- __getset(0,__proto,'colorRGBKeysCount',function(){
- return this._colorRGBKeysCount / 4;
- });
- /**
- *设置梯度模式。
- *@param value 梯度模式。
- */
- /**
- *获取梯度模式。
- *@return 梯度模式。
- */
- __getset(0,__proto,'mode',function(){
- return this._mode;
- },function(value){
- this._mode=value;
- });
- /**
- *获取颜色Alpha数量。
- *@return 颜色Alpha数量。
- */
- __getset(0,__proto,'colorAlphaKeysCount',function(){
- return this._colorAlphaKeysCount / 2;
- });
- /**
- *获取最大颜色RGB帧数量。
- *@return 最大RGB帧数量。
- */
- __getset(0,__proto,'maxColorRGBKeysCount',function(){
- return this._maxColorRGBKeysCount;
- });
- /**
- *获取最大颜色Alpha帧数量。
- *@return 最大Alpha帧数量。
- */
- __getset(0,__proto,'maxColorAlphaKeysCount',function(){
- return this._maxColorAlphaKeysCount;
- });
- return Gradient;
- })()
- /**
- *<code>Quaternion</code> 类用于创建四元数。
- */
- //class laya.d3.math.Quaternion
- var Quaternion=(function(){
- function Quaternion(x,y,z,w,nativeElements){
- /**X轴坐标*/
- //this.x=NaN;
- /**Y轴坐标*/
- //this.y=NaN;
- /**Z轴坐标*/
- //this.z=NaN;
- /**W轴坐标*/
- //this.w=NaN;
- (x===void 0)&& (x=0);
- (y===void 0)&& (y=0);
- (z===void 0)&& (z=0);
- (w===void 0)&& (w=1);
- this.x=x;
- this.y=y;
- this.z=z;
- this.w=w;
- }
- __class(Quaternion,'laya.d3.math.Quaternion');
- var __proto=Quaternion.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *根据缩放值缩放四元数
- *@param scale 缩放值
- *@param out 输出四元数
- */
- __proto.scaling=function(scaling,out){
- out.x=this.x *scaling;
- out.y=this.y *scaling;
- out.z=this.z *scaling;
- out.w=this.w *scaling;
- }
- /**
- *归一化四元数
- *@param out 输出四元数
- */
- __proto.normalize=function(out){
- var len=this.x *this.x+this.y *this.y+this.z *this.z+this.w *this.w;
- if (len > 0){
- len=1 / Math.sqrt(len);
- out.x=this.x *len;
- out.y=this.y *len;
- out.z=this.z *len;
- out.w=this.w *len;
- }
- }
- /**
- *计算四元数的长度
- *@return 长度
- */
- __proto.length=function(){
- return Math.sqrt(this.x *this.x+this.y *this.y+this.z *this.z+this.w *this.w);
- }
- /**
- *根据绕X轴的角度旋转四元数
- *@param rad 角度
- *@param out 输出四元数
- */
- __proto.rotateX=function(rad,out){
- rad *=0.5;
- var bx=Math.sin(rad),bw=Math.cos(rad);
- out.x=this.x *bw+this.w *bx;
- out.y=this.y *bw+this.z *bx;
- out.z=this.z *bw-this.y *bx;
- out.w=this.w *bw-this.x *bx;
- }
- /**
- *根据绕Y轴的制定角度旋转四元数
- *@param rad 角度
- *@param out 输出四元数
- */
- __proto.rotateY=function(rad,out){
- rad *=0.5;
- var by=Math.sin(rad),bw=Math.cos(rad);
- out.x=this.x *bw-this.z *by;
- out.y=this.y *bw+this.w *by;
- out.z=this.z *bw+this.x *by;
- out.w=this.w *bw-this.y *by;
- }
- /**
- *根据绕Z轴的制定角度旋转四元数
- *@param rad 角度
- *@param out 输出四元数
- */
- __proto.rotateZ=function(rad,out){
- rad *=0.5;
- var bz=Math.sin(rad),bw=Math.cos(rad);
- out.x=this.x *bw+this.y *bz;
- out.y=this.y *bw-this.x *bz;
- out.z=this.z *bw+this.w *bz;
- out.w=this.w *bw-this.z *bz;
- }
- /**
- *分解四元数到欧拉角(顺序为Yaw、Pitch、Roll),参考自http://xboxforums.create.msdn.com/forums/p/4574/23988.aspx#23988,问题绕X轴翻转超过±90度时有,会产生瞬间反转
- *@param quaternion 源四元数
- *@param out 欧拉角值
- */
- __proto.getYawPitchRoll=function(out){
- Vector3.transformQuat(Vector3._ForwardRH,this,Quaternion.TEMPVector31);
- Vector3.transformQuat(Vector3._Up,this,Quaternion.TEMPVector32);
- var upe=Quaternion.TEMPVector32;
- Quaternion.angleTo(Vector3._ZERO,Quaternion.TEMPVector31,Quaternion.TEMPVector33);
- var angle=Quaternion.TEMPVector33;
- if (angle.x==Math.PI / 2){
- angle.y=Quaternion.arcTanAngle(upe.z,upe.x);
- angle.z=0;
- }else if (angle.x==-Math.PI / 2){
- angle.y=Quaternion.arcTanAngle(-upe.z,-upe.x);
- angle.z=0;
- }else {
- Matrix4x4.createRotationY(-angle.y,Quaternion.TEMPMatrix0);
- Matrix4x4.createRotationX(-angle.x,Quaternion.TEMPMatrix1);
- Vector3.transformCoordinate(Quaternion.TEMPVector32,Quaternion.TEMPMatrix0,Quaternion.TEMPVector32);
- Vector3.transformCoordinate(Quaternion.TEMPVector32,Quaternion.TEMPMatrix1,Quaternion.TEMPVector32);
- angle.z=Quaternion.arcTanAngle(upe.y,-upe.x);
- }
- if (angle.y <=-Math.PI)
- angle.y=Math.PI;
- if (angle.z <=-Math.PI)
- angle.z=Math.PI;
- if (angle.y >=Math.PI && angle.z >=Math.PI){
- angle.y=0;
- angle.z=0;
- angle.x=Math.PI-angle.x;
- };
- var oe=out;
- oe.x=angle.y;
- oe.y=angle.x;
- oe.z=angle.z;
- }
- /**
- *求四元数的逆
- *@param out 输出四元数
- */
- __proto.invert=function(out){
- var a0=this.x,a1=this.y,a2=this.z,a3=this.w;
- var dot=a0 *a0+a1 *a1+a2 *a2+a3 *a3;
- var invDot=dot ? 1.0 / dot :0;
- out.x=-a0 *invDot;
- out.y=-a1 *invDot;
- out.z=-a2 *invDot;
- out.w=a3 *invDot;
- }
- /**
- *设置四元数为单位算数
- *@param out 输出四元数
- */
- __proto.identity=function(){
- this.x=0;
- this.y=0;
- this.z=0;
- this.w=1;
- }
- /**
- *从Array数组拷贝值。
- *@param array 数组。
- *@param offset 数组偏移。
- */
- __proto.fromArray=function(array,offset){
- (offset===void 0)&& (offset=0);
- this.x=array[offset+0];
- this.y=array[offset+1];
- this.z=array[offset+2];
- this.w=array[offset+3];
- }
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- if (this===destObject){
- return;
- }
- destObject.x=this.x;
- destObject.y=this.y;
- destObject.z=this.z;
- destObject.w=this.w;
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var dest=/*__JS__ */new this.constructor();
- this.cloneTo(dest);
- return dest;
- }
- __proto.equals=function(b){
- 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);
- }
- /**
- *计算长度的平方。
- *@return 长度的平方。
- */
- __proto.lengthSquared=function(){
- return (this.x *this.x)+(this.y *this.y)+(this.z *this.z)+(this.w *this.w);
- }
- __proto.forNativeElement=function(nativeElements){
- if (nativeElements){
- /*__JS__ */this.elements=nativeElements;
- /*__JS__ */this.elements[0]=this.x;
- /*__JS__ */this.elements[1]=this.y;
- /*__JS__ */this.elements[2]=this.z;
- /*__JS__ */this.elements[3]=this.w;
- }
- else{
- /*__JS__ */this.elements=new Float32Array([this.x,this.y,this.z,this.w]);
- }
- Vector2.rewriteNumProperty(this,"x",0);
- Vector2.rewriteNumProperty(this,"y",1);
- Vector2.rewriteNumProperty(this,"z",2);
- Vector2.rewriteNumProperty(this,"w",3);
- }
- Quaternion.createFromYawPitchRoll=function(yaw,pitch,roll,out){
- var halfRoll=roll *0.5;
- var halfPitch=pitch *0.5;
- var halfYaw=yaw *0.5;
- var sinRoll=Math.sin(halfRoll);
- var cosRoll=Math.cos(halfRoll);
- var sinPitch=Math.sin(halfPitch);
- var cosPitch=Math.cos(halfPitch);
- var sinYaw=Math.sin(halfYaw);
- var cosYaw=Math.cos(halfYaw);
- out.x=(cosYaw *sinPitch *cosRoll)+(sinYaw *cosPitch *sinRoll);
- out.y=(sinYaw *cosPitch *cosRoll)-(cosYaw *sinPitch *sinRoll);
- out.z=(cosYaw *cosPitch *sinRoll)-(sinYaw *sinPitch *cosRoll);
- out.w=(cosYaw *cosPitch *cosRoll)+(sinYaw *sinPitch *sinRoll);
- }
- Quaternion.multiply=function(left,right,out){
- var lx=left.x;
- var ly=left.y;
- var lz=left.z;
- var lw=left.w;
- var rx=right.x;
- var ry=right.y;
- var rz=right.z;
- var rw=right.w;
- var a=(ly *rz-lz *ry);
- var b=(lz *rx-lx *rz);
- var c=(lx *ry-ly *rx);
- var d=(lx *rx+ly *ry+lz *rz);
- out.x=(lx *rw+rx *lw)+a;
- out.y=(ly *rw+ry *lw)+b;
- out.z=(lz *rw+rz *lw)+c;
- out.w=lw *rw-d;
- }
- Quaternion.arcTanAngle=function(x,y){
- if (x==0){
- if (y==1)
- return Math.PI / 2;
- return-Math.PI / 2;
- }
- if (x > 0)
- return Math.atan(y / x);
- if (x < 0){
- if (y > 0)
- return Math.atan(y / x)+Math.PI;
- return Math.atan(y / x)-Math.PI;
- }
- return 0;
- }
- Quaternion.angleTo=function(from,location,angle){
- Vector3.subtract(location,from,Quaternion.TEMPVector30);
- Vector3.normalize(Quaternion.TEMPVector30,Quaternion.TEMPVector30);
- angle.x=Math.asin(Quaternion.TEMPVector30.y);
- angle.y=Quaternion.arcTanAngle(-Quaternion.TEMPVector30.z,-Quaternion.TEMPVector30.x);
- }
- Quaternion.createFromAxisAngle=function(axis,rad,out){
- rad=rad *0.5;
- var s=Math.sin(rad);
- out.x=s *axis.x;
- out.y=s *axis.y;
- out.z=s *axis.z;
- out.w=Math.cos(rad);
- }
- Quaternion.createFromMatrix4x4=function(mat,out){
- var me=mat.elements;
- var sqrt;
- var half;
- var scale=me[0]+me[5]+me[10];
- if (scale > 0.0){
- sqrt=Math.sqrt(scale+1.0);
- out.w=sqrt *0.5;
- sqrt=0.5 / sqrt;
- out.x=(me[6]-me[9])*sqrt;
- out.y=(me[8]-me[2])*sqrt;
- out.z=(me[1]-me[4])*sqrt;
- }else if ((me[0] >=me[5])&& (me[0] >=me[10])){
- sqrt=Math.sqrt(1.0+me[0]-me[5]-me[10]);
- half=0.5 / sqrt;
- out.x=0.5 *sqrt;
- out.y=(me[1]+me[4])*half;
- out.z=(me[2]+me[8])*half;
- out.w=(me[6]-me[9])*half;
- }else if (me[5] > me[10]){
- sqrt=Math.sqrt(1.0+me[5]-me[0]-me[10]);
- half=0.5 / sqrt;
- out.x=(me[4]+me[1])*half;
- out.y=0.5 *sqrt;
- out.z=(me[9]+me[6])*half;
- out.w=(me[8]-me[2])*half;
- }else {
- sqrt=Math.sqrt(1.0+me[10]-me[0]-me[5]);
- half=0.5 / sqrt;
- out.x=(me[8]+me[2])*half;
- out.y=(me[9]+me[6])*half;
- out.z=0.5 *sqrt;
- out.w=(me[1]-me[4])*half;
- }
- }
- Quaternion.slerp=function(left,right,t,out){
- 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;
- var omega,cosom,sinom,scale0,scale1;
- cosom=ax *bx+ay *by+az *bz+aw *bw;
- if (cosom < 0.0){
- cosom=-cosom;
- bx=-bx;
- by=-by;
- bz=-bz;
- bw=-bw;
- }
- if ((1.0-cosom)> 0.000001){
- omega=Math.acos(cosom);
- sinom=Math.sin(omega);
- scale0=Math.sin((1.0-t)*omega)/ sinom;
- scale1=Math.sin(t *omega)/ sinom;
- }else {
- scale0=1.0-t;
- scale1=t;
- }
- out.x=scale0 *ax+scale1 *bx;
- out.y=scale0 *ay+scale1 *by;
- out.z=scale0 *az+scale1 *bz;
- out.w=scale0 *aw+scale1 *bw;
- return out;
- }
- Quaternion.lerp=function(left,right,amount,out){
- var inverse=1.0-amount;
- if (Quaternion.dot(left,right)>=0){
- out.x=(inverse *left.x)+(amount *right.x);
- out.y=(inverse *left.y)+(amount *right.y);
- out.z=(inverse *left.z)+(amount *right.z);
- out.w=(inverse *left.w)+(amount *right.w);
- }else {
- out.x=(inverse *left.x)-(amount *right.x);
- out.y=(inverse *left.y)-(amount *right.y);
- out.z=(inverse *left.z)-(amount *right.z);
- out.w=(inverse *left.w)-(amount *right.w);
- }
- out.normalize(out);
- }
- Quaternion.add=function(left,right,out){
- out.x=left.x+right.x;
- out.y=left.y+right.y;
- out.z=left.z+right.z;
- out.w=left.w+right.w;
- }
- Quaternion.dot=function(left,right){
- return left.x *right.x+left.y *right.y+left.z *right.z+left.w *right.w;
- }
- Quaternion.rotationLookAt=function(forward,up,out){
- Quaternion.lookAt(Vector3._ZERO,forward,up,out);
- }
- Quaternion.lookAt=function(eye,target,up,out){
- Matrix3x3.lookAt(eye,target,up,Quaternion._tempMatrix3x3);
- Quaternion.rotationMatrix(Quaternion._tempMatrix3x3,out);
- }
- Quaternion.invert=function(value,out){
- var lengthSq=value.lengthSquared();
- if (!MathUtils3D.isZero(lengthSq)){
- lengthSq=1.0 / lengthSq;
- out.x=-value.x *lengthSq;
- out.y=-value.y *lengthSq;
- out.z=-value.z *lengthSq;
- out.w=value.w *lengthSq;
- }
- }
- Quaternion.rotationMatrix=function(matrix3x3,out){
- var me=matrix3x3.elements;
- var m11=me[0];
- var m12=me[1];
- var m13=me[2];
- var m21=me[3];
- var m22=me[4];
- var m23=me[5];
- var m31=me[6];
- var m32=me[7];
- var m33=me[8];
- var sqrt=NaN,half=NaN;
- var scale=m11+m22+m33;
- if (scale > 0){
- sqrt=Math.sqrt(scale+1);
- out.w=sqrt *0.5;
- sqrt=0.5 / sqrt;
- out.x=(m23-m32)*sqrt;
- out.y=(m31-m13)*sqrt;
- out.z=(m12-m21)*sqrt;
- }else if ((m11 >=m22)&& (m11 >=m33)){
- sqrt=Math.sqrt(1+m11-m22-m33);
- half=0.5 / sqrt;
- out.x=0.5 *sqrt;
- out.y=(m12+m21)*half;
- out.z=(m13+m31)*half;
- out.w=(m23-m32)*half;
- }else if (m22 > m33){
- sqrt=Math.sqrt(1+m22-m11-m33);
- half=0.5 / sqrt;
- out.x=(m21+m12)*half;
- out.y=0.5 *sqrt;
- out.z=(m32+m23)*half;
- out.w=(m31-m13)*half;
- }else {
- sqrt=Math.sqrt(1+m33-m11-m22);
- half=0.5 / sqrt;
- out.x=(m31+m13)*half;
- out.y=(m32+m23)*half;
- out.z=0.5 *sqrt;
- out.w=(m12-m21)*half;
- }
- }
- Quaternion.DEFAULT=new Quaternion();
- __static(Quaternion,
- ['TEMPVector30',function(){return this.TEMPVector30=new Vector3();},'TEMPVector31',function(){return this.TEMPVector31=new Vector3();},'TEMPVector32',function(){return this.TEMPVector32=new Vector3();},'TEMPVector33',function(){return this.TEMPVector33=new Vector3();},'TEMPMatrix0',function(){return this.TEMPMatrix0=new Matrix4x4();},'TEMPMatrix1',function(){return this.TEMPMatrix1=new Matrix4x4();},'_tempMatrix3x3',function(){return this._tempMatrix3x3=new Matrix3x3();},'NAN',function(){return this.NAN=new Quaternion(NaN,NaN,NaN,NaN);}
- ]);
- return Quaternion;
- })()
- /**
- *@private
- */
- //class laya.d3.shader.ShaderData
- var ShaderData=(function(){
- function ShaderData(ownerResource){
- /**@private */
- this._ownerResource=null;
- /**@private */
- this._data=null;
- /**@private [NATIVE]*/
- this._int32Data=null;
- /**@private [NATIVE]*/
- this._float32Data=null;
- /**@private [NATIVE]*/
- this._nativeArray=null;
- /**@private [NATIVE]*/
- this._frameCount=0;
- /**@private [NATIVE]*/
- this._runtimeCopyValues=[];
- this._ownerResource=ownerResource;
- this._initData();
- }
- __class(ShaderData,'laya.d3.shader.ShaderData');
- var __proto=ShaderData.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *@private
- */
- __proto._initData=function(){
- this._data=new Object();
- }
- /**
- *@private
- */
- __proto.getData=function(){
- return this._data;
- }
- /**
- *获取布尔。
- *@param index shader索引。
- *@return 布尔。
- */
- __proto.getBool=function(index){
- return this._data[index];
- }
- /**
- *设置布尔。
- *@param index shader索引。
- *@param value 布尔。
- */
- __proto.setBool=function(index,value){
- this._data[index]=value;
- }
- /**
- *获取整形。
- *@param index shader索引。
- *@return 整形。
- */
- __proto.getInt=function(index){
- return this._data[index];
- }
- /**
- *设置整型。
- *@param index shader索引。
- *@param value 整形。
- */
- __proto.setInt=function(index,value){
- this._data[index]=value;
- }
- /**
- *获取浮点。
- *@param index shader索引。
- *@return 浮点。
- */
- __proto.getNumber=function(index){
- return this._data[index];
- }
- /**
- *设置浮点。
- *@param index shader索引。
- *@param value 浮点。
- */
- __proto.setNumber=function(index,value){
- this._data[index]=value;
- }
- /**
- *获取Vector2向量。
- *@param index shader索引。
- *@return Vector2向量。
- */
- __proto.getVector2=function(index){
- return this._data[index];
- }
- /**
- *设置Vector2向量。
- *@param index shader索引。
- *@param value Vector2向量。
- */
- __proto.setVector2=function(index,value){
- this._data[index]=value;
- }
- /**
- *获取Vector3向量。
- *@param index shader索引。
- *@return Vector3向量。
- */
- __proto.getVector3=function(index){
- return this._data[index];
- }
- /**
- *设置Vector3向量。
- *@param index shader索引。
- *@param value Vector3向量。
- */
- __proto.setVector3=function(index,value){
- this._data[index]=value;
- }
- /**
- *获取颜色。
- *@param index shader索引。
- *@return 颜色向量。
- */
- __proto.getVector=function(index){
- return this._data[index];
- }
- /**
- *设置向量。
- *@param index shader索引。
- *@param value 向量。
- */
- __proto.setVector=function(index,value){
- this._data[index]=value;
- }
- /**
- *获取四元数。
- *@param index shader索引。
- *@return 四元。
- */
- __proto.getQuaternion=function(index){
- return this._data[index];
- }
- /**
- *设置四元数。
- *@param index shader索引。
- *@param value 四元数。
- */
- __proto.setQuaternion=function(index,value){
- this._data[index]=value;
- }
- /**
- *获取矩阵。
- *@param index shader索引。
- *@return 矩阵。
- */
- __proto.getMatrix4x4=function(index){
- return this._data[index];
- }
- /**
- *设置矩阵。
- *@param index shader索引。
- *@param value 矩阵。
- */
- __proto.setMatrix4x4=function(index,value){
- this._data[index]=value;
- }
- /**
- *获取Buffer。
- *@param index shader索引。
- *@return
- */
- __proto.getBuffer=function(shaderIndex){
- return this._data[shaderIndex];
- }
- /**
- *设置Buffer。
- *@param index shader索引。
- *@param value buffer数据。
- */
- __proto.setBuffer=function(index,value){
- this._data[index]=value;
- }
- /**
- *设置纹理。
- *@param index shader索引。
- *@param value 纹理。
- */
- __proto.setTexture=function(index,value){
- var lastValue=this._data[index];
- this._data[index]=value;
- if (this._ownerResource && this._ownerResource.referenceCount > 0){
- (lastValue)&& (lastValue._removeReference());
- (value)&& (value._addReference());
- }
- }
- /**
- *获取纹理。
- *@param index shader索引。
- *@return 纹理。
- */
- __proto.getTexture=function(index){
- return this._data[index];
- }
- /**
- *设置Attribute。
- *@param index shader索引。
- *@param value 纹理。
- */
- __proto.setAttribute=function(index,value){
- this._data[index]=value;
- }
- /**
- *获取Attribute。
- *@param index shader索引。
- *@return 纹理。
- */
- __proto.getAttribute=function(index){
- return this._data[index];
- }
- /**
- *获取长度。
- *@return 长度。
- */
- __proto.getLength=function(){
- return this._data.length;
- }
- /**
- *设置长度。
- *@param 长度。
- */
- __proto.setLength=function(value){
- this._data.length=value;
- }
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var dest=destObject;
- var destData=dest._data;
- for (var k in this._data){
- var value=this._data[k];
- if (value !=null){
- if ((typeof value=='number')){
- destData[k]=value;
- }else if (((typeof value=='number')&& Math.floor(value)==value)){
- destData[k]=value;
- }else if ((typeof value=='boolean')){
- destData[k]=value;
- }else if ((value instanceof laya.d3.math.Vector2 )){
- var v2=(destData[k])|| (destData[k]=new Vector2());
- (value).cloneTo(v2);
- destData[k]=v2;
- }else if ((value instanceof laya.d3.math.Vector3 )){
- var v3=(destData[k])|| (destData[k]=new Vector3());
- (value).cloneTo(v3);
- destData[k]=v3;
- }else if ((value instanceof laya.d3.math.Vector4 )){
- var v4=(destData[k])|| (destData[k]=new Vector4());
- (value).cloneTo(v4);
- destData[k]=v4;
- }else if ((value instanceof laya.d3.math.Matrix4x4 )){
- var mat=(destData[k])|| (destData[k]=new Matrix4x4());
- (value).cloneTo(mat);
- destData[k]=mat;
- }else if ((value instanceof laya.resource.BaseTexture )){
- destData[k]=value;
- }
- }
- }
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var dest=/*__JS__ */new this.constructor();
- this.cloneTo(dest);
- return dest;
- }
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneToForNative=function(destObject){
- var dest=destObject;
- var diffSize=this._int32Data.length-dest._int32Data.length;
- if (diffSize > 0){
- dest.needRenewArrayBufferForNative(this._int32Data.length);
- }
- dest._int32Data.set(this._int32Data,0);
- var destData=dest._nativeArray;
- var dataCount=this._nativeArray.length;
- destData.length=dataCount;
- for (var i=0;i < dataCount;i++){
- var value=this._nativeArray[i];
- if (value){
- if ((typeof value=='number')){
- destData[i]=value;
- dest.setNumber(i,value);
- }else if (((typeof value=='number')&& Math.floor(value)==value)){
- destData[i]=value;
- dest.setInt(i,value);
- }else if ((typeof value=='boolean')){
- destData[i]=value;
- dest.setBool(i,value);
- }else if ((value instanceof laya.d3.math.Vector2 )){
- var v2=(destData[i])|| (destData[i]=new Vector2());
- (value).cloneTo(v2);
- destData[i]=v2;
- dest.setVector2(i,v2);
- }else if ((value instanceof laya.d3.math.Vector3 )){
- var v3=(destData[i])|| (destData[i]=new Vector3());
- (value).cloneTo(v3);
- destData[i]=v3;
- dest.setVector3(i,v3);
- }else if ((value instanceof laya.d3.math.Vector4 )){
- var v4=(destData[i])|| (destData[i]=new Vector4());
- (value).cloneTo(v4);
- destData[i]=v4;
- dest.setVector(i,v4);
- }else if ((value instanceof laya.d3.math.Matrix4x4 )){
- var mat=(destData[i])|| (destData[i]=new Matrix4x4());
- (value).cloneTo(mat);
- destData[i]=mat;
- dest.setMatrix4x4(i,mat);
- }else if ((value instanceof laya.resource.BaseTexture )){
- destData[i]=value;
- dest.setTexture(i,value);
- }
- }
- }
- }
- /**
- *@private [NATIVE]
- */
- __proto._initDataForNative=function(){
- var length=8;
- if (!length){
- alert("ShaderData _initDataForNative error length=0");
- }
- this._frameCount=-1;
- this._runtimeCopyValues.length=0;
- this._nativeArray=[];
- this._data=new ArrayBuffer(length *4);
- this._int32Data=new Int32Array(this._data);
- this._float32Data=new Float32Array(this._data);
- LayaGL.createArrayBufferRef(this._data,/*laya.layagl.LayaGL.ARRAY_BUFFER_TYPE_DATA*/0,true);
- }
- __proto.needRenewArrayBufferForNative=function(index){
- if (index >=this._int32Data.length){
- var nByteLen=(index+1)*4;
- var pre=this._int32Data;
- var preConchRef=this._data["conchRef"];
- var prePtrID=this._data["_ptrID"];
- this._data=new ArrayBuffer(nByteLen);
- this._int32Data=new Int32Array(this._data);
- this._float32Data=new Float32Array(this._data);
- this._data["conchRef"]=preConchRef;
- this._data["_ptrID"]=prePtrID;
- pre && this._int32Data.set(pre,0);
- /*__JS__ */conch.updateArrayBufferRef(this._data['_ptrID'],preConchRef.isSyncToRender(),this._data);
- }
- }
- __proto.getDataForNative=function(){
- return this._nativeArray;
- }
- /**
- *@private [NATIVE]
- */
- __proto.getIntForNative=function(index){
- return this._int32Data[index];
- }
- /**
- *@private [NATIVE]
- */
- __proto.setIntForNative=function(index,value){
- this.needRenewArrayBufferForNative(index);
- this._int32Data[index]=value;
- this._nativeArray[index]=value;
- }
- /**
- *@private [NATIVE]
- */
- __proto.getBoolForNative=function(index){
- return this._int32Data[index]==1;
- }
- /**
- *@private [NATIVE]
- */
- __proto.setBoolForNative=function(index,value){
- this.needRenewArrayBufferForNative(index);
- this._int32Data[index]=value;
- this._nativeArray[index]=value;
- }
- /**
- *@private [NATIVE]
- */
- __proto.getNumberForNative=function(index){
- return this._float32Data[index];
- }
- /**
- *@private [NATIVE]
- */
- __proto.setNumberForNative=function(index,value){
- this.needRenewArrayBufferForNative(index);
- this._float32Data[index]=value;
- this._nativeArray[index]=value;
- }
- /**
- *@private [NATIVE]
- */
- __proto.getMatrix4x4ForNative=function(index){
- return this._nativeArray[index];
- }
- /**
- *@private [NATIVE]
- */
- __proto.setMatrix4x4ForNative=function(index,value){
- this.needRenewArrayBufferForNative(index);
- this._nativeArray[index]=value;
- var nPtrID=this.setReferenceForNative(value.elements);
- this._int32Data[index]=nPtrID;
- }
- /**
- *@private [NATIVE]
- */
- __proto.getVectorForNative=function(index){
- return this._nativeArray[index];
- }
- /**
- *@private [NATIVE]
- */
- __proto.setVectorForNative=function(index,value){
- this.needRenewArrayBufferForNative(index);
- this._nativeArray[index]=value;
- if (!value.elements){
- value.forNativeElement();
- };
- var nPtrID=this.setReferenceForNative(value.elements);
- this._int32Data[index]=nPtrID;
- }
- /**
- *@private [NATIVE]
- */
- __proto.getVector2ForNative=function(index){
- return this._nativeArray[index];
- }
- /**
- *@private [NATIVE]
- */
- __proto.setVector2ForNative=function(index,value){
- this.needRenewArrayBufferForNative(index);
- this._nativeArray[index]=value;
- if (!value.elements){
- value.forNativeElement();
- };
- var nPtrID=this.setReferenceForNative(value.elements);
- this._int32Data[index]=nPtrID;
- }
- /**
- *@private [NATIVE]
- */
- __proto.getVector3ForNative=function(index){
- return this._nativeArray[index];
- }
- /**
- *@private [NATIVE]
- */
- __proto.setVector3ForNative=function(index,value){
- this.needRenewArrayBufferForNative(index);
- this._nativeArray[index]=value;
- if (!value.elements){
- value.forNativeElement();
- };
- var nPtrID=this.setReferenceForNative(value.elements);
- this._int32Data[index]=nPtrID;
- }
- /**
- *@private [NATIVE]
- */
- __proto.getQuaternionForNative=function(index){
- return this._nativeArray[index];
- }
- /**
- *@private [NATIVE]
- */
- __proto.setQuaternionForNative=function(index,value){
- this.needRenewArrayBufferForNative(index);
- this._nativeArray[index]=value;
- if (!value.elements){
- value.forNativeElement();
- };
- var nPtrID=this.setReferenceForNative(value.elements);
- this._int32Data[index]=nPtrID;
- }
- /**
- *@private [NATIVE]
- */
- __proto.getBufferForNative=function(shaderIndex){
- return this._nativeArray[shaderIndex];
- }
- /**
- *@private [NATIVE]
- */
- __proto.setBufferForNative=function(index,value){
- this.needRenewArrayBufferForNative(index);
- this._nativeArray[index]=value;
- var nPtrID=this.setReferenceForNative(value);
- this._int32Data[index]=nPtrID;
- }
- /**
- *@private [NATIVE]
- */
- __proto.getAttributeForNative=function(index){
- return this._nativeArray[index];
- }
- /**
- *@private [NATIVE]
- */
- __proto.setAttributeForNative=function(index,value){
- this._nativeArray[index]=value;
- if (!value["_ptrID"]){
- LayaGL.createArrayBufferRef(value,/*laya.layagl.LayaGL.ARRAY_BUFFER_TYPE_DATA*/0,true);
- }
- LayaGL.syncBufferToRenderThread(value);
- this._int32Data[index]=value["_ptrID"];
- }
- /**
- *@private [NATIVE]
- */
- __proto.getTextureForNative=function(index){
- return this._nativeArray[index];
- }
- /**
- *@private [NATIVE]
- */
- __proto.setTextureForNative=function(index,value){
- if (!value)return;
- this.needRenewArrayBufferForNative(index);
- var lastValue=this._nativeArray[index];
- this._nativeArray[index]=value;
- this._int32Data[index]=(value)._glTexture.id;
- if (this._ownerResource && this._ownerResource.referenceCount > 0){
- (lastValue)&& (lastValue._removeReference());
- (value)&& (value._addReference());
- }
- }
- __proto.setReferenceForNative=function(value){
- this.clearRuntimeCopyArray();
- var nRefID=0;
- var nPtrID=0;
- if (ShaderData._SET_RUNTIME_VALUE_MODE_REFERENCE_){
- LayaGL.createArrayBufferRefs(value,/*laya.layagl.LayaGL.ARRAY_BUFFER_TYPE_DATA*/0,true,/*laya.layagl.LayaGL.ARRAY_BUFFER_REF_REFERENCE*/0);
- nRefID=0;
- nPtrID=value.getPtrID(nRefID);
- }else {
- LayaGL.createArrayBufferRefs(value,/*laya.layagl.LayaGL.ARRAY_BUFFER_TYPE_DATA*/0,true,/*laya.layagl.LayaGL.ARRAY_BUFFER_REF_COPY*/1);
- nRefID=value.getRefNum()-1;
- nPtrID=value.getPtrID(nRefID);
- this._runtimeCopyValues.push({"obj":value,"refID":nRefID,"ptrID":nPtrID});
- }
- LayaGL.syncBufferToRenderThread(value,nRefID);
- return nPtrID;
- }
- __proto.clearRuntimeCopyArray=function(){
- var currentFrame=LayaGL.getFrameCount();
- if (this._frameCount !=currentFrame){
- this._frameCount=currentFrame;
- for (var i=0,n=this._runtimeCopyValues.length;i < n;i++){
- var obj=this._runtimeCopyValues[i];
- obj.obj.clearRefNum();
- }
- this._runtimeCopyValues.length=0;
- }
- }
- ShaderData.setRuntimeValueMode=function(bReference){
- ShaderData._SET_RUNTIME_VALUE_MODE_REFERENCE_=bReference;
- }
- ShaderData._SET_RUNTIME_VALUE_MODE_REFERENCE_=true;
- return ShaderData;
- })()
- /**
- *<code>TerrainLeaf</code> Terrain的叶子节点
- */
- //class laya.d3.terrain.TerrainLeaf
- var TerrainLeaf=(function(){
- function TerrainLeaf(){
- this._boundingSphere=null;
- this._boundingBox=null;
- this._sizeOfY=null;
- this._currentLODLevel=0;
- this._lastDistanceToEye=NaN;
- this._originalBoundingSphere=null;
- this._originalBoundingBox=null;
- this._originalBoundingBoxCorners=null;
- this._bUseStrip=false;
- this._gridSize=NaN;
- this._beginGridX=0;
- //针对整个大地形的偏移
- this._beginGridZ=0;
- //针对整个大地形的偏移
- this._LODError=null;
- TerrainLeaf.__init__();
- this._currentLODLevel=0;
- }
- __class(TerrainLeaf,'laya.d3.terrain.TerrainLeaf');
- var __proto=TerrainLeaf.prototype;
- __proto.calcVertextNorml=function(x,z,terrainHeightData,heighDataWidth,heightDataHeight,normal){
- var dZ=0,dX=0;
- dX=TerrainLeaf.getHeightFromTerrainHeightData(x-1,z-1,terrainHeightData,heighDataWidth,heightDataHeight)*-1.0;
- dX+=TerrainLeaf.getHeightFromTerrainHeightData(x-1,z,terrainHeightData,heighDataWidth,heightDataHeight)*-1.0;
- dX+=TerrainLeaf.getHeightFromTerrainHeightData(x-1,z+1,terrainHeightData,heighDataWidth,heightDataHeight)*-1.0;
- dX+=TerrainLeaf.getHeightFromTerrainHeightData(x+1,z-1,terrainHeightData,heighDataWidth,heightDataHeight)*1.0;
- dX+=TerrainLeaf.getHeightFromTerrainHeightData(x+1,z,terrainHeightData,heighDataWidth,heightDataHeight)*1.0;
- dX+=TerrainLeaf.getHeightFromTerrainHeightData(x+1,z+1,terrainHeightData,heighDataWidth,heightDataHeight)*1.0;
- dZ=TerrainLeaf.getHeightFromTerrainHeightData(x-1,z-1,terrainHeightData,heighDataWidth,heightDataHeight)*-1.0;
- dZ+=TerrainLeaf.getHeightFromTerrainHeightData(x,z-1,terrainHeightData,heighDataWidth,heightDataHeight)*-1.0;
- dZ+=TerrainLeaf.getHeightFromTerrainHeightData(x+1,z-1,terrainHeightData,heighDataWidth,heightDataHeight)*-1.0;
- dZ+=TerrainLeaf.getHeightFromTerrainHeightData(x-1,z+1,terrainHeightData,heighDataWidth,heightDataHeight)*1.0;
- dZ+=TerrainLeaf.getHeightFromTerrainHeightData(x,z+1,terrainHeightData,heighDataWidth,heightDataHeight)*1.0;
- dZ+=TerrainLeaf.getHeightFromTerrainHeightData(x+1,z+1,terrainHeightData,heighDataWidth,heightDataHeight)*1.0;
- normal.x=-dX;
- normal.y=6;
- normal.z=-dZ;
- Vector3.normalize(normal,normal);
- }
- __proto.calcVertextNormlUV=function(x,z,terrainWidth,terrainHeight,normal){
- normal.x=x / terrainWidth;
- normal.y=z / terrainHeight;
- normal.z=z / terrainHeight;
- }
- __proto.calcVertextBuffer=function(offsetChunkX,offsetChunkZ,beginX,beginZ,girdSize,vertextBuffer,offset,strideSize,terrainHeightData,heighDataWidth,heightDataHeight,cameraCoordinateInverse){
- if (cameraCoordinateInverse==true && !TerrainLeaf.__ADAPT_MATRIX__){
- TerrainLeaf.__ADAPT_MATRIX__=new Matrix4x4();
- var mat=new Matrix4x4();
- Matrix4x4.createRotationY(Math.PI,TerrainLeaf.__ADAPT_MATRIX__);
- Matrix4x4.createTranslate(new Vector3(0,0,(heightDataHeight-1)*girdSize),mat);
- Matrix4x4.multiply(mat,TerrainLeaf.__ADAPT_MATRIX__,TerrainLeaf.__ADAPT_MATRIX__);
- TerrainLeaf.__ADAPT_MATRIX_INV__=new Matrix4x4();
- TerrainLeaf.__ADAPT_MATRIX__.invert(TerrainLeaf.__ADAPT_MATRIX_INV__);
- }
- this._gridSize=girdSize;
- this._beginGridX=offsetChunkX *TerrainLeaf.CHUNK_GRID_NUM+beginX;
- this._beginGridZ=offsetChunkZ *TerrainLeaf.CHUNK_GRID_NUM+beginZ;
- var nNum=offset *strideSize;
- var minY=2147483647;
- var maxY=-2147483648;
- var normal=new Vector3();
- for (var i=0,s=TerrainLeaf.LEAF_GRID_NUM+1;i < s;i++){
- for (var j=0,s1=TerrainLeaf.LEAF_GRID_NUM+1;j < s1;j++){
- TerrainLeaf.__VECTOR3__.x=(this._beginGridX+j)*this._gridSize;
- TerrainLeaf.__VECTOR3__.z=(this._beginGridZ+i)*this._gridSize;
- TerrainLeaf.__VECTOR3__.y=terrainHeightData[(this._beginGridZ+i)*(heighDataWidth)+(this._beginGridX+j)];
- minY=TerrainLeaf.__VECTOR3__.y < minY ? TerrainLeaf.__VECTOR3__.y :minY;
- maxY=TerrainLeaf.__VECTOR3__.y > maxY ? TerrainLeaf.__VECTOR3__.y :maxY;
- if (TerrainLeaf.__ADAPT_MATRIX__){
- Vector3.transformV3ToV3(TerrainLeaf.__VECTOR3__,TerrainLeaf.__ADAPT_MATRIX__,TerrainLeaf.__VECTOR3__);
- }
- vertextBuffer[nNum]=TerrainLeaf.__VECTOR3__.x;
- nNum++;
- vertextBuffer[nNum]=TerrainLeaf.__VECTOR3__.y;
- nNum++;
- vertextBuffer[nNum]=TerrainLeaf.__VECTOR3__.z;
- nNum++;
- this.calcVertextNormlUV(this._beginGridX+j,this._beginGridZ+i,heighDataWidth,heightDataHeight,normal);
- vertextBuffer[nNum]=normal.x;
- nNum++;
- vertextBuffer[nNum]=normal.y;
- nNum++;
- vertextBuffer[nNum]=normal.z;
- nNum++;
- vertextBuffer[nNum]=(beginX+j)/ TerrainLeaf.CHUNK_GRID_NUM;
- nNum++;
- vertextBuffer[nNum]=(beginZ+i)/ TerrainLeaf.CHUNK_GRID_NUM;
- nNum++;
- vertextBuffer[nNum]=this._beginGridX+j;
- nNum++;
- vertextBuffer[nNum]=this._beginGridZ+i;
- nNum++;
- }
- }
- this._sizeOfY=new Vector2(minY-1,maxY+1);
- this.calcLODErrors(terrainHeightData,heighDataWidth,heightDataHeight);
- this.calcOriginalBoudingBoxAndSphere();
- }
- __proto.calcSkirtVertextBuffer=function(offsetChunkX,offsetChunkZ,beginX,beginZ,girdSize,vertextBuffer,offset,strideSize,terrainHeightData,heighDataWidth,heightDataHeight){
- this._gridSize=girdSize;
- this._beginGridX=offsetChunkX *TerrainLeaf.CHUNK_GRID_NUM+beginX;
- this._beginGridZ=offsetChunkZ *TerrainLeaf.CHUNK_GRID_NUM+beginZ;
- var nNum=offset *strideSize;
- var i=0,j=0,s=TerrainLeaf.LEAF_GRID_NUM+1;
- var normal=new Vector3();
- var hZIndex=0;
- var hXIndex=0;
- var h=0;
- var zh=0;
- var xh=0;
- for (i=0;i < 2;i++){
- for (j=0;j < s;j++){
- TerrainLeaf.__VECTOR3__.x=(this._beginGridX+j)*this._gridSize;
- TerrainLeaf.__VECTOR3__.y=(i==1 ? terrainHeightData[this._beginGridZ *heighDataWidth+(this._beginGridX+j)] :-this._gridSize);
- TerrainLeaf.__VECTOR3__.z=(this._beginGridZ+0)*this._gridSize;
- if (TerrainLeaf.__ADAPT_MATRIX__){
- Vector3.transformV3ToV3(TerrainLeaf.__VECTOR3__,TerrainLeaf.__ADAPT_MATRIX__,TerrainLeaf.__VECTOR3__);
- }
- vertextBuffer[nNum]=TerrainLeaf.__VECTOR3__.x;
- nNum++;
- vertextBuffer[nNum]=TerrainLeaf.__VECTOR3__.y;
- nNum++;
- vertextBuffer[nNum]=TerrainLeaf.__VECTOR3__.z;
- nNum++;
- if (i==0){
- hZIndex=(this._beginGridZ-1);
- }else {
- hZIndex=this._beginGridZ;
- }
- this.calcVertextNormlUV(this._beginGridX+j,hZIndex,heighDataWidth,heightDataHeight,normal);
- vertextBuffer[nNum]=normal.x;
- nNum++;
- vertextBuffer[nNum]=normal.y;
- nNum++;
- vertextBuffer[nNum]=normal.z;
- nNum++;
- vertextBuffer[nNum]=(beginX+j)/ TerrainLeaf.CHUNK_GRID_NUM;
- nNum++;
- vertextBuffer[nNum]=(beginZ+0)/ TerrainLeaf.CHUNK_GRID_NUM;
- nNum++;
- vertextBuffer[nNum]=this._beginGridX+j;
- nNum++;
- vertextBuffer[nNum]=hZIndex;
- nNum++;
- }
- }
- for (i=0;i < 2;i++){
- for (j=0;j < s;j++){
- TerrainLeaf.__VECTOR3__.x=(this._beginGridX+j)*this._gridSize;
- TerrainLeaf.__VECTOR3__.y=(i==0 ? terrainHeightData[(this._beginGridZ+TerrainLeaf.LEAF_GRID_NUM)*(heighDataWidth)+(this._beginGridX+j)] :-this._gridSize);
- TerrainLeaf.__VECTOR3__.z=(this._beginGridZ+TerrainLeaf.LEAF_GRID_NUM)*this._gridSize;
- if (TerrainLeaf.__ADAPT_MATRIX__){
- Vector3.transformV3ToV3(TerrainLeaf.__VECTOR3__,TerrainLeaf.__ADAPT_MATRIX__,TerrainLeaf.__VECTOR3__);
- }
- vertextBuffer[nNum]=TerrainLeaf.__VECTOR3__.x;
- nNum++;
- vertextBuffer[nNum]=TerrainLeaf.__VECTOR3__.y;
- nNum++;
- vertextBuffer[nNum]=TerrainLeaf.__VECTOR3__.z;
- nNum++;
- if (i==0){
- hZIndex=this._beginGridZ+TerrainLeaf.LEAF_GRID_NUM;
- }else {
- hZIndex=(this._beginGridZ+TerrainLeaf.LEAF_GRID_NUM+1);
- }
- this.calcVertextNormlUV(this._beginGridX+j,hZIndex,heighDataWidth,heightDataHeight,normal);
- vertextBuffer[nNum]=normal.x;
- nNum++;
- vertextBuffer[nNum]=normal.y;
- nNum++;
- vertextBuffer[nNum]=normal.z;
- nNum++;
- vertextBuffer[nNum]=(beginX+j)/ TerrainLeaf.CHUNK_GRID_NUM;
- nNum++;
- vertextBuffer[nNum]=(beginZ+TerrainLeaf.LEAF_GRID_NUM)/ TerrainLeaf.CHUNK_GRID_NUM;
- nNum++;
- vertextBuffer[nNum]=this._beginGridX+j;
- nNum++;
- vertextBuffer[nNum]=hZIndex;
- nNum++;
- }
- }
- for (i=0;i < 2;i++){
- for (j=0;j < s;j++){
- TerrainLeaf.__VECTOR3__.x=(this._beginGridX+0)*this._gridSize;
- TerrainLeaf.__VECTOR3__.y=(i==0 ? terrainHeightData[(this._beginGridZ+j)*(heighDataWidth)+(this._beginGridX+0)] :-this._gridSize);
- TerrainLeaf.__VECTOR3__.z=(this._beginGridZ+j)*this._gridSize;
- if (TerrainLeaf.__ADAPT_MATRIX__){
- Vector3.transformV3ToV3(TerrainLeaf.__VECTOR3__,TerrainLeaf.__ADAPT_MATRIX__,TerrainLeaf.__VECTOR3__);
- }
- vertextBuffer[nNum]=TerrainLeaf.__VECTOR3__.x;
- nNum++;
- vertextBuffer[nNum]=TerrainLeaf.__VECTOR3__.y;
- nNum++;
- vertextBuffer[nNum]=TerrainLeaf.__VECTOR3__.z;
- nNum++;
- if (i==0){
- hXIndex=this._beginGridX;
- }else {
- hXIndex=(this._beginGridX-1);
- }
- this.calcVertextNormlUV(hXIndex,this._beginGridZ+j,heighDataWidth,heightDataHeight,normal);
- vertextBuffer[nNum]=normal.x;
- nNum++;
- vertextBuffer[nNum]=normal.y;
- nNum++;
- vertextBuffer[nNum]=normal.z;
- nNum++;
- vertextBuffer[nNum]=(beginX+0)/ TerrainLeaf.CHUNK_GRID_NUM;
- nNum++;
- vertextBuffer[nNum]=(beginZ+j)/ TerrainLeaf.CHUNK_GRID_NUM;
- nNum++;
- vertextBuffer[nNum]=hXIndex;
- nNum++;
- vertextBuffer[nNum]=this._beginGridZ+j;
- nNum++;
- }
- }
- for (i=0;i < 2;i++){
- for (j=0;j < s;j++){
- TerrainLeaf.__VECTOR3__.x=(this._beginGridX+TerrainLeaf.LEAF_GRID_NUM)*this._gridSize;
- TerrainLeaf.__VECTOR3__.y=(i==1 ? terrainHeightData[(this._beginGridZ+j)*(heighDataWidth)+(this._beginGridX+TerrainLeaf.LEAF_GRID_NUM)] :-this._gridSize);
- TerrainLeaf.__VECTOR3__.z=(this._beginGridZ+j)*this._gridSize;
- if (TerrainLeaf.__ADAPT_MATRIX__){
- Vector3.transformV3ToV3(TerrainLeaf.__VECTOR3__,TerrainLeaf.__ADAPT_MATRIX__,TerrainLeaf.__VECTOR3__);
- }
- vertextBuffer[nNum]=TerrainLeaf.__VECTOR3__.x;
- nNum++;
- vertextBuffer[nNum]=TerrainLeaf.__VECTOR3__.y;
- nNum++;
- vertextBuffer[nNum]=TerrainLeaf.__VECTOR3__.z;
- nNum++;
- if (i==0){
- hXIndex=this._beginGridX+TerrainLeaf.LEAF_GRID_NUM+1;
- }else {
- hXIndex=this._beginGridX+TerrainLeaf.LEAF_GRID_NUM;
- }
- this.calcVertextNormlUV(hXIndex,this._beginGridZ+j,heighDataWidth,heightDataHeight,normal);
- vertextBuffer[nNum]=normal.x;
- nNum++;
- vertextBuffer[nNum]=normal.y;
- nNum++;
- vertextBuffer[nNum]=normal.z;
- nNum++;
- vertextBuffer[nNum]=(beginX+TerrainLeaf.LEAF_GRID_NUM)/ TerrainLeaf.CHUNK_GRID_NUM;
- nNum++;
- vertextBuffer[nNum]=(beginZ+j)/ TerrainLeaf.CHUNK_GRID_NUM;
- nNum++;
- vertextBuffer[nNum]=hXIndex;
- nNum++;
- vertextBuffer[nNum]=this._beginGridZ+j;
- nNum++;
- }
- }
- }
- __proto.calcOriginalBoudingBoxAndSphere=function(){
- var min=new Vector3(this._beginGridX *this._gridSize,this._sizeOfY.x,this._beginGridZ *this._gridSize);
- var max=new Vector3((this._beginGridX+TerrainLeaf.LEAF_GRID_NUM)*this._gridSize,this._sizeOfY.y,(this._beginGridZ+TerrainLeaf.LEAF_GRID_NUM)*this._gridSize);
- if (TerrainLeaf.__ADAPT_MATRIX__){
- Vector3.transformV3ToV3(min,TerrainLeaf.__ADAPT_MATRIX__,min);
- Vector3.transformV3ToV3(max,TerrainLeaf.__ADAPT_MATRIX__,max);
- }
- this._originalBoundingBox=new BoundBox(min,max);
- var size=new Vector3();
- Vector3.subtract(max,min,size);
- Vector3.scale(size,0.5,size);
- var center=new Vector3();
- Vector3.add(min,size,center);
- this._originalBoundingSphere=new BoundSphere(center,Vector3.scalarLength(size));
- this._originalBoundingBoxCorners=__newvec(8,null);
- this._originalBoundingBox.getCorners(this._originalBoundingBoxCorners);
- this._boundingBox=new BoundBox(new Vector3(-0.5,-0.5,-0.5),new Vector3(0.5,0.5,0.5));
- this._boundingSphere=new BoundSphere(new Vector3(0,0,0),1);
- }
- __proto.calcLeafBoudingBox=function(worldMatrix){
- for (var i=0;i < 8;i++){
- Vector3.transformCoordinate(this._originalBoundingBoxCorners[i],worldMatrix,BaseRender._tempBoundBoxCorners[i]);
- }
- BoundBox.createfromPoints(BaseRender._tempBoundBoxCorners,this._boundingBox);
- }
- __proto.calcLeafBoudingSphere=function(worldMatrix,maxScale){
- Vector3.transformCoordinate(this._originalBoundingSphere.center,worldMatrix,this._boundingSphere.center);
- this._boundingSphere.radius=this._originalBoundingSphere.radius *maxScale;
- }
- __proto.calcLODErrors=function(terrainHeightData,heighDataWidth,heightDataHeight){
- this._LODError=new Float32Array(TerrainLeaf._maxLODLevel+1);
- var step=1;
- for (var i=0,n=TerrainLeaf._maxLODLevel+1;i < n;i++){
- var maxError=0;
- for (var y=0,n1=TerrainLeaf.LEAF_GRID_NUM;y < n1;y+=step){
- for (var x=0,n2=TerrainLeaf.LEAF_GRID_NUM;x < n2;x+=step){
- var z00=terrainHeightData[(this._beginGridZ+y)*heighDataWidth+(this._beginGridX+x)];
- var z10=terrainHeightData[(this._beginGridZ+y)*heighDataWidth+(this._beginGridX+x)+step];
- var z01=terrainHeightData[(this._beginGridZ+y+step)*heighDataWidth+(this._beginGridX+x)];
- var z11=terrainHeightData[(this._beginGridZ+y+step)*heighDataWidth+(this._beginGridX+x)+step];
- for (var j=0;j < step;j++){
- var ys=j / step;
- for (var k=0;k < step;k++){
- var xs=k / step;
- var z=terrainHeightData[(this._beginGridZ+y+j)*heighDataWidth+(this._beginGridX+x)+k];
- var iz=(xs+ys <=1)? (z00+(z10-z00)*xs+(z01-z00)*ys):(z11+(z01-z11)*(1-xs)+(z10-z11)*(1-ys));
- var error=Math.abs(iz-z);
- maxError=Math.max(maxError,error);
- }
- }
- }
- }
- step *=2;
- this._LODError[i]=maxError;
- }
- }
- __proto.determineLod=function(eyePos,perspectiveFactor,tolerance,tolerAndPerspectiveChanged){
- var nDistanceToEye=Vector3.distance(eyePos,this._boundingSphere.center);
- var n=TerrainLeaf._maxLODLevel;
- if (!tolerAndPerspectiveChanged){
- if (this._lastDistanceToEye==nDistanceToEye){
- return this._currentLODLevel;
- }else if (this._lastDistanceToEye > nDistanceToEye){
- n=this._currentLODLevel;
- }
- }
- for (var i=n;i >=1;i--){
- if (Terrain.LOD_DISTANCE_FACTOR *this._LODError[i] / nDistanceToEye *perspectiveFactor < tolerance){
- this._currentLODLevel=i;
- break ;
- }
- }
- this._lastDistanceToEye=nDistanceToEye;
- return this._currentLODLevel;
- }
- TerrainLeaf.__init__=function(){
- if (!TerrainLeaf._bInit){
- var nLeafNum=(TerrainLeaf.CHUNK_GRID_NUM / TerrainLeaf.LEAF_GRID_NUM)*(TerrainLeaf.CHUNK_GRID_NUM / TerrainLeaf.LEAF_GRID_NUM);
- TerrainLeaf._planeLODIndex=__newvec(nLeafNum);
- var i=0,j=0,k=0,n=0,n1=0,nOffset=0;
- var nOriginIndexArray=null,nTempIndex=null;
- for (i=0;i < nLeafNum;i++){
- TerrainLeaf._planeLODIndex[i]=new Array(TerrainLeaf._maxLODLevel+1);
- }
- for (i=0,n=TerrainLeaf._maxLODLevel+1;i < n;i++){
- TerrainLeaf._planeLODIndex[0][i]=TerrainLeaf.calcPlaneLODIndex(i);
- }
- for (i=1;i < nLeafNum;i++){
- nOffset=i *TerrainLeaf.LEAF_PLANE_VERTEXT_COUNT;
- for (j=0,n1=TerrainLeaf._maxLODLevel+1;j < n1;j++){
- nOriginIndexArray=TerrainLeaf._planeLODIndex[0][j];
- nTempIndex=new Uint16Array(nOriginIndexArray.length);
- for (k=0;k < nOriginIndexArray.length;k++){
- nTempIndex[k]=nOriginIndexArray[k]+nOffset;
- }
- TerrainLeaf._planeLODIndex[i][j]=nTempIndex;
- }
- }
- TerrainLeaf._skirtLODIndex=__newvec(nLeafNum);
- for (i=0;i < nLeafNum;i++){
- TerrainLeaf._skirtLODIndex[i]=new Array(TerrainLeaf._maxLODLevel+1);
- }
- for (i=0,n=TerrainLeaf._maxLODLevel+1;i < n;i++){
- TerrainLeaf._skirtLODIndex[0][i]=TerrainLeaf.calcSkirtLODIndex(i);
- }
- for (i=1;i < nLeafNum;i++){
- nOffset=i *TerrainLeaf.LEAF_SKIRT_VERTEXT_COUNT;
- for (j=0,n1=TerrainLeaf._maxLODLevel+1;j < n1;j++){
- nOriginIndexArray=TerrainLeaf._skirtLODIndex[0][j];
- nTempIndex=new Uint16Array(nOriginIndexArray.length);
- for (k=0;k < nOriginIndexArray.length;k++){
- nTempIndex[k]=nOriginIndexArray[k]+nOffset;
- }
- TerrainLeaf._skirtLODIndex[i][j]=nTempIndex;
- }
- }
- TerrainLeaf._bInit=true;
- }
- }
- TerrainLeaf.getPlaneLODIndex=function(leafIndex,LODLevel){
- return TerrainLeaf._planeLODIndex[leafIndex][LODLevel];
- }
- TerrainLeaf.getSkirtLODIndex=function(leafIndex,LODLevel){
- return TerrainLeaf._skirtLODIndex[leafIndex][LODLevel];
- }
- TerrainLeaf.calcPlaneLODIndex=function(level){
- if (level > TerrainLeaf._maxLODLevel)level=TerrainLeaf._maxLODLevel;
- var nGridNumAddOne=TerrainLeaf.LEAF_GRID_NUM+1;
- var nNum=0;
- var indexBuffer=null;
- var nLODGridNum=laya.d3.terrain.TerrainLeaf.LEAF_GRID_NUM / Math.pow(2,level);
- indexBuffer=new Uint16Array(nLODGridNum *nLODGridNum *6);
- var nGridSpace=laya.d3.terrain.TerrainLeaf.LEAF_GRID_NUM / nLODGridNum;
- for (var i=0;i < TerrainLeaf.LEAF_GRID_NUM;i+=nGridSpace){
- for (var j=0;j < TerrainLeaf.LEAF_GRID_NUM;j+=nGridSpace){
- indexBuffer[nNum]=(i+nGridSpace)*nGridNumAddOne+j;
- nNum++;
- indexBuffer[nNum]=i *nGridNumAddOne+j;
- nNum++;
- indexBuffer[nNum]=i *nGridNumAddOne+j+nGridSpace;
- nNum++;
- indexBuffer[nNum]=i *nGridNumAddOne+j+nGridSpace;
- nNum++;
- indexBuffer[nNum]=(i+nGridSpace)*nGridNumAddOne+j+nGridSpace;
- nNum++;
- indexBuffer[nNum]=(i+nGridSpace)*nGridNumAddOne+j;
- nNum++;
- }
- }
- return indexBuffer;
- }
- TerrainLeaf.calcSkirtLODIndex=function(level){
- if (level > TerrainLeaf._maxLODLevel)level=TerrainLeaf._maxLODLevel;
- var nSkirtIndexOffset=(TerrainLeaf.CHUNK_GRID_NUM / TerrainLeaf.LEAF_GRID_NUM)*(TerrainLeaf.CHUNK_GRID_NUM / TerrainLeaf.LEAF_GRID_NUM)*TerrainLeaf.LEAF_PLANE_VERTEXT_COUNT;
- var nGridNumAddOne=TerrainLeaf.LEAF_GRID_NUM+1;
- var nNum=0;
- var indexBuffer=null;
- var nLODGridNum=laya.d3.terrain.TerrainLeaf.LEAF_GRID_NUM / Math.pow(2,level);
- indexBuffer=new Uint16Array(nLODGridNum *4 *6);
- var nGridSpace=laya.d3.terrain.TerrainLeaf.LEAF_GRID_NUM / nLODGridNum;
- for (var j=0;j < 4;j++){
- for (var i=0;i < TerrainLeaf.LEAF_GRID_NUM;i+=nGridSpace){
- indexBuffer[nNum]=nSkirtIndexOffset+nGridNumAddOne+i;
- nNum++;
- indexBuffer[nNum]=nSkirtIndexOffset+i;
- nNum++;
- indexBuffer[nNum]=nSkirtIndexOffset+i+nGridSpace;
- nNum++;
- indexBuffer[nNum]=nSkirtIndexOffset+i+nGridSpace;
- nNum++;
- indexBuffer[nNum]=nSkirtIndexOffset+nGridNumAddOne+i+nGridSpace;
- nNum++;
- indexBuffer[nNum]=nSkirtIndexOffset+nGridNumAddOne+i;
- nNum++;
- }
- nSkirtIndexOffset+=nGridNumAddOne *2;
- }
- return indexBuffer;
- }
- TerrainLeaf.getHeightFromTerrainHeightData=function(x,z,terrainHeightData,heighDataWidth,heightDataHeight){
- x=x < 0 ? 0 :x;
- x=(x >=heighDataWidth)? heighDataWidth-1 :x;
- z=z < 0 ? 0 :z;
- z=(z >=heightDataHeight)? heightDataHeight-1 :z;
- return terrainHeightData[z *heighDataWidth+x];
- }
- TerrainLeaf.CHUNK_GRID_NUM=64;
- TerrainLeaf.LEAF_GRID_NUM=32;
- TerrainLeaf.__ADAPT_MATRIX__=null;
- TerrainLeaf.__ADAPT_MATRIX_INV__=null;
- TerrainLeaf._planeLODIndex=null;
- TerrainLeaf._skirtLODIndex=null;
- TerrainLeaf._bInit=false;
- __static(TerrainLeaf,
- ['LEAF_PLANE_VERTEXT_COUNT',function(){return this.LEAF_PLANE_VERTEXT_COUNT=(TerrainLeaf.LEAF_GRID_NUM+1)*(TerrainLeaf.LEAF_GRID_NUM+1);},'LEAF_SKIRT_VERTEXT_COUNT',function(){return this.LEAF_SKIRT_VERTEXT_COUNT=(TerrainLeaf.LEAF_GRID_NUM+1)*2 *4;},'LEAF_VERTEXT_COUNT',function(){return this.LEAF_VERTEXT_COUNT=TerrainLeaf.LEAF_PLANE_VERTEXT_COUNT+TerrainLeaf.LEAF_SKIRT_VERTEXT_COUNT;},'LEAF_PLANE_MAX_INDEX_COUNT',function(){return this.LEAF_PLANE_MAX_INDEX_COUNT=TerrainLeaf.LEAF_GRID_NUM *TerrainLeaf.LEAF_GRID_NUM *6;},'LEAF_SKIRT_MAX_INDEX_COUNT',function(){return this.LEAF_SKIRT_MAX_INDEX_COUNT=TerrainLeaf.LEAF_GRID_NUM *4 *6;},'LEAF_MAX_INDEX_COUNT',function(){return this.LEAF_MAX_INDEX_COUNT=TerrainLeaf.LEAF_PLANE_MAX_INDEX_COUNT+TerrainLeaf.LEAF_SKIRT_MAX_INDEX_COUNT;},'__VECTOR3__',function(){return this.__VECTOR3__=new Vector3();},'_maxLODLevel',function(){return this._maxLODLevel=/*__JS__ */Math.log2(TerrainLeaf.LEAF_GRID_NUM);}
- ]);
- return TerrainLeaf;
- })()
- /**
- *...
- *@author ...
- */
- //class laya.d3.graphics.Vertex.VertexShuriKenParticle
- var VertexShuriKenParticle=(function(){
- function VertexShuriKenParticle(){}
- __class(VertexShuriKenParticle,'laya.d3.graphics.Vertex.VertexShuriKenParticle');
- VertexShuriKenParticle.PARTICLE_CORNERTEXTURECOORDINATE0=0;
- VertexShuriKenParticle.PARTICLE_POSITION0=1;
- VertexShuriKenParticle.PARTICLE_COLOR0=2;
- VertexShuriKenParticle.PARTICLE_TEXTURECOORDINATE0=3;
- VertexShuriKenParticle.PARTICLE_SHAPEPOSITIONSTARTLIFETIME=4;
- VertexShuriKenParticle.PARTICLE_DIRECTIONTIME=5;
- VertexShuriKenParticle.PARTICLE_STARTCOLOR0=6;
- VertexShuriKenParticle.PARTICLE_ENDCOLOR0=7;
- VertexShuriKenParticle.PARTICLE_STARTSIZE=8;
- VertexShuriKenParticle.PARTICLE_STARTROTATION=9;
- VertexShuriKenParticle.PARTICLE_STARTSPEED=10;
- VertexShuriKenParticle.PARTICLE_RANDOM0=11;
- VertexShuriKenParticle.PARTICLE_RANDOM1=12;
- VertexShuriKenParticle.PARTICLE_SIMULATIONWORLDPOSTION=13;
- VertexShuriKenParticle.PARTICLE_SIMULATIONWORLDROTATION=14;
- return VertexShuriKenParticle;
- })()
- /**
- *<code>SizeOverLifetime</code> 类用于粒子的生命周期尺寸。
- */
- //class laya.d3.core.particleShuriKen.module.SizeOverLifetime
- var SizeOverLifetime=(function(){
- function SizeOverLifetime(size){
- /**@private */
- this._size=null;
- /**是否启用*/
- this.enbale=false;
- this._size=size;
- }
- __class(SizeOverLifetime,'laya.d3.core.particleShuriKen.module.SizeOverLifetime');
- var __proto=SizeOverLifetime.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var destSizeOverLifetime=destObject;
- this._size.cloneTo(destSizeOverLifetime._size);
- destSizeOverLifetime.enbale=this.enbale;
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var destSize;
- switch (this._size.type){
- case 0:
- if (this._size.separateAxes)
- destSize=GradientSize.createByGradientSeparate(this._size.gradientX.clone(),this._size.gradientY.clone(),this._size.gradientZ.clone());
- else
- destSize=GradientSize.createByGradient(this._size.gradient.clone());
- break ;
- case 1:
- if (this._size.separateAxes)
- destSize=GradientSize.createByRandomTwoConstantSeparate(this._size.constantMinSeparate.clone(),this._size.constantMaxSeparate.clone());
- else
- destSize=GradientSize.createByRandomTwoConstant(this._size.constantMin,this._size.constantMax);
- break ;
- case 2:
- if (this._size.separateAxes)
- 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());
- else
- destSize=GradientSize.createByRandomTwoGradient(this._size.gradientMin.clone(),this._size.gradientMax.clone());
- break ;
- };
- var destSizeOverLifetime=/*__JS__ */new this.constructor(destSize);
- destSizeOverLifetime.enbale=this.enbale;
- return destSizeOverLifetime;
- }
- /**
- *获取尺寸。
- */
- __getset(0,__proto,'size',function(){
- return this._size;
- });
- return SizeOverLifetime;
- })()
- /**
- *<code>KeyFrame</code> 类用于创建关键帧实例。
- */
- //class laya.d3.core.Keyframe
- var Keyframe=(function(){
- function Keyframe(){
- /**时间。*/
- this.time=NaN;
- }
- __class(Keyframe,'laya.d3.core.Keyframe');
- var __proto=Keyframe.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var destKeyFrame=destObject;
- destKeyFrame.time=this.time;
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var dest=/*__JS__ */new this.constructor();
- this.cloneTo(dest);
- return dest;
- }
- return Keyframe;
- })()
- /**
- *<code>Vector4</code> 类用于创建四维向量。
- */
- //class laya.d3.math.Vector4
- var Vector4=(function(){
- function Vector4(x,y,z,w){
- /**X轴坐标*/
- this.x=NaN;
- /**Y轴坐标*/
- this.y=NaN;
- /**Z轴坐标*/
- this.z=NaN;
- /**W轴坐标*/
- this.w=NaN;
- (x===void 0)&& (x=0);
- (y===void 0)&& (y=0);
- (z===void 0)&& (z=0);
- (w===void 0)&& (w=0);
- this.x=x;
- this.y=y;
- this.z=z;
- this.w=w;
- }
- __class(Vector4,'laya.d3.math.Vector4');
- var __proto=Vector4.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *设置xyzw值。
- *@param x X值。
- *@param y Y值。
- *@param z Z值。
- *@param w W值。
- */
- __proto.setValue=function(x,y,z,w){
- this.x=x;
- this.y=y;
- this.z=z;
- this.w=w;
- }
- /**
- *从Array数组拷贝值。
- *@param array 数组。
- *@param offset 数组偏移。
- */
- __proto.fromArray=function(array,offset){
- (offset===void 0)&& (offset=0);
- this.x=array[offset+0];
- this.y=array[offset+1];
- this.z=array[offset+2];
- this.w=array[offset+3];
- }
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var destVector4=destObject;
- destVector4.x=this.x;
- destVector4.y=this.y;
- destVector4.z=this.z;
- destVector4.w=this.w;
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var destVector4=/*__JS__ */new this.constructor();
- this.cloneTo(destVector4);
- return destVector4;
- }
- /**
- *求四维向量的长度。
- *@return 长度。
- */
- __proto.length=function(){
- return Math.sqrt(this.x *this.x+this.y *this.y+this.z *this.z+this.w *this.w);
- }
- /**
- *求四维向量长度的平方。
- *@return 长度的平方。
- */
- __proto.lengthSquared=function(){
- return this.x *this.x+this.y *this.y+this.z *this.z+this.w *this.w;
- }
- __proto.forNativeElement=function(nativeElements){
- if (nativeElements){
- /*__JS__ */this.elements=nativeElements;
- /*__JS__ */this.elements[0]=this.x;
- /*__JS__ */this.elements[1]=this.y;
- /*__JS__ */this.elements[2]=this.z;
- /*__JS__ */this.elements[3]=this.w;
- }
- else{
- /*__JS__ */this.elements=new Float32Array([this.x,this.y,this.z,this.w]);
- }
- Vector2.rewriteNumProperty(this,"x",0);
- Vector2.rewriteNumProperty(this,"y",1);
- Vector2.rewriteNumProperty(this,"z",2);
- Vector2.rewriteNumProperty(this,"w",3);
- }
- Vector4.lerp=function(a,b,t,out){
- var ax=a.x,ay=a.y,az=a.z,aw=a.w;
- out.x=ax+t *(b.x-ax);
- out.y=ay+t *(b.y-ay);
- out.z=az+t *(b.z-az);
- out.w=aw+t *(b.w-aw);
- }
- Vector4.transformByM4x4=function(vector4,m4x4,out){
- var vx=vector4.x;
- var vy=vector4.y;
- var vz=vector4.z;
- var vw=vector4.w;
- var me=m4x4.elements;
- out.x=vx *me[0]+vy *me[4]+vz *me[8]+vw *me[12];
- out.y=vx *me[1]+vy *me[5]+vz *me[9]+vw *me[13];
- out.z=vx *me[2]+vy *me[6]+vz *me[10]+vw *me[14];
- out.w=vx *me[3]+vy *me[7]+vz *me[11]+vw *me[15];
- }
- Vector4.equals=function(a,b){
- 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));
- }
- Vector4.normalize=function(s,out){
- var len=/*if err,please use iflash.method.xmlLength()*/s.length();
- if (len > 0){
- out.x=s.x *len;
- out.y=s.y *len;
- out.z=s.z *len;
- out.w=s.w *len;
- }
- }
- Vector4.add=function(a,b,out){
- out.x=a.x+b.x;
- out.y=a.y+b.y;
- out.z=a.z+b.z;
- out.w=a.w+b.w;
- }
- Vector4.subtract=function(a,b,out){
- out.x=a.x-b.x;
- out.y=a.y-b.y;
- out.z=a.z-b.z;
- out.w=a.w-b.w;
- }
- Vector4.multiply=function(a,b,out){
- out.x=a.x *b.x;
- out.y=a.y *b.y;
- out.z=a.z *b.z;
- out.w=a.w *b.w;
- }
- Vector4.scale=function(a,b,out){
- out.x=a.x *b;
- out.y=a.y *b;
- out.z=a.z *b;
- out.w=a.w *b;
- }
- Vector4.Clamp=function(value,min,max,out){
- var x=value.x;
- var y=value.y;
- var z=value.z;
- var w=value.w;
- var mineX=min.x;
- var mineY=min.y;
- var mineZ=min.z;
- var mineW=min.w;
- var maxeX=max.x;
- var maxeY=max.y;
- var maxeZ=max.z;
- var maxeW=max.w;
- x=(x > maxeX)? maxeX :x;
- x=(x < mineX)? mineX :x;
- y=(y > maxeY)? maxeY :y;
- y=(y < mineY)? mineY :y;
- z=(z > maxeZ)? maxeZ :z;
- z=(z < mineZ)? mineZ :z;
- w=(w > maxeW)? maxeW :w;
- w=(w < mineW)? mineW :w;
- out.x=x;
- out.y=y;
- out.z=z;
- out.w=w;
- }
- Vector4.distanceSquared=function(value1,value2){
- var x=value1.x-value2.x;
- var y=value1.y-value2.y;
- var z=value1.z-value2.z;
- var w=value1.w-value2.w;
- return (x *x)+(y *y)+(z *z)+(w *w);
- }
- Vector4.distance=function(value1,value2){
- var x=value1.x-value2.x;
- var y=value1.y-value2.y;
- var z=value1.z-value2.z;
- var w=value1.w-value2.w;
- return Math.sqrt((x *x)+(y *y)+(z *z)+(w *w));
- }
- Vector4.dot=function(a,b){
- return (a.x *b.x)+(a.y *b.y)+(a.z *b.z)+(a.w *b.w);
- }
- Vector4.min=function(a,b,out){
- out.x=Math.min(a.x,b.x);
- out.y=Math.min(a.y,b.y);
- out.z=Math.min(a.z,b.z);
- out.w=Math.min(a.w,b.w);
- }
- Vector4.max=function(a,b,out){
- out.x=Math.max(a.x,b.x);
- out.y=Math.max(a.y,b.y);
- out.z=Math.max(a.z,b.z);
- out.w=Math.max(a.w,b.w);
- }
- __static(Vector4,
- ['ZERO',function(){return this.ZERO=new Vector4();},'ONE',function(){return this.ONE=new Vector4(1.0,1.0,1.0,1.0);},'UnitX',function(){return this.UnitX=new Vector4(1.0,0.0,0.0,0.0);},'UnitY',function(){return this.UnitY=new Vector4(0.0,1.0,0.0,0.0);},'UnitZ',function(){return this.UnitZ=new Vector4(0.0,0.0,1.0,0.0);},'UnitW',function(){return this.UnitW=new Vector4(0.0,0.0,0.0,1.0);}
- ]);
- return Vector4;
- })()
- /**
- *@private
- */
- //class laya.d3.shader.ShaderDefines
- var ShaderDefines=(function(){
- function ShaderDefines(superDefines){
- /**@private */
- this._counter=0;
- /**@private [只读]*/
- this.defines={};
- if (superDefines){
- this._counter=superDefines._counter;
- for (var k in superDefines.defines)
- this.defines[k]=superDefines.defines[k];
- }
- }
- __class(ShaderDefines,'laya.d3.shader.ShaderDefines');
- var __proto=ShaderDefines.prototype;
- /**
- *@private
- */
- __proto.registerDefine=function(name){
- var value=Math.pow(2,this._counter++);
- this.defines[value]=name;
- return value;
- }
- return ShaderDefines;
- })()
- /**
- *<code>Vector3</code> 类用于创建三维向量。
- */
- //class laya.d3.math.Vector3
- var Vector3=(function(){
- function Vector3(x,y,z,nativeElements){
- /**X轴坐标*/
- this.x=NaN;
- /**Y轴坐标*/
- this.y=NaN;
- /**Z轴坐标*/
- this.z=NaN;
- (x===void 0)&& (x=0);
- (y===void 0)&& (y=0);
- (z===void 0)&& (z=0);
- this.x=x;
- this.y=y;
- this.z=z;
- }
- __class(Vector3,'laya.d3.math.Vector3');
- var __proto=Vector3.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *设置xyz值。
- *@param x X值。
- *@param y Y值。
- *@param z Z值。
- */
- __proto.setValue=function(x,y,z){
- this.x=x;
- this.y=y;
- this.z=z;
- }
- /**
- *从Array数组拷贝值。
- *@param array 数组。
- *@param offset 数组偏移。
- */
- __proto.fromArray=function(array,offset){
- (offset===void 0)&& (offset=0);
- this.x=array[offset+0];
- this.y=array[offset+1];
- this.z=array[offset+2];
- }
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var destVector3=destObject;
- destVector3.x=this.x;
- destVector3.y=this.y;
- destVector3.z=this.z;
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var destVector3=/*__JS__ */new this.constructor();
- this.cloneTo(destVector3);
- return destVector3;
- }
- __proto.toDefault=function(){
- this.x=0;
- this.y=0;
- this.z=0;
- }
- __proto.forNativeElement=function(nativeElements){
- if (nativeElements){
- /*__JS__ */this.elements=nativeElements;
- /*__JS__ */this.elements[0]=this.x;
- /*__JS__ */this.elements[1]=this.y;
- /*__JS__ */this.elements[2]=this.z;
- }
- else{
- /*__JS__ */this.elements=new Float32Array([this.x,this.y,this.z]);
- }
- Vector2.rewriteNumProperty(this,"x",0);
- Vector2.rewriteNumProperty(this,"y",1);
- Vector2.rewriteNumProperty(this,"z",2);
- }
- Vector3.distanceSquared=function(value1,value2){
- var x=value1.x-value2.x;
- var y=value1.y-value2.y;
- var z=value1.z-value2.z;
- return (x *x)+(y *y)+(z *z);
- }
- Vector3.distance=function(value1,value2){
- var x=value1.x-value2.x;
- var y=value1.y-value2.y;
- var z=value1.z-value2.z;
- return Math.sqrt((x *x)+(y *y)+(z *z));
- }
- Vector3.min=function(a,b,out){
- out.x=Math.min(a.x,b.x);
- out.y=Math.min(a.y,b.y);
- out.z=Math.min(a.z,b.z);
- }
- Vector3.max=function(a,b,out){
- out.x=Math.max(a.x,b.x);
- out.y=Math.max(a.y,b.y);
- out.z=Math.max(a.z,b.z);
- }
- Vector3.transformQuat=function(source,rotation,out){
- 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;
- out.x=ix *qw+iw *-qx+iy *-qz-iz *-qy;
- out.y=iy *qw+iw *-qy+iz *-qx-ix *-qz;
- out.z=iz *qw+iw *-qz+ix *-qy-iy *-qx;
- }
- Vector3.scalarLength=function(a){
- var x=a.x,y=a.y,z=a.z;
- return Math.sqrt(x *x+y *y+z *z);
- }
- Vector3.scalarLengthSquared=function(a){
- var x=a.x,y=a.y,z=a.z;
- return x *x+y *y+z *z;
- }
- Vector3.normalize=function(s,out){
- var x=s.x,y=s.y,z=s.z;
- var len=x *x+y *y+z *z;
- if (len > 0){
- len=1 / Math.sqrt(len);
- out.x=s.x *len;
- out.y=s.y *len;
- out.z=s.z *len;
- }
- }
- Vector3.multiply=function(a,b,out){
- out.x=a.x *b.x;
- out.y=a.y *b.y;
- out.z=a.z *b.z;
- }
- Vector3.scale=function(a,b,out){
- out.x=a.x *b;
- out.y=a.y *b;
- out.z=a.z *b;
- }
- Vector3.lerp=function(a,b,t,out){
- var ax=a.x,ay=a.y,az=a.z;
- out.x=ax+t *(b.x-ax);
- out.y=ay+t *(b.y-ay);
- out.z=az+t *(b.z-az);
- }
- Vector3.transformV3ToV3=function(vector,transform,result){
- var intermediate=Vector3._tempVector4;
- Vector3.transformV3ToV4(vector,transform,intermediate);
- result.x=intermediate.x;
- result.y=intermediate.y;
- result.z=intermediate.z;
- }
- Vector3.transformV3ToV4=function(vector,transform,result){
- var vectorX=vector.x;
- var vectorY=vector.y;
- var vectorZ=vector.z;
- var transformElem=transform.elements;
- result.x=(vectorX *transformElem[0])+(vectorY *transformElem[4])+(vectorZ *transformElem[8])+transformElem[12];
- result.y=(vectorX *transformElem[1])+(vectorY *transformElem[5])+(vectorZ *transformElem[9])+transformElem[13];
- result.z=(vectorX *transformElem[2])+(vectorY *transformElem[6])+(vectorZ *transformElem[10])+transformElem[14];
- result.w=(vectorX *transformElem[3])+(vectorY *transformElem[7])+(vectorZ *transformElem[11])+transformElem[15];
- }
- Vector3.TransformNormal=function(normal,transform,result){
- var normalX=normal.x;
- var normalY=normal.y;
- var normalZ=normal.z;
- var transformElem=transform.elements;
- result.x=(normalX *transformElem[0])+(normalY *transformElem[4])+(normalZ *transformElem[8]);
- result.y=(normalX *transformElem[1])+(normalY *transformElem[5])+(normalZ *transformElem[9]);
- result.z=(normalX *transformElem[2])+(normalY *transformElem[6])+(normalZ *transformElem[10]);
- }
- Vector3.transformCoordinate=function(coordinate,transform,result){
- var coordinateX=coordinate.x;
- var coordinateY=coordinate.y;
- var coordinateZ=coordinate.z;
- var transformElem=transform.elements;
- var w=((coordinateX *transformElem[3])+(coordinateY *transformElem[7])+(coordinateZ *transformElem[11])+transformElem[15]);
- result.x=(coordinateX *transformElem[0])+(coordinateY *transformElem[4])+(coordinateZ *transformElem[8])+transformElem[12] / w;
- result.y=(coordinateX *transformElem[1])+(coordinateY *transformElem[5])+(coordinateZ *transformElem[9])+transformElem[13] / w;
- result.z=(coordinateX *transformElem[2])+(coordinateY *transformElem[6])+(coordinateZ *transformElem[10])+transformElem[14] / w;
- }
- Vector3.Clamp=function(value,min,max,out){
- var x=value.x;
- var y=value.y;
- var z=value.z;
- var mineX=min.x;
- var mineY=min.y;
- var mineZ=min.z;
- var maxeX=max.x;
- var maxeY=max.y;
- var maxeZ=max.z;
- x=(x > maxeX)? maxeX :x;
- x=(x < mineX)? mineX :x;
- y=(y > maxeY)? maxeY :y;
- y=(y < mineY)? mineY :y;
- z=(z > maxeZ)? maxeZ :z;
- z=(z < mineZ)? mineZ :z;
- out.x=x;
- out.y=y;
- out.z=z;
- }
- Vector3.add=function(a,b,out){
- out.x=a.x+b.x;
- out.y=a.y+b.y;
- out.z=a.z+b.z;
- }
- Vector3.subtract=function(a,b,o){
- o.x=a.x-b.x;
- o.y=a.y-b.y;
- o.z=a.z-b.z;
- }
- Vector3.cross=function(a,b,o){
- var ax=a.x,ay=a.y,az=a.z,bx=b.x,by=b.y,bz=b.z;
- o.x=ay *bz-az *by;
- o.y=az *bx-ax *bz;
- o.z=ax *by-ay *bx;
- }
- Vector3.dot=function(a,b){
- return (a.x *b.x)+(a.y *b.y)+(a.z *b.z);
- }
- Vector3.equals=function(a,b){
- return MathUtils3D.nearEqual(a.x,b.x)&& MathUtils3D.nearEqual(a.y,b.y)&& MathUtils3D.nearEqual(a.z,b.z);
- }
- Vector3._ZERO=new Vector3(0.0,0.0,0.0);
- Vector3._ONE=new Vector3(1.0,1.0,1.0);
- Vector3._NegativeUnitX=new Vector3(-1,0,0);
- Vector3._UnitX=new Vector3(1,0,0);
- Vector3._UnitY=new Vector3(0,1,0);
- Vector3._UnitZ=new Vector3(0,0,1);
- Vector3._ForwardRH=new Vector3(0,0,-1);
- Vector3._ForwardLH=new Vector3(0,0,1);
- Vector3._Up=new Vector3(0,1,0);
- __static(Vector3,
- ['_tempVector4',function(){return this._tempVector4=new Vector4();}
- ]);
- return Vector3;
- })()
- /**
- *<code>Vector2</code> 类用于创建二维向量。
- */
- //class laya.d3.math.Vector2
- var Vector2=(function(){
- function Vector2(x,y){
- /**X轴坐标*/
- this.x=NaN;
- /**Y轴坐标*/
- this.y=NaN;
- (x===void 0)&& (x=0);
- (y===void 0)&& (y=0);
- this.x=x;
- this.y=y;
- }
- __class(Vector2,'laya.d3.math.Vector2');
- var __proto=Vector2.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *设置xy值。
- *@param x X值。
- *@param y Y值。
- */
- __proto.setValue=function(x,y){
- this.x=x;
- this.y=y;
- }
- /**
- *从Array数组拷贝值。
- *@param array 数组。
- *@param offset 数组偏移。
- */
- __proto.fromArray=function(array,offset){
- (offset===void 0)&& (offset=0);
- this.x=array[offset+0];
- this.y=array[offset+1];
- }
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var destVector2=destObject;
- destVector2.x=this.x;
- destVector2.y=this.y;
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var destVector2=/*__JS__ */new this.constructor();
- this.cloneTo(destVector2);
- return destVector2;
- }
- __proto.forNativeElement=function(nativeElements){
- if (nativeElements){
- /*__JS__ */this.elements=nativeElements;
- /*__JS__ */this.elements[0]=this.x;
- /*__JS__ */this.elements[1]=this.y;
- }
- else{
- /*__JS__ */this.elements=new Float32Array([this.x,this.y]);
- }
- Vector2.rewriteNumProperty(this,"x",0);
- Vector2.rewriteNumProperty(this,"y",1);
- }
- Vector2.scale=function(a,b,out){
- out.x=a.x *b;
- out.y=a.y *b;
- }
- Vector2.dot=function(a,b){
- return (a.x *b.x)+(a.y *b.y);
- }
- Vector2.normalize=function(s,out){
- var x=s.x,y=s.y;
- var len=x *x+y *y;
- if (len > 0){
- len=1 / Math.sqrt(len);
- out.x=x *len;
- out.y=y *len;
- }
- }
- Vector2.scalarLength=function(a){
- var x=a.x,y=a.y;
- return Math.sqrt(x *x+y *y);
- }
- Vector2.rewriteNumProperty=function(proto,name,index){
- Object["defineProperty"](proto,name,{
- "get":function (){
- return /*__JS__ */this.elements[index];
- },
- "set":function (v){
- /*__JS__ */this.elements[index]=v;
- }
- });
- }
- __static(Vector2,
- ['ZERO',function(){return this.ZERO=new Vector2(0.0,0.0);},'ONE',function(){return this.ONE=new Vector2(1.0,1.0);}
- ]);
- return Vector2;
- })()
- /**
- *<code>AnimatorPlayState</code> 类用于创建动画播放状态信息。
- */
- //class laya.d3.component.AnimatorPlayState
- var AnimatorPlayState=(function(){
- function AnimatorPlayState(){
- /**@private */
- //this._finish=false;
- /**@private */
- //this._startPlayTime=NaN;
- /**@private */
- //this._lastElapsedTime=NaN;
- /**@private */
- //this._elapsedTime=NaN;
- /**@private */
- //this._normalizedTime=NaN;
- /**@private */
- //this._normalizedPlayTime=NaN;
- /**@private */
- //this._duration=NaN;
- /**@private */
- //this._playEventIndex=0;
- /**@private */
- //this._lastIsFront=false;
- }
- __class(AnimatorPlayState,'laya.d3.component.AnimatorPlayState');
- var __proto=AnimatorPlayState.prototype;
- /**
- *@private
- */
- __proto._resetPlayState=function(startTime){
- this._finish=false;
- this._startPlayTime=startTime;
- this._elapsedTime=startTime;
- this._playEventIndex=0;
- this._lastIsFront=true;
- }
- /**
- *@private
- */
- __proto._cloneTo=function(dest){
- dest._finish=this._finish;
- dest._startPlayTime=this._startPlayTime;
- dest._elapsedTime=this._elapsedTime;
- dest._playEventIndex=this._playEventIndex;
- dest._lastIsFront=this._lastIsFront;
- }
- /**
- *获取播放状态的归一化时间,整数为循环次数,小数为单次播放时间。
- */
- __getset(0,__proto,'normalizedTime',function(){
- return this._normalizedTime;
- });
- /**
- *获取当前动画的持续时间,以秒为单位。
- */
- __getset(0,__proto,'duration',function(){
- return this._duration;
- });
- return AnimatorPlayState;
- })()
- /**
- *<code>VelocityOverLifetime</code> 类用于粒子的生命周期速度。
- */
- //class laya.d3.core.particleShuriKen.module.VelocityOverLifetime
- var VelocityOverLifetime=(function(){
- function VelocityOverLifetime(velocity){
- /**@private */
- this._velocity=null;
- /**是否启用*/
- this.enbale=false;
- /**速度空间,0为local,1为world。*/
- this.space=0;
- this._velocity=velocity;
- }
- __class(VelocityOverLifetime,'laya.d3.core.particleShuriKen.module.VelocityOverLifetime');
- var __proto=VelocityOverLifetime.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var destVelocityOverLifetime=destObject;
- this._velocity.cloneTo(destVelocityOverLifetime._velocity);
- destVelocityOverLifetime.enbale=this.enbale;
- destVelocityOverLifetime.space=this.space;
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var destVelocity;
- switch(this._velocity.type){
- case 0:
- destVelocity=GradientVelocity.createByConstant(this._velocity.constant.clone());
- break ;
- case 1:
- destVelocity=GradientVelocity.createByGradient(this._velocity.gradientX.clone(),this._velocity.gradientY.clone(),this._velocity.gradientZ.clone());
- break ;
- case 2:
- destVelocity=GradientVelocity.createByRandomTwoConstant(this._velocity.constantMin.clone(),this._velocity.constantMax.clone());
- break ;
- case 3:
- 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());
- break ;
- };
- var destVelocityOverLifetime=/*__JS__ */new this.constructor(destVelocity);
- destVelocityOverLifetime.enbale=this.enbale;
- destVelocityOverLifetime.space=this.space;
- return destVelocityOverLifetime;
- }
- /**
- *获取尺寸。
- */
- __getset(0,__proto,'velocity',function(){
- return this._velocity;
- });
- return VelocityOverLifetime;
- })()
- /**
- *...
- *@author ...
- */
- //class laya.d3.loaders.MeshReader
- var MeshReader=(function(){
- function MeshReader(){}
- __class(MeshReader,'laya.d3.loaders.MeshReader');
- MeshReader.read=function(data,mesh,subMeshes){
- var readData=new Byte(data);
- readData.pos=0;
- var version=readData.readUTFString();
- switch (version){
- case "LAYAMODEL:0301":
- case "LAYAMODEL:0400":
- case "LAYAMODEL:0401":
- LoadModelV04.parse(readData,version,mesh,subMeshes);
- break ;
- case "LAYAMODEL:05":
- case "LAYAMODEL:COMPRESSION_05":
- LoadModelV05.parse(readData,version,mesh,subMeshes);
- break ;
- default :
- throw new Error("MeshReader: unknown mesh version.");
- }
- mesh._setSubMeshes(subMeshes);
- }
- return MeshReader;
- })()
- /**
- *...
- *@author ...
- */
- //class laya.d3.core.scene.SceneManager
- var SceneManager=(function(){
- function SceneManager(){}
- __class(SceneManager,'laya.d3.core.scene.SceneManager');
- return SceneManager;
- })()
- /**
- *<code>ContainmentType</code> 类用于定义空间物体位置关系。
- */
- //class laya.d3.math.ContainmentType
- var ContainmentType=(function(){
- function ContainmentType(){}
- __class(ContainmentType,'laya.d3.math.ContainmentType');
- ContainmentType.Disjoint=0;
- ContainmentType.Contains=1;
- ContainmentType.Intersects=2;
- return ContainmentType;
- })()
- /**
- *@private
- *<code>LoadModelV05</code> 类用于模型加载。
- */
- //class laya.d3.loaders.LoadModelV05
- var LoadModelV05=(function(){
- function LoadModelV05(){}
- __class(LoadModelV05,'laya.d3.loaders.LoadModelV05');
- LoadModelV05.parse=function(readData,version,mesh,subMeshes){
- LoadModelV05._mesh=mesh;
- LoadModelV05._subMeshes=subMeshes;
- LoadModelV05._version=version;
- LoadModelV05._readData=readData;
- LoadModelV05.READ_DATA();
- LoadModelV05.READ_BLOCK();
- LoadModelV05.READ_STRINGS();
- for (var i=0,n=LoadModelV05._BLOCK.count;i < n;i++){
- LoadModelV05._readData.pos=LoadModelV05._BLOCK.blockStarts[i];
- var index=LoadModelV05._readData.getUint16();
- var blockName=LoadModelV05._strings[index];
- var fn=LoadModelV05["READ_"+blockName];
- if (fn==null)
- throw new Error("model file err,no this function:"+index+" "+blockName);
- else
- fn.call(null);
- }
- LoadModelV05._mesh._bindPoseIndices=new Uint16Array(LoadModelV05._bindPoseIndices);
- LoadModelV05._bindPoseIndices.length=0;
- LoadModelV05._strings.length=0;
- LoadModelV05._readData=null;
- LoadModelV05._version=null;
- LoadModelV05._mesh=null;
- LoadModelV05._subMeshes=null;
- }
- LoadModelV05._readString=function(){
- return LoadModelV05._strings[LoadModelV05._readData.getUint16()];
- }
- LoadModelV05.READ_DATA=function(){
- LoadModelV05._DATA.offset=LoadModelV05._readData.getUint32();
- LoadModelV05._DATA.size=LoadModelV05._readData.getUint32();
- }
- LoadModelV05.READ_BLOCK=function(){
- var count=LoadModelV05._BLOCK.count=LoadModelV05._readData.getUint16();
- var blockStarts=LoadModelV05._BLOCK.blockStarts=[];
- var blockLengths=LoadModelV05._BLOCK.blockLengths=[];
- for (var i=0;i < count;i++){
- blockStarts.push(LoadModelV05._readData.getUint32());
- blockLengths.push(LoadModelV05._readData.getUint32());
- }
- }
- LoadModelV05.READ_STRINGS=function(){
- var offset=LoadModelV05._readData.getUint32();
- var count=LoadModelV05._readData.getUint16();
- var prePos=LoadModelV05._readData.pos;
- LoadModelV05._readData.pos=offset+LoadModelV05._DATA.offset;
- for (var i=0;i < count;i++)
- LoadModelV05._strings[i]=LoadModelV05._readData.readUTFString();
- LoadModelV05._readData.pos=prePos;
- }
- LoadModelV05.READ_MESH=function(){
- var i=0,n=0;
- var memorySize=0;
- var name=LoadModelV05._readString();
- var arrayBuffer=LoadModelV05._readData.__getBuffer();
- var vertexBufferCount=LoadModelV05._readData.getInt16();
- var offset=LoadModelV05._DATA.offset;
- for (i=0;i < vertexBufferCount;i++){
- var vbStart=offset+LoadModelV05._readData.getUint32();
- var vertexCount=LoadModelV05._readData.getUint32();
- var vertexFlag=LoadModelV05._readString();
- var vertexDeclaration=VertexMesh.getVertexDeclaration(vertexFlag,false);
- var vertexStride=vertexDeclaration.vertexStride;
- var vertexData=new ArrayBuffer(vertexStride *vertexCount);
- var floatData=new Float32Array(vertexData);
- var subVertexFlags=vertexFlag.split(",");
- var subVertexCount=subVertexFlags.length;
- switch (LoadModelV05._version){
- case "LAYAMODEL:05":
- floatData=new Float32Array(arrayBuffer.slice(vbStart,vbStart+vertexCount *vertexStride));
- break ;
- case "LAYAMODEL:COMPRESSION_05":;
- var lastPosition=LoadModelV05._readData.pos;
- floatData=new Float32Array(vertexData);
- var uint8Data=new Uint8Array(vertexData);
- LoadModelV05._readData.pos=vbStart;
- for (var j=0;j < vertexCount;j++){
- var subOffset=0;
- var verOffset=j *vertexStride;
- for (var k=0;k < subVertexCount;k++){
- switch (subVertexFlags[k]){
- case "POSITION":
- subOffset=verOffset / 4;
- floatData[subOffset]=HalfFloatUtils.convertToNumber(LoadModelV05._readData.getUint16());
- floatData[subOffset+1]=HalfFloatUtils.convertToNumber(LoadModelV05._readData.getUint16());
- floatData[subOffset+2]=HalfFloatUtils.convertToNumber(LoadModelV05._readData.getUint16());
- verOffset+=12;
- break ;
- case "NORMAL":
- subOffset=verOffset / 4;
- floatData[subOffset]=LoadModelV05._readData.getUint8()/ 127.5-1;
- floatData[subOffset+1]=LoadModelV05._readData.getUint8()/ 127.5-1;
- floatData[subOffset+2]=LoadModelV05._readData.getUint8()/ 127.5-1;
- verOffset+=12;
- break ;
- case "COLOR":
- subOffset=verOffset / 4;
- floatData[subOffset]=LoadModelV05._readData.getUint8()/ 255;
- floatData[subOffset+1]=LoadModelV05._readData.getUint8()/ 255;
- floatData[subOffset+2]=LoadModelV05._readData.getUint8()/ 255;
- floatData[subOffset+3]=LoadModelV05._readData.getUint8()/ 255;
- verOffset+=16;
- break ;
- case "UV":
- subOffset=verOffset / 4;
- floatData[subOffset]=HalfFloatUtils.convertToNumber(LoadModelV05._readData.getUint16());
- floatData[subOffset+1]=HalfFloatUtils.convertToNumber(LoadModelV05._readData.getUint16());
- verOffset+=8;
- break ;
- case "UV1":
- subOffset=verOffset / 4;
- floatData[subOffset]=HalfFloatUtils.convertToNumber(LoadModelV05._readData.getUint16());
- floatData[subOffset+1]=HalfFloatUtils.convertToNumber(LoadModelV05._readData.getUint16());
- verOffset+=8;
- break ;
- case "BLENDWEIGHT":
- subOffset=verOffset / 4;
- floatData[subOffset]=LoadModelV05._readData.getUint8()/ 255;
- floatData[subOffset+1]=LoadModelV05._readData.getUint8()/ 255;
- floatData[subOffset+2]=LoadModelV05._readData.getUint8()/ 255;
- floatData[subOffset+3]=LoadModelV05._readData.getUint8()/ 255;
- verOffset+=16;
- break ;
- case "BLENDINDICES":
- uint8Data[verOffset]=LoadModelV05._readData.getUint8();
- uint8Data[verOffset+1]=LoadModelV05._readData.getUint8();
- uint8Data[verOffset+2]=LoadModelV05._readData.getUint8();
- uint8Data[verOffset+3]=LoadModelV05._readData.getUint8();
- verOffset+=4;
- break ;
- case "TANGENT":
- subOffset=verOffset / 4;
- floatData[subOffset]=LoadModelV05._readData.getUint8()/ 127.5-1;
- floatData[subOffset+1]=LoadModelV05._readData.getUint8()/ 127.5-1;
- floatData[subOffset+2]=LoadModelV05._readData.getUint8()/ 127.5-1;
- floatData[subOffset+3]=LoadModelV05._readData.getUint8()/ 127.5-1;
- verOffset+=16;
- break ;
- }
- }
- }
- LoadModelV05._readData.pos=lastPosition;
- break ;
- };
- var vertexBuffer=new VertexBuffer3D(vertexData.byteLength,/*laya.webgl.WebGLContext.STATIC_DRAW*/0x88E4,true);
- vertexBuffer.vertexDeclaration=vertexDeclaration;
- vertexBuffer.setData(floatData);
- LoadModelV05._mesh._vertexBuffers.push(vertexBuffer);
- LoadModelV05._mesh._vertexCount+=vertexBuffer.vertexCount;
- memorySize+=floatData.length *4;
- };
- var ibStart=offset+LoadModelV05._readData.getUint32();
- var ibLength=LoadModelV05._readData.getUint32();
- var ibDatas=new Uint16Array(arrayBuffer.slice(ibStart,ibStart+ibLength));
- var indexBuffer=new IndexBuffer3D(/*laya.d3.graphics.IndexBuffer3D.INDEXTYPE_USHORT*/"ushort",ibLength / 2,/*laya.webgl.WebGLContext.STATIC_DRAW*/0x88E4,true);
- indexBuffer.setData(ibDatas);
- LoadModelV05._mesh._indexBuffer=indexBuffer;
- LoadModelV05._mesh._setBuffer(LoadModelV05._mesh._vertexBuffers,indexBuffer);
- memorySize+=indexBuffer.indexCount *2;
- LoadModelV05._mesh._setCPUMemory(memorySize);
- LoadModelV05._mesh._setGPUMemory(memorySize);
- var boneNames=LoadModelV05._mesh._boneNames=[];
- var boneCount=LoadModelV05._readData.getUint16();
- boneNames.length=boneCount;
- for (i=0;i < boneCount;i++)
- boneNames[i]=LoadModelV05._strings[LoadModelV05._readData.getUint16()];
- var bindPoseDataStart=LoadModelV05._readData.getUint32();
- var bindPoseDataLength=LoadModelV05._readData.getUint32();
- var bindPoseDatas=new Float32Array(arrayBuffer.slice(offset+bindPoseDataStart,offset+bindPoseDataStart+bindPoseDataLength));
- var bindPoseFloatCount=bindPoseDatas.length;
- var bindPoseCount=bindPoseFloatCount / 16;
- var bindPoseBuffer=LoadModelV05._mesh._inverseBindPosesBuffer=new ArrayBuffer(bindPoseFloatCount *4);
- LoadModelV05._mesh._inverseBindPoses=__newvec(bindPoseCount);
- for (i=0;i < bindPoseFloatCount;i+=16){
- 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));
- LoadModelV05._mesh._inverseBindPoses[i / 16]=inverseGlobalBindPose;
- }
- return true;
- }
- LoadModelV05.READ_SUBMESH=function(){
- var arrayBuffer=LoadModelV05._readData.__getBuffer();
- var submesh=new SubMesh(LoadModelV05._mesh);
- var vbIndex=LoadModelV05._readData.getInt16();
- var ibStart=LoadModelV05._readData.getUint32();
- var ibCount=LoadModelV05._readData.getUint32();
- var indexBuffer=LoadModelV05._mesh._indexBuffer;
- submesh._indexBuffer=indexBuffer;
- submesh._indexStart=ibStart;
- submesh._indexCount=ibCount;
- submesh._indices=new Uint16Array(indexBuffer.getData().buffer,ibStart *2,ibCount);
- var vertexBuffer=LoadModelV05._mesh._vertexBuffers[vbIndex];
- submesh._vertexBuffer=vertexBuffer;
- var offset=LoadModelV05._DATA.offset;
- var subIndexBufferStart=submesh._subIndexBufferStart;
- var subIndexBufferCount=submesh._subIndexBufferCount;
- var boneIndicesList=submesh._boneIndicesList;
- var drawCount=LoadModelV05._readData.getUint16();
- subIndexBufferStart.length=drawCount;
- subIndexBufferCount.length=drawCount;
- boneIndicesList.length=drawCount;
- var pathMarks=LoadModelV05._mesh._skinDataPathMarks;
- var bindPoseIndices=LoadModelV05._bindPoseIndices;
- var subMeshIndex=LoadModelV05._subMeshes.length;
- for (var i=0;i < drawCount;i++){
- subIndexBufferStart[i]=LoadModelV05._readData.getUint32();
- subIndexBufferCount[i]=LoadModelV05._readData.getUint32();
- var boneDicofs=LoadModelV05._readData.getUint32();
- var boneDicCount=LoadModelV05._readData.getUint32();
- var boneIndices=boneIndicesList[i]=new Uint16Array(arrayBuffer.slice(offset+boneDicofs,offset+boneDicofs+boneDicCount));
- for (var j=0,m=boneIndices.length;j < m;j++){
- var index=boneIndices[j];
- var combineIndex=bindPoseIndices.indexOf(index);
- if (combineIndex===-1){
- boneIndices[j]=bindPoseIndices.length;
- bindPoseIndices.push(index);
- pathMarks.push([subMeshIndex,i,j]);
- }else {
- boneIndices[j]=combineIndex;
- }
- }
- }
- LoadModelV05._subMeshes.push(submesh);
- return true;
- }
- LoadModelV05._strings=[];
- LoadModelV05._readData=null;
- LoadModelV05._version=null;
- LoadModelV05._mesh=null;
- LoadModelV05._subMeshes=null;
- LoadModelV05._bindPoseIndices=[];
- __static(LoadModelV05,
- ['_BLOCK',function(){return this._BLOCK={count:0};},'_DATA',function(){return this._DATA={offset:0,size:0};}
- ]);
- return LoadModelV05;
- })()
- /**
- *<code>Color</code> 类用于创建颜色实例。
- */
- //class laya.d3.math.Color
- var Color=(function(){
- function Color(r,g,b,a){
- /**red分量*/
- this.r=NaN;
- /**green分量*/
- this.g=NaN;
- /**blue分量*/
- this.b=NaN;
- /**alpha分量*/
- this.a=NaN;
- (r===void 0)&& (r=1);
- (g===void 0)&& (g=1);
- (b===void 0)&& (b=1);
- (a===void 0)&& (a=1);
- this.r=r;
- this.g=g;
- this.b=b;
- this.a=a;
- }
- __class(Color,'laya.d3.math.Color');
- var __proto=Color.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *Gamma空间转换到线性空间。
- *@param linear 线性空间颜色。
- */
- __proto.toLinear=function(out){
- out.r=Utils3D.gammaToLinearSpace(this.r);
- out.g=Utils3D.gammaToLinearSpace(this.g);
- out.b=Utils3D.gammaToLinearSpace(this.b);
- }
- /**
- *线性空间转换到Gamma空间。
- *@param gamma Gamma空间颜色。
- */
- __proto.toGamma=function(out){
- out.r=Utils3D.linearToGammaSpace(this.r);
- out.g=Utils3D.linearToGammaSpace(this.g);
- out.b=Utils3D.linearToGammaSpace(this.b);
- }
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var destColor=destObject;
- destColor.r=this.r;
- destColor.g=this.g;
- destColor.b=this.b;
- destColor.a=this.a;
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var dest=/*__JS__ */new this.constructor();
- this.cloneTo(dest);
- return dest;
- }
- __proto.forNativeElement=function(nativeElements){
- if (nativeElements){
- /*__JS__ */this.elements=nativeElements;
- /*__JS__ */this.elements[0]=this.r;
- /*__JS__ */this.elements[1]=this.g;
- /*__JS__ */this.elements[2]=this.b;
- /*__JS__ */this.elements[3]=this.a;
- }else {
- /*__JS__ */this.elements=new Float32Array([this.r,this.g,this.b,this.a]);
- }
- Vector2.rewriteNumProperty(this,"r",0);
- Vector2.rewriteNumProperty(this,"g",1);
- Vector2.rewriteNumProperty(this,"b",2);
- Vector2.rewriteNumProperty(this,"a",3);
- }
- __static(Color,
- ['RED',function(){return this.RED=new Color(1,0,0,1);},'GREEN',function(){return this.GREEN=new Color(0,1,0,1);},'BLUE',function(){return this.BLUE=new Color(0,0,1,1);},'CYAN',function(){return this.CYAN=new Color(0,1,1,1);},'YELLOW',function(){return this.YELLOW=new Color(1,0.92,0.016,1);},'MAGENTA',function(){return this.MAGENTA=new Color(1,0,1,1);},'GRAY',function(){return this.GRAY=new Color(0.5,0.5,0.5,1);},'WHITE',function(){return this.WHITE=new Color(1,1,1,1);},'BLACK',function(){return this.BLACK=new Color(0,0,0,1);}
- ]);
- return Color;
- })()
- /**
- *@private
- *<code>LoadModel</code> 类用于模型加载。
- */
- //class laya.d3.loaders.LoadModelV04
- var LoadModelV04=(function(){
- function LoadModelV04(){}
- __class(LoadModelV04,'laya.d3.loaders.LoadModelV04');
- LoadModelV04.parse=function(readData,version,mesh,subMeshes){
- LoadModelV04._mesh=mesh;
- LoadModelV04._subMeshes=subMeshes;
- LoadModelV04._version=version;
- LoadModelV04._readData=readData;
- LoadModelV04.READ_DATA();
- LoadModelV04.READ_BLOCK();
- LoadModelV04.READ_STRINGS();
- for (var i=0,n=LoadModelV04._BLOCK.count;i < n;i++){
- LoadModelV04._readData.pos=LoadModelV04._BLOCK.blockStarts[i];
- var index=LoadModelV04._readData.getUint16();
- var blockName=LoadModelV04._strings[index];
- var fn=LoadModelV04["READ_"+blockName];
- if (fn==null)
- throw new Error("model file err,no this function:"+index+" "+blockName);
- else
- fn.call(null);
- }
- LoadModelV04._mesh._bindPoseIndices=new Uint16Array(LoadModelV04._bindPoseIndices);
- LoadModelV04._bindPoseIndices.length=0;
- LoadModelV04._strings.length=0;
- LoadModelV04._readData=null;
- LoadModelV04._version=null;
- LoadModelV04._mesh=null;
- LoadModelV04._subMeshes=null;
- }
- LoadModelV04._readString=function(){
- return LoadModelV04._strings[LoadModelV04._readData.getUint16()];
- }
- LoadModelV04.READ_DATA=function(){
- LoadModelV04._DATA.offset=LoadModelV04._readData.getUint32();
- LoadModelV04._DATA.size=LoadModelV04._readData.getUint32();
- }
- LoadModelV04.READ_BLOCK=function(){
- var count=LoadModelV04._BLOCK.count=LoadModelV04._readData.getUint16();
- var blockStarts=LoadModelV04._BLOCK.blockStarts=[];
- var blockLengths=LoadModelV04._BLOCK.blockLengths=[];
- for (var i=0;i < count;i++){
- blockStarts.push(LoadModelV04._readData.getUint32());
- blockLengths.push(LoadModelV04._readData.getUint32());
- }
- }
- LoadModelV04.READ_STRINGS=function(){
- var offset=LoadModelV04._readData.getUint32();
- var count=LoadModelV04._readData.getUint16();
- var prePos=LoadModelV04._readData.pos;
- LoadModelV04._readData.pos=offset+LoadModelV04._DATA.offset;
- for (var i=0;i < count;i++)
- LoadModelV04._strings[i]=LoadModelV04._readData.readUTFString();
- LoadModelV04._readData.pos=prePos;
- }
- LoadModelV04.READ_MESH=function(){
- var name=LoadModelV04._readString();
- var arrayBuffer=LoadModelV04._readData.__getBuffer();
- var i=0,n=0;
- var memorySize=0;
- var vertexBufferCount=LoadModelV04._readData.getInt16();
- var offset=LoadModelV04._DATA.offset;
- for (i=0;i < vertexBufferCount;i++){
- var vbStart=offset+LoadModelV04._readData.getUint32();
- var vbLength=LoadModelV04._readData.getUint32();
- var vbDatas=new Float32Array(arrayBuffer.slice(vbStart,vbStart+vbLength));
- var bufferAttribute=LoadModelV04._readString();
- var vertexDeclaration;
- switch (LoadModelV04._version){
- case "LAYAMODEL:0301":
- case "LAYAMODEL:0400":
- vertexDeclaration=VertexMesh.getVertexDeclaration(bufferAttribute);
- break ;
- case "LAYAMODEL:0401":
- vertexDeclaration=VertexMesh.getVertexDeclaration(bufferAttribute,false);
- break ;
- default :
- throw new Error("LoadModelV03: unknown version.");
- }
- if (!vertexDeclaration)
- throw new Error("LoadModelV03: unknown vertexDeclaration.");
- var vertexBuffer=new VertexBuffer3D(vbDatas.length *4,/*laya.webgl.WebGLContext.STATIC_DRAW*/0x88E4,true);
- vertexBuffer.vertexDeclaration=vertexDeclaration;
- vertexBuffer.setData(vbDatas);
- LoadModelV04._mesh._vertexBuffers.push(vertexBuffer);
- LoadModelV04._mesh._vertexCount+=vertexBuffer.vertexCount;
- memorySize+=vbDatas.length *4;
- };
- var ibStart=offset+LoadModelV04._readData.getUint32();
- var ibLength=LoadModelV04._readData.getUint32();
- var ibDatas=new Uint16Array(arrayBuffer.slice(ibStart,ibStart+ibLength));
- var indexBuffer=new IndexBuffer3D(/*laya.d3.graphics.IndexBuffer3D.INDEXTYPE_USHORT*/"ushort",ibLength / 2,/*laya.webgl.WebGLContext.STATIC_DRAW*/0x88E4,true);
- indexBuffer.setData(ibDatas);
- LoadModelV04._mesh._indexBuffer=indexBuffer;
- memorySize+=indexBuffer.indexCount *2;
- LoadModelV04._mesh._setBuffer(LoadModelV04._mesh._vertexBuffers,indexBuffer);
- LoadModelV04._mesh._setCPUMemory(memorySize);
- LoadModelV04._mesh._setGPUMemory(memorySize);
- var boneNames=LoadModelV04._mesh._boneNames=[];
- var boneCount=LoadModelV04._readData.getUint16();
- boneNames.length=boneCount;
- for (i=0;i < boneCount;i++)
- boneNames[i]=LoadModelV04._strings[LoadModelV04._readData.getUint16()];
- LoadModelV04._readData.pos+=8;
- var bindPoseDataStart=LoadModelV04._readData.getUint32();
- var bindPoseDataLength=LoadModelV04._readData.getUint32();
- var bindPoseDatas=new Float32Array(arrayBuffer.slice(offset+bindPoseDataStart,offset+bindPoseDataStart+bindPoseDataLength));
- var bindPoseFloatCount=bindPoseDatas.length;
- var bindPoseCount=bindPoseFloatCount / 16;
- var bindPoseBuffer=LoadModelV04._mesh._inverseBindPosesBuffer=new ArrayBuffer(bindPoseFloatCount *4);
- LoadModelV04._mesh._inverseBindPoses=__newvec(bindPoseCount);
- for (i=0;i < bindPoseFloatCount;i+=16){
- 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));
- LoadModelV04._mesh._inverseBindPoses[i / 16]=inverseGlobalBindPose;
- }
- return true;
- }
- LoadModelV04.READ_SUBMESH=function(){
- var arrayBuffer=LoadModelV04._readData.__getBuffer();
- var submesh=new SubMesh(LoadModelV04._mesh);
- var vbIndex=LoadModelV04._readData.getInt16();
- LoadModelV04._readData.getUint32();
- LoadModelV04._readData.getUint32();
- var ibStart=LoadModelV04._readData.getUint32();
- var ibCount=LoadModelV04._readData.getUint32();
- var indexBuffer=LoadModelV04._mesh._indexBuffer;
- submesh._indexBuffer=indexBuffer;
- submesh._indexStart=ibStart;
- submesh._indexCount=ibCount;
- submesh._indices=new Uint16Array(indexBuffer.getData().buffer,ibStart *2,ibCount);
- var vertexBuffer=LoadModelV04._mesh._vertexBuffers[vbIndex];
- submesh._vertexBuffer=vertexBuffer;
- var offset=LoadModelV04._DATA.offset;
- var subIndexBufferStart=submesh._subIndexBufferStart;
- var subIndexBufferCount=submesh._subIndexBufferCount;
- var boneIndicesList=submesh._boneIndicesList;
- var drawCount=LoadModelV04._readData.getUint16();
- subIndexBufferStart.length=drawCount;
- subIndexBufferCount.length=drawCount;
- boneIndicesList.length=drawCount;
- var pathMarks=LoadModelV04._mesh._skinDataPathMarks;
- var bindPoseIndices=LoadModelV04._bindPoseIndices;
- var subMeshIndex=LoadModelV04._subMeshes.length;
- for (var i=0;i < drawCount;i++){
- subIndexBufferStart[i]=LoadModelV04._readData.getUint32();
- subIndexBufferCount[i]=LoadModelV04._readData.getUint32();
- var boneDicofs=LoadModelV04._readData.getUint32();
- var boneDicCount=LoadModelV04._readData.getUint32();
- var boneIndices=boneIndicesList[i]=new Uint16Array(arrayBuffer.slice(offset+boneDicofs,offset+boneDicofs+boneDicCount));
- for (var j=0,m=boneIndices.length;j < m;j++){
- var index=boneIndices[j];
- var combineIndex=bindPoseIndices.indexOf(index);
- if (combineIndex===-1){
- boneIndices[j]=bindPoseIndices.length;
- bindPoseIndices.push(index);
- pathMarks.push([subMeshIndex,i,j]);
- }else {
- boneIndices[j]=combineIndex;
- }
- }
- }
- LoadModelV04._subMeshes.push(submesh);
- return true;
- }
- LoadModelV04._strings=[];
- LoadModelV04._readData=null;
- LoadModelV04._version=null;
- LoadModelV04._mesh=null;
- LoadModelV04._subMeshes=null;
- LoadModelV04._bindPoseIndices=[];
- __static(LoadModelV04,
- ['_BLOCK',function(){return this._BLOCK={count:0};},'_DATA',function(){return this._DATA={offset:0,size:0};}
- ]);
- return LoadModelV04;
- })()
- /**
- *...
- *@author ...
- */
- //class laya.d3.graphics.Vertex.VertexMesh
- var VertexMesh=(function(){
- function VertexMesh(){}
- __class(VertexMesh,'laya.d3.graphics.Vertex.VertexMesh');
- VertexMesh.getVertexDeclaration=function(vertexFlag,compatible){
- (compatible===void 0)&& (compatible=true);
- var verDec=VertexMesh._vertexDeclarationMap[vertexFlag+(compatible?"_0":"_1")];
- if (!verDec){
- var subFlags=vertexFlag.split(",");
- var offset=0;
- var elements=[];
- for (var i=0,n=subFlags.length;i < n;i++){
- var element;
- switch (subFlags[i]){
- case "POSITION":
- element=new VertexElement(offset,/*laya.d3.graphics.VertexElementFormat.Vector3*/"vector3",/*CLASS CONST:laya.d3.graphics.Vertex.VertexMesh.MESH_POSITION0*/0);
- offset+=12;
- break ;
- case "NORMAL":
- element=new VertexElement(offset,/*laya.d3.graphics.VertexElementFormat.Vector3*/"vector3",/*CLASS CONST:laya.d3.graphics.Vertex.VertexMesh.MESH_NORMAL0*/3);
- offset+=12;
- break ;
- case "COLOR":
- element=new VertexElement(offset,/*laya.d3.graphics.VertexElementFormat.Vector4*/"vector4",/*CLASS CONST:laya.d3.graphics.Vertex.VertexMesh.MESH_COLOR0*/1);
- offset+=16;
- break ;
- case "UV":
- element=new VertexElement(offset,/*laya.d3.graphics.VertexElementFormat.Vector2*/"vector2",/*CLASS CONST:laya.d3.graphics.Vertex.VertexMesh.MESH_TEXTURECOORDINATE0*/2);
- offset+=8;
- break ;
- case "UV1":
- element=new VertexElement(offset,/*laya.d3.graphics.VertexElementFormat.Vector2*/"vector2",/*CLASS CONST:laya.d3.graphics.Vertex.VertexMesh.MESH_TEXTURECOORDINATE1*/7);
- offset+=8;
- break ;
- case "BLENDWEIGHT":
- element=new VertexElement(offset,/*laya.d3.graphics.VertexElementFormat.Vector4*/"vector4",/*CLASS CONST:laya.d3.graphics.Vertex.VertexMesh.MESH_BLENDWEIGHT0*/6);
- offset+=16;
- break ;
- case "BLENDINDICES":
- if (compatible){
- element=new VertexElement(offset,/*laya.d3.graphics.VertexElementFormat.Vector4*/"vector4",/*CLASS CONST:laya.d3.graphics.Vertex.VertexMesh.MESH_BLENDINDICES0*/5);
- offset+=16;
- }else {
- element=new VertexElement(offset,/*laya.d3.graphics.VertexElementFormat.Byte4*/"byte4",/*CLASS CONST:laya.d3.graphics.Vertex.VertexMesh.MESH_BLENDINDICES0*/5);
- offset+=4;
- }
- break ;
- case "TANGENT":
- element=new VertexElement(offset,/*laya.d3.graphics.VertexElementFormat.Vector4*/"vector4",/*CLASS CONST:laya.d3.graphics.Vertex.VertexMesh.MESH_TANGENT0*/4);
- offset+=16;
- break ;
- default :
- throw "VertexMesh: unknown vertex flag.";
- }
- elements.push(element);
- }
- verDec=new VertexDeclaration(offset,elements);
- VertexMesh._vertexDeclarationMap[vertexFlag+(compatible?"_0":"_1")]=verDec;
- }
- return verDec;
- }
- VertexMesh.MESH_POSITION0=0;
- VertexMesh.MESH_COLOR0=1;
- VertexMesh.MESH_TEXTURECOORDINATE0=2;
- VertexMesh.MESH_NORMAL0=3;
- VertexMesh.MESH_TANGENT0=4;
- VertexMesh.MESH_BLENDINDICES0=5;
- VertexMesh.MESH_BLENDWEIGHT0=6;
- VertexMesh.MESH_TEXTURECOORDINATE1=7;
- VertexMesh.MESH_WORLDMATRIX_ROW0=8;
- VertexMesh.MESH_WORLDMATRIX_ROW1=9;
- VertexMesh.MESH_WORLDMATRIX_ROW2=10;
- VertexMesh.MESH_WORLDMATRIX_ROW3=11;
- VertexMesh.MESH_MVPMATRIX_ROW0=12;
- VertexMesh.MESH_MVPMATRIX_ROW1=13;
- VertexMesh.MESH_MVPMATRIX_ROW2=14;
- VertexMesh.MESH_MVPMATRIX_ROW3=15;
- VertexMesh._vertexDeclarationMap={};
- __static(VertexMesh,
- ['instanceWorldMatrixDeclaration',function(){return this.instanceWorldMatrixDeclaration=new VertexDeclaration(64,
- [new VertexElement(0,/*laya.d3.graphics.VertexElementFormat.Vector4*/"vector4",/*CLASS CONST:laya.d3.graphics.Vertex.VertexMesh.MESH_WORLDMATRIX_ROW0*/8),
- new VertexElement(16,/*laya.d3.graphics.VertexElementFormat.Vector4*/"vector4",/*CLASS CONST:laya.d3.graphics.Vertex.VertexMesh.MESH_WORLDMATRIX_ROW1*/9),
- new VertexElement(32,/*laya.d3.graphics.VertexElementFormat.Vector4*/"vector4",/*CLASS CONST:laya.d3.graphics.Vertex.VertexMesh.MESH_WORLDMATRIX_ROW2*/10),
- new VertexElement(48,/*laya.d3.graphics.VertexElementFormat.Vector4*/"vector4",/*CLASS CONST:laya.d3.graphics.Vertex.VertexMesh.MESH_WORLDMATRIX_ROW3*/11)]);},'instanceMVPMatrixDeclaration',function(){return this.instanceMVPMatrixDeclaration=new VertexDeclaration(64,
- [new VertexElement(0,/*laya.d3.graphics.VertexElementFormat.Vector4*/"vector4",/*CLASS CONST:laya.d3.graphics.Vertex.VertexMesh.MESH_MVPMATRIX_ROW0*/12),
- new VertexElement(16,/*laya.d3.graphics.VertexElementFormat.Vector4*/"vector4",/*CLASS CONST:laya.d3.graphics.Vertex.VertexMesh.MESH_MVPMATRIX_ROW1*/13),
- new VertexElement(32,/*laya.d3.graphics.VertexElementFormat.Vector4*/"vector4",/*CLASS CONST:laya.d3.graphics.Vertex.VertexMesh.MESH_MVPMATRIX_ROW2*/14),
- new VertexElement(48,/*laya.d3.graphics.VertexElementFormat.Vector4*/"vector4",/*CLASS CONST:laya.d3.graphics.Vertex.VertexMesh.MESH_MVPMATRIX_ROW3*/15)]);}
- ]);
- return VertexMesh;
- })()
- /**
- *<code>Emission</code> 类用于粒子发射器。
- */
- //class laya.d3.core.particleShuriKen.module.Emission
- var Emission=(function(){
- function Emission(){
- /**@private */
- this._destroyed=false;
- /**@private 粒子发射速率,每秒发射的个数。*/
- this._emissionRate=0;
- /**@private 粒子的爆裂,不允许修改。*/
- this._bursts=null;
- /**是否启用。*/
- this.enbale=false;
- this._destroyed=false;
- this.emissionRate=10;
- this._bursts=[];
- }
- __class(Emission,'laya.d3.core.particleShuriKen.module.Emission');
- var __proto=Emission.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true,"laya.resource.IDestroy":true})
- /**
- *@private
- */
- __proto.destroy=function(){
- this._bursts=null;
- this._destroyed=true;
- }
- /**
- *获取粒子爆裂个数。
- *@return 粒子爆裂个数。
- */
- __proto.getBurstsCount=function(){
- return this._bursts.length;
- }
- /**
- *通过索引获取粒子爆裂。
- *@param index 爆裂索引。
- *@return 粒子爆裂。
- */
- __proto.getBurstByIndex=function(index){
- return this._bursts[index];
- }
- /**
- *增加粒子爆裂。
- *@param burst 爆裂。
- */
- __proto.addBurst=function(burst){
- var burstsCount=this._bursts.length;
- if (burstsCount > 0)
- for (var i=0;i < burstsCount;i++){
- if (this._bursts[i].time > burst.time)
- this._bursts.splice(i,0,burst);
- }
- this._bursts.push(burst);
- }
- /**
- *移除粒子爆裂。
- *@param burst 爆裂。
- */
- __proto.removeBurst=function(burst){
- var index=this._bursts.indexOf(burst);
- if (index!==-1){
- this._bursts.splice(index,1);
- }
- }
- /**
- *通过索引移除粒子爆裂。
- *@param index 爆裂索引。
- */
- __proto.removeBurstByIndex=function(index){
- this._bursts.splice(index,1);
- }
- /**
- *清空粒子爆裂。
- */
- __proto.clearBurst=function(){
- this._bursts.length=0;
- }
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var destEmission=destObject;
- var destBursts=destEmission._bursts;
- destBursts.length=this._bursts.length;
- for (var i=0,n=this._bursts.length;i < n;i++){
- var destBurst=destBursts[i];
- if (destBurst)
- this._bursts[i].cloneTo(destBurst);
- else
- destBursts[i]=this._bursts[i].clone();
- }
- destEmission._emissionRate=this._emissionRate;
- destEmission.enbale=this.enbale;
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var destEmission=/*__JS__ */new this.constructor();
- this.cloneTo(destEmission);
- return destEmission;
- }
- /**
- *获取是否已销毁。
- *@return 是否已销毁。
- */
- __getset(0,__proto,'destroyed',function(){
- return this._destroyed;
- });
- /**
- *设置粒子发射速率。
- *@param emissionRate 粒子发射速率 (个/秒)。
- */
- /**
- *获取粒子发射速率。
- *@return 粒子发射速率 (个/秒)。
- */
- __getset(0,__proto,'emissionRate',function(){
- return this._emissionRate;
- },function(value){
- if (value < 0)
- throw new Error("ParticleBaseShape:emissionRate value must large or equal than 0.");
- this._emissionRate=value;
- });
- return Emission;
- })()
- /**
- *<code>BoundSphere</code> 类用于创建包围球。
- */
- //class laya.d3.math.BoundSphere
- var BoundSphere=(function(){
- function BoundSphere(center,radius){
- /**包围球的中心。*/
- this.center=null;
- /**包围球的半径。*/
- this.radius=NaN;
- this.center=center;
- this.radius=radius;
- }
- __class(BoundSphere,'laya.d3.math.BoundSphere');
- var __proto=BoundSphere.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- __proto.toDefault=function(){
- this.center.toDefault();
- this.radius=0;
- }
- /**
- *判断射线是否与碰撞球交叉,并返回交叉距离。
- *@param ray 射线。
- *@return 距离交叉点的距离,-1表示不交叉。
- */
- __proto.intersectsRayDistance=function(ray){
- return CollisionUtils.intersectsRayAndSphereRD(ray,this);
- }
- /**
- *判断射线是否与碰撞球交叉,并返回交叉点。
- *@param ray 射线。
- *@param outPoint 交叉点。
- *@return 距离交叉点的距离,-1表示不交叉。
- */
- __proto.intersectsRayPoint=function(ray,outPoint){
- return CollisionUtils.intersectsRayAndSphereRP(ray,this,outPoint);
- }
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var dest=destObject;
- this.center.cloneTo(dest.center);
- dest.radius=this.radius;
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var dest=/*__JS__ */new this.constructor(new Vector3(),new Vector3());
- this.cloneTo(dest);
- return dest;
- }
- BoundSphere.createFromSubPoints=function(points,start,count,out){
- if (points==null){
- throw new Error("points");
- }
- if (start < 0 || start >=points.length){
- throw new Error("start"+start+"Must be in the range [0, "+(points.length-1)+"]");
- }
- if (count < 0 || (start+count)> points.length){
- throw new Error("count"+count+"Must be in the range <= "+points.length+"}");
- };
- var upperEnd=start+count;
- var center=BoundSphere._tempVector3;
- center.x=0;
- center.y=0;
- center.z=0;
- for (var i=start;i < upperEnd;++i){
- Vector3.add(points[i],center,center);
- };
- var outCenter=out.center;
- Vector3.scale(center,1 / count,outCenter);
- var radius=0.0;
- for (i=start;i < upperEnd;++i){
- var distance=Vector3.distanceSquared(outCenter,points[i]);
- if (distance > radius)
- radius=distance;
- }
- out.radius=Math.sqrt(radius);
- }
- BoundSphere.createfromPoints=function(points,out){
- if (points==null){
- throw new Error("points");
- }
- BoundSphere.createFromSubPoints(points,0,points.length,out);
- }
- __static(BoundSphere,
- ['_tempVector3',function(){return this._tempVector3=new Vector3();}
- ]);
- return BoundSphere;
- })()
- /**
- *@private
- *<code>RenderElement</code> 类用于实现渲染元素。
- */
- //class laya.d3.core.render.RenderElement
- var RenderElement=(function(){
- function RenderElement(){
- /**@private */
- //this._transform=null;
- /**@private */
- //this._geometry=null;
- /**@private */
- //this.material=null;
- /**@private */
- //this.render=null;
- /**@private */
- //this.staticBatch=null;
- this.renderType=/*CLASS CONST:laya.d3.core.render.RenderElement.RENDERTYPE_NORMAL*/0;
- }
- __class(RenderElement,'laya.d3.core.render.RenderElement');
- var __proto=RenderElement.prototype;
- /**
- *@private
- */
- __proto.setTransform=function(transform){
- this._transform=transform;
- }
- /**
- *@private
- */
- __proto.setGeometry=function(geometry){
- this._geometry=geometry;
- }
- /**
- *@private
- */
- __proto.addToOpaqueRenderQueue=function(context,queue){
- queue.elements.push(this);
- }
- /**
- *@private
- */
- __proto.addToTransparentRenderQueue=function(context,queue){
- queue.elements.push(this);
- queue.lastTransparentBatched=false;
- queue.lastTransparentRenderElement=this;
- }
- /**
- *@private
- */
- __proto._render=function(context,isTarget,customShader,replacementTag){
- var lastStateMaterial,lastStateShaderInstance,lastStateRender;
- var updateMark=Camera._updateMark;
- var scene=context.scene;
- var camera=context.camera;
- var transform=this._transform;
- var geometry=this._geometry;
- context.renderElement=this;
- var updateRender=updateMark!==this.render._updateMark || this.renderType!==this.render._updateRenderType;
- if (updateRender){
- this.render._renderUpdate(context,transform);
- this.render._renderUpdateWithCamera(context,transform);
- this.render._updateMark=updateMark;
- this.render._updateRenderType=this.renderType;
- }
- if (geometry._prepareRender(context)){
- var subShader=this.material._shader.getSubShaderAt(0);
- var passes;
- if (customShader){
- if (replacementTag){
- var oriTag=subShader.getFlag(replacementTag);
- if (oriTag){
- var customSubShaders=customShader._subShaders;
- for (var k=0,p=customSubShaders.length;k < p;k++){
- var customSubShader=customSubShaders[k];
- if (oriTag===customSubShader.getFlag(replacementTag)){
- passes=customSubShader._passes;
- break ;
- }
- }
- if (!passes)
- return;
- }else {
- return;
- }
- }else {
- passes=customShader.getSubShaderAt(0)._passes;
- }
- }else {
- passes=subShader._passes;
- }
- for (var j=0,m=passes.length;j < m;j++){
- var shaderPass=context.shader=passes[j].withCompile((scene._defineDatas.value)& (~this.material._disablePublicDefineDatas.value),this.render._defineDatas.value,this.material._defineDatas.value);
- var switchShader=shaderPass.bind();
- var switchUpdateMark=(updateMark!==shaderPass._uploadMark);
- var uploadScene=(shaderPass._uploadScene!==scene)|| switchUpdateMark;
- if (uploadScene || switchShader){
- shaderPass.uploadUniforms(shaderPass._sceneUniformParamsMap,scene._shaderValues,uploadScene);
- shaderPass._uploadScene=scene;
- };
- var uploadSprite3D=(shaderPass._uploadRender!==this.render || shaderPass._uploadRenderType!==this.renderType)|| switchUpdateMark;
- if (uploadSprite3D || switchShader){
- shaderPass.uploadUniforms(shaderPass._spriteUniformParamsMap,this.render._shaderValues,uploadSprite3D);
- shaderPass._uploadRender=this.render;
- shaderPass._uploadRenderType=this.renderType;
- };
- var uploadCamera=shaderPass._uploadCamera!==camera || switchUpdateMark;
- if (uploadCamera || switchShader){
- shaderPass.uploadUniforms(shaderPass._cameraUniformParamsMap,camera._shaderValues,uploadCamera);
- shaderPass._uploadCamera=camera;
- };
- var uploadMaterial=(shaderPass._uploadMaterial!==this.material)|| switchUpdateMark;
- if (uploadMaterial || switchShader){
- shaderPass.uploadUniforms(shaderPass._materialUniformParamsMap,this.material._shaderValues,uploadMaterial);
- shaderPass._uploadMaterial=this.material;
- };
- var matValues=this.material._shaderValues;
- if (lastStateMaterial!==this.material||lastStateShaderInstance!==shaderPass){
- shaderPass.uploadRenderStateBlendDepth(matValues);
- shaderPass.uploadRenderStateFrontFace(matValues,isTarget,transform);
- lastStateMaterial=this.material;
- lastStateShaderInstance=shaderPass;
- lastStateRender=this.render;
- }else {
- if (lastStateRender!==this.render){
- shaderPass.uploadRenderStateFrontFace(matValues,isTarget,transform);
- lastStateRender=this.render;
- }
- }
- geometry._render(context);
- shaderPass._uploadMark=updateMark;
- }
- }
- if (updateRender && this.renderType!==/*CLASS CONST:laya.d3.core.render.RenderElement.RENDERTYPE_NORMAL*/0)
- this.render._revertBatchRenderUpdate(context);
- Camera._updateMark++;
- }
- /**
- *@private
- */
- __proto.destroy=function(){
- this._transform=null;
- this._geometry=null;
- this.material=null;
- this.render=null;
- }
- RenderElement.RENDERTYPE_NORMAL=0;
- RenderElement.RENDERTYPE_STATICBATCH=1;
- RenderElement.RENDERTYPE_INSTANCEBATCH=2;
- RenderElement.RENDERTYPE_VERTEXBATCH=3;
- return RenderElement;
- })()
- /**
- *<code>HalfFloatUtils</code> 类用于创建HalfFloat工具。
- */
- //class laya.d3.math.HalfFloatUtils
- var HalfFloatUtils=(function(){
- function HalfFloatUtils(){}
- __class(HalfFloatUtils,'laya.d3.math.HalfFloatUtils');
- HalfFloatUtils.__init__=function(){
- for (var i=0;i < 256;++i){
- var e=i-127;
- if (e <-27){
- HalfFloatUtils._baseTable[i | 0x000]=0x0000;
- HalfFloatUtils._baseTable[i | 0x100]=0x8000;
- HalfFloatUtils._shiftTable[i | 0x000]=24;
- HalfFloatUtils._shiftTable[i | 0x100]=24;
- }else if (e <-14){
- HalfFloatUtils._baseTable[i | 0x000]=0x0400 >> (-e-14);
- HalfFloatUtils._baseTable[i | 0x100]=(0x0400 >> (-e-14))| 0x8000;
- HalfFloatUtils._shiftTable[i | 0x000]=-e-1;
- HalfFloatUtils._shiftTable[i | 0x100]=-e-1;
- }else if (e <=15){
- HalfFloatUtils._baseTable[i | 0x000]=(e+15)<< 10;
- HalfFloatUtils._baseTable[i | 0x100]=((e+15)<< 10)| 0x8000;
- HalfFloatUtils._shiftTable[i | 0x000]=13;
- HalfFloatUtils._shiftTable[i | 0x100]=13;
- }else if (e < 128){
- HalfFloatUtils._baseTable[i | 0x000]=0x7c00;
- HalfFloatUtils._baseTable[i | 0x100]=0xfc00;
- HalfFloatUtils._shiftTable[i | 0x000]=24;
- HalfFloatUtils._shiftTable[i | 0x100]=24;
- }else {
- HalfFloatUtils._baseTable[i | 0x000]=0x7c00;
- HalfFloatUtils._baseTable[i | 0x100]=0xfc00;
- HalfFloatUtils._shiftTable[i | 0x000]=13;
- HalfFloatUtils._shiftTable[i | 0x100]=13;
- }
- }
- HalfFloatUtils._mantissaTable[0]=0;
- for (i=1;i < 1024;++i){
- var m=i << 13;
- e=0;
- while ((m & 0x00800000)===0){
- e-=0x00800000;
- m <<=1;
- }
- m &=~0x00800000;
- e+=0x38800000;
- HalfFloatUtils._mantissaTable[i]=m | e;
- }
- for (i=1024;i < 2048;++i){
- HalfFloatUtils._mantissaTable[i]=0x38000000+((i-1024)<< 13);
- }
- HalfFloatUtils._exponentTable[0]=0;
- for (i=1;i < 31;++i){
- HalfFloatUtils._exponentTable[i]=i << 23;
- }
- HalfFloatUtils._exponentTable[31]=0x47800000;
- HalfFloatUtils._exponentTable[32]=0x80000000;
- for (i=33;i < 63;++i){
- HalfFloatUtils._exponentTable[i]=0x80000000+((i-32)<< 23);
- }
- HalfFloatUtils._exponentTable[63]=0xc7800000;
- HalfFloatUtils._offsetTable[0]=0;
- for (i=1;i < 64;++i){
- if (i===32){
- HalfFloatUtils._offsetTable[i]=0;
- }else {
- HalfFloatUtils._offsetTable[i]=1024;
- }
- }
- }
- HalfFloatUtils.roundToFloat16Bits=function(num){
- HalfFloatUtils._floatView[0]=num;
- var f=HalfFloatUtils._uint32View[0];
- var e=(f >> 23)& 0x1ff;
- return HalfFloatUtils._baseTable[e]+((f & 0x007fffff)>> HalfFloatUtils._shiftTable[e]);
- }
- HalfFloatUtils.convertToNumber=function(float16bits){
- var m=float16bits >> 10;
- HalfFloatUtils._uint32View[0]=HalfFloatUtils._mantissaTable[HalfFloatUtils._offsetTable[m]+(float16bits & 0x3ff)]+HalfFloatUtils._exponentTable[m];
- return HalfFloatUtils._floatView[0];
- }
- __static(HalfFloatUtils,
- ['_buffer',function(){return this._buffer=new ArrayBuffer(4);},'_floatView',function(){return this._floatView=new Float32Array(HalfFloatUtils._buffer);},'_uint32View',function(){return this._uint32View=new Uint32Array(HalfFloatUtils._buffer);},'_baseTable',function(){return this._baseTable=new Uint32Array(512);},'_shiftTable',function(){return this._shiftTable=new Uint32Array(512);},'_mantissaTable',function(){return this._mantissaTable=new Uint32Array(2048);},'_exponentTable',function(){return this._exponentTable=new Uint32Array(64);},'_offsetTable',function(){return this._offsetTable=new Uint32Array(64);}
- ]);
- return HalfFloatUtils;
- })()
- /**
- *<code>SkyMesh</code> 类用于实现天空网格。
- */
- //class laya.d3.resource.models.SkyMesh
- var SkyMesh=(function(){
- function SkyMesh(){
- /**@private */
- this._vertexBuffer=null;
- /**@private */
- this._indexBuffer=null;
- /**@private */
- this._bufferState=null;
- }
- __class(SkyMesh,'laya.d3.resource.models.SkyMesh');
- var __proto=SkyMesh.prototype;
- /**
- *@private
- */
- __proto._render=function(state){}
- return SkyMesh;
- })()
- /**
- *<code>TextureSheetAnimation</code> 类用于创建粒子帧动画。
- */
- //class laya.d3.core.particleShuriKen.module.TextureSheetAnimation
- var TextureSheetAnimation=(function(){
- function TextureSheetAnimation(frame,startFrame){
- /**@private */
- this._frame=null;
- /**@private */
- this._startFrame=null;
- /**纹理平铺。*/
- this.tiles=null;
- /**类型,0为whole sheet、1为singal row。*/
- this.type=0;
- /**是否随机行,type为1时有效。*/
- this.randomRow=false;
- /**行索引,type为1时有效。*/
- this.rowIndex=0;
- /**循环次数。*/
- this.cycles=0;
- /**UV通道类型,0为Noting,1为Everything,待补充,暂不支持。*/
- this.enableUVChannels=0;
- /**是否启用*/
- this.enable=false;
- this.tiles=new Vector2(1,1);
- this.type=0;
- this.randomRow=true;
- this.rowIndex=0;
- this.cycles=1;
- this.enableUVChannels=1;
- this._frame=frame;
- this._startFrame=startFrame;
- }
- __class(TextureSheetAnimation,'laya.d3.core.particleShuriKen.module.TextureSheetAnimation');
- var __proto=TextureSheetAnimation.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var destTextureSheetAnimation=destObject;
- this.tiles.cloneTo(destTextureSheetAnimation.tiles);
- destTextureSheetAnimation.type=this.type;
- destTextureSheetAnimation.randomRow=this.randomRow;
- this._frame.cloneTo(destTextureSheetAnimation._frame);
- this._startFrame.cloneTo(destTextureSheetAnimation._startFrame);
- destTextureSheetAnimation.cycles=this.cycles;
- destTextureSheetAnimation.enableUVChannels=this.enableUVChannels;
- destTextureSheetAnimation.enable=this.enable;
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var destFrame;
- switch (this._frame.type){
- case 0:
- destFrame=FrameOverTime.createByConstant(this._frame.constant);
- break ;
- case 1:
- destFrame=FrameOverTime.createByOverTime(this._frame.frameOverTimeData.clone());
- break ;
- case 2:
- destFrame=FrameOverTime.createByRandomTwoConstant(this._frame.constantMin,this._frame.constantMax);
- break ;
- case 3:
- destFrame=FrameOverTime.createByRandomTwoOverTime(this._frame.frameOverTimeDataMin.clone(),this._frame.frameOverTimeDataMax.clone());
- break ;
- };
- var destStartFrame;
- switch (this._startFrame.type){
- case 0:
- destStartFrame=StartFrame.createByConstant(this._startFrame.constant);
- break ;
- case 1:
- destStartFrame=StartFrame.createByRandomTwoConstant(this._startFrame.constantMin,this._startFrame.constantMax);
- break ;
- };
- var destTextureSheetAnimation=/*__JS__ */new this.constructor(destFrame,destStartFrame);
- this.tiles.cloneTo(destTextureSheetAnimation.tiles);
- destTextureSheetAnimation.type=this.type;
- destTextureSheetAnimation.randomRow=this.randomRow;
- destTextureSheetAnimation.cycles=this.cycles;
- destTextureSheetAnimation.enableUVChannels=this.enableUVChannels;
- destTextureSheetAnimation.enable=this.enable;
- return destTextureSheetAnimation;
- }
- /**获取时间帧率。*/
- __getset(0,__proto,'frame',function(){
- return this._frame;
- });
- /**获取开始帧率。*/
- __getset(0,__proto,'startFrame',function(){
- return this._startFrame;
- });
- return TextureSheetAnimation;
- })()
- /**
- *...
- *@author
- */
- //class laya.d3.resource.TextureGenerator
- var TextureGenerator=(function(){
- function TextureGenerator(){}
- __class(TextureGenerator,'laya.d3.resource.TextureGenerator');
- TextureGenerator.lightAttenTexture=function(x,y,maxX,maxY,index,data){
- var sqrRange=x / maxX;
- var atten=1.0 / (1.0+25.0 *sqrRange);
- if (sqrRange >=0.64){
- if (sqrRange > 1.0){
- atten=0;
- }else {
- atten *=1-(sqrRange-0.64)/ (1-0.64);
- }
- }
- data[index]=Math.floor(atten *255.0+0.5);
- }
- TextureGenerator.haloTexture=function(x,y,maxX,maxY,index,data){
- maxX >>=1;
- maxY >>=1;
- var xFac=(x-maxX)/ maxX;
- var yFac=(y-maxY)/ maxY;
- var sqrRange=xFac *xFac+yFac *yFac;
- if (sqrRange > 1.0){
- sqrRange=1.0;
- }
- data[index]=Math.floor((1.0-sqrRange)*255.0+0.5);
- }
- TextureGenerator._generateTexture2D=function(texture,textureWidth,textureHeight,func){
- var index=0;
- var size=0;
- switch (texture.format){
- case /*laya.resource.BaseTexture.FORMAT_R8G8B8*/0:
- size=3;
- break ;
- case /*laya.resource.BaseTexture.FORMAT_R8G8B8A8*/1:
- size=4;
- break ;
- case /*laya.resource.BaseTexture.FORMAT_ALPHA8*/2:
- size=1;
- break ;
- default :
- throw "GeneratedTexture._generateTexture: unkonw texture format.";
- };
- var data=new Uint8Array(textureWidth *textureHeight *size);
- for (var y=0;y < textureHeight;y++){
- for (var x=0;x < textureWidth;x++){
- func(x,y,textureWidth,textureHeight,index,data);
- index+=size;
- }
- }
- texture.setPixels(data);
- }
- return TextureGenerator;
- })()
- /**
- *<code>Shader3D</code> 类用于创建Shader3D。
- */
- //class laya.d3.shader.Shader3D
- var Shader3D=(function(){
- function Shader3D(name,attributeMap,uniformMap,enableInstancing){
- /**@private */
- this._attributeMap=null;
- /**@private */
- this._uniformMap=null;
- /**@private */
- //this._name=null;
- /**@private */
- this._enableInstancing=false;
- this._subShaders=[];
- this._name=name;
- this._attributeMap=attributeMap;
- this._uniformMap=uniformMap;
- this._enableInstancing=enableInstancing;
- }
- __class(Shader3D,'laya.d3.shader.Shader3D');
- var __proto=Shader3D.prototype;
- /**
- *添加子着色器。
- *@param 子着色器。
- */
- __proto.addSubShader=function(subShader){
- this._subShaders.push(subShader);
- subShader._owner=this;
- }
- /**
- *在特定索引获取子着色器。
- *@param index 索引。
- *@return 子着色器。
- */
- __proto.getSubShaderAt=function(index){
- return this._subShaders[index];
- }
- Shader3D.propertyNameToID=function(name){
- if (Shader3D._propertyNameMap[name] !=null){
- return Shader3D._propertyNameMap[name];
- }else {
- var id=Shader3D._propertyNameCounter++;
- Shader3D._propertyNameMap[name]=id;
- return id;
- }
- }
- Shader3D.addInclude=function(fileName,txt){
- ShaderCompile.addInclude(fileName,txt);
- }
- Shader3D.registerPublicDefine=function(name){
- var value=Math.pow(2,Shader3D._publicCounter++);
- Shader3D._globleDefines[value]=name;
- return value;
- }
- Shader3D.compileShader=function(name,subShaderIndex,passIndex,publicDefine,spriteDefine,materialDefine){
- var shader=laya.d3.shader.Shader3D.find(name);
- if (shader){
- var subShader=shader.getSubShaderAt(subShaderIndex);
- if (subShader){
- var pass=subShader._passes[passIndex];
- if (pass){
- if (WebGL.shaderHighPrecision)
- pass.withCompile(publicDefine,spriteDefine,materialDefine);
- else
- pass.withCompile(publicDefine-laya.d3.shader.Shader3D.SHADERDEFINE_HIGHPRECISION,spriteDefine,materialDefine);
- }else {
- console.warn("Shader3D: unknown passIndex.");
- }
- }else {
- console.warn("Shader3D: unknown subShaderIndex.");
- }
- }else {
- console.warn("Shader3D: unknown shader name.");
- }
- }
- Shader3D.add=function(name,attributeMap,uniformMap,enableInstancing){
- (enableInstancing===void 0)&& (enableInstancing=false);
- return laya.d3.shader.Shader3D._preCompileShader[name]=new Shader3D(name,attributeMap,uniformMap,enableInstancing);
- }
- Shader3D.find=function(name){
- return laya.d3.shader.Shader3D._preCompileShader[name];
- }
- Shader3D.RENDER_STATE_CULL=0;
- Shader3D.RENDER_STATE_BLEND=1;
- Shader3D.RENDER_STATE_BLEND_SRC=2;
- Shader3D.RENDER_STATE_BLEND_DST=3;
- Shader3D.RENDER_STATE_BLEND_SRC_RGB=4;
- Shader3D.RENDER_STATE_BLEND_DST_RGB=5;
- Shader3D.RENDER_STATE_BLEND_SRC_ALPHA=6;
- Shader3D.RENDER_STATE_BLEND_DST_ALPHA=7;
- Shader3D.RENDER_STATE_BLEND_CONST_COLOR=8;
- Shader3D.RENDER_STATE_BLEND_EQUATION=9;
- Shader3D.RENDER_STATE_BLEND_EQUATION_RGB=10;
- Shader3D.RENDER_STATE_BLEND_EQUATION_ALPHA=11;
- Shader3D.RENDER_STATE_DEPTH_TEST=12;
- Shader3D.RENDER_STATE_DEPTH_WRITE=13;
- Shader3D.PERIOD_CUSTOM=0;
- Shader3D.PERIOD_MATERIAL=1;
- Shader3D.PERIOD_SPRITE=2;
- Shader3D.PERIOD_CAMERA=3;
- Shader3D.PERIOD_SCENE=4;
- Shader3D.SHADERDEFINE_HIGHPRECISION=0;
- Shader3D._propertyNameCounter=0;
- Shader3D._propertyNameMap={};
- Shader3D._publicCounter=0;
- Shader3D._globleDefines=[];
- Shader3D._preCompileShader={};
- Shader3D.debugMode=false;
- return Shader3D;
- })()
- /**
- *<code>Rand</code> 类用于通过32位无符号整型随机种子创建随机数。
- */
- //class laya.d3.math.Rand
- var Rand=(function(){
- function Rand(seed){
- this._temp=new Uint32Array(1);
- this.seeds=new Uint32Array(4);
- this.seeds[0]=seed;
- this.seeds[1]=this.seeds[0] *0x6C078965+1;
- this.seeds[2]=this.seeds[1] *0x6C078965+1;
- this.seeds[3]=this.seeds[2] *0x6C078965+1;
- }
- __class(Rand,'laya.d3.math.Rand');
- var __proto=Rand.prototype;
- /**
- *获取无符号32位整形随机数。
- *@return 无符号32位整形随机数。
- */
- __proto.getUint=function(){
- this._temp[0]=this.seeds[0] ^ (this.seeds[0] << 11);
- this.seeds[0]=this.seeds[1];
- this.seeds[1]=this.seeds[2];
- this.seeds[2]=this.seeds[3];
- this.seeds[3]=(this.seeds[3] ^ (this.seeds[3] >>> 19))^ (this._temp[0] ^ (this._temp[0] >>> 8));
- return this.seeds[3];
- }
- /**
- *获取0到1之间的浮点随机数。
- *@return 0到1之间的浮点随机数。
- */
- __proto.getFloat=function(){
- this.getUint();
- return (this.seeds[3] & 0x007FFFFF)*(1.0 / 8388607.0);
- }
- /**
- *获取-1到1之间的浮点随机数。
- *@return-1到1之间的浮点随机数。
- */
- __proto.getSignedFloat=function(){
- return this.getFloat()*2.0-1.0;
- }
- /**
- *设置随机种子。
- *@param seed 随机种子。
- */
- /**
- *获取随机种子。
- *@return 随机种子。
- */
- __getset(0,__proto,'seed',function(){
- return this.seeds[0];
- },function(seed){
- this.seeds[0]=seed;
- this.seeds[1]=this.seeds[0] *0x6C078965+1;
- this.seeds[2]=this.seeds[1] *0x6C078965+1;
- this.seeds[3]=this.seeds[2] *0x6C078965+1;
- });
- Rand.getFloatFromInt=function(v){
- return (v & 0x007FFFFF)*(1.0 / 8388607.0)
- }
- Rand.getByteFromInt=function(v){
- return (v & 0x007FFFFF)>>> 15;
- }
- return Rand;
- })()
- /**
- *...
- *@author ...
- */
- //class laya.d3.shadowMap.ParallelSplitShadowMap
- var ParallelSplitShadowMap=(function(){
- function ParallelSplitShadowMap(){
- /**@private */
- //this.lastNearPlane=NaN;
- /**@private */
- //this.lastFieldOfView=NaN;
- /**@private */
- //this.lastAspectRatio=NaN;
- /**@private */
- this._currentPSSM=-1;
- /**@private */
- this._shadowMapCount=3;
- /**@private */
- this._maxDistance=200.0;
- /**@private */
- this._ratioOfDistance=1.0 / this._shadowMapCount;
- /**@private */
- this._statesDirty=true;
- /**@private */
- //this.cameras=null;
- /**@private */
- this._shadowMapTextureSize=1024;
- /**@private */
- this._scene=null;
- /**@private */
- this._PCFType=0;
- /**@private */
- this._shaderValueLightVP=null;
- /**@private */
- //this._shaderValueVPs=null;
- this._spiltDistance=new Array(/*CLASS CONST:laya.d3.shadowMap.ParallelSplitShadowMap.MAX_PSSM_COUNT*/3+1);
- this._globalParallelLightDir=new Vector3(0,-1,0);
- this._boundingSphere=new Array(/*CLASS CONST:laya.d3.shadowMap.ParallelSplitShadowMap.MAX_PSSM_COUNT*/3+1);
- this._boundingBox=new Array(/*CLASS CONST:laya.d3.shadowMap.ParallelSplitShadowMap.MAX_PSSM_COUNT*/3+1);
- this._frustumPos=new Array((/*CLASS CONST:laya.d3.shadowMap.ParallelSplitShadowMap.MAX_PSSM_COUNT*/3+1)*4);
- this._uniformDistance=new Array(/*CLASS CONST:laya.d3.shadowMap.ParallelSplitShadowMap.MAX_PSSM_COUNT*/3+1);
- this._logDistance=new Array(/*CLASS CONST:laya.d3.shadowMap.ParallelSplitShadowMap.MAX_PSSM_COUNT*/3+1);
- this._dimension=new Array(/*CLASS CONST:laya.d3.shadowMap.ParallelSplitShadowMap.MAX_PSSM_COUNT*/3+1);
- this._tempLookAt3=new Vector3();
- this._tempLookAt4=new Vector4();
- this._tempValue=new Vector4();
- this._tempPos=new Vector3();
- this._tempLightUp=new Vector3();
- this._tempMin=new Vector4();
- this._tempMax=new Vector4();
- this._tempMatrix44=new Matrix4x4;
- this._splitFrustumCulling=new BoundFrustum(Matrix4x4.DEFAULT);
- this._tempScaleMatrix44=new Matrix4x4();
- this._shadowPCFOffset=new Vector2(1.0 / 1024.0,1.0 / 1024.0);
- this._shaderValueDistance=new Vector4();
- this.cameras=[];
- this._shaderValueVPs=[];
- var i=0;
- for (i=0;i < this._spiltDistance.length;i++){
- this._spiltDistance[i]=0.0;
- }
- for (i=0;i < this._dimension.length;i++){
- this._dimension[i]=new Vector2();
- }
- for (i=0;i < this._frustumPos.length;i++){
- this._frustumPos[i]=new Vector3();
- }
- for (i=0;i < this._boundingBox.length;i++){
- this._boundingBox[i]=new BoundBox(new Vector3(),new Vector3());
- }
- for (i=0;i < this._boundingSphere.length;i++){
- this._boundingSphere[i]=new BoundSphere(new Vector3(),0.0);
- }
- Matrix4x4.createScaling(new Vector3(0.5,0.5,1.0),this._tempScaleMatrix44);
- this._tempScaleMatrix44.elements[12]=0.5;
- this._tempScaleMatrix44.elements[13]=0.5;
- }
- __class(ParallelSplitShadowMap,'laya.d3.shadowMap.ParallelSplitShadowMap');
- var __proto=ParallelSplitShadowMap.prototype;
- __proto.setInfo=function(scene,maxDistance,globalParallelDir,shadowMapTextureSize,numberOfPSSM,PCFType){
- if (numberOfPSSM > /*CLASS CONST:laya.d3.shadowMap.ParallelSplitShadowMap.MAX_PSSM_COUNT*/3){
- this._shadowMapCount=/*CLASS CONST:laya.d3.shadowMap.ParallelSplitShadowMap.MAX_PSSM_COUNT*/3;
- }
- this._scene=scene;
- this._maxDistance=maxDistance;
- this.shadowMapCount=numberOfPSSM;
- this._globalParallelLightDir=globalParallelDir;
- this._ratioOfDistance=1.0 / this._shadowMapCount;
- for (var i=0;i < this._spiltDistance.length;i++){
- this._spiltDistance[i]=0.0;
- }
- this._shadowMapTextureSize=shadowMapTextureSize;
- this._shadowPCFOffset.x=1.0 / this._shadowMapTextureSize;
- this._shadowPCFOffset.y=1.0 / this._shadowMapTextureSize;
- this.setPCFType(PCFType);
- this._statesDirty=true;
- }
- __proto.setPCFType=function(PCFtype){
- this._PCFType=PCFtype;
- var defineData=this._scene._defineDatas;
- switch (this._PCFType){
- case 0:
- defineData.add(Scene3D.SHADERDEFINE_SHADOW_PCF_NO);
- defineData.remove(Scene3D.SHADERDEFINE_SHADOW_PCF1);
- defineData.remove(Scene3D.SHADERDEFINE_SHADOW_PCF2);
- defineData.remove(Scene3D.SHADERDEFINE_SHADOW_PCF3);
- break ;
- case 1:
- defineData.add(Scene3D.SHADERDEFINE_SHADOW_PCF1);
- defineData.remove(Scene3D.SHADERDEFINE_SHADOW_PCF_NO);
- defineData.remove(Scene3D.SHADERDEFINE_SHADOW_PCF2);
- defineData.remove(Scene3D.SHADERDEFINE_SHADOW_PCF3);
- break ;
- case 2:
- defineData.add(Scene3D.SHADERDEFINE_SHADOW_PCF2);
- defineData.remove(Scene3D.SHADERDEFINE_SHADOW_PCF_NO);
- defineData.remove(Scene3D.SHADERDEFINE_SHADOW_PCF1);
- defineData.remove(Scene3D.SHADERDEFINE_SHADOW_PCF3);
- break ;
- case 3:
- defineData.add(Scene3D.SHADERDEFINE_SHADOW_PCF3);
- defineData.remove(Scene3D.SHADERDEFINE_SHADOW_PCF_NO);
- defineData.remove(Scene3D.SHADERDEFINE_SHADOW_PCF1);
- defineData.remove(Scene3D.SHADERDEFINE_SHADOW_PCF2);
- break ;
- }
- }
- __proto.getPCFType=function(){
- return this._PCFType;
- }
- __proto.setFarDistance=function(value){
- if (this._maxDistance !=value){
- this._maxDistance=value;
- this._statesDirty=true;
- }
- }
- __proto.getFarDistance=function(){
- return this._maxDistance;
- }
- /**
- *@private
- */
- __proto._beginSampler=function(index,sceneCamera){
- if (index < 0 || index > this._shadowMapCount)
- throw new Error("ParallelSplitShadowMap: beginSample invalid index");
- this._currentPSSM=index;
- this._update(sceneCamera);
- }
- /**
- *@private
- */
- __proto.endSampler=function(sceneCamera){
- this._currentPSSM=-1;
- }
- /**
- *@private
- */
- __proto._calcAllLightCameraInfo=function(sceneCamera){
- if (this._shadowMapCount===1){
- this._beginSampler(0,sceneCamera);
- this.endSampler(sceneCamera);
- }else {
- for (var i=0,n=this._shadowMapCount+1;i < n;i++){
- this._beginSampler(i,sceneCamera);
- this.endSampler(sceneCamera);
- }
- }
- }
- /**
- *@private
- */
- __proto._recalculate=function(nearPlane,fieldOfView,aspectRatio){
- this._calcSplitDistance(nearPlane);
- this._calcBoundingBox(fieldOfView,aspectRatio);
- this._rebuildRenderInfo();
- }
- /**
- *@private
- */
- __proto._update=function(sceneCamera){
- var nearPlane=sceneCamera.nearPlane;
- var fieldOfView=sceneCamera.fieldOfView;
- var aspectRatio=(sceneCamera).aspectRatio;
- if (this._statesDirty || this.lastNearPlane!==nearPlane || this.lastFieldOfView!==fieldOfView || this.lastAspectRatio!==aspectRatio){
- this._recalculate(nearPlane,fieldOfView,aspectRatio);
- this._uploadShaderValue();
- this._statesDirty=false;
- this.lastNearPlane=nearPlane;
- this.lastFieldOfView=fieldOfView;
- this.lastAspectRatio=aspectRatio;
- }
- this._calcLightViewProject(sceneCamera);
- }
- /**
- *@private
- */
- __proto._uploadShaderValue=function(){
- var defDatas=this._scene._defineDatas;
- switch (this._shadowMapCount){
- case 1:
- defDatas.add(Scene3D.SHADERDEFINE_SHADOW_PSSM1);
- defDatas.remove(Scene3D.SHADERDEFINE_SHADOW_PSSM2);
- defDatas.remove(Scene3D.SHADERDEFINE_SHADOW_PSSM3);
- break ;
- case 2:
- defDatas.add(Scene3D.SHADERDEFINE_SHADOW_PSSM2);
- defDatas.remove(Scene3D.SHADERDEFINE_SHADOW_PSSM1);
- defDatas.remove(Scene3D.SHADERDEFINE_SHADOW_PSSM3);
- break ;
- case 3:
- defDatas.add(Scene3D.SHADERDEFINE_SHADOW_PSSM3);
- defDatas.remove(Scene3D.SHADERDEFINE_SHADOW_PSSM1);
- defDatas.remove(Scene3D.SHADERDEFINE_SHADOW_PSSM2);
- break ;
- };
- var sceneSV=this._scene._shaderValues;
- sceneSV.setVector(Scene3D.SHADOWDISTANCE,this._shaderValueDistance);
- sceneSV.setBuffer(Scene3D.SHADOWLIGHTVIEWPROJECT,this._shaderValueLightVP);
- sceneSV.setVector2(Scene3D.SHADOWMAPPCFOFFSET,this._shadowPCFOffset);
- switch (this._shadowMapCount){
- case 3:
- sceneSV.setTexture(Scene3D.SHADOWMAPTEXTURE1,this.cameras[1].renderTarget);
- sceneSV.setTexture(Scene3D.SHADOWMAPTEXTURE2,this.cameras[2].renderTarget)
- sceneSV.setTexture(Scene3D.SHADOWMAPTEXTURE3,this.cameras[3].renderTarget);
- break ;
- case 2:
- sceneSV.setTexture(Scene3D.SHADOWMAPTEXTURE1,this.cameras[1].renderTarget);
- sceneSV.setTexture(Scene3D.SHADOWMAPTEXTURE2,this.cameras[2].renderTarget);
- break ;
- case 1:
- sceneSV.setTexture(Scene3D.SHADOWMAPTEXTURE1,this.cameras[1].renderTarget);
- break ;
- }
- }
- /**
- *@private
- */
- __proto._calcSplitDistance=function(nearPlane){
- var far=this._maxDistance;
- var invNumberOfPSSM=1.0 / this._shadowMapCount;
- var i=0;
- for (i=0;i <=this._shadowMapCount;i++){
- this._uniformDistance[i]=nearPlane+(far-nearPlane)*i *invNumberOfPSSM;
- };
- var farDivNear=far / nearPlane;
- for (i=0;i <=this._shadowMapCount;i++){
- var n=Math.pow(farDivNear,i *invNumberOfPSSM);
- this._logDistance[i]=nearPlane *n;
- }
- for (i=0;i <=this._shadowMapCount;i++){
- this._spiltDistance[i]=this._uniformDistance[i] *this._ratioOfDistance+this._logDistance[i] *(1.0-this._ratioOfDistance);
- }
- this._shaderValueDistance.x=this._spiltDistance[1];
- this._shaderValueDistance.y=this._spiltDistance[2];
- this._shaderValueDistance.z=this._spiltDistance[3];
- this._shaderValueDistance.w=0.0;
- }
- /**
- *@private
- */
- __proto._calcBoundingBox=function(fieldOfView,aspectRatio){
- var fov=3.1415926 *fieldOfView / 180.0;
- var halfTanValue=Math.tan(fov / 2.0);
- var height=NaN;
- var width=NaN;
- var distance=NaN;
- var i=0;
- for (i=0;i <=this._shadowMapCount;i++){
- distance=this._spiltDistance[i];
- height=distance *halfTanValue;
- width=height *aspectRatio;
- var temp=this._frustumPos[i *4+0];
- temp.x=-width;
- temp.y=-height;
- temp.z=-distance;
- temp=this._frustumPos[i *4+1];
- temp.x=width;
- temp.y=-height;
- temp.z=-distance;
- temp=this._frustumPos[i *4+2];
- temp.x=-width;
- temp.y=height;
- temp.z=-distance;
- temp=this._frustumPos[i *4+3];
- temp.x=width;
- temp.y=height;
- temp.z=-distance;
- temp=this._dimension[i];
- temp.x=width;
- temp.y=height;
- };
- var d;
- var min;
- var max;
- var center;
- for (i=1;i <=this._shadowMapCount;i++){
- d=this._dimension[i];
- min=this._boundingBox[i].min;
- min.x=-d.x;
- min.y=-d.y;
- min.z=-this._spiltDistance[i];
- max=this._boundingBox[i].max;
- max.x=d.x;
- max.y=d.y;
- max.z=-this._spiltDistance[i-1];
- center=this._boundingSphere[i].center;
- center.x=(min.x+max.x)*0.5;
- center.y=(min.y+max.y)*0.5;
- center.z=(min.z+max.z)*0.5;
- 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;
- }
- min=this._boundingBox[0].min;
- d=this._dimension[this._shadowMapCount];
- min.x=-d.x;
- min.y=-d.y;
- min.z=-this._spiltDistance[this._shadowMapCount];
- max=this._boundingBox[0].max;
- max.x=d.x;
- max.y=d.y;
- max.z=-this._spiltDistance[0];
- center=this._boundingSphere[0].center;
- center.x=(min.x+max.x)*0.5;
- center.y=(min.y+max.y)*0.5;
- center.z=(min.z+max.z)*0.5;
- 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;
- }
- __proto.calcSplitFrustum=function(sceneCamera){
- if (this._currentPSSM > 0){
- Matrix4x4.createPerspective(3.1416 *sceneCamera.fieldOfView / 180.0,(sceneCamera).aspectRatio,this._spiltDistance[this._currentPSSM-1],this._spiltDistance[this._currentPSSM],this._tempMatrix44);
- }else {
- Matrix4x4.createPerspective(3.1416 *sceneCamera.fieldOfView / 180.0,(sceneCamera).aspectRatio,this._spiltDistance[0],this._spiltDistance[this._shadowMapCount],this._tempMatrix44);
- }
- Matrix4x4.multiply(this._tempMatrix44,(sceneCamera).viewMatrix,this._tempMatrix44);
- this._splitFrustumCulling.matrix=this._tempMatrix44;
- }
- /**
- *@private
- */
- __proto._rebuildRenderInfo=function(){
- var nNum=this._shadowMapCount+1;
- var i=0;
- this.cameras.length=nNum;
- for (i=0;i < nNum;i++){
- if (!this.cameras[i]){
- var camera=new Camera();
- camera.name="lightCamera"+i;
- camera.clearColor=new Vector4(1.0,1.0,1.0,1.0);
- this.cameras[i]=camera;
- };
- var shadowMap=this.cameras[i].renderTarget;
- if (shadowMap==null || shadowMap.width !=this._shadowMapTextureSize || shadowMap.height !=this._shadowMapTextureSize){
- (shadowMap)&& (shadowMap.destroy());
- shadowMap=new RenderTexture(this._shadowMapTextureSize,this._shadowMapTextureSize,/*laya.resource.BaseTexture.FORMAT_R8G8B8A8*/1,/*laya.resource.BaseTexture.FORMAT_DEPTH_16*/0);
- shadowMap.filterMode=/*laya.resource.BaseTexture.FILTERMODE_POINT*/0;
- this.cameras[i].renderTarget=shadowMap;
- }
- }
- }
- /**
- *@private
- */
- __proto._calcLightViewProject=function(sceneCamera){
- var boundSphere=this._boundingSphere[this._currentPSSM];
- var cameraMatViewInv=sceneCamera.transform.worldMatrix;
- var radius=boundSphere.radius;
- boundSphere.center.cloneTo(this._tempLookAt3);
- Vector3.transformV3ToV4(this._tempLookAt3,cameraMatViewInv,this._tempLookAt4);
- var lookAt3Element=this._tempLookAt3;
- var lookAt4Element=this._tempLookAt4;
- lookAt3Element.x=lookAt4Element.x;
- lookAt3Element.y=lookAt4Element.y;
- lookAt3Element.z=lookAt4Element.z;
- var lightUpElement=this._tempLightUp;
- sceneCamera.transform.worldMatrix.getForward(ParallelSplitShadowMap._tempVector30);
- var sceneCameraDir=ParallelSplitShadowMap._tempVector30;
- lightUpElement.x=sceneCameraDir.x;
- lightUpElement.y=1.0;
- lightUpElement.z=sceneCameraDir.z;
- Vector3.normalize(this._tempLightUp,this._tempLightUp);
- Vector3.scale(this._globalParallelLightDir,boundSphere.radius *4,this._tempPos);
- Vector3.subtract(this._tempLookAt3,this._tempPos,this._tempPos);
- var curLightCamera=this.cameras[this._currentPSSM];
- curLightCamera.transform.position=this._tempPos;
- curLightCamera.transform.lookAt(this._tempLookAt3,this._tempLightUp,false);
- var tempMax=this._tempMax;
- var tempMin=this._tempMin;
- tempMax.x=tempMax.y=tempMax.z=-100000.0;
- tempMax.w=1.0;
- tempMin.x=tempMin.y=tempMin.z=100000.0;
- tempMin.w=1.0;
- Matrix4x4.multiply(curLightCamera.viewMatrix,cameraMatViewInv,this._tempMatrix44);
- var tempValueElement=this._tempValue;
- var corners=[];
- corners.length=8;
- this._boundingBox[this._currentPSSM].getCorners(corners);
- for (var i=0;i < 8;i++){
- var frustumPosElements=corners[i];
- tempValueElement.x=frustumPosElements.x;
- tempValueElement.y=frustumPosElements.y;
- tempValueElement.z=frustumPosElements.z;
- tempValueElement.w=1.0;
- Vector4.transformByM4x4(this._tempValue,this._tempMatrix44,this._tempValue);
- tempMin.x=(tempValueElement.x < tempMin.x)? tempValueElement.x :tempMin.x;
- tempMin.y=(tempValueElement.y < tempMin.y)? tempValueElement.y :tempMin.y;
- tempMin.z=(tempValueElement.z < tempMin.z)? tempValueElement.z :tempMin.z;
- tempMax.x=(tempValueElement.x > tempMax.x)? tempValueElement.x :tempMax.x;
- tempMax.y=(tempValueElement.y > tempMax.y)? tempValueElement.y :tempMax.y;
- tempMax.z=(tempValueElement.z > tempMax.z)? tempValueElement.z :tempMax.z;
- }
- Vector4.add(this._tempMax,this._tempMin,this._tempValue);
- tempValueElement.x *=0.5;
- tempValueElement.y *=0.5;
- tempValueElement.z *=0.5;
- tempValueElement.w=1;
- Vector4.transformByM4x4(this._tempValue,curLightCamera.transform.worldMatrix,this._tempValue);
- var distance=Math.abs(-this._tempMax.z);
- var farPlane=distance > this._maxDistance ? distance :this._maxDistance;
- Vector3.scale(this._globalParallelLightDir,farPlane,this._tempPos);
- var tempPosElement=this._tempPos;
- tempPosElement.x=tempValueElement.x-tempPosElement.x;
- tempPosElement.y=tempValueElement.y-tempPosElement.y;
- tempPosElement.z=tempValueElement.z-tempPosElement.z;
- curLightCamera.transform.position=this._tempPos;
- curLightCamera.transform.lookAt(this._tempLookAt3,this._tempLightUp,false);
- Matrix4x4.createOrthoOffCenter(tempMin.x,tempMax.x,tempMin.y,tempMax.y,1.0,farPlane+0.5 *(tempMax.z-tempMin.z),curLightCamera.projectionMatrix);
- var projectView=curLightCamera.projectionViewMatrix;
- ParallelSplitShadowMap.multiplyMatrixOutFloat32Array(this._tempScaleMatrix44,projectView,this._shaderValueVPs[this._currentPSSM]);
- this._scene._shaderValues.setBuffer(Scene3D.SHADOWLIGHTVIEWPROJECT,this._shaderValueLightVP);
- }
- __proto.setShadowMapTextureSize=function(size){
- if (size!==this._shadowMapTextureSize){
- this._shadowMapTextureSize=size;
- this._shadowPCFOffset.x=1 / this._shadowMapTextureSize;
- this._shadowPCFOffset.y=1 / this._shadowMapTextureSize;
- this._statesDirty=true;
- }
- }
- __proto.disposeAllRenderTarget=function(){
- for (var i=0,n=this._shadowMapCount+1;i < n;i++){
- if (this.cameras[i].renderTarget){
- this.cameras[i].renderTarget.destroy();
- this.cameras[i].renderTarget=null;
- }
- }
- }
- __getset(0,__proto,'shadowMapCount',function(){
- return this._shadowMapCount;
- },function(value){
- value=value > 0 ? value :1;
- value=value <=3 ? value :3;
- if (this._shadowMapCount !=value){
- this._shadowMapCount=value;
- this._ratioOfDistance=1.0 / this._shadowMapCount;
- this._statesDirty=true;
- this._shaderValueLightVP=new Float32Array(value *16);
- this._shaderValueVPs.length=value;
- for (var i=0;i < value;i++)
- this._shaderValueVPs[i]=new Float32Array(this._shaderValueLightVP.buffer,i *64);
- }
- });
- ParallelSplitShadowMap.multiplyMatrixOutFloat32Array=function(left,right,out){
- var i,a,b,ai0,ai1,ai2,ai3;
- a=left.elements;
- b=right.elements;
- for (i=0;i < 4;i++){
- ai0=a[i];
- ai1=a[i+4];
- ai2=a[i+8];
- ai3=a[i+12];
- out[i]=ai0 *b[0]+ai1 *b[1]+ai2 *b[2]+ai3 *b[3];
- out[i+4]=ai0 *b[4]+ai1 *b[5]+ai2 *b[6]+ai3 *b[7];
- out[i+8]=ai0 *b[8]+ai1 *b[9]+ai2 *b[10]+ai3 *b[11];
- out[i+12]=ai0 *b[12]+ai1 *b[13]+ai2 *b[14]+ai3 *b[15];
- }
- }
- ParallelSplitShadowMap.MAX_PSSM_COUNT=3;
- __static(ParallelSplitShadowMap,
- ['_tempVector30',function(){return this._tempVector30=new Vector3();}
- ]);
- return ParallelSplitShadowMap;
- })()
- /**
- *<code>PrimitiveMesh</code> 类用于创建简单网格。
- */
- //class laya.d3.resource.models.PrimitiveMesh
- var PrimitiveMesh=(function(){
- function PrimitiveMesh(){}
- __class(PrimitiveMesh,'laya.d3.resource.models.PrimitiveMesh');
- PrimitiveMesh._createMesh=function(vertexDeclaration,vertices,indices){
- var mesh=new Mesh();
- var subMesh=new SubMesh(mesh);
- var vertexBuffer=new VertexBuffer3D(vertices.length *4,/*laya.webgl.WebGLContext.STATIC_DRAW*/0x88E4,true);
- vertexBuffer.vertexDeclaration=vertexDeclaration;
- vertexBuffer.setData(vertices);
- mesh._vertexBuffers.push(vertexBuffer);
- mesh._vertexCount+=vertexBuffer.vertexCount;
- var indexBuffer=new IndexBuffer3D(/*laya.d3.graphics.IndexBuffer3D.INDEXTYPE_USHORT*/"ushort",indices.length,/*laya.webgl.WebGLContext.STATIC_DRAW*/0x88E4,true);
- indexBuffer.setData(indices);
- mesh._indexBuffer=indexBuffer;
- var vertexBuffers=__newvec(1,null);
- vertexBuffers[0]=vertexBuffer;
- mesh._setBuffer(vertexBuffers,indexBuffer);
- subMesh._vertexBuffer=vertexBuffer;
- subMesh._indexBuffer=indexBuffer;
- subMesh._indexStart=0;
- subMesh._indexCount=indexBuffer.indexCount;
- var subIndexBufferStart=subMesh._subIndexBufferStart;
- var subIndexBufferCount=subMesh._subIndexBufferCount;
- var boneIndicesList=subMesh._boneIndicesList;
- subIndexBufferStart.length=1;
- subIndexBufferCount.length=1;
- boneIndicesList.length=1;
- subIndexBufferStart[0]=0;
- subIndexBufferCount[0]=indexBuffer.indexCount;
- var subMeshes=[];
- subMeshes.push(subMesh);
- mesh._setSubMeshes(subMeshes);
- var memorySize=vertexBuffer._byteLength+indexBuffer._byteLength;
- mesh._setCPUMemory(memorySize);
- mesh._setGPUMemory(memorySize);
- return mesh;
- }
- PrimitiveMesh.createBox=function(long,height,width){
- (long===void 0)&& (long=1);
- (height===void 0)&& (height=1);
- (width===void 0)&& (width=1);
- var vertexCount=24;
- var indexCount=36;
- var vertexDeclaration=VertexMesh.getVertexDeclaration("POSITION,NORMAL,UV");
- var halfLong=long / 2;
- var halfHeight=height / 2;
- var halfWidth=width / 2;
- var vertices=new Float32Array([
- -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,
- -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,
- -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,
- 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,
- -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,
- -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]);
- var indices=new Uint16Array([
- 0,1,2,2,3,0,
- 4,7,6,6,5,4,
- 8,9,10,10,11,8,
- 12,15,14,14,13,12,
- 16,17,18,18,19,16,
- 20,23,22,22,21,20]);
- return PrimitiveMesh._createMesh(vertexDeclaration,vertices,indices);
- }
- PrimitiveMesh.createCapsule=function(radius,height,stacks,slices){
- (radius===void 0)&& (radius=0.5);
- (height===void 0)&& (height=2);
- (stacks===void 0)&& (stacks=16);
- (slices===void 0)&& (slices=32);
- var vertexCount=(stacks+1)*(slices+1)*2+(slices+1)*2;
- var indexCount=(3 *stacks *(slices+1))*2 *2+2 *slices *3;
- var vertexDeclaration=VertexMesh.getVertexDeclaration("POSITION,NORMAL,UV");
- var vertexFloatStride=vertexDeclaration.vertexStride / 4;
- var vertices=new Float32Array(vertexCount *vertexFloatStride);
- var indices=new Uint16Array(indexCount);
- var stackAngle=(Math.PI / 2.0)/ stacks;
- var sliceAngle=(Math.PI *2.0)/ slices;
- var hcHeight=height / 2-radius;
- var posX=0;
- var posY=0;
- var posZ=0;
- var vc=0;
- var ic=0;
- var verticeCount=0;
- var stack=0,slice=0;
- for (stack=0;stack <=stacks;stack++){
- for (slice=0;slice <=slices;slice++){
- posX=radius *Math.cos(stack *stackAngle)*Math.cos(slice *sliceAngle+Math.PI);
- posY=radius *Math.sin(stack *stackAngle);
- posZ=radius *Math.cos(stack *stackAngle)*Math.sin(slice *sliceAngle+Math.PI);
- vertices[vc++]=posX;
- vertices[vc++]=posY+hcHeight;
- vertices[vc++]=posZ;
- vertices[vc++]=posX;
- vertices[vc++]=posY;
- vertices[vc++]=posZ;
- vertices[vc++]=1-slice / slices;
- vertices[vc++]=(1-stack / stacks)*((Math.PI *radius / 2)/ (height+Math.PI *radius));
- if (stack < stacks){
- indices[ic++]=(stack *(slices+1))+slice+(slices+1);
- indices[ic++]=(stack *(slices+1))+slice;
- indices[ic++]=(stack *(slices+1))+slice+1;
- indices[ic++]=(stack *(slices+1))+slice+(slices);
- indices[ic++]=(stack *(slices+1))+slice;
- indices[ic++]=(stack *(slices+1))+slice+(slices+1);
- }
- }
- }
- verticeCount+=(stacks+1)*(slices+1);
- for (stack=0;stack <=stacks;stack++){
- for (slice=0;slice <=slices;slice++){
- posX=radius *Math.cos(stack *stackAngle)*Math.cos(slice *sliceAngle+Math.PI);
- posY=radius *Math.sin(-stack *stackAngle);
- posZ=radius *Math.cos(stack *stackAngle)*Math.sin(slice *sliceAngle+Math.PI);
- vertices[vc++]=posX;
- vertices[vc++]=posY-hcHeight;
- vertices[vc++]=posZ;
- vertices[vc++]=posX;
- vertices[vc++]=posY;
- vertices[vc++]=posZ;
- vertices[vc++]=1-slice / slices;
- vertices[vc++]=((stack / stacks)*(Math.PI *radius / 2)+(height+Math.PI *radius / 2))/ (height+Math.PI *radius);
- if (stack < stacks){
- indices[ic++]=verticeCount+(stack *(slices+1))+slice;
- indices[ic++]=verticeCount+(stack *(slices+1))+slice+(slices+1);
- indices[ic++]=verticeCount+(stack *(slices+1))+slice+1;
- indices[ic++]=verticeCount+(stack *(slices+1))+slice;
- indices[ic++]=verticeCount+(stack *(slices+1))+slice+(slices);
- indices[ic++]=verticeCount+(stack *(slices+1))+slice+(slices+1);
- }
- }
- }
- verticeCount+=(stacks+1)*(slices+1);
- for (slice=0;slice <=slices;slice++){
- posX=radius *Math.cos(slice *sliceAngle+Math.PI);
- posY=hcHeight;
- posZ=radius *Math.sin(slice *sliceAngle+Math.PI);
- vertices[vc++]=posX;
- vertices[vc+(slices+1)*8-1]=posX;
- vertices[vc++]=posY;
- vertices[vc+(slices+1)*8-1]=-posY;
- vertices[vc++]=posZ;
- vertices[vc+(slices+1)*8-1]=posZ;
- vertices[vc++]=posX;
- vertices[vc+(slices+1)*8-1]=posX;
- vertices[vc++]=0;
- vertices[vc+(slices+1)*8-1]=0;
- vertices[vc++]=posZ;
- vertices[vc+(slices+1)*8-1]=posZ;
- vertices[vc++]=1-slice *1 / slices;
- vertices[vc+(slices+1)*8-1]=1-slice *1 / slices;
- vertices[vc++]=(Math.PI *radius / 2)/ (height+Math.PI *radius);
- vertices[vc+(slices+1)*8-1]=(Math.PI *radius / 2+height)/ (height+Math.PI *radius);
- }
- for (slice=0;slice < slices;slice++){
- indices[ic++]=slice+verticeCount+(slices+1);
- indices[ic++]=slice+verticeCount+1;
- indices[ic++]=slice+verticeCount;
- indices[ic++]=slice+verticeCount+(slices+1);
- indices[ic++]=slice+verticeCount+(slices+1)+1;
- indices[ic++]=slice+verticeCount+1;
- }
- verticeCount+=2 *(slices+1);
- return PrimitiveMesh._createMesh(vertexDeclaration,vertices,indices);
- }
- PrimitiveMesh.createCone=function(radius,height,slices){
- (radius===void 0)&& (radius=0.5);
- (height===void 0)&& (height=1);
- (slices===void 0)&& (slices=32);
- var vertexCount=(slices+1+1)+(slices+1)*2;
- var indexCount=6 *slices+3 *slices;
- var vertexDeclaration=VertexMesh.getVertexDeclaration("POSITION,NORMAL,UV");
- var vertexFloatStride=vertexDeclaration.vertexStride / 4;
- var vertices=new Float32Array(vertexCount *vertexFloatStride);
- var indices=new Uint16Array(indexCount);
- var sliceAngle=(Math.PI *2.0)/ slices;
- var halfHeight=height / 2;
- var curAngle=0;
- var verticeCount=0;
- var posX=0;
- var posY=0;
- var posZ=0;
- var normal=new Vector3();
- var downV3=new Vector3(0,-1,0);
- var upPoint=new Vector3(0,halfHeight,0);
- var downPoint=new Vector3();
- var v3=new Vector3();
- var q4=new Quaternion();
- var rotateAxis=new Vector3();
- var rotateRadius=NaN;
- var vc=0;
- var ic=0;
- for (var rv=0;rv <=slices;rv++){
- curAngle=rv *sliceAngle;
- posX=Math.cos(curAngle+Math.PI)*radius;
- posY=halfHeight;
- posZ=Math.sin(curAngle+Math.PI)*radius;
- vertices[vc++]=0;
- vertices[vc+(slices+1)*8-1]=posX;
- vertices[vc++]=posY;
- vertices[vc+(slices+1)*8-1]=-posY;
- vertices[vc++]=0;
- vertices[vc+(slices+1)*8-1]=posZ;
- normal.x=posX;
- normal.y=0;
- normal.z=posZ;
- downPoint.x=posX;
- downPoint.y=-posY;
- downPoint.z=posZ;
- Vector3.subtract(downPoint,upPoint,v3);
- Vector3.normalize(v3,v3);
- rotateRadius=Math.acos(Vector3.dot(downV3,v3));
- Vector3.cross(downV3,v3,rotateAxis);
- Vector3.normalize(rotateAxis,rotateAxis);
- Quaternion.createFromAxisAngle(rotateAxis,rotateRadius,q4);
- Vector3.normalize(normal,normal);
- Vector3.transformQuat(normal,q4,normal);
- Vector3.normalize(normal,normal);
- vertices[vc++]=normal.x;
- vertices[vc+(slices+1)*8-1]=normal.x;
- vertices[vc++]=normal.y;
- vertices[vc+(slices+1)*8-1]=normal.y;
- vertices[vc++]=normal.z;
- vertices[vc+(slices+1)*8-1]=normal.z;
- vertices[vc++]=1-rv *1 / slices;
- vertices[vc+(slices+1)*8-1]=1-rv *1 / slices;
- vertices[vc++]=0;
- vertices[vc+(slices+1)*8-1]=1;
- }
- vc+=(slices+1)*8;
- for (var ri=0;ri < slices;ri++){
- indices[ic++]=ri+verticeCount+(slices+1);
- indices[ic++]=ri+verticeCount+1;
- indices[ic++]=ri+verticeCount;
- indices[ic++]=ri+verticeCount+(slices+1);
- indices[ic++]=ri+verticeCount+(slices+1)+1;
- indices[ic++]=ri+verticeCount+1;
- }
- verticeCount+=2 *(slices+1);
- for (var bv=0;bv <=slices;bv++){
- if (bv===0){
- vertices[vc++]=0;
- vertices[vc++]=-halfHeight;
- vertices[vc++]=0;
- vertices[vc++]=0;
- vertices[vc++]=-1;
- vertices[vc++]=0;
- vertices[vc++]=0.5;
- vertices[vc++]=0.5;
- }
- curAngle=bv *sliceAngle;
- posX=Math.cos(curAngle+Math.PI)*radius;
- posY=-halfHeight;
- posZ=Math.sin(curAngle+Math.PI)*radius;
- vertices[vc++]=posX;
- vertices[vc++]=posY;
- vertices[vc++]=posZ;
- vertices[vc++]=0;
- vertices[vc++]=-1;
- vertices[vc++]=0;
- vertices[vc++]=0.5+Math.cos(curAngle)*0.5;
- vertices[vc++]=0.5+Math.sin(curAngle)*0.5;
- }
- for (var bi=0;bi < slices;bi++){
- indices[ic++]=0+verticeCount;
- indices[ic++]=bi+2+verticeCount;
- indices[ic++]=bi+1+verticeCount;
- }
- verticeCount+=slices+1+1;
- return PrimitiveMesh._createMesh(vertexDeclaration,vertices,indices);
- }
- PrimitiveMesh.createCylinder=function(radius,height,slices){
- (radius===void 0)&& (radius=0.5);
- (height===void 0)&& (height=2);
- (slices===void 0)&& (slices=32);
- var vertexCount=(slices+1+1)+(slices+1)*2+(slices+1+1);
- var indexCount=3 *slices+6 *slices+3 *slices;
- var vertexDeclaration=VertexMesh.getVertexDeclaration("POSITION,NORMAL,UV");
- var vertexFloatStride=vertexDeclaration.vertexStride / 4;
- var vertices=new Float32Array(vertexCount *vertexFloatStride);
- var indices=new Uint16Array(indexCount);
- var sliceAngle=(Math.PI *2.0)/ slices;
- var halfHeight=height / 2;
- var curAngle=0;
- var verticeCount=0;
- var posX=0;
- var posY=0;
- var posZ=0;
- var vc=0;
- var ic=0;
- for (var tv=0;tv <=slices;tv++){
- if (tv===0){
- vertices[vc++]=0;
- vertices[vc++]=halfHeight;
- vertices[vc++]=0;
- vertices[vc++]=0;
- vertices[vc++]=1;
- vertices[vc++]=0;
- vertices[vc++]=0.5;
- vertices[vc++]=0.5;
- }
- curAngle=tv *sliceAngle;
- posX=Math.cos(curAngle)*radius;
- posY=halfHeight;
- posZ=Math.sin(curAngle)*radius;
- vertices[vc++]=posX;
- vertices[vc++]=posY;
- vertices[vc++]=posZ;
- vertices[vc++]=0;
- vertices[vc++]=1;
- vertices[vc++]=0;
- vertices[vc++]=0.5+Math.cos(curAngle)*0.5;
- vertices[vc++]=0.5+Math.sin(curAngle)*0.5;
- }
- for (var ti=0;ti < slices;ti++){
- indices[ic++]=0;
- indices[ic++]=ti+1;
- indices[ic++]=ti+2;
- }
- verticeCount+=slices+1+1;
- for (var rv=0;rv <=slices;rv++){
- curAngle=rv *sliceAngle;
- posX=Math.cos(curAngle+Math.PI)*radius;
- posY=halfHeight;
- posZ=Math.sin(curAngle+Math.PI)*radius;
- vertices[vc++]=posX;
- vertices[vc+(slices+1)*8-1]=posX;
- vertices[vc++]=posY;
- vertices[vc+(slices+1)*8-1]=-posY;
- vertices[vc++]=posZ;
- vertices[vc+(slices+1)*8-1]=posZ;
- vertices[vc++]=posX;
- vertices[vc+(slices+1)*8-1]=posX;
- vertices[vc++]=0;
- vertices[vc+(slices+1)*8-1]=0;
- vertices[vc++]=posZ;
- vertices[vc+(slices+1)*8-1]=posZ;
- vertices[vc++]=1-rv *1 / slices;
- vertices[vc+(slices+1)*8-1]=1-rv *1 / slices;
- vertices[vc++]=0;
- vertices[vc+(slices+1)*8-1]=1;
- }
- vc+=(slices+1)*8;
- for (var ri=0;ri < slices;ri++){
- indices[ic++]=ri+verticeCount+(slices+1);
- indices[ic++]=ri+verticeCount+1;
- indices[ic++]=ri+verticeCount;
- indices[ic++]=ri+verticeCount+(slices+1);
- indices[ic++]=ri+verticeCount+(slices+1)+1;
- indices[ic++]=ri+verticeCount+1;
- }
- verticeCount+=2 *(slices+1);
- for (var bv=0;bv <=slices;bv++){
- if (bv===0){
- vertices[vc++]=0;
- vertices[vc++]=-halfHeight;
- vertices[vc++]=0;
- vertices[vc++]=0;
- vertices[vc++]=-1;
- vertices[vc++]=0;
- vertices[vc++]=0.5;
- vertices[vc++]=0.5;
- }
- curAngle=bv *sliceAngle;
- posX=Math.cos(curAngle+Math.PI)*radius;
- posY=-halfHeight;
- posZ=Math.sin(curAngle+Math.PI)*radius;
- vertices[vc++]=posX;
- vertices[vc++]=posY;
- vertices[vc++]=posZ;
- vertices[vc++]=0;
- vertices[vc++]=-1;
- vertices[vc++]=0;
- vertices[vc++]=0.5+Math.cos(curAngle)*0.5;
- vertices[vc++]=0.5+Math.sin(curAngle)*0.5;
- }
- for (var bi=0;bi < slices;bi++){
- indices[ic++]=0+verticeCount;
- indices[ic++]=bi+2+verticeCount;
- indices[ic++]=bi+1+verticeCount;
- }
- verticeCount+=slices+1+1;
- return PrimitiveMesh._createMesh(vertexDeclaration,vertices,indices);
- }
- PrimitiveMesh.createPlane=function(long,width,stacks,slices){
- (long===void 0)&& (long=10);
- (width===void 0)&& (width=10);
- (stacks===void 0)&& (stacks=10);
- (slices===void 0)&& (slices=10);
- var vertexCount=(stacks+1)*(slices+1);
- var indexCount=stacks *slices *2 *3;
- var indices=new Uint16Array(indexCount);
- var vertexDeclaration=VertexMesh.getVertexDeclaration("POSITION,NORMAL,UV");
- var vertexFloatStride=vertexDeclaration.vertexStride / 4;
- var vertices=new Float32Array(vertexCount *vertexFloatStride);
- var halfLong=long / 2;
- var halfWidth=width / 2;
- var stacksLong=long / stacks;
- var slicesWidth=width / slices;
- var verticeCount=0;
- for (var i=0;i <=slices;i++){
- for (var j=0;j <=stacks;j++){
- vertices[verticeCount++]=j *stacksLong-halfLong;
- vertices[verticeCount++]=0;
- vertices[verticeCount++]=i *slicesWidth-halfWidth;
- vertices[verticeCount++]=0;
- vertices[verticeCount++]=1;
- vertices[verticeCount++]=0;
- vertices[verticeCount++]=j *1 / stacks;
- vertices[verticeCount++]=i *1 / slices;
- }
- };
- var indiceIndex=0;
- for (i=0;i < slices;i++){
- for (j=0;j < stacks;j++){
- indices[indiceIndex++]=(i+1)*(stacks+1)+j;
- indices[indiceIndex++]=i *(stacks+1)+j;
- indices[indiceIndex++]=(i+1)*(stacks+1)+j+1;
- indices[indiceIndex++]=i *(stacks+1)+j;
- indices[indiceIndex++]=i *(stacks+1)+j+1;
- indices[indiceIndex++]=(i+1)*(stacks+1)+j+1;
- }
- }
- return PrimitiveMesh._createMesh(vertexDeclaration,vertices,indices);
- }
- PrimitiveMesh.createQuad=function(long,width){
- (long===void 0)&& (long=1);
- (width===void 0)&& (width=1);
- var vertexCount=4;
- var indexCount=6;
- var vertexDeclaration=VertexMesh.getVertexDeclaration("POSITION,NORMAL,UV");
- var vertexFloatStride=vertexDeclaration.vertexStride / 4;
- var halfLong=long / 2;
- var halfWidth=width / 2;
- 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,]);
- var indices=new Uint16Array([
- 0,1,2,3,2,1,]);
- return PrimitiveMesh._createMesh(vertexDeclaration,vertices,indices);
- }
- PrimitiveMesh.createSphere=function(radius,stacks,slices){
- (radius===void 0)&& (radius=0.5);
- (stacks===void 0)&& (stacks=32);
- (slices===void 0)&& (slices=32);
- var vertexCount=(stacks+1)*(slices+1);
- var indexCount=(3 *stacks *(slices+1))*2;
- var indices=new Uint16Array(indexCount);
- var vertexDeclaration=VertexMesh.getVertexDeclaration("POSITION,NORMAL,UV");
- var vertexFloatStride=vertexDeclaration.vertexStride / 4;
- var vertices=new Float32Array(vertexCount *vertexFloatStride);
- var stackAngle=Math.PI / stacks;
- var sliceAngle=(Math.PI *2.0)/ slices;
- var vertexIndex=0;
- vertexCount=0;
- indexCount=0;
- for (var stack=0;stack < (stacks+1);stack++){
- var r=Math.sin(stack *stackAngle);
- var y=Math.cos(stack *stackAngle);
- for (var slice=0;slice < (slices+1);slice++){
- var x=r *Math.sin(slice *sliceAngle+Math.PI *1 / 2);
- var z=r *Math.cos(slice *sliceAngle+Math.PI *1 / 2);
- vertices[vertexCount+0]=x *radius;
- vertices[vertexCount+1]=y *radius;
- vertices[vertexCount+2]=z *radius;
- vertices[vertexCount+3]=x;
- vertices[vertexCount+4]=y;
- vertices[vertexCount+5]=z;
- vertices[vertexCount+6]=slice / slices;
- vertices[vertexCount+7]=stack / stacks;
- vertexCount+=vertexFloatStride;
- if (stack !=(stacks-1)){
- indices[indexCount++]=vertexIndex+(slices+1);
- indices[indexCount++]=vertexIndex;
- indices[indexCount++]=vertexIndex+1;
- indices[indexCount++]=vertexIndex+(slices);
- indices[indexCount++]=vertexIndex;
- indices[indexCount++]=vertexIndex+(slices+1);
- vertexIndex++;
- }
- }
- }
- return PrimitiveMesh._createMesh(vertexDeclaration,vertices,indices);
- }
- return PrimitiveMesh;
- })()
- /**
- *<code>PostProcessEffect</code> 类用于创建后期处理渲染效果。
- */
- //class laya.d3.core.render.PostProcessEffect
- var PostProcessEffect=(function(){
- /**
- *创建一个 <code>PostProcessEffect</code> 实例。
- */
- function PostProcessEffect(){}
- __class(PostProcessEffect,'laya.d3.core.render.PostProcessEffect');
- var __proto=PostProcessEffect.prototype;
- /**
- *@private
- */
- __proto.render=function(context){}
- return PostProcessEffect;
- })()
- /**
- *@private
- */
- //class laya.d3.animation.AnimationClipParser04
- var AnimationClipParser04=(function(){
- function AnimationClipParser04(){}
- __class(AnimationClipParser04,'laya.d3.animation.AnimationClipParser04');
- AnimationClipParser04.READ_DATA=function(){
- AnimationClipParser04._DATA.offset=AnimationClipParser04._reader.getUint32();
- AnimationClipParser04._DATA.size=AnimationClipParser04._reader.getUint32();
- }
- AnimationClipParser04.READ_BLOCK=function(){
- var count=AnimationClipParser04._BLOCK.count=AnimationClipParser04._reader.getUint16();
- var blockStarts=AnimationClipParser04._BLOCK.blockStarts=[];
- var blockLengths=AnimationClipParser04._BLOCK.blockLengths=[];
- for (var i=0;i < count;i++){
- blockStarts.push(AnimationClipParser04._reader.getUint32());
- blockLengths.push(AnimationClipParser04._reader.getUint32());
- }
- }
- AnimationClipParser04.READ_STRINGS=function(){
- var offset=AnimationClipParser04._reader.getUint32();
- var count=AnimationClipParser04._reader.getUint16();
- var prePos=AnimationClipParser04._reader.pos;
- AnimationClipParser04._reader.pos=offset+AnimationClipParser04._DATA.offset;
- for (var i=0;i < count;i++)
- AnimationClipParser04._strings[i]=AnimationClipParser04._reader.readUTFString();
- AnimationClipParser04._reader.pos=prePos;
- }
- AnimationClipParser04.parse=function(clip,reader,version){
- AnimationClipParser04._animationClip=clip;
- AnimationClipParser04._reader=reader;
- AnimationClipParser04._version=version;
- AnimationClipParser04.READ_DATA();
- AnimationClipParser04.READ_BLOCK();
- AnimationClipParser04.READ_STRINGS();
- for (var i=0,n=AnimationClipParser04._BLOCK.count;i < n;i++){
- var index=reader.getUint16();
- var blockName=AnimationClipParser04._strings[index];
- var fn=AnimationClipParser04["READ_"+blockName];
- if (fn==null)
- throw new Error("model file err,no this function:"+index+" "+blockName);
- else
- fn.call(null);
- }
- AnimationClipParser04._version=null;
- AnimationClipParser04._reader=null;
- AnimationClipParser04._animationClip=null;
- }
- AnimationClipParser04.READ_ANIMATIONS=function(){
- var i=0,j=0;
- var node;
- var reader=AnimationClipParser04._reader;
- var buffer=reader.__getBuffer();
- var startTimeTypes=[];
- var startTimeTypeCount=reader.getUint16();
- startTimeTypes.length=startTimeTypeCount;
- for (i=0;i < startTimeTypeCount;i++)
- startTimeTypes[i]=reader.getFloat32();
- var clip=AnimationClipParser04._animationClip;
- clip.name=AnimationClipParser04._strings[reader.getUint16()];
- var clipDur=clip._duration=reader.getFloat32();
- clip.islooping=!!reader.getByte();
- clip._frameRate=reader.getInt16();
- var nodeCount=reader.getInt16();
- var nodes=clip._nodes;
- nodes.count=nodeCount;
- var nodesMap=clip._nodesMap={};
- var nodesDic=clip._nodesDic={};
- for (i=0;i < nodeCount;i++){
- node=new KeyframeNode();
- nodes.setNodeByIndex(i,node);
- node._indexInList=i;
- var type=node.type=reader.getUint8();
- var pathLength=reader.getUint16();
- node._setOwnerPathCount(pathLength);
- for (j=0;j < pathLength;j++)
- node._setOwnerPathByIndex(j,AnimationClipParser04._strings[reader.getUint16()]);
- var nodePath=node._joinOwnerPath("/");
- var mapArray=nodesMap[nodePath];
- (mapArray)|| (nodesMap[nodePath]=mapArray=[]);
- mapArray.push(node);
- node.propertyOwner=AnimationClipParser04._strings[reader.getUint16()];
- var propertyLength=reader.getUint16();
- node._setPropertyCount(propertyLength);
- for (j=0;j < propertyLength;j++)
- node._setPropertyByIndex(j,AnimationClipParser04._strings[reader.getUint16()]);
- var fullPath=nodePath+"."+node.propertyOwner+"."+node._joinProperty(".");
- nodesDic[fullPath]=node;
- node.fullPath=fullPath;
- var keyframeCount=reader.getUint16();
- node._setKeyframeCount(keyframeCount);
- var startTime=NaN;
- switch (type){
- case 0:
- break ;
- case 1:
- case 3:
- case 4:
- node.data=Render.supportWebGLPlusAnimation ? new ConchVector3 :new Vector3();
- break ;
- case 2:
- node.data=Render.supportWebGLPlusAnimation ? new ConchQuaternion :new Quaternion();
- break ;
- default :
- throw "AnimationClipParser04:unknown type.";
- }
- switch (AnimationClipParser04._version){
- case "LAYAANIMATION:04":
- for (j=0;j < keyframeCount;j++){
- switch (type){
- case 0:;
- var floatKeyframe=new FloatKeyframe();
- node._setKeyframeByIndex(j,floatKeyframe);
- startTime=floatKeyframe.time=startTimeTypes[reader.getUint16()];
- floatKeyframe.inTangent=reader.getFloat32();
- floatKeyframe.outTangent=reader.getFloat32();
- floatKeyframe.value=reader.getFloat32();
- break ;
- case 1:
- case 3:
- case 4:;
- var floatArrayKeyframe=new Vector3Keyframe();
- node._setKeyframeByIndex(j,floatArrayKeyframe);
- startTime=floatArrayKeyframe.time=startTimeTypes[reader.getUint16()];
- if (Render.supportWebGLPlusAnimation){
- var data=(floatArrayKeyframe).data=new Float32Array(3 *3);
- for (var k=0;k < 3;k++)
- data[k]=reader.getFloat32();
- for (k=0;k < 3;k++)
- data[3+k]=reader.getFloat32();
- for (k=0;k < 3;k++)
- data[6+k]=reader.getFloat32();
- }
- else {
- var inTangent=floatArrayKeyframe.inTangent;
- var outTangent=floatArrayKeyframe.outTangent;
- var value=floatArrayKeyframe.value;
- inTangent.x=reader.getFloat32();
- inTangent.y=reader.getFloat32();
- inTangent.z=reader.getFloat32();
- outTangent.x=reader.getFloat32();
- outTangent.y=reader.getFloat32();
- outTangent.z=reader.getFloat32();
- value.x=reader.getFloat32();
- value.y=reader.getFloat32();
- value.z=reader.getFloat32();
- }
- break ;
- case 2:;
- var quaternionKeyframe=new QuaternionKeyframe();
- node._setKeyframeByIndex(j,quaternionKeyframe);
- startTime=quaternionKeyframe.time=startTimeTypes[reader.getUint16()];
- if (Render.supportWebGLPlusAnimation){
- data=(quaternionKeyframe).data=new Float32Array(3 *4);
- for (k=0;k < 4;k++)
- data[k]=reader.getFloat32();
- for (k=0;k < 4;k++)
- data[4+k]=reader.getFloat32();
- for (k=0;k < 4;k++)
- data[8+k]=reader.getFloat32();
- }
- else {
- var inTangentQua=quaternionKeyframe.inTangent;
- var outTangentQua=quaternionKeyframe.outTangent;
- var valueQua=quaternionKeyframe.value;
- inTangentQua.x=reader.getFloat32();
- inTangentQua.y=reader.getFloat32();
- inTangentQua.z=reader.getFloat32();
- inTangentQua.w=reader.getFloat32();
- outTangentQua.x=reader.getFloat32();
- outTangentQua.y=reader.getFloat32();
- outTangentQua.z=reader.getFloat32();
- outTangentQua.w=reader.getFloat32();
- valueQua.x=reader.getFloat32();
- valueQua.y=reader.getFloat32();
- valueQua.z=reader.getFloat32();
- valueQua.w=reader.getFloat32();
- }
- break ;
- default :
- throw "AnimationClipParser04:unknown type.";
- }
- }
- break ;
- case "LAYAANIMATION:COMPRESSION_04":
- for (j=0;j < keyframeCount;j++){
- switch (type){
- case 0:
- floatKeyframe=new FloatKeyframe();
- node._setKeyframeByIndex(j,floatKeyframe);
- startTime=floatKeyframe.time=startTimeTypes[reader.getUint16()];
- floatKeyframe.inTangent=HalfFloatUtils.convertToNumber(reader.getUint16());
- floatKeyframe.outTangent=HalfFloatUtils.convertToNumber(reader.getUint16());
- floatKeyframe.value=HalfFloatUtils.convertToNumber(reader.getUint16());
- break ;
- case 1:
- case 3:
- case 4:
- floatArrayKeyframe=new Vector3Keyframe();
- node._setKeyframeByIndex(j,floatArrayKeyframe);
- startTime=floatArrayKeyframe.time=startTimeTypes[reader.getUint16()];
- if (Render.supportWebGLPlusAnimation){
- data=(floatArrayKeyframe).data=new Float32Array(3 *3);
- for (k=0;k < 3;k++)
- data[k]=HalfFloatUtils.convertToNumber(reader.getUint16());
- for (k=0;k < 3;k++)
- data[3+k]=HalfFloatUtils.convertToNumber(reader.getUint16());
- for (k=0;k < 3;k++)
- data[6+k]=HalfFloatUtils.convertToNumber(reader.getUint16());
- }
- else {
- inTangent=floatArrayKeyframe.inTangent;
- outTangent=floatArrayKeyframe.outTangent;
- value=floatArrayKeyframe.value;
- inTangent.x=HalfFloatUtils.convertToNumber(reader.getUint16());
- inTangent.y=HalfFloatUtils.convertToNumber(reader.getUint16());
- inTangent.z=HalfFloatUtils.convertToNumber(reader.getUint16());
- outTangent.x=HalfFloatUtils.convertToNumber(reader.getUint16());
- outTangent.y=HalfFloatUtils.convertToNumber(reader.getUint16());
- outTangent.z=HalfFloatUtils.convertToNumber(reader.getUint16());
- value.x=HalfFloatUtils.convertToNumber(reader.getUint16());
- value.y=HalfFloatUtils.convertToNumber(reader.getUint16());
- value.z=HalfFloatUtils.convertToNumber(reader.getUint16());
- }
- break ;
- case 2:
- quaternionKeyframe=new QuaternionKeyframe();
- node._setKeyframeByIndex(j,quaternionKeyframe);
- startTime=quaternionKeyframe.time=startTimeTypes[reader.getUint16()];
- if (Render.supportWebGLPlusAnimation){
- data=(quaternionKeyframe).data=new Float32Array(3 *4);
- for (k=0;k < 4;k++)
- data[k]=HalfFloatUtils.convertToNumber(reader.getUint16());
- for (k=0;k < 4;k++)
- data[4+k]=HalfFloatUtils.convertToNumber(reader.getUint16());
- for (k=0;k < 4;k++)
- data[8+k]=HalfFloatUtils.convertToNumber(reader.getUint16());
- }
- else {
- inTangentQua=quaternionKeyframe.inTangent;
- outTangentQua=quaternionKeyframe.outTangent;
- valueQua=quaternionKeyframe.value;
- inTangentQua.x=HalfFloatUtils.convertToNumber(reader.getUint16());
- inTangentQua.y=HalfFloatUtils.convertToNumber(reader.getUint16());
- inTangentQua.z=HalfFloatUtils.convertToNumber(reader.getUint16());
- inTangentQua.w=HalfFloatUtils.convertToNumber(reader.getUint16());
- outTangentQua.x=HalfFloatUtils.convertToNumber(reader.getUint16());
- outTangentQua.y=HalfFloatUtils.convertToNumber(reader.getUint16());
- outTangentQua.z=HalfFloatUtils.convertToNumber(reader.getUint16());
- outTangentQua.w=HalfFloatUtils.convertToNumber(reader.getUint16());
- valueQua.x=HalfFloatUtils.convertToNumber(reader.getUint16());
- valueQua.y=HalfFloatUtils.convertToNumber(reader.getUint16());
- valueQua.z=HalfFloatUtils.convertToNumber(reader.getUint16());
- valueQua.w=HalfFloatUtils.convertToNumber(reader.getUint16());
- }
- break ;
- default :
- throw "AnimationClipParser04:unknown type.";
- }
- }
- break ;
- }
- };
- var eventCount=reader.getUint16();
- for (i=0;i < eventCount;i++){
- var event=new AnimationEvent();
- event.time=Math.min(clipDur,reader.getFloat32());
- event.eventName=AnimationClipParser04._strings[reader.getUint16()];
- var params;
- var paramCount=reader.getUint16();
- (paramCount > 0)&& (event.params=params=[]);
- for (j=0;j < paramCount;j++){
- var eventType=reader.getByte();
- switch (eventType){
- case 0:
- params.push(!!reader.getByte());
- break ;
- case 1:
- params.push(reader.getInt32());
- break ;
- case 2:
- params.push(reader.getFloat32());
- break ;
- case 3:
- params.push(AnimationClipParser04._strings[reader.getUint16()]);
- break ;
- default :
- throw new Error("unknown type.");
- }
- }
- clip.addEvent(event);
- }
- }
- AnimationClipParser04._animationClip=null;
- AnimationClipParser04._reader=null;
- AnimationClipParser04._strings=[];
- AnimationClipParser04._version=null;
- __static(AnimationClipParser04,
- ['_BLOCK',function(){return this._BLOCK={count:0};},'_DATA',function(){return this._DATA={offset:0,size:0};}
- ]);
- return AnimationClipParser04;
- })()
- /**
- *@private
- */
- //class laya.d3.animation.AnimationClipParser03
- var AnimationClipParser03=(function(){
- function AnimationClipParser03(){}
- __class(AnimationClipParser03,'laya.d3.animation.AnimationClipParser03');
- AnimationClipParser03.READ_DATA=function(){
- AnimationClipParser03._DATA.offset=AnimationClipParser03._reader.getUint32();
- AnimationClipParser03._DATA.size=AnimationClipParser03._reader.getUint32();
- }
- AnimationClipParser03.READ_BLOCK=function(){
- var count=AnimationClipParser03._BLOCK.count=AnimationClipParser03._reader.getUint16();
- var blockStarts=AnimationClipParser03._BLOCK.blockStarts=[];
- var blockLengths=AnimationClipParser03._BLOCK.blockLengths=[];
- for (var i=0;i < count;i++){
- blockStarts.push(AnimationClipParser03._reader.getUint32());
- blockLengths.push(AnimationClipParser03._reader.getUint32());
- }
- }
- AnimationClipParser03.READ_STRINGS=function(){
- var offset=AnimationClipParser03._reader.getUint32();
- var count=AnimationClipParser03._reader.getUint16();
- var prePos=AnimationClipParser03._reader.pos;
- AnimationClipParser03._reader.pos=offset+AnimationClipParser03._DATA.offset;
- for (var i=0;i < count;i++)
- AnimationClipParser03._strings[i]=AnimationClipParser03._reader.readUTFString();
- AnimationClipParser03._reader.pos=prePos;
- }
- AnimationClipParser03.parse=function(clip,reader){
- AnimationClipParser03._animationClip=clip;
- AnimationClipParser03._reader=reader;
- var arrayBuffer=reader.__getBuffer();
- AnimationClipParser03.READ_DATA();
- AnimationClipParser03.READ_BLOCK();
- AnimationClipParser03.READ_STRINGS();
- for (var i=0,n=AnimationClipParser03._BLOCK.count;i < n;i++){
- var index=reader.getUint16();
- var blockName=AnimationClipParser03._strings[index];
- var fn=AnimationClipParser03["READ_"+blockName];
- if (fn==null)
- throw new Error("model file err,no this function:"+index+" "+blockName);
- else
- fn.call(null);
- }
- }
- AnimationClipParser03.READ_ANIMATIONS=function(){
- var i=0,j=0;
- var node;
- var reader=AnimationClipParser03._reader;
- var buffer=reader.__getBuffer();
- var startTimeTypes=[];
- var startTimeTypeCount=reader.getUint16();
- startTimeTypes.length=startTimeTypeCount;
- for (i=0;i < startTimeTypeCount;i++)
- startTimeTypes[i]=reader.getFloat32();
- var clip=AnimationClipParser03._animationClip;
- clip.name=AnimationClipParser03._strings[reader.getUint16()];
- var clipDur=clip._duration=reader.getFloat32();
- clip.islooping=!!reader.getByte();
- clip._frameRate=reader.getInt16();
- var nodeCount=reader.getInt16();
- var nodes=clip._nodes;
- nodes.count=nodeCount;
- var nodesMap=clip._nodesMap={};
- var nodesDic=clip._nodesDic={};
- for (i=0;i < nodeCount;i++){
- node=new KeyframeNode();
- nodes.setNodeByIndex(i,node);
- node._indexInList=i;
- var type=node.type=reader.getUint8();
- var pathLength=reader.getUint16();
- node._setOwnerPathCount(pathLength);
- for (j=0;j < pathLength;j++)
- node._setOwnerPathByIndex(j,AnimationClipParser03._strings[reader.getUint16()]);
- var nodePath=node._joinOwnerPath("/");
- var mapArray=nodesMap[nodePath];
- (mapArray)|| (nodesMap[nodePath]=mapArray=[]);
- mapArray.push(node);
- node.propertyOwner=AnimationClipParser03._strings[reader.getUint16()];
- var propertyLength=reader.getUint16();
- node._setPropertyCount(propertyLength);
- for (j=0;j < propertyLength;j++)
- node._setPropertyByIndex(j,AnimationClipParser03._strings[reader.getUint16()]);
- var fullPath=nodePath+"."+node.propertyOwner+"."+node._joinProperty(".");
- nodesDic[fullPath]=node;
- node.fullPath=fullPath;
- var keyframeCount=reader.getUint16();
- node._setKeyframeCount(keyframeCount);
- var startTime=NaN;
- switch (type){
- case 0:
- break ;
- case 1:
- case 3:
- case 4:
- node.data=Render.supportWebGLPlusAnimation ? new ConchVector3 :new Vector3();
- break ;
- case 2:
- node.data=Render.supportWebGLPlusAnimation ? new ConchQuaternion :new Quaternion();
- break ;
- default :
- throw "AnimationClipParser03:unknown type.";
- }
- for (j=0;j < keyframeCount;j++){
- switch (type){
- case 0:;
- var floatKeyframe=new FloatKeyframe();
- node._setKeyframeByIndex(j,floatKeyframe);
- startTime=floatKeyframe.time=startTimeTypes[reader.getUint16()];
- floatKeyframe.inTangent=reader.getFloat32();
- floatKeyframe.outTangent=reader.getFloat32();
- floatKeyframe.value=reader.getFloat32();
- break ;
- case 1:
- case 3:
- case 4:;
- var floatArrayKeyframe=new Vector3Keyframe();
- node._setKeyframeByIndex(j,floatArrayKeyframe);
- startTime=floatArrayKeyframe.time=startTimeTypes[reader.getUint16()];
- if (Render.supportWebGLPlusAnimation){
- var data=(floatArrayKeyframe).data=new Float32Array(3 *3);
- for (var k=0;k < 3;k++)
- data[k]=reader.getFloat32();
- for (k=0;k < 3;k++)
- data[3+k]=reader.getFloat32();
- for (k=0;k < 3;k++)
- data[6+k]=reader.getFloat32();
- }
- else {
- var inTangent=floatArrayKeyframe.inTangent;
- var outTangent=floatArrayKeyframe.outTangent;
- var value=floatArrayKeyframe.value;
- inTangent.x=reader.getFloat32();
- inTangent.y=reader.getFloat32();
- inTangent.z=reader.getFloat32();
- outTangent.x=reader.getFloat32();
- outTangent.y=reader.getFloat32();
- outTangent.z=reader.getFloat32();
- value.x=reader.getFloat32();
- value.y=reader.getFloat32();
- value.z=reader.getFloat32();
- }
- break ;
- case 2:;
- var quaArrayKeyframe=new QuaternionKeyframe();
- node._setKeyframeByIndex(j,quaArrayKeyframe);
- startTime=quaArrayKeyframe.time=startTimeTypes[reader.getUint16()];
- if (Render.supportWebGLPlusAnimation){
- data=(quaArrayKeyframe).data=new Float32Array(3 *4);
- for (k=0;k < 4;k++)
- data[k]=reader.getFloat32();
- for (k=0;k < 4;k++)
- data[4+k]=reader.getFloat32();
- for (k=0;k < 4;k++)
- data[8+k]=reader.getFloat32();
- }
- else {
- var inTangentQua=quaArrayKeyframe.inTangent;
- var outTangentQua=quaArrayKeyframe.outTangent;
- var valueQua=quaArrayKeyframe.value;
- inTangentQua.x=reader.getFloat32();
- inTangentQua.y=reader.getFloat32();
- inTangentQua.z=reader.getFloat32();
- inTangentQua.w=reader.getFloat32();
- outTangentQua.x=reader.getFloat32();
- outTangentQua.y=reader.getFloat32();
- outTangentQua.z=reader.getFloat32();
- outTangentQua.w=reader.getFloat32();
- valueQua.x=reader.getFloat32();
- valueQua.y=reader.getFloat32();
- valueQua.z=reader.getFloat32();
- valueQua.w=reader.getFloat32();
- }
- break ;
- default :
- throw "AnimationClipParser03:unknown type.";
- }
- }
- };
- var eventCount=reader.getUint16();
- for (i=0;i < eventCount;i++){
- var event=new AnimationEvent();
- event.time=Math.min(clipDur,reader.getFloat32());
- event.eventName=AnimationClipParser03._strings[reader.getUint16()];
- var params;
- var paramCount=reader.getUint16();
- (paramCount > 0)&& (event.params=params=[]);
- for (j=0;j < paramCount;j++){
- var eventType=reader.getByte();
- switch (eventType){
- case 0:
- params.push(!!reader.getByte());
- break ;
- case 1:
- params.push(reader.getInt32());
- break ;
- case 2:
- params.push(reader.getFloat32());
- break ;
- case 3:
- params.push(AnimationClipParser03._strings[reader.getUint16()]);
- break ;
- default :
- throw new Error("unknown type.");
- }
- }
- clip.addEvent(event);
- }
- }
- AnimationClipParser03._animationClip=null;
- AnimationClipParser03._reader=null;
- AnimationClipParser03._strings=[];
- __static(AnimationClipParser03,
- ['_BLOCK',function(){return this._BLOCK={count:0};},'_DATA',function(){return this._DATA={offset:0,size:0};}
- ]);
- return AnimationClipParser03;
- })()
- /**
- *<code>DefineDatas</code> 类用于创建宏定义数据。
- */
- //class laya.d3.shader.DefineDatas
- var DefineDatas=(function(){
- function DefineDatas(){
- /**@private */
- //this.value=0;
- this.value=0;
- }
- __class(DefineDatas,'laya.d3.shader.DefineDatas');
- var __proto=DefineDatas.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *增加Shader宏定义。
- *@param value 宏定义。
- */
- __proto.add=function(define){
- this.value |=define;
- }
- /**
- *移除Shader宏定义。
- *@param value 宏定义。
- */
- __proto.remove=function(define){
- this.value &=~define;
- }
- /**
- *是否包含Shader宏定义。
- *@param value 宏定义。
- */
- __proto.has=function(define){
- return (this.value & define)> 0;
- }
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var destDefineData=destObject;
- destDefineData.value=this.value;
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var dest=/*__JS__ */new this.constructor();
- this.cloneTo(dest);
- return dest;
- }
- return DefineDatas;
- })()
- /**
- *<code>VertexElement</code> 类用于创建顶点结构分配。
- */
- //class laya.d3.graphics.VertexElement
- var VertexElement=(function(){
- function VertexElement(offset,elementFormat,elementUsage){
- this.offset=0;
- this.elementFormat=null;
- this.elementUsage=0;
- this.offset=offset;
- this.elementFormat=elementFormat;
- this.elementUsage=elementUsage;
- }
- __class(VertexElement,'laya.d3.graphics.VertexElement');
- return VertexElement;
- })()
- /**
- *<code>HeightMap</code> 类用于实现高度图数据。
- */
- //class laya.d3.core.HeightMap
- var HeightMap=(function(){
- function HeightMap(width,height,minHeight,maxHeight){
- /**@private */
- this._datas=null;
- /**@private */
- this._w=0;
- /**@private */
- this._h=0;
- /**@private */
- this._minHeight=NaN;
- /**@private */
- this._maxHeight=NaN;
- this._datas=[];
- this._w=width;
- this._h=height;
- this._minHeight=minHeight;
- this._maxHeight=maxHeight;
- }
- __class(HeightMap,'laya.d3.core.HeightMap');
- var __proto=HeightMap.prototype;
- /**@private */
- __proto._inBounds=function(row,col){
- return row >=0 && row < this._h && col >=0 && col < this._w;
- }
- /**
- *获取高度。
- *@param row 列数。
- *@param col 行数。
- *@return 高度。
- */
- __proto.getHeight=function(row,col){
- if (this._inBounds(row,col))
- return this._datas[row][col];
- else
- return NaN;
- }
- /**
- *获取宽度。
- *@return value 宽度。
- */
- __getset(0,__proto,'width',function(){
- return this._w;
- });
- /**
- *获取高度。
- *@return value 高度。
- */
- __getset(0,__proto,'height',function(){
- return this._h;
- });
- /**
- *最大高度。
- *@return value 最大高度。
- */
- __getset(0,__proto,'maxHeight',function(){
- return this._maxHeight;
- });
- /**
- *最大高度。
- *@return value 最大高度。
- */
- __getset(0,__proto,'minHeight',function(){
- return this._minHeight;
- });
- HeightMap.creatFromMesh=function(mesh,width,height,outCellSize){
- var vertices=[];
- var indexs=[];
- var submesheCount=mesh.subMeshCount;
- for (var i=0;i < submesheCount;i++){
- var subMesh=mesh._getSubMesh(i);
- var vertexBuffer=subMesh._vertexBuffer;
- var verts=vertexBuffer.getData();
- var subMeshVertices=[];
- for (var j=0;j < verts.length;j+=vertexBuffer.vertexDeclaration.vertexStride / 4){
- var position=new Vector3(verts[j+0],verts[j+1],verts[j+2]);
- subMeshVertices.push(position);
- }
- vertices.push(subMeshVertices);
- var ib=subMesh._indexBuffer;
- indexs.push(ib.getData());
- };
- var bounds=mesh.bounds;
- var minX=bounds.getMin().x;
- var minZ=bounds.getMin().z;
- var maxX=bounds.getMax().x;
- var maxZ=bounds.getMax().z;
- var minY=bounds.getMin().y;
- var maxY=bounds.getMax().y;
- var widthSize=maxX-minX;
- var heightSize=maxZ-minZ;
- var cellWidth=outCellSize.x=widthSize / (width-1);
- var cellHeight=outCellSize.y=heightSize / (height-1);
- var heightMap=new HeightMap(width,height,minY,maxY);
- var ray=HeightMap._tempRay;
- var rayDir=ray.direction;
- rayDir.x=0;
- rayDir.y=-1;
- rayDir.z=0;
- var heightOffset=0.1;
- var rayY=maxY+heightOffset;
- ray.origin.y=rayY;
- for (var h=0;h < height;h++){
- var posZ=minZ+h *cellHeight;
- heightMap._datas[h]=[];
- for (var w=0;w < width;w++){
- var posX=minX+w *cellWidth;
- var rayOri=ray.origin;
- rayOri.x=posX;
- rayOri.z=posZ;
- var closestIntersection=HeightMap._getPosition(ray,vertices,indexs);
- heightMap._datas[h][w]=(closestIntersection===Number.MAX_VALUE)? NaN :rayY-closestIntersection;
- }
- }
- return heightMap;
- }
- HeightMap.createFromImage=function(texture,minHeight,maxHeight){
- var textureWidth=texture.width;
- var textureHeight=texture.height;
- var heightMap=new HeightMap(textureWidth,textureHeight,minHeight,maxHeight);
- var compressionRatio=(maxHeight-minHeight)/ 254;
- var pixelsInfo=texture.getPixels();
- var index=0;
- for (var h=0;h <textureHeight;h++){
- var colDatas=heightMap._datas[h]=[];
- for (var w=0;w < textureWidth;w++){
- var r=pixelsInfo[index++];
- var g=pixelsInfo[index++];
- var b=pixelsInfo[index++];
- var a=pixelsInfo[index++];
- if (r==255 && g==255 && b==255 && a==255)
- colDatas[w]=NaN;
- else {
- colDatas[w]=(r+g+b)/ 3 *compressionRatio+minHeight;
- }
- }
- }
- return heightMap;
- }
- HeightMap._getPosition=function(ray,vertices,indexs){
- var closestIntersection=Number.MAX_VALUE;
- for (var i=0;i < vertices.length;i++){
- var subMeshVertices=vertices[i];
- var subMeshIndexes=indexs[i];
- for (var j=0;j < subMeshIndexes.length;j+=3){
- var vertex1=subMeshVertices[subMeshIndexes[j+0]];
- var vertex2=subMeshVertices[subMeshIndexes[j+1]];
- var vertex3=subMeshVertices[subMeshIndexes[j+2]];
- var intersection=Picker.rayIntersectsTriangle(ray,vertex1,vertex2,vertex3);
- if (!isNaN(intersection)&& intersection < closestIntersection){
- closestIntersection=intersection;
- }
- }
- }
- return closestIntersection;
- }
- __static(HeightMap,
- ['_tempRay',function(){return this._tempRay=new Ray(new Vector3(),new Vector3());}
- ]);
- return HeightMap;
- })()
- /**
- *@private
- *<code>ShaderInit</code> 类用于初始化内置Shader。
- */
- //class laya.d3.shader.ShaderInit3D
- var ShaderInit3D=(function(){
- /**
- *创建一个 <code>ShaderInit</code> 实例。
- */
- function ShaderInit3D(){}
- __class(ShaderInit3D,'laya.d3.shader.ShaderInit3D');
- ShaderInit3D.__init__=function(){
- ShaderInit3D._rangeAttenTex=Utils3D._buildTexture2D(1024,1,/*laya.resource.BaseTexture.FORMAT_ALPHA8*/2,TextureGenerator.lightAttenTexture);
- ShaderInit3D._rangeAttenTex.wrapModeU=/*laya.resource.BaseTexture.WARPMODE_CLAMP*/1;
- ShaderInit3D._rangeAttenTex.wrapModeV=/*laya.resource.BaseTexture.WARPMODE_CLAMP*/1;
- ShaderInit3D._rangeAttenTex.lock=true;
- Shader3D.SHADERDEFINE_HIGHPRECISION=Shader3D.registerPublicDefine("HIGHPRECISION");
- Scene3D.SHADERDEFINE_FOG=Shader3D.registerPublicDefine("FOG");
- Scene3D.SHADERDEFINE_DIRECTIONLIGHT=Shader3D.registerPublicDefine("DIRECTIONLIGHT");
- Scene3D.SHADERDEFINE_POINTLIGHT=Shader3D.registerPublicDefine("POINTLIGHT");
- Scene3D.SHADERDEFINE_SPOTLIGHT=Shader3D.registerPublicDefine("SPOTLIGHT");
- Scene3D.SHADERDEFINE_CAST_SHADOW=Shader3D.registerPublicDefine("CASTSHADOW");
- Scene3D.SHADERDEFINE_SHADOW_PSSM1=Shader3D.registerPublicDefine("SHADOWMAP_PSSM1");
- Scene3D.SHADERDEFINE_SHADOW_PSSM2=Shader3D.registerPublicDefine("SHADOWMAP_PSSM2");
- Scene3D.SHADERDEFINE_SHADOW_PSSM3=Shader3D.registerPublicDefine("SHADOWMAP_PSSM3");
- Scene3D.SHADERDEFINE_SHADOW_PCF_NO=Shader3D.registerPublicDefine("SHADOWMAP_PCF_NO");
- Scene3D.SHADERDEFINE_SHADOW_PCF1=Shader3D.registerPublicDefine("SHADOWMAP_PCF1");
- Scene3D.SHADERDEFINE_SHADOW_PCF2=Shader3D.registerPublicDefine("SHADOWMAP_PCF2");
- Scene3D.SHADERDEFINE_SHADOW_PCF3=Shader3D.registerPublicDefine("SHADOWMAP_PCF3");
- Scene3D.SHADERDEFINE_REFLECTMAP=Shader3D.registerPublicDefine("REFLECTMAP");
- Shader3D.addInclude("Lighting.glsl","\nstruct DirectionLight {\n vec3 Color;\n vec3 Direction;\n};\n\nstruct PointLight {\n vec3 Color;\n vec3 Position;\n float Range;\n};\n\nstruct SpotLight {\n vec3 Color;\n vec3 Position;\n vec3 Direction;\n float Spot;\n float Range;\n};\n\n// Laya中使用衰减纹理\nfloat LayaAttenuation(in vec3 L,in float invLightRadius) {\n float fRatio = clamp(length(L) * invLightRadius,0.0,1.0);\n fRatio *= fRatio;\n return 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\n}\n\n// Same as Just Cause 2 and Crysis 2 (you can read GPU Pro 1 book for more information)\nfloat BasicAttenuation(in vec3 L,in float invLightRadius) {\n vec3 distance = L * invLightRadius;\n float attenuation = clamp(1.0 - dot(distance, distance),0.0,1.0); // Equals float attenuation = saturate(1.0f - dot(L, L) / (lightRadius * lightRadius));\n return attenuation * attenuation;\n}\n\n// Inspired on http://fools.slindev.com/viewtopic.php?f=11&t=21&view=unread#unread\nfloat NaturalAttenuation(in vec3 L,in float invLightRadius) {\n float attenuationFactor = 30.0;\n vec3 distance = L * invLightRadius;\n float attenuation = dot(distance, distance); // Equals float attenuation = dot(L, L) / (lightRadius * lightRadius);\n attenuation = 1.0 / (attenuation * attenuationFactor + 1.0);\n // Second we move down the function therewith it reaches zero at abscissa 1:\n attenuationFactor = 1.0 / (attenuationFactor + 1.0); //attenuationFactor contains now the value we have to subtract\n attenuation = max(attenuation - attenuationFactor, 0.0); // The max fixes a bug.\n // Finally we expand the equation along the y-axis so that it starts with a function value of 1 again.\n attenuation /= 1.0 - attenuationFactor;\n return attenuation;\n}\n\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) {\n mediump vec3 h = normalize(viewDir-lightVec);\n lowp float ln = max (0.0, dot (-lightVec,normal));\n float nh = max (0.0, dot (h,normal));\n diffuseColor=lightColor * ln;\n specularColor=lightColor *specColor*pow (nh, specColorIntensity*128.0) * gloss;\n}\n\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) {\n vec3 lightVec=normalize(light.Direction);\n LayaAirBlinnPhongLight(specColor,specColorIntensity,normal,gloss,viewDir,light.Color,lightVec,diffuseColor,specularColor);\n}\n\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) {\n vec3 lightVec = pos-light.Position;\n //if( length(lightVec) > light.Range )\n // return;\n LayaAirBlinnPhongLight(specColor,specColorIntensity,normal,gloss,viewDir,light.Color,lightVec/length(lightVec),diffuseColor,specularColor);\n float attenuate = LayaAttenuation(lightVec, 1.0/light.Range);\n diffuseColor *= attenuate;\n specularColor*= attenuate;\n}\n\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) {\n vec3 lightVec = pos-light.Position;\n //if( length(lightVec) > light.Range)\n // return;\n\n vec3 normalLightVec=lightVec/length(lightVec);\n LayaAirBlinnPhongLight(specColor,specColorIntensity,normal,gloss,viewDir,light.Color,normalLightVec,diffuseColor,specularColor);\n vec2 cosAngles=cos(vec2(light.Spot,light.Spot*0.5)*0.5);//ConeAttenuation\n float dl=dot(normalize(light.Direction),normalLightVec);\n dl*=smoothstep(cosAngles[0],cosAngles[1],dl);\n float attenuate = LayaAttenuation(lightVec, 1.0/light.Range)*dl;\n diffuseColor *=attenuate;\n specularColor *=attenuate;\n}\n\nvec3 NormalSampleToWorldSpace(vec3 normalMapSample, vec3 unitNormal, vec3 tangent,vec3 binormal) {\n vec3 normalT =vec3(2.0*normalMapSample.x - 1.0,1.0-2.0*normalMapSample.y,2.0*normalMapSample.z - 1.0);\n\n // Build orthonormal basis.\n vec3 N = normalize(unitNormal);\n vec3 T = normalize(tangent);\n vec3 B = normalize(binormal);\n mat3 TBN = mat3(T, B, N);\n\n // Transform from tangent space to world space.\n vec3 bumpedNormal = TBN*normalT;\n\n return bumpedNormal;\n}\n\nvec3 NormalSampleToWorldSpace1(vec4 normalMapSample, vec3 tangent, vec3 binormal, vec3 unitNormal) {\n vec3 normalT;\n normalT.x = 2.0 * normalMapSample.x - 1.0;\n normalT.y = 1.0 - 2.0 * normalMapSample.y;\n normalT.z = sqrt(1.0 - clamp(dot(normalT.xy, normalT.xy), 0.0, 1.0));\n\n vec3 T = normalize(tangent);\n vec3 B = normalize(binormal);\n vec3 N = normalize(unitNormal);\n mat3 TBN = mat3(T, B, N);\n\n // Transform from tangent space to world space.\n vec3 bumpedNormal = TBN * normalize(normalT);\n\n return bumpedNormal;\n}\n\nvec3 DecodeLightmap(vec4 color) {\n return color.rgb*color.a*5.0;\n}\n\nvec2 TransformUV(vec2 texcoord,vec4 tilingOffset) {\n vec2 transTexcoord=vec2(texcoord.x,texcoord.y-1.0)*tilingOffset.xy+vec2(tilingOffset.z,-tilingOffset.w);\n transTexcoord.y+=1.0;\n return transTexcoord;\n}\n\nvec4 remapGLPositionZ(vec4 position) {\n position.z=position.z * 2.0 - position.w;\n return position;\n}\n\nmat3 inverse(mat3 m) {\n float a00 = m[0][0], a01 = m[0][1], a02 = m[0][2];\n float a10 = m[1][0], a11 = m[1][1], a12 = m[1][2];\n float a20 = m[2][0], a21 = m[2][1], a22 = m[2][2];\n\n float b01 = a22 * a11 - a12 * a21;\n float b11 = -a22 * a10 + a12 * a20;\n float b21 = a21 * a10 - a11 * a20;\n\n float det = a00 * b01 + a01 * b11 + a02 * b21;\n\n return mat3(b01, (-a22 * a01 + a02 * a21), (a12 * a01 - a02 * a11),\n b11, (a22 * a00 - a02 * a20), (-a12 * a00 + a02 * a10),\n b21, (-a21 * a00 + a01 * a20), (a11 * a00 - a01 * a10)) / det;\n}\n\n");
- Shader3D.addInclude("ShadowHelper.glsl","uniform sampler2D u_shadowMap1;\nuniform sampler2D u_shadowMap2;\nuniform sampler2D u_shadowMap3;\nuniform vec2 u_shadowPCFoffset;\nuniform vec4 u_shadowPSSMDistance;\nvec4 packDepth(const in float depth)\n{\n const vec4 bitShift = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);\n const vec4 bitMask = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);\n vec4 res = mod(depth*bitShift*vec4(255), vec4(256))/vec4(255);\n res -= res.xxyz * bitMask;\n return res;\n}\nfloat unpackDepth(const in vec4 rgbaDepth)\n{\n const vec4 bitShift = vec4(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0), 1.0/256.0, 1.0);\n float depth = dot(rgbaDepth, bitShift);\n return depth;\n}\nfloat tex2DPCF( sampler2D shadowMap,vec2 texcoord,vec2 invsize,float zRef )\n{\n vec2 texelpos =texcoord / invsize;\n vec2 lerps = fract( texelpos );\n float sourcevals[4];\n sourcevals[0] = float( unpackDepth(texture2D(shadowMap,texcoord)) > zRef );\n sourcevals[1] = float( unpackDepth(texture2D(shadowMap,texcoord + vec2(invsize.x,0))) > zRef );\n sourcevals[2] = float( unpackDepth(texture2D(shadowMap,texcoord + vec2(0,invsize.y))) > zRef );\n sourcevals[3] = float( unpackDepth(texture2D(shadowMap,texcoord + vec2(invsize.x, invsize.y) )) > zRef );\n return mix( mix(sourcevals[0],sourcevals[2],lerps.y),mix(sourcevals[1],sourcevals[3],lerps.y),lerps.x );\n}\nfloat getShadowPSSM3( sampler2D shadowMap1,sampler2D shadowMap2,sampler2D shadowMap3,mat4 lightShadowVP[4],vec4 pssmDistance,vec2 shadowPCFOffset,vec3 worldPos,float posViewZ,float zBias )\n{\n float value = 1.0;\n int nPSNum = int(posViewZ>pssmDistance.x);\n nPSNum += int(posViewZ>pssmDistance.y);\n nPSNum += int(posViewZ>pssmDistance.z);\n //真SB,webgl不支持在PS中直接访问数组\n mat4 lightVP;\n if( nPSNum == 0 )\n {\n lightVP = lightShadowVP[1];\n }\n else if( nPSNum == 1 )\n {\n lightVP = lightShadowVP[2];\n }\n else if( nPSNum == 2 )\n {\n lightVP = lightShadowVP[3];\n }\n vec4 vLightMVPPos = lightVP * vec4(worldPos,1.0);\n //为了效率,在CPU计算/2.0 + 0.5\n //vec3 vText = (vLightMVPPos.xyz / vLightMVPPos.w)/2.0 + 0.5;\n vec3 vText = vLightMVPPos.xyz / vLightMVPPos.w;\n float fMyZ = vText.z - zBias;\n /*\n bvec4 bInFrustumVec = bvec4 ( vText.x >= 0.0, vText.x <= 1.0, vText.y >= 0.0, vText.y <= 1.0 );\n bool bInFrustum = all( bInFrustumVec );\n bvec2 bFrustumTestVec = bvec2( bInFrustum, fMyZ <= 1.0 );\n bool bFrustumTest = all( bFrustumTestVec );\n if ( bFrustumTest ) \n */\n if( fMyZ <= 1.0 )\n {\n float zdepth=0.0;\n#ifdef SHADOWMAP_PCF3\n if ( nPSNum == 0 )\n {\n value = tex2DPCF( shadowMap1, vText.xy,shadowPCFOffset,fMyZ );\n value += tex2DPCF( shadowMap1, vText.xy+vec2(shadowPCFOffset.xy),shadowPCFOffset, fMyZ );\n value += tex2DPCF( shadowMap1, vText.xy+vec2(shadowPCFOffset.x,0),shadowPCFOffset, fMyZ );\n value += tex2DPCF( shadowMap1, vText.xy+vec2(0,shadowPCFOffset.y),shadowPCFOffset, fMyZ );\n value = value/4.0;\n } \n else if( nPSNum == 1 )\n {\n value = tex2DPCF( shadowMap2,vText.xy,shadowPCFOffset,fMyZ);\n }\n else if( nPSNum == 2 )\n {\n vec4 color = texture2D( shadowMap3,vText.xy );\n zdepth = unpackDepth(color);\n value = float(fMyZ < zdepth);\n }\n#endif\n#ifdef SHADOWMAP_PCF2\n if ( nPSNum == 0 )\n {\n value = tex2DPCF( shadowMap1,vText.xy,shadowPCFOffset,fMyZ);\n }\n else if( nPSNum == 1 )\n {\n value = tex2DPCF( shadowMap2,vText.xy,shadowPCFOffset,fMyZ);\n }\n else if( nPSNum == 2 )\n {\n vec4 color = texture2D( shadowMap3,vText.xy );\n zdepth = unpackDepth(color);\n value = float(fMyZ < zdepth);\n }\n\n#endif\n#ifdef SHADOWMAP_PCF1\n if ( nPSNum == 0 )\n {\n value = tex2DPCF( shadowMap1,vText.xy,shadowPCFOffset,fMyZ);\n }\n else if( nPSNum == 1 )\n {\n vec4 color = texture2D( shadowMap2,vText.xy );\n zdepth = unpackDepth(color);\n value = float(fMyZ < zdepth);\n }\n else if( nPSNum == 2 )\n {\n vec4 color = texture2D( shadowMap3,vText.xy );\n zdepth = unpackDepth(color);\n value = float(fMyZ < zdepth);\n }\n#endif\n#ifdef SHADOWMAP_PCF_NO\n vec4 color;\n if ( nPSNum == 0 )\n {\n color = texture2D( shadowMap1,vText.xy );\n }\n else if( nPSNum == 1 )\n {\n color = texture2D( shadowMap2,vText.xy );\n }\n else if( nPSNum == 2 )\n {\n color = texture2D( shadowMap3,vText.xy );\n }\n zdepth = unpackDepth(color);\n value = float(fMyZ < zdepth);\n#endif\n }\n return value;\n}\nfloat getShadowPSSM2( sampler2D shadowMap1,sampler2D shadowMap2,mat4 lightShadowVP[4],vec4 pssmDistance,vec2 shadowPCFOffset,vec3 worldPos,float posViewZ,float zBias )\n{\n float value = 1.0;\n int nPSNum = int(posViewZ>pssmDistance.x);\n nPSNum += int(posViewZ>pssmDistance.y);\n //真SB,webgl不支持在PS中直接访问数组\n mat4 lightVP;\n if( nPSNum == 0 )\n {\n lightVP = lightShadowVP[1];\n }\n else if( nPSNum == 1 )\n {\n lightVP = lightShadowVP[2];\n }\n vec4 vLightMVPPos = lightVP * vec4(worldPos,1.0);\n //为了效率,在CPU计算/2.0 + 0.5\n //vec3 vText = (vLightMVPPos.xyz / vLightMVPPos.w)/2.0 + 0.5;\n vec3 vText = vLightMVPPos.xyz / vLightMVPPos.w;\n float fMyZ = vText.z - zBias;\n /*\n bvec4 bInFrustumVec = bvec4 ( vText.x >= 0.0, vText.x <= 1.0, vText.y >= 0.0, vText.y <= 1.0 );\n bool bInFrustum = all( bInFrustumVec );\n bvec2 bFrustumTestVec = bvec2( bInFrustum, fMyZ <= 1.0 );\n bool bFrustumTest = all( bFrustumTestVec );\n if ( bFrustumTest ) \n */\n if( fMyZ <= 1.0 )\n {\n float zdepth=0.0;\n#ifdef SHADOWMAP_PCF3\n if ( nPSNum == 0 )\n {\n value = tex2DPCF( shadowMap1, vText.xy,shadowPCFOffset,fMyZ );\n value += tex2DPCF( shadowMap1, vText.xy+vec2(shadowPCFOffset.xy),shadowPCFOffset, fMyZ );\n value += tex2DPCF( shadowMap1, vText.xy+vec2(shadowPCFOffset.x,0),shadowPCFOffset, fMyZ );\n value += tex2DPCF( shadowMap1, vText.xy+vec2(0,shadowPCFOffset.y),shadowPCFOffset, fMyZ );\n value = value/4.0;\n }\n else if( nPSNum == 1 )\n {\n value = tex2DPCF( shadowMap2,vText.xy,shadowPCFOffset,fMyZ);\n }\n#endif\n#ifdef SHADOWMAP_PCF2\n if ( nPSNum == 0 )\n {\n value = tex2DPCF( shadowMap1,vText.xy,shadowPCFOffset,fMyZ);\n }\n else if( nPSNum == 1 )\n {\n value = tex2DPCF( shadowMap2,vText.xy,shadowPCFOffset,fMyZ);\n }\n#endif\n#ifdef SHADOWMAP_PCF1\n if ( nPSNum == 0 )\n {\n value = tex2DPCF( shadowMap1,vText.xy,shadowPCFOffset,fMyZ);\n }\n else if( nPSNum == 1 )\n {\n vec4 color = texture2D( shadowMap2,vText.xy );\n zdepth = unpackDepth(color);\n value = float(fMyZ < zdepth);\n }\n#endif\n#ifdef SHADOWMAP_PCF_NO\n vec4 color;\n if ( nPSNum == 0 )\n {\n color = texture2D( shadowMap1,vText.xy );\n }\n else if( nPSNum == 1 )\n {\n color = texture2D( shadowMap2,vText.xy );\n }\n zdepth = unpackDepth(color);\n value = float(fMyZ < zdepth);\n#endif\n }\n return value;\n}\nfloat getShadowPSSM1( sampler2D shadowMap1,vec4 lightMVPPos,vec4 pssmDistance,vec2 shadowPCFOffset,float posViewZ,float zBias )\n{\n float value = 1.0;\n if( posViewZ < pssmDistance.x )\n {\n vec3 vText = lightMVPPos.xyz / lightMVPPos.w;\n float fMyZ = vText.z - zBias;\n /*\n bvec4 bInFrustumVec = bvec4 ( vText.x >= 0.0, vText.x <= 1.0, vText.y >= 0.0, vText.y <= 1.0 );\n bool bInFrustum = all( bInFrustumVec );\n bvec2 bFrustumTestVec = bvec2( bInFrustum, fMyZ <= 1.0 );\n bool bFrustumTest = all( bFrustumTestVec );\n */\n if ( fMyZ <= 1.0 ) \n {\n float zdepth=0.0;\n#ifdef SHADOWMAP_PCF3\n value = tex2DPCF( shadowMap1, vText.xy,shadowPCFOffset,fMyZ );\n value += tex2DPCF( shadowMap1, vText.xy+vec2(shadowPCFOffset.xy),shadowPCFOffset,fMyZ );\n value += tex2DPCF( shadowMap1, vText.xy+vec2(shadowPCFOffset.x,0),shadowPCFOffset,fMyZ );\n value += tex2DPCF( shadowMap1, vText.xy+vec2(0,shadowPCFOffset.y),shadowPCFOffset,fMyZ );\n value = value/4.0;\n#endif\n#ifdef SHADOWMAP_PCF2 \n value = tex2DPCF( shadowMap1,vText.xy,shadowPCFOffset,fMyZ);\n#endif\n#ifdef SHADOWMAP_PCF1\n value = tex2DPCF( shadowMap1,vText.xy,shadowPCFOffset,fMyZ);\n#endif\n#ifdef SHADOWMAP_PCF_NO \n vec4 color = texture2D( shadowMap1,vText.xy );\n zdepth = unpackDepth(color);\n value = float(fMyZ < zdepth);\n#endif\n }\n }\n return value;\n}");
- Shader3D.addInclude("BRDF.glsl","struct LayaGI\n{\n vec3 diffuse;\n vec3 specular;\n};\n\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)\n{\n float perceptualRoughness = SmoothnessToPerceptualRoughness(smoothness);\n vec3 halfDir = SafeNormalize(viewDir - lightDir);\n \n float nv = abs(dot(normal, viewDir));\n \n float nl = clamp(dot(normal, -lightDir), 0.0, 1.0);\n float nh = clamp(dot(normal, halfDir), 0.0, 1.0);\n float lv = clamp(dot(lightDir, viewDir), 0.0, 1.0);\n float lh = clamp(dot(lightDir, -halfDir), 0.0, 1.0);\n \n float diffuseTerm = DisneyDiffuse(nv, nl, lh, perceptualRoughness) * nl;\n \n float roughness = PerceptualRoughnessToRoughness(perceptualRoughness);\n \n //#if UNITY_BRDF_GGX\n float V = SmithJointGGXVisibilityTerm(nl, nv, roughness);\n float D = GGXTerm(nh, roughness);\n \n float specularTerm = V * D * PI;\n \n specularTerm = sqrt(max(0.0001, specularTerm));\n specularTerm = max(0.0, specularTerm * nl);\n \n float surfaceReduction = 1.0 - 0.28 * roughness * perceptualRoughness;\n float grazingTerm = clamp(smoothness + (1.0 - oneMinusReflectivity), 0.0, 1.0);\n \n vec4 color;\n color.rgb = diffuseColor * (gi.diffuse + lightColor * diffuseTerm) \n + specularTerm * lightColor * FresnelTerm (specularColor, lh)\n + surfaceReduction * gi.specular * FresnelLerp(specularColor, vec3(grazingTerm), nv);\n \n return color;\n}");
- Shader3D.addInclude("PBRUtils.glsl","struct DirectionLight\n{\n vec3 Color;\n vec3 Direction;\n};\n\nstruct PointLight\n{\n vec3 Color;\n vec3 Position;\n float Range;\n};\n\nstruct SpotLight\n{\n vec3 Color;\n vec3 Position;\n vec3 Direction;\n float SpotAngle;\n float Range;\n};\n\nvec3 UnpackScaleNormal(in vec2 uv0)\n{\n #ifdef NORMALTEXTURE\n vec3 normalT;\n vec4 normalMapSample = texture2D(u_NormalTexture, uv0);\n normalT.x = 2.0 * normalMapSample.x - 1.0;\n normalT.y = 1.0 - 2.0 * normalMapSample.y;\n normalT.xy *= u_normalScale;\n normalT.z = sqrt(1.0 - clamp(dot(normalT.xy, normalT.xy), 0.0, 1.0));\n \n vec3 T = normalize(v_Tangent);\n vec3 B = normalize(v_Binormal);\n vec3 N = normalize(v_Normal);\n mat3 TBN = mat3(T, B, N);\n \n vec3 bumpedNormal = TBN * normalize(normalT);\n return bumpedNormal;\n #else\n return normalize(v_Normal);\n #endif\n}\n\nvec4 DielectricSpecularColor = vec4(0.220916301, 0.220916301, 0.220916301, 1.0 - 0.220916301);\n\nfloat PI = 3.14159265359;\n\nvec3 FresnelTerm (in vec3 F0, in float cosA)\n{\n return F0 + (vec3(1.0) - F0) * pow(1.0 - cosA, 5.0);\n}\n\nvec3 FresnelLerp (in vec3 F0, in vec3 F90, float cosA)\n{\n float t = pow(1.0 - cosA, 5.0);\n return mix(F0, F90, t);\n}\n\nfloat PerceptualRoughnessToRoughness(in float perceptualRoughness)\n{\n return perceptualRoughness * perceptualRoughness;\n}\n\nfloat PerceptualRoughnessToSpecularPower(in float perceptualRoughness)\n{\n float m = PerceptualRoughnessToRoughness(perceptualRoughness);\n float sq = max(0.0001, m * m);\n float n = (2.0 / sq) - 2.0;\n n = max(n, 0.0001);\n return n;\n}\n\nfloat RoughnessToPerceptualRoughness(in float roughness)\n{\n return sqrt(roughness);\n}\n\nfloat SmoothnessToRoughness(in float smoothness)\n{\n return (1.0 - smoothness) * (1.0 - smoothness);\n}\n\nfloat SmoothnessToPerceptualRoughness(in float smoothness)\n{\n return (1.0 - smoothness);\n}\n\nvec3 SafeNormalize(in vec3 inVec)\n{\n float dp3 = max(0.001,dot(inVec,inVec));\n return inVec * (1.0 / sqrt(dp3));\n}\n\nfloat DisneyDiffuse(in float NdotV, in float NdotL, in float LdotH, in float perceptualRoughness)\n{\n float fd90 = 0.5 + 2.0 * LdotH * LdotH * perceptualRoughness;\n float lightScatter = (1.0 + (fd90 - 1.0) * pow(1.0 - NdotL,5.0));\n float viewScatter = (1.0 + (fd90 - 1.0) * pow(1.0 - NdotV,5.0));\n\n return lightScatter * viewScatter;\n}\n\nfloat SmithJointGGXVisibilityTerm (float NdotL, float NdotV, float roughness)\n{\n float a = roughness;\n float lambdaV = NdotL * (NdotV * (1.0 - a) + a);\n float lambdaL = NdotV * (NdotL * (1.0 - a) + a);\n\n return 0.5 / (lambdaV + lambdaL + 0.00001);\n}\n\nfloat GGXTerm (float NdotH, float roughness)\n{\n float a2 = roughness * roughness;\n float d = (NdotH * a2 - NdotH) * NdotH + 1.0;\n return 0.31830988618 * a2 / (d * d + 0.0000001);\n}\n\nfloat OneMinusReflectivityFromMetallic(in float metallic)\n{\n float oneMinusDielectricSpec = DielectricSpecularColor.a;\n return oneMinusDielectricSpec - metallic * oneMinusDielectricSpec;\n}\n\nfloat SpecularStrength(vec3 specular)\n{\n //(SHADER_TARGET < 30)return specular.r; \n return max (max (specular.r, specular.g), specular.b);\n}\n\nvec3 DiffuseAndSpecularFromMetallic(in vec3 diffuseColor, in float metallic, out vec3 specularColor, out float oneMinusReflectivity)\n{\n specularColor = mix(DielectricSpecularColor.rgb, diffuseColor, metallic);\n oneMinusReflectivity = OneMinusReflectivityFromMetallic(metallic);\n return diffuseColor * oneMinusReflectivity;\n}\n\nvec3 EnergyConservationBetweenDiffuseAndSpecular(in vec3 diffuseColor, in vec3 specularColor, out float oneMinusReflectivity)\n{\n oneMinusReflectivity = 1.0 - SpecularStrength(specularColor);\n return diffuseColor * oneMinusReflectivity;\n}\n\nvec4 Occlusion(in vec2 uv0){\n #ifdef OCCLUSIONTEXTURE\n vec4 occlusionTextureColor = texture2D(u_OcclusionTexture, uv0);\n float occ = occlusionTextureColor.g;\n float oneMinusT = 1.0 - u_occlusionStrength;\n float lerpOneTo = oneMinusT + occ * u_occlusionStrength;\n return occlusionTextureColor * lerpOneTo;\n #else\n return vec4(1.0);\n #endif\n}\n\nvec2 ParallaxOffset(in vec3 viewDir){\n #ifdef PARALLAXTEXTURE\n float h = texture2D(u_ParallaxTexture, v_Texcoord0).g;\n h = h * u_parallaxScale - u_parallaxScale / 2.0;\n vec3 v = viewDir;\n v.z += 0.42;\n vec2 offset = h * (v.xy / v.z);\n return v_Texcoord0 + offset;\n #else\n return v_Texcoord0;\n #endif\n}\n\nvec3 ReflectCubeMap(in vec3 viewDir, in vec3 normal){\n #ifdef REFLECTMAP\n vec3 incident = -viewDir;\n vec3 reflectionVector = reflect(incident, normal);\n vec3 reflectionColor = textureCube(u_ReflectTexture, vec3(-reflectionVector.x, reflectionVector.yz)).rgb;\n return reflectionColor * u_ReflectIntensity;\n #else\n return vec3(0.0);\n #endif\n}\n\nfloat LayaAttenuation(in vec3 L, in float invLightRadius)\n{\n float fRatio = clamp(length(L) * invLightRadius, 0.0, 1.0);\n fRatio *= fRatio;\n return 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\n}\n\nvec3 LayaPreMultiplyAlpha(vec3 diffColor, float alpha, float oneMinusReflectivity, out float outModifiedAlpha)\n{\n #ifdef ALPHAPREMULTIPLY\n diffColor *= alpha;\n outModifiedAlpha = 1.0 - oneMinusReflectivity + alpha * oneMinusReflectivity;\n #else\n outModifiedAlpha = alpha;\n #endif\n return diffColor;\n}\n\n");
- Shader3D.addInclude("PBRStandardLighting.glsl","#include \"PBRUtils.glsl\"\n#include \"BRDF.glsl\"\n\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)\n{\n float oneMinusReflectivity;\n vec3 diffuseColor;\n vec3 specularColor;\n float alpha;\n \n diffuseColor = DiffuseAndSpecularFromMetallic (albedoColor.rgb, metallic, specularColor, oneMinusReflectivity);\n \n diffuseColor = LayaPreMultiplyAlpha(diffuseColor, albedoColor.a, oneMinusReflectivity, alpha);\n \n vec4 color = LayaAirBRDF(diffuseColor, specularColor, oneMinusReflectivity, smoothness, normal, viewDir, lightDir, lightColor, gi);\n color.a = alpha;\n return color;\n}\n\nvec4 PBRStandardDiectionLight (in vec4 albedoColor, in float metallic, in float smoothness, in vec3 normal, in vec3 viewDir, in DirectionLight light, in LayaGI gi)\n{\n vec3 lightVec = normalize(light.Direction);\n return PBRStandardLight(albedoColor, metallic, smoothness, normal, viewDir, lightVec, light.Color, gi);\n}\n\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)\n{\n vec3 lightCoord = (u_PointLightMatrix * vec4(pos, 1.0)).xyz;\n float distance = dot(lightCoord, lightCoord);\n float attenuate = texture2D(u_RangeTexture, vec2(distance)).w;\n vec3 lightVec = normalize(pos - light.Position);\n return PBRStandardLight(albedoColor, metallic, smoothness, normal, viewDir, lightVec, light.Color, gi) * attenuate;\n}\n\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)\n{\n vec3 lightVec = pos - light.Position;\n vec3 normalLightVec = normalize(lightVec);\n vec2 cosAngles = cos(vec2(light.SpotAngle, light.SpotAngle*0.5) * 0.5);//ConeAttenuation\n float dl = dot(normalize(light.Direction), normalLightVec);\n dl *= smoothstep(cosAngles[0], cosAngles[1], dl);\n float attenuate = LayaAttenuation(lightVec, 1.0/light.Range) * dl;\n return PBRStandardLight(albedoColor, metallic, smoothness, normal, viewDir, lightVec, light.Color, gi) * attenuate;\n}\n\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)\n//{\n// vec4 lightCoord = u_SpotLightMatrix * vec4(pos, 1.0);\n// \n// float distance = dot(lightCoord, lightCoord);\n// float attenuate = (lightCoord.z < 0.0) ? texture2D(u_RangeTexture, vec2(distance)).w : 0.0;\n// //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;\n// //vec2 _uv = vec2(pos.x * 180.0/(2.0 * pos.z) + 0.5, pos.y * 180.0/(2.0 * pos.z) + 0.5);\n// vec3 lightVec = normalize(pos - light.Position);\n// return PBRStandardLight(albedoColor, metallic, smoothness, normal, viewDir, lightVec, light.Color, gi) * attenuate;\n//}\n\nvec2 MetallicGloss(in float albedoTextureAlpha, in vec2 uv0)\n{\n vec2 mg;\n \n #ifdef METALLICGLOSSTEXTURE\n vec4 metallicGlossTextureColor = texture2D(u_MetallicGlossTexture, uv0);\n #ifdef SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA\n mg.r = metallicGlossTextureColor.r;\n mg.g = albedoTextureAlpha;\n #else\n mg = metallicGlossTextureColor.ra;\n #endif\n mg.g *= u_smoothnessScale;\n #else\n mg.r = u_metallic;\n #ifdef SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA\n mg.g = albedoTextureAlpha * u_smoothnessScale;\n #else\n mg.g = u_smoothness;\n #endif\n #endif\n \n return mg;\n}\n\n");
- Shader3D.addInclude("PBRSpecularLighting.glsl","#include \"PBRUtils.glsl\"\n#include \"BRDF.glsl\"\n\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)\n{\n float oneMinusReflectivity;\n vec3 diffuseColor;\n float alpha;\n \n diffuseColor = EnergyConservationBetweenDiffuseAndSpecular (albedoColor.rgb, specularColor, oneMinusReflectivity);\n \n diffuseColor = LayaPreMultiplyAlpha(diffuseColor, albedoColor.a, oneMinusReflectivity, alpha);\n \n vec4 color = LayaAirBRDF(diffuseColor, specularColor, oneMinusReflectivity, smoothness, normal, viewDir, lightDir, lightColor, gi);\n color.a = alpha;\n return color;\n}\n\nvec4 PBRSpecularDiectionLight (in vec4 albedoColor, in vec3 specularColor, in float smoothness, in vec3 normal, in vec3 viewDir, in DirectionLight light, in LayaGI gi)\n{\n vec3 lightVec = normalize(light.Direction);\n return PBRSpecularLight(albedoColor, specularColor, smoothness, normal, viewDir, lightVec, light.Color, gi);\n}\n\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)\n{\n vec3 lightCoord = (u_PointLightMatrix * vec4(pos, 1.0)).xyz;\n float distance = dot(lightCoord, lightCoord);\n float attenuate = texture2D(u_RangeTexture, vec2(distance)).w;\n vec3 lightVec = normalize(pos - light.Position);\n return PBRSpecularLight(albedoColor, specularColor, smoothness, normal, viewDir, lightVec, light.Color, gi) * attenuate;\n}\n\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)\n{\n vec3 lightVec = pos - light.Position;\n vec3 normalLightVec = normalize(lightVec);\n vec2 cosAngles = cos(vec2(light.SpotAngle, light.SpotAngle*0.5) * 0.5);//ConeAttenuation\n float dl = dot(normalize(light.Direction), normalLightVec);\n dl *= smoothstep(cosAngles[0], cosAngles[1], dl);\n float attenuate = LayaAttenuation(lightVec, 1.0/light.Range) * dl;\n return PBRSpecularLight(albedoColor, specularColor, smoothness, normal, viewDir, lightVec, light.Color, gi) * attenuate;\n}\n\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)\n//{\n// vec4 lightCoord = u_SpotLightMatrix * vec4(pos, 1.0);\n// \n// float distance = dot(lightCoord, lightCoord);\n// float attenuate = (lightCoord.z < 0.0) ? texture2D(u_RangeTexture, vec2(distance)).w : 0.0;\n// //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;\n// //vec2 _uv = vec2(pos.x * 180.0/(2.0 * pos.z) + 0.5, pos.y * 180.0/(2.0 * pos.z) + 0.5);\n// vec3 lightVec = normalize(pos - light.Position);\n// return PBRStandardLight(albedoColor, metallic, smoothness, normal, viewDir, lightVec, light.Color, gi) * attenuate;\n//}\n\nvec4 SpecularGloss(float albedoTextureAlpha, in vec2 uv0)\n{\n vec4 sg;\n \n #ifdef SPECULARTEXTURE\n vec4 specularTextureColor = texture2D(u_SpecularTexture, uv0);\n #ifdef SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA\n sg.rgb = specularTextureColor.rgb;\n sg.a = albedoTextureAlpha;\n #else\n sg = specularTextureColor;\n #endif\n sg.a *= u_smoothnessScale;\n #else\n sg.rgb = u_SpecularColor.rgb;\n #ifdef SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA\n sg.a = albedoTextureAlpha * u_smoothnessScale;\n #else\n sg.a = u_smoothness;\n #endif\n #endif\n \n return sg;\n}\n\n");
- Shader3D.addInclude("Colors.glsl","#include \"StdLib.glsl\";\n\n#define EPSILON 1.0e-4\n\n// Quadratic color thresholding\n// curve = (threshold - knee, knee * 2, 0.25 / knee)\nmediump vec4 quadraticThreshold(mediump vec4 color, mediump float threshold, mediump vec3 curve) {\n // Pixel brightness\n mediump float br = max3(color.r, color.g, color.b);\n\n // Under-threshold part: quadratic curve\n mediump float rq = clamp(br - curve.x, 0.0, curve.y);\n rq = curve.z * rq * rq;\n\n // Combine and apply the brightness response curve.\n color *= max(rq, br - threshold) / max(br, EPSILON);\n\n return color;\n}\n\n//\n// sRGB transfer functions\n// Fast path ref: http://chilliant.blogspot.com.au/2012/08/srgb-approximations-for-hlsl.html?m=1\n//\nmediump vec3 SRGBToLinear(mediump vec3 c) {\n #ifdef USE_VERY_FAST_SRGB\n return c * c;\n #elif defined(USE_FAST_SRGB)\n return c * (c * (c * 0.305306011 + 0.682171111) + 0.012522878);\n #else\n mediump vec3 linearRGBLo = c / 12.92;\n mediump vec3 power=vec3(2.4, 2.4, 2.4);\n mediump vec3 linearRGBHi = positivePow((c + 0.055) / 1.055, power);\n mediump 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);\n return linearRGB;\n #endif\n}\n\nmediump vec3 LinearToSRGB(mediump vec3 c) {\n #ifdef USE_VERY_FAST_SRGB\n return sqrt(c);\n #elif defined(USE_FAST_SRGB)\n return max(1.055 * PositivePow(c, 0.416666667) - 0.055, 0.0);\n #else\n mediump vec3 sRGBLo = c * 12.92;\n mediump vec3 power=vec3(1.0 / 2.4, 1.0 / 2.4, 1.0 / 2.4);\n mediump vec3 sRGBHi = (positivePow(c, power) * 1.055) - 0.055;\n mediump 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);\n return sRGB;\n #endif\n}");
- Shader3D.addInclude("Sampling.glsl","// Better, temporally stable box filtering\n// [Jimenez14] http://goo.gl/eomGso\n// . . . . . . .\n// . A . B . C .\n// . . D . E . .\n// . F . G . H .\n// . . I . J . .\n// . K . L . M .\n// . . . . . . .\nmediump vec4 downsampleBox13Tap(sampler2D tex, vec2 uv, vec2 texelSize)\n{\n mediump vec4 A = texture2D(tex, uv + texelSize * vec2(-1.0, -1.0));\n mediump vec4 B = texture2D(tex, uv + texelSize * vec2( 0.0, -1.0));\n mediump vec4 C = texture2D(tex, uv + texelSize * vec2( 1.0, -1.0));\n mediump vec4 D = texture2D(tex, uv + texelSize * vec2(-0.5, -0.5));\n mediump vec4 E = texture2D(tex, uv + texelSize * vec2( 0.5, -0.5));\n mediump vec4 F = texture2D(tex, uv + texelSize * vec2(-1.0, 0.0));\n mediump vec4 G = texture2D(tex, uv);\n mediump vec4 H = texture2D(tex, uv + texelSize * vec2( 1.0, 0.0));\n mediump vec4 I = texture2D(tex, uv + texelSize * vec2(-0.5, 0.5));\n mediump vec4 J = texture2D(tex, uv + texelSize * vec2( 0.5, 0.5));\n mediump vec4 K = texture2D(tex, uv + texelSize * vec2(-1.0, 1.0));\n mediump vec4 L = texture2D(tex, uv + texelSize * vec2( 0.0, 1.0));\n mediump vec4 M = texture2D(tex, uv + texelSize * vec2( 1.0, 1.0));\n\n mediump vec2 scale= vec2(0.5, 0.125);\n mediump vec2 div = (1.0 / 4.0) * scale;\n\n mediump vec4 o = (D + E + I + J) * div.x;\n o += (A + B + G + F) * div.y;\n o += (B + C + H + G) * div.y;\n o += (F + G + L + K) * div.y;\n o += (G + H + M + L) * div.y;\n\n return o;\n}\n\n// Standard box filtering\nmediump vec4 downsampleBox4Tap(sampler2D tex, vec2 uv, vec2 texelSize)\n{\n vec4 d = texelSize.xyxy * vec4(-1.0, -1.0, 1.0, 1.0);\n\n mediump vec4 s = texture2D(tex, uv + d.xy);\n s += texture2D(tex, uv + d.zy);\n s += texture2D(tex, uv + d.xw);\n s += texture2D(tex, uv + d.zw);\n\n return s * (1.0 / 4.0);\n}\n\n// 9-tap bilinear upsampler (tent filter)\n// . . . . . . .\n// . 1 . 2 . 1 .\n// . . . . . . .\n// . 2 . 4 . 2 .\n// . . . . . . .\n// . 1 . 2 . 1 .\n// . . . . . . .\nmediump vec4 upsampleTent(sampler2D tex, vec2 uv, vec2 texelSize, vec4 sampleScale)\n{\n vec4 d = texelSize.xyxy * vec4(1.0, 1.0, -1.0, 0.0) * sampleScale;\n\n mediump vec4 s = texture2D(tex, uv - d.xy);\n s += texture2D(tex, uv - d.wy) * 2.0;\n s += texture2D(tex, uv - d.zy);\n\n s += texture2D(tex, uv + d.zw) * 2.0;\n s += texture2D(tex, uv) * 4.0;\n s += texture2D(tex, uv + d.xw) * 2.0;\n\n s += texture2D(tex, uv + d.zy);\n s += texture2D(tex, uv + d.wy) * 2.0;\n s += texture2D(tex, uv + d.xy);\n\n return s * (1.0 / 16.0);\n}\n\n// Standard box filtering\nmediump vec4 upsampleBox(sampler2D tex, vec2 uv, vec2 texelSize, vec4 sampleScale)\n{\n vec4 d = texelSize.xyxy * vec4(-1.0, -1.0, 1.0, 1.0) * (sampleScale * 0.5);\n\n mediump vec4 s = texture2D(tex, uv + d.xy);\n s += texture2D(tex, uv + d.zy);\n s += texture2D(tex, uv + d.xw);\n s += texture2D(tex, uv + d.zw);\n\n return s * (1.0 / 4.0);\n}");
- Shader3D.addInclude("StdLib.glsl","#define HALF_MAX 65504.0 // (2 - 2^-10) * 2^15\n\n#define FLT_EPSILON 1.192092896e-07 // Smallest positive number, such that 1.0 + FLT_EPSILON != 1.0\n\nmediump vec4 safeHDR(mediump vec4 c)\n{\n return min(c, HALF_MAX);\n}\n\nfloat max3(float a, float b, float c)\n{\n return max(max(a, b), c);\n}\n\nvec3 positivePow(vec3 base, vec3 power)\n{\n return pow(max(abs(base), vec3(FLT_EPSILON, FLT_EPSILON, FLT_EPSILON)), power);\n}");
- var vs,ps;
- var attributeMap={
- 'a_Position':/*laya.d3.graphics.Vertex.VertexMesh.MESH_POSITION0*/0,
- 'a_Color':/*laya.d3.graphics.Vertex.VertexMesh.MESH_COLOR0*/1,
- 'a_Normal':/*laya.d3.graphics.Vertex.VertexMesh.MESH_NORMAL0*/3,
- 'a_Texcoord0':/*laya.d3.graphics.Vertex.VertexMesh.MESH_TEXTURECOORDINATE0*/2,
- 'a_Texcoord1':/*laya.d3.graphics.Vertex.VertexMesh.MESH_TEXTURECOORDINATE1*/7,
- 'a_BoneWeights':/*laya.d3.graphics.Vertex.VertexMesh.MESH_BLENDWEIGHT0*/6,
- 'a_BoneIndices':/*laya.d3.graphics.Vertex.VertexMesh.MESH_BLENDINDICES0*/5,
- 'a_Tangent0':/*laya.d3.graphics.Vertex.VertexMesh.MESH_TANGENT0*/4,
- 'a_MvpMatrix':/*laya.d3.graphics.Vertex.VertexMesh.MESH_MVPMATRIX_ROW0*/12,
- 'a_WorldMat':/*laya.d3.graphics.Vertex.VertexMesh.MESH_WORLDMATRIX_ROW0*/8
- };
- var uniformMap={
- 'u_Bones':/*laya.d3.shader.Shader3D.PERIOD_CUSTOM*/0,
- 'u_DiffuseTexture':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_SpecularTexture':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_NormalTexture':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_AlphaTestValue':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_DiffuseColor':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_MaterialSpecular':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_Shininess':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_TilingOffset':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_WorldMat':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_MvpMatrix':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_LightmapScaleOffset':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_LightMap':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_CameraPos':/*laya.d3.shader.Shader3D.PERIOD_CAMERA*/3,
- 'u_ReflectTexture':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_ReflectIntensity':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_FogStart':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_FogRange':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_FogColor':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_DirectionLight.Color':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_DirectionLight.Direction':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_PointLight.Position':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_PointLight.Range':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_PointLight.Color':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_SpotLight.Position':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_SpotLight.Direction':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_SpotLight.Range':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_SpotLight.Spot':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_SpotLight.Color':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_AmbientColor':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_shadowMap1':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_shadowMap2':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_shadowMap3':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_shadowPSSMDistance':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_lightShadowVP':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_shadowPCFoffset':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4
- };
- var stateMap={
- 's_Cull':/*laya.d3.shader.Shader3D.RENDER_STATE_CULL*/0,
- 's_Blend':/*laya.d3.shader.Shader3D.RENDER_STATE_BLEND*/1,
- 's_BlendSrc':/*laya.d3.shader.Shader3D.RENDER_STATE_BLEND_SRC*/2,
- 's_BlendDst':/*laya.d3.shader.Shader3D.RENDER_STATE_BLEND_DST*/3,
- 's_DepthTest':/*laya.d3.shader.Shader3D.RENDER_STATE_DEPTH_TEST*/12,
- 's_DepthWrite':/*laya.d3.shader.Shader3D.RENDER_STATE_DEPTH_WRITE*/13
- }
- vs="#include \"Lighting.glsl\";\n\nattribute vec4 a_Position;\n\n#ifdef GPU_INSTANCE\n attribute mat4 a_MvpMatrix;\n#else\n uniform mat4 u_MvpMatrix;\n#endif\n\n\n#if defined(DIFFUSEMAP)||((defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT))&&(defined(SPECULARMAP)||defined(NORMALMAP)))||(defined(LIGHTMAP)&&defined(UV))\n attribute vec2 a_Texcoord0;\n varying vec2 v_Texcoord0;\n#endif\n\n#if defined(LIGHTMAP)&&defined(UV1)\n attribute vec2 a_Texcoord1;\n#endif\n\n#ifdef LIGHTMAP\n uniform vec4 u_LightmapScaleOffset;\n varying vec2 v_LightMapUV;\n#endif\n\n#ifdef COLOR\n attribute vec4 a_Color;\n varying vec4 v_Color;\n#endif\n\n#ifdef BONE\n const int c_MaxBoneCount = 24;\n attribute vec4 a_BoneIndices;\n attribute vec4 a_BoneWeights;\n uniform mat4 u_Bones[c_MaxBoneCount];\n#endif\n\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\n attribute vec3 a_Normal;\n varying vec3 v_Normal; \n uniform vec3 u_CameraPos;\n varying vec3 v_ViewDir; \n#endif\n\n#if (defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT))&&defined(NORMALMAP)\n attribute vec4 a_Tangent0;\n varying vec3 v_Tangent;\n varying vec3 v_Binormal;\n#endif\n\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(RECEIVESHADOW)\n #ifdef GPU_INSTANCE\n attribute mat4 a_WorldMat;\n #else\n uniform mat4 u_WorldMat;\n #endif\n varying vec3 v_PositionWorld;\n#endif\n\nvarying float v_posViewZ;\n#ifdef RECEIVESHADOW\n #ifdef SHADOWMAP_PSSM1 \n varying vec4 v_lightMVPPos;\n uniform mat4 u_lightShadowVP[4];\n #endif\n#endif\n\n#ifdef TILINGOFFSET\n uniform vec4 u_TilingOffset;\n#endif\n\nvoid main_castShadow()\n{\n vec4 position;\n #ifdef BONE\n mat4 skinTransform = u_Bones[int(a_BoneIndices.x)] * a_BoneWeights.x;\n skinTransform += u_Bones[int(a_BoneIndices.y)] * a_BoneWeights.y;\n skinTransform += u_Bones[int(a_BoneIndices.z)] * a_BoneWeights.z;\n skinTransform += u_Bones[int(a_BoneIndices.w)] * a_BoneWeights.w;\n position=skinTransform*a_Position;\n #else\n position=a_Position;\n #endif\n #ifdef GPU_INSTANCE\n gl_Position = a_MvpMatrix * position;\n #else\n gl_Position = u_MvpMatrix * position;\n #endif\n \n //TODO没考虑UV动画呢\n #if defined(DIFFUSEMAP)&&defined(ALPHATEST)\n v_Texcoord0=a_Texcoord0;\n #endif\n gl_Position=remapGLPositionZ(gl_Position);\n v_posViewZ = gl_Position.z;\n}\n\nvoid main_normal()\n{\n vec4 position;\n #ifdef BONE\n mat4 skinTransform = u_Bones[int(a_BoneIndices.x)] * a_BoneWeights.x;\n skinTransform += u_Bones[int(a_BoneIndices.y)] * a_BoneWeights.y;\n skinTransform += u_Bones[int(a_BoneIndices.z)] * a_BoneWeights.z;\n skinTransform += u_Bones[int(a_BoneIndices.w)] * a_BoneWeights.w;\n position=skinTransform*a_Position;\n #else\n position=a_Position;\n #endif\n #ifdef GPU_INSTANCE\n gl_Position = a_MvpMatrix * position;\n #else\n gl_Position = u_MvpMatrix * position;\n #endif\n \n #if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(RECEIVESHADOW)\n mat4 worldMat;\n #ifdef GPU_INSTANCE\n worldMat = a_WorldMat;\n #else\n worldMat = u_WorldMat;\n #endif\n #endif\n \n\n #if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\n mat3 worldInvMat;\n #ifdef BONE\n worldInvMat=inverse(mat3(worldMat*skinTransform));\n #else\n worldInvMat=inverse(mat3(worldMat));\n #endif \n v_Normal=a_Normal*worldInvMat;\n #if (defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT))&&defined(NORMALMAP)\n v_Tangent=a_Tangent0.xyz*worldInvMat;\n v_Binormal=cross(v_Normal,v_Tangent)*a_Tangent0.w;\n #endif\n #endif\n\n #if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(RECEIVESHADOW)\n v_PositionWorld=(worldMat*position).xyz;\n #endif\n \n #if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\n v_ViewDir=u_CameraPos-v_PositionWorld;\n #endif\n\n #if defined(DIFFUSEMAP)||((defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT))&&(defined(SPECULARMAP)||defined(NORMALMAP)))\n #ifdef TILINGOFFSET\n v_Texcoord0=TransformUV(a_Texcoord0,u_TilingOffset);\n #else\n v_Texcoord0=a_Texcoord0;\n #endif\n #endif\n\n #ifdef LIGHTMAP\n #ifdef SCALEOFFSETLIGHTINGMAPUV\n #ifdef UV1\n v_LightMapUV=vec2(a_Texcoord1.x,1.0-a_Texcoord1.y)*u_LightmapScaleOffset.xy+u_LightmapScaleOffset.zw;\n #else\n v_LightMapUV=vec2(a_Texcoord0.x,1.0-a_Texcoord0.y)*u_LightmapScaleOffset.xy+u_LightmapScaleOffset.zw;\n #endif \n v_LightMapUV.y=1.0-v_LightMapUV.y;\n #else\n #ifdef UV1\n v_LightMapUV=a_Texcoord1;\n #else\n v_LightMapUV=a_Texcoord0;\n #endif \n #endif \n #endif\n\n #if defined(COLOR)&&defined(ENABLEVERTEXCOLOR)\n v_Color=a_Color;\n #endif\n\n #ifdef RECEIVESHADOW\n v_posViewZ = gl_Position.w;\n #ifdef SHADOWMAP_PSSM1 \n v_lightMVPPos = u_lightShadowVP[0] * vec4(v_PositionWorld,1.0);\n #endif\n #endif\n gl_Position=remapGLPositionZ(gl_Position);\n}\n\nvoid main()\n{\n #ifdef CASTSHADOW\n main_castShadow();\n #else\n main_normal();\n #endif\n}";
- ps="#ifdef HIGHPRECISION\n precision highp float;\n#else\n precision mediump float;\n#endif\n\n#include \"Lighting.glsl\";\n\nuniform vec4 u_DiffuseColor;\n\n#if defined(COLOR)&&defined(ENABLEVERTEXCOLOR)\n varying vec4 v_Color;\n#endif\n\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\n varying vec3 v_ViewDir; \n#endif\n\n#ifdef ALPHATEST\n uniform float u_AlphaTestValue;\n#endif\n\n#ifdef DIFFUSEMAP\n uniform sampler2D u_DiffuseTexture;\n#endif\n\n\n\n#if defined(DIFFUSEMAP)||((defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT))&&(defined(SPECULARMAP)||defined(NORMALMAP)))\n varying vec2 v_Texcoord0;\n#endif\n\n#ifdef LIGHTMAP\n varying vec2 v_LightMapUV;\n uniform sampler2D u_LightMap;\n#endif\n\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\n uniform vec3 u_MaterialSpecular;\n uniform float u_Shininess;\n #ifdef SPECULARMAP \n uniform sampler2D u_SpecularTexture;\n #endif\n#endif\n\n#ifdef FOG\n uniform float u_FogStart;\n uniform float u_FogRange;\n uniform vec3 u_FogColor;\n#endif\n\n\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\n varying vec3 v_Normal;\n#endif\n\n#if (defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT))&&defined(NORMALMAP)\n uniform sampler2D u_NormalTexture;\n varying vec3 v_Tangent;\n varying vec3 v_Binormal;\n#endif\n\n#ifdef DIRECTIONLIGHT\n uniform DirectionLight u_DirectionLight;\n#endif\n\n#ifdef POINTLIGHT\n uniform PointLight u_PointLight;\n#endif\n\n#ifdef SPOTLIGHT\n uniform SpotLight u_SpotLight;\n#endif\n\nuniform vec3 u_AmbientColor;\n\n\n#if defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(RECEIVESHADOW)\n varying vec3 v_PositionWorld;\n#endif\n\n#include \"ShadowHelper.glsl\"\nvarying float v_posViewZ;\n#ifdef RECEIVESHADOW\n #if defined(SHADOWMAP_PSSM2)||defined(SHADOWMAP_PSSM3)\n uniform mat4 u_lightShadowVP[4];\n #endif\n #ifdef SHADOWMAP_PSSM1 \n varying vec4 v_lightMVPPos;\n #endif\n#endif\n\nvoid main_castShadow()\n{\n //gl_FragColor=vec4(v_posViewZ,0.0,0.0,1.0);\n gl_FragColor=packDepth(v_posViewZ);\n #if defined(DIFFUSEMAP)&&defined(ALPHATEST)\n float alpha = texture2D(u_DiffuseTexture,v_Texcoord0).w;\n if( alpha < u_AlphaTestValue )\n {\n discard;\n }\n #endif\n}\nvoid main_normal()\n{\n vec3 globalDiffuse=u_AmbientColor;\n #ifdef LIGHTMAP \n globalDiffuse += DecodeLightmap(texture2D(u_LightMap, v_LightMapUV));\n #endif\n \n #if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\n vec3 normal;\n #if (defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT))&&defined(NORMALMAP)\n vec3 normalMapSample = texture2D(u_NormalTexture, v_Texcoord0).rgb;\n normal = normalize(NormalSampleToWorldSpace(normalMapSample, v_Normal, v_Tangent,v_Binormal));\n #else\n normal = normalize(v_Normal);\n #endif\n vec3 viewDir= normalize(v_ViewDir);\n #endif\n \n vec4 mainColor=u_DiffuseColor;\n #ifdef DIFFUSEMAP\n vec4 difTexColor=texture2D(u_DiffuseTexture, v_Texcoord0);\n mainColor=mainColor*difTexColor;\n #endif \n #if defined(COLOR)&&defined(ENABLEVERTEXCOLOR)\n mainColor=mainColor*v_Color;\n #endif \n \n #ifdef ALPHATEST\n if(mainColor.a<u_AlphaTestValue)\n discard;\n #endif\n \n \n vec3 diffuse = vec3(0.0);\n vec3 specular= vec3(0.0);\n #if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\n vec3 dif,spe;\n #ifdef SPECULARMAP\n vec3 gloss=texture2D(u_SpecularTexture, v_Texcoord0).rgb;\n #else\n #ifdef DIFFUSEMAP\n vec3 gloss=vec3(difTexColor.a);\n #else\n vec3 gloss=vec3(1.0);\n #endif\n #endif\n #endif\n\n \n #ifdef DIRECTIONLIGHT\n LayaAirBlinnPhongDiectionLight(u_MaterialSpecular,u_Shininess,normal,gloss,viewDir,u_DirectionLight,dif,spe);\n diffuse+=dif;\n specular+=spe;\n #endif\n \n #ifdef POINTLIGHT\n LayaAirBlinnPhongPointLight(v_PositionWorld,u_MaterialSpecular,u_Shininess,normal,gloss,viewDir,u_PointLight,dif,spe);\n diffuse+=dif;\n specular+=spe;\n #endif\n\n #ifdef SPOTLIGHT\n LayaAirBlinnPhongSpotLight(v_PositionWorld,u_MaterialSpecular,u_Shininess,normal,gloss,viewDir,u_SpotLight,dif,spe);\n diffuse+=dif;\n specular+=spe;\n #endif\n\n #ifdef RECEIVESHADOW\n float shadowValue = 1.0;\n #ifdef SHADOWMAP_PSSM3\n shadowValue = getShadowPSSM3(u_shadowMap1,u_shadowMap2,u_shadowMap3,u_lightShadowVP,u_shadowPSSMDistance,u_shadowPCFoffset,v_PositionWorld,v_posViewZ,0.001);\n #endif\n #ifdef SHADOWMAP_PSSM2\n shadowValue = getShadowPSSM2(u_shadowMap1,u_shadowMap2,u_lightShadowVP,u_shadowPSSMDistance,u_shadowPCFoffset,v_PositionWorld,v_posViewZ,0.001);\n #endif \n #ifdef SHADOWMAP_PSSM1\n shadowValue = getShadowPSSM1(u_shadowMap1,v_lightMVPPos,u_shadowPSSMDistance,u_shadowPCFoffset,v_posViewZ,0.001);\n #endif\n gl_FragColor =vec4(mainColor.rgb*(globalDiffuse + diffuse*shadowValue),mainColor.a);\n #else\n gl_FragColor =vec4(mainColor.rgb*(globalDiffuse + diffuse),mainColor.a);\n #endif\n\n #if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\n #ifdef RECEIVESHADOW\n gl_FragColor.rgb+=specular*shadowValue;\n #else\n gl_FragColor.rgb+=specular;\n #endif\n #endif\n \n #ifdef FOG\n float lerpFact=clamp((1.0/gl_FragCoord.w-u_FogStart)/u_FogRange,0.0,1.0);\n gl_FragColor.rgb=mix(gl_FragColor.rgb,u_FogColor,lerpFact);\n #endif\n}\n\nvoid main()\n{\n #ifdef CASTSHADOW \n main_castShadow();\n #else\n main_normal();\n #endif \n}\n\n";
- var shader=Shader3D.add("BLINNPHONG",true);
- var subShader=new SubShader(attributeMap,uniformMap,SkinnedMeshSprite3D.shaderDefines,BlinnPhongMaterial.shaderDefines);
- shader.addSubShader(subShader);
- subShader.addShaderPass(vs,ps,stateMap);
- attributeMap={
- 'a_Position':/*laya.d3.graphics.Vertex.VertexMesh.MESH_POSITION0*/0,
- 'a_Color':/*laya.d3.graphics.Vertex.VertexMesh.MESH_COLOR0*/1};
- uniformMap={
- 'u_MvpMatrix':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_Color':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1
- };
- stateMap={
- 's_Cull':/*laya.d3.shader.Shader3D.RENDER_STATE_CULL*/0,
- 's_Blend':/*laya.d3.shader.Shader3D.RENDER_STATE_BLEND*/1,
- 's_BlendSrc':/*laya.d3.shader.Shader3D.RENDER_STATE_BLEND_SRC*/2,
- 's_BlendDst':/*laya.d3.shader.Shader3D.RENDER_STATE_BLEND_DST*/3,
- 's_DepthTest':/*laya.d3.shader.Shader3D.RENDER_STATE_DEPTH_TEST*/12,
- 's_DepthWrite':/*laya.d3.shader.Shader3D.RENDER_STATE_DEPTH_WRITE*/13
- }
- vs="#include \"Lighting.glsl\";\n\nattribute vec4 a_Position;\nuniform mat4 u_MvpMatrix;\nuniform vec4 u_Color;\nattribute vec4 a_Color;\nvarying vec4 v_Color;\n\n\nvoid main()\n{\n gl_Position = u_MvpMatrix * a_Position;\n v_Color=a_Color*u_Color;\n gl_Position=remapGLPositionZ(gl_Position);\n}";
- ps="#ifdef HIGHPRECISION\nprecision highp float;\n#else\nprecision mediump float;\n#endif\n\nvarying vec4 v_Color;\nuniform vec4 u_Color;\n\nvoid main()\n{\n gl_FragColor = v_Color * u_Color; \n}\n\n";
- shader=Shader3D.add("LineShader");
- subShader=new SubShader(attributeMap,uniformMap);
- shader.addSubShader(subShader);
- subShader.addShaderPass(vs,ps,stateMap);
- attributeMap={
- 'a_Position':/*laya.d3.graphics.Vertex.VertexMesh.MESH_POSITION0*/0,
- 'a_Normal':/*laya.d3.graphics.Vertex.VertexMesh.MESH_NORMAL0*/3,
- 'a_Tangent0':/*laya.d3.graphics.Vertex.VertexMesh.MESH_TANGENT0*/4,
- 'a_Texcoord0':/*laya.d3.graphics.Vertex.VertexMesh.MESH_TEXTURECOORDINATE0*/2,
- 'a_BoneWeights':/*laya.d3.graphics.Vertex.VertexMesh.MESH_BLENDWEIGHT0*/6,
- 'a_BoneIndices':/*laya.d3.graphics.Vertex.VertexMesh.MESH_BLENDINDICES0*/5,
- 'a_MvpMatrix':/*laya.d3.graphics.Vertex.VertexMesh.MESH_MVPMATRIX_ROW0*/12,
- 'a_WorldMat':/*laya.d3.graphics.Vertex.VertexMesh.MESH_WORLDMATRIX_ROW0*/8
- };
- uniformMap={
- 'u_Bones':/*laya.d3.shader.Shader3D.PERIOD_CUSTOM*/0,
- 'u_MvpMatrix':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_WorldMat':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_CameraPos':/*laya.d3.shader.Shader3D.PERIOD_CAMERA*/3,
- 'u_AlphaTestValue':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_AlbedoColor':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_EmissionColor':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_AlbedoTexture':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_NormalTexture':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_ParallaxTexture':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_MetallicGlossTexture':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_OcclusionTexture':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_EmissionTexture':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_metallic':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_smoothness':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_smoothnessScale':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_occlusionStrength':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_normalScale':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_parallaxScale':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_TilingOffset':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_DirectionLight.Direction':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_DirectionLight.Color':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_PointLightMatrix':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_PointLight.Position':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_PointLight.Range':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_PointLight.Color':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_SpotLight.Position':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_SpotLight.Direction':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_SpotLight.Range':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_SpotLight.SpotAngle':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_SpotLight.Color':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_RangeTexture':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_ReflectTexture':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_ReflectIntensity':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_AmbientColor':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_shadowMap1':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_shadowMap2':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_shadowMap3':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_shadowPSSMDistance':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_lightShadowVP':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_shadowPCFoffset':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_FogStart':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_FogRange':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_FogColor':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4
- };
- stateMap={
- 's_Cull':/*laya.d3.shader.Shader3D.RENDER_STATE_CULL*/0,
- 's_Blend':/*laya.d3.shader.Shader3D.RENDER_STATE_BLEND*/1,
- 's_BlendSrc':/*laya.d3.shader.Shader3D.RENDER_STATE_BLEND_SRC*/2,
- 's_BlendDst':/*laya.d3.shader.Shader3D.RENDER_STATE_BLEND_DST*/3,
- 's_DepthTest':/*laya.d3.shader.Shader3D.RENDER_STATE_DEPTH_TEST*/12,
- 's_DepthWrite':/*laya.d3.shader.Shader3D.RENDER_STATE_DEPTH_WRITE*/13
- }
- vs="#include \"Lighting.glsl\";\n\nattribute vec4 a_Position;\nattribute vec3 a_Normal;\nattribute vec4 a_Tangent0;\nattribute vec2 a_Texcoord0;\n\n#ifdef GPU_INSTANCE\n attribute mat4 a_MvpMatrix;\n#else\n uniform mat4 u_MvpMatrix;\n#endif\n\n#ifdef GPU_INSTANCE\n attribute mat4 a_WorldMat;\n#else\n uniform mat4 u_WorldMat;\n#endif\n\nuniform vec3 u_CameraPos;\n\nvarying vec2 v_Texcoord0;\nvarying vec3 v_Normal;\nvarying vec3 v_Tangent;\nvarying vec3 v_Binormal;\nvarying vec3 v_ViewDir;\nvarying vec3 v_PositionWorld;\n\n#ifdef TILINGOFFSET\n uniform vec4 u_TilingOffset;\n#endif\n\nvarying float v_posViewZ;\n#ifdef RECEIVESHADOW\n #ifdef SHADOWMAP_PSSM1 \n varying vec4 v_lightMVPPos;\n uniform mat4 u_lightShadowVP[4];\n #endif\n#endif\n\n#ifdef BONE\n const int c_MaxBoneCount = 24;\n attribute vec4 a_BoneIndices;\n attribute vec4 a_BoneWeights;\n uniform mat4 u_Bones[c_MaxBoneCount];\n#endif\n\nvoid main_castShadow()\n{\n vec4 position;\n #ifdef BONE\n mat4 skinTransform = u_Bones[int(a_BoneIndices.x)] * a_BoneWeights.x;\n skinTransform += u_Bones[int(a_BoneIndices.y)] * a_BoneWeights.y;\n skinTransform += u_Bones[int(a_BoneIndices.z)] * a_BoneWeights.z;\n skinTransform += u_Bones[int(a_BoneIndices.w)] * a_BoneWeights.w;\n position=skinTransform*a_Position;\n #else\n position=a_Position;\n #endif\n #ifdef GPU_INSTANCE\n gl_Position = a_MvpMatrix * position;\n #else\n gl_Position = u_MvpMatrix * position;\n #endif\n \n //TODO没考虑UV动画呢\n #if defined(DIFFUSEMAP)&&defined(ALPHATEST)\n v_Texcoord0 = a_Texcoord0;\n #endif\n gl_Position=remapGLPositionZ(gl_Position);\n v_posViewZ = gl_Position.z;\n}\n\nvoid main_normal()\n{\n vec4 position;\n #ifdef BONE\n mat4 skinTransform = u_Bones[int(a_BoneIndices.x)] * a_BoneWeights.x;\n skinTransform += u_Bones[int(a_BoneIndices.y)] * a_BoneWeights.y;\n skinTransform += u_Bones[int(a_BoneIndices.z)] * a_BoneWeights.z;\n skinTransform += u_Bones[int(a_BoneIndices.w)] * a_BoneWeights.w;\n position=skinTransform*a_Position;\n #else\n position=a_Position;\n #endif\n #ifdef GPU_INSTANCE\n gl_Position = a_MvpMatrix * position;\n #else\n gl_Position = u_MvpMatrix * position;\n #endif\n \n #if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(RECEIVESHADOW)\n mat4 worldMat;\n #ifdef GPU_INSTANCE\n worldMat = a_WorldMat;\n #else\n worldMat = u_WorldMat;\n #endif\n #endif\n \n #if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\n mat3 worldInvMat;\n #ifdef BONE\n worldInvMat=inverse(mat3(worldMat*skinTransform));\n #else\n worldInvMat=inverse(mat3(worldMat));\n #endif \n v_Normal=a_Normal*worldInvMat;\n #if (defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT))\n v_Tangent=a_Tangent0.xyz*worldInvMat;\n v_Binormal=cross(v_Normal,v_Tangent)*a_Tangent0.w;\n #endif\n #endif\n \n \n #if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(RECEIVESHADOW)\n v_PositionWorld=(worldMat*position).xyz;\n #endif\n \n \n #if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\n v_ViewDir=u_CameraPos-v_PositionWorld;\n #endif\n\n #ifdef TILINGOFFSET\n v_Texcoord0=TransformUV(a_Texcoord0,u_TilingOffset);\n #else\n v_Texcoord0=a_Texcoord0;\n #endif\n \n #ifdef RECEIVESHADOW\n v_posViewZ = gl_Position.w;\n #ifdef SHADOWMAP_PSSM1 \n v_lightMVPPos = u_lightShadowVP[0] * vec4(v_PositionWorld,1.0);\n #endif\n #endif\n gl_Position=remapGLPositionZ(gl_Position);\n}\n\nvoid main()\n{\n #ifdef CASTSHADOW\n main_castShadow();\n #else\n main_normal();\n #endif\n}";
- ps="#ifdef FSHIGHPRECISION\n precision highp float;\n#else\n precision mediump float;\n#endif\n\nvarying vec2 v_Texcoord0;\nvarying vec3 v_Normal;\nvarying vec3 v_Tangent;\nvarying vec3 v_Binormal;\nvarying vec3 v_ViewDir;\nvarying vec3 v_PositionWorld;\n\nuniform vec3 u_AmbientColor;\nuniform vec4 u_AlbedoColor;\n\n#ifdef ALBEDOTEXTURE\n uniform sampler2D u_AlbedoTexture;\n#endif\n#ifdef METALLICGLOSSTEXTURE\n uniform sampler2D u_MetallicGlossTexture;\n#endif\n#ifdef NORMALTEXTURE\n uniform sampler2D u_NormalTexture;\n uniform float u_normalScale;\n#endif\n#ifdef PARALLAXTEXTURE\n uniform sampler2D u_ParallaxTexture;\n uniform float u_parallaxScale;\n#endif\n#ifdef OCCLUSIONTEXTURE\n uniform sampler2D u_OcclusionTexture;\n uniform float u_occlusionStrength;\n#endif\n#ifdef EMISSION\n #ifdef EMISSIONTEXTURE\n uniform sampler2D u_EmissionTexture;\n #endif\n uniform vec4 u_EmissionColor;\n#endif\n#ifdef REFLECTMAP\n uniform samplerCube u_ReflectTexture;\n uniform float u_ReflectIntensity;\n#endif\n\nuniform float u_AlphaTestValue;\nuniform float u_metallic;\nuniform float u_smoothness;\nuniform float u_smoothnessScale;\n\nuniform sampler2D u_RangeTexture;\n//uniform sampler2D u_AngleTexture;\nuniform mat4 u_PointLightMatrix;\n//uniform mat4 u_SpotLightMatrix;\n\n#include \"PBRStandardLighting.glsl\"\n#include \"ShadowHelper.glsl\"\n\nvarying float v_posViewZ;\n#ifdef RECEIVESHADOW\n #if defined(SHADOWMAP_PSSM2)||defined(SHADOWMAP_PSSM3)\n uniform mat4 u_lightShadowVP[4];\n #endif\n #ifdef SHADOWMAP_PSSM1 \n varying vec4 v_lightMVPPos;\n #endif\n#endif\n\n#ifdef DIRECTIONLIGHT\n uniform DirectionLight u_DirectionLight;\n#endif\n#ifdef POINTLIGHT\n uniform PointLight u_PointLight;\n#endif\n#ifdef SPOTLIGHT\n uniform SpotLight u_SpotLight;\n#endif\n\n#ifdef FOG\n uniform float u_FogStart;\n uniform float u_FogRange;\n uniform vec3 u_FogColor;\n#endif\n\nvoid main_castShadow()\n{\n gl_FragColor=packDepth(v_posViewZ);\n #if defined(DIFFUSEMAP)&&defined(ALPHATEST)\n float alpha = texture2D(u_AlbedoTexture,v_Texcoord0).w;\n if( alpha < u_AlphaTestValue )\n {\n discard;\n }\n #endif\n}\n\nvoid main_normal()\n{ \n vec3 viewDir = normalize(v_ViewDir);\n \n vec2 uv0 = ParallaxOffset(viewDir);\n \n vec2 mg;\n vec4 albedoColor;\n #ifdef ALBEDOTEXTURE\n vec4 abledoTextureColor = texture2D(u_AlbedoTexture, uv0);\n albedoColor = abledoTextureColor * u_AlbedoColor;\n mg = MetallicGloss(abledoTextureColor.a, uv0);\n #else\n albedoColor = u_AlbedoColor;\n mg = MetallicGloss(1.0, uv0);\n #endif\n \n #ifdef ALPHATEST\n if(albedoColor.a < u_AlphaTestValue)\n discard;\n #endif\n \n vec3 normal = UnpackScaleNormal(uv0);\n \n LayaGI gi;\n gi.diffuse = u_AmbientColor * Occlusion(uv0).rgb;\n gi.specular = ReflectCubeMap(viewDir, normal);\n \n vec4 color = vec4(0.0);\n \n #ifdef DIRECTIONLIGHT\n color += PBRStandardDiectionLight(albedoColor, mg.r, mg.g, normal, viewDir, u_DirectionLight, gi);\n #endif\n \n #ifdef POINTLIGHT\n color.a = 0.0;\n color += PBRStandardPointLight(albedoColor, mg.r, mg.g, normal, viewDir, u_PointLight, v_PositionWorld, gi);\n #endif\n \n #ifdef SPOTLIGHT\n color.a = 0.0;\n color += PBRStandardSpotLight(albedoColor, mg.r, mg.g, normal, viewDir, u_SpotLight, v_PositionWorld, gi);\n #endif\n \n #ifdef EMISSION\n vec4 emissionColor = u_EmissionColor;\n #ifdef EMISSIONTEXTURE\n emissionColor *= texture2D(u_EmissionTexture, uv0);\n #endif\n color.rgb += emissionColor.rgb;\n #endif\n \n #ifdef RECEIVESHADOW\n float shadowValue = 1.0;\n #ifdef SHADOWMAP_PSSM3\n shadowValue = getShadowPSSM3( u_shadowMap1,u_shadowMap2,u_shadowMap3,u_lightShadowVP,u_shadowPSSMDistance,u_shadowPCFoffset,v_PositionWorld,v_posViewZ,0.001);\n #endif\n #ifdef SHADOWMAP_PSSM2\n shadowValue = getShadowPSSM2( u_shadowMap1,u_shadowMap2,u_lightShadowVP,u_shadowPSSMDistance,u_shadowPCFoffset,v_PositionWorld,v_posViewZ,0.001);\n #endif \n #ifdef SHADOWMAP_PSSM1\n shadowValue = getShadowPSSM1( u_shadowMap1,v_lightMVPPos,u_shadowPSSMDistance,u_shadowPCFoffset,v_posViewZ,0.001);\n #endif\n gl_FragColor = vec4(color.rgb * shadowValue, color.a);\n #else\n gl_FragColor = color;\n #endif\n \n #ifdef FOG\n float lerpFact = clamp((1.0 / gl_FragCoord.w - u_FogStart) / u_FogRange, 0.0, 1.0);\n gl_FragColor.rgb = mix(gl_FragColor.rgb, u_FogColor, lerpFact);\n #endif\n}\n\nvoid main()\n{\n #ifdef CASTSHADOW \n main_castShadow();\n #else\n main_normal();\n #endif \n}";
- shader=Shader3D.add("PBRStandard",true);
- subShader=new SubShader(attributeMap,uniformMap,SkinnedMeshSprite3D.shaderDefines,PBRStandardMaterial.shaderDefines);
- shader.addSubShader(subShader);
- subShader.addShaderPass(vs,ps,stateMap);
- attributeMap={
- 'a_Position':/*laya.d3.graphics.Vertex.VertexMesh.MESH_POSITION0*/0,
- 'a_Normal':/*laya.d3.graphics.Vertex.VertexMesh.MESH_NORMAL0*/3,
- 'a_Tangent0':/*laya.d3.graphics.Vertex.VertexMesh.MESH_TANGENT0*/4,
- 'a_Texcoord0':/*laya.d3.graphics.Vertex.VertexMesh.MESH_TEXTURECOORDINATE0*/2,
- 'a_BoneWeights':/*laya.d3.graphics.Vertex.VertexMesh.MESH_BLENDWEIGHT0*/6,
- 'a_BoneIndices':/*laya.d3.graphics.Vertex.VertexMesh.MESH_BLENDINDICES0*/5,
- 'a_MvpMatrix':/*laya.d3.graphics.Vertex.VertexMesh.MESH_MVPMATRIX_ROW0*/12,
- 'a_WorldMat':/*laya.d3.graphics.Vertex.VertexMesh.MESH_WORLDMATRIX_ROW0*/8
- };
- uniformMap={
- 'u_Bones':/*laya.d3.shader.Shader3D.PERIOD_CUSTOM*/0,
- 'u_MvpMatrix':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_WorldMat':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_CameraPos':/*laya.d3.shader.Shader3D.PERIOD_CAMERA*/3,
- 'u_AlphaTestValue':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_AlbedoColor':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_SpecularColor':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_EmissionColor':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_AlbedoTexture':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_NormalTexture':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_ParallaxTexture':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_SpecularTexture':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_OcclusionTexture':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_EmissionTexture':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_smoothness':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_smoothnessScale':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_occlusionStrength':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_normalScale':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_parallaxScale':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_TilingOffset':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_DirectionLight.Direction':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_DirectionLight.Color':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_PointLightMatrix':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_PointLight.Position':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_PointLight.Range':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_PointLight.Color':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_SpotLight.Position':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_SpotLight.Direction':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_SpotLight.Range':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_SpotLight.SpotAngle':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_SpotLight.Color':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_RangeTexture':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_ReflectTexture':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_ReflectIntensity':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_AmbientColor':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_shadowMap1':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_shadowMap2':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_shadowMap3':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_shadowPSSMDistance':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_lightShadowVP':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_shadowPCFoffset':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_FogStart':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_FogRange':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_FogColor':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4
- };
- stateMap={
- 's_Cull':/*laya.d3.shader.Shader3D.RENDER_STATE_CULL*/0,
- 's_Blend':/*laya.d3.shader.Shader3D.RENDER_STATE_BLEND*/1,
- 's_BlendSrc':/*laya.d3.shader.Shader3D.RENDER_STATE_BLEND_SRC*/2,
- 's_BlendDst':/*laya.d3.shader.Shader3D.RENDER_STATE_BLEND_DST*/3,
- 's_DepthTest':/*laya.d3.shader.Shader3D.RENDER_STATE_DEPTH_TEST*/12,
- 's_DepthWrite':/*laya.d3.shader.Shader3D.RENDER_STATE_DEPTH_WRITE*/13
- }
- vs="#include \"Lighting.glsl\";\n\nattribute vec4 a_Position;\nattribute vec3 a_Normal;\nattribute vec4 a_Tangent0;\nattribute vec2 a_Texcoord0;\n\n#ifdef GPU_INSTANCE\n attribute mat4 a_MvpMatrix;\n#else\n uniform mat4 u_MvpMatrix;\n#endif\n\n#ifdef GPU_INSTANCE\n attribute mat4 a_WorldMat;\n#else\n uniform mat4 u_WorldMat;\n#endif\nuniform vec3 u_CameraPos;\n\nvarying vec2 v_Texcoord0;\nvarying vec3 v_Normal;\nvarying vec3 v_Tangent;\nvarying vec3 v_Binormal;\nvarying vec3 v_ViewDir;\nvarying vec3 v_PositionWorld;\n\n#ifdef TILINGOFFSET\n uniform vec4 u_TilingOffset;\n#endif\n\nvarying float v_posViewZ;\n#ifdef RECEIVESHADOW\n #ifdef SHADOWMAP_PSSM1 \n varying vec4 v_lightMVPPos;\n uniform mat4 u_lightShadowVP[4];\n #endif\n#endif\n\n#ifdef BONE\n const int c_MaxBoneCount = 24;\n attribute vec4 a_BoneIndices;\n attribute vec4 a_BoneWeights;\n uniform mat4 u_Bones[c_MaxBoneCount];\n#endif\n\nvoid main_castShadow()\n{\n vec4 position;\n #ifdef BONE\n mat4 skinTransform = u_Bones[int(a_BoneIndices.x)] * a_BoneWeights.x;\n skinTransform += u_Bones[int(a_BoneIndices.y)] * a_BoneWeights.y;\n skinTransform += u_Bones[int(a_BoneIndices.z)] * a_BoneWeights.z;\n skinTransform += u_Bones[int(a_BoneIndices.w)] * a_BoneWeights.w;\n position=skinTransform*a_Position;\n #else\n position=a_Position;\n #endif\n #ifdef GPU_INSTANCE\n gl_Position = a_MvpMatrix * position;\n #else\n gl_Position = u_MvpMatrix * position;\n #endif\n \n //TODO没考虑UV动画呢\n #if defined(DIFFUSEMAP)&&defined(ALPHATEST)\n v_Texcoord0 = a_Texcoord0;\n #endif\n gl_Position=remapGLPositionZ(gl_Position);\n v_posViewZ = gl_Position.z;\n}\n\nvoid main_normal()\n{\n vec4 position;\n #ifdef BONE\n mat4 skinTransform = u_Bones[int(a_BoneIndices.x)] * a_BoneWeights.x;\n skinTransform += u_Bones[int(a_BoneIndices.y)] * a_BoneWeights.y;\n skinTransform += u_Bones[int(a_BoneIndices.z)] * a_BoneWeights.z;\n skinTransform += u_Bones[int(a_BoneIndices.w)] * a_BoneWeights.w;\n position=skinTransform*a_Position;\n #else\n position=a_Position;\n #endif\n #ifdef GPU_INSTANCE\n gl_Position = a_MvpMatrix * position;\n #else\n gl_Position = u_MvpMatrix * position;\n #endif\n \n #if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(RECEIVESHADOW)\n mat4 worldMat;\n #ifdef GPU_INSTANCE\n worldMat = a_WorldMat;\n #else\n worldMat = u_WorldMat;\n #endif\n #endif\n \n #if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\n mat3 worldInvMat;\n #ifdef BONE\n worldInvMat=inverse(mat3(worldMat*skinTransform));\n #else\n worldInvMat=inverse(mat3(worldMat));\n #endif \n v_Normal=a_Normal*worldInvMat;\n #if (defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT))\n v_Tangent=a_Tangent0.xyz*worldInvMat;\n v_Binormal=cross(v_Normal,v_Tangent)*a_Tangent0.w;\n #endif\n #endif\n \n \n #if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(RECEIVESHADOW)\n v_PositionWorld=(worldMat*position).xyz;\n #endif\n \n \n #if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\n v_ViewDir=u_CameraPos-v_PositionWorld;\n #endif\n\n #ifdef TILINGOFFSET\n v_Texcoord0=TransformUV(a_Texcoord0,u_TilingOffset);\n #else\n v_Texcoord0=a_Texcoord0;\n #endif\n \n #ifdef RECEIVESHADOW\n v_posViewZ = gl_Position.w;\n #ifdef SHADOWMAP_PSSM1 \n v_lightMVPPos = u_lightShadowVP[0] * vec4(v_PositionWorld,1.0);\n #endif\n #endif\n gl_Position=remapGLPositionZ(gl_Position);\n}\n\nvoid main()\n{\n #ifdef CASTSHADOW\n main_castShadow();\n #else\n main_normal();\n #endif\n}";
- ps="#ifdef FSHIGHPRECISION\n precision highp float;\n#else\n precision mediump float;\n#endif\n\nvarying vec2 v_Texcoord0;\nvarying vec3 v_Normal;\nvarying vec3 v_Tangent;\nvarying vec3 v_Binormal;\nvarying vec3 v_ViewDir;\nvarying vec3 v_PositionWorld;\n\nuniform vec3 u_AmbientColor;\nuniform vec4 u_AlbedoColor;\nuniform vec4 u_SpecularColor;\n\n#ifdef ALBEDOTEXTURE\n uniform sampler2D u_AlbedoTexture;\n#endif\n#ifdef SPECULARTEXTURE\n uniform sampler2D u_SpecularTexture;\n#endif\n#ifdef NORMALTEXTURE\n uniform sampler2D u_NormalTexture;\n uniform float u_normalScale;\n#endif\n#ifdef PARALLAXTEXTURE\n uniform sampler2D u_ParallaxTexture;\n uniform float u_parallaxScale;\n#endif\n#ifdef OCCLUSIONTEXTURE\n uniform sampler2D u_OcclusionTexture;\n uniform float u_occlusionStrength;\n#endif\n#ifdef EMISSION\n #ifdef EMISSIONTEXTURE\n uniform sampler2D u_EmissionTexture;\n #endif\n uniform vec4 u_EmissionColor;\n#endif\n#ifdef REFLECTMAP\n uniform samplerCube u_ReflectTexture;\n uniform float u_ReflectIntensity;\n#endif\n\nuniform float u_AlphaTestValue;\nuniform float u_metallic;\nuniform float u_smoothness;\nuniform float u_smoothnessScale;\n\nuniform sampler2D u_RangeTexture;\n//uniform sampler2D u_AngleTexture;\nuniform mat4 u_PointLightMatrix;\n//uniform mat4 u_SpotLightMatrix;\n\n#include \"PBRSpecularLighting.glsl\"\n#include \"ShadowHelper.glsl\"\n\nvarying float v_posViewZ;\n#ifdef RECEIVESHADOW\n #if defined(SHADOWMAP_PSSM2)||defined(SHADOWMAP_PSSM3)\n uniform mat4 u_lightShadowVP[4];\n #endif\n #ifdef SHADOWMAP_PSSM1 \n varying vec4 v_lightMVPPos;\n #endif\n#endif\n\n#ifdef DIRECTIONLIGHT\n uniform DirectionLight u_DirectionLight;\n#endif\n#ifdef POINTLIGHT\n uniform PointLight u_PointLight;\n#endif\n#ifdef SPOTLIGHT\n uniform SpotLight u_SpotLight;\n#endif\n\n#ifdef FOG\n uniform float u_FogStart;\n uniform float u_FogRange;\n uniform vec3 u_FogColor;\n#endif\n\nvoid main_castShadow()\n{\n gl_FragColor=packDepth(v_posViewZ);\n #if defined(DIFFUSEMAP)&&defined(ALPHATEST)\n float alpha = texture2D(u_AlbedoTexture,v_Texcoord0).w;\n if( alpha < u_AlphaTestValue )\n {\n discard;\n }\n #endif\n}\n\nvoid main_normal()\n{ \n vec3 viewDir = normalize(v_ViewDir);\n \n vec2 uv0 = ParallaxOffset(viewDir);\n \n vec4 sg;\n vec4 albedoColor;\n #ifdef ALBEDOTEXTURE\n vec4 albedoTextureColor = texture2D(u_AlbedoTexture, uv0);\n albedoColor = albedoTextureColor * u_AlbedoColor;\n sg = SpecularGloss(albedoTextureColor.a, uv0);\n #else\n albedoColor = u_AlbedoColor;\n sg = SpecularGloss(1.0, uv0);\n #endif\n \n #ifdef ALPHATEST\n if(albedoColor.a < u_AlphaTestValue)\n discard;\n #endif\n \n vec3 normal = UnpackScaleNormal(uv0);\n \n LayaGI gi;\n gi.diffuse = u_AmbientColor * Occlusion(uv0).rgb;\n gi.specular = ReflectCubeMap(viewDir, normal);\n \n //float a = (sg.r+sg.g+sg.b) / 3.0;\n \n vec4 color = vec4(0.0);\n \n #ifdef DIRECTIONLIGHT\n color += PBRSpecularDiectionLight(albedoColor, sg.rgb, sg.a, normal, viewDir, u_DirectionLight, gi);\n #endif\n \n #ifdef POINTLIGHT\n color.a = 0.0;\n color += PBRSpecularPointLight(albedoColor, sg.rgb, sg.a, normal, viewDir, u_PointLight, v_PositionWorld, gi);\n #endif\n \n #ifdef SPOTLIGHT\n color.a = 0.0;\n color += PBRSpecularSpotLight(albedoColor, sg.rgb, sg.a, normal, viewDir, u_SpotLight, v_PositionWorld, gi);\n #endif\n \n #ifdef EMISSION\n vec4 emissionColor = u_EmissionColor;\n #ifdef EMISSIONTEXTURE\n emissionColor *= texture2D(u_EmissionTexture, uv0);\n #endif\n color.rgb += emissionColor.rgb;\n #endif\n \n #ifdef RECEIVESHADOW\n float shadowValue = 1.0;\n #ifdef SHADOWMAP_PSSM3\n shadowValue = getShadowPSSM3( u_shadowMap1,u_shadowMap2,u_shadowMap3,u_lightShadowVP,u_shadowPSSMDistance,u_shadowPCFoffset,v_PositionWorld,v_posViewZ,0.001);\n #endif\n #ifdef SHADOWMAP_PSSM2\n shadowValue = getShadowPSSM2( u_shadowMap1,u_shadowMap2,u_lightShadowVP,u_shadowPSSMDistance,u_shadowPCFoffset,v_PositionWorld,v_posViewZ,0.001);\n #endif \n #ifdef SHADOWMAP_PSSM1\n shadowValue = getShadowPSSM1( u_shadowMap1,v_lightMVPPos,u_shadowPSSMDistance,u_shadowPCFoffset,v_posViewZ,0.001);\n #endif\n gl_FragColor = vec4(color.rgb * shadowValue, color.a);\n #else\n gl_FragColor = color;\n #endif\n \n #ifdef FOG\n float lerpFact = clamp((1.0 / gl_FragCoord.w - u_FogStart) / u_FogRange, 0.0, 1.0);\n gl_FragColor.rgb = mix(gl_FragColor.rgb, u_FogColor, lerpFact);\n #endif\n}\n\nvoid main()\n{\n #ifdef CASTSHADOW \n main_castShadow();\n #else\n main_normal();\n #endif \n}\n\n";
- shader=Shader3D.add("PBRSpecular",true);
- subShader=new SubShader(attributeMap,uniformMap,SkinnedMeshSprite3D.shaderDefines,PBRSpecularMaterial.shaderDefines);
- shader.addSubShader(subShader);
- subShader.addShaderPass(vs,ps,stateMap);
- attributeMap={
- 'a_Position':/*laya.d3.graphics.Vertex.VertexMesh.MESH_POSITION0*/0,
- 'a_Color':/*laya.d3.graphics.Vertex.VertexMesh.MESH_COLOR0*/1,
- 'a_Texcoord0':/*laya.d3.graphics.Vertex.VertexMesh.MESH_TEXTURECOORDINATE0*/2,
- 'a_BoneWeights':/*laya.d3.graphics.Vertex.VertexMesh.MESH_BLENDWEIGHT0*/6,
- 'a_BoneIndices':/*laya.d3.graphics.Vertex.VertexMesh.MESH_BLENDINDICES0*/5,
- 'a_MvpMatrix':/*laya.d3.graphics.Vertex.VertexMesh.MESH_MVPMATRIX_ROW0*/12
- };
- uniformMap={
- 'u_Bones':/*laya.d3.shader.Shader3D.PERIOD_CUSTOM*/0,
- 'u_AlbedoTexture':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_AlbedoColor':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_TilingOffset':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_AlphaTestValue':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_MvpMatrix':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_FogStart':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_FogRange':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_FogColor':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4
- };
- stateMap={
- 's_Cull':/*laya.d3.shader.Shader3D.RENDER_STATE_CULL*/0,
- 's_Blend':/*laya.d3.shader.Shader3D.RENDER_STATE_BLEND*/1,
- 's_BlendSrc':/*laya.d3.shader.Shader3D.RENDER_STATE_BLEND_SRC*/2,
- 's_BlendDst':/*laya.d3.shader.Shader3D.RENDER_STATE_BLEND_DST*/3,
- 's_DepthTest':/*laya.d3.shader.Shader3D.RENDER_STATE_DEPTH_TEST*/12,
- 's_DepthWrite':/*laya.d3.shader.Shader3D.RENDER_STATE_DEPTH_WRITE*/13
- }
- vs="#include \"Lighting.glsl\";\n\nattribute vec4 a_Position;\n\nattribute vec2 a_Texcoord0;\n\n#ifdef GPU_INSTANCE\n attribute mat4 a_MvpMatrix;\n#else\n uniform mat4 u_MvpMatrix;\n#endif\n\nattribute vec4 a_Color;\nvarying vec4 v_Color;\nvarying vec2 v_Texcoord0;\n\n#ifdef TILINGOFFSET\n uniform vec4 u_TilingOffset;\n#endif\n\n#ifdef BONE\n const int c_MaxBoneCount = 24;\n attribute vec4 a_BoneIndices;\n attribute vec4 a_BoneWeights;\n uniform mat4 u_Bones[c_MaxBoneCount];\n#endif\n\nvoid main() {\n vec4 position;\n #ifdef BONE\n mat4 skinTransform = u_Bones[int(a_BoneIndices.x)] * a_BoneWeights.x;\n skinTransform += u_Bones[int(a_BoneIndices.y)] * a_BoneWeights.y;\n skinTransform += u_Bones[int(a_BoneIndices.z)] * a_BoneWeights.z;\n skinTransform += u_Bones[int(a_BoneIndices.w)] * a_BoneWeights.w;\n position=skinTransform*a_Position;\n #else\n position=a_Position;\n #endif\n #ifdef GPU_INSTANCE\n gl_Position = a_MvpMatrix * position;\n #else\n gl_Position = u_MvpMatrix * position;\n #endif\n\n #ifdef TILINGOFFSET\n v_Texcoord0=TransformUV(a_Texcoord0,u_TilingOffset);\n #else\n v_Texcoord0=a_Texcoord0;\n #endif\n\n #if defined(COLOR)&&defined(ENABLEVERTEXCOLOR)\n v_Color = a_Color;\n #endif\n gl_Position=remapGLPositionZ(gl_Position);\n}";
- ps="#ifdef FSHIGHPRECISION\n precision highp float;\n#else\n precision mediump float;\n#endif\n\n#if defined(COLOR)&&defined(ENABLEVERTEXCOLOR)\n varying vec4 v_Color;\n#endif\n\n#ifdef ALBEDOTEXTURE\n uniform sampler2D u_AlbedoTexture;\n varying vec2 v_Texcoord0;\n#endif\n\nuniform vec4 u_AlbedoColor;\n\n#ifdef ALPHATEST\n uniform float u_AlphaTestValue;\n#endif\n\n#ifdef FOG\n uniform float u_FogStart;\n uniform float u_FogRange;\n #ifdef ADDTIVEFOG\n #else\n uniform vec3 u_FogColor;\n #endif\n#endif\n\nvoid main()\n{\n vec4 color = u_AlbedoColor;\n #ifdef ALBEDOTEXTURE\n color *= texture2D(u_AlbedoTexture, v_Texcoord0);\n #endif\n #if defined(COLOR)&&defined(ENABLEVERTEXCOLOR)\n color *= v_Color;\n #endif\n \n #ifdef ALPHATEST\n if(color.a < u_AlphaTestValue)\n discard;\n #endif\n \n gl_FragColor = color;\n \n #ifdef FOG\n float lerpFact = clamp((1.0 / gl_FragCoord.w - u_FogStart) / u_FogRange, 0.0, 1.0);\n #ifdef ADDTIVEFOG\n gl_FragColor.rgb = mix(gl_FragColor.rgb, vec3(0.0), lerpFact);\n #else\n gl_FragColor.rgb = mix(gl_FragColor.rgb, u_FogColor, lerpFact);\n #endif\n #endif\n \n}\n\n";
- shader=Shader3D.add("Unlit",true);
- subShader=new SubShader(attributeMap,uniformMap,SkinnedMeshSprite3D.shaderDefines,UnlitMaterial.shaderDefines);
- shader.addSubShader(subShader);
- subShader.addShaderPass(vs,ps,stateMap);
- attributeMap={
- 'a_Position':/*laya.d3.graphics.Vertex.VertexMesh.MESH_POSITION0*/0,
- 'a_Texcoord0':/*laya.d3.graphics.Vertex.VertexMesh.MESH_TEXTURECOORDINATE0*/2,
- 'a_BoneWeights':/*laya.d3.graphics.Vertex.VertexMesh.MESH_BLENDWEIGHT0*/6,
- 'a_BoneIndices':/*laya.d3.graphics.Vertex.VertexMesh.MESH_BLENDINDICES0*/5,
- 'a_MvpMatrix':/*laya.d3.graphics.Vertex.VertexMesh.MESH_MVPMATRIX_ROW0*/12
- };
- uniformMap={
- 'u_Bones':/*laya.d3.shader.Shader3D.PERIOD_CUSTOM*/0,
- 'u_AlbedoTexture':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_AlbedoColor':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_TilingOffset':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_AlphaTestValue':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_MvpMatrix':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_FogStart':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_FogRange':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_FogColor':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4
- };
- stateMap={
- 's_Cull':/*laya.d3.shader.Shader3D.RENDER_STATE_CULL*/0,
- 's_Blend':/*laya.d3.shader.Shader3D.RENDER_STATE_BLEND*/1,
- 's_BlendSrc':/*laya.d3.shader.Shader3D.RENDER_STATE_BLEND_SRC*/2,
- 's_BlendDst':/*laya.d3.shader.Shader3D.RENDER_STATE_BLEND_DST*/3,
- 's_DepthTest':/*laya.d3.shader.Shader3D.RENDER_STATE_DEPTH_TEST*/12,
- 's_DepthWrite':/*laya.d3.shader.Shader3D.RENDER_STATE_DEPTH_WRITE*/13
- }
- vs="#include \"Lighting.glsl\";\n\nattribute vec4 a_Position;\nattribute vec4 a_Color;\nattribute vec2 a_Texcoord0;\n\n#ifdef GPU_INSTANCE\n attribute mat4 a_MvpMatrix;\n#else\n uniform mat4 u_MvpMatrix;\n#endif\n\nvarying vec4 v_Color;\nvarying vec2 v_Texcoord0;\n\n#ifdef TILINGOFFSET\n uniform vec4 u_TilingOffset;\n#endif\n\n#ifdef BONE\n const int c_MaxBoneCount = 24;\n attribute vec4 a_BoneIndices;\n attribute vec4 a_BoneWeights;\n uniform mat4 u_Bones[c_MaxBoneCount];\n#endif\n\nvoid main()\n{\n vec4 position;\n #ifdef BONE\n mat4 skinTransform = u_Bones[int(a_BoneIndices.x)] * a_BoneWeights.x;\n skinTransform += u_Bones[int(a_BoneIndices.y)] * a_BoneWeights.y;\n skinTransform += u_Bones[int(a_BoneIndices.z)] * a_BoneWeights.z;\n skinTransform += u_Bones[int(a_BoneIndices.w)] * a_BoneWeights.w;\n position=skinTransform*a_Position;\n #else\n position=a_Position;\n #endif\n #ifdef GPU_INSTANCE\n gl_Position = a_MvpMatrix * position;\n #else\n gl_Position = u_MvpMatrix * position;\n #endif\n \n #ifdef TILINGOFFSET\n v_Texcoord0=TransformUV(a_Texcoord0,u_TilingOffset);\n #else\n v_Texcoord0=a_Texcoord0;\n #endif\n \n v_Color = a_Color;\n gl_Position=remapGLPositionZ(gl_Position);\n}";
- ps="#ifdef FSHIGHPRECISION\n precision highp float;\n#else\n precision mediump float;\n#endif\n\n#ifdef COLOR\n varying vec4 v_Color;\n#endif\nvarying vec2 v_Texcoord0;\n\n#ifdef MAINTEXTURE\n uniform sampler2D u_AlbedoTexture;\n#endif\n\nuniform vec4 u_AlbedoColor;\n\n#ifdef FOG\n uniform float u_FogStart;\n uniform float u_FogRange;\n #ifdef ADDTIVEFOG\n #else\n uniform vec3 u_FogColor;\n #endif\n#endif\n\nvoid main()\n{\n vec4 color = 2.0 * u_AlbedoColor;\n #ifdef COLOR\n color *= v_Color;\n #endif\n #ifdef MAINTEXTURE\n color *= texture2D(u_AlbedoTexture, v_Texcoord0);\n #endif\n \n gl_FragColor = color;\n \n #ifdef FOG\n float lerpFact = clamp((1.0 / gl_FragCoord.w - u_FogStart) / u_FogRange, 0.0, 1.0);\n #ifdef ADDTIVEFOG\n gl_FragColor.rgb = mix(gl_FragColor.rgb, vec3(0.0), lerpFact);\n #else\n gl_FragColor.rgb = mix(gl_FragColor.rgb, u_FogColor, lerpFact);\n #endif\n #endif\n}\n\n";
- shader=Shader3D.add("Effect",true);
- subShader=new SubShader(attributeMap,uniformMap,SkinnedMeshSprite3D.shaderDefines,EffectMaterial.shaderDefines);
- shader.addSubShader(subShader);
- subShader.addShaderPass(vs,ps,stateMap);
- attributeMap={
- 'a_CornerTextureCoordinate':/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_CORNERTEXTURECOORDINATE0*/0,
- 'a_MeshPosition':/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_POSITION0*/1,
- 'a_MeshColor':/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_COLOR0*/2,
- 'a_MeshTextureCoordinate':/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_TEXTURECOORDINATE0*/3,
- 'a_ShapePositionStartLifeTime':/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_SHAPEPOSITIONSTARTLIFETIME*/4,
- 'a_DirectionTime':/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_DIRECTIONTIME*/5,
- 'a_StartColor':/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_STARTCOLOR0*/6,
- 'a_EndColor':/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_ENDCOLOR0*/7,
- 'a_StartSize':/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_STARTSIZE*/8,
- 'a_StartRotation0':/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_STARTROTATION*/9,
- 'a_StartSpeed':/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_STARTSPEED*/10,
- 'a_Random0':/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_RANDOM0*/11,
- 'a_Random1':/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_RANDOM1*/12,
- 'a_SimulationWorldPostion':/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_SIMULATIONWORLDPOSTION*/13,
- 'a_SimulationWorldRotation':/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_SIMULATIONWORLDROTATION*/14};
- uniformMap={
- 'u_Tintcolor':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_TilingOffset':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_texture':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_WorldPosition':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_WorldRotation':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_PositionScale':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_SizeScale':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_ScalingMode':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_Gravity':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_ThreeDStartRotation':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_StretchedBillboardLengthScale':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_StretchedBillboardSpeedScale':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_SimulationSpace':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_CurrentTime':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_ColorOverLifeGradientAlphas':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_ColorOverLifeGradientColors':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_MaxColorOverLifeGradientAlphas':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_MaxColorOverLifeGradientColors':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_VOLVelocityConst':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_VOLVelocityGradientX':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_VOLVelocityGradientY':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_VOLVelocityGradientZ':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_VOLVelocityConstMax':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_VOLVelocityGradientMaxX':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_VOLVelocityGradientMaxY':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_VOLVelocityGradientMaxZ':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_VOLSpaceType':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_SOLSizeGradient':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_SOLSizeGradientX':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_SOLSizeGradientY':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_SOLSizeGradientZ':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_SOLSizeGradientMax':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_SOLSizeGradientMaxX':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_SOLSizeGradientMaxY':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_SOLSizeGradientMaxZ':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_ROLAngularVelocityConst':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_ROLAngularVelocityConstSeprarate':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_ROLAngularVelocityGradient':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_ROLAngularVelocityGradientX':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_ROLAngularVelocityGradientY':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_ROLAngularVelocityGradientZ':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_ROLAngularVelocityConstMax':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_ROLAngularVelocityConstMaxSeprarate':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_ROLAngularVelocityGradientMax':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_ROLAngularVelocityGradientMaxX':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_ROLAngularVelocityGradientMaxY':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_ROLAngularVelocityGradientMaxZ':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_ROLAngularVelocityGradientMaxW':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_TSACycles':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_TSASubUVLength':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_TSAGradientUVs':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_TSAMaxGradientUVs':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_CameraPos':/*laya.d3.shader.Shader3D.PERIOD_CAMERA*/3,
- 'u_CameraDirection':/*laya.d3.shader.Shader3D.PERIOD_CAMERA*/3,
- 'u_CameraUp':/*laya.d3.shader.Shader3D.PERIOD_CAMERA*/3,
- 'u_View':/*laya.d3.shader.Shader3D.PERIOD_CAMERA*/3,
- 'u_Projection':/*laya.d3.shader.Shader3D.PERIOD_CAMERA*/3,
- 'u_FogStart':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_FogRange':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_FogColor':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4
- };
- stateMap={
- 's_Cull':/*laya.d3.shader.Shader3D.RENDER_STATE_CULL*/0,
- 's_Blend':/*laya.d3.shader.Shader3D.RENDER_STATE_BLEND*/1,
- 's_BlendSrc':/*laya.d3.shader.Shader3D.RENDER_STATE_BLEND_SRC*/2,
- 's_BlendDst':/*laya.d3.shader.Shader3D.RENDER_STATE_BLEND_DST*/3,
- 's_DepthTest':/*laya.d3.shader.Shader3D.RENDER_STATE_DEPTH_TEST*/12,
- 's_DepthWrite':/*laya.d3.shader.Shader3D.RENDER_STATE_DEPTH_WRITE*/13
- };
- vs="#include \"Lighting.glsl\";\n\n#ifdef HIGHPRECISION\n precision highp float;\n#else\n precision mediump float;\n#endif\n\n#if defined(SPHERHBILLBOARD)||defined(STRETCHEDBILLBOARD)||defined(HORIZONTALBILLBOARD)||defined(VERTICALBILLBOARD)\n attribute vec4 a_CornerTextureCoordinate;\n#endif\n#ifdef RENDERMODE_MESH\n attribute vec3 a_MeshPosition;\n attribute vec4 a_MeshColor;\n attribute vec2 a_MeshTextureCoordinate;\n varying vec4 v_MeshColor;\n#endif\n\nattribute vec4 a_ShapePositionStartLifeTime;\nattribute vec4 a_DirectionTime;\nattribute vec4 a_StartColor;\nattribute vec3 a_StartSize;\nattribute vec3 a_StartRotation0;\nattribute float a_StartSpeed;\n#if defined(COLOROVERLIFETIME)||defined(RANDOMCOLOROVERLIFETIME)||defined(SIZEOVERLIFETIMERANDOMCURVES)||defined(SIZEOVERLIFETIMERANDOMCURVESSEPERATE)||defined(ROTATIONOVERLIFETIMERANDOMCONSTANTS)||defined(ROTATIONOVERLIFETIMERANDOMCURVES)\n attribute vec4 a_Random0;\n#endif\n#if defined(TEXTURESHEETANIMATIONRANDOMCURVE)||defined(VELOCITYOVERLIFETIMERANDOMCONSTANT)||defined(VELOCITYOVERLIFETIMERANDOMCURVE)\n attribute vec4 a_Random1;\n#endif\nattribute vec3 a_SimulationWorldPostion;\nattribute vec4 a_SimulationWorldRotation;\n\nvarying float v_Discard;\nvarying vec4 v_Color;\n#ifdef DIFFUSEMAP\n varying vec2 v_TextureCoordinate;\n#endif\n\nuniform float u_CurrentTime;\nuniform vec3 u_Gravity;\n\nuniform vec3 u_WorldPosition;\nuniform vec4 u_WorldRotation;\nuniform bool u_ThreeDStartRotation;\nuniform int u_ScalingMode;\nuniform vec3 u_PositionScale;\nuniform vec3 u_SizeScale;\nuniform mat4 u_View;\nuniform mat4 u_Projection;\n\n#ifdef STRETCHEDBILLBOARD\n uniform vec3 u_CameraPosition;\n#endif\nuniform vec3 u_CameraDirection;//TODO:只有几种广告牌模式需要用\nuniform vec3 u_CameraUp;\n\nuniform float u_StretchedBillboardLengthScale;\nuniform float u_StretchedBillboardSpeedScale;\nuniform int u_SimulationSpace;\n\n#if defined(VELOCITYOVERLIFETIMECONSTANT)||defined(VELOCITYOVERLIFETIMECURVE)||defined(VELOCITYOVERLIFETIMERANDOMCONSTANT)||defined(VELOCITYOVERLIFETIMERANDOMCURVE)\n uniform int u_VOLSpaceType;\n#endif\n#if defined(VELOCITYOVERLIFETIMECONSTANT)||defined(VELOCITYOVERLIFETIMERANDOMCONSTANT)\n uniform vec3 u_VOLVelocityConst;\n#endif\n#if defined(VELOCITYOVERLIFETIMECURVE)||defined(VELOCITYOVERLIFETIMERANDOMCURVE)\n uniform vec2 u_VOLVelocityGradientX[4];//x为key,y为速度\n uniform vec2 u_VOLVelocityGradientY[4];//x为key,y为速度\n uniform vec2 u_VOLVelocityGradientZ[4];//x为key,y为速度\n#endif\n#ifdef VELOCITYOVERLIFETIMERANDOMCONSTANT\n uniform vec3 u_VOLVelocityConstMax;\n#endif\n#ifdef VELOCITYOVERLIFETIMERANDOMCURVE\n uniform vec2 u_VOLVelocityGradientMaxX[4];//x为key,y为速度\n uniform vec2 u_VOLVelocityGradientMaxY[4];//x为key,y为速度\n uniform vec2 u_VOLVelocityGradientMaxZ[4];//x为key,y为速度\n#endif\n\n#ifdef COLOROVERLIFETIME\n uniform vec4 u_ColorOverLifeGradientColors[4];//x为key,yzw为Color\n uniform vec2 u_ColorOverLifeGradientAlphas[4];//x为key,y为Alpha\n#endif\n#ifdef RANDOMCOLOROVERLIFETIME\n uniform vec4 u_ColorOverLifeGradientColors[4];//x为key,yzw为Color\n uniform vec2 u_ColorOverLifeGradientAlphas[4];//x为key,y为Alpha\n uniform vec4 u_MaxColorOverLifeGradientColors[4];//x为key,yzw为Color\n uniform vec2 u_MaxColorOverLifeGradientAlphas[4];//x为key,y为Alpha\n#endif\n\n\n#if defined(SIZEOVERLIFETIMECURVE)||defined(SIZEOVERLIFETIMERANDOMCURVES)\n uniform vec2 u_SOLSizeGradient[4];//x为key,y为尺寸\n#endif\n#ifdef SIZEOVERLIFETIMERANDOMCURVES\n uniform vec2 u_SOLSizeGradientMax[4];//x为key,y为尺寸\n#endif\n#if defined(SIZEOVERLIFETIMECURVESEPERATE)||defined(SIZEOVERLIFETIMERANDOMCURVESSEPERATE)\n uniform vec2 u_SOLSizeGradientX[4];//x为key,y为尺寸\n uniform vec2 u_SOLSizeGradientY[4];//x为key,y为尺寸\n uniform vec2 u_SOLSizeGradientZ[4];//x为key,y为尺寸\n#endif\n#ifdef SIZEOVERLIFETIMERANDOMCURVESSEPERATE\n uniform vec2 u_SOLSizeGradientMaxX[4];//x为key,y为尺寸\n uniform vec2 u_SOLSizeGradientMaxY[4];//x为key,y为尺寸\n uniform vec2 u_SOLSizeGradientMaxZ[4];//x为key,y为尺寸\n#endif\n\n\n#ifdef ROTATIONOVERLIFETIME\n #if defined(ROTATIONOVERLIFETIMECONSTANT)||defined(ROTATIONOVERLIFETIMERANDOMCONSTANTS)\n uniform float u_ROLAngularVelocityConst;\n #endif\n #ifdef ROTATIONOVERLIFETIMERANDOMCONSTANTS\n uniform float u_ROLAngularVelocityConstMax;\n #endif\n #if defined(ROTATIONOVERLIFETIMECURVE)||defined(ROTATIONOVERLIFETIMERANDOMCURVES)\n uniform vec2 u_ROLAngularVelocityGradient[4];//x为key,y为旋转\n #endif\n #ifdef ROTATIONOVERLIFETIMERANDOMCURVES\n uniform vec2 u_ROLAngularVelocityGradientMax[4];//x为key,y为旋转\n #endif\n#endif\n#ifdef ROTATIONOVERLIFETIMESEPERATE\n #if defined(ROTATIONOVERLIFETIMECONSTANT)||defined(ROTATIONOVERLIFETIMERANDOMCONSTANTS)\n uniform vec3 u_ROLAngularVelocityConstSeprarate;\n #endif\n #ifdef ROTATIONOVERLIFETIMERANDOMCONSTANTS\n uniform vec3 u_ROLAngularVelocityConstMaxSeprarate;\n #endif\n #if defined(ROTATIONOVERLIFETIMECURVE)||defined(ROTATIONOVERLIFETIMERANDOMCURVES)\n uniform vec2 u_ROLAngularVelocityGradientX[4];\n uniform vec2 u_ROLAngularVelocityGradientY[4];\n uniform vec2 u_ROLAngularVelocityGradientZ[4];\n #endif\n #ifdef ROTATIONOVERLIFETIMERANDOMCURVES\n uniform vec2 u_ROLAngularVelocityGradientMaxX[4];\n uniform vec2 u_ROLAngularVelocityGradientMaxY[4];\n uniform vec2 u_ROLAngularVelocityGradientMaxZ[4];\n uniform vec2 u_ROLAngularVelocityGradientMaxW[4];\n #endif\n#endif\n\n#if defined(TEXTURESHEETANIMATIONCURVE)||defined(TEXTURESHEETANIMATIONRANDOMCURVE)\n uniform float u_TSACycles;\n uniform vec2 u_TSASubUVLength;\n uniform vec2 u_TSAGradientUVs[4];//x为key,y为frame\n#endif\n#ifdef TEXTURESHEETANIMATIONRANDOMCURVE\n uniform vec2 u_TSAMaxGradientUVs[4];//x为key,y为frame\n#endif\n\n#ifdef FOG\n varying vec3 v_PositionWorld;\n#endif\n\n#ifdef TILINGOFFSET\n uniform vec4 u_TilingOffset;\n#endif\n\nvec3 rotationByEuler(in vec3 vector,in vec3 rot)\n{\n float halfRoll = rot.z * 0.5;\n float halfPitch = rot.x * 0.5;\n float halfYaw = rot.y * 0.5;\n\n float sinRoll = sin(halfRoll);\n float cosRoll = cos(halfRoll);\n float sinPitch = sin(halfPitch);\n float cosPitch = cos(halfPitch);\n float sinYaw = sin(halfYaw);\n float cosYaw = cos(halfYaw);\n\n float quaX = (cosYaw * sinPitch * cosRoll) + (sinYaw * cosPitch * sinRoll);\n float quaY = (sinYaw * cosPitch * cosRoll) - (cosYaw * sinPitch * sinRoll);\n float quaZ = (cosYaw * cosPitch * sinRoll) - (sinYaw * sinPitch * cosRoll);\n float quaW = (cosYaw * cosPitch * cosRoll) + (sinYaw * sinPitch * sinRoll);\n \n //vec4 q=vec4(quaX,quaY,quaZ,quaW);\n //vec3 temp = cross(q.xyz, vector) + q.w * vector;\n //return (cross(temp, -q.xyz) + dot(q.xyz,vector) * q.xyz + q.w * temp);\n \n float x = quaX + quaX;\n float y = quaY + quaY;\n float z = quaZ + quaZ;\n float wx = quaW * x;\n float wy = quaW * y;\n float wz = quaW * z;\n float xx = quaX * x;\n float xy = quaX * y;\n float xz = quaX * z;\n float yy = quaY * y;\n float yz = quaY * z;\n float zz = quaZ * z;\n\n return vec3(((vector.x * ((1.0 - yy) - zz)) + (vector.y * (xy - wz))) + (vector.z * (xz + wy)),\n ((vector.x * (xy + wz)) + (vector.y * ((1.0 - xx) - zz))) + (vector.z * (yz - wx)),\n ((vector.x * (xz - wy)) + (vector.y * (yz + wx))) + (vector.z * ((1.0 - xx) - yy)));\n \n}\n\n//假定axis已经归一化\nvec3 rotationByAxis(in vec3 vector,in vec3 axis, in float angle)\n{\n float halfAngle = angle * 0.5;\n float sin = sin(halfAngle);\n \n float quaX = axis.x * sin;\n float quaY = axis.y * sin;\n float quaZ = axis.z * sin;\n float quaW = cos(halfAngle);\n \n //vec4 q=vec4(quaX,quaY,quaZ,quaW);\n //vec3 temp = cross(q.xyz, vector) + q.w * vector;\n //return (cross(temp, -q.xyz) + dot(q.xyz,vector) * q.xyz + q.w * temp);\n \n float x = quaX + quaX;\n float y = quaY + quaY;\n float z = quaZ + quaZ;\n float wx = quaW * x;\n float wy = quaW * y;\n float wz = quaW * z;\n float xx = quaX * x;\n float xy = quaX * y;\n float xz = quaX * z;\n float yy = quaY * y;\n float yz = quaY * z;\n float zz = quaZ * z;\n\n return vec3(((vector.x * ((1.0 - yy) - zz)) + (vector.y * (xy - wz))) + (vector.z * (xz + wy)),\n ((vector.x * (xy + wz)) + (vector.y * ((1.0 - xx) - zz))) + (vector.z * (yz - wx)),\n ((vector.x * (xz - wy)) + (vector.y * (yz + wx))) + (vector.z * ((1.0 - xx) - yy)));\n \n}\n\nvec3 rotationByQuaternions(in vec3 v,in vec4 q) \n{\n return v + 2.0 * cross(q.xyz, cross(q.xyz, v) + q.w * v);\n}\n\n \n#if defined(VELOCITYOVERLIFETIMECURVE)||defined(VELOCITYOVERLIFETIMERANDOMCURVE)||defined(SIZEOVERLIFETIMECURVE)||defined(SIZEOVERLIFETIMECURVESEPERATE)||defined(SIZEOVERLIFETIMERANDOMCURVES)||defined(SIZEOVERLIFETIMERANDOMCURVESSEPERATE)\nfloat getCurValueFromGradientFloat(in vec2 gradientNumbers[4],in float normalizedAge)\n{\n float curValue;\n for(int i=1;i<4;i++)\n {\n vec2 gradientNumber=gradientNumbers[i];\n float key=gradientNumber.x;\n if(key>=normalizedAge)\n {\n vec2 lastGradientNumber=gradientNumbers[i-1];\n float lastKey=lastGradientNumber.x;\n float age=(normalizedAge-lastKey)/(key-lastKey);\n curValue=mix(lastGradientNumber.y,gradientNumber.y,age);\n break;\n }\n }\n return curValue;\n}\n#endif\n\n#if defined(VELOCITYOVERLIFETIMECURVE)||defined(VELOCITYOVERLIFETIMERANDOMCURVE)||defined(ROTATIONOVERLIFETIMECURVE)||defined(ROTATIONOVERLIFETIMERANDOMCURVES)\nfloat getTotalValueFromGradientFloat(in vec2 gradientNumbers[4],in float normalizedAge)\n{\n float totalValue=0.0;\n for(int i=1;i<4;i++)\n {\n vec2 gradientNumber=gradientNumbers[i];\n float key=gradientNumber.x;\n vec2 lastGradientNumber=gradientNumbers[i-1];\n float lastValue=lastGradientNumber.y;\n \n if(key>=normalizedAge){\n float lastKey=lastGradientNumber.x;\n float age=(normalizedAge-lastKey)/(key-lastKey);\n totalValue+=(lastValue+mix(lastValue,gradientNumber.y,age))/2.0*a_ShapePositionStartLifeTime.w*(normalizedAge-lastKey);\n break;\n }\n else{\n totalValue+=(lastValue+gradientNumber.y)/2.0*a_ShapePositionStartLifeTime.w*(key-lastGradientNumber.x);\n }\n }\n return totalValue;\n}\n#endif\n\n#if defined(COLOROVERLIFETIME)||defined(RANDOMCOLOROVERLIFETIME)\nvec4 getColorFromGradient(in vec2 gradientAlphas[4],in vec4 gradientColors[4],in float normalizedAge)\n{\n vec4 overTimeColor;\n for(int i=1;i<4;i++)\n {\n vec2 gradientAlpha=gradientAlphas[i];\n float alphaKey=gradientAlpha.x;\n if(alphaKey>=normalizedAge)\n {\n vec2 lastGradientAlpha=gradientAlphas[i-1];\n float lastAlphaKey=lastGradientAlpha.x;\n float age=(normalizedAge-lastAlphaKey)/(alphaKey-lastAlphaKey);\n overTimeColor.a=mix(lastGradientAlpha.y,gradientAlpha.y,age);\n break;\n }\n }\n \n for(int i=1;i<4;i++)\n {\n vec4 gradientColor=gradientColors[i];\n float colorKey=gradientColor.x;\n if(colorKey>=normalizedAge)\n {\n vec4 lastGradientColor=gradientColors[i-1];\n float lastColorKey=lastGradientColor.x;\n float age=(normalizedAge-lastColorKey)/(colorKey-lastColorKey);\n overTimeColor.rgb=mix(gradientColors[i-1].yzw,gradientColor.yzw,age);\n break;\n }\n }\n return overTimeColor;\n}\n#endif\n\n\n#if defined(TEXTURESHEETANIMATIONCURVE)||defined(TEXTURESHEETANIMATIONRANDOMCURVE)\nfloat getFrameFromGradient(in vec2 gradientFrames[4],in float normalizedAge)\n{\n float overTimeFrame;\n for(int i=1;i<4;i++)\n {\n vec2 gradientFrame=gradientFrames[i];\n float key=gradientFrame.x;\n if(key>=normalizedAge)\n {\n vec2 lastGradientFrame=gradientFrames[i-1];\n float lastKey=lastGradientFrame.x;\n float age=(normalizedAge-lastKey)/(key-lastKey);\n overTimeFrame=mix(lastGradientFrame.y,gradientFrame.y,age);\n break;\n }\n }\n return floor(overTimeFrame);\n}\n#endif\n\n#if defined(VELOCITYOVERLIFETIMECONSTANT)||defined(VELOCITYOVERLIFETIMECURVE)||defined(VELOCITYOVERLIFETIMERANDOMCONSTANT)||defined(VELOCITYOVERLIFETIMERANDOMCURVE)\nvec3 computeParticleLifeVelocity(in float normalizedAge)\n{\n vec3 outLifeVelocity;\n #ifdef VELOCITYOVERLIFETIMECONSTANT\n outLifeVelocity=u_VOLVelocityConst; \n #endif\n #ifdef VELOCITYOVERLIFETIMECURVE\n outLifeVelocity= vec3(getCurValueFromGradientFloat(u_VOLVelocityGradientX,normalizedAge),getCurValueFromGradientFloat(u_VOLVelocityGradientY,normalizedAge),getCurValueFromGradientFloat(u_VOLVelocityGradientZ,normalizedAge));\n #endif\n #ifdef VELOCITYOVERLIFETIMERANDOMCONSTANT\n outLifeVelocity=mix(u_VOLVelocityConst,u_VOLVelocityConstMax,vec3(a_Random1.y,a_Random1.z,a_Random1.w)); \n #endif\n #ifdef VELOCITYOVERLIFETIMERANDOMCURVE\n outLifeVelocity=vec3(mix(getCurValueFromGradientFloat(u_VOLVelocityGradientX,normalizedAge),getCurValueFromGradientFloat(u_VOLVelocityGradientMaxX,normalizedAge),a_Random1.y),\n mix(getCurValueFromGradientFloat(u_VOLVelocityGradientY,normalizedAge),getCurValueFromGradientFloat(u_VOLVelocityGradientMaxY,normalizedAge),a_Random1.z),\n mix(getCurValueFromGradientFloat(u_VOLVelocityGradientZ,normalizedAge),getCurValueFromGradientFloat(u_VOLVelocityGradientMaxZ,normalizedAge),a_Random1.w));\n #endif\n \n return outLifeVelocity;\n} \n#endif\n\nvec3 computeParticlePosition(in vec3 startVelocity, in vec3 lifeVelocity,in float age,in float normalizedAge,vec3 gravityVelocity,vec4 worldRotation)\n{\n vec3 startPosition;\n vec3 lifePosition;\n #if defined(VELOCITYOVERLIFETIMECONSTANT)||defined(VELOCITYOVERLIFETIMECURVE)||defined(VELOCITYOVERLIFETIMERANDOMCONSTANT)||defined(VELOCITYOVERLIFETIMERANDOMCURVE)\n #ifdef VELOCITYOVERLIFETIMECONSTANT\n startPosition=startVelocity*age;\n lifePosition=lifeVelocity*age;\n #endif\n #ifdef VELOCITYOVERLIFETIMECURVE\n startPosition=startVelocity*age;\n lifePosition=vec3(getTotalValueFromGradientFloat(u_VOLVelocityGradientX,normalizedAge),getTotalValueFromGradientFloat(u_VOLVelocityGradientY,normalizedAge),getTotalValueFromGradientFloat(u_VOLVelocityGradientZ,normalizedAge));\n #endif\n #ifdef VELOCITYOVERLIFETIMERANDOMCONSTANT\n startPosition=startVelocity*age;\n lifePosition=lifeVelocity*age;\n #endif\n #ifdef VELOCITYOVERLIFETIMERANDOMCURVE\n startPosition=startVelocity*age;\n lifePosition=vec3(mix(getTotalValueFromGradientFloat(u_VOLVelocityGradientX,normalizedAge),getTotalValueFromGradientFloat(u_VOLVelocityGradientMaxX,normalizedAge),a_Random1.y)\n ,mix(getTotalValueFromGradientFloat(u_VOLVelocityGradientY,normalizedAge),getTotalValueFromGradientFloat(u_VOLVelocityGradientMaxY,normalizedAge),a_Random1.z)\n ,mix(getTotalValueFromGradientFloat(u_VOLVelocityGradientZ,normalizedAge),getTotalValueFromGradientFloat(u_VOLVelocityGradientMaxZ,normalizedAge),a_Random1.w));\n #endif\n \n vec3 finalPosition;\n if(u_VOLSpaceType==0){\n if(u_ScalingMode!=2)\n finalPosition =rotationByQuaternions(u_PositionScale*(a_ShapePositionStartLifeTime.xyz+startPosition+lifePosition),worldRotation);\n else\n finalPosition =rotationByQuaternions(u_PositionScale*a_ShapePositionStartLifeTime.xyz+startPosition+lifePosition,worldRotation);\n }\n else{\n if(u_ScalingMode!=2)\n finalPosition = rotationByQuaternions(u_PositionScale*(a_ShapePositionStartLifeTime.xyz+startPosition),worldRotation)+lifePosition;\n else\n finalPosition = rotationByQuaternions(u_PositionScale*a_ShapePositionStartLifeTime.xyz+startPosition,worldRotation)+lifePosition;\n }\n #else\n startPosition=startVelocity*age;\n vec3 finalPosition;\n if(u_ScalingMode!=2)\n finalPosition = rotationByQuaternions(u_PositionScale*(a_ShapePositionStartLifeTime.xyz+startPosition),worldRotation);\n else\n finalPosition = rotationByQuaternions(u_PositionScale*a_ShapePositionStartLifeTime.xyz+startPosition,worldRotation);\n #endif\n \n if(u_SimulationSpace==0)\n finalPosition=finalPosition+a_SimulationWorldPostion;\n else if(u_SimulationSpace==1) \n finalPosition=finalPosition+u_WorldPosition;\n \n finalPosition+=0.5*gravityVelocity*age;\n \n return finalPosition;\n}\n\n\nvec4 computeParticleColor(in vec4 color,in float normalizedAge)\n{\n #ifdef COLOROVERLIFETIME\n color*=getColorFromGradient(u_ColorOverLifeGradientAlphas,u_ColorOverLifeGradientColors,normalizedAge);\n #endif\n \n #ifdef RANDOMCOLOROVERLIFETIME\n color*=mix(getColorFromGradient(u_ColorOverLifeGradientAlphas,u_ColorOverLifeGradientColors,normalizedAge),getColorFromGradient(u_MaxColorOverLifeGradientAlphas,u_MaxColorOverLifeGradientColors,normalizedAge),a_Random0.y);\n #endif\n\n return color;\n}\n\nvec2 computeParticleSizeBillbard(in vec2 size,in float normalizedAge)\n{\n #ifdef SIZEOVERLIFETIMECURVE\n size*=getCurValueFromGradientFloat(u_SOLSizeGradient,normalizedAge);\n #endif\n #ifdef SIZEOVERLIFETIMERANDOMCURVES\n size*=mix(getCurValueFromGradientFloat(u_SOLSizeGradient,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientMax,normalizedAge),a_Random0.z); \n #endif\n #ifdef SIZEOVERLIFETIMECURVESEPERATE\n size*=vec2(getCurValueFromGradientFloat(u_SOLSizeGradientX,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientY,normalizedAge));\n #endif\n #ifdef SIZEOVERLIFETIMERANDOMCURVESSEPERATE\n size*=vec2(mix(getCurValueFromGradientFloat(u_SOLSizeGradientX,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientMaxX,normalizedAge),a_Random0.z)\n ,mix(getCurValueFromGradientFloat(u_SOLSizeGradientY,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientMaxY,normalizedAge),a_Random0.z));\n #endif\n return size;\n}\n\n#ifdef RENDERMODE_MESH\nvec3 computeParticleSizeMesh(in vec3 size,in float normalizedAge)\n{\n #ifdef SIZEOVERLIFETIMECURVE\n size*=getCurValueFromGradientFloat(u_SOLSizeGradient,normalizedAge);\n #endif\n #ifdef SIZEOVERLIFETIMERANDOMCURVES\n size*=mix(getCurValueFromGradientFloat(u_SOLSizeGradient,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientMax,normalizedAge),a_Random0.z); \n #endif\n #ifdef SIZEOVERLIFETIMECURVESEPERATE\n size*=vec3(getCurValueFromGradientFloat(u_SOLSizeGradientX,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientY,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientZ,normalizedAge));\n #endif\n #ifdef SIZEOVERLIFETIMERANDOMCURVESSEPERATE\n size*=vec3(mix(getCurValueFromGradientFloat(u_SOLSizeGradientX,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientMaxX,normalizedAge),a_Random0.z)\n ,mix(getCurValueFromGradientFloat(u_SOLSizeGradientY,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientMaxY,normalizedAge),a_Random0.z)\n ,mix(getCurValueFromGradientFloat(u_SOLSizeGradientZ,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientMaxZ,normalizedAge),a_Random0.z));\n #endif\n return size;\n}\n#endif\n\nfloat computeParticleRotationFloat(in float rotation,in float age,in float normalizedAge)\n{ \n #ifdef ROTATIONOVERLIFETIME\n #ifdef ROTATIONOVERLIFETIMECONSTANT\n float ageRot=u_ROLAngularVelocityConst*age;\n rotation+=ageRot;\n #endif\n #ifdef ROTATIONOVERLIFETIMECURVE\n rotation+=getTotalValueFromGradientFloat(u_ROLAngularVelocityGradient,normalizedAge);\n #endif\n #ifdef ROTATIONOVERLIFETIMERANDOMCONSTANTS\n float ageRot=mix(u_ROLAngularVelocityConst,u_ROLAngularVelocityConstMax,a_Random0.w)*age;\n rotation+=ageRot;\n #endif\n #ifdef ROTATIONOVERLIFETIMERANDOMCURVES\n rotation+=mix(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradient,normalizedAge),getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientMax,normalizedAge),a_Random0.w);\n #endif\n #endif\n #ifdef ROTATIONOVERLIFETIMESEPERATE\n #ifdef ROTATIONOVERLIFETIMECONSTANT\n float ageRot=u_ROLAngularVelocityConstSeprarate.z*age;\n rotation+=ageRot;\n #endif\n #ifdef ROTATIONOVERLIFETIMECURVE\n rotation+=getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientZ,normalizedAge);\n #endif\n #ifdef ROTATIONOVERLIFETIMERANDOMCONSTANTS\n float ageRot=mix(u_ROLAngularVelocityConstSeprarate.z,u_ROLAngularVelocityConstMaxSeprarate.z,a_Random0.w)*age;\n rotation+=ageRot;\n #endif\n #ifdef ROTATIONOVERLIFETIMERANDOMCURVES\n rotation+=mix(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientZ,normalizedAge),getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientMaxZ,normalizedAge),a_Random0.w));\n #endif\n #endif\n return rotation;\n}\n\n#if defined(RENDERMODE_MESH)&&(defined(ROTATIONOVERLIFETIME)||defined(ROTATIONOVERLIFETIMESEPERATE))\nvec3 computeParticleRotationVec3(in vec3 rotation,in float age,in float normalizedAge)\n{ \n #ifdef ROTATIONOVERLIFETIME\n #ifdef ROTATIONOVERLIFETIMECONSTANT\n float ageRot=u_ROLAngularVelocityConst*age;\n rotation+=ageRot;\n #endif\n #ifdef ROTATIONOVERLIFETIMECURVE\n rotation+=getTotalValueFromGradientFloat(u_ROLAngularVelocityGradient,normalizedAge);\n #endif\n #ifdef ROTATIONOVERLIFETIMERANDOMCONSTANTS\n float ageRot=mix(u_ROLAngularVelocityConst,u_ROLAngularVelocityConstMax,a_Random0.w)*age;\n rotation+=ageRot;\n #endif\n #ifdef ROTATIONOVERLIFETIMERANDOMCURVES\n rotation+=mix(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradient,normalizedAge),getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientMax,normalizedAge),a_Random0.w);\n #endif\n #endif\n #ifdef ROTATIONOVERLIFETIMESEPERATE\n #ifdef ROTATIONOVERLIFETIMECONSTANT\n vec3 ageRot=u_ROLAngularVelocityConstSeprarate*age;\n rotation+=ageRot;\n #endif\n #ifdef ROTATIONOVERLIFETIMECURVE\n rotation+=vec3(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientX,normalizedAge),getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientY,normalizedAge),getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientZ,normalizedAge));\n #endif\n #ifdef ROTATIONOVERLIFETIMERANDOMCONSTANTS\n vec3 ageRot=mix(u_ROLAngularVelocityConstSeprarate,u_ROLAngularVelocityConstMaxSeprarate,a_Random0.w)*age;\n rotation+=ageRot;\n #endif\n #ifdef ROTATIONOVERLIFETIMERANDOMCURVES\n rotation+=vec3(mix(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientX,normalizedAge),getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientMaxX,normalizedAge),a_Random0.w)\n ,mix(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientY,normalizedAge),getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientMaxY,normalizedAge),a_Random0.w)\n ,mix(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientZ,normalizedAge),getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientMaxZ,normalizedAge),a_Random0.w));\n #endif\n #endif\n return rotation;\n}\n#endif\n\nvec2 computeParticleUV(in vec2 uv,in float normalizedAge)\n{ \n #ifdef TEXTURESHEETANIMATIONCURVE\n float cycleNormalizedAge=normalizedAge*u_TSACycles;\n float frame=getFrameFromGradient(u_TSAGradientUVs,cycleNormalizedAge-floor(cycleNormalizedAge));\n float totalULength=frame*u_TSASubUVLength.x;\n float floorTotalULength=floor(totalULength);\n uv.x+=totalULength-floorTotalULength;\n uv.y+=floorTotalULength*u_TSASubUVLength.y;\n #endif\n #ifdef TEXTURESHEETANIMATIONRANDOMCURVE\n float cycleNormalizedAge=normalizedAge*u_TSACycles;\n float uvNormalizedAge=cycleNormalizedAge-floor(cycleNormalizedAge);\n float frame=floor(mix(getFrameFromGradient(u_TSAGradientUVs,uvNormalizedAge),getFrameFromGradient(u_TSAMaxGradientUVs,uvNormalizedAge),a_Random1.x));\n float totalULength=frame*u_TSASubUVLength.x;\n float floorTotalULength=floor(totalULength);\n uv.x+=totalULength-floorTotalULength;\n uv.y+=floorTotalULength*u_TSASubUVLength.y;\n #endif\n return uv;\n}\n\nvoid main()\n{\n float age = u_CurrentTime - a_DirectionTime.w;\n float normalizedAge = age/a_ShapePositionStartLifeTime.w;\n vec3 lifeVelocity;\n if(normalizedAge<1.0){ \n vec3 startVelocity=a_DirectionTime.xyz*a_StartSpeed;\n #if defined(VELOCITYOVERLIFETIMECONSTANT)||defined(VELOCITYOVERLIFETIMECURVE)||defined(VELOCITYOVERLIFETIMERANDOMCONSTANT)||defined(VELOCITYOVERLIFETIMERANDOMCURVE)\n lifeVelocity= computeParticleLifeVelocity(normalizedAge);//计算粒子生命周期速度\n #endif \n vec3 gravityVelocity=u_Gravity*age;\n \n vec4 worldRotation;\n if(u_SimulationSpace==0)\n worldRotation=a_SimulationWorldRotation;\n else\n worldRotation=u_WorldRotation;\n \n vec3 center=computeParticlePosition(startVelocity, lifeVelocity, age, normalizedAge,gravityVelocity,worldRotation);//计算粒子位置\n \n \n #ifdef SPHERHBILLBOARD\n vec2 corner=a_CornerTextureCoordinate.xy;//Billboard模式z轴无效\n vec3 cameraUpVector =normalize(u_CameraUp);//TODO:是否外面归一化\n vec3 sideVector = normalize(cross(u_CameraDirection,cameraUpVector));\n vec3 upVector = normalize(cross(sideVector,u_CameraDirection));\n corner*=computeParticleSizeBillbard(a_StartSize.xy,normalizedAge);\n #if defined(ROTATIONOVERLIFETIME)||defined(ROTATIONOVERLIFETIMESEPERATE)\n if(u_ThreeDStartRotation){\n vec3 rotation=vec3(a_StartRotation0.xy,computeParticleRotationFloat(a_StartRotation0.z,age,normalizedAge));\n center += u_SizeScale.xzy*rotationByEuler(corner.x*sideVector+corner.y*upVector,rotation);\n }\n else{\n float rot = computeParticleRotationFloat(a_StartRotation0.x, age,normalizedAge);\n float c = cos(rot);\n float s = sin(rot);\n mat2 rotation= mat2(c, -s, s, c);\n corner=rotation*corner;\n center += u_SizeScale.xzy*(corner.x*sideVector+corner.y*upVector);\n }\n #else\n if(u_ThreeDStartRotation){\n center += u_SizeScale.xzy*rotationByEuler(corner.x*sideVector+corner.y*upVector,a_StartRotation0);\n }\n else{\n float c = cos(a_StartRotation0.x);\n float s = sin(a_StartRotation0.x);\n mat2 rotation= mat2(c, -s, s, c);\n corner=rotation*corner;\n center += u_SizeScale.xzy*(corner.x*sideVector+corner.y*upVector);\n }\n #endif\n #endif\n \n #ifdef STRETCHEDBILLBOARD\n vec2 corner=a_CornerTextureCoordinate.xy;//Billboard模式z轴无效\n vec3 velocity;\n #if defined(VELOCITYOVERLIFETIMECONSTANT)||defined(VELOCITYOVERLIFETIMECURVE)||defined(VELOCITYOVERLIFETIMERANDOMCONSTANT)||defined(VELOCITYOVERLIFETIMERANDOMCURVE)\n if(u_VOLSpaceType==0)\n velocity=rotationByQuaternions(u_SizeScale*(startVelocity+lifeVelocity),worldRotation)+gravityVelocity;\n else\n velocity=rotationByQuaternions(u_SizeScale*startVelocity,worldRotation)+lifeVelocity+gravityVelocity;\n #else\n velocity= rotationByQuaternions(u_SizeScale*startVelocity,worldRotation)+gravityVelocity;\n #endif \n vec3 cameraUpVector = normalize(velocity);\n vec3 direction = normalize(center-u_CameraPosition);\n vec3 sideVector = normalize(cross(direction,normalize(velocity)));\n \n sideVector=u_SizeScale.xzy*sideVector;\n cameraUpVector=length(vec3(u_SizeScale.x,0.0,0.0))*cameraUpVector;\n \n vec2 size=computeParticleSizeBillbard(a_StartSize.xy,normalizedAge);\n \n const mat2 rotaionZHalfPI=mat2(0.0, -1.0, 1.0, 0.0);\n corner=rotaionZHalfPI*corner;\n corner.y=corner.y-abs(corner.y);\n \n float speed=length(velocity);//TODO:\n center +=sign(u_SizeScale.x)*(sign(u_StretchedBillboardLengthScale)*size.x*corner.x*sideVector+(speed*u_StretchedBillboardSpeedScale+size.y*u_StretchedBillboardLengthScale)*corner.y*cameraUpVector);\n #endif\n \n #ifdef HORIZONTALBILLBOARD\n vec2 corner=a_CornerTextureCoordinate.xy;//Billboard模式z轴无效\n const vec3 cameraUpVector=vec3(0.0,0.0,1.0);\n const vec3 sideVector = vec3(-1.0,0.0,0.0);\n \n float rot = computeParticleRotationFloat(a_StartRotation0.x, age,normalizedAge);\n float c = cos(rot);\n float s = sin(rot);\n mat2 rotation= mat2(c, -s, s, c);\n corner=rotation*corner*cos(0.78539816339744830961566084581988);//TODO:临时缩小cos45,不确定U3D原因\n corner*=computeParticleSizeBillbard(a_StartSize.xy,normalizedAge);\n center +=u_SizeScale.xzy*(corner.x*sideVector+ corner.y*cameraUpVector);\n #endif\n \n #ifdef VERTICALBILLBOARD\n vec2 corner=a_CornerTextureCoordinate.xy;//Billboard模式z轴无效\n const vec3 cameraUpVector =vec3(0.0,1.0,0.0);\n vec3 sideVector = normalize(cross(u_CameraDirection,cameraUpVector));\n \n float rot = computeParticleRotationFloat(a_StartRotation0.x, age,normalizedAge);\n float c = cos(rot);\n float s = sin(rot);\n mat2 rotation= mat2(c, -s, s, c);\n corner=rotation*corner*cos(0.78539816339744830961566084581988);//TODO:临时缩小cos45,不确定U3D原因\n corner*=computeParticleSizeBillbard(a_StartSize.xy,normalizedAge);\n center +=u_SizeScale.xzy*(corner.x*sideVector+ corner.y*cameraUpVector);\n #endif\n \n #ifdef RENDERMODE_MESH\n vec3 size=computeParticleSizeMesh(a_StartSize,normalizedAge);\n #if defined(ROTATIONOVERLIFETIME)||defined(ROTATIONOVERLIFETIMESEPERATE)\n if(u_ThreeDStartRotation){\n vec3 rotation=vec3(a_StartRotation0.xy,computeParticleRotationFloat(a_StartRotation0.z, age,normalizedAge));\n center+= rotationByQuaternions(u_SizeScale*rotationByEuler(a_MeshPosition*size,rotation),worldRotation);\n }\n else{\n #ifdef ROTATIONOVERLIFETIME\n float angle=computeParticleRotationFloat(a_StartRotation0.x, age,normalizedAge);\n if(a_ShapePositionStartLifeTime.x!=0.0||a_ShapePositionStartLifeTime.y!=0.0){\n center+= (rotationByQuaternions(rotationByAxis(u_SizeScale*a_MeshPosition*size,normalize(cross(vec3(0.0,0.0,1.0),vec3(a_ShapePositionStartLifeTime.xy,0.0))),angle),worldRotation));//已验证\n }\n else{\n #ifdef SHAPE\n center+= u_SizeScale.xzy*(rotationByQuaternions(rotationByAxis(a_MeshPosition*size,vec3(0.0,-1.0,0.0),angle),worldRotation));\n #else\n if(u_SimulationSpace==0)\n center+=rotationByAxis(u_SizeScale*a_MeshPosition*size,vec3(0.0,0.0,-1.0),angle);//已验证\n else if(u_SimulationSpace==1)\n center+=rotationByQuaternions(u_SizeScale*rotationByAxis(a_MeshPosition*size,vec3(0.0,0.0,-1.0),angle),worldRotation);//已验证\n #endif\n }\n #endif\n #ifdef ROTATIONOVERLIFETIMESEPERATE\n //TODO:是否应合并if(u_ThreeDStartRotation)分支代码,待测试\n vec3 angle=computeParticleRotationVec3(vec3(0.0,0.0,-a_StartRotation0.x), age,normalizedAge);\n center+= (rotationByQuaternions(rotationByEuler(u_SizeScale*a_MeshPosition*size,vec3(angle.x,angle.y,angle.z)),worldRotation));//已验证\n #endif \n }\n #else\n if(u_ThreeDStartRotation){\n center+= rotationByQuaternions(u_SizeScale*rotationByEuler(a_MeshPosition*size,a_StartRotation0),worldRotation);//已验证\n }\n else{\n if(a_ShapePositionStartLifeTime.x!=0.0||a_ShapePositionStartLifeTime.y!=0.0){\n if(u_SimulationSpace==0)\n center+= rotationByAxis(u_SizeScale*a_MeshPosition*size,normalize(cross(vec3(0.0,0.0,1.0),vec3(a_ShapePositionStartLifeTime.xy,0.0))),a_StartRotation0.x);\n else if(u_SimulationSpace==1)\n center+= (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));//已验证\n }\n else{\n #ifdef SHAPE\n if(u_SimulationSpace==0)\n center+= u_SizeScale*rotationByAxis(a_MeshPosition*size,vec3(0.0,-1.0,0.0),a_StartRotation0.x);\n else if(u_SimulationSpace==1)\n center+= rotationByQuaternions(u_SizeScale*rotationByAxis(a_MeshPosition*size,vec3(0.0,-1.0,0.0),a_StartRotation0.x),worldRotation); \n #else\n if(u_SimulationSpace==0)\n center+= rotationByAxis(u_SizeScale*a_MeshPosition*size,vec3(0.0,0.0,-1.0),a_StartRotation0.x);\n else if(u_SimulationSpace==1)\n center+= rotationByQuaternions(u_SizeScale*rotationByAxis(a_MeshPosition*size,vec3(0.0,0.0,-1.0),a_StartRotation0.x),worldRotation);//已验证\n #endif\n }\n }\n #endif\n v_MeshColor=a_MeshColor;\n #endif\n \n gl_Position=u_Projection*u_View*vec4(center,1.0);\n v_Color = computeParticleColor(a_StartColor, normalizedAge);\n #ifdef DIFFUSEMAP\n #if defined(SPHERHBILLBOARD)||defined(STRETCHEDBILLBOARD)||defined(HORIZONTALBILLBOARD)||defined(VERTICALBILLBOARD)\n v_TextureCoordinate =computeParticleUV(a_CornerTextureCoordinate.zw, normalizedAge);\n #endif\n #ifdef RENDERMODE_MESH\n v_TextureCoordinate =computeParticleUV(a_MeshTextureCoordinate, normalizedAge);\n #endif\n \n #ifdef TILINGOFFSET\n v_TextureCoordinate=vec2(v_TextureCoordinate.x,1.0-v_TextureCoordinate.y)*u_TilingOffset.xy+vec2(u_TilingOffset.z,-u_TilingOffset.w);//需要特殊处理\n v_TextureCoordinate=vec2(v_TextureCoordinate.x,1.0-v_TextureCoordinate.y);//需要特殊处理\n #endif\n #endif\n v_Discard=0.0;\n \n #ifdef FOG\n v_PositionWorld=center;\n #endif\n }\n else\n {\n v_Discard=1.0;\n }\n gl_Position=remapGLPositionZ(gl_Position);\n}\n\n";
- ps="#ifdef HIGHPRECISION\n precision highp float;\n#else\n precision mediump float;\n#endif\n\nvarying float v_Discard;\nvarying vec4 v_Color;\nvarying vec2 v_TextureCoordinate;\nuniform sampler2D u_texture;\nuniform vec4 u_Tintcolor;\n\n#ifdef RENDERMODE_MESH\n varying vec4 v_MeshColor;\n#endif\n\n#ifdef FOG\n varying vec3 v_PositionWorld;\n uniform vec3 u_CameraPosition;\n uniform float u_FogStart;\n uniform float u_FogRange;\n #ifdef ADDTIVEFOG\n #else\n uniform vec3 u_FogColor;\n #endif\n#endif\n\n\nvoid main()\n{ \n #ifdef RENDERMODE_MESH\n gl_FragColor=v_MeshColor;\n #else\n gl_FragColor=vec4(1.0); \n #endif\n \n #ifdef DIFFUSEMAP\n if(v_Discard!=0.0)\n discard;\n #ifdef TINTCOLOR\n gl_FragColor*=texture2D(u_texture,v_TextureCoordinate)*u_Tintcolor*2.0*v_Color;\n #else\n gl_FragColor*=texture2D(u_texture,v_TextureCoordinate)*v_Color;\n #endif\n #else\n #ifdef TINTCOLOR\n gl_FragColor*=u_Tintcolor*2.0*v_Color;\n #else\n gl_FragColor*=v_Color;\n #endif\n #endif\n \n #ifdef FOG\n vec3 toEye=u_CameraPosition-v_PositionWorld;\n float toEyeLength=length(toEye);\n toEye/=toEyeLength;\n \n float lerpFact=clamp((toEyeLength-u_FogStart)/u_FogRange,0.0,1.0);\n #ifdef ADDTIVEFOG\n gl_FragColor.rgb=mix(gl_FragColor.rgb,vec3(0.0,0.0,0.0),lerpFact);\n #else\n gl_FragColor.rgb=mix(gl_FragColor.rgb,u_FogColor,lerpFact);\n #endif\n #endif\n}";
- shader=Shader3D.add("PARTICLESHURIKEN");
- subShader=new SubShader(attributeMap,uniformMap,ShuriKenParticle3D.shaderDefines,ShurikenParticleMaterial.shaderDefines);
- shader.addSubShader(subShader);
- subShader.addShaderPass(vs,ps,stateMap);
- attributeMap={
- 'a_Position':/*laya.d3.graphics.Vertex.VertexMesh.MESH_POSITION0*/0};
- uniformMap={
- 'u_TintColor':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_Exposure':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_Rotation':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_CubeTexture':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_MvpMatrix':/*laya.d3.shader.Shader3D.PERIOD_CAMERA*/3};
- vs="#include \"Lighting.glsl\";\n\nattribute vec4 a_Position;\nuniform mat4 u_MvpMatrix;\nuniform float u_Rotation;\nvarying vec3 v_Texcoord;\n\n\nvec4 rotateAroundYInDegrees (vec4 vertex, float degrees)\n{\n float angle = degrees * 3.141593 / 180.0;\n float sina=sin(angle);\n float cosa=cos(angle);\n mat2 m = mat2(cosa, -sina, sina, cosa);\n return vec4(m*vertex.xz, vertex.yw).xzyw;\n}\n \nvoid main()\n{\n vec4 position=rotateAroundYInDegrees(a_Position,u_Rotation);\n gl_Position = (u_MvpMatrix*position).xyww;\n v_Texcoord=vec3(-a_Position.x,a_Position.yz);//转换坐标系\n gl_Position=remapGLPositionZ(gl_Position);\n}\n";
- ps="#ifdef HIGHPRECISION\nprecision highp float;\n#else\nprecision mediump float;\n#endif\n\nvarying vec3 v_Texcoord;\n\nuniform samplerCube u_CubeTexture;\nuniform float u_Exposure;\nuniform vec4 u_TintColor;\n\n\nvoid main()\n{ \n vec3 color=textureCube(u_CubeTexture, v_Texcoord).rgb*u_TintColor.rgb*u_Exposure*2.0;\n gl_FragColor=vec4(color,1.0);\n}\n\n";
- shader=Shader3D.add("SkyBox");
- subShader=new SubShader(attributeMap,uniformMap);
- shader.addSubShader(subShader);
- subShader.addShaderPass(vs,ps);
- attributeMap={
- 'a_Position':/*laya.d3.graphics.Vertex.VertexMesh.MESH_POSITION0*/0};
- uniformMap={
- 'u_SunSize':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_SunSizeConvergence':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_AtmosphereThickness':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_SkyTint':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_GroundTint':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_Exposure':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_MvpMatrix':/*laya.d3.shader.Shader3D.PERIOD_CAMERA*/3,
- 'u_DirectionLight.Direction':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_DirectionLight.Color':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4
- };
- vs="#ifdef HIGHPRECISION\n precision highp float;\n#else\n precision mediump float;\n#endif\n\n#include \"Lighting.glsl\";\n\n#define OUTER_RADIUS 1.025\n#define RAYLEIGH (mix(0.0, 0.0025, pow(u_AtmosphereThickness,2.5)))// Rayleigh constant Rayleigh为夜空光和极光亮度单位\n#define MIE 0.0010 // Mie constant 米氏散射\n#define SUN_BRIGHTNESS 20.0 // Sun brightness\n#define MAX_SCATTER 50.0 // Maximum scattering value, to prevent math overflows on Adrenos\n\nconst float SKY_GROUND_THRESHOLD = 0.02;\nconst float outerRadius = OUTER_RADIUS;\nconst float outerRadius2 = OUTER_RADIUS*OUTER_RADIUS;\nconst float innerRadius = 1.0;\nconst float innerRadius2 = 1.0;\nconst float cameraHeight = 0.0001;\n\nconst float HDSundiskIntensityFactor = 15.0;\nconst float simpleSundiskIntensityFactor = 27.0;\n\nconst float sunScale = 400.0 * SUN_BRIGHTNESS;\nconst float kmESun = MIE * SUN_BRIGHTNESS;\nconst float km4PI = MIE * 4.0 * 3.14159265;\nconst float scale = 1.0 / (OUTER_RADIUS - 1.0);\nconst float scaleDepth = 0.25;\nconst float scaleOverScaleDepth = (1.0 / (OUTER_RADIUS - 1.0)) / 0.25;\nconst float samples = 2.0; // THIS IS UNROLLED MANUALLY, DON'T TOUCH\n\n// RGB wavelengths .35 (.62=158), .43 (.68=174), .525 (.75=190)\nconst vec3 c_DefaultScatteringWavelength = vec3(0.65, 0.57, 0.475);//默认散射波长\nconst vec3 c_VariableRangeForScatteringWavelength = vec3(0.15, 0.15, 0.15);//散射播放的可变范围\n\nattribute vec4 a_Position;\n\nuniform mat4 u_MvpMatrix;\nuniform vec3 u_SkyTint;\nuniform vec3 u_GroundTint;\nuniform float u_Exposure;\nuniform float u_AtmosphereThickness;\nuniform DirectionLight u_DirectionLight;\n\nvarying vec3 v_GroundColor;\nvarying vec3 v_SkyColor;\n\n#ifdef SUN_HIGH_QUALITY\n varying vec3 v_Vertex;\n#elif defined(SUN_SIMPLE)\n varying vec3 v_RayDir;\n#else\n varying float v_SkyGroundFactor;\n#endif\n\n#if defined(SUN_HIGH_QUALITY)||defined(SUN_SIMPLE)\n varying vec3 v_SunColor;\n#endif\n\n// Calculates the Rayleigh phase function\nfloat getRayleighPhase(vec3 light, vec3 ray) \n{\n float eyeCos = dot(light, ray);\n return 0.75 + 0.75*eyeCos*eyeCos;\n}\n\nfloat scaleAngle(float inCos)\n{\n float x = 1.0 - inCos;\n return 0.25 * exp(-0.00287 + x*(0.459 + x*(3.83 + x*(-6.80 + x*5.25))));\n}\n\n\nvoid main () {\n gl_Position = (u_MvpMatrix*a_Position).xyww;\n\n vec3 skyTintInGammaSpace = u_SkyTint;//支持非GAMMA空间后要调整\n vec3 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\n vec3 invWavelength = 1.0 / pow(scatteringWavelength, vec3(4.0));\n\n float krESun = RAYLEIGH * SUN_BRIGHTNESS;\n float kr4PI = RAYLEIGH * 4.0 * 3.14159265;\n\n vec3 cameraPos = vec3(0.0,innerRadius + cameraHeight,0.0); // The camera's current position\n\n // Get the ray from the camera to the vertex and its length (which is the far point of the ray passing through the atmosphere)\n vec3 eyeRay = normalize(a_Position.xyz);\n\n float far = 0.0;\n vec3 cIn, cOut;\n if (eyeRay.y >= 0.0) {// Sky\n // Calculate the length of the \"atmosphere\"\n far = sqrt(outerRadius2 + innerRadius2 * eyeRay.y * eyeRay.y - innerRadius2) - innerRadius * eyeRay.y;\n\n // Calculate the ray's starting position, then calculate its scattering offset\n float height = innerRadius + cameraHeight;\n float depth = exp(scaleOverScaleDepth * -cameraHeight);\n float startAngle = dot(eyeRay, cameraPos) / height;\n float startOffset = depth*scaleAngle(startAngle);\n\n // Initialize the scattering loop variables\n float sampleLength = far / samples;\n float scaledLength = sampleLength * scale;\n vec3 sampleRay = eyeRay * sampleLength;\n vec3 samplePoint = cameraPos + sampleRay * 0.5;\n\n vec3 frontColor = vec3(0.0);\n //unrolling this manually to avoid some platform for loop slow\n {\n float height = length(samplePoint);\n float depth = exp(scaleOverScaleDepth * (innerRadius - height));\n float lightAngle = dot(-u_DirectionLight.Direction, samplePoint) / height;\n float cameraAngle = dot(eyeRay, samplePoint) / height;\n float scatter = (startOffset + depth*(scaleAngle(lightAngle) - scaleAngle(cameraAngle)));\n vec3 attenuate = exp(-clamp(scatter, 0.0, MAX_SCATTER) * (invWavelength * kr4PI + km4PI));\n\n frontColor += attenuate * (depth * scaledLength);\n samplePoint += sampleRay;\n }\n {\n float height = length(samplePoint);\n float depth = exp(scaleOverScaleDepth * (innerRadius - height));\n float lightAngle = dot(-u_DirectionLight.Direction, samplePoint) / height;\n float cameraAngle = dot(eyeRay, samplePoint) / height;\n float scatter = (startOffset + depth*(scaleAngle(lightAngle) - scaleAngle(cameraAngle)));\n vec3 attenuate = exp(-clamp(scatter, 0.0, MAX_SCATTER) * (invWavelength * kr4PI + km4PI));\n\n frontColor += attenuate * (depth * scaledLength);\n samplePoint += sampleRay;\n }\n\n // Finally, scale the Mie and Rayleigh colors and set up the varying variables for the pixel shader\n cIn = frontColor * (invWavelength * krESun);\n cOut = frontColor * kmESun;\n } else {// Ground\n far = (-cameraHeight) / (min(-0.001, eyeRay.y));\n vec3 pos = cameraPos + far * eyeRay;\n\n // Calculate the ray's starting position, then calculate its scattering offset\n float depth = exp((-cameraHeight) * (1.0/scaleDepth));\n float cameraAngle = dot(-eyeRay, pos);\n float lightAngle = dot(-u_DirectionLight.Direction, pos);\n float cameraScale = scaleAngle(cameraAngle);\n float lightScale = scaleAngle(lightAngle);\n float cameraOffset = depth*cameraScale;\n float temp = lightScale + cameraScale;\n\n // Initialize the scattering loop variables\n float sampleLength = far / samples;\n float scaledLength = sampleLength * scale;\n vec3 sampleRay = eyeRay * sampleLength;\n vec3 samplePoint = cameraPos + sampleRay * 0.5;\n\n // Now loop through the sample rays\n vec3 frontColor = vec3(0.0, 0.0, 0.0);\n vec3 attenuate;\n\n // Loop removed because we kept hitting SM2.0 temp variable limits. Doesn't affect the image too much.\n {\n float height = length(samplePoint);\n float depth = exp(scaleOverScaleDepth * (innerRadius - height));\n float scatter = depth*temp - cameraOffset;\n attenuate = exp(-clamp(scatter, 0.0, MAX_SCATTER) * (invWavelength * kr4PI + km4PI));\n frontColor += attenuate * (depth * scaledLength);\n samplePoint += sampleRay;\n }\n\n cIn = frontColor * (invWavelength * krESun + kmESun);\n cOut = clamp(attenuate, 0.0, 1.0);\n }\n\n #ifdef SUN_HIGH_QUALITY\n v_Vertex = -a_Position.xyz;\n #elif defined(SUN_SIMPLE) \n v_RayDir = -eyeRay;\n #else\n v_SkyGroundFactor = -eyeRay.y / SKY_GROUND_THRESHOLD;\n #endif\n\n // if we want to calculate color in vprog:\n // 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)\n v_GroundColor = u_Exposure * (cIn + u_GroundTint*u_GroundTint * cOut);//u_GroundColor*u_GroundColor is gamma space convert to linear space\n v_SkyColor = u_Exposure * (cIn * getRayleighPhase(-u_DirectionLight.Direction, -eyeRay));\n\n \n // The sun should have a stable intensity in its course in the sky. Moreover it should match the highlight of a purely specular material.\n // This matching was done using the Unity3D standard shader BRDF1 on the 5/31/2017\n // Finally we want the sun to be always bright even in LDR thus the normalization of the lightColor for low intensity.\n float lightColorIntensity = clamp(length(u_DirectionLight.Color), 0.25, 1.0);\n\n #ifdef SUN_HIGH_QUALITY \n v_SunColor = HDSundiskIntensityFactor * clamp(cOut,0.0,1.0) * u_DirectionLight.Color / lightColorIntensity;\n #elif defined(SUN_SIMPLE) \n v_SunColor = simpleSundiskIntensityFactor * clamp(cOut * sunScale,0.0,1.0) * u_DirectionLight.Color / lightColorIntensity;\n #endif\n gl_Position=remapGLPositionZ(gl_Position);\n}\n";
- ps="#ifdef HIGHPRECISION\n precision highp float;\n#else\n precision mediump float;\n#endif\n\n#include \"Lighting.glsl\";\n\nconst float MIE_G = -0.990;\nconst float MIE_G2 = 0.9801;\nconst float SKY_GROUND_THRESHOLD = 0.02;\n\nuniform float u_SunSize;\nuniform float u_SunSizeConvergence;\nuniform DirectionLight u_DirectionLight;\n\n\nvarying vec3 v_GroundColor;\nvarying vec3 v_SkyColor;\n\n\n#ifdef SUN_HIGH_QUALITY\n varying vec3 v_Vertex;\n#elif defined(SUN_SIMPLE)\n varying vec3 v_RayDir;\n#else\n varying float v_SkyGroundFactor;\n#endif\n\n#if defined(SUN_HIGH_QUALITY)||defined(SUN_SIMPLE)\n varying vec3 v_SunColor;\n#endif\n\n// Calculates the Mie phase function\nfloat getMiePhase(float eyeCos, float eyeCos2) {\n float temp = 1.0 + MIE_G2 - 2.0 * MIE_G * eyeCos;\n temp = pow(temp, pow(u_SunSize,0.65) * 10.0);\n temp = max(temp,1.0e-4); // prevent division by zero, esp. in half precision\n temp = 1.5 * ((1.0 - MIE_G2) / (2.0 + MIE_G2)) * (1.0 + eyeCos2) / temp;\n return temp;\n}\n\n// Calculates the sun shape\nfloat calcSunAttenuation(vec3 lightPos, vec3 ray) {\n #ifdef SUN_HIGH_QUALITY\n float focusedEyeCos = pow(clamp(dot(lightPos, ray),0.0,1.0), u_SunSizeConvergence);\n return getMiePhase(-focusedEyeCos, focusedEyeCos * focusedEyeCos);\n #else //SUN_SIMPLE\n vec3 delta = lightPos - ray;\n float dist = length(delta);\n float spot = 1.0 - smoothstep(0.0, u_SunSize, dist);\n return spot * spot;\n #endif\n}\n\nvoid main() {\n // if y > 1 [eyeRay.y < -SKY_GROUND_THRESHOLD] - ground\n // if y >= 0 and < 1 [eyeRay.y <= 0 and > -SKY_GROUND_THRESHOLD] - horizon\n // if y < 0 [eyeRay.y > 0] - sky\n vec3 col = vec3(0.0, 0.0, 0.0);\n\n #ifdef SUN_HIGH_QUALITY\n vec3 ray = normalize(v_Vertex);\n float y = ray.y / SKY_GROUND_THRESHOLD;\n #elif defined(SUN_SIMPLE) \n vec3 ray = v_RayDir;\n float y = ray.y / SKY_GROUND_THRESHOLD; \n #else\n float y = v_SkyGroundFactor;\n #endif\n\n // if we did precalculate color in vprog: just do lerp between them\n col = mix(v_SkyColor, v_GroundColor, clamp(y,0.0,1.0));\n\n #if defined(SUN_HIGH_QUALITY)||defined(SUN_SIMPLE)\n if (y < 0.0)\n col += v_SunColor * calcSunAttenuation(-u_DirectionLight.Direction, -ray);\n #endif\n\n col = sqrt(col);//linear space convert to gamma space\n gl_FragColor=vec4(col,1.0);\n}\n\n";
- shader=Shader3D.add("SkyBoxProcedural");
- subShader=new SubShader(attributeMap,uniformMap,null,SkyProceduralMaterial.shaderDefines);
- shader.addSubShader(subShader);
- subShader.addShaderPass(vs,ps);
- attributeMap={
- 'a_Position':/*laya.d3.graphics.Vertex.VertexMesh.MESH_POSITION0*/0,
- 'a_Normal':/*laya.d3.graphics.Vertex.VertexMesh.MESH_NORMAL0*/3,
- 'a_Texcoord0':/*laya.d3.graphics.Vertex.VertexMesh.MESH_TEXTURECOORDINATE0*/2
- };
- uniformMap={
- 'u_MvpMatrix':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_WorldMat':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_CameraPos':/*laya.d3.shader.Shader3D.PERIOD_CAMERA*/3,
- 'u_LightmapScaleOffset':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_LightMap':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_SplatAlphaTexture':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_DiffuseTexture1':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_DiffuseTexture2':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_DiffuseTexture3':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_DiffuseTexture4':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_DiffuseTexture5':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_DiffuseScaleOffset1':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_DiffuseScaleOffset2':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_DiffuseScaleOffset3':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_DiffuseScaleOffset4':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_DiffuseScaleOffset5':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_FogStart':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_FogRange':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_FogColor':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_DirectionLight.Direction':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_DirectionLight.Color':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_PointLight.Position':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_PointLight.Range':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_PointLight.Attenuation':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_PointLight.Color':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_SpotLight.Position':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_SpotLight.Direction':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_SpotLight.Range':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_SpotLight.Spot':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_SpotLight.Color':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_AmbientColor':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_shadowMap1':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_shadowMap2':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_shadowMap3':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_shadowPSSMDistance':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_lightShadowVP':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_shadowPCFoffset':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4
- };
- stateMap={
- 's_Cull':/*laya.d3.shader.Shader3D.RENDER_STATE_CULL*/0,
- 's_Blend':/*laya.d3.shader.Shader3D.RENDER_STATE_BLEND*/1,
- 's_BlendSrc':/*laya.d3.shader.Shader3D.RENDER_STATE_BLEND_SRC*/2,
- 's_BlendDst':/*laya.d3.shader.Shader3D.RENDER_STATE_BLEND_DST*/3,
- 's_DepthTest':/*laya.d3.shader.Shader3D.RENDER_STATE_DEPTH_TEST*/12,
- 's_DepthWrite':/*laya.d3.shader.Shader3D.RENDER_STATE_DEPTH_WRITE*/13
- };
- vs="#include \"Lighting.glsl\";\n\nattribute vec4 a_Position;\nattribute vec2 a_Texcoord0;\n\nuniform mat4 u_MvpMatrix;\n\nvarying vec2 v_Texcoord0;\n\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(LIGHTMAP)\n attribute vec3 a_Normal;\n varying vec3 v_Normal;\n#endif\n\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(FOG)||(defined(RECEIVESHADOW)&&defined(SHADOWMAP_PSSM1))\n uniform mat4 u_WorldMat;\n varying vec3 v_PositionWorld;\n#endif\n\n#ifdef LIGHTMAP\n varying vec2 v_LightMapUV;\n uniform vec4 u_LightmapScaleOffset;\n#endif\n\n#ifdef RECEIVESHADOW\n varying float v_posViewZ;\n #ifdef SHADOWMAP_PSSM1 \n varying vec4 v_lightMVPPos;\n uniform mat4 u_lightShadowVP[4];\n #endif\n#endif\n\nvoid main()\n{\n gl_Position = u_MvpMatrix * a_Position;\n \n v_Texcoord0 = a_Texcoord0;\n \n #ifdef LIGHTMAP\n v_LightMapUV = vec2(a_Texcoord0.x, 1.0 - a_Texcoord0.y) * u_LightmapScaleOffset.xy + u_LightmapScaleOffset.zw;\n v_LightMapUV.y = 1.0 - v_LightMapUV.y;\n #endif\n \n #if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\n v_Normal = a_Normal;\n #endif\n\n #if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(FOG)||(defined(RECEIVESHADOW)&&defined(SHADOWMAP_PSSM1))\n v_PositionWorld=(u_WorldMat*a_Position).xyz;\n #endif\n\n #ifdef RECEIVESHADOW\n v_posViewZ = gl_Position.w;\n #ifdef SHADOWMAP_PSSM1\n v_lightMVPPos = u_lightShadowVP[0] * vec4(v_PositionWorld,1.0);\n #endif\n #endif\n gl_Position=remapGLPositionZ(gl_Position);\n}";
- ps="#ifdef HIGHPRECISION\n precision highp float;\n#else\n precision mediump float;\n#endif\n\n#include \"Lighting.glsl\";\n\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(FOG)\n uniform vec3 u_CameraPos;\n varying vec3 v_Normal;\n varying vec3 v_PositionWorld;\n#endif\n\n#ifdef FOG\n uniform float u_FogStart;\n uniform float u_FogRange;\n uniform vec3 u_FogColor;\n#endif\n\n\n#ifdef DIRECTIONLIGHT\n uniform DirectionLight u_DirectionLight;\n#endif\n\n#ifdef POINTLIGHT\n uniform PointLight u_PointLight;\n#endif\n\n#ifdef SPOTLIGHT\n uniform SpotLight u_SpotLight;\n#endif\n\n#include \"ShadowHelper.glsl\"\n#ifdef RECEIVESHADOW\n #if defined(SHADOWMAP_PSSM2)||defined(SHADOWMAP_PSSM3)\n uniform mat4 u_lightShadowVP[4];\n #endif\n #ifdef SHADOWMAP_PSSM1 \n varying vec4 v_lightMVPPos;\n #endif\n#endif\nvarying float v_posViewZ;\n\nuniform vec3 u_AmbientColor;\n\nuniform sampler2D u_SplatAlphaTexture;\n\nuniform sampler2D u_DiffuseTexture1;\nuniform sampler2D u_DiffuseTexture2;\nuniform sampler2D u_DiffuseTexture3;\nuniform sampler2D u_DiffuseTexture4;\nuniform sampler2D u_DiffuseTexture5;\n\nuniform vec4 u_DiffuseScaleOffset1;\nuniform vec4 u_DiffuseScaleOffset2;\nuniform vec4 u_DiffuseScaleOffset3;\nuniform vec4 u_DiffuseScaleOffset4;\nuniform vec4 u_DiffuseScaleOffset5;\n\nvarying vec2 v_Texcoord0;\n\n#ifdef LIGHTMAP\n uniform sampler2D u_LightMap;\n varying vec2 v_LightMapUV;\n#endif\n\nvoid main()\n{\n vec4 splatAlpha = vec4(1.0);\n #ifdef ExtendTerrain_DETAIL_NUM1\n splatAlpha = texture2D(u_SplatAlphaTexture, v_Texcoord0);\n vec4 color1 = texture2D(u_DiffuseTexture1, v_Texcoord0 * u_DiffuseScaleOffset1.xy);\n gl_FragColor.xyz = color1.xyz * splatAlpha.r;\n #endif\n #ifdef ExtendTerrain_DETAIL_NUM2\n splatAlpha = texture2D(u_SplatAlphaTexture, v_Texcoord0);\n vec4 color1 = texture2D(u_DiffuseTexture1, v_Texcoord0 * u_DiffuseScaleOffset1.xy);\n vec4 color2 = texture2D(u_DiffuseTexture2, v_Texcoord0 * u_DiffuseScaleOffset2.xy);\n gl_FragColor.xyz = color1.xyz * splatAlpha.r + color2.xyz * (1.0 - splatAlpha.r);\n #endif\n #ifdef ExtendTerrain_DETAIL_NUM3\n splatAlpha = texture2D(u_SplatAlphaTexture, v_Texcoord0);\n vec4 color1 = texture2D(u_DiffuseTexture1, v_Texcoord0 * u_DiffuseScaleOffset1.xy);\n vec4 color2 = texture2D(u_DiffuseTexture2, v_Texcoord0 * u_DiffuseScaleOffset2.xy);\n vec4 color3 = texture2D(u_DiffuseTexture3, v_Texcoord0 * u_DiffuseScaleOffset3.xy);\n gl_FragColor.xyz = color1.xyz * splatAlpha.r + color2.xyz * splatAlpha.g + color3.xyz * (1.0 - splatAlpha.r - splatAlpha.g);\n #endif\n #ifdef ExtendTerrain_DETAIL_NUM4\n splatAlpha = texture2D(u_SplatAlphaTexture, v_Texcoord0);\n vec4 color1 = texture2D(u_DiffuseTexture1, v_Texcoord0 * u_DiffuseScaleOffset1.xy);\n vec4 color2 = texture2D(u_DiffuseTexture2, v_Texcoord0 * u_DiffuseScaleOffset2.xy);\n vec4 color3 = texture2D(u_DiffuseTexture3, v_Texcoord0 * u_DiffuseScaleOffset3.xy);\n vec4 color4 = texture2D(u_DiffuseTexture4, v_Texcoord0 * u_DiffuseScaleOffset4.xy);\n gl_FragColor.xyz = color1.xyz * splatAlpha.r + color2.xyz * splatAlpha.g + color3.xyz * splatAlpha.b + color4.xyz * (1.0 - splatAlpha.r - splatAlpha.g - splatAlpha.b);\n #endif\n #ifdef ExtendTerrain_DETAIL_NUM5\n splatAlpha = texture2D(u_SplatAlphaTexture, v_Texcoord0);\n vec4 color1 = texture2D(u_DiffuseTexture1, v_Texcoord0 * u_DiffuseScaleOffset1.xy);\n vec4 color2 = texture2D(u_DiffuseTexture2, v_Texcoord0 * u_DiffuseScaleOffset2.xy);\n vec4 color3 = texture2D(u_DiffuseTexture3, v_Texcoord0 * u_DiffuseScaleOffset3.xy);\n vec4 color4 = texture2D(u_DiffuseTexture4, v_Texcoord0 * u_DiffuseScaleOffset4.xy);\n vec4 color5 = texture2D(u_DiffuseTexture5, v_Texcoord0 * u_DiffuseScaleOffset5.xy);\n gl_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);\n #endif\n gl_FragColor.w = splatAlpha.a;\n \n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\n vec3 normal = v_Normal;\n vec3 dif, spe;\n#endif\n\nvec3 diffuse = vec3(0.0);\nvec3 specular= vec3(0.0);\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(FOG)\n vec3 toEye;\n #ifdef FOG\n toEye=u_CameraPos-v_PositionWorld;\n float toEyeLength=length(toEye);\n toEye/=toEyeLength;\n #else\n toEye=normalize(u_CameraPos-v_PositionWorld);\n #endif\n#endif\n\n#ifdef DIRECTIONLIGHT\n LayaAirBlinnPhongDiectionLight(vec3(0.0), 1.0, normal, vec3(1.0), toEye,u_DirectionLight, dif, spe);\n diffuse+=dif;\n specular+=spe;\n#endif\n \n#ifdef POINTLIGHT\n LayaAirBlinnPhongPointLight(v_PositionWorld, vec3(0.0), 1.0, normal, vec3(1.0), toEye, u_PointLight, dif, spe);\n diffuse+=dif;\n specular+=spe;\n#endif\n\n#ifdef SPOTLIGHT\n LayaAirBlinnPhongSpotLight(v_PositionWorld, vec3(0.0), 1.0, normal, vec3(1.0), toEye, u_SpotLight, dif, spe);\n diffuse+=dif;\n specular+=spe;\n#endif\n\nvec3 globalDiffuse = u_AmbientColor;\n#ifdef LIGHTMAP\n globalDiffuse += DecodeLightmap(texture2D(u_LightMap, v_LightMapUV));\n#endif\n\n#ifdef RECEIVESHADOW\n float shadowValue = 1.0;\n #ifdef SHADOWMAP_PSSM3\n shadowValue = getShadowPSSM3( u_shadowMap1,u_shadowMap2,u_shadowMap3,u_lightShadowVP,u_shadowPSSMDistance,u_shadowPCFoffset,v_PositionWorld,v_posViewZ,0.001);\n #endif\n #ifdef SHADOWMAP_PSSM2\n shadowValue = getShadowPSSM2( u_shadowMap1,u_shadowMap2,u_lightShadowVP,u_shadowPSSMDistance,u_shadowPCFoffset,v_PositionWorld,v_posViewZ,0.001);\n #endif \n #ifdef SHADOWMAP_PSSM1\n shadowValue = getShadowPSSM1( u_shadowMap1,v_lightMVPPos,u_shadowPSSMDistance,u_shadowPCFoffset,v_posViewZ,0.001);\n #endif\n gl_FragColor = vec4(gl_FragColor.rgb * (globalDiffuse + diffuse) * shadowValue, gl_FragColor.a);\n#else\n gl_FragColor = vec4(gl_FragColor.rgb * (globalDiffuse + diffuse), gl_FragColor.a);\n#endif\n\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\n #ifdef RECEIVESHADOW\n gl_FragColor.rgb += specular * shadowValue;\n #else\n gl_FragColor.rgb += specular;\n #endif\n#endif\n\n#ifdef FOG\n float lerpFact=clamp((toEyeLength-u_FogStart)/u_FogRange,0.0,1.0);\n gl_FragColor.rgb=mix(gl_FragColor.rgb,u_FogColor,lerpFact);\n#endif\n}\n\n\n\n\n\n";
- shader=Shader3D.add("ExtendTerrain");
- subShader=new SubShader(attributeMap,uniformMap,RenderableSprite3D.shaderDefines,ExtendTerrainMaterial.shaderDefines);
- shader.addSubShader(subShader);
- subShader.addShaderPass(vs,ps,stateMap);
- attributeMap={
- 'a_Position' :/*laya.d3.core.trail.VertexTrail.TRAIL_POSITION0*/0,
- 'a_OffsetVector':/*laya.d3.core.trail.VertexTrail.TRAIL_OFFSETVECTOR*/1,
- 'a_Texcoord0X' :/*laya.d3.core.trail.VertexTrail.TRAIL_TEXTURECOORDINATE0X*/4,
- 'a_Texcoord0Y' :/*laya.d3.core.trail.VertexTrail.TRAIL_TEXTURECOORDINATE0Y*/3,
- 'a_BirthTime' :/*laya.d3.core.trail.VertexTrail.TRAIL_TIME0*/2
- };
- uniformMap={
- 'u_MvpMatrix':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_View':/*laya.d3.shader.Shader3D.PERIOD_CAMERA*/3,
- 'u_Projection':/*laya.d3.shader.Shader3D.PERIOD_CAMERA*/3,
- 'u_TilingOffset':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_MainTexture':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_MainColor':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_CurTime' :/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_LifeTime' :/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_WidthCurve' :/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_WidthCurveKeyLength' :/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_GradientColorkey' :/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_GradientAlphakey' :/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2
- };
- stateMap={
- 's_Cull':/*laya.d3.shader.Shader3D.RENDER_STATE_CULL*/0,
- 's_Blend':/*laya.d3.shader.Shader3D.RENDER_STATE_BLEND*/1,
- 's_BlendSrc':/*laya.d3.shader.Shader3D.RENDER_STATE_BLEND_SRC*/2,
- 's_BlendDst':/*laya.d3.shader.Shader3D.RENDER_STATE_BLEND_DST*/3,
- 's_DepthTest':/*laya.d3.shader.Shader3D.RENDER_STATE_DEPTH_TEST*/12,
- 's_DepthWrite':/*laya.d3.shader.Shader3D.RENDER_STATE_DEPTH_WRITE*/13
- };
- vs="#include \"Lighting.glsl\";\n\nattribute vec3 a_Position;\nattribute vec3 a_OffsetVector;\nattribute vec4 a_Color;\nattribute float a_Texcoord0X;\nattribute float a_Texcoord0Y;\nattribute float a_BirthTime;\n\nuniform mat4 u_View;\nuniform mat4 u_Projection;\n\nuniform vec4 u_TilingOffset;\n\nuniform float u_CurTime;\nuniform float u_LifeTime;\nuniform vec4 u_WidthCurve[10];\nuniform int u_WidthCurveKeyLength;\n\nuniform vec4 u_GradientColorkey[10];\nuniform vec2 u_GradientAlphakey[10];\n\nvarying vec2 v_Texcoord0;\nvarying vec4 v_Color;\n\nfloat hermiteInterpolate(float t, float outTangent, float inTangent, float duration, float value1, float value2)\n{\n float t2 = t * t;\n float t3 = t2 * t;\n float a = 2.0 * t3 - 3.0 * t2 + 1.0;\n float b = t3 - 2.0 * t2 + t;\n float c = t3 - t2;\n float d = -2.0 * t3 + 3.0 * t2;\n return a * value1 + b * outTangent * duration + c * inTangent * duration + d * value2;\n}\n\nfloat getCurWidth(in float normalizeTime)\n{\n float width;\n if(normalizeTime == 0.0){\n width=u_WidthCurve[0].w;\n }\n else if(normalizeTime >= 1.0){\n width=u_WidthCurve[u_WidthCurveKeyLength - 1].w;\n }\n else{\n for(int i = 0; i < 10; i ++ )\n {\n if(normalizeTime == u_WidthCurve[i].x){\n width=u_WidthCurve[i].w;\n break;\n }\n \n vec4 lastFrame = u_WidthCurve[i];\n vec4 nextFrame = u_WidthCurve[i + 1];\n if(normalizeTime > lastFrame.x && normalizeTime < nextFrame.x)\n {\n float duration = nextFrame.x - lastFrame.x;\n float t = (normalizeTime - lastFrame.x) / duration;\n float outTangent = lastFrame.z;\n float inTangent = nextFrame.y;\n float value1 = lastFrame.w;\n float value2 = nextFrame.w;\n width=hermiteInterpolate(t, outTangent, inTangent, duration, value1, value2);\n break;\n }\n }\n }\n return width;\n} \n\nvec4 getColorFromGradientByBlend(in vec4 gradientColors[10], in vec2 gradientAlphas[10], in float normalizeTime)\n{\n vec4 color;\n for(int i = 1; i < 10; i++)\n {\n vec4 gradientColor = gradientColors[i];\n float colorKey = gradientColor.x;\n if(colorKey >= normalizeTime)\n {\n vec4 lastGradientColor = gradientColors[i-1];\n float lastColorKey = lastGradientColor.x;\n float age = (normalizeTime - lastColorKey) / (colorKey - lastColorKey);\n color.rgb = mix(gradientColors[i-1].yzw, gradientColor.yzw, age);\n break;\n }\n }\n for(int i = 1; i < 10; i++)\n {\n vec2 gradientAlpha = gradientAlphas[i];\n float alphaKey = gradientAlpha.x;\n if(alphaKey >= normalizeTime)\n {\n vec2 lastGradientAlpha = gradientAlphas[i-1];\n float lastAlphaKey = lastGradientAlpha.x;\n float age = (normalizeTime - lastAlphaKey) / (alphaKey - lastAlphaKey);\n color.a = mix(lastGradientAlpha.y, gradientAlpha.y, age);\n break;\n }\n }\n return color;\n}\n\nvec4 getColorFromGradientByFixed(in vec4 gradientColors[10], in vec2 gradientAlphas[10], in float normalizeTime)\n{\n vec4 color;\n for(int i = 1; i < 10; i++)\n {\n vec4 gradientColor = gradientColors[i];\n if(gradientColor.w >= normalizeTime)\n {\n color.rgb = gradientColor.xyz;\n break;\n }\n }\n for(int i = 1; i < 10; i++)\n {\n vec2 gradientAlpha = gradientAlphas[i];\n if(gradientAlpha.y >= normalizeTime)\n {\n color.a = gradientAlpha.x;\n break;\n }\n }\n return color;\n}\n\nvoid main()\n{\n float normalizeTime = (u_CurTime - a_BirthTime) / u_LifeTime;\n \n #ifdef TILINGOFFSET\n v_Texcoord0 = vec2(a_Texcoord0X, 1.0 - a_Texcoord0Y) * u_TilingOffset.xy + u_TilingOffset.zw;\n #else\n v_Texcoord0 = vec2(a_Texcoord0X, a_Texcoord0Y);\n #endif\n \n #ifdef GRADIENTMODE_BLEND\n v_Color = getColorFromGradientByBlend(u_GradientColorkey, u_GradientAlphakey, normalizeTime);\n #else\n v_Color = getColorFromGradientByFixed(u_GradientColorkey, u_GradientAlphakey, normalizeTime);\n #endif\n \n gl_Position = u_Projection * u_View * vec4(a_Position + a_OffsetVector * getCurWidth(normalizeTime),1.0);\n gl_Position=remapGLPositionZ(gl_Position);\n}\n";
- ps="#ifdef HIGHPRECISION\n precision highp float;\n#else\n precision mediump float;\n#endif\n\nuniform sampler2D u_MainTexture;\nuniform vec4 u_MainColor;\n\nvarying vec2 v_Texcoord0;\nvarying vec4 v_Color;\n\nvoid main()\n{ \n vec4 color = 2.0 * u_MainColor * v_Color;\n #ifdef MAINTEXTURE\n vec4 mainTextureColor = texture2D(u_MainTexture, v_Texcoord0);\n color *= mainTextureColor;\n #endif\n gl_FragColor = color;\n}\n\n";
- shader=Shader3D.add("Trail");
- subShader=new SubShader(attributeMap,uniformMap,TrailSprite3D.shaderDefines,TrailMaterial.shaderDefines);
- shader.addSubShader(subShader);
- subShader.addShaderPass(vs,ps,stateMap);
- attributeMap={
- 'a_Position':/*laya.d3.graphics.Vertex.VertexMesh.MESH_POSITION0*/0,
- 'a_Normal':/*laya.d3.graphics.Vertex.VertexMesh.MESH_NORMAL0*/3,
- 'a_Tangent0':/*laya.d3.graphics.Vertex.VertexMesh.MESH_TANGENT0*/4
- };
- uniformMap={
- 'u_MvpMatrix':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_WorldMat':/*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2,
- 'u_CameraPos':/*laya.d3.shader.Shader3D.PERIOD_CAMERA*/3,
- 'u_Time':/*laya.d3.shader.Shader3D.PERIOD_SCENE*/4,
- 'u_MainTexture':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_NormalTexture':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_HorizonColor':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_WaveScale' :/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_WaveSpeed' :/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1
- };
- vs="#include \"Lighting.glsl\";\n\nattribute vec4 a_Position;\nattribute vec3 a_Normal;\nattribute vec4 a_Tangent0;\n\nuniform mat4 u_MvpMatrix;\nuniform mat4 u_WorldMat;\nuniform vec3 u_CameraPos;\nuniform float u_WaveScale;\nuniform vec4 u_WaveSpeed;\nuniform float u_Time;\n\nvarying vec3 v_Normal;\nvarying vec3 v_Tangent;\nvarying vec3 v_Binormal;\nvarying vec3 v_ViewDir;\nvarying vec2 v_Texcoord0;\nvarying vec2 v_Texcoord1;\n\nvoid main()\n{\n vec4 positionWorld = u_WorldMat * a_Position;\n vec4 position = u_MvpMatrix * a_Position;\n \n vec4 temp = vec4(positionWorld.x, positionWorld.z, positionWorld.x, positionWorld.z) * u_WaveScale + u_WaveSpeed * u_WaveScale * u_Time;\n \n v_Texcoord0 = temp.xy * vec2(0.4, 0.45);\n v_Texcoord1 = temp.wz;\n \n mat3 worldMat = mat3(u_WorldMat);\n v_Normal = worldMat * a_Normal;\n v_Tangent = worldMat * a_Tangent0.xyz;\n v_Binormal = cross(v_Normal, v_Tangent) * a_Tangent0.w;\n \n v_ViewDir = u_CameraPos - positionWorld.xyz;\n gl_Position = position;\n gl_Position=remapGLPositionZ(gl_Position);\n}";
- ps="#ifdef FSHIGHPRECISION\n precision highp float;\n#else\n precision mediump float;\n#endif\n\n#ifdef MAINTEXTURE\n uniform sampler2D u_MainTexture;\n#endif\n\n#ifdef NORMALTEXTURE\n uniform sampler2D u_NormalTexture;\n#endif\n\nuniform vec4 u_HorizonColor;\n\nvarying vec3 v_Normal;\nvarying vec3 v_Tangent;\nvarying vec3 v_Binormal;\nvarying vec3 v_ViewDir;\nvarying vec2 v_Texcoord0;\nvarying vec2 v_Texcoord1;\n\n#include \"Lighting.glsl\"\n\nvoid main()\n{\n vec4 bumpColor1 = texture2D(u_NormalTexture, v_Texcoord0);\n vec4 bumpColor2 = texture2D(u_NormalTexture, v_Texcoord1);\n \n vec3 normal1 = NormalSampleToWorldSpace1(bumpColor1, v_Tangent, v_Binormal, v_Normal);\n vec3 normal2 = NormalSampleToWorldSpace1(bumpColor2, v_Tangent, v_Binormal, v_Normal);\n \n vec3 normal = normalize((normal1 + normal2) * 0.5);\n vec3 viewDir = normalize(v_ViewDir);\n float fresnel = dot(viewDir, normal);\n \n vec4 waterColor = texture2D(u_MainTexture, vec2(fresnel, fresnel));\n \n vec4 color;\n color.rgb = mix(waterColor.rgb, u_HorizonColor.rgb, vec3(waterColor.a));\n color.a = u_HorizonColor.a;\n \n gl_FragColor = color;\n}\n\n";
- shader=Shader3D.add("WaterPrimary");
- subShader=new SubShader(attributeMap,uniformMap,null,WaterPrimaryMaterial.shaderDefines);
- shader.addSubShader(subShader);
- subShader.addShaderPass(vs,ps);
- attributeMap={
- 'a_PositionTexcoord':/*laya.d3.graphics.Vertex.VertexMesh.MESH_POSITION0*/0
- };
- uniformMap={
- 'u_ScreenTexture':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1
- };
- vs="#include \"Lighting.glsl\";\n\nattribute vec4 a_PositionTexcoord;\nvarying vec2 v_Texcoord0;\n\nvoid main() {\n gl_Position = vec4(a_PositionTexcoord.xy, 0.0, 1.0);\n v_Texcoord0 = a_PositionTexcoord.zw;\n gl_Position = remapGLPositionZ(gl_Position);\n}";
- ps="#ifdef FSHIGHPRECISION\n precision highp float;\n#else\n precision mediump float;\n#endif\n\nuniform sampler2D u_ScreenTexture;\nvarying vec2 v_Texcoord0;\n\nvoid main() {\n gl_FragColor = texture2D(u_ScreenTexture, v_Texcoord0);\n}\n\n";
- shader=Shader3D.add("ScreenQuad");
- subShader=new SubShader(attributeMap,uniformMap,null,null);
- shader.addSubShader(subShader);
- var shaderPass=subShader.addShaderPass(vs,ps);
- var renderState=shaderPass.renderState;
- renderState.depthTest=/*laya.d3.core.material.RenderState.DEPTHTEST_ALWAYS*/0x0207;
- renderState.depthWrite=false;
- renderState.cull=/*laya.d3.core.material.RenderState.CULL_NONE*/0;
- renderState.blend=/*laya.d3.core.material.RenderState.BLEND_DISABLE*/0;
- attributeMap={
- 'a_PositionTexcoord':/*laya.d3.graphics.Vertex.VertexMesh.MESH_POSITION0*/0
- };
- uniformMap={
- 'u_MainTex':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_BloomTex':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_AutoExposureTex':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_MainTex_TexelSize':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_SampleScale':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_Threshold':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_Params' :/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1
- };
- shader=Shader3D.add("PostProcessBloom",attributeMap,uniformMap);
- subShader=new SubShader(null,null,null,null);
- shader.addSubShader(subShader);
- shaderPass=subShader.addShaderPass("#include \"Lighting.glsl\";\n\nattribute vec4 a_PositionTexcoord;\nvarying vec2 v_Texcoord0;\n\nvoid main() {\n gl_Position = vec4(a_PositionTexcoord.xy, 0.0, 1.0);\n v_Texcoord0 = a_PositionTexcoord.zw;\n gl_Position = remapGLPositionZ(gl_Position);\n}","#ifdef HIGHPRECISION\n precision highp float;\n#else\n precision mediump float;\n#endif\n\n#include \"Colors.glsl\";\n#include \"Sampling.glsl\";\n\nvarying vec2 v_Texcoord0;\n\nuniform sampler2D u_MainTex;\nuniform sampler2D u_AutoExposureTex;\nuniform vec4 u_MainTex_TexelSize;\nuniform vec4 u_Threshold; // x: threshold value (linear), y: threshold - knee, z: knee * 2, w: 0.25 / knee\nuniform vec4 u_Params; // x: clamp, yzw: unused\n\nmediump vec4 prefilter(mediump vec4 color, vec2 uv) {\n mediump float autoExposure = texture2D(u_AutoExposureTex, uv).r;\n color *= autoExposure;\n color = min(vec4(u_Params.x), color); // clamp to max\n color = quadraticThreshold(color, u_Threshold.x, u_Threshold.yzw);\n return color;\n}\n\nvoid fragPrefilter13() {\n mediump vec4 color = downsampleBox13Tap(u_MainTex, v_Texcoord0, u_MainTex_TexelSize.xy);\n gl_FragColor = prefilter(safeHDR(color), v_Texcoord0);\n}\n\nvoid main() {\n fragPrefilter13();\n}");
- renderState=shaderPass.renderState;
- renderState.depthTest=/*laya.d3.core.material.RenderState.DEPTHTEST_ALWAYS*/0x0207;
- renderState.depthWrite=false;
- renderState.cull=/*laya.d3.core.material.RenderState.CULL_NONE*/0;
- renderState.blend=/*laya.d3.core.material.RenderState.BLEND_DISABLE*/0;
- subShader=new SubShader(null,null,null,null);
- shader.addSubShader(subShader);
- shaderPass=subShader.addShaderPass("#include \"Lighting.glsl\";\n\nattribute vec4 a_PositionTexcoord;\nvarying vec2 v_Texcoord0;\n\nvoid main() {\n gl_Position = vec4(a_PositionTexcoord.xy, 0.0, 1.0);\n v_Texcoord0 = a_PositionTexcoord.zw;\n gl_Position = remapGLPositionZ(gl_Position);\n}","#ifdef HIGHPRECISION\n precision highp float;\n#else\n precision mediump float;\n#endif\n\n#include \"Colors.glsl\";\n#include \"Sampling.glsl\";\n\nvarying vec2 v_Texcoord0;\n\nuniform sampler2D u_MainTex;\nuniform sampler2D u_AutoExposureTex;\nuniform vec4 u_MainTex_TexelSize;\nuniform vec4 u_Threshold; // x: threshold value (linear), y: threshold - knee, z: knee * 2, w: 0.25 / knee\nuniform vec4 u_Params; // x: clamp, yzw: unused\n\nmediump vec4 prefilter(mediump vec4 color, vec2 uv) {\n mediump float autoExposure = texture2D(u_AutoExposureTex, uv).r;\n color *= autoExposure;\n color = min(vec4(u_Params.x), color); // clamp to max\n color = quadraticThreshold(color, u_Threshold.x, u_Threshold.yzw);\n return color;\n}\n\nvoid fragPrefilter4() {\n mediump vec4 color = downsampleBox4Tap(u_MainTex, v_Texcoord0, u_MainTex_TexelSize.xy);\n gl_FragColor = prefilter(safeHDR(color), v_Texcoord0);\n}\n\nvoid main() {\n fragPrefilter4();\n}");
- renderState=shaderPass.renderState;
- renderState.depthTest=/*laya.d3.core.material.RenderState.DEPTHTEST_ALWAYS*/0x0207;
- renderState.depthWrite=false;
- renderState.cull=/*laya.d3.core.material.RenderState.CULL_NONE*/0;
- renderState.blend=/*laya.d3.core.material.RenderState.BLEND_DISABLE*/0;
- subShader=new SubShader(null,null,null,null);
- shader.addSubShader(subShader);
- shaderPass=subShader.addShaderPass("#include \"Lighting.glsl\";\n\nattribute vec4 a_PositionTexcoord;\nvarying vec2 v_Texcoord0;\n\nvoid main() {\n gl_Position = vec4(a_PositionTexcoord.xy, 0.0, 1.0);\n v_Texcoord0 = a_PositionTexcoord.zw;\n gl_Position = remapGLPositionZ(gl_Position);\n}","#ifdef HIGHPRECISION\n precision highp float;\n#else\n precision mediump float;\n#endif\n\n#include \"Colors.glsl\";\n#include \"Sampling.glsl\";\n\nvarying vec2 v_Texcoord0;\n\nuniform sampler2D u_MainTex;\nuniform vec4 u_MainTex_TexelSize;\n\nvoid fragDownsample13() {\n mediump vec4 color = downsampleBox13Tap(u_MainTex, v_Texcoord0, u_MainTex_TexelSize.xy);\n gl_FragColor = color;\n}\n\nvoid main() {\n fragDownsample13();\n}");
- renderState=shaderPass.renderState;
- renderState.depthTest=/*laya.d3.core.material.RenderState.DEPTHTEST_ALWAYS*/0x0207;
- renderState.depthWrite=false;
- renderState.cull=/*laya.d3.core.material.RenderState.CULL_NONE*/0;
- renderState.blend=/*laya.d3.core.material.RenderState.BLEND_DISABLE*/0;
- subShader=new SubShader(null,null,null,null);
- shader.addSubShader(subShader);
- shaderPass=subShader.addShaderPass("#include \"Lighting.glsl\";\n\nattribute vec4 a_PositionTexcoord;\nvarying vec2 v_Texcoord0;\n\nvoid main() {\n gl_Position = vec4(a_PositionTexcoord.xy, 0.0, 1.0);\n v_Texcoord0 = a_PositionTexcoord.zw;\n gl_Position = remapGLPositionZ(gl_Position);\n}","#ifdef HIGHPRECISION\n precision highp float;\n#else\n precision mediump float;\n#endif\n\n#include \"Colors.glsl\";\n#include \"Sampling.glsl\";\n\nvarying vec2 v_Texcoord0;\n\nuniform sampler2D u_MainTex;\nuniform sampler2D u_BloomTex;\n\nuniform vec4 u_MainTex_TexelSize;\nuniform float u_SampleScale;\n\nmediump vec4 combine(mediump vec4 bloom, vec2 uv) {\n mediump vec4 color = texture2D(u_BloomTex, uv);\n return bloom + color;\n}\n\nvoid fragUpsampleTent() {\n mediump vec4 bloom = UpsampleTent(u_MainTex, v_Texcoord0, u_MainTex_TexelSize.xy, u_SampleScale);\n gl_FragColor = combine(bloom, v_Texcoord0);\n}\n\nvoid main() {\n fragUpsampleTent();\n}");
- renderState=shaderPass.renderState;
- renderState.depthTest=/*laya.d3.core.material.RenderState.DEPTHTEST_ALWAYS*/0x0207;
- renderState.depthWrite=false;
- renderState.cull=/*laya.d3.core.material.RenderState.CULL_NONE*/0;
- renderState.blend=/*laya.d3.core.material.RenderState.BLEND_DISABLE*/0;
- subShader=new SubShader(null,null,null,null);
- shader.addSubShader(subShader);
- shaderPass=subShader.addShaderPass("#include \"Lighting.glsl\";\n\nattribute vec4 a_PositionTexcoord;\nvarying vec2 v_Texcoord0;\n\nvoid main() {\n gl_Position = vec4(a_PositionTexcoord.xy, 0.0, 1.0);\n v_Texcoord0 = a_PositionTexcoord.zw;\n gl_Position = remapGLPositionZ(gl_Position);\n}","#ifdef HIGHPRECISION\n precision highp float;\n#else\n precision mediump float;\n#endif\n\n#include \"Colors.glsl\";\n#include \"Sampling.glsl\";\n\nvarying vec2 v_Texcoord0;\n\nuniform sampler2D u_MainTex;\nuniform sampler2D u_BloomTex;\n\nuniform vec4 u_MainTex_TexelSize;\nuniform float u_SampleScale;\n\nmediump vec4 combine(mediump vec4 bloom, vec2 uv) {\n mediump vec4 color = texture2D(u_BloomTex, uv);\n return bloom + color;\n}\n\nvoid fragUpsampleBox() {\n mediump vec4 bloom = upsampleBox(u_MainTex, v_Texcoord0, u_MainTex_TexelSize.xy, vec4(u_SampleScale));\n gl_FragColor = combine(bloom, v_Texcoord0);\n}\n\nvoid main() {\n fragUpsampleBox();\n}");
- renderState=shaderPass.renderState;
- renderState.depthTest=/*laya.d3.core.material.RenderState.DEPTHTEST_ALWAYS*/0x0207;
- renderState.depthWrite=false;
- renderState.cull=/*laya.d3.core.material.RenderState.CULL_NONE*/0;
- renderState.blend=/*laya.d3.core.material.RenderState.BLEND_DISABLE*/0;
- subShader=new SubShader(null,null,null,null);
- shader.addSubShader(subShader);
- shaderPass=subShader.addShaderPass("#include \"Lighting.glsl\";\n\nattribute vec4 a_PositionTexcoord;\nvarying vec2 v_Texcoord0;\n\nvoid main() {\n gl_Position = vec4(a_PositionTexcoord.xy, 0.0, 1.0);\n v_Texcoord0 = a_PositionTexcoord.zw;\n gl_Position = remapGLPositionZ(gl_Position);\n}","#ifdef HIGHPRECISION\n precision highp float;\n#else\n precision mediump float;\n#endif\n\n#include \"Colors.glsl\";\n#include \"Sampling.glsl\";\n\nvarying vec2 v_Texcoord0;\n\nuniform sampler2D u_MainTex;\nuniform sampler2D u_AutoExposureTex;\nuniform vec4 u_MainTex_TexelSize;\nuniform vec4 u_Threshold; // x: threshold value (linear), y: threshold - knee, z: knee * 2, w: 0.25 / knee\nuniform vec4 u_Params; // x: clamp, yzw: unused\n\nmediump vec4 prefilter(mediump vec4 color, vec2 uv) {\n mediump float autoExposure = texture2D(u_AutoExposureTex, uv).r;\n color *= autoExposure;\n color = min(vec4(u_Params.x), color); // clamp to max\n color = quadraticThreshold(color, u_Threshold.x, u_Threshold.yzw);\n return color;\n}\n\nvoid fragPrefilter13() {\n mediump vec4 color = downsampleBox13Tap(u_MainTex, v_Texcoord0, u_MainTex_TexelSize.xy);\n gl_FragColor = prefilter(safeHDR(color), v_Texcoord0);\n}\n\nvoid main() {\n fragPrefilter13();\n}");
- renderState=shaderPass.renderState;
- renderState.depthTest=/*laya.d3.core.material.RenderState.DEPTHTEST_ALWAYS*/0x0207;
- renderState.depthWrite=false;
- renderState.cull=/*laya.d3.core.material.RenderState.CULL_NONE*/0;
- renderState.blend=/*laya.d3.core.material.RenderState.BLEND_DISABLE*/0;
- attributeMap={
- 'a_PositionTexcoord':/*laya.d3.graphics.Vertex.VertexMesh.MESH_POSITION0*/0
- };
- uniformMap={
- 'u_MainTex':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_BloomTex':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_AutoExposureTex':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_Bloom_DirtTex':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_BloomTex_TexelSize':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_Bloom_Settings':/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1,
- 'u_Bloom_Color' :/*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1
- };
- shader=Shader3D.add("PostProcessComposite",attributeMap,uniformMap);
- subShader=new SubShader(null,null,null,PostProcess.shaderDefines);
- shader.addSubShader(subShader);
- shaderPass=subShader.addShaderPass("attribute vec4 a_Position;\nvarying vec2 v_Texcoord0;\n\nvec2 TransformTriangleVertexToUV(vec2 vertex)\n{\n vec2 uv = (vertex + 1.0) * 0.5;\n return uv;\n}\n\nvoid main() {\n gl_Position =vec4(a_Position.xy, 0.0, 1.0);\n v_Texcoord0=TransformTriangleVertexToUV(a_Position.xy);\n gl_Position=remapGLPositionZ(gl_Position);\n}","#include \"Colors.glsl\";\n#include \"Sampling.glsl\";\n\nvarying vec2 v_Texcoord0;\n\nuniform sampler2D u_MainTex;\nuniform sampler2D u_BloomTex;\n\nuniform sampler2D u_AutoExposureTex;\nuniform sampler2D u_Bloom_DirtTex;\nuniform vec4 u_BloomTex_TexelSize;\nuniform vec4 u_Bloom_DirtTileOffset; // xy: tiling, zw: offset\nuniform mediump vec3 u_Bloom_Settings;// x: sampleScale, y: intensity, z: dirt intensity\nuniform mediump vec3 u_Bloom_Color;\n\nvoid main() {\n mediump float autoExposure = texture2D(u_AutoExposureTex, v_Texcoord0).r;\n mediump vec4 color=vec4(0.0)\n color = texture2D(u_MainTex, v_Texcoord0);\n \n color = SRGBToLinear(color);\n color.rgb *= autoExposure;\n \n #if BLOOM || BLOOM_LOW\n {\n #if BLOOM\n mediump vec4 bloom = UpsampleTent(_BloomTex, uvDistorted, _BloomTex_TexelSize.xy, _Bloom_Settings.x);\n #else\n mediump vec4 bloom = UpsampleBox(_BloomTex, uvDistorted, _BloomTex_TexelSize.xy, _Bloom_Settings.x);\n #endif\n\n // UVs should be Distort(uv * _Bloom_DirtTileOffset.xy + _Bloom_DirtTileOffset.zw)\n // but considering we use a cover-style scale on the dirt texture the difference\n // isn't massive so we chose to save a few ALUs here instead in case lens distortion\n // is active\n mediump vec4 dirt = mediump vec4(SAMPLE_TEXTURE2D(_Bloom_DirtTex, sampler_Bloom_DirtTex, uvDistorted * _Bloom_DirtTileOffset.xy + _Bloom_DirtTileOffset.zw).rgb, 0.0);\n\n // Additive bloom (artist friendly)\n bloom *= _Bloom_Settings.y;\n dirt *= _Bloom_Settings.z;\n color += bloom * half4(_Bloom_Color, 1.0);\n color += dirt * bloom;\n }\n #endif\n \n half4 output = color;\n output = LinearToSRGB(output);\n //output.rgb = Dither(output.rgb, v_Texcoord0);//TODO:\n}");
- renderState=shaderPass.renderState;
- renderState.depthTest=/*laya.d3.core.material.RenderState.DEPTHTEST_ALWAYS*/0x0207;
- renderState.depthWrite=false;
- renderState.cull=/*laya.d3.core.material.RenderState.CULL_NONE*/0;
- renderState.blend=/*laya.d3.core.material.RenderState.BLEND_DISABLE*/0;
- }
- ShaderInit3D._rangeAttenTex=null;
- return ShaderInit3D;
- })()
- /**
- *<code>Utils3D</code> 类用于创建3D工具。
- */
- //class laya.d3.utils.Utils3D
- var Utils3D=(function(){
- function Utils3D(){}
- __class(Utils3D,'laya.d3.utils.Utils3D');
- Utils3D._convertToLayaVec3=function(bVector,out,inverseX){
- out.x=inverseX ?-bVector.x():bVector.x();
- out.y=bVector.y();
- out.z=bVector.z();
- }
- Utils3D._convertToBulletVec3=function(lVector,out,inverseX){
- out.setValue(inverseX ?-lVector.x :lVector.x,lVector.y,lVector.z);
- }
- Utils3D._rotationTransformScaleSkinAnimation=function(tx,ty,tz,qx,qy,qz,qw,sx,sy,sz,outArray,outOffset){
- var re=Utils3D._tempArray16_0;
- var se=Utils3D._tempArray16_1;
- var tse=Utils3D._tempArray16_2;
- var x2=qx+qx;
- var y2=qy+qy;
- var z2=qz+qz;
- var xx=qx *x2;
- var yx=qy *x2;
- var yy=qy *y2;
- var zx=qz *x2;
- var zy=qz *y2;
- var zz=qz *z2;
- var wx=qw *x2;
- var wy=qw *y2;
- var wz=qw *z2;
- re[15]=1;
- re[0]=1-yy-zz;
- re[1]=yx+wz;
- re[2]=zx-wy;
- re[4]=yx-wz;
- re[5]=1-xx-zz;
- re[6]=zy+wx;
- re[8]=zx+wy;
- re[9]=zy-wx;
- re[10]=1-xx-yy;
- se[15]=1;
- se[0]=sx;
- se[5]=sy;
- se[10]=sz;
- var i,a,b,e,ai0,ai1,ai2,ai3;
- for (i=0;i < 4;i++){
- ai0=re[i];
- ai1=re[i+4];
- ai2=re[i+8];
- ai3=re[i+12];
- tse[i]=ai0;
- tse[i+4]=ai1;
- tse[i+8]=ai2;
- tse[i+12]=ai0 *tx+ai1 *ty+ai2 *tz+ai3;
- }
- for (i=0;i < 4;i++){
- ai0=tse[i];
- ai1=tse[i+4];
- ai2=tse[i+8];
- ai3=tse[i+12];
- outArray[i+outOffset]=ai0 *se[0]+ai1 *se[1]+ai2 *se[2]+ai3 *se[3];
- outArray[i+outOffset+4]=ai0 *se[4]+ai1 *se[5]+ai2 *se[6]+ai3 *se[7];
- outArray[i+outOffset+8]=ai0 *se[8]+ai1 *se[9]+ai2 *se[10]+ai3 *se[11];
- outArray[i+outOffset+12]=ai0 *se[12]+ai1 *se[13]+ai2 *se[14]+ai3 *se[15];
- }
- }
- Utils3D._createSceneByJsonForMaker=function(nodeData,outBatchSprites,initTool){
- var scene3d=Utils3D._createNodeByJsonForMaker(nodeData,outBatchSprites,initTool);
- Utils3D._addComponentByJsonForMaker(nodeData,outBatchSprites,initTool);
- return scene3d;
- }
- Utils3D._createNodeByJsonForMaker=function(nodeData,outBatchSprites,initTool){
- var node;
- switch (nodeData.type){
- case "Scene3D":
- node=new Scene3D();
- break ;
- case "Sprite3D":
- node=new Sprite3D();
- break ;
- case "MeshSprite3D":
- node=new MeshSprite3D();
- (outBatchSprites)&& (outBatchSprites.push(node));
- break ;
- case "SkinnedMeshSprite3D":
- node=new SkinnedMeshSprite3D();
- break ;
- case "ShuriKenParticle3D":
- node=new ShuriKenParticle3D();
- break ;
- case "Terrain":
- node=new Terrain();
- break ;
- case "Camera":
- node=new Camera();
- break ;
- case "DirectionLight":
- node=new DirectionLight();
- break ;
- case "PointLight":
- node=new PointLight();
- break ;
- case "SpotLight":
- node=new SpotLight();
- break ;
- case "TrailSprite3D":
- node=new TrailSprite3D();
- break ;
- default :;
- var clas=ClassUtils.getClass(nodeData.props.runtime);
- node=new clas();
- break ;
- };
- var childData=nodeData.child;
- if (childData){
- for (var i=0,n=childData.length;i < n;i++){
- var child=Utils3D._createNodeByJsonForMaker(childData[i],outBatchSprites,initTool);
- node.addChild(child);
- }
- };
- var compId=nodeData.compId;
- (node).compId=compId;
- node._parse(nodeData.props,null);
- if (initTool){
- initTool._idMap[compId]=node;
- }
- Utils3D._compIdToNode[compId]=node;
- var componentsData=nodeData.components;
- if (componentsData){
- for (var j=0,m=componentsData.length;j < m;j++){
- var data=componentsData[j];
- clas=Browser.window.Laya[data.type];
- if (!clas){
- clas=Browser.window;
- var clasPaths=data.type.split('.');
- clasPaths.forEach(function(cls){
- clas=clas[cls];
- });
- }
- if (typeof(clas)=='function'){
- var comp=new clas();
- if (initTool){
- initTool._idMap[data.compId]=comp;
- console.log(data.compId);
- }
- }else {
- console.warn("Utils3D:Unkown component type.");
- }
- }
- }
- return node;
- }
- Utils3D._addComponentByJsonForMaker=function(nodeData,outBatchSprites,initTool){
- var compId=nodeData.compId;
- var node=Utils3D._compIdToNode[compId];
- var childData=nodeData.child;
- if (childData){
- for (var i=0,n=childData.length;i < n;i++){
- var child=Utils3D._addComponentByJsonForMaker(childData[i],outBatchSprites,initTool);
- }
- };
- var componentsData=nodeData.components;
- if (componentsData){
- for (var j=0,m=componentsData.length;j < m;j++){
- var data=componentsData[j];
- clas=Browser.window.Laya[data.type];
- if (!clas){
- var clasPaths=data.type.split('.');
- var clas=Browser.window;
- clasPaths.forEach(function(cls){
- clas=clas[cls];
- });
- }
- if (typeof(clas)=='function'){
- var component=initTool._idMap[data.compId];
- node.addComponentIntance(component);
- component._parse(data);
- }else {
- console.warn("Utils3D:Unkown component type.");
- }
- }
- }
- }
- Utils3D._createSprite3DInstance=function(nodeData,spriteMap,outBatchSprites){
- var node;
- switch (nodeData.type){
- case "Scene3D":
- node=new Scene3D();
- break ;
- case "Sprite3D":
- node=new Sprite3D();
- break ;
- case "MeshSprite3D":
- node=new MeshSprite3D();
- (outBatchSprites)&& (outBatchSprites.push(node));
- break ;
- case "SkinnedMeshSprite3D":
- node=new SkinnedMeshSprite3D();
- break ;
- case "ShuriKenParticle3D":
- node=new ShuriKenParticle3D();
- break ;
- case "Terrain":
- node=new Terrain();
- break ;
- case "Camera":
- node=new Camera();
- break ;
- case "DirectionLight":
- node=new DirectionLight();
- break ;
- case "PointLight":
- node=new PointLight();
- break ;
- case "SpotLight":
- node=new SpotLight();
- break ;
- case "TrailSprite3D":
- node=new TrailSprite3D();
- break ;
- default :
- throw new Error("Utils3D:unidentified class type in (.lh) file.");
- };
- var childData=nodeData.child;
- if (childData){
- for (var i=0,n=childData.length;i < n;i++){
- var child=Utils3D._createSprite3DInstance(childData[i],spriteMap,outBatchSprites)
- node.addChild(child);
- }
- }
- spriteMap[nodeData.instanceID]=node;
- return node;
- }
- Utils3D._createComponentInstance=function(nodeData,spriteMap){
- var node=spriteMap[nodeData.instanceID];
- node._parse(nodeData.props,spriteMap);
- var childData=nodeData.child;
- if (childData){
- for (var i=0,n=childData.length;i < n;i++)
- Utils3D._createComponentInstance(childData[i],spriteMap)
- };
- var componentsData=nodeData.components;
- if (componentsData){
- for (var j=0,m=componentsData.length;j < m;j++){
- var data=componentsData[j];
- var clas=Browser.window.Laya[data.type];
- if (!clas){
- var clasPaths=data.type.split('.');
- clas=Browser.window;
- clasPaths.forEach(function(cls){
- clas=clas[cls];
- });
- }
- if (typeof(clas)=='function'){
- var component=node.addComponent(clas);
- component._parse(data);
- }else {
- console.warn("Unkown component type.");
- }
- }
- }
- }
- Utils3D._createNodeByJson02=function(nodeData,outBatchSprites){
- var spriteMap={};
- var node=Utils3D._createSprite3DInstance(nodeData,spriteMap,outBatchSprites);
- Utils3D._createComponentInstance(nodeData,spriteMap);
- return node;
- }
- Utils3D._computeBoneAndAnimationDatasByBindPoseMatrxix=function(bones,curData,inverGlobalBindPose,outBonesDatas,outAnimationDatas,boneIndexToMesh){
- var offset=0;
- var matOffset=0;
- var i;
- var parentOffset;
- var boneLength=bones.length;
- for (i=0;i < boneLength;offset+=bones[i].keyframeWidth,matOffset+=16,i++){
- laya.d3.utils.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);
- if (i !=0){
- parentOffset=bones[i].parentIndex *16;
- laya.d3.utils.Utils3D.mulMatrixByArray(outBonesDatas,parentOffset,outBonesDatas,matOffset,outBonesDatas,matOffset);
- }
- };
- var n=inverGlobalBindPose.length;
- for (i=0;i < n;i++){
- laya.d3.utils.Utils3D.mulMatrixByArrayAndMatrixFast(outBonesDatas,boneIndexToMesh[i] *16,inverGlobalBindPose[i],outAnimationDatas,i *16);
- }
- }
- Utils3D._computeAnimationDatasByArrayAndMatrixFast=function(inverGlobalBindPose,bonesDatas,outAnimationDatas,boneIndexToMesh){
- for (var i=0,n=inverGlobalBindPose.length;i < n;i++)
- laya.d3.utils.Utils3D.mulMatrixByArrayAndMatrixFast(bonesDatas,boneIndexToMesh[i] *16,inverGlobalBindPose[i],outAnimationDatas,i *16);
- }
- Utils3D._computeBoneAndAnimationDatasByBindPoseMatrxixOld=function(bones,curData,inverGlobalBindPose,outBonesDatas,outAnimationDatas){
- var offset=0;
- var matOffset=0;
- var i;
- var parentOffset;
- var boneLength=bones.length;
- for (i=0;i < boneLength;offset+=bones[i].keyframeWidth,matOffset+=16,i++){
- laya.d3.utils.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);
- if (i !=0){
- parentOffset=bones[i].parentIndex *16;
- laya.d3.utils.Utils3D.mulMatrixByArray(outBonesDatas,parentOffset,outBonesDatas,matOffset,outBonesDatas,matOffset);
- }
- };
- var n=inverGlobalBindPose.length;
- for (i=0;i < n;i++){
- var arrayOffset=i *16;
- laya.d3.utils.Utils3D.mulMatrixByArrayAndMatrixFast(outBonesDatas,arrayOffset,inverGlobalBindPose[i],outAnimationDatas,arrayOffset);
- }
- }
- Utils3D._computeAnimationDatasByArrayAndMatrixFastOld=function(inverGlobalBindPose,bonesDatas,outAnimationDatas){
- var n=inverGlobalBindPose.length;
- for (var i=0;i < n;i++){
- var arrayOffset=i *16;
- laya.d3.utils.Utils3D.mulMatrixByArrayAndMatrixFast(bonesDatas,arrayOffset,inverGlobalBindPose[i],outAnimationDatas,arrayOffset);
- }
- }
- Utils3D._computeRootAnimationData=function(bones,curData,animationDatas){
- for (var i=0,offset=0,matOffset=0,boneLength=bones.length;i < boneLength;offset+=bones[i].keyframeWidth,matOffset+=16,i++)
- laya.d3.utils.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);
- }
- Utils3D.transformVector3ArrayByQuat=function(sourceArray,sourceOffset,rotation,outArray,outOffset){
- 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;
- outArray[outOffset]=ix *qw+iw *-qx+iy *-qz-iz *-qy;
- outArray[outOffset+1]=iy *qw+iw *-qy+iz *-qx-ix *-qz;
- outArray[outOffset+2]=iz *qw+iw *-qz+ix *-qy-iy *-qx;
- }
- Utils3D.mulMatrixByArray=function(leftArray,leftOffset,rightArray,rightOffset,outArray,outOffset){
- var i,ai0,ai1,ai2,ai3;
- if (outArray===rightArray){
- rightArray=Utils3D._tempArray16_3;
- for (i=0;i < 16;++i){
- rightArray[i]=outArray[outOffset+i];
- }
- rightOffset=0;
- }
- for (i=0;i < 4;i++){
- ai0=leftArray[leftOffset+i];
- ai1=leftArray[leftOffset+i+4];
- ai2=leftArray[leftOffset+i+8];
- ai3=leftArray[leftOffset+i+12];
- outArray[outOffset+i]=ai0 *rightArray[rightOffset+0]+ai1 *rightArray[rightOffset+1]+ai2 *rightArray[rightOffset+2]+ai3 *rightArray[rightOffset+3];
- outArray[outOffset+i+4]=ai0 *rightArray[rightOffset+4]+ai1 *rightArray[rightOffset+5]+ai2 *rightArray[rightOffset+6]+ai3 *rightArray[rightOffset+7];
- outArray[outOffset+i+8]=ai0 *rightArray[rightOffset+8]+ai1 *rightArray[rightOffset+9]+ai2 *rightArray[rightOffset+10]+ai3 *rightArray[rightOffset+11];
- outArray[outOffset+i+12]=ai0 *rightArray[rightOffset+12]+ai1 *rightArray[rightOffset+13]+ai2 *rightArray[rightOffset+14]+ai3 *rightArray[rightOffset+15];
- }
- }
- Utils3D.mulMatrixByArrayFast=function(leftArray,leftOffset,rightArray,rightOffset,outArray,outOffset){
- var i,ai0,ai1,ai2,ai3;
- for (i=0;i < 4;i++){
- ai0=leftArray[leftOffset+i];
- ai1=leftArray[leftOffset+i+4];
- ai2=leftArray[leftOffset+i+8];
- ai3=leftArray[leftOffset+i+12];
- outArray[outOffset+i]=ai0 *rightArray[rightOffset+0]+ai1 *rightArray[rightOffset+1]+ai2 *rightArray[rightOffset+2]+ai3 *rightArray[rightOffset+3];
- outArray[outOffset+i+4]=ai0 *rightArray[rightOffset+4]+ai1 *rightArray[rightOffset+5]+ai2 *rightArray[rightOffset+6]+ai3 *rightArray[rightOffset+7];
- outArray[outOffset+i+8]=ai0 *rightArray[rightOffset+8]+ai1 *rightArray[rightOffset+9]+ai2 *rightArray[rightOffset+10]+ai3 *rightArray[rightOffset+11];
- outArray[outOffset+i+12]=ai0 *rightArray[rightOffset+12]+ai1 *rightArray[rightOffset+13]+ai2 *rightArray[rightOffset+14]+ai3 *rightArray[rightOffset+15];
- }
- }
- Utils3D.mulMatrixByArrayAndMatrixFast=function(leftArray,leftOffset,rightMatrix,outArray,outOffset){
- var i,ai0,ai1,ai2,ai3;
- var rightMatrixE=rightMatrix.elements;
- var m11=rightMatrixE[0],m12=rightMatrixE[1],m13=rightMatrixE[2],m14=rightMatrixE[3];
- var m21=rightMatrixE[4],m22=rightMatrixE[5],m23=rightMatrixE[6],m24=rightMatrixE[7];
- var m31=rightMatrixE[8],m32=rightMatrixE[9],m33=rightMatrixE[10],m34=rightMatrixE[11];
- var m41=rightMatrixE[12],m42=rightMatrixE[13],m43=rightMatrixE[14],m44=rightMatrixE[15];
- var ai0LeftOffset=leftOffset;
- var ai1LeftOffset=leftOffset+4;
- var ai2LeftOffset=leftOffset+8;
- var ai3LeftOffset=leftOffset+12;
- var ai0OutOffset=outOffset;
- var ai1OutOffset=outOffset+4;
- var ai2OutOffset=outOffset+8;
- var ai3OutOffset=outOffset+12;
- for (i=0;i < 4;i++){
- ai0=leftArray[ai0LeftOffset+i];
- ai1=leftArray[ai1LeftOffset+i];
- ai2=leftArray[ai2LeftOffset+i];
- ai3=leftArray[ai3LeftOffset+i];
- outArray[ai0OutOffset+i]=ai0 *m11+ai1 *m12+ai2 *m13+ai3 *m14;
- outArray[ai1OutOffset+i]=ai0 *m21+ai1 *m22+ai2 *m23+ai3 *m24;
- outArray[ai2OutOffset+i]=ai0 *m31+ai1 *m32+ai2 *m33+ai3 *m34;
- outArray[ai3OutOffset+i]=ai0 *m41+ai1 *m42+ai2 *m43+ai3 *m44;
- }
- }
- Utils3D.createAffineTransformationArray=function(tX,tY,tZ,rX,rY,rZ,rW,sX,sY,sZ,outArray,outOffset){
- var x2=rX+rX,y2=rY+rY,z2=rZ+rZ;
- var xx=rX *x2,xy=rX *y2,xz=rX *z2,yy=rY *y2,yz=rY *z2,zz=rZ *z2;
- var wx=rW *x2,wy=rW *y2,wz=rW *z2;
- outArray[outOffset+0]=(1-(yy+zz))*sX;
- outArray[outOffset+1]=(xy+wz)*sX;
- outArray[outOffset+2]=(xz-wy)*sX;
- outArray[outOffset+3]=0;
- outArray[outOffset+4]=(xy-wz)*sY;
- outArray[outOffset+5]=(1-(xx+zz))*sY;
- outArray[outOffset+6]=(yz+wx)*sY;
- outArray[outOffset+7]=0;
- outArray[outOffset+8]=(xz+wy)*sZ;
- outArray[outOffset+9]=(yz-wx)*sZ;
- outArray[outOffset+10]=(1-(xx+yy))*sZ;
- outArray[outOffset+11]=0;
- outArray[outOffset+12]=tX;
- outArray[outOffset+13]=tY;
- outArray[outOffset+14]=tZ;
- outArray[outOffset+15]=1;
- }
- Utils3D.transformVector3ArrayToVector3ArrayCoordinate=function(source,sourceOffset,transform,result,resultOffset){
- var coordinateX=source[sourceOffset+0];
- var coordinateY=source[sourceOffset+1];
- var coordinateZ=source[sourceOffset+2];
- var transformElem=transform.elements;
- var w=((coordinateX *transformElem[3])+(coordinateY *transformElem[7])+(coordinateZ *transformElem[11])+transformElem[15]);
- result[resultOffset]=(coordinateX *transformElem[0])+(coordinateY *transformElem[4])+(coordinateZ *transformElem[8])+transformElem[12] / w;
- result[resultOffset+1]=(coordinateX *transformElem[1])+(coordinateY *transformElem[5])+(coordinateZ *transformElem[9])+transformElem[13] / w;
- result[resultOffset+2]=(coordinateX *transformElem[2])+(coordinateY *transformElem[6])+(coordinateZ *transformElem[10])+transformElem[14] / w;
- }
- Utils3D.transformLightingMapTexcoordArray=function(source,sourceOffset,lightingMapScaleOffset,result,resultOffset){
- result[resultOffset+0]=source[sourceOffset+0] *lightingMapScaleOffset.x+lightingMapScaleOffset.z;
- result[resultOffset+1]=1.0-((1.0-source[sourceOffset+1])*lightingMapScaleOffset.y+lightingMapScaleOffset.w);
- }
- Utils3D.getURLVerion=function(url){
- var index=url.indexOf("?");
- return index >=0 ? url.substr(index):null;
- }
- Utils3D._createAffineTransformationArray=function(trans,rot,scale,outE){
- var x=rot.x,y=rot.y,z=rot.z,w=rot.w,x2=x+x,y2=y+y,z2=z+z;
- var xx=x *x2,xy=x *y2,xz=x *z2,yy=y *y2,yz=y *z2,zz=z *z2;
- var wx=w *x2,wy=w *y2,wz=w *z2,sx=scale.x,sy=scale.y,sz=scale.z;
- outE[0]=(1-(yy+zz))*sx;
- outE[1]=(xy+wz)*sx;
- outE[2]=(xz-wy)*sx;
- outE[3]=0;
- outE[4]=(xy-wz)*sy;
- outE[5]=(1-(xx+zz))*sy;
- outE[6]=(yz+wx)*sy;
- outE[7]=0;
- outE[8]=(xz+wy)*sz;
- outE[9]=(yz-wx)*sz;
- outE[10]=(1-(xx+yy))*sz;
- outE[11]=0;
- outE[12]=trans.x;
- outE[13]=trans.y;
- outE[14]=trans.z;
- outE[15]=1;
- }
- Utils3D._mulMatrixArray=function(leftMatrixE,rightMatrix,outArray,outOffset){
- var i,ai0,ai1,ai2,ai3;
- var rightMatrixE=rightMatrix.elements;
- var m11=rightMatrixE[0],m12=rightMatrixE[1],m13=rightMatrixE[2],m14=rightMatrixE[3];
- var m21=rightMatrixE[4],m22=rightMatrixE[5],m23=rightMatrixE[6],m24=rightMatrixE[7];
- var m31=rightMatrixE[8],m32=rightMatrixE[9],m33=rightMatrixE[10],m34=rightMatrixE[11];
- var m41=rightMatrixE[12],m42=rightMatrixE[13],m43=rightMatrixE[14],m44=rightMatrixE[15];
- var ai0OutOffset=outOffset;
- var ai1OutOffset=outOffset+4;
- var ai2OutOffset=outOffset+8;
- var ai3OutOffset=outOffset+12;
- for (i=0;i < 4;i++){
- ai0=leftMatrixE[i];
- ai1=leftMatrixE[i+4];
- ai2=leftMatrixE[i+8];
- ai3=leftMatrixE[i+12];
- outArray[ai0OutOffset+i]=ai0 *m11+ai1 *m12+ai2 *m13+ai3 *m14;
- outArray[ai1OutOffset+i]=ai0 *m21+ai1 *m22+ai2 *m23+ai3 *m24;
- outArray[ai2OutOffset+i]=ai0 *m31+ai1 *m32+ai2 *m33+ai3 *m34;
- outArray[ai3OutOffset+i]=ai0 *m41+ai1 *m42+ai2 *m43+ai3 *m44;
- }
- }
- Utils3D.arcTanAngle=function(x,y){
- if (x==0){
- if (y==1)
- return Math.PI / 2;
- return-Math.PI / 2;
- }
- if (x > 0)
- return Math.atan(y / x);
- if (x < 0){
- if (y > 0)
- return Math.atan(y / x)+Math.PI;
- return Math.atan(y / x)-Math.PI;
- }
- return 0;
- }
- Utils3D.angleTo=function(from,location,angle){
- Vector3.subtract(location,from,Quaternion.TEMPVector30);
- Vector3.normalize(Quaternion.TEMPVector30,Quaternion.TEMPVector30);
- angle.x=Math.asin(Quaternion.TEMPVector30.y);
- angle.y=Utils3D.arcTanAngle(-Quaternion.TEMPVector30.z,-Quaternion.TEMPVector30.x);
- }
- Utils3D.transformQuat=function(source,rotation,out){
- var re=rotation;
- 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;
- out.x=ix *qw+iw *-qx+iy *-qz-iz *-qy;
- out.y=iy *qw+iw *-qy+iz *-qx-ix *-qz;
- out.z=iz *qw+iw *-qz+ix *-qy-iy *-qx;
- }
- Utils3D.quaternionWeight=function(f,weight,e){
- e.x=f.x *weight;
- e.y=f.y *weight;
- e.z=f.z *weight;
- e.w=f.w;
- }
- Utils3D.quaternionConjugate=function(value,result){
- result.x=-value.x;
- result.y=-value.y;
- result.z=-value.z;
- result.w=value.w;
- }
- Utils3D.scaleWeight=function(s,w,out){
- var sX=s.x,sY=s.y,sZ=s.z;
- out.x=sX > 0 ? Math.pow(Math.abs(sX),w):-Math.pow(Math.abs(sX),w);
- out.y=sY > 0 ? Math.pow(Math.abs(sY),w):-Math.pow(Math.abs(sY),w);
- out.z=sZ > 0 ? Math.pow(Math.abs(sZ),w):-Math.pow(Math.abs(sZ),w);
- }
- Utils3D.scaleBlend=function(sa,sb,w,out){
- var saw=Utils3D._tempVector3_0;
- var sbw=Utils3D._tempVector3_1;
- Utils3D.scaleWeight(sa,1.0-w,saw);
- Utils3D.scaleWeight(sb,w,sbw);
- var sng=w > 0.5 ? sb :sa;
- out.x=sng.x > 0 ? Math.abs(saw.x *sbw.x):-Math.abs(saw.x *sbw.x);
- out.y=sng.y > 0 ? Math.abs(saw.y *sbw.y):-Math.abs(saw.y *sbw.y);
- out.z=sng.z > 0 ? Math.abs(saw.z *sbw.z):-Math.abs(saw.z *sbw.z);
- }
- Utils3D.gammaToLinearSpace=function(value){
- if (value <=0.04045)
- return value / 12.92;
- else if (value < 1.0)
- return Math.pow((value+0.055)/ 1.055,2.4);
- else
- return Math.pow(value,2.4);
- }
- Utils3D.linearToGammaSpace=function(value){
- if (value <=0.0)
- return 0.0;
- else if (value <=0.0031308)
- return 12.92 *value;
- else if (value <=1.0)
- return 1.055 *Math.pow(value,0.41666)-0.055;
- else
- return Math.pow(value,0.41666);
- }
- Utils3D.matrix4x4MultiplyFFF=function(a,b,e){
- var i,ai0,ai1,ai2,ai3;
- if (e===b){
- b=new Float32Array(16);
- for (i=0;i < 16;++i){
- b[i]=e[i];
- }
- };
- var b0=b[0],b1=b[1],b2=b[2],b3=b[3];
- var b4=b[4],b5=b[5],b6=b[6],b7=b[7];
- var b8=b[8],b9=b[9],b10=b[10],b11=b[11];
- var b12=b[12],b13=b[13],b14=b[14],b15=b[15];
- for (i=0;i < 4;i++){
- ai0=a[i];
- ai1=a[i+4];
- ai2=a[i+8];
- ai3=a[i+12];
- e[i]=ai0 *b0+ai1 *b1+ai2 *b2+ai3 *b3;
- e[i+4]=ai0 *b4+ai1 *b5+ai2 *b6+ai3 *b7;
- e[i+8]=ai0 *b8+ai1 *b9+ai2 *b10+ai3 *b11;
- e[i+12]=ai0 *b12+ai1 *b13+ai2 *b14+ai3 *b15;
- }
- }
- Utils3D.matrix4x4MultiplyFFFForNative=function(a,b,e){
- LayaGL.instance.matrix4x4Multiply(a,b,e);
- }
- Utils3D.matrix4x4MultiplyMFM=function(left,right,out){
- Utils3D.matrix4x4MultiplyFFF(left.elements,right,out.elements);
- }
- Utils3D._buildTexture2D=function(width,height,format,colorFunc,mipmaps){
- (mipmaps===void 0)&& (mipmaps=false);
- var texture=new Texture2D(width,height,format,mipmaps,true);
- texture.anisoLevel=1;
- texture.filterMode=/*laya.resource.BaseTexture.FILTERMODE_POINT*/0;
- TextureGenerator._generateTexture2D(texture,width,height,colorFunc);
- return texture;
- }
- Utils3D._drawBound=function(debugLine,boundBox,color){
- if (debugLine.lineCount+12 > debugLine.maxLineCount)
- debugLine.maxLineCount+=12;
- var start=Utils3D._tempVector3_0;
- var end=Utils3D._tempVector3_1;
- var min=boundBox.min;
- var max=boundBox.max;
- start.setValue(min.x,min.y,min.z);
- end.setValue(max.x,min.y,min.z);
- debugLine.addLine(start,end,color,color);
- start.setValue(min.x,min.y,min.z);
- end.setValue(min.x,min.y,max.z);
- debugLine.addLine(start,end,color,color);
- start.setValue(max.x,min.y,min.z);
- end.setValue(max.x,min.y,max.z);
- debugLine.addLine(start,end,color,color);
- start.setValue(min.x,min.y,max.z);
- end.setValue(max.x,min.y,max.z);
- debugLine.addLine(start,end,color,color);
- start.setValue(min.x,min.y,min.z);
- end.setValue(min.x,max.y,min.z);
- debugLine.addLine(start,end,color,color);
- start.setValue(min.x,min.y,max.z);
- end.setValue(min.x,max.y,max.z);
- debugLine.addLine(start,end,color,color);
- start.setValue(max.x,min.y,min.z);
- end.setValue(max.x,max.y,min.z);
- debugLine.addLine(start,end,color,color);
- start.setValue(max.x,min.y,max.z);
- end.setValue(max.x,max.y,max.z);
- debugLine.addLine(start,end,color,color);
- start.setValue(min.x,max.y,min.z);
- end.setValue(max.x,max.y,min.z);
- debugLine.addLine(start,end,color,color);
- start.setValue(min.x,max.y,min.z);
- end.setValue(min.x,max.y,max.z);
- debugLine.addLine(start,end,color,color);
- start.setValue(max.x,max.y,min.z);
- end.setValue(max.x,max.y,max.z);
- debugLine.addLine(start,end,color,color);
- start.setValue(min.x,max.y,max.z);
- end.setValue(max.x,max.y,max.z);
- debugLine.addLine(start,end,color,color);
- }
- Utils3D._getHierarchyPath=function(rootSprite,checkSprite,path){
- path.length=0;
- var sprite=checkSprite;
- while (sprite!==rootSprite){
- var parent=sprite._parent;
- if (parent)
- path.push(parent.getChildIndex(sprite));
- else
- return null;
- sprite=parent;
- }
- return path;
- }
- Utils3D._getNodeByHierarchyPath=function(rootSprite,invPath){
- var sprite=rootSprite;
- for (var i=invPath.length-1;i >=0;i--){
- sprite=sprite.getChildAt(invPath[i]);
- }
- return sprite;
- }
- Utils3D._createNodeByJson=function(nodeData,outBatchSprites){
- var node;
- switch (nodeData.type){
- case "Scene3D":
- node=new Scene3D();
- break ;
- case "Sprite3D":
- node=new Sprite3D();
- break ;
- case "MeshSprite3D":
- node=new MeshSprite3D();
- (outBatchSprites)&& (outBatchSprites.push(node));
- break ;
- case "SkinnedMeshSprite3D":
- node=new SkinnedMeshSprite3D();
- break ;
- case "ShuriKenParticle3D":
- node=new ShuriKenParticle3D();
- break ;
- case "Terrain":
- node=new Terrain();
- break ;
- case "Camera":
- node=new Camera();
- break ;
- case "DirectionLight":
- node=new DirectionLight();
- break ;
- case "PointLight":
- node=new PointLight();
- break ;
- case "SpotLight":
- node=new SpotLight();
- break ;
- case "TrailSprite3D":
- node=new TrailSprite3D();
- break ;
- default :
- throw new Error("Utils3D:unidentified class type in (.lh) file.");
- };
- var childData=nodeData.child;
- if (childData){
- for (var i=0,n=childData.length;i < n;i++){
- var child=Utils3D._createNodeByJson(childData[i],outBatchSprites)
- node.addChild(child);
- }
- };
- var componentsData=nodeData.components;
- if (componentsData){
- for (var j=0,m=componentsData.length;j < m;j++){
- var data=componentsData[j];
- clas=Browser.window.Laya[data.type];
- if (!clas){
- var clasPaths=data.type.split('.');
- var clas=Browser.window;
- clasPaths.forEach(function(cls){
- clas=clas[cls];
- });
- }
- if (typeof(clas)=='function'){
- var component=node.addComponent(clas);
- component._parse(data);
- }else {
- console.warn("Unkown component type.");
- }
- }
- }
- node._parse(nodeData.props,null);
- return node;
- }
- Utils3D._tempArray16_0=new Float32Array(16);
- Utils3D._tempArray16_1=new Float32Array(16);
- Utils3D._tempArray16_2=new Float32Array(16);
- Utils3D._tempArray16_3=new Float32Array(16);
- __static(Utils3D,
- ['_tempVector3_0',function(){return this._tempVector3_0=new Vector3();},'_tempVector3_1',function(){return this._tempVector3_1=new Vector3();},'_tempVector3_2',function(){return this._tempVector3_2=new Vector3();},'_tempColor0',function(){return this._tempColor0=new Color();},'_compIdToNode',function(){return this._compIdToNode=new Object();}
- ]);
- return Utils3D;
- })()
- /**
- *<code>GradientDataNumber</code> 类用于创建浮点渐变。
- */
- //class laya.d3.core.particleShuriKen.module.GradientDataNumber
- var GradientDataNumber=(function(){
- function GradientDataNumber(){
- /**@private */
- this._currentLength=0;
- /**@private 开发者禁止修改。*/
- this._elements=null;
- this._elements=new Float32Array(8);
- }
- __class(GradientDataNumber,'laya.d3.core.particleShuriKen.module.GradientDataNumber');
- var __proto=GradientDataNumber.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *增加浮点渐变。
- *@param key 生命周期,范围为0到1。
- *@param value 浮点值。
- */
- __proto.add=function(key,value){
- if (this._currentLength < 8){
- if ((this._currentLength===6)&& ((key!==1))){
- key=1;
- console.log("GradientDataNumber warning:the forth key is be force set to 1.");
- }
- this._elements[this._currentLength++]=key;
- this._elements[this._currentLength++]=value;
- }else {
- console.log("GradientDataNumber warning:data count must lessEqual than 4");
- }
- }
- /**
- *通过索引获取键。
- *@param index 索引。
- *@return value 键。
- */
- __proto.getKeyByIndex=function(index){
- return this._elements[index *2];
- }
- /**
- *通过索引获取值。
- *@param index 索引。
- *@return value 值。
- */
- __proto.getValueByIndex=function(index){
- return this._elements[index *2+1];
- }
- /**
- *获取平均值。
- */
- __proto.getAverageValue=function(){
- var total=0;
- for (var i=0,n=this._currentLength-2;i < n;i+=2){
- var subValue=this._elements[i+1];
- subValue+=this._elements[i+3];
- subValue=subValue *(this._elements[i+2]-this._elements[i]);
- }
- return total / 2;
- }
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var destGradientDataNumber=destObject;
- destGradientDataNumber._currentLength=this._currentLength;
- var destElements=destGradientDataNumber._elements;
- destElements.length=this._elements.length;
- for (var i=0,n=this._elements.length;i < n;i++)
- destElements[i]=this._elements[i];
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var destGradientDataNumber=/*__JS__ */new this.constructor();
- this.cloneTo(destGradientDataNumber);
- return destGradientDataNumber;
- }
- /**渐变浮点数量。*/
- __getset(0,__proto,'gradientCount',function(){
- return this._currentLength / 2;
- });
- return GradientDataNumber;
- })()
- /**
- *...
- *@author
- */
- //class laya.d3.core.pixelLine.PixelLineVertex
- var PixelLineVertex=(function(){
- function PixelLineVertex(){}
- __class(PixelLineVertex,'laya.d3.core.pixelLine.PixelLineVertex');
- var __proto=PixelLineVertex.prototype;
- __getset(0,__proto,'vertexDeclaration',function(){
- return PixelLineVertex._vertexDeclaration;
- });
- __getset(1,PixelLineVertex,'vertexDeclaration',function(){
- return PixelLineVertex._vertexDeclaration;
- });
- __static(PixelLineVertex,
- ['_vertexDeclaration',function(){return this._vertexDeclaration=new VertexDeclaration(28,
- [new VertexElement(0,/*laya.d3.graphics.VertexElementFormat.Vector3*/"vector3",/*laya.d3.graphics.Vertex.VertexMesh.MESH_POSITION0*/0),
- new VertexElement(12,/*laya.d3.graphics.VertexElementFormat.Vector4*/"vector4",/*laya.d3.graphics.Vertex.VertexMesh.MESH_COLOR0*/1)]);}
- ]);
- return PixelLineVertex;
- })()
- /**
- *<code>CollisionMap</code> 类用于实现碰撞组合实例图。
- */
- //class laya.d3.physics.CollisionTool
- var CollisionTool=(function(){
- function CollisionTool(){
- /**@private */
- this._hitResultsPoolIndex=0;
- /**@private */
- this._contactPonintsPoolIndex=0;
- /**@private */
- this._collisions={};
- this._hitResultsPool=[];
- this._contactPointsPool=[];
- this._collisionsPool=[];
- }
- __class(CollisionTool,'laya.d3.physics.CollisionTool');
- var __proto=CollisionTool.prototype;
- /**
- *@private
- */
- __proto.getHitResult=function(){
- var hitResult=this._hitResultsPool[this._hitResultsPoolIndex++];
- if (!hitResult){
- hitResult=new HitResult();
- this._hitResultsPool.push(hitResult);
- }
- return hitResult;
- }
- /**
- *@private
- */
- __proto.recoverAllHitResultsPool=function(){
- this._hitResultsPoolIndex=0;
- }
- /**
- *@private
- */
- __proto.getContactPoints=function(){
- var contactPoint=this._contactPointsPool[this._contactPonintsPoolIndex++];
- if (!contactPoint){
- contactPoint=new ContactPoint();
- this._contactPointsPool.push(contactPoint);
- }
- return contactPoint;
- }
- /**
- *@private
- */
- __proto.recoverAllContactPointsPool=function(){
- this._contactPonintsPoolIndex=0;
- }
- /**
- *@private
- */
- __proto.getCollision=function(physicComponentA,physicComponentB){
- var collision;
- var idA=physicComponentA.id;
- var idB=physicComponentB.id;
- var subCollisionFirst=this._collisions[idA];
- if (subCollisionFirst)
- collision=subCollisionFirst[idB];
- if (!collision){
- if (!subCollisionFirst){
- subCollisionFirst={};
- this._collisions[idA]=subCollisionFirst;
- }
- collision=this._collisionsPool.length===0 ? new Collision():this._collisionsPool.pop();
- collision._colliderA=physicComponentA;
- collision._colliderB=physicComponentB;
- subCollisionFirst[idB]=collision;
- }
- return collision;
- }
- /**
- *@private
- */
- __proto.recoverCollision=function(collision){
- var idA=collision._colliderA.id;
- var idB=collision._colliderB.id;
- this._collisions[idA][idB]=null;
- this._collisionsPool.push(collision);
- }
- /**
- *@private
- */
- __proto.garbageCollection=function(){
- this._hitResultsPoolIndex=0;
- this._hitResultsPool.length=0;
- this._contactPonintsPoolIndex=0;
- this._contactPointsPool.length=0;
- this._collisionsPool.length=0;
- for (var subCollisionsKey in this._collisionsPool){
- var subCollisions=this._collisionsPool[subCollisionsKey];
- var wholeDelete=true;
- for (var collisionKey in subCollisions){
- if (subCollisions[collisionKey])
- wholeDelete=false;
- else
- delete subCollisions[collisionKey];
- }
- if (wholeDelete)
- delete this._collisionsPool[subCollisionsKey];
- }
- }
- return CollisionTool;
- })()
- /**
- *<code>Input3D</code> 类用于实现3D输入。
- */
- //class laya.d3.Input3D
- var Input3D=(function(){
- function Input3D(){
- /**@private */
- this._scene=null;
- /**@private */
- this._eventList=[];
- /**@private */
- this._multiTouchEnabled=true;
- this._mouseTouch=new MouseTouch();
- this._touchPool=[];
- this._touches=new SimpleSingletonList();
- }
- __class(Input3D,'laya.d3.Input3D');
- var __proto=Input3D.prototype;
- /**
- *@private
- */
- __proto.__init__=function(canvas,scene){
- this._scene=scene;
- var list=this._eventList;
- canvas.oncontextmenu=function (e){
- return false;
- }
- canvas.addEventListener('mousedown',function(e){
- e.preventDefault();
- list.push(e);
- });
- canvas.addEventListener('mouseup',function(e){
- e.preventDefault();
- list.push(e);
- },true);
- canvas.addEventListener('mousemove',function(e){
- e.preventDefault();
- list.push(e);
- },true);
- canvas.addEventListener("touchstart",function(e){
- e.preventDefault();
- list.push(e);
- });
- canvas.addEventListener("touchend",function(e){
- e.preventDefault();
- list.push(e);
- },true);
- canvas.addEventListener("touchmove",function(e){
- e.preventDefault();
- list.push(e);
- },true);
- canvas.addEventListener("touchcancel",function(e){
- list.push(e);
- },true);
- }
- /**
- *获取触摸点个数。
- *@return 触摸点个数。
- */
- __proto.touchCount=function(){
- return this._touches.length;
- }
- /**
- *@private
- */
- __proto._getTouch=function(touchID){
- var touch=this._touchPool[touchID];
- if (!touch){
- touch=new Touch();
- this._touchPool[touchID]=touch;
- touch._identifier=touchID;
- }
- return touch;
- }
- /**
- *@private
- */
- __proto._mouseTouchDown=function(){
- var touch=this._mouseTouch;
- var sprite=touch.sprite;
- touch._pressedSprite=sprite;
- touch._pressedLoopCount=Stat.loopCount;
- if (sprite){
- var scripts=sprite._scripts;
- if (scripts){
- for (var i=0,n=scripts.length;i < n;i++)
- scripts[i].onMouseDown();
- }
- }
- }
- /**
- *@private
- */
- __proto._mouseTouchUp=function(){
- var i=0,n=0;
- var touch=this._mouseTouch;
- var lastPressedSprite=touch._pressedSprite;
- touch._pressedSprite=null;
- touch._pressedLoopCount=-1;
- var sprite=touch.sprite;
- if (sprite){
- if (sprite===lastPressedSprite){
- var scripts=sprite._scripts;
- if (scripts){
- for (i=0,n=scripts.length;i < n;i++)
- scripts[i].onMouseClick();
- }
- }
- }
- if (lastPressedSprite){
- var lastScripts=lastPressedSprite._scripts;
- if (lastScripts){
- for (i=0,n=lastScripts.length;i < n;i++)
- lastScripts[i].onMouseUp();
- }
- }
- }
- /**
- *@private
- */
- __proto._mouseTouchRayCast=function(cameras){
- var touchHitResult=Input3D._tempHitResult0;
- var touchPos=Input3D._tempVector20;
- var touchRay=Input3D._tempRay0;
- touchHitResult.succeeded=false;
- var x=this._mouseTouch.mousePositionX;
- var y=this._mouseTouch.mousePositionY;
- touchPos.x=x;
- touchPos.y=y;
- for (var i=cameras.length-1;i >=0;i--){
- var camera=cameras [i];
- var viewport=camera.viewport;
- if (touchPos.x >=viewport.x && touchPos.y >=viewport.y && touchPos.x <=viewport.width && touchPos.y <=viewport.height){
- camera.viewportPointToRay(touchPos,touchRay);
- var sucess=this._scene._physicsSimulation.rayCast(touchRay,touchHitResult);
- if (sucess || (camera.clearFlag===/*laya.d3.core.BaseCamera.CLEARFLAG_SOLIDCOLOR*/0 || camera.clearFlag===/*laya.d3.core.BaseCamera.CLEARFLAG_SKY*/1))
- break ;
- }
- };
- var touch=this._mouseTouch;
- var lastSprite=touch.sprite;
- if (touchHitResult.succeeded){
- var touchSprite=touchHitResult.collider.owner;
- touch.sprite=touchSprite;
- var scripts=touchSprite._scripts;
- if (lastSprite!==touchSprite){
- if (scripts){
- for (var j=0,m=scripts.length;j < m;j++)
- scripts[j].onMouseEnter();
- }
- }
- }else {
- touch.sprite=null;
- }
- if (lastSprite && (lastSprite!==touchSprite)){
- var outScripts=lastSprite._scripts;
- if (outScripts){
- for (j=0,m=outScripts.length;j < m;j++)
- outScripts[j].onMouseOut();
- }
- }
- }
- /**
- *@private
- *@param flag 0:add、1:remove、2:change
- */
- __proto._changeTouches=function(changedTouches,flag){
- var offsetX=0,offsetY=0;
- var lastCount=this._touches.length;
- for (var j=0,m=changedTouches.length;j < m;j++){
- var nativeTouch=changedTouches[j];
- var identifier=nativeTouch.identifier;
- if (!this._multiTouchEnabled && identifier!==0)
- continue ;
- var touch=this._getTouch(identifier);
- var pos=touch._position;
- var mousePoint=Input3D._tempPoint;
- mousePoint.setTo(nativeTouch.pageX,nativeTouch.pageY);
- Laya.stage._canvasTransform.invertTransformPoint(mousePoint);
- var posX=mousePoint.x;
- var posY=mousePoint.y;
- switch (flag){
- case 0:
- this._touches.add(touch);
- offsetX+=posX;
- offsetY+=posY;
- break ;
- case 1:
- this._touches.remove(touch);
- offsetX-=posX;
- offsetY-=posY;
- break ;
- case 2:
- offsetX=posX-pos.x;
- offsetY=posY-pos.y;
- break ;
- }
- pos.x=posX;
- pos.y=posY;
- };
- var touchCount=this._touches.length;
- if (touchCount===0){
- this._mouseTouch.mousePositionX=0;
- this._mouseTouch.mousePositionY=0;
- }else {
- this._mouseTouch.mousePositionX=(this._mouseTouch.mousePositionX *lastCount+offsetX)/ touchCount;
- this._mouseTouch.mousePositionY=(this._mouseTouch.mousePositionY *lastCount+offsetY)/ touchCount;
- }
- }
- /**
- *@private
- */
- __proto._update=function(){
- var i=0,n=0,j=0,m=0;
- n=this._eventList.length;
- var cameras=this._scene._cameraPool;
- if (n > 0){
- for (i=0;i < n;i++){
- var e=this._eventList[i];
- switch (e.type){
- case "mousedown":
- this._mouseTouchDown();
- break ;
- case "mouseup":
- this._mouseTouchUp();
- break ;
- case "mousemove":;
- var mousePoint=Input3D._tempPoint;
- mousePoint.setTo(e.pageX,e.pageY);
- Laya.stage._canvasTransform.invertTransformPoint(mousePoint);
- this._mouseTouch.mousePositionX=mousePoint.x;
- this._mouseTouch.mousePositionY=mousePoint.y;
- this._mouseTouchRayCast(cameras);
- break ;
- case "touchstart":;
- var lastLength=this._touches.length;
- this._changeTouches(e.changedTouches,0);
- this._mouseTouchRayCast(cameras);
- (lastLength===0)&& (this._mouseTouchDown());
- break ;
- case "touchend":
- case "touchcancel":
- this._changeTouches(e.changedTouches,1);
- (this._touches.length===0)&& (this._mouseTouchUp());
- break ;
- case "touchmove":
- this._changeTouches(e.changedTouches,2);
- this._mouseTouchRayCast(cameras);
- break ;
- default :
- throw "Input3D:unkonwn event type.";
- }
- }
- this._eventList.length=0;
- };
- var mouseTouch=this._mouseTouch;
- var pressedSprite=mouseTouch._pressedSprite;
- if (pressedSprite && (Stat.loopCount > mouseTouch._pressedLoopCount)){
- var pressedScripts=pressedSprite._scripts;
- if (pressedScripts){
- for (j=0,m=pressedScripts.length;j < m;j++)
- pressedScripts[j].onMouseDrag();
- }
- };
- var touchSprite=mouseTouch.sprite;
- if (touchSprite){
- var scripts=touchSprite._scripts;
- if (scripts){
- for (j=0,m=scripts.length;j < m;j++)
- scripts[j].onMouseOver();
- }
- }
- }
- /**
- *获取触摸点。
- *@param index 索引。
- *@return 触摸点。
- */
- __proto.getTouch=function(index){
- if (index < this._touches.length){
- return this._touches.elements [index];
- }else {
- return null;
- }
- }
- /**
- *设置是否可以使用多点触摸。
- *@param 是否可以使用多点触摸。
- */
- /**
- *获取是否可以使用多点触摸。
- *@return 是否可以使用多点触摸。
- */
- __getset(0,__proto,'multiTouchEnabled',function(){
- return this._multiTouchEnabled;
- },function(value){
- this._multiTouchEnabled=value;
- });
- __static(Input3D,
- ['_tempPoint',function(){return this._tempPoint=new Point();},'_tempVector20',function(){return this._tempVector20=new Vector2();},'_tempRay0',function(){return this._tempRay0=new Ray(new Vector3(),new Vector3());},'_tempHitResult0',function(){return this._tempHitResult0=new HitResult();}
- ]);
- return Input3D;
- })()
- /**
- *@private
- */
- //class laya.d3.core.particleShuriKen.ShurikenParticleData
- var ShurikenParticleData=(function(){
- function ShurikenParticleData(){}
- __class(ShurikenParticleData,'laya.d3.core.particleShuriKen.ShurikenParticleData');
- ShurikenParticleData._getStartLifetimeFromGradient=function(startLifeTimeGradient,emissionTime){
- for (var i=1,n=startLifeTimeGradient.gradientCount;i < n;i++){
- var key=startLifeTimeGradient.getKeyByIndex(i);
- if (key >=emissionTime){
- var lastKey=startLifeTimeGradient.getKeyByIndex(i-1);
- var age=(emissionTime-lastKey)/ (key-lastKey);
- return MathUtil.lerp(startLifeTimeGradient.getValueByIndex(i-1),startLifeTimeGradient.getValueByIndex(i),age)
- }
- }
- throw new Error("ShurikenParticleData: can't get value foam startLifeTimeGradient.");
- }
- ShurikenParticleData._randomInvertRoationArray=function(rotatonE,outE,randomizeRotationDirection,rand,randomSeeds){
- var randDic=NaN;
- if (rand){
- rand.seed=randomSeeds[6];
- randDic=rand.getFloat();
- randomSeeds[6]=rand.seed;
- }else {
- randDic=Math.random();
- }
- if (randDic < randomizeRotationDirection){
- outE.x=-rotatonE.x;
- outE.y=-rotatonE.y;
- outE.z=-rotatonE.z;
- }else {
- outE.x=rotatonE.x;
- outE.y=rotatonE.y;
- outE.z=rotatonE.z;
- }
- }
- ShurikenParticleData._randomInvertRoation=function(rotaton,randomizeRotationDirection,rand,randomSeeds){
- var randDic=NaN;
- if (rand){
- rand.seed=randomSeeds[6];
- randDic=rand.getFloat();
- randomSeeds[6]=rand.seed;
- }else {
- randDic=Math.random();
- }
- if (randDic < randomizeRotationDirection)
- rotaton=-rotaton;
- return rotaton;
- }
- ShurikenParticleData.create=function(particleSystem,particleRender,transform){
- var autoRandomSeed=particleSystem.autoRandomSeed;
- var rand=particleSystem._rand;
- var randomSeeds=particleSystem._randomSeeds;
- switch (particleSystem.startColorType){
- case 0:;
- var constantStartColor=particleSystem.startColorConstant;
- ShurikenParticleData.startColor.x=constantStartColor.x;
- ShurikenParticleData.startColor.y=constantStartColor.y;
- ShurikenParticleData.startColor.z=constantStartColor.z;
- ShurikenParticleData.startColor.w=constantStartColor.w;
- break ;
- case 2:
- if (autoRandomSeed){
- Vector4.lerp(particleSystem.startColorConstantMin,particleSystem.startColorConstantMax,Math.random(),ShurikenParticleData.startColor);
- }else {
- rand.seed=randomSeeds[3];
- Vector4.lerp(particleSystem.startColorConstantMin,particleSystem.startColorConstantMax,rand.getFloat(),ShurikenParticleData.startColor);
- randomSeeds[3]=rand.seed;
- }
- break ;
- };
- var colorOverLifetime=particleSystem.colorOverLifetime;
- if (colorOverLifetime && colorOverLifetime.enbale){
- var color=colorOverLifetime.color;
- switch (color.type){
- case 0:
- ShurikenParticleData.startColor.x=ShurikenParticleData.startColor.x *color.constant.x;
- ShurikenParticleData.startColor.y=ShurikenParticleData.startColor.y *color.constant.y;
- ShurikenParticleData.startColor.z=ShurikenParticleData.startColor.z *color.constant.z;
- ShurikenParticleData.startColor.w=ShurikenParticleData.startColor.w *color.constant.w;
- break ;
- case 2:;
- var colorRandom=NaN;
- if (autoRandomSeed){
- colorRandom=Math.random();
- }else {
- rand.seed=randomSeeds[10];
- colorRandom=rand.getFloat();
- randomSeeds[10]=rand.seed;
- };
- var minConstantColor=color.constantMin;
- var maxConstantColor=color.constantMax;
- ShurikenParticleData.startColor.x=ShurikenParticleData.startColor.x *MathUtil.lerp(minConstantColor.x,maxConstantColor.x,colorRandom);
- ShurikenParticleData.startColor.y=ShurikenParticleData.startColor.y *MathUtil.lerp(minConstantColor.y,maxConstantColor.y,colorRandom);
- ShurikenParticleData.startColor.z=ShurikenParticleData.startColor.z *MathUtil.lerp(minConstantColor.z,maxConstantColor.z,colorRandom);
- ShurikenParticleData.startColor.w=ShurikenParticleData.startColor.w *MathUtil.lerp(minConstantColor.w,maxConstantColor.w,colorRandom);
- break ;
- }
- };
- var particleSize=ShurikenParticleData.startSize;
- switch (particleSystem.startSizeType){
- case 0:
- if (particleSystem.threeDStartSize){
- var startSizeConstantSeparate=particleSystem.startSizeConstantSeparate;
- particleSize[0]=startSizeConstantSeparate.x;
- particleSize[1]=startSizeConstantSeparate.y;
- particleSize[2]=startSizeConstantSeparate.z;
- }else {
- particleSize[0]=particleSize[1]=particleSize[2]=particleSystem.startSizeConstant;
- }
- break ;
- case 2:
- if (particleSystem.threeDStartSize){
- var startSizeConstantMinSeparate=particleSystem.startSizeConstantMinSeparate;
- var startSizeConstantMaxSeparate=particleSystem.startSizeConstantMaxSeparate;
- if (autoRandomSeed){
- particleSize[0]=MathUtil.lerp(startSizeConstantMinSeparate.x,startSizeConstantMaxSeparate.x,Math.random());
- particleSize[1]=MathUtil.lerp(startSizeConstantMinSeparate.y,startSizeConstantMaxSeparate.y,Math.random());
- particleSize[2]=MathUtil.lerp(startSizeConstantMinSeparate.z,startSizeConstantMaxSeparate.z,Math.random());
- }else {
- rand.seed=randomSeeds[4];
- particleSize[0]=MathUtil.lerp(startSizeConstantMinSeparate.x,startSizeConstantMaxSeparate.x,rand.getFloat());
- particleSize[1]=MathUtil.lerp(startSizeConstantMinSeparate.y,startSizeConstantMaxSeparate.y,rand.getFloat());
- particleSize[2]=MathUtil.lerp(startSizeConstantMinSeparate.z,startSizeConstantMaxSeparate.z,rand.getFloat());
- randomSeeds[4]=rand.seed;
- }
- }else {
- if (autoRandomSeed){
- particleSize[0]=particleSize[1]=particleSize[2]=MathUtil.lerp(particleSystem.startSizeConstantMin,particleSystem.startSizeConstantMax,Math.random());
- }else {
- rand.seed=randomSeeds[4];
- particleSize[0]=particleSize[1]=particleSize[2]=MathUtil.lerp(particleSystem.startSizeConstantMin,particleSystem.startSizeConstantMax,rand.getFloat());
- randomSeeds[4]=rand.seed;
- }
- }
- break ;
- };
- var sizeOverLifetime=particleSystem.sizeOverLifetime;
- if (sizeOverLifetime && sizeOverLifetime.enbale && sizeOverLifetime.size.type===1){
- var size=sizeOverLifetime.size;
- if (size.separateAxes){
- if (autoRandomSeed){
- particleSize[0]=particleSize[0] *MathUtil.lerp(size.constantMinSeparate.x,size.constantMaxSeparate.x,Math.random());
- particleSize[1]=particleSize[1] *MathUtil.lerp(size.constantMinSeparate.y,size.constantMaxSeparate.y,Math.random());
- particleSize[2]=particleSize[2] *MathUtil.lerp(size.constantMinSeparate.z,size.constantMaxSeparate.z,Math.random());
- }else {
- rand.seed=randomSeeds[11];
- particleSize[0]=particleSize[0] *MathUtil.lerp(size.constantMinSeparate.x,size.constantMaxSeparate.x,rand.getFloat());
- particleSize[1]=particleSize[1] *MathUtil.lerp(size.constantMinSeparate.y,size.constantMaxSeparate.y,rand.getFloat());
- particleSize[2]=particleSize[2] *MathUtil.lerp(size.constantMinSeparate.z,size.constantMaxSeparate.z,rand.getFloat());
- randomSeeds[11]=rand.seed;
- }
- }else {
- var randomSize=NaN;
- if (autoRandomSeed){
- randomSize=MathUtil.lerp(size.constantMin,size.constantMax,Math.random());
- }else {
- rand.seed=randomSeeds[11];
- randomSize=MathUtil.lerp(size.constantMin,size.constantMax,rand.getFloat());
- randomSeeds[11]=rand.seed;
- }
- particleSize[0]=particleSize[0] *randomSize;
- particleSize[1]=particleSize[1] *randomSize;
- particleSize[2]=particleSize[2] *randomSize;
- }
- };
- var renderMode=particleRender.renderMode;
- if (renderMode!==1){
- switch (particleSystem.startRotationType){
- case 0:
- if (particleSystem.threeDStartRotation){
- var startRotationConstantSeparate=particleSystem.startRotationConstantSeparate;
- var randomRotationE=ShurikenParticleData._tempVector30;
- ShurikenParticleData._randomInvertRoationArray(startRotationConstantSeparate,randomRotationE,particleSystem.randomizeRotationDirection,autoRandomSeed ? null :rand,randomSeeds);
- ShurikenParticleData.startRotation[0]=randomRotationE.x;
- ShurikenParticleData.startRotation[1]=randomRotationE.y;
- if (renderMode!==4)
- ShurikenParticleData.startRotation[2]=-randomRotationE.z;
- else
- ShurikenParticleData.startRotation[2]=randomRotationE.z;
- }else {
- ShurikenParticleData.startRotation[0]=ShurikenParticleData._randomInvertRoation(particleSystem.startRotationConstant,particleSystem.randomizeRotationDirection,autoRandomSeed ? null :rand,randomSeeds);
- ShurikenParticleData.startRotation[1]=0;
- ShurikenParticleData.startRotation[2]=0;
- }
- break ;
- case 2:
- if (particleSystem.threeDStartRotation){
- var startRotationConstantMinSeparate=particleSystem.startRotationConstantMinSeparate;
- var startRotationConstantMaxSeparate=particleSystem.startRotationConstantMaxSeparate;
- var lerpRoationE=ShurikenParticleData._tempVector30;
- if (autoRandomSeed){
- lerpRoationE.x=MathUtil.lerp(startRotationConstantMinSeparate.x,startRotationConstantMaxSeparate.x,Math.random());
- lerpRoationE.y=MathUtil.lerp(startRotationConstantMinSeparate.y,startRotationConstantMaxSeparate.y,Math.random());
- lerpRoationE.z=MathUtil.lerp(startRotationConstantMinSeparate.z,startRotationConstantMaxSeparate.z,Math.random());
- }else {
- rand.seed=randomSeeds[5];
- lerpRoationE.x=MathUtil.lerp(startRotationConstantMinSeparate.x,startRotationConstantMaxSeparate.x,rand.getFloat());
- lerpRoationE.y=MathUtil.lerp(startRotationConstantMinSeparate.y,startRotationConstantMaxSeparate.y,rand.getFloat());
- lerpRoationE.z=MathUtil.lerp(startRotationConstantMinSeparate.z,startRotationConstantMaxSeparate.z,rand.getFloat());
- randomSeeds[5]=rand.seed;
- }
- ShurikenParticleData._randomInvertRoationArray(lerpRoationE,lerpRoationE,particleSystem.randomizeRotationDirection,autoRandomSeed ? null :rand,randomSeeds);
- ShurikenParticleData.startRotation[0]=lerpRoationE.x;
- ShurikenParticleData.startRotation[1]=lerpRoationE.y;
- if (renderMode!==4)
- ShurikenParticleData.startRotation[2]=-lerpRoationE.z;
- else
- ShurikenParticleData.startRotation[2]=lerpRoationE.z;
- }else {
- if (autoRandomSeed){
- ShurikenParticleData.startRotation[0]=ShurikenParticleData._randomInvertRoation(MathUtil.lerp(particleSystem.startRotationConstantMin,particleSystem.startRotationConstantMax,Math.random()),particleSystem.randomizeRotationDirection,autoRandomSeed ? null :rand,randomSeeds);
- }else {
- rand.seed=randomSeeds[5];
- ShurikenParticleData.startRotation[0]=ShurikenParticleData._randomInvertRoation(MathUtil.lerp(particleSystem.startRotationConstantMin,particleSystem.startRotationConstantMax,rand.getFloat()),particleSystem.randomizeRotationDirection,autoRandomSeed ? null :rand,randomSeeds);
- randomSeeds[5]=rand.seed;
- }
- }
- break ;
- }
- }
- switch (particleSystem.startLifetimeType){
- case 0:
- ShurikenParticleData.startLifeTime=particleSystem.startLifetimeConstant;
- break ;
- case 1:
- ShurikenParticleData.startLifeTime=ShurikenParticleData._getStartLifetimeFromGradient(particleSystem.startLifeTimeGradient,particleSystem.emissionTime);
- break ;
- case 2:
- if (autoRandomSeed){
- ShurikenParticleData.startLifeTime=MathUtil.lerp(particleSystem.startLifetimeConstantMin,particleSystem.startLifetimeConstantMax,Math.random());
- }else {
- rand.seed=randomSeeds[7];
- ShurikenParticleData.startLifeTime=MathUtil.lerp(particleSystem.startLifetimeConstantMin,particleSystem.startLifetimeConstantMax,rand.getFloat());
- randomSeeds[7]=rand.seed;
- }
- break ;
- case 3:;
- var emissionTime=particleSystem.emissionTime;
- if (autoRandomSeed){
- ShurikenParticleData.startLifeTime=MathUtil.lerp(ShurikenParticleData._getStartLifetimeFromGradient(particleSystem.startLifeTimeGradientMin,emissionTime),ShurikenParticleData._getStartLifetimeFromGradient(particleSystem.startLifeTimeGradientMax,emissionTime),Math.random());
- }else {
- rand.seed=randomSeeds[7];
- ShurikenParticleData.startLifeTime=MathUtil.lerp(ShurikenParticleData._getStartLifetimeFromGradient(particleSystem.startLifeTimeGradientMin,emissionTime),ShurikenParticleData._getStartLifetimeFromGradient(particleSystem.startLifeTimeGradientMax,emissionTime),rand.getFloat());
- randomSeeds[7]=rand.seed;
- }
- break ;
- }
- switch (particleSystem.startSpeedType){
- case 0:
- ShurikenParticleData.startSpeed=particleSystem.startSpeedConstant;
- break ;
- case 2:
- if (autoRandomSeed){
- ShurikenParticleData.startSpeed=MathUtil.lerp(particleSystem.startSpeedConstantMin,particleSystem.startSpeedConstantMax,Math.random());
- }else {
- rand.seed=randomSeeds[8];
- ShurikenParticleData.startSpeed=MathUtil.lerp(particleSystem.startSpeedConstantMin,particleSystem.startSpeedConstantMax,rand.getFloat());
- randomSeeds[8]=rand.seed;
- }
- break ;
- };
- var textureSheetAnimation=particleSystem.textureSheetAnimation;
- var enableSheetAnimation=textureSheetAnimation && textureSheetAnimation.enable;
- if (enableSheetAnimation){
- var title=textureSheetAnimation.tiles;
- var titleX=title.x,titleY=title.y;
- var subU=1.0 / titleX,subV=1.0 / titleY;
- var startFrameCount=0;
- var startFrame=textureSheetAnimation.startFrame;
- switch (startFrame.type){
- case 0:
- startFrameCount=startFrame.constant;
- break ;
- case 1:
- if (autoRandomSeed){
- startFrameCount=MathUtil.lerp(startFrame.constantMin,startFrame.constantMax,Math.random());
- }else {
- rand.seed=randomSeeds[14];
- startFrameCount=MathUtil.lerp(startFrame.constantMin,startFrame.constantMax,rand.getFloat());
- randomSeeds[14]=rand.seed;
- }
- break ;
- };
- var frame=textureSheetAnimation.frame;
- switch (frame.type){
- case 0:
- startFrameCount+=frame.constant;
- break ;
- case 2:
- if (autoRandomSeed){
- startFrameCount+=MathUtil.lerp(frame.constantMin,frame.constantMax,Math.random());
- }else {
- rand.seed=randomSeeds[15];
- startFrameCount+=MathUtil.lerp(frame.constantMin,frame.constantMax,rand.getFloat());
- randomSeeds[15]=rand.seed;
- }
- break ;
- };
- var startRow=0;
- switch (textureSheetAnimation.type){
- case 0:
- startRow=Math.floor(startFrameCount / titleX);
- break ;
- case 1:
- if (textureSheetAnimation.randomRow){
- if (autoRandomSeed){
- startRow=Math.floor(Math.random()*titleY);
- }else {
- rand.seed=randomSeeds[13];
- startRow=Math.floor(rand.getFloat()*titleY);
- randomSeeds[13]=rand.seed;
- }
- }else {
- startRow=textureSheetAnimation.rowIndex;
- }
- break ;
- };
- var startCol=Math.floor(startFrameCount % titleX);
- ShurikenParticleData.startUVInfo=ShurikenParticleData.startUVInfo;
- ShurikenParticleData.startUVInfo[0]=subU;
- ShurikenParticleData.startUVInfo[1]=subV;
- ShurikenParticleData.startUVInfo[2]=startCol *subU;
- ShurikenParticleData.startUVInfo[3]=startRow *subV;
- }else {
- ShurikenParticleData.startUVInfo=ShurikenParticleData.startUVInfo;
- ShurikenParticleData.startUVInfo[0]=1.0;
- ShurikenParticleData.startUVInfo[1]=1.0;
- ShurikenParticleData.startUVInfo[2]=0.0;
- ShurikenParticleData.startUVInfo[3]=0.0;
- }
- switch (particleSystem.simulationSpace){
- case 0:;
- var position=transform.position;
- ShurikenParticleData.simulationWorldPostion[0]=position.x;
- ShurikenParticleData.simulationWorldPostion[1]=position.y;
- ShurikenParticleData.simulationWorldPostion[2]=position.z;
- var rotation=transform.rotation;
- ShurikenParticleData.simulationWorldRotation[0]=rotation.x;
- ShurikenParticleData.simulationWorldRotation[1]=rotation.y;
- ShurikenParticleData.simulationWorldRotation[2]=rotation.z;
- ShurikenParticleData.simulationWorldRotation[3]=rotation.w;
- break ;
- case 1:
- break ;
- default :
- throw new Error("ShurikenParticleMaterial: SimulationSpace value is invalid.");
- break ;
- }
- }
- ShurikenParticleData.startLifeTime=NaN;
- ShurikenParticleData.startSpeed=NaN;
- __static(ShurikenParticleData,
- ['_tempVector30',function(){return this._tempVector30=new Vector3();},'_tempQuaternion',function(){return this._tempQuaternion=new Quaternion();},'startColor',function(){return this.startColor=new Vector4();},'startSize',function(){return this.startSize=new Float32Array(3);},'startRotation',function(){return this.startRotation=new Float32Array(3);},'startUVInfo',function(){return this.startUVInfo=new Float32Array(4);},'simulationWorldPostion',function(){return this.simulationWorldPostion=new Float32Array(3);},'simulationWorldRotation',function(){return this.simulationWorldRotation=new Float32Array(4);}
- ]);
- return ShurikenParticleData;
- })()
- /**
- *<code>BoundsOctreeNode</code> 类用于创建八叉树节点。
- */
- //class laya.d3.core.scene.BoundsOctreeNode
- var BoundsOctreeNode=(function(){
- function BoundsOctreeNode(octree,parent,baseLength,center){
- /**@private */
- this._octree=null;
- /**@private */
- this._parent=null;
- /**@private */
- this._children=null;
- /**@private [Debug]*/
- this._isContaion=false;
- /**@private [只读]*/
- this.baseLength=0.0;
- this._bounds=new BoundBox(new Vector3(),new Vector3());
- this._objects=[];
- this.center=new Vector3();
- this._setValues(octree,parent,baseLength,center);
- }
- __class(BoundsOctreeNode,'laya.d3.core.scene.BoundsOctreeNode');
- var __proto=BoundsOctreeNode.prototype;
- /**
- *@private
- */
- __proto._setValues=function(octree,parent,baseLength,center){
- this._octree=octree;
- this._parent=parent;
- this.baseLength=baseLength;
- center.cloneTo(this.center);
- var min=this._bounds.min;
- var max=this._bounds.max;
- var halfSize=(octree._looseness *baseLength)/ 2;
- min.setValue(center.x-halfSize,center.y-halfSize,center.z-halfSize);
- max.setValue(center.x+halfSize,center.y+halfSize,center.z+halfSize);
- }
- /**
- *@private
- */
- __proto._getChildBound=function(index){
- if (this._children !=null && this._children[index]){
- return this._children[index]._bounds;
- }else {
- var quarter=this.baseLength / 4;
- var halfChildSize=((this.baseLength / 2)*this._octree._looseness)/ 2;
- var bounds=BoundsOctreeNode._tempBoundBox;
- var min=bounds.min;
- var max=bounds.max;
- switch (index){
- case 0:
- min.x=this.center.x-quarter-halfChildSize;
- min.y=this.center.y+quarter-halfChildSize;
- min.z=this.center.z-quarter-halfChildSize;
- max.x=this.center.x-quarter+halfChildSize;
- max.y=this.center.y+quarter+halfChildSize;
- max.z=this.center.z-quarter+halfChildSize;
- break ;
- case 1:
- min.x=this.center.x+quarter-halfChildSize;
- min.y=this.center.y+quarter-halfChildSize;
- min.z=this.center.z-quarter-halfChildSize;
- max.x=this.center.x+quarter+halfChildSize;
- max.y=this.center.y+quarter+halfChildSize;
- max.z=this.center.z-quarter+halfChildSize;
- break ;
- case 2:
- min.x=this.center.x-quarter-halfChildSize;
- min.y=this.center.y+quarter-halfChildSize;
- min.z=this.center.z+quarter-halfChildSize;
- max.x=this.center.x-quarter+halfChildSize;
- max.y=this.center.y+quarter+halfChildSize;
- max.z=this.center.z+quarter+halfChildSize;
- break ;
- case 3:
- min.x=this.center.x+quarter-halfChildSize;
- min.y=this.center.y+quarter-halfChildSize;
- min.z=this.center.z+quarter-halfChildSize;
- max.x=this.center.x+quarter+halfChildSize;
- max.y=this.center.y+quarter+halfChildSize;
- max.z=this.center.z+quarter+halfChildSize;
- break ;
- case 4:
- min.x=this.center.x-quarter-halfChildSize;
- min.y=this.center.y-quarter-halfChildSize;
- min.z=this.center.z-quarter-halfChildSize;
- max.x=this.center.x-quarter+halfChildSize;
- max.y=this.center.y-quarter+halfChildSize;
- max.z=this.center.z-quarter+halfChildSize;
- break ;
- case 5:
- min.x=this.center.x+quarter-halfChildSize;
- min.y=this.center.y-quarter-halfChildSize;
- min.z=this.center.z-quarter-halfChildSize;
- max.x=this.center.x+quarter+halfChildSize;
- max.y=this.center.y-quarter+halfChildSize;
- max.z=this.center.z-quarter+halfChildSize;
- break ;
- case 6:
- min.x=this.center.x-quarter-halfChildSize;
- min.y=this.center.y-quarter-halfChildSize;
- min.z=this.center.z+quarter-halfChildSize;
- max.x=this.center.x-quarter+halfChildSize;
- max.y=this.center.y-quarter+halfChildSize;
- max.z=this.center.z+quarter+halfChildSize;
- break ;
- case 7:
- min.x=this.center.x+quarter-halfChildSize;
- min.y=this.center.y-quarter-halfChildSize;
- min.z=this.center.z+quarter-halfChildSize;
- max.x=this.center.x+quarter+halfChildSize;
- max.y=this.center.y-quarter+halfChildSize;
- max.z=this.center.z+quarter+halfChildSize;
- break ;
- default :
- }
- return bounds;
- }
- }
- /**
- *@private
- */
- __proto._getChildCenter=function(index){
- if (this._children !=null){
- return this._children[index].center;
- }else {
- var quarter=this.baseLength / 4;
- var childCenter=BoundsOctreeNode._tempVector30;
- switch (index){
- case 0:
- childCenter.x=this.center.x-quarter;
- childCenter.y=this.center.y+quarter;
- childCenter.z=this.center.z-quarter;
- break ;
- case 1:
- childCenter.x=this.center.x+quarter;
- childCenter.y=this.center.y+quarter;
- childCenter.z=this.center.z-quarter;
- break ;
- case 2:
- childCenter.x=this.center.x-quarter;
- childCenter.y=this.center.y+quarter;
- childCenter.z=this.center.z+quarter;
- break ;
- case 3:
- childCenter.x=this.center.x+quarter;
- childCenter.y=this.center.y+quarter;
- childCenter.z=this.center.z+quarter;
- break ;
- case 4:
- childCenter.x=this.center.x-quarter;
- childCenter.y=this.center.y-quarter;
- childCenter.z=this.center.z-quarter;
- break ;
- case 5:
- childCenter.x=this.center.x+quarter;
- childCenter.y=this.center.y-quarter;
- childCenter.z=this.center.z-quarter;
- break ;
- case 6:
- childCenter.x=this.center.x-quarter;
- childCenter.y=this.center.y-quarter;
- childCenter.z=this.center.z+quarter;
- break ;
- case 7:
- childCenter.x=this.center.x+quarter;
- childCenter.y=this.center.y-quarter;
- childCenter.z=this.center.z+quarter;
- break ;
- default :
- }
- return childCenter;
- }
- }
- /**
- *@private
- */
- __proto._getChild=function(index){
- var quarter=this.baseLength / 4;
- this._children || (this._children=__newvec(8,null));
- switch (index){
- case 0:
- 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)));
- case 1:
- 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)));
- case 2:
- 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)));
- case 3:
- 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)));
- case 4:
- 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)));
- case 5:
- 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)));
- case 6:
- 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)));
- case 7:
- 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)));
- default :
- throw "BoundsOctreeNode: unknown index.";
- }
- }
- /**
- *@private
- *是否合并判断(如果该节点和子节点包含的物体小于_NUM_OBJECTS_ALLOWED则应将子节点合并到该节点)
- */
- __proto._shouldMerge=function(){
- var objectCount=this._objects.length;
- for (var i=0;i < 8;i++){
- var child=this._children[i];
- if (child){
- if (child._children !=null)
- return false;
- objectCount+=child._objects.length;
- }
- }
- return objectCount <=8;
- }
- /**
- *@private
- */
- __proto._mergeChildren=function(){
- for (var i=0;i < 8;i++){
- var child=this._children[i];
- if (child){
- child._parent=null;
- var childObjects=child._objects;
- for (var j=childObjects.length-1;j >=0;j--){
- var childObject=childObjects[j];
- this._objects.push(childObject);
- childObject._setOctreeNode(this);
- }
- }
- }
- this._children=null;
- }
- /**
- *@private
- */
- __proto._merge=function(){
- if (this._children===null){
- var parent=this._parent;
- if (parent && parent._shouldMerge()){
- parent._mergeChildren();
- parent._merge();
- }
- }
- }
- /**
- *@private
- */
- __proto._checkAddNode=function(object){
- if (this._children==null){
- if (this._objects.length < 8 || (this.baseLength / 2)< this._octree._minSize){
- return this;
- }
- for (var i=this._objects.length-1;i >=0;i--){
- var existObject=this._objects[i];
- var fitChildIndex=this._bestFitChild(existObject.bounds.getCenter());
- if (BoundsOctreeNode._encapsulates(this._getChildBound(fitChildIndex),existObject.bounds._getBoundBox())){
- this._objects.splice(this._objects.indexOf(existObject),1);
- this._getChild(fitChildIndex)._add(existObject);
- }
- }
- };
- var newFitChildIndex=this._bestFitChild(object.bounds.getCenter());
- if (BoundsOctreeNode._encapsulates(this._getChildBound(newFitChildIndex),object.bounds._getBoundBox()))
- return this._getChild(newFitChildIndex)._checkAddNode(object);
- else
- return this;
- }
- /**
- *@private
- */
- __proto._add=function(object){
- var addNode=this._checkAddNode(object);
- addNode._objects.push(object);
- object._setOctreeNode(addNode);
- }
- /**
- *@private
- */
- __proto._remove=function(object){
- var index=this._objects.indexOf(object);
- this._objects.splice(index,1);
- object._setOctreeNode(null);
- this._merge();
- }
- /**
- *@private
- */
- __proto._addUp=function(object){
- if ((CollisionUtils.boxContainsBox(this._bounds,object.bounds._getBoundBox())===/*laya.d3.math.ContainmentType.Contains*/1)){
- this._add(object);
- return true;
- }else {
- if (this._parent)
- return this._parent._addUp(object);
- else
- return false;
- }
- }
- /**
- *@private
- */
- __proto._getCollidingWithFrustum=function(context,frustum,testVisible,camPos){
- if (testVisible){
- var type=frustum.containsBoundBox(this._bounds);
- Stat.octreeNodeCulling++;
- if (type===/*laya.d3.math.ContainmentType.Disjoint*/0)
- return;
- testVisible=(type===/*laya.d3.math.ContainmentType.Intersects*/2);
- }
- this._isContaion=!testVisible;
- var camera=context.camera;
- var scene=context.scene;
- for (var i=0,n=this._objects.length;i < n;i++){
- var render=this._objects [i];
- if (camera._isLayerVisible(render._owner.layer)&& render._enable){
- if (testVisible){
- Stat.frustumCulling++;
- if (!render._needRender(frustum))
- continue ;
- }
- render._distanceForSort=Vector3.distance(render.bounds.getCenter(),camPos);
- var elements=render._renderElements;
- for (var j=0,m=elements.length;j < m;j++){
- var element=elements[j];
- var renderQueue=scene._getRenderQueue(element.material.renderQueue);
- if (renderQueue.isTransparent)
- element.addToTransparentRenderQueue(context,renderQueue);
- else
- element.addToOpaqueRenderQueue(context,renderQueue);
- }
- }
- }
- if (this._children !=null){
- for (i=0;i < 8;i++){
- var child=this._children[i];
- child && child._getCollidingWithFrustum(context,frustum,testVisible,camPos);
- }
- }
- }
- /**
- *@private
- */
- __proto._getCollidingWithBoundBox=function(checkBound,testVisible,result){
- if (testVisible){
- var type=CollisionUtils.boxContainsBox(this._bounds,checkBound);
- if (type===/*laya.d3.math.ContainmentType.Disjoint*/0)
- return;
- testVisible=(type===/*laya.d3.math.ContainmentType.Intersects*/2);
- }
- if (testVisible){
- for (var i=0,n=this._objects.length;i < n;i++){
- var object=this._objects[i];
- if (CollisionUtils.intersectsBoxAndBox(object.bounds._getBoundBox(),checkBound)){
- result.push(object);
- }
- }
- }
- if (this._children !=null){
- for (i=0;i < 8;i++){
- var child=this._children[i];
- child._getCollidingWithBoundBox(checkBound,testVisible,result);
- }
- }
- }
- /**
- *@private
- */
- __proto._bestFitChild=function(boundCenter){
- return (boundCenter.x <=this.center.x ? 0 :1)+(boundCenter.y >=this.center.y ? 0 :4)+(boundCenter.z <=this.center.z ? 0 :2);
- }
- /**
- *@private
- *@return 是否需要扩充根节点
- */
- __proto._update=function(object){
- if (CollisionUtils.boxContainsBox(this._bounds,object.bounds._getBoundBox())===/*laya.d3.math.ContainmentType.Contains*/1){
- var addNode=this._checkAddNode(object);
- if (addNode!==object._getOctreeNode()){
- addNode._objects.push(object);
- object._setOctreeNode(addNode);
- var index=this._objects.indexOf(object);
- this._objects.splice(index,1);
- this._merge();
- }
- return true;
- }else {
- if (this._parent){
- var sucess=this._parent._addUp(object);
- if (sucess){
- index=this._objects.indexOf(object);
- this._objects.splice(index,1);
- this._merge();
- }
- return sucess;
- }else {
- return false;
- }
- }
- }
- /**
- *添加指定物体。
- *@param object 指定物体。
- */
- __proto.add=function(object){
- if (!BoundsOctreeNode._encapsulates(this._bounds,object.bounds._getBoundBox()))
- return false;
- this._add(object);
- return true;
- }
- /**
- *移除指定物体。
- *@param obejct 指定物体。
- *@return 是否成功。
- */
- __proto.remove=function(object){
- if (object._getOctreeNode()!==this)
- return false;
- this._remove(object);
- return true;
- }
- /**
- *更新制定物体,
- *@param obejct 指定物体。
- *@return 是否成功。
- */
- __proto.update=function(object){
- if (object._getOctreeNode()!==this)
- return false;
- return this._update(object);
- }
- /**
- *收缩八叉树节点。
- *-所有物体都在根节点的八分之一区域
- *-该节点无子节点或有子节点但1/8的子节点不包含物体
- *@param minLength 最小尺寸。
- *@return 新的根节点。
- */
- __proto.shrinkIfPossible=function(minLength){
- if (this.baseLength < minLength *2)
- return this;
- var bestFit=-1;
- for (var i=0,n=this._objects.length;i < n;i++){
- var object=this._objects[i];
- var newBestFit=this._bestFitChild(object.bounds.getCenter());
- if (i==0 || newBestFit==bestFit){
- var childBounds=this._getChildBound(newBestFit);
- if (BoundsOctreeNode._encapsulates(childBounds,object.bounds._getBoundBox()))
- (i==0)&& (bestFit=newBestFit);
- else
- return this;
- }else {
- return this;
- }
- }
- if (this._children !=null){
- var childHadContent=false;
- for (i=0,n=this._children.length;i < n;i++){
- var child=this._children[i];
- if (child && child.hasAnyObjects()){
- if (childHadContent)
- return this;
- if (bestFit >=0 && bestFit !=i)
- return this;
- childHadContent=true;
- bestFit=i;
- }
- }
- }else {
- if (bestFit !=-1){
- var childCenter=this._getChildCenter(bestFit);
- this._setValues(this._octree,null,this.baseLength / 2,childCenter);
- }
- return this;
- }
- if (bestFit !=-1){
- var newRoot=this._children[bestFit];
- newRoot._parent=null;
- return newRoot;
- }else {
- return this;
- }
- }
- /**
- *检查该节点和其子节点是否包含任意物体。
- *@return 是否包含任意物体。
- */
- __proto.hasAnyObjects=function(){
- if (this._objects.length > 0)
- return true;
- if (this._children !=null){
- for (var i=0;i < 8;i++){
- var child=this._children[i];
- if (child && child.hasAnyObjects())
- return true;
- }
- }
- return false;
- }
- /**
- *获取与指定包围盒相交的物体列表。
- *@param checkBound AABB包围盒。
- *@param result 相交物体列表
- */
- __proto.getCollidingWithBoundBox=function(checkBound,result){
- this._getCollidingWithBoundBox(checkBound,true,result);
- }
- /**
- *获取与指定射线相交的的物理列表。
- *@param ray 射线。
- *@param result 相交物体列表。
- *@param maxDistance 射线的最大距离。
- */
- __proto.getCollidingWithRay=function(ray,result,maxDistance){
- (maxDistance===void 0)&& (maxDistance=Number.MAX_VALUE);
- var distance=CollisionUtils.intersectsRayAndBoxRD(ray,this._bounds);
- if (distance==-1 || distance > maxDistance)
- return;
- for (var i=0,n=this._objects.length;i < n;i++){
- var object=this._objects[i];
- distance=CollisionUtils.intersectsRayAndBoxRD(ray,object.bounds._getBoundBox());
- if (distance!==-1 && distance <=maxDistance)
- result.push(object);
- }
- if (this._children !=null){
- for (i=0;i < 8;i++){
- var child=this._children[i];
- child.getCollidingWithRay(ray,result,maxDistance);
- }
- }
- }
- /**
- *获取与指定视锥相交的的物理列表。
- *@param ray 射线。.
- *@param result 相交物体列表。
- */
- __proto.getCollidingWithFrustum=function(context){
- var cameraPos=context.camera.transform.position;
- var boundFrustum=(context.camera).boundFrustum;
- this._getCollidingWithFrustum(context,boundFrustum,true,cameraPos);
- }
- /**
- *获取是否与指定包围盒相交。
- *@param checkBound AABB包围盒。
- *@return 是否相交。
- */
- __proto.isCollidingWithBoundBox=function(checkBound){
- if (!(CollisionUtils.intersectsBoxAndBox(this._bounds,checkBound)))
- return false;
- for (var i=0,n=this._objects.length;i < n;i++){
- var object=this._objects[i];
- if (CollisionUtils.intersectsBoxAndBox(object.bounds._getBoundBox(),checkBound))
- return true;
- }
- if (this._children !=null){
- for (i=0;i < 8;i++){
- var child=this._children[i];
- if (child.isCollidingWithBoundBox(checkBound))
- return true;
- }
- }
- return false;
- }
- /**
- *获取是否与指定射线相交。
- *@param ray 射线。
- *@param maxDistance 射线的最大距离。
- *@return 是否相交。
- */
- __proto.isCollidingWithRay=function(ray,maxDistance){
- (maxDistance===void 0)&& (maxDistance=Number.MAX_VALUE);
- var distance=CollisionUtils.intersectsRayAndBoxRD(ray,this._bounds);
- if (distance==-1 || distance > maxDistance)
- return false;
- for (var i=0,n=this._objects.length;i < n;i++){
- var object=this._objects[i];
- distance=CollisionUtils.intersectsRayAndBoxRD(ray,object.bounds._getBoundBox());
- if (distance!==-1 && distance <=maxDistance)
- return true;
- }
- if (this._children !=null){
- for (i=0;i < 8;i++){
- var child=this._children[i];
- if (child.isCollidingWithRay(ray,maxDistance))
- return true;
- }
- }
- return false;
- }
- /**
- *获取包围盒。
- */
- __proto.getBound=function(){
- return this._bounds;
- }
- /**
- *@private
- *[Debug]
- */
- __proto.drawAllBounds=function(debugLine,currentDepth,maxDepth){
- if (this._children===null && this._objects.length==0)
- return;
- currentDepth++;
- var color=BoundsOctreeNode._tempColor0;
- if (this._isContaion){
- color.r=0.0;
- color.g=0.0;
- color.b=1.0;
- }else {
- var tint=maxDepth ? currentDepth / maxDepth :0;
- color.r=1.0-tint;
- color.g=tint;
- color.b=0.0;
- }
- color.a=0.3;
- Utils3D._drawBound(debugLine,this._bounds,color);
- if (this._children !=null){
- for (var i=0;i < 8;i++){
- var child=this._children[i];
- child && child.drawAllBounds(debugLine,currentDepth,maxDepth);
- }
- }
- }
- /**
- *@private
- *[Debug]
- */
- __proto.drawAllObjects=function(debugLine,currentDepth,maxDepth){
- currentDepth++;
- var color=BoundsOctreeNode._tempColor0;
- if (this._isContaion){
- color.r=0.0;
- color.g=0.0;
- color.b=1.0;
- }else {
- var tint=maxDepth ? currentDepth / maxDepth :0;
- color.r=1.0-tint;
- color.g=tint;
- color.b=0.0;
- }
- color.a=1.0;
- for (var i=0,n=this._objects.length;i < n;i++)
- Utils3D._drawBound(debugLine,this._objects[i].bounds._getBoundBox(),color);
- if (this._children !=null){
- for (i=0;i < 8;i++){
- var child=this._children[i];
- child && child.drawAllObjects(debugLine,currentDepth,maxDepth);
- }
- }
- }
- BoundsOctreeNode._encapsulates=function(outerBound,innerBound){
- return CollisionUtils.boxContainsBox(outerBound,innerBound)==/*laya.d3.math.ContainmentType.Contains*/1;
- }
- BoundsOctreeNode._NUM_OBJECTS_ALLOWED=8;
- __static(BoundsOctreeNode,
- ['_tempVector3',function(){return this._tempVector3=new Vector3();},'_tempVector30',function(){return this._tempVector30=new Vector3();},'_tempVector31',function(){return this._tempVector31=new Vector3();},'_tempColor0',function(){return this._tempColor0=new Color();},'_tempBoundBox',function(){return this._tempBoundBox=new BoundBox(new Vector3(),new Vector3());}
- ]);
- return BoundsOctreeNode;
- })()
- /**
- *<code>GradientDataVector2</code> 类用于创建二维向量渐变。
- */
- //class laya.d3.core.particleShuriKen.module.GradientDataVector2
- var GradientDataVector2=(function(){
- function GradientDataVector2(){
- /**@private */
- this._currentLength=0;
- /**@private 开发者禁止修改。*/
- this._elements=null;
- this._elements=new Float32Array(12);
- }
- __class(GradientDataVector2,'laya.d3.core.particleShuriKen.module.GradientDataVector2');
- var __proto=GradientDataVector2.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *增加二维向量渐变。
- *@param key 生命周期,范围为0到1。
- *@param value 二维向量值。
- */
- __proto.add=function(key,value){
- if (this._currentLength < 8){
- if ((this._currentLength===6)&& ((key!==1))){
- key=1;
- console.log("GradientDataVector2 warning:the forth key is be force set to 1.");
- }
- this._elements[this._currentLength++]=key;
- this._elements[this._currentLength++]=value.x;
- this._elements[this._currentLength++]=value.y;
- }else {
- console.log("GradientDataVector2 warning:data count must lessEqual than 4");
- }
- }
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var destGradientDataVector2=destObject;
- destGradientDataVector2._currentLength=this._currentLength;
- var destElements=destGradientDataVector2._elements;
- destElements.length=this._elements.length;
- for (var i=0,n=this._elements.length;i < n;i++){
- destElements[i]=this._elements[i];
- }
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var destGradientDataVector2=/*__JS__ */new this.constructor();
- this.cloneTo(destGradientDataVector2);
- return destGradientDataVector2;
- }
- /**二维向量渐变数量。*/
- __getset(0,__proto,'gradientCount',function(){
- return this._currentLength / 3;
- });
- return GradientDataVector2;
- })()
- /**
- *<code>VertexPositionTerrain</code> 类用于创建位置、法线、纹理1、纹理2顶点结构。
- */
- //class laya.d3.graphics.Vertex.VertexPositionTerrain
- var VertexPositionTerrain=(function(){
- function VertexPositionTerrain(position,normal,textureCoord0,textureCoord1){
- this._position=null;
- this._normal=null;
- this._textureCoord0=null;
- this._textureCoord1=null;
- this._position=position;
- this._normal=normal;
- this._textureCoord0=textureCoord0;
- this._textureCoord1=textureCoord1;
- }
- __class(VertexPositionTerrain,'laya.d3.graphics.Vertex.VertexPositionTerrain');
- var __proto=VertexPositionTerrain.prototype;
- Laya.imps(__proto,{"laya.d3.graphics.IVertex":true})
- __getset(0,__proto,'normal',function(){
- return this._normal;
- });
- __getset(0,__proto,'position',function(){
- return this._position;
- });
- __getset(0,__proto,'textureCoord0',function(){
- return this._textureCoord0;
- });
- __getset(0,__proto,'textureCoord1',function(){
- return this._textureCoord1;
- });
- __getset(0,__proto,'vertexDeclaration',function(){
- return VertexPositionTerrain._vertexDeclaration;
- });
- __getset(1,VertexPositionTerrain,'vertexDeclaration',function(){
- return VertexPositionTerrain._vertexDeclaration;
- });
- VertexPositionTerrain.TERRAIN_POSITION0=0;
- VertexPositionTerrain.TERRAIN_NORMAL0=1;
- VertexPositionTerrain.TERRAIN_TEXTURECOORDINATE0=2;
- VertexPositionTerrain.TERRAIN_TEXTURECOORDINATE1=3;
- __static(VertexPositionTerrain,
- ['_vertexDeclaration',function(){return this._vertexDeclaration=new VertexDeclaration(40,[
- new VertexElement(0,/*laya.d3.graphics.VertexElementFormat.Vector3*/"vector3",/*CLASS CONST:laya.d3.graphics.Vertex.VertexPositionTerrain.TERRAIN_POSITION0*/0),
- new VertexElement(12,/*laya.d3.graphics.VertexElementFormat.Vector3*/"vector3",/*CLASS CONST:laya.d3.graphics.Vertex.VertexPositionTerrain.TERRAIN_NORMAL0*/1),
- new VertexElement(24,/*laya.d3.graphics.VertexElementFormat.Vector2*/"vector2",/*CLASS CONST:laya.d3.graphics.Vertex.VertexPositionTerrain.TERRAIN_TEXTURECOORDINATE0*/2),
- new VertexElement(32,/*laya.d3.graphics.VertexElementFormat.Vector2*/"vector2",/*CLASS CONST:laya.d3.graphics.Vertex.VertexPositionTerrain.TERRAIN_TEXTURECOORDINATE1*/3)]);}
- ]);
- return VertexPositionTerrain;
- })()
- /**
- *<code>KeyframeNodeList</code> 类用于创建KeyframeNode节点队列。
- */
- //class laya.d3.animation.KeyframeNodeList
- var KeyframeNodeList=(function(){
- function KeyframeNodeList(){
- this._nodes=[];
- }
- __class(KeyframeNodeList,'laya.d3.animation.KeyframeNodeList');
- var __proto=KeyframeNodeList.prototype;
- /**
- *通过索引获取节点。
- *@param index 索引。
- *@return 节点。
- */
- __proto.getNodeByIndex=function(index){
- return this._nodes[index];
- }
- /**
- *通过索引设置节点。
- *@param index 索引。
- *@param 节点。
- */
- __proto.setNodeByIndex=function(index,node){
- this._nodes[index]=node;
- }
- /**
- *设置节点个数。
- *@param value 节点个数。
- */
- /**
- *获取节点个数。
- *@return 节点个数。
- */
- __getset(0,__proto,'count',function(){
- return this._nodes.length;
- },function(value){
- this._nodes.length=value;
- });
- return KeyframeNodeList;
- })()
- /**
- *<code>BoundsOctree</code> 类用于创建八叉树。
- */
- //class laya.d3.core.scene.BoundsOctree
- var BoundsOctree=(function(){
- function BoundsOctree(initialWorldSize,initialWorldPos,minNodeSize,looseness){
- /**@private */
- this._initialSize=NaN;
- /**@private */
- this._rootNode=null;
- /**@private */
- this._looseness=NaN;
- /**@private */
- this._minSize=NaN;
- /**@private [只读]*/
- this.count=0;
- this._motionObjects=new OctreeMotionList();
- if (minNodeSize > initialWorldSize){
- console.warn("Minimum node size must be at least as big as the initial world size. Was: "+minNodeSize+" Adjusted to: "+initialWorldSize);
- minNodeSize=initialWorldSize;
- }
- this._initialSize=initialWorldSize;
- this._minSize=minNodeSize;
- this._looseness=Math.min(Math.max(looseness,1.0),2.0);
- this._rootNode=new BoundsOctreeNode(this,null,initialWorldSize,initialWorldPos);
- }
- __class(BoundsOctree,'laya.d3.core.scene.BoundsOctree');
- var __proto=BoundsOctree.prototype;
- /**
- *@private
- */
- __proto._getMaxDepth=function(node,depth){
- depth++;
- var children=node._children;
- if (children !=null){
- var curDepth=depth;
- for (var i=0,n=children.length;i < n;i++){
- var child=children[i];
- child && (depth=Math.max(this._getMaxDepth(child,curDepth),depth));
- }
- }
- return depth;
- }
- /**
- *@private
- */
- __proto._grow=function(growObjectCenter){
- var xDirection=growObjectCenter.x >=0 ? 1 :-1;
- var yDirection=growObjectCenter.y >=0 ? 1 :-1;
- var zDirection=growObjectCenter.z >=0 ? 1 :-1;
- var oldRoot=this._rootNode;
- var half=this._rootNode.baseLength / 2;
- var newLength=this._rootNode.baseLength *2;
- var rootCenter=this._rootNode.center;
- var newCenter=new Vector3(rootCenter.x+xDirection *half,rootCenter.y+yDirection *half,rootCenter.z+zDirection *half);
- this._rootNode=new BoundsOctreeNode(this,null,newLength,newCenter);
- if (oldRoot.hasAnyObjects()){
- var rootPos=this._rootNode._bestFitChild(oldRoot.center);
- var children=__newvec(8,null);
- for (var i=0;i < 8;i++){
- if (i==rootPos){
- oldRoot._parent=this._rootNode;
- children[i]=oldRoot;
- }
- }
- this._rootNode._children=children;
- }
- }
- /**
- *添加物体
- *@param object
- */
- __proto.add=function(object){
- var count=0;
- while (!this._rootNode.add(object)){
- var growCenter=BoundsOctree._tempVector30;
- Vector3.subtract(object.bounds.getCenter(),this._rootNode.center,growCenter);
- this._grow(growCenter);
- if (++count > 20){
- throw "Aborted Add operation as it seemed to be going on forever ("+(count-1)+") attempts at growing the octree.";
- }
- }
- this.count++;
- }
- /**
- *移除物体
- *@return 是否成功
- */
- __proto.remove=function(object){
- var removed=object._getOctreeNode().remove(object);
- if (removed){
- this.count--;
- }
- return removed;
- }
- /**
- *更新物体
- */
- __proto.update=function(object){
- var count=0;
- var octreeNode=object._getOctreeNode();
- if (octreeNode){
- while (!octreeNode._update(object)){
- this._grow(object.bounds.getCenter());
- if (++count > 20){
- throw "Aborted Add operation as it seemed to be going on forever ("+(count-1)+") attempts at growing the octree.";
- }
- }
- return true;
- }else {
- return false;
- }
- }
- /**
- *如果可能则收缩根节点。
- */
- __proto.shrinkRootIfPossible=function(){
- this._rootNode=this._rootNode.shrinkIfPossible(this._initialSize);
- }
- /**
- *添加运动物体。
- *@param 运动物体。
- */
- __proto.addMotionObject=function(object){
- this._motionObjects.add(object);
- }
- /**
- *移除运动物体。
- *@param 运动物体。
- */
- __proto.removeMotionObject=function(object){
- this._motionObjects.remove(object);
- }
- /**
- *更新所有运动物体。
- */
- __proto.updateMotionObjects=function(){
- var elements=this._motionObjects.elements;
- for (var i=0,n=this._motionObjects.length;i < n;i++){
- var object=elements [i];
- this.update(object);
- object._setIndexInMotionList(-1);
- }
- this._motionObjects.length=0;
- }
- /**
- *获取是否与指定包围盒相交。
- *@param checkBound AABB包围盒。
- *@return 是否相交。
- */
- __proto.isCollidingWithBoundBox=function(checkBounds){
- return this._rootNode.isCollidingWithBoundBox(checkBounds);
- }
- /**
- *获取是否与指定射线相交。
- *@param ray 射线。
- *@param maxDistance 射线的最大距离。
- *@return 是否相交。
- */
- __proto.isCollidingWithRay=function(ray,maxDistance){
- (maxDistance===void 0)&& (maxDistance=Number.MAX_VALUE);
- return this._rootNode.isCollidingWithRay(ray,maxDistance);
- }
- /**
- *获取与指定包围盒相交的物体列表。
- *@param checkBound AABB包围盒。
- *@param result 相交物体列表
- */
- __proto.getCollidingWithBoundBox=function(checkBound,result){
- this._rootNode.getCollidingWithBoundBox(checkBound,result);
- }
- /**
- *获取与指定射线相交的的物理列表。
- *@param ray 射线。
- *@param result 相交物体列表。
- *@param maxDistance 射线的最大距离。
- */
- __proto.getCollidingWithRay=function(ray,result,maxDistance){
- (maxDistance===void 0)&& (maxDistance=Number.MAX_VALUE);
- this._rootNode.getCollidingWithRay(ray,result,maxDistance);
- }
- /**
- *获取与指定视锥相交的的物理列表。
- *@param 渲染上下文。
- */
- __proto.getCollidingWithFrustum=function(context){
- this._rootNode.getCollidingWithFrustum(context);
- }
- /**
- *获取最大包围盒
- *@return 最大包围盒
- */
- __proto.getMaxBounds=function(){
- return this._rootNode.getBound();
- }
- /**
- *@private
- *[Debug]
- */
- __proto.drawAllBounds=function(pixelLine){
- var maxDepth=this._getMaxDepth(this._rootNode,-1);
- this._rootNode.drawAllBounds(pixelLine,-1,maxDepth);
- }
- /**
- *@private
- *[Debug]
- */
- __proto.drawAllObjects=function(pixelLine){
- var maxDepth=this._getMaxDepth(this._rootNode,-1);
- this._rootNode.drawAllObjects(pixelLine,-1,maxDepth);
- }
- __static(BoundsOctree,
- ['_tempVector30',function(){return this._tempVector30=new Vector3();}
- ]);
- return BoundsOctree;
- })()
- /**
- *<code>MeshFilter</code> 类用于创建网格过滤器。
- */
- //class laya.d3.core.MeshFilter
- var MeshFilter=(function(){
- function MeshFilter(owner){
- /**@private */
- this._owner=null;
- /**@private */
- this._sharedMesh=null;
- this._owner=owner;
- }
- __class(MeshFilter,'laya.d3.core.MeshFilter');
- var __proto=MeshFilter.prototype;
- /**
- *@private
- */
- __proto._getMeshDefine=function(mesh){
- var define=0;
- for (var i=0,n=mesh._subMeshCount;i < n;i++){
- var subMesh=mesh._getSubMesh(i);
- var vertexElements=subMesh._vertexBuffer._vertexDeclaration.vertexElements;
- for (var j=0,m=vertexElements.length;j < m;j++){
- var vertexElement=vertexElements[j];
- var name=vertexElement.elementUsage;
- switch (name){
- case /*laya.d3.graphics.Vertex.VertexMesh.MESH_COLOR0*/1:
- define |=MeshSprite3D.SHADERDEFINE_COLOR;
- break
- case /*laya.d3.graphics.Vertex.VertexMesh.MESH_TEXTURECOORDINATE0*/2:
- define |=MeshSprite3D.SHADERDEFINE_UV0;
- break ;
- case /*laya.d3.graphics.Vertex.VertexMesh.MESH_TEXTURECOORDINATE1*/7:
- define |=MeshSprite3D.SHADERDEFINE_UV1;
- break ;
- }
- }
- }
- return define;
- }
- /**
- *@inheritDoc
- */
- __proto.destroy=function(){
- this._owner=null;
- (this._sharedMesh)&& (this._sharedMesh._removeReference(),this._sharedMesh=null);
- }
- /**
- *设置共享网格。
- *@return value 共享网格。
- */
- /**
- *获取共享网格。
- *@return 共享网格。
- */
- __getset(0,__proto,'sharedMesh',function(){
- return this._sharedMesh;
- },function(value){
- if (this._sharedMesh!==value){
- var defineDatas=this._owner._render._defineDatas;
- var lastValue=this._sharedMesh;
- if (lastValue){
- lastValue._removeReference();
- defineDatas.remove(this._getMeshDefine(lastValue));
- }
- value._addReference();
- this._sharedMesh=value;
- defineDatas.add(this._getMeshDefine(value));
- (this._owner._render)._changeRenderObjectsByMesh(value);
- }
- (this._owner._render)._onMeshChange(value);
- });
- return MeshFilter;
- })()
- /**
- *<code>TrailFilter</code> 类用于创建拖尾过滤器。
- */
- //class laya.d3.core.trail.TrailFilter
- var TrailFilter=(function(){
- function TrailFilter(owner){
- /**@private */
- this._minVertexDistance=NaN;
- /**@private */
- this._widthMultiplier=NaN;
- /**@private */
- this._time=NaN;
- /**@private */
- this._widthCurve=null;
- /**@private */
- this._colorGradient=null;
- /**@private */
- this._textureMode=0;
- /**@private */
- this._trialGeometry=null;
- /**@private 拖尾总长度*/
- this._totalLength=0;
- this._owner=null;
- this._curtime=0;
- this._trailRenderElementIndex=0;
- this._lastPosition=new Vector3();
- this.alignment=0;
- this._owner=owner;
- this._initDefaultData();
- this.addRenderElement();
- }
- __class(TrailFilter,'laya.d3.core.trail.TrailFilter');
- var __proto=TrailFilter.prototype;
- /**
- *@private
- */
- __proto.addRenderElement=function(){
- var render=this._owner._render;
- var elements=render._renderElements;
- var material=render.sharedMaterials [0];
- (material)|| (material=TrailMaterial.defaultMaterial);
- var element=new RenderElement();
- element.setTransform(this._owner._transform);
- element.render=render;
- element.material=material;
- this._trialGeometry=new TrailGeometry(this);
- element.setGeometry(this._trialGeometry);
- elements.push(element);
- }
- /**
- *@private
- */
- __proto._update=function(state){
- var render=this._owner._render;
- this._curtime+=(state.scene).timer._delta / 1000;
- render._shaderValues.setNumber(TrailSprite3D.CURTIME,this._curtime);
- var curPos=this._owner.transform.position;
- var element=render._renderElements[0] ._geometry;
- element._updateDisappear();
- element._updateTrail(state.camera,this._lastPosition,curPos);
- element._updateVertexBufferUV();
- curPos.cloneTo(this._lastPosition);
- }
- /**
- *@private
- */
- __proto._initDefaultData=function(){
- this.time=5.0;
- this.minVertexDistance=0.1;
- this.widthMultiplier=1;
- this.textureMode=/*laya.d3.core.TextureMode.Stretch*/0;
- var widthKeyFrames=[];
- var widthKeyFrame1=new FloatKeyframe();
- widthKeyFrame1.time=0;
- widthKeyFrame1.inTangent=0;
- widthKeyFrame1.outTangent=0;
- widthKeyFrame1.value=1;
- widthKeyFrames.push(widthKeyFrame1);
- var widthKeyFrame2=new FloatKeyframe();
- widthKeyFrame2.time=1;
- widthKeyFrame2.inTangent=0;
- widthKeyFrame2.outTangent=0;
- widthKeyFrame2.value=1;
- widthKeyFrames.push(widthKeyFrame2);
- this.widthCurve=widthKeyFrames;
- var gradient=new Gradient(2,2);
- gradient.mode=/*laya.d3.core.GradientMode.Blend*/0;
- gradient.addColorRGB(0,Color.WHITE);
- gradient.addColorRGB(1,Color.WHITE);
- gradient.addColorAlpha(0,1);
- gradient.addColorAlpha(1,1);
- this.colorGradient=gradient;
- }
- /**
- *@private
- */
- __proto.destroy=function(){
- this._trialGeometry.destroy();
- this._trialGeometry=null;
- this._widthCurve=null;
- this._colorGradient=null;
- }
- /**
- *设置宽度倍数。
- *@param value 宽度倍数。
- */
- /**
- *获取宽度倍数。
- *@return 宽度倍数。
- */
- __getset(0,__proto,'widthMultiplier',function(){
- return this._widthMultiplier;
- },function(value){
- this._widthMultiplier=value;
- });
- /**
- *设置淡出时间。
- *@param value 淡出时间。
- */
- /**
- *获取淡出时间。
- *@return 淡出时间。
- */
- __getset(0,__proto,'time',function(){
- return this._time;
- },function(value){
- this._time=value;
- this._owner._render._shaderValues.setNumber(TrailSprite3D.LIFETIME,value);
- });
- /**
- *设置宽度曲线。
- *@param value 宽度曲线。
- */
- /**
- *获取宽度曲线。
- *@return 宽度曲线。
- */
- __getset(0,__proto,'widthCurve',function(){
- return this._widthCurve;
- },function(value){
- this._widthCurve=value;
- var widthCurveFloatArray=new Float32Array(value.length *4);
- var i=0,j=0,index=0;
- for (i=0,j=value.length;i < j;i++){
- widthCurveFloatArray[index++]=value[i].time;
- widthCurveFloatArray[index++]=value[i].inTangent;
- widthCurveFloatArray[index++]=value[i].outTangent;
- widthCurveFloatArray[index++]=value[i].value;
- }
- this._owner._render._shaderValues.setBuffer(TrailSprite3D.WIDTHCURVE,widthCurveFloatArray);
- this._owner._render._shaderValues.setInt(TrailSprite3D.WIDTHCURVEKEYLENGTH,value.length);
- });
- /**
- *设置新旧顶点之间最小距离。
- *@param value 新旧顶点之间最小距离。
- */
- /**
- *获取新旧顶点之间最小距离。
- *@return 新旧顶点之间最小距离。
- */
- __getset(0,__proto,'minVertexDistance',function(){
- return this._minVertexDistance;
- },function(value){
- this._minVertexDistance=value;
- });
- /**
- *设置颜色梯度。
- *@param value 颜色梯度。
- */
- /**
- *获取颜色梯度。
- *@return 颜色梯度。
- */
- __getset(0,__proto,'colorGradient',function(){
- return this._colorGradient;
- },function(value){
- this._colorGradient=value;
- this._owner._render._shaderValues.setBuffer(TrailSprite3D.GRADIENTCOLORKEY,value._rgbElements);
- this._owner._render._shaderValues.setBuffer(TrailSprite3D.GRADIENTALPHAKEY,value._alphaElements);
- if (value.mode==/*laya.d3.core.GradientMode.Blend*/0){
- this._owner._render._defineDatas.add(TrailSprite3D.SHADERDEFINE_GRADIENTMODE_BLEND);
- }else {
- this._owner._render._defineDatas.remove(TrailSprite3D.SHADERDEFINE_GRADIENTMODE_BLEND);
- }
- });
- /**
- *设置纹理模式。
- *@param value 纹理模式。
- */
- /**
- *获取纹理模式。
- *@return 纹理模式。
- */
- __getset(0,__proto,'textureMode',function(){
- return this._textureMode;
- },function(value){
- this._textureMode=value;
- });
- TrailFilter.ALIGNMENT_VIEW=0;
- TrailFilter.ALIGNMENT_TRANSFORM_Z=1;
- return TrailFilter;
- })()
- /**
- *<code>VertexTrail</code> 类用于创建拖尾顶点结构。
- */
- //class laya.d3.core.trail.VertexTrail
- var VertexTrail=(function(){
- function VertexTrail(){}
- __class(VertexTrail,'laya.d3.core.trail.VertexTrail');
- var __proto=VertexTrail.prototype;
- Laya.imps(__proto,{"laya.d3.graphics.IVertex":true})
- __getset(0,__proto,'vertexDeclaration',function(){
- return VertexTrail._vertexDeclaration1;
- });
- __getset(1,VertexTrail,'vertexDeclaration1',function(){
- return VertexTrail._vertexDeclaration1;
- });
- __getset(1,VertexTrail,'vertexDeclaration2',function(){
- return VertexTrail._vertexDeclaration2;
- });
- VertexTrail.TRAIL_POSITION0=0;
- VertexTrail.TRAIL_OFFSETVECTOR=1;
- VertexTrail.TRAIL_TIME0=2;
- VertexTrail.TRAIL_TEXTURECOORDINATE0Y=3;
- VertexTrail.TRAIL_TEXTURECOORDINATE0X=4;
- __static(VertexTrail,
- ['_vertexDeclaration1',function(){return this._vertexDeclaration1=new VertexDeclaration(32,
- [new VertexElement(0,/*laya.d3.graphics.VertexElementFormat.Vector3*/"vector3",/*CLASS CONST:laya.d3.core.trail.VertexTrail.TRAIL_POSITION0*/0),
- new VertexElement(12,/*laya.d3.graphics.VertexElementFormat.Vector3*/"vector3",/*CLASS CONST:laya.d3.core.trail.VertexTrail.TRAIL_OFFSETVECTOR*/1),
- new VertexElement(24,/*laya.d3.graphics.VertexElementFormat.Single*/"single",/*CLASS CONST:laya.d3.core.trail.VertexTrail.TRAIL_TIME0*/2),
- new VertexElement(28,/*laya.d3.graphics.VertexElementFormat.Single*/"single",/*CLASS CONST:laya.d3.core.trail.VertexTrail.TRAIL_TEXTURECOORDINATE0Y*/3)]);},'_vertexDeclaration2',function(){return this._vertexDeclaration2=new VertexDeclaration(4,
- [new VertexElement(0,/*laya.d3.graphics.VertexElementFormat.Single*/"single",/*CLASS CONST:laya.d3.core.trail.VertexTrail.TRAIL_TEXTURECOORDINATE0X*/4)]);}
- ]);
- return VertexTrail;
- })()
- /**
- *<code>Burst</code> 类用于粒子的爆裂描述。
- */
- //class laya.d3.core.particleShuriKen.module.Burst
- var Burst=(function(){
- function Burst(time,minCount,maxCount){
- /**@private 爆裂时间,单位为秒。*/
- this._time=NaN;
- /**@private 爆裂的最小数量。*/
- this._minCount=0;
- /**@private 爆裂的最大数量。*/
- this._maxCount=0;
- this._time=time;
- this._minCount=minCount;
- this._maxCount=maxCount;
- }
- __class(Burst,'laya.d3.core.particleShuriKen.module.Burst');
- var __proto=Burst.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var destBurst=destObject;
- destBurst._time=this._time
- destBurst._minCount=this._minCount;
- destBurst._maxCount=this._maxCount;
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var destBurst=/*__JS__ */new this.constructor();
- this.cloneTo(destBurst);
- return destBurst;
- }
- /**
- *获取爆裂时间,单位为秒。
- *@return 爆裂时间,单位为秒。
- */
- __getset(0,__proto,'time',function(){
- return this._time;
- });
- /**
- *获取爆裂的最小数量。
- *@return 爆裂的最小数量。
- */
- __getset(0,__proto,'minCount',function(){
- return this._minCount;
- });
- /**
- *获取爆裂的最大数量。
- *@return 爆裂的最大数量。
- */
- __getset(0,__proto,'maxCount',function(){
- return this._maxCount;
- });
- return Burst;
- })()
- /**
- *<code>AnimationEvent</code> 类用于实现动画事件。
- */
- //class laya.d3.animation.AnimationEvent
- var AnimationEvent=(function(){
- function AnimationEvent(){
- /**事件触发时间。*/
- this.time=NaN;
- /**事件触发名称。*/
- this.eventName=null;
- /**事件触发参数。*/
- this.params=null;
- }
- __class(AnimationEvent,'laya.d3.animation.AnimationEvent');
- return AnimationEvent;
- })()
- /**
- *...
- *@author ...
- */
- //class laya.d3.physics.Constraint3D
- var Constraint3D=(function(){
- function Constraint3D(){
- /**@private */
- this._nativeConstraint=null;
- /**@private */
- this._simulation=null;
- /**获取刚体A。[只读]*/
- this.rigidbodyA=null;
- /**获取刚体A。[只读]*/
- this.rigidbodyB=null;
- }
- __class(Constraint3D,'laya.d3.physics.Constraint3D');
- return Constraint3D;
- })()
- /**
- *@private
- */
- //class laya.d3.MouseTouch
- var MouseTouch=(function(){
- function MouseTouch(){
- /**@private */
- this._pressedSprite=null;
- /**@private */
- this._pressedLoopCount=-1;
- /**@private */
- this.sprite=null;
- /**@private */
- this.mousePositionX=0;
- /**@private */
- this.mousePositionY=0;
- }
- __class(MouseTouch,'laya.d3.MouseTouch');
- return MouseTouch;
- })()
- /**
- *<code>GradientDataInt</code> 类用于创建整形渐变。
- */
- //class laya.d3.core.particleShuriKen.module.GradientDataInt
- var GradientDataInt=(function(){
- function GradientDataInt(){
- /**@private */
- this._currentLength=0;
- /**@private 开发者禁止修改。*/
- this._elements=null;
- this._elements=new Float32Array(8);
- }
- __class(GradientDataInt,'laya.d3.core.particleShuriKen.module.GradientDataInt');
- var __proto=GradientDataInt.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *增加整形渐变。
- *@param key 生命周期,范围为0到1。
- *@param value 整形值。
- */
- __proto.add=function(key,value){
- if (this._currentLength < 8){
- if ((this._currentLength===6)&& ((key!==1))){
- key=1;
- console.log("Warning:the forth key is be force set to 1.");
- }
- this._elements[this._currentLength++]=key;
- this._elements[this._currentLength++]=value;
- }else {
- console.log("Warning:data count must lessEqual than 4");
- }
- }
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var destGradientDataInt=destObject;
- destGradientDataInt._currentLength=this._currentLength;
- var destElements=destGradientDataInt._elements;
- destElements.length=this._elements.length;
- for (var i=0,n=this._elements.length;i < n;i++){
- destElements[i]=this._elements[i];
- }
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var destGradientDataInt=/*__JS__ */new this.constructor();
- this.cloneTo(destGradientDataInt);
- return destGradientDataInt;
- }
- /**整形渐变数量。*/
- __getset(0,__proto,'gradientCount',function(){
- return this._currentLength / 2;
- });
- return GradientDataInt;
- })()
- /**
- *<code>SubShader</code> 类用于创建SubShader。
- */
- //class laya.d3.shader.SubShader
- var SubShader=(function(){
- function SubShader(attributeMap,uniformMap,spriteDefines,materialDefines){
- /**@private */
- this._attributeMap=null;
- /**@private */
- this._uniformMap=null;
- /**@private */
- this._publicDefines=null;
- /**@private */
- this._publicDefinesMap=null;
- /**@private */
- this._spriteDefines=null;
- /**@private */
- this._spriteDefinesMap=null;
- /**@private */
- this._materialDefines=null;
- /**@private */
- this._materialDefinesMap=null;
- /**@private */
- this._owner=null;
- /**@private */
- this._flags={};
- this._passes=[];
- this._publicDefines=[];
- this._publicDefinesMap={};
- this._spriteDefines=[];
- this._spriteDefinesMap={};
- this._materialDefines=[];
- this._materialDefinesMap={};
- this._addDefines(this._publicDefines,this._publicDefinesMap,Shader3D._globleDefines);
- (spriteDefines)&& (this._addDefines(this._spriteDefines,this._spriteDefinesMap,spriteDefines.defines));
- (materialDefines)&& (this._addDefines(this._materialDefines,this._materialDefinesMap,materialDefines.defines));
- this._attributeMap=attributeMap;
- this._uniformMap=uniformMap;
- }
- __class(SubShader,'laya.d3.shader.SubShader');
- var __proto=SubShader.prototype;
- /**
- *@private
- */
- __proto._addDefines=function(defines,definesMap,supportDefines){
- for (var k in supportDefines){
- var name=supportDefines[k];
- var i=parseInt(k);
- defines[i]=name;
- definesMap[name]=i;
- }
- }
- /**
- *通过名称获取宏定义值。
- *@param name 名称。
- *@return 宏定义值。
- */
- __proto.getMaterialDefineByName=function(name){
- return this._materialDefinesMap[name];
- }
- /**
- *添加标记。
- *@param key 标记键。
- *@param value 标记值。
- */
- __proto.setFlag=function(key,value){
- if (value)
- this._flags[key]=value;
- else
- delete this._flags[key];
- }
- /**
- *获取标记值。
- *@return key 标记键。
- */
- __proto.getFlag=function(key){
- return this._flags[key];
- }
- /**
- *@private
- */
- __proto.addShaderPass=function(vs,ps,stateMap){
- var shaderPass=new ShaderPass(this,vs,ps,stateMap);
- this._passes.push(shaderPass);
- return shaderPass;
- }
- return SubShader;
- })()
- /**
- **<code>PostProcessRenderContext</code> 类用于创建后期处理渲染上下文。
- */
- //class laya.d3.core.render.PostProcessRenderContext
- var PostProcessRenderContext=(function(){
- function PostProcessRenderContext(){
- /**源纹理。*/
- this.source=null;
- /**输出纹理。*/
- this.destination=null;
- /**渲染相机。*/
- this.camera=null;
- /**合成着色器数据。*/
- this.compositeShaderData=null;
- /**合成着色器宏定义。*/
- this.compositeDefineData=null;
- /**后期处理指令流。*/
- this.command=null;
- this.tempRenderTextures=[];
- }
- __class(PostProcessRenderContext,'laya.d3.core.render.PostProcessRenderContext');
- return PostProcessRenderContext;
- })()
- /**
- *<code>CommandBuffer</code> 类用于创建命令流。
- */
- //class laya.d3.core.render.command.CommandBuffer
- var CommandBuffer=(function(){
- function CommandBuffer(){
- this._commands=[];
- }
- __class(CommandBuffer,'laya.d3.core.render.command.CommandBuffer');
- var __proto=CommandBuffer.prototype;
- /**
- *@private
- */
- __proto._apply=function(){
- for (var i=0,n=this._commands.length;i < n;i++)
- this._commands[i].run();
- }
- /**
- *@private
- */
- __proto.setShaderDataTexture=function(shaderData,nameID,source){
- this._commands.push(SetShaderDataTextureCMD.create(shaderData,nameID,source));
- }
- /**
- *@private
- */
- __proto.blit=function(source,dest,shader,shaderData,subShader){
- (subShader===void 0)&& (subShader=0);
- this._commands.push(BlitCMD.create(source,dest,shader,shaderData,subShader));
- }
- /**
- *@private
- */
- __proto.setRenderTarget=function(renderTexture){
- this._commands.push(SetRenderTargetCMD.create(renderTexture));
- }
- /**
- *@private
- */
- __proto.clear=function(){
- for (var i=0,n=this._commands.length;i < n;i++)
- this._commands[i].recover();
- this._commands.length=0;
- }
- CommandBuffer.SCREENTEXTURE_NAME="u_ScreenTexture";
- __static(CommandBuffer,
- ['screenShader',function(){return this.screenShader=Shader3D.find("ScreenQuad");},'SCREENTEXTURE_ID',function(){return this.SCREENTEXTURE_ID=Shader3D.propertyNameToID("u_ScreenTexture");}
- ]);
- return CommandBuffer;
- })()
- /**
- *<code>GradientRotation</code> 类用于创建渐变角速度。
- */
- //class laya.d3.core.particleShuriKen.module.GradientAngularVelocity
- var GradientAngularVelocity=(function(){
- function GradientAngularVelocity(){
- /**@private */
- this._type=0;
- /**@private */
- this._separateAxes=false;
- /**@private */
- this._constant=NaN;
- /**@private */
- this._constantSeparate=null;
- /**@private */
- this._gradient=null;
- /**@private */
- this._gradientX=null;
- /**@private */
- this._gradientY=null;
- /**@private */
- this._gradientZ=null;
- /**@private */
- this._gradientW=null;
- /**@private */
- this._constantMin=NaN;
- /**@private */
- this._constantMax=NaN;
- /**@private */
- this._constantMinSeparate=null;
- /**@private */
- this._constantMaxSeparate=null;
- /**@private */
- this._gradientMin=null;
- /**@private */
- this._gradientMax=null;
- /**@private */
- this._gradientXMin=null;
- /**@private */
- this._gradientXMax=null;
- /**@private */
- this._gradientYMin=null;
- /**@private */
- this._gradientYMax=null;
- /**@private */
- this._gradientZMin=null;
- /**@private */
- this._gradientZMax=null;
- /**@private */
- this._gradientWMin=null;
- /**@private */
- this._gradientWMax=null;
- }
- __class(GradientAngularVelocity,'laya.d3.core.particleShuriKen.module.GradientAngularVelocity');
- var __proto=GradientAngularVelocity.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var destGradientAngularVelocity=destObject;
- destGradientAngularVelocity._type=this._type;
- destGradientAngularVelocity._separateAxes=this._separateAxes;
- destGradientAngularVelocity._constant=this._constant;
- this._constantSeparate.cloneTo(destGradientAngularVelocity._constantSeparate);
- this._gradient.cloneTo(destGradientAngularVelocity._gradient);
- this._gradientX.cloneTo(destGradientAngularVelocity._gradientX);
- this._gradientY.cloneTo(destGradientAngularVelocity._gradientY);
- this._gradientZ.cloneTo(destGradientAngularVelocity._gradientZ);
- destGradientAngularVelocity._constantMin=this._constantMin;
- destGradientAngularVelocity._constantMax=this._constantMax;
- this._constantMinSeparate.cloneTo(destGradientAngularVelocity._constantMinSeparate);
- this._constantMaxSeparate.cloneTo(destGradientAngularVelocity._constantMaxSeparate);
- this._gradientMin.cloneTo(destGradientAngularVelocity._gradientMin);
- this._gradientMax.cloneTo(destGradientAngularVelocity._gradientMax);
- this._gradientXMin.cloneTo(destGradientAngularVelocity._gradientXMin);
- this._gradientXMax.cloneTo(destGradientAngularVelocity._gradientXMax);
- this._gradientYMin.cloneTo(destGradientAngularVelocity._gradientYMin);
- this._gradientYMax.cloneTo(destGradientAngularVelocity._gradientYMax);
- this._gradientZMin.cloneTo(destGradientAngularVelocity._gradientZMin);
- this._gradientZMax.cloneTo(destGradientAngularVelocity._gradientZMax);
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var destGradientAngularVelocity=/*__JS__ */new this.constructor();
- this.cloneTo(destGradientAngularVelocity);
- return destGradientAngularVelocity;
- }
- /**
- *渐变角速度Z。
- */
- __getset(0,__proto,'gradientZ',function(){
- return this._gradientZ;
- });
- /**
- *固定角速度。
- */
- __getset(0,__proto,'constant',function(){
- return this._constant;
- });
- /**
- *渐变角速度。
- */
- __getset(0,__proto,'gradient',function(){
- return this._gradient;
- });
- /**
- *是否分轴。
- */
- __getset(0,__proto,'separateAxes',function(){
- return this._separateAxes;
- });
- /**
- *生命周期角速度类型,0常量模式,1曲线模式,2随机双常量模式,3随机双曲线模式。
- */
- __getset(0,__proto,'type',function(){
- return this._type;
- });
- /**
- *分轴固定角速度。
- */
- __getset(0,__proto,'constantSeparate',function(){
- return this._constantSeparate;
- });
- /**
- *渐变角角速度X。
- */
- __getset(0,__proto,'gradientX',function(){
- return this._gradientX;
- });
- /**
- *渐变角速度Y。
- */
- __getset(0,__proto,'gradientY',function(){
- return this._gradientY;
- });
- /**
- *渐变角速度Z。
- */
- __getset(0,__proto,'gradientW',function(){
- return this._gradientW;
- });
- /**
- *最小渐变角速度。
- */
- __getset(0,__proto,'gradientMin',function(){
- return this._gradientMin;
- });
- /**
- *最小随机双固定角速度。
- */
- __getset(0,__proto,'constantMin',function(){
- return this._constantMin;
- });
- /**
- *最大渐变角速度。
- */
- __getset(0,__proto,'gradientMax',function(){
- return this._gradientMax;
- });
- /**
- *最大随机双固定角速度。
- */
- __getset(0,__proto,'constantMax',function(){
- return this._constantMax;
- });
- /**
- *最小渐变角速度Z。
- */
- __getset(0,__proto,'gradientWMin',function(){
- return this._gradientWMin;
- });
- /**
- *最小分轴随机双固定角速度。
- */
- __getset(0,__proto,'constantMinSeparate',function(){
- return this._constantMinSeparate;
- });
- /**
- *最大分轴随机双固定角速度。
- */
- __getset(0,__proto,'constantMaxSeparate',function(){
- return this._constantMaxSeparate;
- });
- /**
- *最小渐变角速度X。
- */
- __getset(0,__proto,'gradientXMin',function(){
- return this._gradientXMin;
- });
- /**
- *最大渐变角速度X。
- */
- __getset(0,__proto,'gradientXMax',function(){
- return this._gradientXMax;
- });
- /**
- *最大渐变角速度Z。
- */
- __getset(0,__proto,'gradientWMax',function(){
- return this._gradientWMax;
- });
- /**
- *最小渐变角速度Y。
- */
- __getset(0,__proto,'gradientYMin',function(){
- return this._gradientYMin;
- });
- /**
- *最大渐变角速度Y。
- */
- __getset(0,__proto,'gradientYMax',function(){
- return this._gradientYMax;
- });
- /**
- *最小渐变角速度Z。
- */
- __getset(0,__proto,'gradientZMin',function(){
- return this._gradientZMin;
- });
- /**
- *最大渐变角速度Z。
- */
- __getset(0,__proto,'gradientZMax',function(){
- return this._gradientZMax;
- });
- GradientAngularVelocity.createByConstant=function(constant){
- var gradientAngularVelocity=new GradientAngularVelocity();
- gradientAngularVelocity._type=0;
- gradientAngularVelocity._separateAxes=false;
- gradientAngularVelocity._constant=constant;
- return gradientAngularVelocity;
- }
- GradientAngularVelocity.createByConstantSeparate=function(separateConstant){
- var gradientAngularVelocity=new GradientAngularVelocity();
- gradientAngularVelocity._type=0;
- gradientAngularVelocity._separateAxes=true;
- gradientAngularVelocity._constantSeparate=separateConstant;
- return gradientAngularVelocity;
- }
- GradientAngularVelocity.createByGradient=function(gradient){
- var gradientAngularVelocity=new GradientAngularVelocity();
- gradientAngularVelocity._type=1;
- gradientAngularVelocity._separateAxes=false;
- gradientAngularVelocity._gradient=gradient;
- return gradientAngularVelocity;
- }
- GradientAngularVelocity.createByGradientSeparate=function(gradientX,gradientY,gradientZ){
- var gradientAngularVelocity=new GradientAngularVelocity();
- gradientAngularVelocity._type=1;
- gradientAngularVelocity._separateAxes=true;
- gradientAngularVelocity._gradientX=gradientX;
- gradientAngularVelocity._gradientY=gradientY;
- gradientAngularVelocity._gradientZ=gradientZ;
- return gradientAngularVelocity;
- }
- GradientAngularVelocity.createByRandomTwoConstant=function(constantMin,constantMax){
- var gradientAngularVelocity=new GradientAngularVelocity();
- gradientAngularVelocity._type=2;
- gradientAngularVelocity._separateAxes=false;
- gradientAngularVelocity._constantMin=constantMin;
- gradientAngularVelocity._constantMax=constantMax;
- return gradientAngularVelocity;
- }
- GradientAngularVelocity.createByRandomTwoConstantSeparate=function(separateConstantMin,separateConstantMax){
- var gradientAngularVelocity=new GradientAngularVelocity();
- gradientAngularVelocity._type=2;
- gradientAngularVelocity._separateAxes=true;
- gradientAngularVelocity._constantMinSeparate=separateConstantMin;
- gradientAngularVelocity._constantMaxSeparate=separateConstantMax;
- return gradientAngularVelocity;
- }
- GradientAngularVelocity.createByRandomTwoGradient=function(gradientMin,gradientMax){
- var gradientAngularVelocity=new GradientAngularVelocity();
- gradientAngularVelocity._type=3;
- gradientAngularVelocity._separateAxes=false;
- gradientAngularVelocity._gradientMin=gradientMin;
- gradientAngularVelocity._gradientMax=gradientMax;
- return gradientAngularVelocity;
- }
- GradientAngularVelocity.createByRandomTwoGradientSeparate=function(gradientXMin,gradientXMax,gradientYMin,gradientYMax,gradientZMin,gradientZMax,gradientWMin,gradientWMax){
- var gradientAngularVelocity=new GradientAngularVelocity();
- gradientAngularVelocity._type=3;
- gradientAngularVelocity._separateAxes=true;
- gradientAngularVelocity._gradientXMin=gradientXMin;
- gradientAngularVelocity._gradientXMax=gradientXMax;
- gradientAngularVelocity._gradientYMin=gradientYMin;
- gradientAngularVelocity._gradientYMax=gradientYMax;
- gradientAngularVelocity._gradientZMin=gradientZMin;
- gradientAngularVelocity._gradientZMax=gradientZMax;
- gradientAngularVelocity._gradientWMin=gradientWMin;
- gradientAngularVelocity._gradientWMax=gradientWMax;
- return gradientAngularVelocity;
- }
- return GradientAngularVelocity;
- })()
- /**
- *<code>Config3D</code> 类用于创建3D初始化配置。
- */
- //class Config3D
- var Config3D=(function(){
- function Config3D(){
- /**@private */
- this._defaultPhysicsMemory=16;
- /**@private */
- this._editerEnvironment=false;
- /**是否开启抗锯齿。*/
- this.isAntialias=true;
- /**设置画布是否透明。*/
- this.isAlpha=false;
- /**设置画布是否预乘。*/
- this.premultipliedAlpha=true;
- /**设置画布的是否开启模板缓冲。*/
- this.isStencil=true;
- /**是否开启八叉树裁剪。*/
- this.octreeCulling=false;
- /**八叉树初始化尺寸。*/
- this.octreeInitialSize=64.0;
- /**八叉树最小尺寸。*/
- this.octreeMinNodeSize=2.0;
- /**八叉树松散值。*/
- this.octreeLooseness=1.25;
- /**
- *是否开启视锥裁剪调试。
- *如果开启八叉树裁剪,使用红色绘制高层次八叉树节点包围盒,使用蓝色绘制低层次八叉节点包围盒,精灵包围盒和八叉树节点包围盒颜色一致,但Alpha为半透明。如果视锥完全包含八叉树节点,八叉树节点包围盒和精灵包围盒变为蓝色,同样精灵包围盒的Alpha为半透明。
- *如果不开启八叉树裁剪,使用绿色像素线绘制精灵包围盒。
- */
- this.debugFrustumCulling=false;
- this.octreeInitialCenter=new Vector3(0,0,0);
- }
- __class(Config3D,'Config3D');
- var __proto=Config3D.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(dest){
- var destConfig3D=dest;
- destConfig3D._defaultPhysicsMemory=this._defaultPhysicsMemory;
- destConfig3D._editerEnvironment=this._editerEnvironment;
- destConfig3D.isAntialias=this.isAntialias;
- destConfig3D.isAlpha=this.isAlpha;
- destConfig3D.premultipliedAlpha=this.premultipliedAlpha;
- destConfig3D.isStencil=this.isStencil;
- destConfig3D.octreeCulling=this.octreeCulling;
- this.octreeInitialCenter.cloneTo(destConfig3D.octreeInitialCenter);
- destConfig3D.octreeMinNodeSize=this.octreeMinNodeSize;
- destConfig3D.octreeLooseness=this.octreeLooseness;
- destConfig3D.debugFrustumCulling=this.debugFrustumCulling;
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var dest=new Config3D();
- this.cloneTo(dest);
- return dest;
- }
- /**
- *设置默认物理功能初始化内存,单位为M。
- *@param value 默认物理功能初始化内存。
- */
- /**
- *获取默认物理功能初始化内存,单位为M。
- *@return 默认物理功能初始化内存。
- */
- __getset(0,__proto,'defaultPhysicsMemory',function(){
- return this._defaultPhysicsMemory;
- },function(value){
- if (value < 16)
- throw "defaultPhysicsMemory must large than 16M";
- this._defaultPhysicsMemory=value;
- });
- __static(Config3D,
- ['_default',function(){return this._default=new Config3D();}
- ]);
- return Config3D;
- })()
- /**
- *<code>Rand</code> 类用于通过128位整型种子创建随机数,算法来自:https://github.com/AndreasMadsen/xorshift。
- */
- //class laya.d3.math.RandX
- var RandX=(function(){
- function RandX(seed){
- /**@private */
- this._state0U=NaN;
- /**@private */
- this._state0L=NaN;
- /**@private */
- this._state1U=NaN;
- /**@private */
- this._state1L=NaN;
- if (!((seed instanceof Array))|| seed.length!==4)
- throw new Error('Rand:Seed must be an array with 4 numbers');
- this._state0U=seed[0] | 0;
- this._state0L=seed[1] | 0;
- this._state1U=seed[2] | 0;
- this._state1L=seed[3] | 0;
- }
- __class(RandX,'laya.d3.math.RandX');
- var __proto=RandX.prototype;
- /**
- *通过2x32位的数组,返回64位的随机数。
- *@return 64位的随机数。
- */
- __proto.randomint=function(){
- var s1U=this._state0U,s1L=this._state0L;
- var s0U=this._state1U,s0L=this._state1L;
- var sumL=(s0L >>> 0)+(s1L >>> 0);
- var resU=(s0U+s1U+(sumL / 2 >>> 31))>>> 0;
- var resL=sumL >>> 0;
- this._state0U=s0U;
- this._state0L=s0L;
- var t1U=0,t1L=0;
- var t2U=0,t2L=0;
- var a1=23;
- var m1=0xFFFFFFFF << (32-a1);
- t1U=(s1U << a1)| ((s1L & m1)>>> (32-a1));
- t1L=s1L << a1;
- s1U=s1U ^ t1U;
- s1L=s1L ^ t1L;
- t1U=s1U ^ s0U;
- t1L=s1L ^ s0L;
- var a2=18;
- var m2=0xFFFFFFFF >>> (32-a2);
- t2U=s1U >>> a2;
- t2L=(s1L >>> a2)| ((s1U & m2)<< (32-a2));
- t1U=t1U ^ t2U;
- t1L=t1L ^ t2L;
- var a3=5;
- var m3=0xFFFFFFFF >>> (32-a3);
- t2U=s0U >>> a3;
- t2L=(s0L >>> a3)| ((s0U & m3)<< (32-a3));
- t1U=t1U ^ t2U;
- t1L=t1L ^ t2L;
- this._state1U=t1U;
- this._state1L=t1L;
- return [resU,resL];
- }
- /**
- *返回[0,1)之间的随机数。
- *@return
- */
- __proto.random=function(){
- var t2=this.randomint();
- var t2U=t2[0];
- var t2L=t2[1];
- var eU=0x3FF << (52-32);
- var eL=0;
- var a1=12;
- var m1=0xFFFFFFFF >>> (32-a1);
- var sU=t2U >>> a1;
- var sL=(t2L >>> a1)| ((t2U & m1)<< (32-a1));
- var xU=eU | sU;
- var xL=eL | sL;
- RandX._CONVERTION_BUFFER.setUint32(0,xU,false);
- RandX._CONVERTION_BUFFER.setUint32(4,xL,false);
- var d=/*__JS__ */Rand._CONVERTION_BUFFER.getFloat64(0,false);
- return d-1;
- }
- __static(RandX,
- ['_CONVERTION_BUFFER',function(){return this._CONVERTION_BUFFER=new DataView(new ArrayBuffer(8));},'defaultRand',function(){return this.defaultRand=/*__JS__ */new Rand([0,Date.now()/ 65536,0,Date.now()% 65536]);}
- ]);
- return RandX;
- })()
- /**
- *<code>Picker</code> 类用于创建拾取。
- */
- //class laya.d3.utils.Picker
- var Picker=(function(){
- /**
- *创建一个 <code>Picker</code> 实例。
- */
- function Picker(){}
- __class(Picker,'laya.d3.utils.Picker');
- Picker.calculateCursorRay=function(point,viewPort,projectionMatrix,viewMatrix,world,out){
- var x=point.x;
- var y=point.y;
- var nearSource=Picker._tempVector30;
- var nerSourceE=nearSource;
- nerSourceE.x=x;
- nerSourceE.y=y;
- nerSourceE.z=viewPort.minDepth;
- var farSource=Picker._tempVector31;
- var farSourceE=farSource;
- farSourceE.x=x;
- farSourceE.y=y;
- farSourceE.z=viewPort.maxDepth;
- var nearPoint=out.origin;
- var farPoint=Picker._tempVector32;
- viewPort.unprojectFromWVP(nearSource,projectionMatrix,viewMatrix,world,nearPoint);
- viewPort.unprojectFromWVP(farSource,projectionMatrix,viewMatrix,world,farPoint);
- var outDire=out.direction;
- outDire.x=farPoint.x-nearPoint.x;
- outDire.y=farPoint.y-nearPoint.y;
- outDire.z=farPoint.z-nearPoint.z;
- Vector3.normalize(out.direction,out.direction);
- }
- Picker.rayIntersectsTriangle=function(ray,vertex1,vertex2,vertex3){
- var result;
- var edge1=Picker._tempVector30,edge2=Picker._tempVector31;
- Vector3.subtract(vertex2,vertex1,edge1);
- Vector3.subtract(vertex3,vertex1,edge2);
- var directionCrossEdge2=Picker._tempVector32;
- Vector3.cross(ray.direction,edge2,directionCrossEdge2);
- var determinant;
- determinant=Vector3.dot(edge1,directionCrossEdge2);
- if (determinant >-Number.MIN_VALUE && determinant < Number.MIN_VALUE){
- result=Number.NaN;
- return result;
- };
- var inverseDeterminant=1.0 / determinant;
- var distanceVector=Picker._tempVector33;
- Vector3.subtract(ray.origin,vertex1,distanceVector);
- var triangleU;
- triangleU=Vector3.dot(distanceVector,directionCrossEdge2);
- triangleU *=inverseDeterminant;
- if (triangleU < 0 || triangleU > 1){
- result=Number.NaN;
- return result;
- };
- var distanceCrossEdge1=Picker._tempVector34;
- Vector3.cross(distanceVector,edge1,distanceCrossEdge1);
- var triangleV;
- triangleV=Vector3.dot(ray.direction,distanceCrossEdge1);
- triangleV *=inverseDeterminant;
- if (triangleV < 0 || triangleU+triangleV > 1){
- result=Number.NaN;
- return result;
- };
- var rayDistance;
- rayDistance=Vector3.dot(edge2,distanceCrossEdge1);
- rayDistance *=inverseDeterminant;
- if (rayDistance < 0){
- result=Number.NaN;
- return result;
- }
- result=rayDistance;
- return result;
- }
- __static(Picker,
- ['_tempVector30',function(){return this._tempVector30=new Vector3();},'_tempVector31',function(){return this._tempVector31=new Vector3();},'_tempVector32',function(){return this._tempVector32=new Vector3();},'_tempVector33',function(){return this._tempVector33=new Vector3();},'_tempVector34',function(){return this._tempVector34=new Vector3();}
- ]);
- return Picker;
- })()
- /**
- *<code>Touch</code> 类用于实现触摸描述。
- */
- //class laya.d3.Touch
- var Touch=(function(){
- function Touch(){
- /**@private [实现IListPool接口]*/
- this._indexInList=-1;
- /**@private */
- this._identifier=-1;
- this._position=new Vector2();
- }
- __class(Touch,'laya.d3.Touch');
- var __proto=Touch.prototype;
- Laya.imps(__proto,{"laya.resource.ISingletonElement":true})
- /**
- *@private [实现ISingletonElement接口]
- */
- __proto._getIndexInList=function(){
- return this._indexInList;
- }
- /**
- *@private [实现ISingletonElement接口]
- */
- __proto._setIndexInList=function(index){
- this._indexInList=index;
- }
- /**
- *获取唯一识别ID。
- *@return 唯一识别ID。
- */
- __getset(0,__proto,'identifier',function(){
- return this._identifier;
- });
- /**
- *获取触摸点的像素坐标。
- *@return 触摸点的像素坐标 [只读]。
- */
- __getset(0,__proto,'position',function(){
- return this._position;
- });
- return Touch;
- })()
- /**
- *<code>PixelLineData</code> 类用于表示线数据。
- */
- //class laya.d3.core.pixelLine.PixelLineData
- var PixelLineData=(function(){
- function PixelLineData(){
- this.startPosition=new Vector3();
- this.endPosition=new Vector3();
- this.startColor=new Color();
- this.endColor=new Color();
- }
- __class(PixelLineData,'laya.d3.core.pixelLine.PixelLineData');
- var __proto=PixelLineData.prototype;
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- this.startPosition.cloneTo(destObject.startPosition);
- this.endPosition.cloneTo(destObject.endPosition);
- this.startColor.cloneTo(destObject.startColor);
- this.endColor.cloneTo(destObject.endColor);
- }
- return PixelLineData;
- })()
- /**
- *<code>Collision</code> 类用于创建物理碰撞信息。
- */
- //class laya.d3.physics.Collision
- var Collision=(function(){
- function Collision(){
- /**@private */
- this._lastUpdateFrame=-2147483648;
- /**@private */
- this._updateFrame=-2147483648;
- /**@private */
- this._isTrigger=false;
- /**@private */
- //this._colliderA=null;
- /**@private */
- //this._colliderB=null;
- /**@private [只读]*/
- //this.other=null;
- this.contacts=[];
- }
- __class(Collision,'laya.d3.physics.Collision');
- var __proto=Collision.prototype;
- /**
- *@private
- */
- __proto._setUpdateFrame=function(farme){
- this._lastUpdateFrame=this._updateFrame;
- this._updateFrame=farme;
- }
- return Collision;
- })()
- /**
- *@private
- *<code>VertexDeclaration</code> 类用于生成顶点声明。
- */
- //class laya.d3.graphics.VertexDeclaration
- var VertexDeclaration=(function(){
- function VertexDeclaration(vertexStride,vertexElements){
- /**@private */
- this._id=0;
- /**@private */
- this._vertexStride=0;
- /**@private */
- this._vertexElementsDic=null;
- /**@private */
- this._shaderValues=null;
- /**@private */
- this._defineDatas=null;
- /**@private [只读]*/
- this.vertexElements=null;
- this._id=++VertexDeclaration._uniqueIDCounter;
- this._defineDatas=new DefineDatas();
- this._vertexElementsDic={};
- this._vertexStride=vertexStride;
- this.vertexElements=vertexElements;
- var count=vertexElements.length;
- this._shaderValues=new ShaderData(null);
- for (var j=0;j < count;j++){
- var vertexElement=vertexElements[j];
- var name=vertexElement.elementUsage;
- this._vertexElementsDic[name]=vertexElement;
- var value=new Int32Array(5);
- var elmentInfo=VertexElementFormat.getElementInfos(vertexElement.elementFormat);
- value[0]=elmentInfo[0];
- value[1]=elmentInfo[1];
- value[2]=elmentInfo[2];
- value[3]=this._vertexStride;
- value[4]=vertexElement.offset;
- this._shaderValues.setAttribute(name,value);
- }
- }
- __class(VertexDeclaration,'laya.d3.graphics.VertexDeclaration');
- var __proto=VertexDeclaration.prototype;
- /**
- *@private
- */
- __proto.getVertexElementByUsage=function(usage){
- return this._vertexElementsDic[usage];
- }
- /**
- *@private
- */
- __proto.unBinding=function(){}
- /**
- *获取唯一标识ID(通常用于优化或识别)。
- *@return 唯一标识ID
- */
- __getset(0,__proto,'id',function(){
- return this._id;
- });
- /**
- *@private
- */
- __getset(0,__proto,'vertexStride',function(){
- return this._vertexStride;
- });
- VertexDeclaration._uniqueIDCounter=1;
- return VertexDeclaration;
- })()
- /**
- *<code>SkyRenderer</code> 类用于实现天空渲染器。
- */
- //class laya.d3.resource.models.SkyRenderer
- var SkyRenderer=(function(){
- function SkyRenderer(){
- /**@private */
- this._material=null;
- this._mesh=SkyBox.instance;
- }
- __class(SkyRenderer,'laya.d3.resource.models.SkyRenderer');
- var __proto=SkyRenderer.prototype;
- /**
- *@private
- *是否可用。
- */
- __proto._isAvailable=function(){
- return this._material && this._mesh;
- }
- /**
- *@private
- */
- __proto._render=function(state){
- if (this._material && this._mesh){
- var gl=LayaGL.instance;
- var scene=state.scene;
- var camera=state.camera;
- WebGLContext.setCullFace(gl,false);
- WebGLContext.setDepthFunc(gl,/*laya.webgl.WebGLContext.LEQUAL*/0x0203);
- WebGLContext.setDepthMask(gl,false);
- var shader=state.shader=this._material._shader.getSubShaderAt(0)._passes[0].withCompile(0,0,this._material._defineDatas.value);
- var switchShader=shader.bind();
- var switchShaderLoop=(Stat.loopCount!==shader._uploadMark);
- var uploadScene=(shader._uploadScene!==scene)|| switchShaderLoop;
- if (uploadScene || switchShader){
- shader.uploadUniforms(shader._sceneUniformParamsMap,scene._shaderValues,uploadScene);
- shader._uploadScene=scene;
- };
- var uploadCamera=(shader._uploadCamera!==camera)|| switchShaderLoop;
- if (uploadCamera || switchShader){
- shader.uploadUniforms(shader._cameraUniformParamsMap,camera._shaderValues,uploadCamera);
- shader._uploadCamera=camera;
- };
- var uploadMaterial=(shader._uploadMaterial!==this._material)|| switchShaderLoop;
- if (uploadMaterial || switchShader){
- shader.uploadUniforms(shader._materialUniformParamsMap,this._material._shaderValues,uploadMaterial);
- shader._uploadMaterial=this._material;
- }
- this._mesh._bufferState.bind();
- this._mesh._render(state);
- WebGLContext.setDepthFunc(gl,/*laya.webgl.WebGLContext.LESS*/0x0201);
- WebGLContext.setDepthMask(gl,true);
- }
- }
- /**
- *@private
- */
- __proto.destroy=function(){
- if (this._material){
- this._material._removeReference();
- this._material=null;
- }
- }
- /**
- *设置材质。
- *@param 材质。
- */
- /**
- *获取材质。
- *@return 材质。
- */
- __getset(0,__proto,'material',function(){
- return this._material;
- },function(value){
- if (this._material!==value){
- (this._material)&& (this._material._removeReference());
- (value)&& (value._addReference());
- this._material=value;
- }
- });
- /**
- *设置网格。
- *@param 网格。
- */
- /**
- *获取网格。
- *@return 网格。
- */
- __getset(0,__proto,'mesh',function(){
- return this._mesh;
- },function(value){
- if (this._mesh!==value){
- this._mesh=value;
- }
- });
- return SkyRenderer;
- })()
- /**
- *<code>AnimatorStateScript</code> 类用于动画状态脚本的父类,该类为抽象类,不允许实例。
- */
- //class laya.d3.animation.AnimatorStateScript
- var AnimatorStateScript=(function(){
- /**
- *创建一个新的 <code>AnimatorStateScript</code> 实例。
- */
- function AnimatorStateScript(){}
- __class(AnimatorStateScript,'laya.d3.animation.AnimatorStateScript');
- var __proto=AnimatorStateScript.prototype;
- /**
- *动画状态开始时执行。
- */
- __proto.onStateEnter=function(){}
- /**
- *动画状态更新时执行。
- */
- __proto.onStateUpdate=function(){}
- /**
- *动画状态退出时执行。
- */
- __proto.onStateExit=function(){}
- return AnimatorStateScript;
- })()
- /**
- *@private
- */
- //class laya.d3.core.render.BatchMark
- var BatchMark=(function(){
- function BatchMark(){
- /**@private */
- this.updateMark=-1;
- /**@private */
- this.indexInList=-1;
- /**@private */
- this.batched=false;
- }
- __class(BatchMark,'laya.d3.core.render.BatchMark');
- return BatchMark;
- })()
- /**
- *<code>HitResult</code> 类用于实现射线检测或形状扫描的结果。
- */
- //class laya.d3.physics.HitResult
- var HitResult=(function(){
- function HitResult(){
- /**是否成功。 */
- this.succeeded=false;
- /**发生碰撞的碰撞组件。*/
- this.collider=null;
- /**碰撞分数。 */
- this.hitFraction=0;
- this.point=new Vector3();
- this.normal=new Vector3();
- }
- __class(HitResult,'laya.d3.physics.HitResult');
- return HitResult;
- })()
- /**
- *<code>GradientSize</code> 类用于创建渐变尺寸。
- */
- //class laya.d3.core.particleShuriKen.module.GradientSize
- var GradientSize=(function(){
- function GradientSize(){
- /**@private */
- this._type=0;
- /**@private */
- this._separateAxes=false;
- /**@private */
- this._gradient=null;
- /**@private */
- this._gradientX=null;
- /**@private */
- this._gradientY=null;
- /**@private */
- this._gradientZ=null;
- /**@private */
- this._constantMin=NaN;
- /**@private */
- this._constantMax=NaN;
- /**@private */
- this._constantMinSeparate=null;
- /**@private */
- this._constantMaxSeparate=null;
- /**@private */
- this._gradientMin=null;
- /**@private */
- this._gradientMax=null;
- /**@private */
- this._gradientXMin=null;
- /**@private */
- this._gradientXMax=null;
- /**@private */
- this._gradientYMin=null;
- /**@private */
- this._gradientYMax=null;
- /**@private */
- this._gradientZMin=null;
- /**@private */
- this._gradientZMax=null;
- }
- __class(GradientSize,'laya.d3.core.particleShuriKen.module.GradientSize');
- var __proto=GradientSize.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *获取最大尺寸。
- */
- __proto.getMaxSizeInGradient=function(){
- var i=0,n=0;
- var maxSize=-Number.MAX_VALUE;
- switch (this._type){
- case 0:
- if (this._separateAxes){
- for (i=0,n=this._gradientX.gradientCount;i < n;i++)
- maxSize=Math.max(maxSize,this._gradientX.getValueByIndex(i));
- for (i=0,n=this._gradientY.gradientCount;i < n;i++)
- maxSize=Math.max(maxSize,this._gradientY.getValueByIndex(i));
- }else {
- for (i=0,n=this._gradient.gradientCount;i < n;i++)
- maxSize=Math.max(maxSize,this._gradient.getValueByIndex(i));
- }
- break ;
- case 1:
- if (this._separateAxes){
- maxSize=Math.max(this._constantMinSeparate.x,this._constantMaxSeparate.x);
- maxSize=Math.max(maxSize,this._constantMinSeparate.y);
- maxSize=Math.max(maxSize,this._constantMaxSeparate.y);
- }else {
- maxSize=Math.max(this._constantMin,this._constantMax);
- }
- break ;
- case 2:
- if (this._separateAxes){
- for (i=0,n=this._gradientXMin.gradientCount;i < n;i++)
- maxSize=Math.max(maxSize,this._gradientXMin.getValueByIndex(i));
- for (i=0,n=this._gradientXMax.gradientCount;i < n;i++)
- maxSize=Math.max(maxSize,this._gradientXMax.getValueByIndex(i));
- for (i=0,n=this._gradientYMin.gradientCount;i < n;i++)
- maxSize=Math.max(maxSize,this._gradientYMin.getValueByIndex(i));
- for (i=0,n=this._gradientZMax.gradientCount;i < n;i++)
- maxSize=Math.max(maxSize,this._gradientZMax.getValueByIndex(i));
- }else {
- for (i=0,n=this._gradientMin.gradientCount;i < n;i++)
- maxSize=Math.max(maxSize,this._gradientMin.getValueByIndex(i));
- for (i=0,n=this._gradientMax.gradientCount;i < n;i++)
- maxSize=Math.max(maxSize,this._gradientMax.getValueByIndex(i));
- }
- break ;
- }
- return maxSize;
- }
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var destGradientSize=destObject;
- destGradientSize._type=this._type;
- destGradientSize._separateAxes=this._separateAxes;
- this._gradient.cloneTo(destGradientSize._gradient);
- this._gradientX.cloneTo(destGradientSize._gradientX);
- this._gradientY.cloneTo(destGradientSize._gradientY);
- this._gradientZ.cloneTo(destGradientSize._gradientZ);
- destGradientSize._constantMin=this._constantMin;
- destGradientSize._constantMax=this._constantMax;
- this._constantMinSeparate.cloneTo(destGradientSize._constantMinSeparate);
- this._constantMaxSeparate.cloneTo(destGradientSize._constantMaxSeparate);
- this._gradientMin.cloneTo(destGradientSize._gradientMin);
- this._gradientMax.cloneTo(destGradientSize._gradientMax);
- this._gradientXMin.cloneTo(destGradientSize._gradientXMin);
- this._gradientXMax.cloneTo(destGradientSize._gradientXMax);
- this._gradientYMin.cloneTo(destGradientSize._gradientYMin);
- this._gradientYMax.cloneTo(destGradientSize._gradientYMax);
- this._gradientZMin.cloneTo(destGradientSize._gradientZMin);
- this._gradientZMax.cloneTo(destGradientSize._gradientZMax);
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var destGradientSize=/*__JS__ */new this.constructor();
- this.cloneTo(destGradientSize);
- return destGradientSize;
- }
- /**
- *渐变尺寸Z。
- */
- __getset(0,__proto,'gradientZ',function(){
- return this._gradientZ;
- });
- /**
- *渐变尺寸。
- */
- __getset(0,__proto,'gradient',function(){
- return this._gradient;
- });
- /**
- *是否分轴。
- */
- __getset(0,__proto,'separateAxes',function(){
- return this._separateAxes;
- });
- /**
- *生命周期尺寸类型,0曲线模式,1随机双常量模式,2随机双曲线模式。
- */
- __getset(0,__proto,'type',function(){
- return this._type;
- });
- /**
- *渐变最小尺寸。
- */
- __getset(0,__proto,'gradientMin',function(){
- return this._gradientMin;
- });
- /**
- *最小随机双固定尺寸。
- */
- __getset(0,__proto,'constantMin',function(){
- return this._constantMin;
- });
- /**
- *渐变尺寸X。
- */
- __getset(0,__proto,'gradientX',function(){
- return this._gradientX;
- });
- /**
- *渐变尺寸Y。
- */
- __getset(0,__proto,'gradientY',function(){
- return this._gradientY;
- });
- /**
- *渐变最大尺寸。
- */
- __getset(0,__proto,'gradientMax',function(){
- return this._gradientMax;
- });
- /**
- *最大随机双固定尺寸。
- */
- __getset(0,__proto,'constantMax',function(){
- return this._constantMax;
- });
- /**
- *最小分轴随机双固定尺寸。
- */
- __getset(0,__proto,'constantMinSeparate',function(){
- return this._constantMinSeparate;
- });
- /**
- *最小分轴随机双固定尺寸。
- */
- __getset(0,__proto,'constantMaxSeparate',function(){
- return this._constantMaxSeparate;
- });
- /**
- *渐变最小尺寸X。
- */
- __getset(0,__proto,'gradientXMin',function(){
- return this._gradientXMin;
- });
- /**
- *渐变最大尺寸X。
- */
- __getset(0,__proto,'gradientXMax',function(){
- return this._gradientXMax;
- });
- /**
- *渐变最小尺寸Y。
- */
- __getset(0,__proto,'gradientYMin',function(){
- return this._gradientYMin;
- });
- /**
- *渐变最大尺寸Y。
- */
- __getset(0,__proto,'gradientYMax',function(){
- return this._gradientYMax;
- });
- /**
- *渐变最小尺寸Z。
- */
- __getset(0,__proto,'gradientZMin',function(){
- return this._gradientZMin;
- });
- /**
- *渐变最大尺寸Z。
- */
- __getset(0,__proto,'gradientZMax',function(){
- return this._gradientZMax;
- });
- GradientSize.createByGradient=function(gradient){
- var gradientSize=new GradientSize();
- gradientSize._type=0;
- gradientSize._separateAxes=false;
- gradientSize._gradient=gradient;
- return gradientSize;
- }
- GradientSize.createByGradientSeparate=function(gradientX,gradientY,gradientZ){
- var gradientSize=new GradientSize();
- gradientSize._type=0;
- gradientSize._separateAxes=true;
- gradientSize._gradientX=gradientX;
- gradientSize._gradientY=gradientY;
- gradientSize._gradientZ=gradientZ;
- return gradientSize;
- }
- GradientSize.createByRandomTwoConstant=function(constantMin,constantMax){
- var gradientSize=new GradientSize();
- gradientSize._type=1;
- gradientSize._separateAxes=false;
- gradientSize._constantMin=constantMin;
- gradientSize._constantMax=constantMax;
- return gradientSize;
- }
- GradientSize.createByRandomTwoConstantSeparate=function(constantMinSeparate,constantMaxSeparate){
- var gradientSize=new GradientSize();
- gradientSize._type=1;
- gradientSize._separateAxes=true;
- gradientSize._constantMinSeparate=constantMinSeparate;
- gradientSize._constantMaxSeparate=constantMaxSeparate;
- return gradientSize;
- }
- GradientSize.createByRandomTwoGradient=function(gradientMin,gradientMax){
- var gradientSize=new GradientSize();
- gradientSize._type=2;
- gradientSize._separateAxes=false;
- gradientSize._gradientMin=gradientMin;
- gradientSize._gradientMax=gradientMax;
- return gradientSize;
- }
- GradientSize.createByRandomTwoGradientSeparate=function(gradientXMin,gradientXMax,gradientYMin,gradientYMax,gradientZMin,gradientZMax){
- var gradientSize=new GradientSize();
- gradientSize._type=2;
- gradientSize._separateAxes=true;
- gradientSize._gradientXMin=gradientXMin;
- gradientSize._gradientXMax=gradientXMax;
- gradientSize._gradientYMin=gradientYMin;
- gradientSize._gradientYMax=gradientYMax;
- gradientSize._gradientZMin=gradientZMin;
- gradientSize._gradientZMax=gradientZMax;
- return gradientSize;
- }
- return GradientSize;
- })()
- /**
- *<code>DetailTextureInfo</code> 类用于描述地形细节纹理。
- */
- //class laya.d3.terrain.unit.ChunkInfo
- var ChunkInfo=(function(){
- function ChunkInfo(){
- this.alphaMap=null;
- this.detailID=null;
- this.normalMap=null;
- }
- __class(ChunkInfo,'laya.d3.terrain.unit.ChunkInfo');
- return ChunkInfo;
- })()
- /**
- *@private
- *<code>shaderVariable</code> 类用于保存shader变量上传相关信息。
- */
- //class laya.d3.shader.ShaderVariable
- var ShaderVariable=(function(){
- function ShaderVariable(){
- /**@private */
- //this.name=null;
- /**@private */
- //this.type=0;
- /**@private */
- //this.location=0;
- /**@private */
- //this.isArray=false;
- /**@private */
- //this.textureID=0;
- /**@private */
- //this.dataOffset=0;
- /**@private */
- //this.caller=null;
- /**@private */
- //this.fun=null;
- /**@private */
- //this.uploadedValue=null;
- this.textureID=-1;
- }
- __class(ShaderVariable,'laya.d3.shader.ShaderVariable');
- return ShaderVariable;
- })()
- /**
- *@private
- */
- //class laya.d3.animation.KeyframeNode
- var KeyframeNode=(function(){
- function KeyframeNode(){
- /**@private */
- this._indexInList=0;
- /**@private */
- this.type=0;
- /**@private */
- this.fullPath=null;
- /**@private */
- this.propertyOwner=null;
- /**@private */
- this.data=null;
- this._ownerPath=[];
- this._propertys=[];
- this._keyFrames=[];
- }
- __class(KeyframeNode,'laya.d3.animation.KeyframeNode');
- var __proto=KeyframeNode.prototype;
- /**
- *@private
- */
- __proto._setOwnerPathCount=function(value){
- this._ownerPath.length=value;
- }
- /**
- *@private
- */
- __proto._setOwnerPathByIndex=function(index,value){
- this._ownerPath[index]=value;
- }
- /**
- *@private
- */
- __proto._joinOwnerPath=function(sep){
- return this._ownerPath.join(sep);
- }
- /**
- *@private
- */
- __proto._setPropertyCount=function(value){
- this._propertys.length=value;
- }
- /**
- *@private
- */
- __proto._setPropertyByIndex=function(index,value){
- this._propertys[index]=value;
- }
- /**
- *@private
- */
- __proto._joinProperty=function(sep){
- return this._propertys.join(sep);
- }
- /**
- *@private
- */
- __proto._setKeyframeCount=function(value){
- this._keyFrames.length=value;
- }
- /**
- *@private
- */
- __proto._setKeyframeByIndex=function(index,value){
- this._keyFrames[index]=value;
- }
- /**
- *通过索引获取精灵路径。
- *@param index 索引。
- */
- __proto.getOwnerPathByIndex=function(index){
- return this._ownerPath[index];
- }
- /**
- *通过索引获取属性路径。
- *@param index 索引。
- */
- __proto.getPropertyByIndex=function(index){
- return this._propertys[index];
- }
- /**
- *通过索引获取帧。
- *@param index 索引。
- */
- __proto.getKeyframeByIndex=function(index){
- return this._keyFrames[index];
- }
- /**
- *获取精灵路径个数。
- *@return 精灵路径个数。
- */
- __getset(0,__proto,'ownerPathCount',function(){
- return this._ownerPath.length;
- });
- /**
- *获取属性路径个数。
- *@return 数量路径个数。
- */
- __getset(0,__proto,'propertyCount',function(){
- return this._propertys.length;
- });
- /**
- *获取帧个数。
- *帧个数。
- */
- __getset(0,__proto,'keyFramesCount',function(){
- return this._keyFrames.length;
- });
- return KeyframeNode;
- })()
- /**
- *<code>GradientVelocity</code> 类用于创建渐变速度。
- */
- //class laya.d3.core.particleShuriKen.module.GradientVelocity
- var GradientVelocity=(function(){
- function GradientVelocity(){
- /**@private */
- this._type=0;
- /**@private */
- this._constant=null;
- /**@private */
- this._gradientX=null;
- /**@private */
- this._gradientY=null;
- /**@private */
- this._gradientZ=null;
- /**@private */
- this._constantMin=null;
- /**@private */
- this._constantMax=null;
- /**@private */
- this._gradientXMin=null;
- /**@private */
- this._gradientXMax=null;
- /**@private */
- this._gradientYMin=null;
- /**@private */
- this._gradientYMax=null;
- /**@private */
- this._gradientZMin=null;
- /**@private */
- this._gradientZMax=null;
- }
- __class(GradientVelocity,'laya.d3.core.particleShuriKen.module.GradientVelocity');
- var __proto=GradientVelocity.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var destGradientVelocity=destObject;
- destGradientVelocity._type=this._type;
- this._constant.cloneTo(destGradientVelocity._constant);
- this._gradientX.cloneTo(destGradientVelocity._gradientX);
- this._gradientY.cloneTo(destGradientVelocity._gradientY);
- this._gradientZ.cloneTo(destGradientVelocity._gradientZ);
- this._constantMin.cloneTo(destGradientVelocity._constantMin);
- this._constantMax.cloneTo(destGradientVelocity._constantMax);
- this._gradientXMin.cloneTo(destGradientVelocity._gradientXMin);
- this._gradientXMax.cloneTo(destGradientVelocity._gradientXMax);
- this._gradientYMin.cloneTo(destGradientVelocity._gradientYMin);
- this._gradientYMax.cloneTo(destGradientVelocity._gradientYMax);
- this._gradientZMin.cloneTo(destGradientVelocity._gradientZMin);
- this._gradientZMax.cloneTo(destGradientVelocity._gradientZMax);
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var destGradientVelocity=/*__JS__ */new this.constructor();
- this.cloneTo(destGradientVelocity);
- return destGradientVelocity;
- }
- /**
- *渐变速度Z。
- */
- __getset(0,__proto,'gradientZ',function(){
- return this._gradientZ;
- });
- /**固定速度。*/
- __getset(0,__proto,'constant',function(){
- return this._constant;
- });
- /**
- *生命周期速度类型,0常量模式,1曲线模式,2随机双常量模式,3随机双曲线模式。
- */
- __getset(0,__proto,'type',function(){
- return this._type;
- });
- /**
- *渐变最大速度X。
- */
- __getset(0,__proto,'gradientXMax',function(){
- return this._gradientXMax;
- });
- /**最小固定速度。*/
- __getset(0,__proto,'constantMin',function(){
- return this._constantMin;
- });
- /**
- *渐变速度X。
- */
- __getset(0,__proto,'gradientX',function(){
- return this._gradientX;
- });
- /**
- *渐变速度Y。
- */
- __getset(0,__proto,'gradientY',function(){
- return this._gradientY;
- });
- /**
- *渐变最小速度X。
- */
- __getset(0,__proto,'gradientXMin',function(){
- return this._gradientXMin;
- });
- /**最大固定速度。*/
- __getset(0,__proto,'constantMax',function(){
- return this._constantMax;
- });
- /**
- *渐变最小速度Y。
- */
- __getset(0,__proto,'gradientYMin',function(){
- return this._gradientYMin;
- });
- /**
- *渐变最大速度Y。
- */
- __getset(0,__proto,'gradientYMax',function(){
- return this._gradientYMax;
- });
- /**
- *渐变最小速度Z。
- */
- __getset(0,__proto,'gradientZMin',function(){
- return this._gradientZMin;
- });
- /**
- *渐变最大速度Z。
- */
- __getset(0,__proto,'gradientZMax',function(){
- return this._gradientZMax;
- });
- GradientVelocity.createByConstant=function(constant){
- var gradientVelocity=new GradientVelocity();
- gradientVelocity._type=0;
- gradientVelocity._constant=constant;
- return gradientVelocity;
- }
- GradientVelocity.createByGradient=function(gradientX,gradientY,gradientZ){
- var gradientVelocity=new GradientVelocity();
- gradientVelocity._type=1;
- gradientVelocity._gradientX=gradientX;
- gradientVelocity._gradientY=gradientY;
- gradientVelocity._gradientZ=gradientZ;
- return gradientVelocity;
- }
- GradientVelocity.createByRandomTwoConstant=function(constantMin,constantMax){
- var gradientVelocity=new GradientVelocity();
- gradientVelocity._type=2;
- gradientVelocity._constantMin=constantMin;
- gradientVelocity._constantMax=constantMax;
- return gradientVelocity;
- }
- GradientVelocity.createByRandomTwoGradient=function(gradientXMin,gradientXMax,gradientYMin,gradientYMax,gradientZMin,gradientZMax){
- var gradientVelocity=new GradientVelocity();
- gradientVelocity._type=3;
- gradientVelocity._gradientXMin=gradientXMin;
- gradientVelocity._gradientXMax=gradientXMax;
- gradientVelocity._gradientYMin=gradientYMin;
- gradientVelocity._gradientYMax=gradientYMax;
- gradientVelocity._gradientZMin=gradientZMin;
- gradientVelocity._gradientZMax=gradientZMax;
- return gradientVelocity;
- }
- return GradientVelocity;
- })()
- /**
- *<code>Bounds</code> 类用于创建包围体。
- */
- //class laya.d3.core.Bounds
- var Bounds=(function(){
- function Bounds(min,max){
- /**@private */
- this._updateFlag=0;
- this._center=new Vector3();
- this._extent=new Vector3();
- this._boundBox=new BoundBox(new Vector3(),new Vector3());
- min.cloneTo(this._boundBox.min);
- max.cloneTo(this._boundBox.max);
- this._setUpdateFlag(0x04 | 0x08,true);
- }
- __class(Bounds,'laya.d3.core.Bounds');
- var __proto=Bounds.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *设置包围盒的最小点。
- *@param value 包围盒的最小点。
- */
- __proto.setMin=function(value){
- var min=this._boundBox.min;
- if (value!==min)
- value.cloneTo(min);
- this._setUpdateFlag(0x04 | 0x08,true);
- this._setUpdateFlag(0x01,false);
- }
- /**
- *获取包围盒的最小点。
- *@return 包围盒的最小点。
- */
- __proto.getMin=function(){
- var min=this._boundBox.min;
- if (this._getUpdateFlag(0x01)){
- this._getMin(this.getCenter(),this.getExtent(),min);
- this._setUpdateFlag(0x01,false);
- }
- return min;
- }
- /**
- *设置包围盒的最大点。
- *@param value 包围盒的最大点。
- */
- __proto.setMax=function(value){
- var max=this._boundBox.max;
- if (value!==max)
- value.cloneTo(max);
- this._setUpdateFlag(0x04 | 0x08,true);
- this._setUpdateFlag(0x02,false);
- }
- /**
- *获取包围盒的最大点。
- *@return 包围盒的最大点。
- */
- __proto.getMax=function(){
- var max=this._boundBox.max;
- if (this._getUpdateFlag(0x02)){
- this._getMax(this.getCenter(),this.getExtent(),max);
- this._setUpdateFlag(0x02,false);
- }
- return max;
- }
- /**
- *设置包围盒的中心点。
- *@param value 包围盒的中心点。
- */
- __proto.setCenter=function(value){
- if (value!==this._center)
- value.cloneTo(this._center);
- this._setUpdateFlag(0x01 | 0x02,true);
- this._setUpdateFlag(0x04,false);
- }
- /**
- *获取包围盒的中心点。
- *@return 包围盒的中心点。
- */
- __proto.getCenter=function(){
- if (this._getUpdateFlag(0x04)){
- this._getCenter(this.getMin(),this.getMax(),this._center);
- this._setUpdateFlag(0x04,false);
- }
- return this._center;
- }
- /**
- *设置包围盒的范围。
- *@param value 包围盒的范围。
- */
- __proto.setExtent=function(value){
- if (value!==this._extent)
- value.cloneTo(this._extent);
- this._setUpdateFlag(0x01 | 0x02,true);
- this._setUpdateFlag(0x08,false);
- }
- /**
- *获取包围盒的范围。
- *@return 包围盒的范围。
- */
- __proto.getExtent=function(){
- if (this._getUpdateFlag(0x08)){
- this._getExtent(this.getMin(),this.getMax(),this._extent);
- this._setUpdateFlag(0x08,false);
- }
- return this._extent;
- }
- /**
- *@private
- */
- __proto._getUpdateFlag=function(type){
- return (this._updateFlag & type)!=0;
- }
- /**
- *@private
- */
- __proto._setUpdateFlag=function(type,value){
- if (value)
- this._updateFlag |=type;
- else
- this._updateFlag &=~type;
- }
- /**
- *@private
- */
- __proto._getCenter=function(min,max,out){
- Vector3.add(min,max,out);
- Vector3.scale(out,0.5,out);
- }
- /**
- *@private
- */
- __proto._getExtent=function(min,max,out){
- Vector3.subtract(max,min,out);
- Vector3.scale(out,0.5,out);
- }
- /**
- *@private
- */
- __proto._getMin=function(center,extent,out){
- Vector3.subtract(center,extent,out);
- }
- /**
- *@private
- */
- __proto._getMax=function(center,extent,out){
- Vector3.add(center,extent,out);
- }
- /**
- *@private
- */
- __proto._rotateExtents=function(extents,rotation,out){
- var extentsX=extents.x;
- var extentsY=extents.y;
- var extentsZ=extents.z;
- var matE=rotation.elements;
- out.x=Math.abs(matE[0] *extentsX)+Math.abs(matE[4] *extentsY)+Math.abs(matE[8] *extentsZ);
- out.y=Math.abs(matE[1] *extentsX)+Math.abs(matE[5] *extentsY)+Math.abs(matE[9] *extentsZ);
- out.z=Math.abs(matE[2] *extentsX)+Math.abs(matE[6] *extentsY)+Math.abs(matE[10] *extentsZ);
- }
- /**
- *@private
- */
- __proto._tranform=function(matrix,out){
- var outCen=out._center;
- var outExt=out._extent;
- Vector3.transformCoordinate(this.getCenter(),matrix,outCen);
- this._rotateExtents(this.getExtent(),matrix,outExt);
- out._boundBox.setCenterAndExtent(outCen,outExt);
- out._updateFlag=0;
- }
- /**
- *@private
- */
- __proto._getBoundBox=function(){
- var min=this._boundBox.min;
- if (this._getUpdateFlag(0x01)){
- this._getMin(this.getCenter(),this.getExtent(),min);
- this._setUpdateFlag(0x01,false);
- };
- var max=this._boundBox.max;
- if (this._getUpdateFlag(0x02)){
- this._getMax(this.getCenter(),this.getExtent(),max);
- this._setUpdateFlag(0x02,false);
- }
- return this._boundBox;
- }
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var destBounds=destObject;
- this.getMin().cloneTo(destBounds._boundBox.min);
- this.getMax().cloneTo(destBounds._boundBox.max);
- this.getCenter().cloneTo(destBounds._center);
- this.getExtent().cloneTo(destBounds._extent);
- destBounds._updateFlag=0;
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var dest=/*__JS__ */new this.constructor();
- this.cloneTo(dest);
- return dest;
- }
- Bounds._UPDATE_MIN=0x01;
- Bounds._UPDATE_MAX=0x02;
- Bounds._UPDATE_CENTER=0x04;
- Bounds._UPDATE_EXTENT=0x08;
- return Bounds;
- })()
- /**
- *<code>StartFrame</code> 类用于创建开始帧。
- */
- //class laya.d3.core.particleShuriKen.module.StartFrame
- var StartFrame=(function(){
- function StartFrame(){
- /**@private */
- this._type=0;
- /**@private */
- this._constant=NaN;
- /**@private */
- this._constantMin=NaN;
- /**@private */
- this._constantMax=NaN;
- }
- __class(StartFrame,'laya.d3.core.particleShuriKen.module.StartFrame');
- var __proto=StartFrame.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var destStartFrame=destObject;
- destStartFrame._type=this._type;
- destStartFrame._constant=this._constant;
- destStartFrame._constantMin=this._constantMin;
- destStartFrame._constantMax=this._constantMax;
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var destStartFrame=/*__JS__ */new this.constructor();
- this.cloneTo(destStartFrame);
- return destStartFrame;
- }
- /**
- *固定帧。
- */
- __getset(0,__proto,'constant',function(){
- return this._constant;
- });
- /**
- *开始帧类型,0常量模式,1随机双常量模式。
- */
- __getset(0,__proto,'type',function(){
- return this._type;
- });
- /**
- *最小固定帧。
- */
- __getset(0,__proto,'constantMin',function(){
- return this._constantMin;
- });
- /**
- *最大固定帧。
- */
- __getset(0,__proto,'constantMax',function(){
- return this._constantMax;
- });
- StartFrame.createByConstant=function(constant){
- var rotationOverLifetime=new StartFrame();
- rotationOverLifetime._type=0;
- rotationOverLifetime._constant=constant;
- return rotationOverLifetime;
- }
- StartFrame.createByRandomTwoConstant=function(constantMin,constantMax){
- var rotationOverLifetime=new StartFrame();
- rotationOverLifetime._type=1;
- rotationOverLifetime._constantMin=constantMin;
- rotationOverLifetime._constantMax=constantMax;
- return rotationOverLifetime;
- }
- return StartFrame;
- })()
- /**
- *<code>BoneNode</code> 类用于实现骨骼节点。
- */
- //class laya.d3.animation.AnimationNode
- var AnimationNode=(function(){
- function AnimationNode(localPosition,localRotation,localScale,worldMatrix){
- /**@private */
- //this._children=null;
- /**@private */
- //this._parent=null;
- /**@private [只读]*/
- //this.transform=null;
- /**节点名称。 */
- //this.name=null;
- /**@private [NATIVE]*/
- //this._worldMatrixIndex=0;
- this._children=[];
- this.transform=new AnimationTransform3D(this,localPosition,localRotation,localScale,worldMatrix);
- }
- __class(AnimationNode,'laya.d3.animation.AnimationNode');
- var __proto=AnimationNode.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *添加子节点。
- *@param child 子节点。
- */
- __proto.addChild=function(child){
- child._parent=this;
- child.transform.setParent(this.transform);
- this._children.push(child);
- }
- /**
- *移除子节点。
- *@param child 子节点。
- */
- __proto.removeChild=function(child){
- var index=this._children.indexOf(child);
- (index!==-1)&& (this._children.splice(index,1));
- }
- /**
- *根据名字获取子节点。
- *@param name 名字。
- */
- __proto.getChildByName=function(name){
- for (var i=0,n=this._children.length;i < n;i++){
- var child=this._children[i];
- if (child.name===name)
- return child;
- }
- return null;
- }
- /**
- *根据索引获取子节点。
- *@param index 索引。
- */
- __proto.getChildByIndex=function(index){
- return this._children[index];
- }
- /**
- *获取子节点的个数。
- */
- __proto.getChildCount=function(){
- return this._children.length;
- }
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var destNode=destObject;
- destNode.name=this.name;
- for (var i=0,n=this._children.length;i < n;i++){
- var child=this._children[i];
- var destChild=child.clone();
- destNode.addChild(destChild);
- var transform=child.transform;
- var destTransform=destChild.transform;
- var destLocalPosition=destTransform.localPosition;
- var destLocalRotation=destTransform.localRotation;
- var destLocalScale=destTransform.localScale;
- transform.localPosition.cloneTo(destLocalPosition);
- transform.localRotation.cloneTo(destLocalRotation);
- transform.localScale.cloneTo(destLocalScale);
- destTransform.localPosition=destLocalPosition;
- destTransform.localRotation=destLocalRotation;
- destTransform.localScale=destLocalScale;
- }
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var dest=new AnimationNode();
- this.cloneTo(dest);
- return dest;
- }
- /**
- *@private [NATIVE]
- */
- __proto._cloneNative=function(localPositions,localRotations,localScales,animationNodeWorldMatrixs,animationNodeParentIndices,parentIndex,avatar){
- var curID=avatar._nativeCurCloneCount;
- animationNodeParentIndices[curID]=parentIndex;
- var localPosition=new Float32Array(localPositions.buffer,curID *3 *4,3);
- var localRotation=new Float32Array(localRotations.buffer,curID *4 *4,4);
- var localScale=new Float32Array(localScales.buffer,curID *3 *4,3);
- var worldMatrix=new Float32Array(animationNodeWorldMatrixs.buffer,curID *16 *4,16);
- var dest=new AnimationNode(localPosition,localRotation,localScale,worldMatrix);
- dest._worldMatrixIndex=curID;
- this._cloneToNative(dest,localPositions,localRotations,localScales,animationNodeWorldMatrixs,animationNodeParentIndices,curID,avatar);
- return dest;
- }
- /**
- *@private [NATIVE]
- */
- __proto._cloneToNative=function(destObject,localPositions,localRotations,localScales,animationNodeWorldMatrixs,animationNodeParentIndices,parentIndex,avatar){
- var destNode=destObject;
- destNode.name=this.name;
- for (var i=0,n=this._children.length;i < n;i++){
- var child=this._children[i];
- avatar._nativeCurCloneCount++;
- var destChild=child._cloneNative(localPositions,localRotations,localScales,animationNodeWorldMatrixs,animationNodeParentIndices,parentIndex,avatar);
- destNode.addChild(destChild);
- var transform=child.transform;
- var destTransform=destChild.transform;
- var destLocalPosition=destTransform.localPosition;
- var destLocalRotation=destTransform.localRotation;
- var destLocalScale=destTransform.localScale;
- transform.localPosition.cloneTo(destLocalPosition);
- transform.localRotation.cloneTo(destLocalRotation);
- transform.localScale.cloneTo(destLocalScale);
- destTransform.localPosition=destLocalPosition;
- destTransform.localRotation=destLocalRotation;
- destTransform.localScale=destLocalScale;
- }
- }
- return AnimationNode;
- })()
- /**
- *<code>PostProcess</code> 类用于创建后期处理组件。
- */
- //class laya.d3.component.PostProcess
- var PostProcess=(function(){
- function PostProcess(){
- /**@private */
- this._context=null;
- this._compositeShader=Shader3D.find("PostProcessComposite");
- this._compositeShaderData=new ShaderData();
- this._compositeDefineData=new DefineDatas();
- this._effects=[];
- this._context=new PostProcessRenderContext();
- this._context.compositeShaderData=this._compositeShaderData;
- this._context.compositeDefineData=this._compositeDefineData;
- }
- __class(PostProcess,'laya.d3.component.PostProcess');
- var __proto=PostProcess.prototype;
- /**
- *@private
- */
- __proto._init=function(camera,command){
- this._context.camera=camera;
- this._context.command=command;
- }
- /**
- *@private
- */
- __proto._render=function(){
- var screenTexture=RenderTexture.getTemporary(RenderContext3D.clientWidth,RenderContext3D.clientHeight,/*laya.resource.BaseTexture.FORMAT_R8G8B8*/0,/*laya.resource.BaseTexture.FORMAT_DEPTHSTENCIL_NONE*/3);
- var cameraTarget=this._context.camera.getRenderTexture();
- this._context.command.clear();
- this._context.source=screenTexture;
- this._context.destination=cameraTarget;
- for (var i=0,n=this._effects.length;i < n;i++)
- this._effects[i].render(this._context);
- RenderTexture.setReleaseTemporary(screenTexture);
- var tempRenderTextures=this._context.tempRenderTextures;
- for (i=0,n=tempRenderTextures.length;i < n;i++)
- RenderTexture.setReleaseTemporary(tempRenderTextures[i]);
- }
- /**
- *添加后期处理效果。
- */
- __proto.addEffect=function(effect){
- this._effects.push(effect);
- }
- /**
- *移除后期处理效果。
- */
- __proto.removeEffect=function(effect){
- var index=this._effects.indexOf(effect);
- if (index!==-1)
- this._effects.splice(index,1);
- }
- PostProcess.__init__=function(){
- PostProcess.SHADERDEFINE_BLOOM_LOW=PostProcess.shaderDefines.registerDefine("BLOOM_LOW");
- PostProcess.SHADERDEFINE_BLOOM=PostProcess.shaderDefines.registerDefine("BLOOM");
- }
- PostProcess.SHADERDEFINE_BLOOM_LOW=0;
- PostProcess.SHADERDEFINE_BLOOM=0;
- __static(PostProcess,
- ['SHADERVALUE_MAINTEX',function(){return this.SHADERVALUE_MAINTEX=Shader3D.propertyNameToID("u_MainTex");},'SHADERVALUE_BLOOMTEX',function(){return this.SHADERVALUE_BLOOMTEX=Shader3D.propertyNameToID("u_BloomTex");},'SHADERVALUE_AUTOEXPOSURETEX',function(){return this.SHADERVALUE_AUTOEXPOSURETEX=Shader3D.propertyNameToID("u_AutoExposureTex");},'SHADERVALUE_BLOOM_DIRTTEX',function(){return this.SHADERVALUE_BLOOM_DIRTTEX=Shader3D.propertyNameToID("u_Bloom_DirtTex");},'SHADERVALUE_BLOOMTEX_TEXELSIZE',function(){return this.SHADERVALUE_BLOOMTEX_TEXELSIZE=Shader3D.propertyNameToID("u_BloomTex_TexelSize");},'SHADERVALUE_BLOOM_DIRTTILEOFFSET',function(){return this.SHADERVALUE_BLOOM_DIRTTILEOFFSET=Shader3D.propertyNameToID("u_Bloom_DirtTileOffset");},'SHADERVALUE_BLOOM_SETTINGS',function(){return this.SHADERVALUE_BLOOM_SETTINGS=Shader3D.propertyNameToID("u_Bloom_Settings");},'SHADERVALUE_BLOOM_COLOR',function(){return this.SHADERVALUE_BLOOM_COLOR=Shader3D.propertyNameToID("u_Bloom_Color");},'shaderDefines',function(){return this.shaderDefines=new ShaderDefines();}
- ]);
- return PostProcess;
- })()
- /**
- *<code>Viewport</code> 类用于创建视口。
- */
- //class laya.d3.math.Viewport
- var Viewport=(function(){
- function Viewport(x,y,width,height){
- /**X轴坐标*/
- //this.x=NaN;
- /**Y轴坐标*/
- //this.y=NaN;
- /**宽度*/
- //this.width=NaN;
- /**高度*/
- //this.height=NaN;
- /**最小深度*/
- //this.minDepth=NaN;
- /**最大深度*/
- //this.maxDepth=NaN;
- this.minDepth=0.0;
- this.maxDepth=1.0;
- this.x=x;
- this.y=y;
- this.width=width;
- this.height=height;
- }
- __class(Viewport,'laya.d3.math.Viewport');
- var __proto=Viewport.prototype;
- /**
- *变换一个三维向量。
- *@param source 源三维向量。
- *@param matrix 变换矩阵。
- *@param vector 输出三维向量。
- */
- __proto.project=function(source,matrix,out){
- Vector3.transformV3ToV3(source,matrix,out);
- var matrixEleme=matrix.elements;
- var a=(((source.x *matrixEleme[3])+(source.y *matrixEleme[7]))+(source.z *matrixEleme[11]))+matrixEleme[15];
- if (a!==1.0){
- out.x=out.x / a;
- out.y=out.y / a;
- out.z=out.z / a;
- }
- out.x=(((out.x+1.0)*0.5)*this.width)+this.x;
- out.y=(((-out.y+1.0)*0.5)*this.height)+this.y;
- out.z=(out.z *(this.maxDepth-this.minDepth))+this.minDepth;
- }
- __proto.project1=function(source,matrix,out){
- var v4=Vector3._tempVector4;
- Vector3.transformV3ToV4(source,matrix,v4);
- var dist=v4.w;
- if (dist < 1e-1 && dist >-1e-6)dist=1e-6;
- v4.x /=dist;
- v4.y /=dist;
- v4.z /=dist;
- out.x=(v4.x+1)*this.width / 2+this.x;
- out.y=(-v4.y+1)*this.height / 2+this.y;
- out.z=v4.w;
- return;
- }
- /**
- *反变换一个三维向量。
- *@param source 源三维向量。
- *@param matrix 变换矩阵。
- *@param vector 输出三维向量。
- */
- __proto.unprojectFromMat=function(source,matrix,out){
- var matrixEleme=matrix.elements;
- out.x=(((source.x-this.x)/ (this.width))*2.0)-1.0;
- out.y=-((((source.y-this.y)/ (this.height))*2.0)-1.0);
- var halfDepth=(this.maxDepth-this.minDepth)/ 2;
- out.z=(source.z-this.minDepth-halfDepth)/ halfDepth;
- var a=(((out.x *matrixEleme[3])+(out.y *matrixEleme[7]))+(out.z *matrixEleme[11]))+matrixEleme[15];
- Vector3.transformV3ToV3(out,matrix,out);
- if (a!==1.0){
- out.x=out.x / a;
- out.y=out.y / a;
- out.z=out.z / a;
- }
- }
- /**
- *反变换一个三维向量。
- *@param source 源三维向量。
- *@param projection 透视投影矩阵。
- *@param view 视图矩阵。
- *@param world 世界矩阵,可设置为null。
- *@param out 输出向量。
- */
- __proto.unprojectFromWVP=function(source,projection,view,world,out){
- Matrix4x4.multiply(projection,view,Viewport._tempMatrix4x4);
- (world)&& (Matrix4x4.multiply(Viewport._tempMatrix4x4,world,Viewport._tempMatrix4x4));
- Viewport._tempMatrix4x4.invert(Viewport._tempMatrix4x4);
- this.unprojectFromMat(source,Viewport._tempMatrix4x4,out);
- }
- /**
- *克隆
- *@param out
- */
- __proto.cloneTo=function(out){
- out.x=this.x;
- out.y=this.y;
- out.width=this.width;
- out.height=this.height;
- out.minDepth=this.minDepth;
- out.maxDepth=this.maxDepth;
- }
- __static(Viewport,
- ['_tempMatrix4x4',function(){return this._tempMatrix4x4=new Matrix4x4();}
- ]);
- return Viewport;
- })()
- /**
- *<code>DetailTextureInfo</code> 类用于描述地形细节纹理。
- */
- //class laya.d3.terrain.unit.DetailTextureInfo
- var DetailTextureInfo=(function(){
- function DetailTextureInfo(){
- this.diffuseTexture=null;
- this.normalTexture=null;
- this.scale=null;
- this.offset=null;
- }
- __class(DetailTextureInfo,'laya.d3.terrain.unit.DetailTextureInfo');
- return DetailTextureInfo;
- })()
- /**
- *<code>OrientedBoundBox</code> 类用于创建OBB包围盒。
- */
- //class laya.d3.math.OrientedBoundBox
- var OrientedBoundBox=(function(){
- function OrientedBoundBox(extents,transformation){
- /**每个轴长度的一半*/
- this.extents=null;
- /**这个矩阵表示包围盒的位置和缩放,它的平移向量表示该包围盒的中心*/
- this.transformation=null;
- this.extents=extents;
- this.transformation=transformation;
- }
- __class(OrientedBoundBox,'laya.d3.math.OrientedBoundBox');
- var __proto=OrientedBoundBox.prototype;
- /**
- *获取OBB包围盒的8个顶点。
- *@param corners 返回顶点的输出队列。
- */
- __proto.getCorners=function(corners){
- OrientedBoundBox._tempV30.x=this.extents.x;
- OrientedBoundBox._tempV30.y=OrientedBoundBox._tempV30.z=0;
- OrientedBoundBox._tempV31.y=this.extents.y;
- OrientedBoundBox._tempV31.x=OrientedBoundBox._tempV31.z=0;
- OrientedBoundBox._tempV32.z=this.extents.z;
- OrientedBoundBox._tempV32.x=OrientedBoundBox._tempV32.y=0;
- Vector3.TransformNormal(OrientedBoundBox._tempV30,this.transformation,OrientedBoundBox._tempV30);
- Vector3.TransformNormal(OrientedBoundBox._tempV31,this.transformation,OrientedBoundBox._tempV31);
- Vector3.TransformNormal(OrientedBoundBox._tempV32,this.transformation,OrientedBoundBox._tempV32);
- var center=OrientedBoundBox._tempV33;
- this.transformation.getTranslationVector(center);
- corners.length=8;
- Vector3.add(center,OrientedBoundBox._tempV30,OrientedBoundBox._tempV34);
- Vector3.add(OrientedBoundBox._tempV34,OrientedBoundBox._tempV31,OrientedBoundBox._tempV34);
- Vector3.add(OrientedBoundBox._tempV34,OrientedBoundBox._tempV32,corners[0]);
- Vector3.add(center,OrientedBoundBox._tempV30,OrientedBoundBox._tempV34);
- Vector3.add(OrientedBoundBox._tempV34,OrientedBoundBox._tempV31,OrientedBoundBox._tempV34);
- Vector3.subtract(OrientedBoundBox._tempV34,OrientedBoundBox._tempV32,corners[1]);
- Vector3.subtract(center,OrientedBoundBox._tempV30,OrientedBoundBox._tempV34);
- Vector3.add(OrientedBoundBox._tempV34,OrientedBoundBox._tempV31,OrientedBoundBox._tempV34);
- Vector3.subtract(OrientedBoundBox._tempV34,OrientedBoundBox._tempV32,corners[2]);
- Vector3.subtract(center,OrientedBoundBox._tempV30,OrientedBoundBox._tempV34);
- Vector3.add(OrientedBoundBox._tempV34,OrientedBoundBox._tempV31,OrientedBoundBox._tempV34);
- Vector3.add(OrientedBoundBox._tempV34,OrientedBoundBox._tempV32,corners[3]);
- Vector3.add(center,OrientedBoundBox._tempV30,OrientedBoundBox._tempV34);
- Vector3.subtract(OrientedBoundBox._tempV34,OrientedBoundBox._tempV31,OrientedBoundBox._tempV34);
- Vector3.add(OrientedBoundBox._tempV34,OrientedBoundBox._tempV32,corners[4]);
- Vector3.add(center,OrientedBoundBox._tempV30,OrientedBoundBox._tempV34);
- Vector3.subtract(OrientedBoundBox._tempV34,OrientedBoundBox._tempV31,OrientedBoundBox._tempV34);
- Vector3.subtract(OrientedBoundBox._tempV34,OrientedBoundBox._tempV32,corners[5]);
- Vector3.subtract(center,OrientedBoundBox._tempV30,OrientedBoundBox._tempV34);
- Vector3.subtract(OrientedBoundBox._tempV34,OrientedBoundBox._tempV31,OrientedBoundBox._tempV34);
- Vector3.subtract(OrientedBoundBox._tempV34,OrientedBoundBox._tempV32,corners[6]);
- Vector3.subtract(center,OrientedBoundBox._tempV30,OrientedBoundBox._tempV34);
- Vector3.subtract(OrientedBoundBox._tempV34,OrientedBoundBox._tempV31,OrientedBoundBox._tempV34);
- Vector3.add(OrientedBoundBox._tempV34,OrientedBoundBox._tempV32,corners[7]);
- }
- /**
- *变换该包围盒的矩阵信息。
- *@param mat 矩阵
- */
- __proto.transform=function(mat){
- Matrix4x4.multiply(this.transformation,mat,this.transformation);
- }
- /**
- *缩放该包围盒
- *@param scaling 各轴的缩放比。
- */
- __proto.scale=function(scaling){
- Vector3.multiply(this.extents,scaling,this.extents);
- }
- /**
- *平移该包围盒。
- *@param translation 平移参数
- */
- __proto.translate=function(translation){
- this.transformation.getTranslationVector(OrientedBoundBox._tempV30);
- Vector3.add(OrientedBoundBox._tempV30,translation,OrientedBoundBox._tempV31);
- this.transformation.setTranslationVector(OrientedBoundBox._tempV31);
- }
- /**
- *该包围盒的尺寸。
- *@param out 输出
- */
- __proto.Size=function(out){
- Vector3.scale(this.extents,2,out);
- }
- /**
- *该包围盒需要考虑的尺寸
- *@param out 输出
- */
- __proto.getSize=function(out){
- OrientedBoundBox._tempV30.x=this.extents.x;
- OrientedBoundBox._tempV31.y=this.extents.y;
- OrientedBoundBox._tempV32.z=this.extents.z;
- Vector3.TransformNormal(OrientedBoundBox._tempV30,this.transformation,OrientedBoundBox._tempV30);
- Vector3.TransformNormal(OrientedBoundBox._tempV31,this.transformation,OrientedBoundBox._tempV31);
- Vector3.TransformNormal(OrientedBoundBox._tempV31,this.transformation,OrientedBoundBox._tempV32);
- out.x=Vector3.scalarLength(OrientedBoundBox._tempV30);
- out.y=Vector3.scalarLength(OrientedBoundBox._tempV31);
- out.z=Vector3.scalarLength(OrientedBoundBox._tempV32);
- }
- /**
- *该包围盒需要考虑尺寸的平方
- *@param out 输出
- */
- __proto.getSizeSquared=function(out){
- OrientedBoundBox._tempV30.x=this.extents.x;
- OrientedBoundBox._tempV31.y=this.extents.y;
- OrientedBoundBox._tempV32.z=this.extents.z;
- Vector3.TransformNormal(OrientedBoundBox._tempV30,this.transformation,OrientedBoundBox._tempV30);
- Vector3.TransformNormal(OrientedBoundBox._tempV31,this.transformation,OrientedBoundBox._tempV31);
- Vector3.TransformNormal(OrientedBoundBox._tempV31,this.transformation,OrientedBoundBox._tempV32);
- out.x=Vector3.scalarLengthSquared(OrientedBoundBox._tempV30);
- out.y=Vector3.scalarLengthSquared(OrientedBoundBox._tempV31);
- out.z=Vector3.scalarLengthSquared(OrientedBoundBox._tempV32);
- }
- /**
- *该包围盒的几何中心
- */
- __proto.getCenter=function(center){
- this.transformation.getTranslationVector(center);
- }
- /**
- *该包围盒是否包含空间中一点
- *@param point 点
- *@return 返回位置关系
- */
- __proto.containsPoint=function(point){
- var extentsEX=this.extents.x;
- var extentsEY=this.extents.y;
- var extentsEZ=this.extents.z;
- this.transformation.invert(OrientedBoundBox._tempM0);
- Vector3.transformCoordinate(point,OrientedBoundBox._tempM0,OrientedBoundBox._tempV30);
- var _tempV30ex=Math.abs(OrientedBoundBox._tempV30.x);
- var _tempV30ey=Math.abs(OrientedBoundBox._tempV30.y);
- var _tempV30ez=Math.abs(OrientedBoundBox._tempV30.z);
- if (MathUtils3D.nearEqual(_tempV30ex,extentsEX)&& MathUtils3D.nearEqual(_tempV30ey,extentsEY)&& MathUtils3D.nearEqual(_tempV30ez,extentsEZ))
- return /*laya.d3.math.ContainmentType.Intersects*/2;
- if (_tempV30ex < extentsEX && _tempV30ey < extentsEY && _tempV30ez < extentsEZ)
- return /*laya.d3.math.ContainmentType.Contains*/1;
- else
- return /*laya.d3.math.ContainmentType.Disjoint*/0;
- }
- /**
- *该包围盒是否包含空间中多点
- *@param point 点
- *@return 返回位置关系
- */
- __proto.containsPoints=function(points){
- var extentsex=this.extents.x;
- var extentsey=this.extents.y;
- var extentsez=this.extents.z;
- this.transformation.invert(OrientedBoundBox._tempM0);
- var containsAll=true;
- var containsAny=false;
- for (var i=0;i < points.length;i++){
- Vector3.transformCoordinate(points[i],OrientedBoundBox._tempM0,OrientedBoundBox._tempV30);
- var _tempV30ex=Math.abs(OrientedBoundBox._tempV30.x);
- var _tempV30ey=Math.abs(OrientedBoundBox._tempV30.y);
- var _tempV30ez=Math.abs(OrientedBoundBox._tempV30.z);
- if (MathUtils3D.nearEqual(_tempV30ex,extentsex)&& MathUtils3D.nearEqual(_tempV30ey,extentsey)&& MathUtils3D.nearEqual(_tempV30ez,extentsez))
- containsAny=true;
- if (_tempV30ex < extentsex && _tempV30ey < extentsey && _tempV30ez < extentsez)
- containsAny=true;
- else
- containsAll=false;
- }
- if (containsAll)
- return /*laya.d3.math.ContainmentType.Contains*/1;
- else if (containsAny)
- return /*laya.d3.math.ContainmentType.Intersects*/2;
- else
- return /*laya.d3.math.ContainmentType.Disjoint*/0;
- }
- /**
- *该包围盒是否包含空间中一包围球
- *@param sphere 包围球
- *@param ignoreScale 是否考虑该包围盒的缩放
- *@return 返回位置关系
- */
- __proto.containsSphere=function(sphere,ignoreScale){
- (ignoreScale===void 0)&& (ignoreScale=false);
- var extentsEX=this.extents.x;
- var extentsEY=this.extents.y;
- var extentsEZ=this.extents.z;
- var sphereR=sphere.radius;
- this.transformation.invert(OrientedBoundBox._tempM0);
- Vector3.transformCoordinate(sphere.center,OrientedBoundBox._tempM0,OrientedBoundBox._tempV30);
- var locRadius=NaN;
- if (ignoreScale){
- locRadius=sphereR;
- }else {
- Vector3.scale(Vector3._UnitX,sphereR,OrientedBoundBox._tempV31);
- Vector3.TransformNormal(OrientedBoundBox._tempV31,OrientedBoundBox._tempM0,OrientedBoundBox._tempV31);
- locRadius=Vector3.scalarLength(OrientedBoundBox._tempV31);
- }
- Vector3.scale(this.extents,-1,OrientedBoundBox._tempV32);
- Vector3.Clamp(OrientedBoundBox._tempV30,OrientedBoundBox._tempV32,this.extents,OrientedBoundBox._tempV33);
- var distance=Vector3.distanceSquared(OrientedBoundBox._tempV30,OrientedBoundBox._tempV33);
- if (distance > locRadius *locRadius)
- return /*laya.d3.math.ContainmentType.Disjoint*/0;
- var tempV30ex=OrientedBoundBox._tempV30.x;
- var tempV30ey=OrientedBoundBox._tempV30.y;
- var tempV30ez=OrientedBoundBox._tempV30.z;
- var tempV32ex=OrientedBoundBox._tempV32.x;
- var tempV32ey=OrientedBoundBox._tempV32.y;
- var tempV32ez=OrientedBoundBox._tempV32.z;
- if ((((tempV32ex+locRadius <=tempV30ex)&& (tempV30ex <=extentsEX-locRadius))&& ((extentsEX-tempV32ex > locRadius)&& (tempV32ey+locRadius <=tempV30ey)))&& (((tempV30ey <=extentsEY-locRadius)&& (extentsEY-tempV32ey > locRadius))&& (((tempV32ez+locRadius <=tempV30ez)&& (tempV30ez <=extentsEZ-locRadius))&& (extentsEZ-tempV32ez > locRadius)))){
- return /*laya.d3.math.ContainmentType.Contains*/1;
- }
- return /*laya.d3.math.ContainmentType.Intersects*/2;
- }
- /**
- *For accuracy,The transformation matrix for both <see cref="OrientedBoundingBox"/> must not have any scaling applied to it.
- *Anyway,scaling using Scale method will keep this method accurate.
- *该包围盒是否包含空间中另一OBB包围盒
- *@param obb OBB包围盒
- *@return 返回位置关系
- */
- __proto.containsOrientedBoundBox=function(obb){
- var i=0,k=0;
- obb.getCorners(OrientedBoundBox._corners);
- var cornersCheck=this.containsPoints(OrientedBoundBox._corners);
- if (cornersCheck !=/*laya.d3.math.ContainmentType.Disjoint*/0)
- return cornersCheck;
- OrientedBoundBox._sizeAe[0]=this.extents.x;
- OrientedBoundBox._sizeAe[1]=this.extents.y;
- OrientedBoundBox._sizeAe[2]=this.extents.z;
- obb.extents.cloneTo(OrientedBoundBox._tempV35);
- OrientedBoundBox._sizeBe[0]=OrientedBoundBox._tempV35.x;
- OrientedBoundBox._sizeBe[1]=OrientedBoundBox._tempV35.y;
- OrientedBoundBox._sizeBe[2]=OrientedBoundBox._tempV35.z;
- OrientedBoundBox._getRows(this.transformation,OrientedBoundBox._rows1);
- OrientedBoundBox._getRows(obb.transformation,OrientedBoundBox._rows2);
- var extentA=NaN,extentB=NaN,separation=NaN,dotNumber=NaN;
- for (i=0;i < 4;i++){
- for (k=0;k < 4;k++){
- if (i==3 || k==3){
- OrientedBoundBox._tempM0.setElementByRowColumn(i,k,0);
- OrientedBoundBox._tempM1.setElementByRowColumn(i,k,0);
- }else {
- dotNumber=Vector3.dot(OrientedBoundBox._rows1[i],OrientedBoundBox._rows2[k]);
- OrientedBoundBox._tempM0.setElementByRowColumn(i,k,dotNumber);
- OrientedBoundBox._tempM1.setElementByRowColumn(i,k,Math.abs(dotNumber));
- }
- }
- }
- obb.getCenter(OrientedBoundBox._tempV34);
- this.getCenter(OrientedBoundBox._tempV36);
- Vector3.subtract(OrientedBoundBox._tempV34,OrientedBoundBox._tempV36,OrientedBoundBox._tempV30);
- OrientedBoundBox._tempV31.x=Vector3.dot(OrientedBoundBox._tempV30,OrientedBoundBox._rows1[0]);
- OrientedBoundBox._tempV31.y=Vector3.dot(OrientedBoundBox._tempV30,OrientedBoundBox._rows1[1]);
- OrientedBoundBox._tempV31.z=Vector3.dot(OrientedBoundBox._tempV30,OrientedBoundBox._rows1[2]);
- OrientedBoundBox._vsepAe[0]=OrientedBoundBox._tempV31.x;
- OrientedBoundBox._vsepAe[1]=OrientedBoundBox._tempV31.y;
- OrientedBoundBox._vsepAe[2]=OrientedBoundBox._tempV31.z;
- for (i=0;i < 3;i++){
- OrientedBoundBox._tempV32.x=OrientedBoundBox._tempM1.getElementByRowColumn(i,0);
- OrientedBoundBox._tempV32.y=OrientedBoundBox._tempM1.getElementByRowColumn(i,1);
- OrientedBoundBox._tempV32.z=OrientedBoundBox._tempM1.getElementByRowColumn(i,2);
- extentA=OrientedBoundBox._sizeAe[i];
- extentB=Vector3.dot(OrientedBoundBox._tempV35,OrientedBoundBox._tempV32);
- separation=Math.abs(OrientedBoundBox._vsepAe[i]);
- if (separation > extentA+extentB)
- return /*laya.d3.math.ContainmentType.Disjoint*/0;
- }
- for (k=0;k < 3;k++){
- OrientedBoundBox._tempV32.x=OrientedBoundBox._tempM1.getElementByRowColumn(0,k);
- OrientedBoundBox._tempV32.y=OrientedBoundBox._tempM1.getElementByRowColumn(1,k);
- OrientedBoundBox._tempV32.z=OrientedBoundBox._tempM1.getElementByRowColumn(2,k);
- OrientedBoundBox._tempV33.x=OrientedBoundBox._tempM0.getElementByRowColumn(0,k);
- OrientedBoundBox._tempV33.y=OrientedBoundBox._tempM0.getElementByRowColumn(1,k);
- OrientedBoundBox._tempV33.z=OrientedBoundBox._tempM0.getElementByRowColumn(2,k);
- extentA=Vector3.dot(this.extents,OrientedBoundBox._tempV32);
- extentB=OrientedBoundBox._sizeBe[k];
- separation=Math.abs(Vector3.dot(OrientedBoundBox._tempV31,OrientedBoundBox._tempV33));
- if (separation > extentA+extentB)
- return /*laya.d3.math.ContainmentType.Disjoint*/0;
- }
- for (i=0;i < 3;i++){
- for (k=0;k < 3;k++){
- var i1=(i+1)% 3,i2=(i+2)% 3;
- var k1=(k+1)% 3,k2=(k+2)% 3;
- extentA=OrientedBoundBox._sizeAe[i1] *OrientedBoundBox._tempM1.getElementByRowColumn(i2,k)+OrientedBoundBox._sizeAe[i2] *OrientedBoundBox._tempM1.getElementByRowColumn(i1,k);
- extentB=OrientedBoundBox._sizeBe[k1] *OrientedBoundBox._tempM1.getElementByRowColumn(i,k2)+OrientedBoundBox._sizeBe[k2] *OrientedBoundBox._tempM1.getElementByRowColumn(i,k1);
- separation=Math.abs(OrientedBoundBox._vsepAe[i2] *OrientedBoundBox._tempM0.getElementByRowColumn(i1,k)-OrientedBoundBox._vsepAe[i1] *OrientedBoundBox._tempM0.getElementByRowColumn(i2,k));
- if (separation > extentA+extentB)
- return /*laya.d3.math.ContainmentType.Disjoint*/0;
- }
- }
- return /*laya.d3.math.ContainmentType.Intersects*/2;
- }
- /**
- *该包围盒是否包含空间中一条线
- *@param point1 点1
- *@param point2 点2
- *@return 返回位置关系
- */
- __proto.containsLine=function(point1,point2){
- OrientedBoundBox._corners[0]=point1;
- OrientedBoundBox._corners[1]=point2;
- var cornersCheck=this.containsPoints(OrientedBoundBox._corners);
- if (cornersCheck !=/*laya.d3.math.ContainmentType.Disjoint*/0)
- return cornersCheck;
- var extentsX=this.extents.x;
- var extentsY=this.extents.y;
- var extentsZ=this.extents.z;
- this.transformation.invert(OrientedBoundBox._tempM0);
- Vector3.transformCoordinate(point1,OrientedBoundBox._tempM0,OrientedBoundBox._tempV30);
- Vector3.transformCoordinate(point2,OrientedBoundBox._tempM0,OrientedBoundBox._tempV31);
- Vector3.add(OrientedBoundBox._tempV30,OrientedBoundBox._tempV31,OrientedBoundBox._tempV32);
- Vector3.scale(OrientedBoundBox._tempV32,0.5,OrientedBoundBox._tempV32);
- Vector3.subtract(OrientedBoundBox._tempV30,OrientedBoundBox._tempV32,OrientedBoundBox._tempV33);
- var _tempV33X=OrientedBoundBox._tempV33.x;
- var _tempV33Y=OrientedBoundBox._tempV33.y;
- var _tempV33Z=OrientedBoundBox._tempV33.z;
- var _tempV34X=OrientedBoundBox._tempV34.x=Math.abs(OrientedBoundBox._tempV33.x);
- var _tempV34Y=OrientedBoundBox._tempV34.y=Math.abs(OrientedBoundBox._tempV33.y);
- var _tempV34Z=OrientedBoundBox._tempV34.z=Math.abs(OrientedBoundBox._tempV33.z);
- var _tempV32X=OrientedBoundBox._tempV32.x;
- var _tempV32Y=OrientedBoundBox._tempV32.y;
- var _tempV32Z=OrientedBoundBox._tempV32.z;
- if (Math.abs(_tempV32X)> extentsX+_tempV34X)
- return /*laya.d3.math.ContainmentType.Disjoint*/0;
- if (Math.abs(_tempV32Y)> extentsY+_tempV34Y)
- return /*laya.d3.math.ContainmentType.Disjoint*/0;
- if (Math.abs(_tempV32Z)> extentsZ+_tempV34Z)
- return /*laya.d3.math.ContainmentType.Disjoint*/0;
- if (Math.abs(_tempV32Y *_tempV33Z-_tempV32Z *_tempV33Y)> (extentsY *_tempV34Z+extentsZ *_tempV34Y))
- return /*laya.d3.math.ContainmentType.Disjoint*/0;
- if (Math.abs(_tempV32X *_tempV33Z-_tempV32Z *_tempV33X)> (extentsX *_tempV34Z+extentsZ *_tempV34X))
- return /*laya.d3.math.ContainmentType.Disjoint*/0;
- if (Math.abs(_tempV32X *_tempV33Y-_tempV32Y *_tempV33X)> (extentsX *_tempV34Y+extentsY *_tempV34X))
- return /*laya.d3.math.ContainmentType.Disjoint*/0;
- return /*laya.d3.math.ContainmentType.Intersects*/2;
- }
- /**
- *该包围盒是否包含空间中另一OBB包围盒
- *@param box 包围盒
- *@return 返回位置关系
- */
- __proto.containsBoundBox=function(box){
- var i=0,k=0;
- var min=box.min;
- var max=box.max;
- box.getCorners(OrientedBoundBox._corners);
- var cornersCheck=this.containsPoints(OrientedBoundBox._corners);
- if (cornersCheck !=/*laya.d3.math.ContainmentType.Disjoint*/0)
- return cornersCheck;
- Vector3.subtract(max,min,OrientedBoundBox._tempV30);
- Vector3.scale(OrientedBoundBox._tempV30,0.5,OrientedBoundBox._tempV30);
- Vector3.add(min,OrientedBoundBox._tempV30,OrientedBoundBox._tempV30);
- Vector3.subtract(max,OrientedBoundBox._tempV30,OrientedBoundBox._tempV31);
- OrientedBoundBox._sizeAe[0]=this.extents.x;
- OrientedBoundBox._sizeAe[1]=this.extents.y;
- OrientedBoundBox._sizeAe[2]=this.extents.z;
- OrientedBoundBox._sizeBe[0]=OrientedBoundBox._tempV31.x;
- OrientedBoundBox._sizeBe[1]=OrientedBoundBox._tempV31.y;
- OrientedBoundBox._sizeBe[2]=OrientedBoundBox._tempV31.z;
- OrientedBoundBox._getRows(this.transformation,OrientedBoundBox._rows1);
- this.transformation.invert(OrientedBoundBox._tempM0);
- var extentA=NaN,extentB=NaN,separation=NaN,dotNumber=NaN;
- for (i=0;i < 3;i++){
- for (k=0;k < 3;k++){
- OrientedBoundBox._tempM1.setElementByRowColumn(i,k,Math.abs(OrientedBoundBox._tempM0.getElementByRowColumn(i,k)));
- }
- }
- this.getCenter(OrientedBoundBox._tempV35);
- Vector3.subtract(OrientedBoundBox._tempV30,OrientedBoundBox._tempV35,OrientedBoundBox._tempV32);
- OrientedBoundBox._tempV31.x=Vector3.dot(OrientedBoundBox._tempV32,OrientedBoundBox._rows1[0]);
- OrientedBoundBox._tempV31.y=Vector3.dot(OrientedBoundBox._tempV32,OrientedBoundBox._rows1[1]);
- OrientedBoundBox._tempV31.z=Vector3.dot(OrientedBoundBox._tempV32,OrientedBoundBox._rows1[2]);
- OrientedBoundBox._vsepAe[0]=OrientedBoundBox._tempV31.x;
- OrientedBoundBox._vsepAe[1]=OrientedBoundBox._tempV31.y;
- OrientedBoundBox._vsepAe[2]=OrientedBoundBox._tempV31.z;
- for (i=0;i < 3;i++){
- OrientedBoundBox._tempV33.x=OrientedBoundBox._tempM1.getElementByRowColumn(i,0);
- OrientedBoundBox._tempV33.y=OrientedBoundBox._tempM1.getElementByRowColumn(i,1);
- OrientedBoundBox._tempV33.z=OrientedBoundBox._tempM1.getElementByRowColumn(i,2);
- extentA=OrientedBoundBox._sizeAe[i];
- extentB=Vector3.dot(OrientedBoundBox._tempV31,OrientedBoundBox._tempV33);
- separation=Math.abs(OrientedBoundBox._vsepAe[i]);
- if (separation > extentA+extentB)
- return /*laya.d3.math.ContainmentType.Disjoint*/0;
- }
- for (k=0;k < 3;k++){
- OrientedBoundBox._tempV33.x=OrientedBoundBox._tempM1.getElementByRowColumn(0,k);
- OrientedBoundBox._tempV33.y=OrientedBoundBox._tempM1.getElementByRowColumn(1,k);
- OrientedBoundBox._tempV33.z=OrientedBoundBox._tempM1.getElementByRowColumn(2,k);
- OrientedBoundBox._tempV34.x=OrientedBoundBox._tempM0.getElementByRowColumn(0,k);
- OrientedBoundBox._tempV34.y=OrientedBoundBox._tempM0.getElementByRowColumn(1,k);
- OrientedBoundBox._tempV34.z=OrientedBoundBox._tempM0.getElementByRowColumn(2,k);
- extentA=Vector3.dot(this.extents,OrientedBoundBox._tempV33);
- extentB=OrientedBoundBox._sizeBe[k];
- separation=Math.abs(Vector3.dot(OrientedBoundBox._tempV31,OrientedBoundBox._tempV34));
- if (separation > extentA+extentB)
- return /*laya.d3.math.ContainmentType.Disjoint*/0;
- }
- for (i=0;i < 3;i++){
- for (k=0;k < 3;k++){
- var i1=(i+1)% 3,i2=(i+2)% 3;
- var k1=(k+1)% 3,k2=(k+2)% 3;
- extentA=OrientedBoundBox._sizeAe[i1] *OrientedBoundBox._tempM1.getElementByRowColumn(i2,k)+OrientedBoundBox._sizeAe[i2] *OrientedBoundBox._tempM1.getElementByRowColumn(i1,k);
- extentB=OrientedBoundBox._sizeBe[k1] *OrientedBoundBox._tempM1.getElementByRowColumn(i,k2)+OrientedBoundBox._sizeBe[k2] *OrientedBoundBox._tempM1.getElementByRowColumn(i,k1);
- separation=Math.abs(OrientedBoundBox._vsepAe[i2] *OrientedBoundBox._tempM0.getElementByRowColumn(i1,k)-OrientedBoundBox._vsepAe[i1] *OrientedBoundBox._tempM0.getElementByRowColumn(i2,k));
- if (separation > extentA+extentB)
- return /*laya.d3.math.ContainmentType.Disjoint*/0;
- }
- }
- return /*laya.d3.math.ContainmentType.Intersects*/2;
- }
- /**
- *该包围盒是否与空间中另一射线相交
- *@param ray
- *@param out
- *@return
- */
- __proto.intersectsRay=function(ray,out){
- Vector3.scale(this.extents,-1,OrientedBoundBox._tempV30);
- this.transformation.invert(OrientedBoundBox._tempM0);
- Vector3.TransformNormal(ray.direction,OrientedBoundBox._tempM0,OrientedBoundBox._ray.direction);
- Vector3.transformCoordinate(ray.origin,OrientedBoundBox._tempM0,OrientedBoundBox._ray.origin);
- OrientedBoundBox._boxBound1.min=OrientedBoundBox._tempV30;
- OrientedBoundBox._boxBound1.max=this.extents;
- var intersects=CollisionUtils.intersectsRayAndBoxRP(OrientedBoundBox._ray,OrientedBoundBox._boxBound1,out);
- if (intersects!==-1)
- Vector3.transformCoordinate(out,this.transformation,out);
- return intersects;
- }
- __proto._getLocalCorners=function(corners){
- corners.length=8;
- OrientedBoundBox._tempV30.x=this.extents.x;
- OrientedBoundBox._tempV31.y=this.extents.y;
- OrientedBoundBox._tempV32.z=this.extents.z;
- Vector3.add(OrientedBoundBox._tempV30,OrientedBoundBox._tempV31,OrientedBoundBox._tempV33);
- Vector3.add(OrientedBoundBox._tempV33,OrientedBoundBox._tempV32,corners[0]);
- Vector3.add(OrientedBoundBox._tempV30,OrientedBoundBox._tempV31,OrientedBoundBox._tempV33);
- Vector3.subtract(OrientedBoundBox._tempV33,OrientedBoundBox._tempV32,corners[1]);
- Vector3.subtract(OrientedBoundBox._tempV31,OrientedBoundBox._tempV30,OrientedBoundBox._tempV33);
- Vector3.subtract(OrientedBoundBox._tempV33,OrientedBoundBox._tempV30,corners[2]);
- Vector3.subtract(OrientedBoundBox._tempV31,OrientedBoundBox._tempV30,OrientedBoundBox._tempV33);
- Vector3.add(OrientedBoundBox._tempV33,OrientedBoundBox._tempV32,corners[3]);
- Vector3.subtract(OrientedBoundBox._tempV30,OrientedBoundBox._tempV31,OrientedBoundBox._tempV33);
- Vector3.add(OrientedBoundBox._tempV33,OrientedBoundBox._tempV32,corners[4]);
- Vector3.subtract(OrientedBoundBox._tempV30,OrientedBoundBox._tempV31,OrientedBoundBox._tempV33);
- Vector3.subtract(OrientedBoundBox._tempV33,OrientedBoundBox._tempV32,corners[5]);
- Vector3.scale(corners[0],-1,corners[6]);
- Vector3.subtract(OrientedBoundBox._tempV32,OrientedBoundBox._tempV30,OrientedBoundBox._tempV33);
- Vector3.subtract(OrientedBoundBox._tempV33,OrientedBoundBox._tempV31,corners[7]);
- }
- /**
- *判断两个包围盒是否相等
- *@param obb obb包围盒
- *@return Boolean
- */
- __proto.equals=function(obb){
- return this.extents==obb.extents && this.transformation==obb.transformation;
- }
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var dest=destObject;
- this.extents.cloneTo(dest.extents);
- this.transformation.cloneTo(dest.transformation);
- }
- OrientedBoundBox.createByBoundBox=function(box,out){
- var min=box.min;
- var max=box.max;
- Vector3.subtract(max,min,OrientedBoundBox._tempV30);
- Vector3.scale(OrientedBoundBox._tempV30,0.5,OrientedBoundBox._tempV30);
- Vector3.add(min,OrientedBoundBox._tempV30,OrientedBoundBox._tempV31);
- Vector3.subtract(max,OrientedBoundBox._tempV31,OrientedBoundBox._tempV32);
- Matrix4x4.translation(OrientedBoundBox._tempV31,OrientedBoundBox._tempM0);
- var extents=OrientedBoundBox._tempV32.clone();
- var transformation=OrientedBoundBox._tempM0.clone();
- out.extents=extents;
- out.transformation=transformation;
- }
- OrientedBoundBox.createByMinAndMaxVertex=function(min,max){
- Vector3.subtract(max,min,OrientedBoundBox._tempV30);
- Vector3.scale(OrientedBoundBox._tempV30,0.5,OrientedBoundBox._tempV30);
- Vector3.add(min,OrientedBoundBox._tempV30,OrientedBoundBox._tempV31);
- Vector3.subtract(max,OrientedBoundBox._tempV31,OrientedBoundBox._tempV32);
- Matrix4x4.translation(OrientedBoundBox._tempV31,OrientedBoundBox._tempM0);
- var obb=new OrientedBoundBox(OrientedBoundBox._tempV32,OrientedBoundBox._tempM0);
- return obb;
- }
- OrientedBoundBox._getRows=function(mat,out){
- out.length=3;
- var mate=mat.elements;
- out[0].x=mate[0];
- out[0].y=mate[1];
- out[0].z=mate[2];
- out[1].x=mate[4];
- out[1].y=mate[5];
- out[1].z=mate[6];
- out[2].x=mate[8];
- out[2].y=mate[9];
- out[2].z=mate[10];
- }
- OrientedBoundBox.getObbtoObbMatrix4x4=function(a,b,noMatrixScaleApplied,out){
- var at=a.transformation;
- var bt=b.transformation;
- if (noMatrixScaleApplied){
- OrientedBoundBox._getRows(at,OrientedBoundBox._rows1);
- OrientedBoundBox._getRows(bt,OrientedBoundBox._rows2);
- for (var i=0;i < 3;i++){
- for (var k=0;k < 3;k++){
- out.setElementByRowColumn(i,k,Vector3.dot(OrientedBoundBox._rows2[i],OrientedBoundBox._rows1[k]));
- }
- }
- b.getCenter(OrientedBoundBox._tempV30);
- a.getCenter(OrientedBoundBox._tempV31);
- Vector3.subtract(OrientedBoundBox._tempV30,OrientedBoundBox._tempV31,OrientedBoundBox._tempV32);
- var AtoBMe=out.elements;
- AtoBMe[12]=Vector3.dot(OrientedBoundBox._tempV32,OrientedBoundBox._rows1[0]);
- AtoBMe[13]=Vector3.dot(OrientedBoundBox._tempV32,OrientedBoundBox._rows1[1]);
- AtoBMe[14]=Vector3.dot(OrientedBoundBox._tempV32,OrientedBoundBox._rows1[2]);
- AtoBMe[15]=1;
- }else {
- at.invert(OrientedBoundBox._tempM0);
- Matrix4x4.multiply(bt,OrientedBoundBox._tempM0,out);
- }
- }
- OrientedBoundBox.merge=function(a,b,noMatrixScaleApplied){
- var ae=a.extents;
- var at=a.transformation;
- OrientedBoundBox.getObbtoObbMatrix4x4(a,b,noMatrixScaleApplied,OrientedBoundBox._tempM0);
- b._getLocalCorners(OrientedBoundBox._corners);
- Vector3.transformCoordinate(OrientedBoundBox._corners[0],OrientedBoundBox._tempM0,OrientedBoundBox._corners[0]);
- Vector3.transformCoordinate(OrientedBoundBox._corners[1],OrientedBoundBox._tempM0,OrientedBoundBox._corners[1]);
- Vector3.transformCoordinate(OrientedBoundBox._corners[2],OrientedBoundBox._tempM0,OrientedBoundBox._corners[2]);
- Vector3.transformCoordinate(OrientedBoundBox._corners[3],OrientedBoundBox._tempM0,OrientedBoundBox._corners[3]);
- Vector3.transformCoordinate(OrientedBoundBox._corners[4],OrientedBoundBox._tempM0,OrientedBoundBox._corners[4]);
- Vector3.transformCoordinate(OrientedBoundBox._corners[5],OrientedBoundBox._tempM0,OrientedBoundBox._corners[5]);
- Vector3.transformCoordinate(OrientedBoundBox._corners[6],OrientedBoundBox._tempM0,OrientedBoundBox._corners[6]);
- Vector3.transformCoordinate(OrientedBoundBox._corners[7],OrientedBoundBox._tempM0,OrientedBoundBox._corners[7]);
- Vector3.scale(ae,-1,OrientedBoundBox._boxBound1.min);
- ae.cloneTo(OrientedBoundBox._boxBound1.max);
- BoundBox.createfromPoints(OrientedBoundBox._corners,OrientedBoundBox._boxBound2);
- BoundBox.merge(OrientedBoundBox._boxBound2,OrientedBoundBox._boxBound1,OrientedBoundBox._boxBound3);
- var box3Min=OrientedBoundBox._boxBound3.min;
- var box3Max=OrientedBoundBox._boxBound3.max;
- Vector3.subtract(box3Max,box3Min,OrientedBoundBox._tempV30);
- Vector3.scale(OrientedBoundBox._tempV30,0.5,OrientedBoundBox._tempV30);
- Vector3.add(box3Min,OrientedBoundBox._tempV30,OrientedBoundBox._tempV32);
- Vector3.subtract(box3Max,OrientedBoundBox._tempV32,ae);
- Vector3.transformCoordinate(OrientedBoundBox._tempV32,at,OrientedBoundBox._tempV33);
- }
- __static(OrientedBoundBox,
- ['_tempV30',function(){return this._tempV30=new Vector3();},'_tempV31',function(){return this._tempV31=new Vector3();},'_tempV32',function(){return this._tempV32=new Vector3();},'_tempV33',function(){return this._tempV33=new Vector3();},'_tempV34',function(){return this._tempV34=new Vector3();},'_tempV35',function(){return this._tempV35=new Vector3();},'_tempV36',function(){return this._tempV36=new Vector3();},'_tempM0',function(){return this._tempM0=new Matrix4x4();},'_tempM1',function(){return this._tempM1=new Matrix4x4();},'_corners',function(){return this._corners=/*new vector.<>*/[new Vector3(),new Vector3(),new Vector3(),new Vector3(),new Vector3(),new Vector3(),new Vector3(),new Vector3()];},'_rows1',function(){return this._rows1=/*new vector.<>*/[new Vector3(),new Vector3(),new Vector3()];},'_rows2',function(){return this._rows2=/*new vector.<>*/[new Vector3(),new Vector3(),new Vector3()];},'_ray',function(){return this._ray=new Ray(new Vector3(),new Vector3());},'_boxBound1',function(){return this._boxBound1=new BoundBox(new Vector3(),new Vector3());},'_boxBound2',function(){return this._boxBound2=new BoundBox(new Vector3(),new Vector3());},'_boxBound3',function(){return this._boxBound3=new BoundBox(new Vector3(),new Vector3());},'_vsepAe',function(){return this._vsepAe=new Float32Array();},'_sizeBe',function(){return this._sizeBe=new Float32Array();},'_sizeAe',function(){return this._sizeAe=new Float32Array();}
- ]);
- return OrientedBoundBox;
- })()
- /**
- *@private
- *<code>RenderQuene</code> 类用于实现渲染队列。
- */
- //class laya.d3.core.render.RenderQueue
- var RenderQueue=(function(){
- function RenderQueue(isTransparent){
- /**@private [只读]*/
- //this.isTransparent=false;
- /**@private */
- //this.elements=null;
- /**@private */
- //this.lastTransparentRenderElement=null;
- /**@private */
- //this.lastTransparentBatched=false;
- (isTransparent===void 0)&& (isTransparent=false);
- this.isTransparent=isTransparent;
- this.elements=[];
- }
- __class(RenderQueue,'laya.d3.core.render.RenderQueue');
- var __proto=RenderQueue.prototype;
- /**
- *@private
- */
- __proto._compare=function(left,right){
- var renderQueue=left.material.renderQueue-right.material.renderQueue;
- if (renderQueue===0){
- var sort=this.isTransparent ? right.render._distanceForSort-left.render._distanceForSort :left.render._distanceForSort-right.render._distanceForSort;
- return sort+right.render.sortingFudge-left.render.sortingFudge;
- }else {
- return renderQueue;
- }
- }
- /**
- *@private
- */
- __proto._partitionRenderObject=function(left,right){
- var pivot=this.elements[Math.floor((right+left)/ 2)];
- while (left <=right){
- while (this._compare(this.elements[left],pivot)< 0)
- left++;
- while (this._compare(this.elements[right],pivot)> 0)
- right--;
- if (left < right){
- var temp=this.elements[left];
- this.elements[left]=this.elements[right];
- this.elements[right]=temp;
- left++;
- right--;
- }else if (left===right){
- left++;
- break ;
- }
- }
- return left;
- }
- /**
- *@private
- */
- __proto._quickSort=function(left,right){
- if (this.elements.length > 1){
- var index=this._partitionRenderObject(left,right);
- var leftIndex=index-1;
- if (left < leftIndex)
- this._quickSort(left,leftIndex);
- if (index < right)
- this._quickSort(index,right);
- }
- }
- /**
- *@private
- */
- __proto._render=function(context,isTarget,customShader,replacementTag){
- for (var i=0,n=this.elements.length;i < n;i++)
- this.elements[i]._render(context,isTarget,customShader,replacementTag);
- }
- /**
- *@private
- */
- __proto.clear=function(){
- this.elements.length=0;
- this.lastTransparentRenderElement=null;
- this.lastTransparentBatched=false;
- }
- return RenderQueue;
- })()
- /**
- *...
- *@author ...
- */
- //class laya.d3.core.TextureMode
- var TextureMode=(function(){
- function TextureMode(){}
- __class(TextureMode,'laya.d3.core.TextureMode');
- TextureMode.Stretch=0;
- TextureMode.Tile=1;
- return TextureMode;
- })()
- /**
- *...
- *@author ...
- */
- //class laya.d3.physics.shape.HeightfieldColliderShape
- var HeightfieldColliderShape=(function(){
- function HeightfieldColliderShape(){}
- __class(HeightfieldColliderShape,'laya.d3.physics.shape.HeightfieldColliderShape');
- return HeightfieldColliderShape;
- })()
- /**
- *...
- *@author ...
- */
- //class laya.d3.core.particleShuriKen.module.shape.ShapeUtils
- var ShapeUtils=(function(){
- function ShapeUtils(){}
- __class(ShapeUtils,'laya.d3.core.particleShuriKen.module.shape.ShapeUtils');
- ShapeUtils._randomPointUnitArcCircle=function(arc,out,rand){
- var angle=NaN;
- if (rand)
- angle=rand.getFloat()*arc;
- else
- angle=Math.random()*arc;
- out.x=Math.cos(angle);
- out.y=Math.sin(angle);
- }
- ShapeUtils._randomPointInsideUnitArcCircle=function(arc,out,rand){
- ShapeUtils._randomPointUnitArcCircle(arc,out,rand);
- var range=NaN;
- if (rand)
- range=Math.pow(rand.getFloat(),1.0 / 2.0);
- else
- range=Math.pow(Math.random(),1.0 / 2.0);
- out.x=out.x *range;
- out.y=out.y *range;
- }
- ShapeUtils._randomPointUnitCircle=function(out,rand){
- var angle=NaN;
- if (rand)
- angle=rand.getFloat()*Math.PI *2;
- else
- angle=Math.random()*Math.PI *2;
- out.x=Math.cos(angle);
- out.y=Math.sin(angle);
- }
- ShapeUtils._randomPointInsideUnitCircle=function(out,rand){
- ShapeUtils._randomPointUnitCircle(out);
- var range=NaN;
- if (rand)
- range=Math.pow(rand.getFloat(),1.0 / 2.0);
- else
- range=Math.pow(Math.random(),1.0 / 2.0);
- out.x=out.x *range;
- out.y=out.y *range;
- }
- ShapeUtils._randomPointUnitSphere=function(out,rand){
- var z=NaN;
- var a=NaN;
- if (rand){
- z=out.z=rand.getFloat()*2-1.0;
- a=rand.getFloat()*Math.PI *2;
- }else {
- z=out.z=Math.random()*2-1.0;
- a=Math.random()*Math.PI *2;
- };
- var r=Math.sqrt(1.0-z *z);
- out.x=r *Math.cos(a);
- out.y=r *Math.sin(a);
- }
- ShapeUtils._randomPointInsideUnitSphere=function(out,rand){;
- ShapeUtils._randomPointUnitSphere(out);
- var range=NaN;
- if (rand)
- range=Math.pow(rand.getFloat(),1.0 / 3.0);
- else
- range=Math.pow(Math.random(),1.0 / 3.0);
- out.x=out.x *range;
- out.y=out.y *range;
- out.z=out.z *range;
- }
- ShapeUtils._randomPointInsideHalfUnitBox=function(out,rand){
- if (rand){
- out.x=(rand.getFloat()-0.5);
- out.y=(rand.getFloat()-0.5);
- out.z=(rand.getFloat()-0.5);
- }else {
- out.x=(Math.random()-0.5);
- out.y=(Math.random()-0.5);
- out.z=(Math.random()-0.5);
- }
- }
- return ShapeUtils;
- })()
- /**
- *...
- *@author ...
- */
- //class laya.d3.graphics.VertexElementFormat
- var VertexElementFormat=(function(){
- function VertexElementFormat(){}
- __class(VertexElementFormat,'laya.d3.graphics.VertexElementFormat');
- VertexElementFormat.getElementInfos=function(element){
- var info=VertexElementFormat._elementInfos[element];
- if (info)
- return info;
- else
- throw "VertexElementFormat: this vertexElementFormat is not implement.";
- }
- VertexElementFormat.Single="single";
- VertexElementFormat.Vector2="vector2";
- VertexElementFormat.Vector3="vector3";
- VertexElementFormat.Vector4="vector4";
- VertexElementFormat.Color="color";
- VertexElementFormat.Byte4="byte4";
- VertexElementFormat.Short2="short2";
- VertexElementFormat.Short4="short4";
- VertexElementFormat.NormalizedShort2="normalizedshort2";
- VertexElementFormat.NormalizedShort4="normalizedshort4";
- VertexElementFormat.HalfVector2="halfvector2";
- VertexElementFormat.HalfVector4="halfvector4";
- __static(VertexElementFormat,
- ['_elementInfos',function(){return this._elementInfos={
- "single":[1,/*laya.webgl.WebGLContext.FLOAT*/0x1406,0],
- "vector2":[2,/*laya.webgl.WebGLContext.FLOAT*/0x1406,0],
- "vector3":[3,/*laya.webgl.WebGLContext.FLOAT*/0x1406,0],
- "vector4":[4,/*laya.webgl.WebGLContext.FLOAT*/0x1406,0],
- "color":[4,/*laya.webgl.WebGLContext.FLOAT*/0x1406,0],
- "byte4":[4,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,0],
- "short2":[2,/*laya.webgl.WebGLContext.FLOAT*/0x1406,0],
- "short4":[4,/*laya.webgl.WebGLContext.FLOAT*/0x1406,0],
- "normalizedshort2":[2,/*laya.webgl.WebGLContext.FLOAT*/0x1406,0],
- "normalizedshort4":[4,/*laya.webgl.WebGLContext.FLOAT*/0x1406,0],
- "halfvector2":[2,/*laya.webgl.WebGLContext.FLOAT*/0x1406,0],
- "halfvector4":[4,/*laya.webgl.WebGLContext.FLOAT*/0x1406,0]
- };}
- ]);
- return VertexElementFormat;
- })()
- /**
- *<code>RotationOverLifetime</code> 类用于粒子的生命周期旋转。
- */
- //class laya.d3.core.particleShuriKen.module.RotationOverLifetime
- var RotationOverLifetime=(function(){
- function RotationOverLifetime(angularVelocity){
- /**@private */
- this._angularVelocity=null;
- /**是否启用*/
- this.enbale=false;
- this._angularVelocity=angularVelocity;
- }
- __class(RotationOverLifetime,'laya.d3.core.particleShuriKen.module.RotationOverLifetime');
- var __proto=RotationOverLifetime.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var destRotationOverLifetime=destObject;
- this._angularVelocity.cloneTo(destRotationOverLifetime._angularVelocity);
- destRotationOverLifetime.enbale=this.enbale;
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var destAngularVelocity;
- switch (this._angularVelocity.type){
- case 0:
- if (this._angularVelocity.separateAxes)
- destAngularVelocity=GradientAngularVelocity.createByConstantSeparate(this._angularVelocity.constantSeparate.clone());
- else
- destAngularVelocity=GradientAngularVelocity.createByConstant(this._angularVelocity.constant);
- break ;
- case 1:
- if (this._angularVelocity.separateAxes)
- destAngularVelocity=GradientAngularVelocity.createByGradientSeparate(this._angularVelocity.gradientX.clone(),this._angularVelocity.gradientY.clone(),this._angularVelocity.gradientZ.clone());
- else
- destAngularVelocity=GradientAngularVelocity.createByGradient(this._angularVelocity.gradient.clone());
- break ;
- case 2:
- if (this._angularVelocity.separateAxes)
- destAngularVelocity=GradientAngularVelocity.createByRandomTwoConstantSeparate(this._angularVelocity.constantMinSeparate.clone(),this._angularVelocity.constantMaxSeparate.clone());
- else
- destAngularVelocity=GradientAngularVelocity.createByRandomTwoConstant(this._angularVelocity.constantMin,this._angularVelocity.constantMax);
- break ;
- case 3:
- if (this._angularVelocity.separateAxes)
- 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());
- else
- destAngularVelocity=GradientAngularVelocity.createByRandomTwoGradient(this._angularVelocity.gradientMin.clone(),this._angularVelocity.gradientMax.clone());
- break ;
- };
- var destRotationOverLifetime=/*__JS__ */new this.constructor(destAngularVelocity);
- destRotationOverLifetime.enbale=this.enbale;
- return destRotationOverLifetime;
- }
- /**
- *获取角速度。
- */
- __getset(0,__proto,'angularVelocity',function(){
- return this._angularVelocity;
- });
- return RotationOverLifetime;
- })()
- /**
- *<code>BoundFrustum</code> 类用于创建锥截体。
- */
- //class laya.d3.math.BoundFrustum
- var BoundFrustum=(function(){
- function BoundFrustum(matrix){
- /**4x4矩阵*/
- this._matrix=null;
- /**近平面*/
- this._near=null;
- /**远平面*/
- this._far=null;
- /**左平面*/
- this._left=null;
- /**右平面*/
- this._right=null;
- /**顶平面*/
- this._top=null;
- /**底平面*/
- this._bottom=null;
- this._matrix=matrix;
- this._near=new Plane(new Vector3());
- this._far=new Plane(new Vector3());
- this._left=new Plane(new Vector3());
- this._right=new Plane(new Vector3());
- this._top=new Plane(new Vector3());
- this._bottom=new Plane(new Vector3());
- BoundFrustum._getPlanesFromMatrix(this._matrix,this._near,this._far,this._left,this._right,this._top,this._bottom);
- }
- __class(BoundFrustum,'laya.d3.math.BoundFrustum');
- var __proto=BoundFrustum.prototype;
- /**
- *判断是否与其他锥截体相等。
- *@param other 锥截体。
- */
- __proto.equalsBoundFrustum=function(other){
- return this._matrix.equalsOtherMatrix(other.matrix)
- }
- /**
- *判断是否与其他对象相等。
- *@param obj 对象。
- */
- __proto.equalsObj=function(obj){
- if ((obj instanceof laya.d3.math.BoundFrustum )){
- var bf=obj;
- return this.equalsBoundFrustum(bf);
- }
- return false;
- }
- /**
- *获取锥截体的任意一平面。
- *0:近平面
- *1:远平面
- *2:左平面
- *3:右平面
- *4:顶平面
- *5:底平面
- *@param index 索引。
- */
- __proto.getPlane=function(index){
- switch (index){
- case 0:
- return this._near;
- case 1:
- return this._far;
- case 2:
- return this._left;
- case 3:
- return this._right;
- case 4:
- return this._top;
- case 5:
- return this._bottom;
- default :
- return null;
- }
- }
- /**
- *锥截体的8个顶点。
- *@param corners 返回顶点的输出队列。
- */
- __proto.getCorners=function(corners){
- BoundFrustum._get3PlaneInterPoint(this._near,this._bottom,this._right).cloneTo(corners[0]);
- BoundFrustum._get3PlaneInterPoint(this._near,this._top,this._right).cloneTo(corners[1]);
- BoundFrustum._get3PlaneInterPoint(this._near,this._top,this._left).cloneTo(corners[2]);
- BoundFrustum._get3PlaneInterPoint(this._near,this._bottom,this._left).cloneTo(corners[3]);
- BoundFrustum._get3PlaneInterPoint(this._far,this._bottom,this._right).cloneTo(corners[4]);
- BoundFrustum._get3PlaneInterPoint(this._far,this._top,this._right).cloneTo(corners[5]);
- BoundFrustum._get3PlaneInterPoint(this._far,this._top,this._left).cloneTo(corners[6]);
- BoundFrustum._get3PlaneInterPoint(this._far,this._bottom,this._left).cloneTo(corners[7]);
- }
- /**
- *与点的位置关系。返回-1,包涵;0,相交;1,不相交
- *@param point 点。
- */
- __proto.containsPoint=function(point){
- var result=Plane.PlaneIntersectionType_Front;
- var planeResult=Plane.PlaneIntersectionType_Front;
- for (var i=0;i < 6;i++){
- switch (i){
- case 0:
- planeResult=CollisionUtils.intersectsPlaneAndPoint(this._near,point);
- break ;
- case 1:
- planeResult=CollisionUtils.intersectsPlaneAndPoint(this._far,point);
- break ;
- case 2:
- planeResult=CollisionUtils.intersectsPlaneAndPoint(this._left,point);
- break ;
- case 3:
- planeResult=CollisionUtils.intersectsPlaneAndPoint(this._right,point);
- break ;
- case 4:
- planeResult=CollisionUtils.intersectsPlaneAndPoint(this._top,point);
- break ;
- case 5:
- planeResult=CollisionUtils.intersectsPlaneAndPoint(this._bottom,point);
- break ;
- }
- switch (planeResult){
- case Plane.PlaneIntersectionType_Back:
- return /*laya.d3.math.ContainmentType.Disjoint*/0;
- case Plane.PlaneIntersectionType_Intersecting:
- result=Plane.PlaneIntersectionType_Intersecting;
- break ;
- }
- }
- switch (result){
- case Plane.PlaneIntersectionType_Intersecting:
- return /*laya.d3.math.ContainmentType.Intersects*/2;
- default :
- return /*laya.d3.math.ContainmentType.Contains*/1;
- }
- }
- /**
- *与包围盒的位置关系。返回-1,包涵;0,相交;1,不相交
- *@param box 包围盒。
- */
- __proto.containsBoundBox=function(box){
- var p=BoundFrustum._tempV30,n=BoundFrustum._tempV31;
- var boxMin=box.min;
- var boxMax=box.max;
- var result=/*laya.d3.math.ContainmentType.Contains*/1;
- for (var i=0;i < 6;i++){
- var plane=this.getPlane(i);
- var planeNor=plane.normal;
- if (planeNor.x >=0){
- p.x=boxMax.x;
- n.x=boxMin.x;
- }else {
- p.x=boxMin.x;
- n.x=boxMax.x;
- }
- if (planeNor.y >=0){
- p.y=boxMax.y;
- n.y=boxMin.y;
- }else {
- p.y=boxMin.y;
- n.y=boxMax.y;
- }
- if (planeNor.z >=0){
- p.z=boxMax.z;
- n.z=boxMin.z;
- }else {
- p.z=boxMin.z;
- n.z=boxMax.z;
- }
- if (CollisionUtils.intersectsPlaneAndPoint(plane,p)===Plane.PlaneIntersectionType_Back)
- return /*laya.d3.math.ContainmentType.Disjoint*/0;
- if (CollisionUtils.intersectsPlaneAndPoint(plane,n)===Plane.PlaneIntersectionType_Back)
- result=/*laya.d3.math.ContainmentType.Intersects*/2;
- }
- return result;
- }
- /**
- *与包围球的位置关系。返回-1,包涵;0,相交;1,不相交
- *@param sphere 包围球。
- */
- __proto.containsBoundSphere=function(sphere){
- var result=Plane.PlaneIntersectionType_Front;
- var planeResult=Plane.PlaneIntersectionType_Front;
- for (var i=0;i < 6;i++){
- switch (i){
- case 0:
- planeResult=CollisionUtils.intersectsPlaneAndSphere(this._near,sphere);
- break ;
- case 1:
- planeResult=CollisionUtils.intersectsPlaneAndSphere(this._far,sphere);
- break ;
- case 2:
- planeResult=CollisionUtils.intersectsPlaneAndSphere(this._left,sphere);
- break ;
- case 3:
- planeResult=CollisionUtils.intersectsPlaneAndSphere(this._right,sphere);
- break ;
- case 4:
- planeResult=CollisionUtils.intersectsPlaneAndSphere(this._top,sphere);
- break ;
- case 5:
- planeResult=CollisionUtils.intersectsPlaneAndSphere(this._bottom,sphere);
- break ;
- }
- switch (planeResult){
- case Plane.PlaneIntersectionType_Back:
- return /*laya.d3.math.ContainmentType.Disjoint*/0;
- case Plane.PlaneIntersectionType_Intersecting:
- result=Plane.PlaneIntersectionType_Intersecting;
- break ;
- }
- }
- switch (result){
- case Plane.PlaneIntersectionType_Intersecting:
- return /*laya.d3.math.ContainmentType.Intersects*/2;
- default :
- return /*laya.d3.math.ContainmentType.Contains*/1;
- }
- }
- /**
- *获取顶平面。
- *@return 顶平面。
- */
- __getset(0,__proto,'top',function(){
- return this._top;
- });
- /**
- *设置描述矩阵。
- *@param matrix 描述矩阵。
- */
- /**
- *获取描述矩阵。
- *@return 描述矩阵。
- */
- __getset(0,__proto,'matrix',function(){
- return this._matrix;
- },function(matrix){
- this._matrix=matrix;
- BoundFrustum._getPlanesFromMatrix(this._matrix,this._near,this._far,this._left,this._right,this._top,this._bottom);
- });
- /**
- *获取近平面。
- *@return 近平面。
- */
- __getset(0,__proto,'near',function(){
- return this._near;
- });
- /**
- *获取远平面。
- *@return 远平面。
- */
- __getset(0,__proto,'far',function(){
- return this._far;
- });
- /**
- *获取左平面。
- *@return 左平面。
- */
- __getset(0,__proto,'left',function(){
- return this._left;
- });
- /**
- *获取右平面。
- *@return 右平面。
- */
- __getset(0,__proto,'right',function(){
- return this._right;
- });
- /**
- *获取底平面。
- *@return 底平面。
- */
- __getset(0,__proto,'bottom',function(){
- return this._bottom;
- });
- BoundFrustum._getPlanesFromMatrix=function(m,np,fp,lp,rp,tp,bp){
- var matrixE=m.elements;
- var m11=matrixE[0];
- var m12=matrixE[1];
- var m13=matrixE[2];
- var m14=matrixE[3];
- var m21=matrixE[4];
- var m22=matrixE[5];
- var m23=matrixE[6];
- var m24=matrixE[7];
- var m31=matrixE[8];
- var m32=matrixE[9];
- var m33=matrixE[10];
- var m34=matrixE[11];
- var m41=matrixE[12];
- var m42=matrixE[13];
- var m43=matrixE[14];
- var m44=matrixE[15];
- var nearNorE=np.normal;
- nearNorE.x=m14+m13;
- nearNorE.y=m24+m23;
- nearNorE.z=m34+m33;
- np.distance=m44+m43;
- np.normalize();
- var farNorE=fp.normal;
- farNorE.x=m14-m13;
- farNorE.y=m24-m23;
- farNorE.z=m34-m33;
- fp.distance=m44-m43;
- fp.normalize();
- var leftNorE=lp.normal;
- leftNorE.x=m14+m11;
- leftNorE.y=m24+m21;
- leftNorE.z=m34+m31;
- lp.distance=m44+m41;
- lp.normalize();
- var rightNorE=rp.normal;
- rightNorE.x=m14-m11;
- rightNorE.y=m24-m21;
- rightNorE.z=m34-m31;
- rp.distance=m44-m41;
- rp.normalize();
- var topNorE=tp.normal;
- topNorE.x=m14-m12;
- topNorE.y=m24-m22;
- topNorE.z=m34-m32;
- tp.distance=m44-m42;
- tp.normalize();
- var bottomNorE=bp.normal;
- bottomNorE.x=m14+m12;
- bottomNorE.y=m24+m22;
- bottomNorE.z=m34+m32;
- bp.distance=m44+m42;
- bp.normalize();
- }
- BoundFrustum._get3PlaneInterPoint=function(p1,p2,p3){
- var p1Nor=p1.normal;
- var p2Nor=p2.normal;
- var p3Nor=p3.normal;
- Vector3.cross(p2Nor,p3Nor,BoundFrustum._tempV30);
- Vector3.cross(p3Nor,p1Nor,BoundFrustum._tempV31);
- Vector3.cross(p1Nor,p2Nor,BoundFrustum._tempV32);
- var a=Vector3.dot(p1Nor,BoundFrustum._tempV30);
- var b=Vector3.dot(p2Nor,BoundFrustum._tempV31);
- var c=Vector3.dot(p3Nor,BoundFrustum._tempV32);
- Vector3.scale(BoundFrustum._tempV30,-p1.distance / a,BoundFrustum._tempV33);
- Vector3.scale(BoundFrustum._tempV31,-p2.distance / b,BoundFrustum._tempV34);
- Vector3.scale(BoundFrustum._tempV32,-p3.distance / c,BoundFrustum._tempV35);
- Vector3.add(BoundFrustum._tempV33,BoundFrustum._tempV34,BoundFrustum._tempV36);
- Vector3.add(BoundFrustum._tempV35,BoundFrustum._tempV36,BoundFrustum._tempV37);
- var v=BoundFrustum._tempV37;
- return v;
- }
- __static(BoundFrustum,
- ['_tempV30',function(){return this._tempV30=new Vector3();},'_tempV31',function(){return this._tempV31=new Vector3();},'_tempV32',function(){return this._tempV32=new Vector3();},'_tempV33',function(){return this._tempV33=new Vector3();},'_tempV34',function(){return this._tempV34=new Vector3();},'_tempV35',function(){return this._tempV35=new Vector3();},'_tempV36',function(){return this._tempV36=new Vector3();},'_tempV37',function(){return this._tempV37=new Vector3();}
- ]);
- return BoundFrustum;
- })()
- /**
- *@private
- *<code>KeyframeNodeOwner</code> 类用于保存帧节点的拥有者信息。
- */
- //class laya.d3.component.KeyframeNodeOwner
- var KeyframeNodeOwner=(function(){
- function KeyframeNodeOwner(){
- /**@private */
- this.indexInList=-1;
- /**@private */
- this.referenceCount=0;
- /**@private */
- this.updateMark=-1;
- /**@private */
- this.type=-1;
- /**@private */
- this.fullPath=null;
- /**@private */
- this.propertyOwner=null;
- /**@private */
- this.property=null;
- /**@private */
- this.defaultValue=null;
- /**@private */
- this.crossFixedValue=null;
- }
- __class(KeyframeNodeOwner,'laya.d3.component.KeyframeNodeOwner');
- var __proto=KeyframeNodeOwner.prototype;
- /**
- *@private
- */
- __proto.saveCrossFixedValue=function(){
- var pro=this.propertyOwner;
- if (pro){
- switch (this.type){
- case 0:;
- var proPat=this.property;
- var m=proPat.length-1;
- for (var j=0;j < m;j++){
- pro=pro[proPat[j]];
- if (!pro)
- break ;
- }
- this.crossFixedValue=pro[proPat[m]];
- break ;
- case 1:;
- var locPos=pro.localPosition;
- this.crossFixedValue || (this.crossFixedValue=new Vector3());
- this.crossFixedValue.x=locPos.x;
- this.crossFixedValue.y=locPos.y;
- this.crossFixedValue.z=locPos.z;
- break ;
- case 2:;
- var locRot=pro.localRotation;
- this.crossFixedValue || (this.crossFixedValue=new Quaternion());
- this.crossFixedValue.x=locRot.x;
- this.crossFixedValue.y=locRot.y;
- this.crossFixedValue.z=locRot.z;
- this.crossFixedValue.w=locRot.w;
- break ;
- case 3:;
- var locSca=pro.localScale;
- this.crossFixedValue || (this.crossFixedValue=new Vector3());
- this.crossFixedValue.x=locSca.x;
- this.crossFixedValue.y=locSca.y;
- this.crossFixedValue.z=locSca.z;
- break ;
- case 4:;
- var locEul=pro.localRotationEuler;
- this.crossFixedValue || (this.crossFixedValue=new Vector3());
- this.crossFixedValue.x=locEul.x;
- this.crossFixedValue.y=locEul.y;
- this.crossFixedValue.z=locEul.z;
- break ;
- default :
- throw "Animator:unknown type.";
- }
- }
- }
- return KeyframeNodeOwner;
- })()
- /**
- *@private
- *<code>FrustumCulling</code> 类用于裁剪。
- */
- //class laya.d3.graphics.FrustumCulling
- var FrustumCulling=(function(){
- /**
- *创建一个 <code>FrustumCulling</code> 实例。
- */
- function FrustumCulling(){}
- __class(FrustumCulling,'laya.d3.graphics.FrustumCulling');
- FrustumCulling.__init__=function(){
- if (Render.supportWebGLPlusCulling){
- FrustumCulling._cullingBufferLength=0;
- FrustumCulling._cullingBuffer=new Float32Array(4096);
- }
- }
- FrustumCulling._drawTraversalCullingBound=function(renderList,debugTool){
- var validCount=renderList.length;
- var renders=renderList.elements;
- for (var i=0,n=renderList.length;i < n;i++){
- var color=FrustumCulling._tempColor0;
- color.r=0;
- color.g=1;
- color.b=0;
- color.a=1;
- Utils3D._drawBound(debugTool,(renders [i]).bounds._getBoundBox(),color);
- }
- }
- FrustumCulling._traversalCulling=function(camera,scene,context,renderList){
- var validCount=renderList.length;
- var renders=renderList.elements;
- var boundFrustum=camera.boundFrustum;
- var camPos=camera._transform.position;
- for (var i=0;i < validCount;i++){
- var render=renders [i];
- if (camera._isLayerVisible(render._owner._layer)&& render._enable){
- Stat.frustumCulling++;
- if (!camera.useOcclusionCulling || render._needRender(boundFrustum)){
- render._visible=true;
- var bounds=render.bounds;
- render._distanceForSort=Vector3.distance(bounds.getCenter(),camPos);
- var elements=render._renderElements;
- for (var j=0,m=elements.length;j < m;j++){
- var element=elements[j];
- var renderQueue=scene._getRenderQueue(element.material.renderQueue);
- if (renderQueue.isTransparent)
- element.addToTransparentRenderQueue(context,renderQueue);
- else
- element.addToOpaqueRenderQueue(context,renderQueue);
- }
- }else {
- render._visible=false;
- }
- }else {
- render._visible=false;
- }
- }
- }
- FrustumCulling.renderObjectCulling=function(camera,scene,context,renderList){
- var i=0,n=0,j=0,m=0;
- var opaqueQueue=scene._opaqueQueue;
- var transparentQueue=scene._transparentQueue;
- opaqueQueue.clear();
- transparentQueue.clear();
- var staticBatchManagers=StaticBatchManager._managers;
- for (i=0,n=staticBatchManagers.length;i < n;i++)
- staticBatchManagers[i]._clear();
- var dynamicBatchManagers=DynamicBatchManager._managers;
- for (i=0,n=dynamicBatchManagers.length;i < n;i++)
- dynamicBatchManagers[i]._clear();
- var octree=scene._octree;
- if (octree){
- octree.updateMotionObjects();
- octree.shrinkRootIfPossible();
- octree.getCollidingWithFrustum(context);
- }else {
- FrustumCulling._traversalCulling(camera,scene,context,renderList);
- }
- if (Laya3D._config.debugFrustumCulling){
- var debugTool=scene._debugTool;
- debugTool.clear();
- if (octree){
- octree.drawAllBounds(debugTool);
- octree.drawAllObjects(debugTool);
- }else {
- FrustumCulling._drawTraversalCullingBound(renderList,debugTool);
- }
- };
- var count=opaqueQueue.elements.length;
- (count > 0)&& (opaqueQueue._quickSort(0,count-1));
- count=transparentQueue.elements.length;
- (count > 0)&& (transparentQueue._quickSort(0,count-1));
- }
- FrustumCulling.renderObjectCullingNative=function(camera,scene,context,renderList){
- var i=0,n=0,j=0,m=0;
- var opaqueQueue=scene._opaqueQueue;
- var transparentQueue=scene._transparentQueue;
- opaqueQueue.clear();
- transparentQueue.clear();
- var staticBatchManagers=StaticBatchManager._managers;
- for (i=0,n=staticBatchManagers.length;i < n;i++)
- staticBatchManagers[i]._clear();
- var dynamicBatchManagers=DynamicBatchManager._managers;
- for (i=0,n=dynamicBatchManagers.length;i < n;i++)
- dynamicBatchManagers[i]._clear();
- var validCount=renderList.length;
- var renders=renderList.elements;
- for (i=0;i < validCount;i++){
- (renders [i]).bounds;
- };
- var boundFrustum=camera.boundFrustum;
- FrustumCulling.cullingNative(camera._boundFrustumBuffer,FrustumCulling._cullingBuffer,scene._cullingBufferIndices,validCount,scene._cullingBufferResult);
- var camPos=context.camera._transform.position;
- for (i=0;i < validCount;i++){
- var render=renders [i];
- if (camera._isLayerVisible(render._owner._layer)&& render._enable && scene._cullingBufferResult[i]){
- render._visible=true;
- render._distanceForSort=Vector3.distance(render.bounds.getCenter(),camPos);
- var elements=render._renderElements;
- for (j=0,m=elements.length;j < m;j++){
- var element=elements[j];
- var renderQueue=scene._getRenderQueue(element.material.renderQueue);
- if (renderQueue.isTransparent)
- element.addToTransparentRenderQueue(context,renderQueue);
- else
- element.addToOpaqueRenderQueue(context,renderQueue);
- }
- }else {
- render._visible=false;
- }
- };
- var count=opaqueQueue.elements.length;
- (count > 0)&& (opaqueQueue._quickSort(0,count-1));
- count=transparentQueue.elements.length;
- (count > 0)&& (transparentQueue._quickSort(0,count-1));
- }
- FrustumCulling.cullingNative=function(boundFrustumBuffer,cullingBuffer,cullingBufferIndices,cullingCount,cullingBufferResult){
- return LayaGL.instance.culling(boundFrustumBuffer,cullingBuffer,cullingBufferIndices,cullingCount,cullingBufferResult);
- }
- FrustumCulling._cullingBufferLength=0;
- FrustumCulling._cullingBuffer=null;
- __static(FrustumCulling,
- ['_tempVector3',function(){return this._tempVector3=new Vector3();},'_tempColor0',function(){return this._tempColor0=new Color();}
- ]);
- return FrustumCulling;
- })()
- /**
- *<code>AnimatorControllerLayer</code> 类用于创建动画控制器层。
- */
- //class laya.d3.component.AnimatorControllerLayer
- var AnimatorControllerLayer=(function(){
- function AnimatorControllerLayer(name){
- /**@private */
- this._defaultState=null;
- /**@private 0:常规播放、1:动态融合播放、2:固定融合播放*/
- //this._playType=0;
- /**@private */
- //this._crossDuration=NaN;
- /**@private */
- //this._crossPlayState=null;
- /**@private */
- //this._crossMark=0;
- /**@private */
- //this._crossNodesOwnersCount=0;
- /**@private */
- //this._crossNodesOwners=null;
- /**@private */
- //this._crossNodesOwnersIndicesMap=null;
- /**@private */
- //this._srcCrossClipNodeIndices=null;
- /**@private */
- //this._destCrossClipNodeIndices=null;
- /**@private */
- //this._currentPlayState=null;
- /**@private */
- this._statesMap={};
- /**@private */
- //this._states=null;
- /**@private */
- //this._playStateInfo=null;
- /**@private */
- //this._crossPlayStateInfo=null;
- /**层的名称。*/
- //this.name=null;
- /**名称。*/
- //this.blendingMode=0;
- /**权重。*/
- //this.defaultWeight=0;
- /**激活时是否自动播放*/
- this.playOnWake=true;
- this._playType=-1;
- this._crossMark=0;
- this._crossDuration=-1;
- this._crossNodesOwnersIndicesMap={};
- this._crossNodesOwnersCount=0;
- this._crossNodesOwners=[];
- this._currentPlayState=null;
- this._states=[];
- this._playStateInfo=new AnimatorPlayState();
- this._crossPlayStateInfo=new AnimatorPlayState();
- this._srcCrossClipNodeIndices=[];
- this._destCrossClipNodeIndices=[];
- this.name=name;
- this.defaultWeight=1.0;
- this.blendingMode=laya.d3.component.AnimatorControllerLayer.BLENDINGMODE_OVERRIDE;
- }
- __class(AnimatorControllerLayer,'laya.d3.component.AnimatorControllerLayer');
- var __proto=AnimatorControllerLayer.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *@private
- */
- __proto.getAnimatorState=function(name){
- var state=this._statesMap[name];
- return state ? state :null;
- }
- /**
- *@private
- */
- __proto.destroy=function(){
- this._statesMap=null;
- this._states=null;
- this._playStateInfo=null;
- this._crossPlayStateInfo=null;
- this._defaultState=null;
- }
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var dest=destObject;
- dest.name=this.name;
- dest.blendingMode=this.blendingMode;
- dest.defaultWeight=this.defaultWeight;
- dest.playOnWake=this.playOnWake;
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var dest=/*__JS__ */new this.constructor();
- this.cloneTo(dest);
- return dest;
- }
- /**
- *设置默认动画状态。
- *@param value 默认动画状态。
- */
- /**
- *获取默认动画状态。
- *@return 默认动画状态。
- */
- __getset(0,__proto,'defaultState',function(){
- return this._defaultState;
- },function(value){
- this._defaultState=value;
- this._statesMap[value.name]=value;
- });
- AnimatorControllerLayer.BLENDINGMODE_OVERRIDE=0;
- AnimatorControllerLayer.BLENDINGMODE_ADDTIVE=1;
- return AnimatorControllerLayer;
- })()
- /**
- *<code>Collision</code> 类用于检测碰撞。
- */
- //class laya.d3.math.CollisionUtils
- var CollisionUtils=(function(){
- /**
- *创建一个 <code>Collision</code> 实例。
- */
- function CollisionUtils(){}
- __class(CollisionUtils,'laya.d3.math.CollisionUtils');
- CollisionUtils.distancePlaneToPoint=function(plane,point){
- var dot=Vector3.dot(plane.normal,point);
- return dot-plane.distance;
- }
- CollisionUtils.distanceBoxToPoint=function(box,point){
- var boxMin=box.min;
- var boxMineX=boxMin.x;
- var boxMineY=boxMin.y;
- var boxMineZ=boxMin.z;
- var boxMax=box.max;
- var boxMaxeX=boxMax.x;
- var boxMaxeY=boxMax.y;
- var boxMaxeZ=boxMax.z;
- var pointeX=point.x;
- var pointeY=point.y;
- var pointeZ=point.z;
- var distance=0;
- if (pointeX < boxMineX)
- distance+=(boxMineX-pointeX)*(boxMineX-pointeX);
- if (pointeX > boxMaxeX)
- distance+=(boxMaxeX-pointeX)*(boxMaxeX-pointeX);
- if (pointeY < boxMineY)
- distance+=(boxMineY-pointeY)*(boxMineY-pointeY);
- if (pointeY > boxMaxeY)
- distance+=(boxMaxeY-pointeY)*(boxMaxeY-pointeY);
- if (pointeZ < boxMineZ)
- distance+=(boxMineZ-pointeZ)*(boxMineZ-pointeZ);
- if (pointeZ > boxMaxeZ)
- distance+=(boxMaxeZ-pointeZ)*(boxMaxeZ-pointeZ);
- return Math.sqrt(distance);
- }
- CollisionUtils.distanceBoxToBox=function(box1,box2){
- var box1Mine=box1.min;
- var box1MineX=box1Mine.x;
- var box1MineY=box1Mine.y;
- var box1MineZ=box1Mine.z;
- var box1Maxe=box1.max;
- var box1MaxeX=box1Maxe.x;
- var box1MaxeY=box1Maxe.y;
- var box1MaxeZ=box1Maxe.z;
- var box2Mine=box2.min;
- var box2MineX=box2Mine.x;
- var box2MineY=box2Mine.y;
- var box2MineZ=box2Mine.z;
- var box2Maxe=box2.max;
- var box2MaxeX=box2Maxe.x;
- var box2MaxeY=box2Maxe.y;
- var box2MaxeZ=box2Maxe.z;
- var distance=0;
- var delta=NaN;
- if (box1MineX > box2MaxeX){
- delta=box1MineX-box2MaxeX;
- distance+=delta *delta;
- }else if (box2MineX > box1MaxeX){
- delta=box2MineX-box1MaxeX;
- distance+=delta *delta;
- }
- if (box1MineY > box2MaxeY){
- delta=box1MineY-box2MaxeY;
- distance+=delta *delta;
- }else if (box2MineY > box1MaxeY){
- delta=box2MineY-box1MaxeY;
- distance+=delta *delta;
- }
- if (box1MineZ > box2MaxeZ){
- delta=box1MineZ-box2MaxeZ;
- distance+=delta *delta;
- }else if (box2MineZ > box1MaxeZ){
- delta=box2MineZ-box1MaxeZ;
- distance+=delta *delta;
- }
- return Math.sqrt(distance);
- }
- CollisionUtils.distanceSphereToPoint=function(sphere,point){
- var distance=Math.sqrt(Vector3.distanceSquared(sphere.center,point));
- distance-=sphere.radius;
- return Math.max(distance,0);
- }
- CollisionUtils.distanceSphereToSphere=function(sphere1,sphere2){
- var distance=Math.sqrt(Vector3.distanceSquared(sphere1.center,sphere2.center));
- distance-=sphere1.radius+sphere2.radius;
- return Math.max(distance,0);
- }
- CollisionUtils.intersectsRayAndTriangleRD=function(ray,vertex1,vertex2,vertex3,out){
- var rayO=ray.origin;
- var rayOeX=rayO.x;
- var rayOeY=rayO.y;
- var rayOeZ=rayO.z;
- var rayD=ray.direction;
- var rayDeX=rayD.x;
- var rayDeY=rayD.y;
- var rayDeZ=rayD.z;
- var v1eX=vertex1.x;
- var v1eY=vertex1.y;
- var v1eZ=vertex1.z;
- var v2eX=vertex2.x;
- var v2eY=vertex2.y;
- var v2eZ=vertex2.z;
- var v3eX=vertex3.x;
- var v3eY=vertex3.y;
- var v3eZ=vertex3.z;
- var _tempV30eX=CollisionUtils._tempV30.x;
- var _tempV30eY=CollisionUtils._tempV30.y;
- var _tempV30eZ=CollisionUtils._tempV30.z;
- _tempV30eX=v2eX-v1eX;
- _tempV30eY=v2eY-v1eY;
- _tempV30eZ=v2eZ-v1eZ;
- var _tempV31eX=CollisionUtils._tempV31.x;
- var _tempV31eY=CollisionUtils._tempV31.y;
- var _tempV31eZ=CollisionUtils._tempV31.z;
- _tempV31eX=v3eX-v1eX;
- _tempV31eY=v3eY-v1eY;
- _tempV31eZ=v3eZ-v1eZ;
- var _tempV32eX=CollisionUtils._tempV32.x;
- var _tempV32eY=CollisionUtils._tempV32.y;
- var _tempV32eZ=CollisionUtils._tempV32.z;
- _tempV32eX=(rayDeY *_tempV31eZ)-(rayDeZ *_tempV31eY);
- _tempV32eY=(rayDeZ *_tempV31eX)-(rayDeX *_tempV31eZ);
- _tempV32eZ=(rayDeX *_tempV31eY)-(rayDeY *_tempV31eX);
- var determinant=(_tempV30eX *_tempV32eX)+(_tempV30eY *_tempV32eY)+(_tempV30eZ *_tempV32eZ);
- if (MathUtils3D.isZero(determinant)){
- out=0;
- return false;
- };
- var inversedeterminant=1 / determinant;
- var _tempV33eX=CollisionUtils._tempV33.x;
- var _tempV33eY=CollisionUtils._tempV33.y;
- var _tempV33eZ=CollisionUtils._tempV33.z;
- _tempV33eX=rayOeX-v1eX;
- _tempV33eY=rayOeY-v1eY;
- _tempV33eZ=rayOeZ-v1eZ;
- var triangleU=(_tempV33eX *_tempV32eX)+(_tempV33eY *_tempV32eY)+(_tempV33eZ *_tempV32eZ);
- triangleU *=inversedeterminant;
- if (triangleU < 0 || triangleU > 1){
- out=0;
- return false;
- };
- var _tempV34eX=CollisionUtils._tempV34.x;
- var _tempV34eY=CollisionUtils._tempV34.y;
- var _tempV34eZ=CollisionUtils._tempV34.z;
- _tempV34eX=(_tempV33eY *_tempV30eZ)-(_tempV33eZ *_tempV30eY);
- _tempV34eY=(_tempV33eZ *_tempV30eX)-(_tempV33eX *_tempV30eZ);
- _tempV34eZ=(_tempV33eX *_tempV30eY)-(_tempV33eY *_tempV30eX);
- var triangleV=((rayDeX *_tempV34eX)+(rayDeY *_tempV34eY))+(rayDeZ *_tempV34eZ);
- triangleV *=inversedeterminant;
- if (triangleV < 0 || triangleU+triangleV > 1){
- out=0;
- return false;
- };
- var raydistance=(_tempV31eX *_tempV34eX)+(_tempV31eY *_tempV34eY)+(_tempV31eZ *_tempV34eZ);
- raydistance *=inversedeterminant;
- if (raydistance < 0){
- out=0;
- return false;
- }
- out=raydistance;
- return true;
- }
- CollisionUtils.intersectsRayAndTriangleRP=function(ray,vertex1,vertex2,vertex3,out){
- var distance=NaN;
- if (!CollisionUtils.intersectsRayAndTriangleRD(ray,vertex1,vertex2,vertex3,distance)){
- out=Vector3._ZERO;
- return false;
- }
- Vector3.scale(ray.direction,distance,CollisionUtils._tempV30);
- Vector3.add(ray.origin,CollisionUtils._tempV30,out);
- return true;
- }
- CollisionUtils.intersectsRayAndPoint=function(ray,point){
- Vector3.subtract(ray.origin,point,CollisionUtils._tempV30);
- var b=Vector3.dot(CollisionUtils._tempV30,ray.direction);
- var c=Vector3.dot(CollisionUtils._tempV30,CollisionUtils._tempV30)-MathUtils3D.zeroTolerance;
- if (c > 0 && b > 0)
- return false;
- var discriminant=b *b-c;
- if (discriminant < 0)
- return false;
- return true;
- }
- CollisionUtils.intersectsRayAndRay=function(ray1,ray2,out){
- var ray1o=ray1.origin;
- var ray1oeX=ray1o.x;
- var ray1oeY=ray1o.y;
- var ray1oeZ=ray1o.z;
- var ray1d=ray1.direction;
- var ray1deX=ray1d.x;
- var ray1deY=ray1d.y;
- var ray1deZ=ray1d.z;
- var ray2o=ray2.origin;
- var ray2oeX=ray2o.x;
- var ray2oeY=ray2o.y;
- var ray2oeZ=ray2o.z;
- var ray2d=ray2.direction;
- var ray2deX=ray2d.x;
- var ray2deY=ray2d.y;
- var ray2deZ=ray2d.z;
- Vector3.cross(ray1d,ray2d,CollisionUtils._tempV30);
- var tempV3=CollisionUtils._tempV30;
- var denominator=Vector3.scalarLength(CollisionUtils._tempV30);
- if (MathUtils3D.isZero(denominator)){
- if (MathUtils3D.nearEqual(ray2oeX,ray1oeX)&& MathUtils3D.nearEqual(ray2oeY,ray1oeY)&& MathUtils3D.nearEqual(ray2oeZ,ray1oeZ)){
- out=Vector3._ZERO;
- return true;
- }
- }
- denominator=denominator *denominator;
- var m11=ray2oeX-ray1oeX;
- var m12=ray2oeY-ray1oeY;
- var m13=ray2oeZ-ray1oeZ;
- var m21=ray2deX;
- var m22=ray2deY;
- var m23=ray2deZ;
- var m31=tempV3.x;
- var m32=tempV3.y;
- var m33=tempV3.z;
- var dets=m11 *m22 *m33+m12 *m23 *m31+m13 *m21 *m32-m11 *m23 *m32-m12 *m21 *m33-m13 *m22 *m31;
- m21=ray1deX;
- m22=ray1deY;
- m23=ray1deZ;
- var dett=m11 *m22 *m33+m12 *m23 *m31+m13 *m21 *m32-m11 *m23 *m32-m12 *m21 *m33-m13 *m22 *m31;
- var s=dets / denominator;
- var t=dett / denominator;
- Vector3.scale(ray1d,s,CollisionUtils._tempV30);
- Vector3.scale(ray2d,s,CollisionUtils._tempV31);
- Vector3.add(ray1o,CollisionUtils._tempV30,CollisionUtils._tempV32);
- Vector3.add(ray2o,CollisionUtils._tempV31,CollisionUtils._tempV33);
- var point1e=CollisionUtils._tempV32;
- var point2e=CollisionUtils._tempV33;
- if (!MathUtils3D.nearEqual(point2e.x,point1e.x)|| !MathUtils3D.nearEqual(point2e.y,point1e.y)|| !MathUtils3D.nearEqual(point2e.z,point1e.z)){
- out=Vector3._ZERO;
- return false;
- }
- out=CollisionUtils._tempV32;
- return true;
- }
- CollisionUtils.intersectsPlaneAndTriangle=function(plane,vertex1,vertex2,vertex3){
- var test1=CollisionUtils.intersectsPlaneAndPoint(plane,vertex1);
- var test2=CollisionUtils.intersectsPlaneAndPoint(plane,vertex2);
- var test3=CollisionUtils.intersectsPlaneAndPoint(plane,vertex3);
- if (test1==Plane.PlaneIntersectionType_Front && test2==Plane.PlaneIntersectionType_Front && test3==Plane.PlaneIntersectionType_Front)
- return Plane.PlaneIntersectionType_Front;
- if (test1==Plane.PlaneIntersectionType_Back && test2==Plane.PlaneIntersectionType_Back && test3==Plane.PlaneIntersectionType_Back)
- return Plane.PlaneIntersectionType_Back;
- return Plane.PlaneIntersectionType_Intersecting;
- }
- CollisionUtils.intersectsRayAndPlaneRD=function(ray,plane,out){
- var planeNor=plane.normal;
- var direction=Vector3.dot(planeNor,ray.direction);
- if (MathUtils3D.isZero(direction)){
- out=0;
- return false;
- };
- var position=Vector3.dot(planeNor,ray.origin);
- out=(-plane.distance-position)/ direction;
- if (out < 0){
- out=0;
- return false;
- }
- return true;
- }
- CollisionUtils.intersectsRayAndPlaneRP=function(ray,plane,out){
- var distance=NaN;
- if (!CollisionUtils.intersectsRayAndPlaneRD(ray,plane,distance)){
- out=Vector3._ZERO;
- return false;
- }
- Vector3.scale(ray.direction,distance,CollisionUtils._tempV30);
- Vector3.add(ray.origin,CollisionUtils._tempV30,CollisionUtils._tempV31);
- out=CollisionUtils._tempV31;
- return true;
- }
- CollisionUtils.intersectsRayAndBoxRD=function(ray,box){
- var rayoe=ray.origin;
- var rayoeX=rayoe.x;
- var rayoeY=rayoe.y;
- var rayoeZ=rayoe.z;
- var rayde=ray.direction;
- var raydeX=rayde.x;
- var raydeY=rayde.y;
- var raydeZ=rayde.z;
- var boxMine=box.min;
- var boxMineX=boxMine.x;
- var boxMineY=boxMine.y;
- var boxMineZ=boxMine.z;
- var boxMaxe=box.max;
- var boxMaxeX=boxMaxe.x;
- var boxMaxeY=boxMaxe.y;
- var boxMaxeZ=boxMaxe.z;
- var out=0;
- var tmax=MathUtils3D.MaxValue;
- if (MathUtils3D.isZero(raydeX)){
- if (rayoeX < boxMineX || rayoeX > boxMaxeX){
- return-1;
- }
- }else {
- var inverse=1 / raydeX;
- var t1=(boxMineX-rayoeX)*inverse;
- var t2=(boxMaxeX-rayoeX)*inverse;
- if (t1 > t2){
- var temp=t1;
- t1=t2;
- t2=temp;
- }
- out=Math.max(t1,out);
- tmax=Math.min(t2,tmax);
- if (out > tmax){
- return-1;
- }
- }
- if (MathUtils3D.isZero(raydeY)){
- if (rayoeY < boxMineY || rayoeY > boxMaxeY){
- return-1;
- }
- }else {
- var inverse1=1 / raydeY;
- var t3=(boxMineY-rayoeY)*inverse1;
- var t4=(boxMaxeY-rayoeY)*inverse1;
- if (t3 > t4){
- var temp1=t3;
- t3=t4;
- t4=temp1;
- }
- out=Math.max(t3,out);
- tmax=Math.min(t4,tmax);
- if (out > tmax){
- return-1;
- }
- }
- if (MathUtils3D.isZero(raydeZ)){
- if (rayoeZ < boxMineZ || rayoeZ > boxMaxeZ){
- return-1;
- }
- }else {
- var inverse2=1 / raydeZ;
- var t5=(boxMineZ-rayoeZ)*inverse2;
- var t6=(boxMaxeZ-rayoeZ)*inverse2;
- if (t5 > t6){
- var temp2=t5;
- t5=t6;
- t6=temp2;
- }
- out=Math.max(t5,out);
- tmax=Math.min(t6,tmax);
- if (out > tmax){
- return-1;
- }
- }
- return out;
- }
- CollisionUtils.intersectsRayAndBoxRP=function(ray,box,out){
- var distance=CollisionUtils.intersectsRayAndBoxRD(ray,box);
- if (distance===-1){
- Vector3._ZERO.cloneTo(out);
- return distance;
- }
- Vector3.scale(ray.direction,distance,CollisionUtils._tempV30);
- Vector3.add(ray.origin,CollisionUtils._tempV30,CollisionUtils._tempV31);
- CollisionUtils._tempV31.cloneTo(out);
- return distance;
- }
- CollisionUtils.intersectsRayAndSphereRD=function(ray,sphere){
- var sphereR=sphere.radius;
- Vector3.subtract(ray.origin,sphere.center,CollisionUtils._tempV30);
- var b=Vector3.dot(CollisionUtils._tempV30,ray.direction);
- var c=Vector3.dot(CollisionUtils._tempV30,CollisionUtils._tempV30)-(sphereR *sphereR);
- if (c > 0 && b > 0){
- return-1;
- };
- var discriminant=b *b-c;
- if (discriminant < 0){
- return-1;
- };
- var distance=-b-Math.sqrt(discriminant);
- if (distance < 0)
- distance=0;
- return distance;
- }
- CollisionUtils.intersectsRayAndSphereRP=function(ray,sphere,out){
- var distance=CollisionUtils.intersectsRayAndSphereRD(ray,sphere);
- if (distance===-1){
- Vector3._ZERO.cloneTo(out);
- return distance;
- }
- Vector3.scale(ray.direction,distance,CollisionUtils._tempV30);
- Vector3.add(ray.origin,CollisionUtils._tempV30,CollisionUtils._tempV31);
- CollisionUtils._tempV31.cloneTo(out);
- return distance;
- }
- CollisionUtils.intersectsSphereAndTriangle=function(sphere,vertex1,vertex2,vertex3){
- var sphereC=sphere.center;
- var sphereR=sphere.radius;
- CollisionUtils.closestPointPointTriangle(sphereC,vertex1,vertex2,vertex3,CollisionUtils._tempV30);
- Vector3.subtract(CollisionUtils._tempV30,sphereC,CollisionUtils._tempV31);
- var dot=Vector3.dot(CollisionUtils._tempV31,CollisionUtils._tempV31);
- return dot <=sphereR *sphereR;
- }
- CollisionUtils.intersectsPlaneAndPoint=function(plane,point){
- var distance=Vector3.dot(plane.normal,point)+plane.distance;
- if (distance > 0)
- return Plane.PlaneIntersectionType_Front;
- if (distance < 0)
- return Plane.PlaneIntersectionType_Back;
- return Plane.PlaneIntersectionType_Intersecting;
- }
- CollisionUtils.intersectsPlaneAndPlane=function(plane1,plane2){
- Vector3.cross(plane1.normal,plane2.normal,CollisionUtils._tempV30);
- var denominator=Vector3.dot(CollisionUtils._tempV30,CollisionUtils._tempV30);
- if (MathUtils3D.isZero(denominator))
- return false;
- return true;
- }
- CollisionUtils.intersectsPlaneAndPlaneRL=function(plane1,plane2,line){
- var plane1nor=plane1.normal;
- var plane2nor=plane2.normal;
- Vector3.cross(plane1nor,plane2nor,CollisionUtils._tempV34);
- var denominator=Vector3.dot(CollisionUtils._tempV34,CollisionUtils._tempV34);
- if (MathUtils3D.isZero(denominator))
- return false;
- Vector3.scale(plane2nor,plane1.distance,CollisionUtils._tempV30);
- Vector3.scale(plane1nor,plane2.distance,CollisionUtils._tempV31);
- Vector3.subtract(CollisionUtils._tempV30,CollisionUtils._tempV31,CollisionUtils._tempV32);
- Vector3.cross(CollisionUtils._tempV32,CollisionUtils._tempV34,CollisionUtils._tempV33);
- Vector3.normalize(CollisionUtils._tempV34,CollisionUtils._tempV34);
- line=new Ray(CollisionUtils._tempV33,CollisionUtils._tempV34);
- return true;
- }
- CollisionUtils.intersectsPlaneAndBox=function(plane,box){
- var planeD=plane.distance;
- var planeNor=plane.normal;
- var planeNoreX=planeNor.x;
- var planeNoreY=planeNor.y;
- var planeNoreZ=planeNor.z;
- var boxMine=box.min;
- var boxMineX=boxMine.x;
- var boxMineY=boxMine.y;
- var boxMineZ=boxMine.z;
- var boxMaxe=box.max;
- var boxMaxeX=boxMaxe.x;
- var boxMaxeY=boxMaxe.y;
- var boxMaxeZ=boxMaxe.z;
- CollisionUtils._tempV30.x=(planeNoreX > 0)? boxMineX :boxMaxeX;
- CollisionUtils._tempV30.y=(planeNoreY > 0)? boxMineY :boxMaxeY;
- CollisionUtils._tempV30.z=(planeNoreZ > 0)? boxMineZ :boxMaxeZ;
- CollisionUtils._tempV31.x=(planeNoreX > 0)? boxMaxeX :boxMineX;
- CollisionUtils._tempV31.y=(planeNoreY > 0)? boxMaxeY :boxMineY;
- CollisionUtils._tempV31.z=(planeNoreZ > 0)? boxMaxeZ :boxMineZ;
- var distance=Vector3.dot(planeNor,CollisionUtils._tempV30);
- if (distance+planeD > 0)
- return Plane.PlaneIntersectionType_Front;
- distance=Vector3.dot(planeNor,CollisionUtils._tempV31);
- if (distance+planeD < 0)
- return Plane.PlaneIntersectionType_Back;
- return Plane.PlaneIntersectionType_Intersecting;
- }
- CollisionUtils.intersectsPlaneAndSphere=function(plane,sphere){
- var sphereR=sphere.radius;
- var distance=Vector3.dot(plane.normal,sphere.center)+plane.distance;
- if (distance > sphereR)
- return Plane.PlaneIntersectionType_Front;
- if (distance <-sphereR)
- return Plane.PlaneIntersectionType_Back;
- return Plane.PlaneIntersectionType_Intersecting;
- }
- CollisionUtils.intersectsBoxAndBox=function(box1,box2){
- var box1Mine=box1.min;
- var box1Maxe=box1.max;
- var box2Mine=box2.min;
- var box2Maxe=box2.max;
- if (box1Mine.x > box2Maxe.x || box2Mine.x > box1Maxe.x)
- return false;
- if (box1Mine.y > box2Maxe.y || box2Mine.y > box1Maxe.y)
- return false;
- if (box1Mine.z > box2Maxe.z || box2Mine.z > box1Maxe.z)
- return false;
- return true;
- }
- CollisionUtils.intersectsBoxAndSphere=function(box,sphere){
- var sphereC=sphere.center;
- var sphereR=sphere.radius;
- Vector3.Clamp(sphereC,box.min,box.max,CollisionUtils._tempV30);
- var distance=Vector3.distanceSquared(sphereC,CollisionUtils._tempV30);
- return distance <=sphereR *sphereR;
- }
- CollisionUtils.intersectsSphereAndSphere=function(sphere1,sphere2){
- var radiisum=sphere1.radius+sphere2.radius;
- return Vector3.distanceSquared(sphere1.center,sphere2.center)<=radiisum *radiisum;
- }
- CollisionUtils.boxContainsPoint=function(box,point){
- var boxMine=box.min;
- var boxMaxe=box.max;
- 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)
- return /*laya.d3.math.ContainmentType.Contains*/1;
- return /*laya.d3.math.ContainmentType.Disjoint*/0;
- }
- CollisionUtils.boxContainsBox=function(box1,box2){
- var box1Mine=box1.min;
- var box1MineX=box1Mine.x;
- var box1MineY=box1Mine.y;
- var box1MineZ=box1Mine.z;
- var box1Maxe=box1.max;
- var box1MaxeX=box1Maxe.x;
- var box1MaxeY=box1Maxe.y;
- var box1MaxeZ=box1Maxe.z;
- var box2Mine=box2.min;
- var box2MineX=box2Mine.x;
- var box2MineY=box2Mine.y;
- var box2MineZ=box2Mine.z;
- var box2Maxe=box2.max;
- var box2MaxeX=box2Maxe.x;
- var box2MaxeY=box2Maxe.y;
- var box2MaxeZ=box2Maxe.z;
- if (box1MaxeX < box2MineX || box1MineX > box2MaxeX)
- return /*laya.d3.math.ContainmentType.Disjoint*/0;
- if (box1MaxeY < box2MineY || box1MineY > box2MaxeY)
- return /*laya.d3.math.ContainmentType.Disjoint*/0;
- if (box1MaxeZ < box2MineZ || box1MineZ > box2MaxeZ)
- return /*laya.d3.math.ContainmentType.Disjoint*/0;
- if (box1MineX <=box2MineX && box2MaxeX <=box1MaxeX && box1MineY <=box2MineY && box2MaxeY <=box1MaxeY && box1MineZ <=box2MineZ && box2MaxeZ <=box1MaxeZ){
- return /*laya.d3.math.ContainmentType.Contains*/1;
- }
- return /*laya.d3.math.ContainmentType.Intersects*/2;
- }
- CollisionUtils.boxContainsSphere=function(box,sphere){
- var boxMin=box.min;
- var boxMineX=boxMin.x;
- var boxMineY=boxMin.y;
- var boxMineZ=boxMin.z;
- var boxMax=box.max;
- var boxMaxeX=boxMax.x;
- var boxMaxeY=boxMax.y;
- var boxMaxeZ=boxMax.z;
- var sphereC=sphere.center;
- var sphereCeX=sphereC.x;
- var sphereCeY=sphereC.y;
- var sphereCeZ=sphereC.z;
- var sphereR=sphere.radius;
- Vector3.Clamp(sphereC,boxMin,boxMax,CollisionUtils._tempV30);
- var distance=Vector3.distanceSquared(sphereC,CollisionUtils._tempV30);
- if (distance > sphereR *sphereR)
- return /*laya.d3.math.ContainmentType.Disjoint*/0;
- if ((((boxMineX+sphereR <=sphereCeX)&& (sphereCeX <=boxMaxeX-sphereR))&& ((boxMaxeX-boxMineX > sphereR)&&
- (boxMineY+sphereR <=sphereCeY)))&& (((sphereCeY <=boxMaxeY-sphereR)&& (boxMaxeY-boxMineY > sphereR))&&
- (((boxMineZ+sphereR <=sphereCeZ)&& (sphereCeZ <=boxMaxeZ-sphereR))&& (boxMaxeZ-boxMineZ > sphereR))))
- return /*laya.d3.math.ContainmentType.Contains*/1;
- return /*laya.d3.math.ContainmentType.Intersects*/2;
- }
- CollisionUtils.sphereContainsPoint=function(sphere,point){
- if (Vector3.distanceSquared(point,sphere.center)<=sphere.radius *sphere.radius)
- return /*laya.d3.math.ContainmentType.Contains*/1;
- return /*laya.d3.math.ContainmentType.Disjoint*/0;
- }
- CollisionUtils.sphereContainsTriangle=function(sphere,vertex1,vertex2,vertex3){
- var test1=CollisionUtils.sphereContainsPoint(sphere,vertex1);
- var test2=CollisionUtils.sphereContainsPoint(sphere,vertex2);
- var test3=CollisionUtils.sphereContainsPoint(sphere,vertex3);
- if (test1==/*laya.d3.math.ContainmentType.Contains*/1 && test2==/*laya.d3.math.ContainmentType.Contains*/1 && test3==/*laya.d3.math.ContainmentType.Contains*/1)
- return /*laya.d3.math.ContainmentType.Contains*/1;
- if (CollisionUtils.intersectsSphereAndTriangle(sphere,vertex1,vertex2,vertex3))
- return /*laya.d3.math.ContainmentType.Intersects*/2;
- return /*laya.d3.math.ContainmentType.Disjoint*/0;
- }
- CollisionUtils.sphereContainsBox=function(sphere,box){
- var sphereC=sphere.center;
- var sphereCeX=sphereC.x;
- var sphereCeY=sphereC.y;
- var sphereCeZ=sphereC.z;
- var sphereR=sphere.radius;
- var boxMin=box.min;
- var boxMineX=boxMin.x;
- var boxMineY=boxMin.y;
- var boxMineZ=boxMin.z;
- var boxMax=box.max;
- var boxMaxeX=boxMax.x;
- var boxMaxeY=boxMax.y;
- var boxMaxeZ=boxMax.z;
- var _tempV30e=CollisionUtils._tempV30;
- var _tempV30eX=_tempV30e.x;
- var _tempV30eY=_tempV30e.y;
- var _tempV30eZ=_tempV30e.z;
- if (!CollisionUtils.intersectsBoxAndSphere(box,sphere))
- return /*laya.d3.math.ContainmentType.Disjoint*/0;
- var radiusSquared=sphereR *sphereR;
- _tempV30eX=sphereCeX-boxMineX;
- _tempV30eY=sphereCeY-boxMaxeY;
- _tempV30eZ=sphereCeZ-boxMaxeZ;
- if (Vector3.scalarLengthSquared(CollisionUtils._tempV30)> radiusSquared)
- return /*laya.d3.math.ContainmentType.Intersects*/2;
- _tempV30eX=sphereCeX-boxMaxeX;
- _tempV30eY=sphereCeY-boxMaxeY;
- _tempV30eZ=sphereCeZ-boxMaxeZ;
- if (Vector3.scalarLengthSquared(CollisionUtils._tempV30)> radiusSquared)
- return /*laya.d3.math.ContainmentType.Intersects*/2;
- _tempV30eX=sphereCeX-boxMaxeX;
- _tempV30eY=sphereCeY-boxMineY;
- _tempV30eZ=sphereCeZ-boxMaxeZ;
- if (Vector3.scalarLengthSquared(CollisionUtils._tempV30)> radiusSquared)
- return /*laya.d3.math.ContainmentType.Intersects*/2;
- _tempV30eX=sphereCeX-boxMineX;
- _tempV30eY=sphereCeY-boxMineY;
- _tempV30eZ=sphereCeZ-boxMaxeZ;
- if (Vector3.scalarLengthSquared(CollisionUtils._tempV30)> radiusSquared)
- return /*laya.d3.math.ContainmentType.Intersects*/2;
- _tempV30eX=sphereCeX-boxMineX;
- _tempV30eY=sphereCeY-boxMaxeY;
- _tempV30eZ=sphereCeZ-boxMineZ;
- if (Vector3.scalarLengthSquared(CollisionUtils._tempV30)> radiusSquared)
- return /*laya.d3.math.ContainmentType.Intersects*/2;
- _tempV30eX=sphereCeX-boxMaxeX;
- _tempV30eY=sphereCeY-boxMaxeY;
- _tempV30eZ=sphereCeZ-boxMineZ;
- if (Vector3.scalarLengthSquared(CollisionUtils._tempV30)> radiusSquared)
- return /*laya.d3.math.ContainmentType.Intersects*/2;
- _tempV30eX=sphereCeX-boxMaxeX;
- _tempV30eY=sphereCeY-boxMineY;
- _tempV30eZ=sphereCeZ-boxMineZ;
- if (Vector3.scalarLengthSquared(CollisionUtils._tempV30)> radiusSquared)
- return /*laya.d3.math.ContainmentType.Intersects*/2;
- _tempV30eX=sphereCeX-boxMineX;
- _tempV30eY=sphereCeY-boxMineY;
- _tempV30eZ=sphereCeZ-boxMineZ;
- if (Vector3.scalarLengthSquared(CollisionUtils._tempV30)> radiusSquared)
- return /*laya.d3.math.ContainmentType.Intersects*/2;
- return /*laya.d3.math.ContainmentType.Contains*/1;
- }
- CollisionUtils.sphereContainsSphere=function(sphere1,sphere2){
- var sphere1R=sphere1.radius;
- var sphere2R=sphere2.radius;
- var distance=Vector3.distance(sphere1.center,sphere2.center);
- if (sphere1R+sphere2R < distance)
- return /*laya.d3.math.ContainmentType.Disjoint*/0;
- if (sphere1R-sphere2R < distance)
- return /*laya.d3.math.ContainmentType.Intersects*/2;
- return /*laya.d3.math.ContainmentType.Contains*/1;
- }
- CollisionUtils.closestPointPointTriangle=function(point,vertex1,vertex2,vertex3,out){
- Vector3.subtract(vertex2,vertex1,CollisionUtils._tempV30);
- Vector3.subtract(vertex3,vertex1,CollisionUtils._tempV31);
- Vector3.subtract(point,vertex1,CollisionUtils._tempV32);
- Vector3.subtract(point,vertex2,CollisionUtils._tempV33);
- Vector3.subtract(point,vertex3,CollisionUtils._tempV34);
- var d1=Vector3.dot(CollisionUtils._tempV30,CollisionUtils._tempV32);
- var d2=Vector3.dot(CollisionUtils._tempV31,CollisionUtils._tempV32);
- var d3=Vector3.dot(CollisionUtils._tempV30,CollisionUtils._tempV33);
- var d4=Vector3.dot(CollisionUtils._tempV31,CollisionUtils._tempV33);
- var d5=Vector3.dot(CollisionUtils._tempV30,CollisionUtils._tempV34);
- var d6=Vector3.dot(CollisionUtils._tempV31,CollisionUtils._tempV34);
- if (d1 <=0 && d2 <=0){
- vertex1.cloneTo(out);
- return;
- }
- if (d3 >=0 && d4 <=d3){
- vertex2.cloneTo(out);
- return;
- };
- var vc=d1 *d4-d3 *d2;
- if (vc <=0 && d1 >=0 && d3 <=0){
- var v=d1 / (d1-d3);
- Vector3.scale(CollisionUtils._tempV30,v,out);
- Vector3.add(vertex1,out,out);
- return;
- }
- if (d6 >=0 && d5 <=d6){
- vertex3.cloneTo(out);
- return;
- };
- var vb=d5 *d2-d1 *d6;
- if (vb <=0 && d2 >=0 && d6 <=0){
- var w=d2 / (d2-d6);
- Vector3.scale(CollisionUtils._tempV31,w,out);
- Vector3.add(vertex1,out,out);
- return;
- };
- var va=d3 *d6-d5 *d4;
- if (va <=0 && (d4-d3)>=0 && (d5-d6)>=0){
- var w3=(d4-d3)/ ((d4-d3)+(d5-d6));
- Vector3.subtract(vertex3,vertex2,out);
- Vector3.scale(out,w3,out);
- Vector3.add(vertex2,out,out);
- return;
- };
- var denom=1 / (va+vb+vc);
- var v2=vb *denom;
- var w2=vc *denom;
- Vector3.scale(CollisionUtils._tempV30,v2,CollisionUtils._tempV35);
- Vector3.scale(CollisionUtils._tempV31,w2,CollisionUtils._tempV36);
- Vector3.add(CollisionUtils._tempV35,CollisionUtils._tempV36,out);
- Vector3.add(vertex1,out,out);
- }
- CollisionUtils.closestPointPlanePoint=function(plane,point,out){
- var planeN=plane.normal;
- var t=Vector3.dot(planeN,point)-plane.distance;
- Vector3.scale(planeN,t,CollisionUtils._tempV30);
- Vector3.subtract(point,CollisionUtils._tempV30,out);
- }
- CollisionUtils.closestPointBoxPoint=function(box,point,out){
- Vector3.max(point,box.min,CollisionUtils._tempV30);
- Vector3.min(CollisionUtils._tempV30,box.max,out);
- }
- CollisionUtils.closestPointSpherePoint=function(sphere,point,out){
- var sphereC=sphere.center;
- Vector3.subtract(point,sphereC,out);
- Vector3.normalize(out,out);
- Vector3.scale(out,sphere.radius,out);
- Vector3.add(out,sphereC,out);
- }
- CollisionUtils.closestPointSphereSphere=function(sphere1,sphere2,out){
- var sphere1C=sphere1.center;
- Vector3.subtract(sphere2.center,sphere1C,out);
- Vector3.normalize(out,out);
- Vector3.scale(out,sphere1.radius,out);
- Vector3.add(out,sphere1C,out);
- }
- __static(CollisionUtils,
- ['_tempV30',function(){return this._tempV30=new Vector3();},'_tempV31',function(){return this._tempV31=new Vector3();},'_tempV32',function(){return this._tempV32=new Vector3();},'_tempV33',function(){return this._tempV33=new Vector3();},'_tempV34',function(){return this._tempV34=new Vector3();},'_tempV35',function(){return this._tempV35=new Vector3();},'_tempV36',function(){return this._tempV36=new Vector3();}
- ]);
- return CollisionUtils;
- })()
- /**
- *<code>Matrix3x3</code> 类用于创建3x3矩阵。
- */
- //class laya.d3.math.Matrix3x3
- var Matrix3x3=(function(){
- function Matrix3x3(){
- /**矩阵元素数组*/
- //this.elements=null;
- var e=this.elements=new Float32Array(9);
- e[0]=1;
- e[1]=0;
- e[2]=0;
- e[3]=0;
- e[4]=1;
- e[5]=0;
- e[6]=0;
- e[7]=0;
- e[8]=1;
- }
- __class(Matrix3x3,'laya.d3.math.Matrix3x3');
- var __proto=Matrix3x3.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *计算3x3矩阵的行列式
- *@return 矩阵的行列式
- */
- __proto.determinant=function(){
- var f=this.elements;
- var a00=f[0],a01=f[1],a02=f[2];
- var a10=f[3],a11=f[4],a12=f[5];
- var a20=f[6],a21=f[7],a22=f[8];
- return a00 *(a22 *a11-a12 *a21)+a01 *(-a22 *a10+a12 *a20)+a02 *(a21 *a10-a11 *a20);
- }
- /**
- *通过一个二维向量转换3x3矩阵
- *@param tra 转换向量
- *@param out 输出矩阵
- */
- __proto.translate=function(trans,out){
- var e=out.elements;
- var f=this.elements;
- var a00=f[0],a01=f[1],a02=f[2];
- var a10=f[3],a11=f[4],a12=f[5];
- var a20=f[6],a21=f[7],a22=f[8];
- var x=trans.x,y=trans.y;
- e[0]=a00;
- e[1]=a01;
- e[2]=a02;
- e[3]=a10;
- e[4]=a11;
- e[5]=a12;
- e[6]=x *a00+y *a10+a20;
- e[7]=x *a01+y *a11+a21;
- e[8]=x *a02+y *a12+a22;
- }
- /**
- *根据指定角度旋转3x3矩阵
- *@param rad 旋转角度
- *@param out 输出矩阵
- */
- __proto.rotate=function(rad,out){
- var e=out.elements;
- var f=this.elements;
- var a00=f[0],a01=f[1],a02=f[2];
- var a10=f[3],a11=f[4],a12=f[5];
- var a20=f[6],a21=f[7],a22=f[8];
- var s=Math.sin(rad);
- var c=Math.cos(rad);
- e[0]=c *a00+s *a10;
- e[1]=c *a01+s *a11;
- e[2]=c *a02+s *a12;
- e[3]=c *a10-s *a00;
- e[4]=c *a11-s *a01;
- e[5]=c *a12-s *a02;
- e[6]=a20;
- e[7]=a21;
- e[8]=a22;
- }
- /**
- *根据制定缩放3x3矩阵
- *@param scale 缩放值
- *@param out 输出矩阵
- */
- __proto.scale=function(scale,out){
- var e=out.elements;
- var f=this.elements;
- var x=scale.x,y=scale.y;
- e[0]=x *f[0];
- e[1]=x *f[1];
- e[2]=x *f[2];
- e[3]=y *f[3];
- e[4]=y *f[4];
- e[5]=y *f[5];
- e[6]=f[6];
- e[7]=f[7];
- e[8]=f[8];
- }
- /**
- *计算3x3矩阵的逆矩阵
- *@param out 输出的逆矩阵
- */
- __proto.invert=function(out){
- var e=out.elements;
- var f=this.elements;
- var a00=f[0],a01=f[1],a02=f[2];
- var a10=f[3],a11=f[4],a12=f[5];
- var a20=f[6],a21=f[7],a22=f[8];
- var b01=a22 *a11-a12 *a21;
- var b11=-a22 *a10+a12 *a20;
- var b21=a21 *a10-a11 *a20;
- var det=a00 *b01+a01 *b11+a02 *b21;
- if (!det){
- out=null;
- }
- det=1.0 / det;
- e[0]=b01 *det;
- e[1]=(-a22 *a01+a02 *a21)*det;
- e[2]=(a12 *a01-a02 *a11)*det;
- e[3]=b11 *det;
- e[4]=(a22 *a00-a02 *a20)*det;
- e[5]=(-a12 *a00+a02 *a10)*det;
- e[6]=b21 *det;
- e[7]=(-a21 *a00+a01 *a20)*det;
- e[8]=(a11 *a00-a01 *a10)*det;
- }
- /**
- *计算3x3矩阵的转置矩阵
- *@param out 输出矩阵
- */
- __proto.transpose=function(out){
- var e=out.elements;
- var f=this.elements;
- if (out===this){
- var a01=f[1],a02=f[2],a12=f[5];
- e[1]=f[3];
- e[2]=f[6];
- e[3]=a01;
- e[5]=f[7];
- e[6]=a02;
- e[7]=a12;
- }else {
- e[0]=f[0];
- e[1]=f[3];
- e[2]=f[6];
- e[3]=f[1];
- e[4]=f[4];
- e[5]=f[7];
- e[6]=f[2];
- e[7]=f[5];
- e[8]=f[8];
- }
- }
- /**设置已有的矩阵为单位矩阵*/
- __proto.identity=function(){
- var e=this.elements;
- e[0]=1;
- e[1]=0;
- e[2]=0;
- e[3]=0;
- e[4]=1;
- e[5]=0;
- e[6]=0;
- e[7]=0;
- e[8]=1;
- }
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var i,s,d;
- s=this.elements;
- d=destObject.elements;
- if (s===d){
- return;
- }
- for (i=0;i < 9;++i){
- d[i]=s[i];
- }
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var dest=/*__JS__ */new this.constructor();
- this.cloneTo(dest);
- return dest;
- }
- Matrix3x3.createFromTranslation=function(trans,out){
- var e=out.elements;
- out[0]=1;
- out[1]=0;
- out[2]=0;
- out[3]=0;
- out[4]=1;
- out[5]=0;
- out[6]=trans.x;
- out[7]=trans.y;
- out[8]=1;
- }
- Matrix3x3.createFromRotation=function(rad,out){
- var e=out.elements;
- var s=Math.sin(rad),c=Math.cos(rad);
- e[0]=c;
- e[1]=s;
- e[2]=0;
- e[3]=-s;
- e[4]=c;
- e[5]=0;
- e[6]=0;
- e[7]=0;
- e[8]=1;
- }
- Matrix3x3.createFromScaling=function(scale,out){
- var e=out.elements;
- e[0]=scale.x;
- e[1]=0;
- e[2]=0;
- e[3]=0;
- e[4]=scale.y;
- e[5]=0;
- e[6]=0;
- e[7]=0;
- e[8]=1;
- }
- Matrix3x3.createFromMatrix4x4=function(sou,out){
- out[0]=sou[0];
- out[1]=sou[1];
- out[2]=sou[2];
- out[3]=sou[4];
- out[4]=sou[5];
- out[5]=sou[6];
- out[6]=sou[8];
- out[7]=sou[9];
- out[8]=sou[10];
- }
- Matrix3x3.multiply=function(left,right,out){
- var e=out.elements;
- var f=left.elements;
- var g=right.elements;
- var a00=f[0],a01=f[1],a02=f[2];
- var a10=f[3],a11=f[4],a12=f[5];
- var a20=f[6],a21=f[7],a22=f[8];
- var b00=g[0],b01=g[1],b02=g[2];
- var b10=g[3],b11=g[4],b12=g[5];
- var b20=g[6],b21=g[7],b22=g[8];
- e[0]=b00 *a00+b01 *a10+b02 *a20;
- e[1]=b00 *a01+b01 *a11+b02 *a21;
- e[2]=b00 *a02+b01 *a12+b02 *a22;
- e[3]=b10 *a00+b11 *a10+b12 *a20;
- e[4]=b10 *a01+b11 *a11+b12 *a21;
- e[5]=b10 *a02+b11 *a12+b12 *a22;
- e[6]=b20 *a00+b21 *a10+b22 *a20;
- e[7]=b20 *a01+b21 *a11+b22 *a21;
- e[8]=b20 *a02+b21 *a12+b22 *a22;
- }
- Matrix3x3.lookAt=function(eye,target,up,out){
- Vector3.subtract(eye,target,Matrix3x3._tempV30);
- Vector3.normalize(Matrix3x3._tempV30,Matrix3x3._tempV30);
- Vector3.cross(up,Matrix3x3._tempV30,Matrix3x3._tempV31);
- Vector3.normalize(Matrix3x3._tempV31,Matrix3x3._tempV31);
- Vector3.cross(Matrix3x3._tempV30,Matrix3x3._tempV31,Matrix3x3._tempV32);
- var v0=Matrix3x3._tempV30;
- var v1=Matrix3x3._tempV31;
- var v2=Matrix3x3._tempV32;
- var me=out.elements;
- me[0]=v1.x;
- me[3]=v1.y;
- me[6]=v1.z;
- me[1]=v2.x;
- me[4]=v2.y;
- me[7]=v2.z;
- me[2]=v0.x;
- me[5]=v0.y;
- me[8]=v0.z;
- }
- Matrix3x3.DEFAULT=new Matrix3x3();
- __static(Matrix3x3,
- ['_tempV30',function(){return this._tempV30=new Vector3();},'_tempV31',function(){return this._tempV31=new Vector3();},'_tempV32',function(){return this._tempV32=new Vector3();}
- ]);
- return Matrix3x3;
- })()
- /**
- *<code>Physics</code> 类用于简单物理检测。
- */
- //class laya.d3.utils.Physics3DUtils
- var Physics3DUtils=(function(){
- /**
- *创建一个 <code>Physics</code> 实例。
- */
- function Physics3DUtils(){}
- __class(Physics3DUtils,'laya.d3.utils.Physics3DUtils');
- Physics3DUtils.setColliderCollision=function(collider1,collider2,collsion){}
- Physics3DUtils.getIColliderCollision=function(collider1,collider2){
- return false;
- }
- Physics3DUtils.COLLISIONFILTERGROUP_DEFAULTFILTER=0x1;
- Physics3DUtils.COLLISIONFILTERGROUP_STATICFILTER=0x2;
- Physics3DUtils.COLLISIONFILTERGROUP_KINEMATICFILTER=0x4;
- Physics3DUtils.COLLISIONFILTERGROUP_DEBRISFILTER=0x8;
- Physics3DUtils.COLLISIONFILTERGROUP_SENSORTRIGGER=0x10;
- Physics3DUtils.COLLISIONFILTERGROUP_CHARACTERFILTER=0x20;
- Physics3DUtils.COLLISIONFILTERGROUP_CUSTOMFILTER1=0x40;
- Physics3DUtils.COLLISIONFILTERGROUP_CUSTOMFILTER2=0x80;
- Physics3DUtils.COLLISIONFILTERGROUP_CUSTOMFILTER3=0x100;
- Physics3DUtils.COLLISIONFILTERGROUP_CUSTOMFILTER4=0x200;
- Physics3DUtils.COLLISIONFILTERGROUP_CUSTOMFILTER5=0x400;
- Physics3DUtils.COLLISIONFILTERGROUP_CUSTOMFILTER6=0x800;
- Physics3DUtils.COLLISIONFILTERGROUP_CUSTOMFILTER7=0x1000;
- Physics3DUtils.COLLISIONFILTERGROUP_CUSTOMFILTER8=0x2000;
- Physics3DUtils.COLLISIONFILTERGROUP_CUSTOMFILTER9=0x4000;
- Physics3DUtils.COLLISIONFILTERGROUP_CUSTOMFILTER10=0x8000;
- Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER=-1;
- __static(Physics3DUtils,
- ['gravity',function(){return this.gravity=new Vector3(0,-9.81,0);}
- ]);
- return Physics3DUtils;
- })()
- /**
- *<code>BoundBox</code> 类用于创建包围盒。
- */
- //class laya.d3.math.BoundBox
- var BoundBox=(function(){
- function BoundBox(min,max){
- /**最小顶点。*/
- this.min=null;
- /**最大顶点。*/
- this.max=null;
- this.min=min;
- this.max=max;
- }
- __class(BoundBox,'laya.d3.math.BoundBox');
- var __proto=BoundBox.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *@private
- */
- __proto._rotateExtents=function(extents,rotation,out){
- var extentsX=extents.x;
- var extentsY=extents.y;
- var extentsZ=extents.z;
- var matElements=rotation.elements;
- out.x=Math.abs(matElements[0] *extentsX)+Math.abs(matElements[4] *extentsY)+Math.abs(matElements[8] *extentsZ);
- out.y=Math.abs(matElements[1] *extentsX)+Math.abs(matElements[5] *extentsY)+Math.abs(matElements[9] *extentsZ);
- out.z=Math.abs(matElements[2] *extentsX)+Math.abs(matElements[6] *extentsY)+Math.abs(matElements[10] *extentsZ);
- }
- /**
- *获取包围盒的8个角顶点。
- *@param corners 返回顶点的输出队列。
- */
- __proto.getCorners=function(corners){
- corners.length=8;
- var minX=this.min.x;
- var minY=this.min.y;
- var minZ=this.min.z;
- var maxX=this.max.x;
- var maxY=this.max.y;
- var maxZ=this.max.z;
- corners[0]=new Vector3(minX,maxY,maxZ);
- corners[1]=new Vector3(maxX,maxY,maxZ);
- corners[2]=new Vector3(maxX,minY,maxZ);
- corners[3]=new Vector3(minX,minY,maxZ);
- corners[4]=new Vector3(minX,maxY,minZ);
- corners[5]=new Vector3(maxX,maxY,minZ);
- corners[6]=new Vector3(maxX,minY,minZ);
- corners[7]=new Vector3(minX,minY,minZ);
- }
- /**
- *获取中心点。
- *@param out
- */
- __proto.getCenter=function(out){
- Vector3.add(this.min,this.max,out);
- Vector3.scale(out,0.5,out);
- }
- /**
- *获取范围。
- *@param out
- */
- __proto.getExtent=function(out){
- Vector3.subtract(this.max,this.min,out);
- Vector3.scale(out,0.5,out);
- }
- /**
- *设置中心点和范围。
- *@param center
- */
- __proto.setCenterAndExtent=function(center,extent){
- Vector3.subtract(center,extent,this.min);
- Vector3.add(center,extent,this.max);
- }
- /**
- *@private
- */
- __proto.tranform=function(matrix,out){
- var center=BoundBox._tempVector30;
- var extent=BoundBox._tempVector31;
- this.getCenter(center);
- this.getExtent(extent);
- Vector3.transformCoordinate(center,matrix,center);
- this._rotateExtents(extent,matrix,extent);
- out.setCenterAndExtent(center,extent);
- }
- __proto.toDefault=function(){
- this.min.toDefault();
- this.max.toDefault();
- }
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var dest=destObject;
- this.min.cloneTo(dest.min);
- this.max.cloneTo(dest.max);
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var dest=/*__JS__ */new this.constructor(new Vector3(),new Vector3());
- this.cloneTo(dest);
- return dest;
- }
- BoundBox.createfromPoints=function(points,out){
- if (points==null)
- throw new Error("points");
- var min=out.min;
- var max=out.max;
- min.x=Number.MAX_VALUE;
- min.y=Number.MAX_VALUE;
- min.z=Number.MAX_VALUE;
- max.x=-Number.MAX_VALUE;
- max.y=-Number.MAX_VALUE;
- max.z=-Number.MAX_VALUE;
- for (var i=0,n=points.length;i < n;++i){
- Vector3.min(min,points[i],min);
- Vector3.max(max,points[i],max);
- }
- }
- BoundBox.merge=function(box1,box2,out){
- Vector3.min(box1.min,box2.min,out.min);
- Vector3.max(box1.max,box2.max,out.max);
- }
- __static(BoundBox,
- ['_tempVector30',function(){return this._tempVector30=new Vector3();},'_tempVector31',function(){return this._tempVector31=new Vector3();}
- ]);
- return BoundBox;
- })()
- /**
- *<code>AnimatorState</code> 类用于创建动作状态。
- */
- //class laya.d3.component.AnimatorState
- var AnimatorState=(function(){
- function AnimatorState(){
- /**@private */
- //this._clip=null;
- /**@private */
- //this._currentFrameIndices=null;
- /**@private */
- //this._scripts=null;
- /**名称。*/
- //this.name=null;
- /**动画播放速度,1.0为正常播放速度。*/
- this.speed=1.0;
- /**动作播放起始时间。*/
- this.clipStart=0.0;
- /**动作播放结束时间。*/
- this.clipEnd=1.0;
- this._nodeOwners=[];
- }
- __class(AnimatorState,'laya.d3.component.AnimatorState');
- var __proto=AnimatorState.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *@private
- */
- __proto._resetFrameIndices=function(){
- for (var i=0,n=this._currentFrameIndices.length;i < n;i++)
- this._currentFrameIndices[i]=-1;
- }
- /**
- *添加脚本。
- *@param type 组件类型。
- *@return 脚本。
- *
- */
- __proto.addScript=function(type){
- var script=new type();
- this._scripts=this._scripts || [];
- this._scripts.push(script);
- return script;
- }
- /**
- *获取脚本。
- *@param type 组件类型。
- *@return 脚本。
- *
- */
- __proto.getScript=function(type){
- if (this._scripts){
- for (var i=0,n=this._scripts.length;i < n;i++){
- var script=this._scripts[i];
- if (Laya.__typeof(script,type))
- return script;
- }
- }
- return null;
- }
- /**
- *获取脚本集合。
- *@param type 组件类型。
- *@return 脚本集合。
- *
- */
- __proto.getScripts=function(type){
- var coms;
- if (this._scripts){
- for (var i=0,n=this._scripts.length;i < n;i++){
- var script=this._scripts[i];
- if (Laya.__typeof(script,type)){
- coms=coms ||[];
- coms.push(script);
- }
- }
- }
- return coms;
- }
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var dest=destObject;
- dest.name=this.name;
- dest.speed=this.speed;
- dest.clipStart=this.clipStart;
- dest.clipEnd=this.clipEnd;
- dest.clip=this._clip;
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var dest=/*__JS__ */new this.constructor();
- this.cloneTo(dest);
- return dest;
- }
- /**
- *设置动作。
- *@param value 动作。
- */
- /**
- *获取动作。
- *@return 动作
- */
- __getset(0,__proto,'clip',function(){
- return this._clip;
- },function(value){
- this._clip=value;
- this._currentFrameIndices=new Int16Array(value._nodes.count);
- this._resetFrameIndices();
- });
- return AnimatorState;
- })()
- /**
- *<code>TextMesh</code> 类用于创建文本网格。
- */
- //class laya.d3.text.TextMesh
- var TextMesh=(function(){
- function TextMesh(){
- /**@private */
- this._vertices=null;
- /**@private */
- this._vertexBuffer=null;
- /**@private */
- this._text=null;
- /**@private */
- this._fontSize=0;
- /**@private */
- this._color=null;
- }
- __class(TextMesh,'laya.d3.text.TextMesh');
- var __proto=TextMesh.prototype;
- /**
- *@private
- */
- __proto._createVertexBuffer=function(charCount){}
- /**
- *@private
- */
- __proto._resizeVertexBuffer=function(charCount){}
- /**
- *@private
- */
- __proto._addChar=function(){}
- /**
- *设置文本。
- *@param value 文本。
- */
- /**
- *获取文本。
- *@return 文本。
- */
- __getset(0,__proto,'text',function(){
- return this._text;
- },function(value){
- this._text=value;
- });
- /**
- *设置字体储存。
- *@return 字体尺寸。
- */
- /**
- *获取字体尺寸。
- *@param value 字体尺寸。
- */
- __getset(0,__proto,'fontSize',function(){
- return this._fontSize;
- },function(value){
- this._fontSize=value;
- });
- /**
- *设置颜色。
- *@param 颜色。
- */
- /**
- *获取颜色。
- *@return 颜色。
- */
- __getset(0,__proto,'color',function(){
- return this._color;
- },function(value){
- this._color=value;
- });
- TextMesh._indexBuffer=null;
- return TextMesh;
- })()
- /**
- *<code>Matrix4x4</code> 类用于创建4x4矩阵。
- */
- //class laya.d3.math.Matrix4x4
- var Matrix4x4=(function(){
- function Matrix4x4(m11,m12,m13,m14,m21,m22,m23,m24,m31,m32,m33,m34,m41,m42,m43,m44,elements){
- /**矩阵元素数组*/
- //this.elements=null;
- (m11===void 0)&& (m11=1);
- (m12===void 0)&& (m12=0);
- (m13===void 0)&& (m13=0);
- (m14===void 0)&& (m14=0);
- (m21===void 0)&& (m21=0);
- (m22===void 0)&& (m22=1);
- (m23===void 0)&& (m23=0);
- (m24===void 0)&& (m24=0);
- (m31===void 0)&& (m31=0);
- (m32===void 0)&& (m32=0);
- (m33===void 0)&& (m33=1);
- (m34===void 0)&& (m34=0);
- (m41===void 0)&& (m41=0);
- (m42===void 0)&& (m42=0);
- (m43===void 0)&& (m43=0);
- (m44===void 0)&& (m44=1);
- var e=elements ? this.elements=elements :this.elements=new Float32Array(16);
- e[0]=m11;
- e[1]=m12;
- e[2]=m13;
- e[3]=m14;
- e[4]=m21;
- e[5]=m22;
- e[6]=m23;
- e[7]=m24;
- e[8]=m31;
- e[9]=m32;
- e[10]=m33;
- e[11]=m34;
- e[12]=m41;
- e[13]=m42;
- e[14]=m43;
- e[15]=m44;
- }
- __class(Matrix4x4,'laya.d3.math.Matrix4x4');
- var __proto=Matrix4x4.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- __proto.setRotation=function(rotation){
- var rotationX=rotation.x;
- var rotationY=rotation.y;
- var rotationZ=rotation.z;
- var rotationW=rotation.w;
- var xx=rotationX *rotationX;
- var yy=rotationY *rotationY;
- var zz=rotationZ *rotationZ;
- var xy=rotationX *rotationY;
- var zw=rotationZ *rotationW;
- var zx=rotationZ *rotationX;
- var yw=rotationY *rotationW;
- var yz=rotationY *rotationZ;
- var xw=rotationX *rotationW;
- var e=this.elements;
- e[0]=1.0-(2.0 *(yy+zz));
- e[1]=2.0 *(xy+zw);
- e[2]=2.0 *(zx-yw);
- e[4]=2.0 *(xy-zw);
- e[5]=1.0-(2.0 *(zz+xx));
- e[6]=2.0 *(yz+xw);
- e[8]=2.0 *(zx+yw);
- e[9]=2.0 *(yz-xw);
- e[10]=1.0-(2.0 *(yy+xx));
- }
- __proto.setPosition=function(position){
- var e=this.elements;
- e[12]=position.x;
- e[13]=position.y;
- e[14]=position.z;
- }
- __proto.getElementByRowColumn=function(row,column){
- if (row < 0 || row > 3)
- throw new Error("row","Rows and columns for matrices run from 0 to 3, inclusive.");
- if (column < 0 || column > 3)
- throw new Error("column","Rows and columns for matrices run from 0 to 3, inclusive.");
- return this.elements[(row *4)+column];
- }
- __proto.setElementByRowColumn=function(row,column,value){
- if (row < 0 || row > 3)
- throw new Error("row","Rows and columns for matrices run from 0 to 3, inclusive.");
- if (column < 0 || column > 3)
- throw new Error("column","Rows and columns for matrices run from 0 to 3, inclusive.");
- this.elements[(row *4)+column]=value;
- }
- /**
- *判断两个4x4矩阵的值是否相等。
- *@param other 4x4矩阵
- */
- __proto.equalsOtherMatrix=function(other){
- var e=this.elements;
- var oe=other.elements;
- 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]));
- }
- /**
- *分解矩阵为平移向量、旋转四元数、缩放向量。
- *@param translation 平移向量。
- *@param rotation 旋转四元数。
- *@param scale 缩放向量。
- *@return 是否分解成功。
- */
- __proto.decomposeTransRotScale=function(translation,rotation,scale){
- var rotationMatrix=Matrix4x4._tempMatrix4x4;
- if (this.decomposeTransRotMatScale(translation,rotationMatrix,scale)){
- Quaternion.createFromMatrix4x4(rotationMatrix,rotation);
- return true;
- }else {
- rotation.identity();
- return false;
- }
- }
- /**
- *分解矩阵为平移向量、旋转矩阵、缩放向量。
- *@param translation 平移向量。
- *@param rotationMatrix 旋转矩阵。
- *@param scale 缩放向量。
- *@return 是否分解成功。
- */
- __proto.decomposeTransRotMatScale=function(translation,rotationMatrix,scale){
- var e=this.elements;
- var te=translation;
- var re=rotationMatrix.elements;
- var se=scale;
- te.x=e[12];
- te.y=e[13];
- te.z=e[14];
- var m11=e[0],m12=e[1],m13=e[2];
- var m21=e[4],m22=e[5],m23=e[6];
- var m31=e[8],m32=e[9],m33=e[10];
- var sX=se.x=Math.sqrt((m11 *m11)+(m12 *m12)+(m13 *m13));
- var sY=se.y=Math.sqrt((m21 *m21)+(m22 *m22)+(m23 *m23));
- var sZ=se.z=Math.sqrt((m31 *m31)+(m32 *m32)+(m33 *m33));
- if (MathUtils3D.isZero(sX)|| MathUtils3D.isZero(sY)|| MathUtils3D.isZero(sZ)){
- 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;
- re[0]=re[5]=re[10]=re[15]=1;
- return false;
- };
- var at=Matrix4x4._tempVector0;
- at.x=m31 / sZ;
- at.y=m32 / sZ;
- at.z=m33 / sZ;
- var tempRight=Matrix4x4._tempVector1;
- tempRight.x=m11 / sX;
- tempRight.y=m12 / sX;
- tempRight.z=m13 / sX;
- var up=Matrix4x4._tempVector2;
- Vector3.cross(at,tempRight,up);
- var right=Matrix4x4._tempVector1;
- Vector3.cross(up,at,right);
- re[3]=re[7]=re[11]=re[12]=re[13]=re[14]=0;
- re[15]=1;
- re[0]=right.x;
- re[1]=right.y;
- re[2]=right.z;
- re[4]=up.x;
- re[5]=up.y;
- re[6]=up.z;
- re[8]=at.x;
- re[9]=at.y;
- re[10]=at.z;
- ((re[0] *m11+re[1] *m12+re[2] *m13)< 0.0)&& (se[0]=-sX);
- ((re[4] *m21+re[5] *m22+re[6] *m23)< 0.0)&& (se[1]=-sY);
- ((re[8] *m31+re[9] *m32+re[10] *m33)< 0.0)&& (se[2]=-sZ);
- return true;
- }
- /**
- *分解旋转矩阵的旋转为YawPitchRoll欧拉角。
- *@param out float yaw
- *@param out float pitch
- *@param out float roll
- *@return
- */
- __proto.decomposeYawPitchRoll=function(yawPitchRoll){
- var pitch=Math.asin(-this.elements[9]);
- yawPitchRoll.y=pitch;
- var test=Math.cos(pitch);
- if (test > MathUtils3D.zeroTolerance){
- yawPitchRoll.z=Math.atan2(this.elements[1],this.elements[5]);
- yawPitchRoll.x=Math.atan2(this.elements[8],this.elements[10]);
- }else {
- yawPitchRoll.z=Math.atan2(-this.elements[4],this.elements[0]);
- yawPitchRoll.x=0.0;
- }
- }
- /**归一化矩阵 */
- __proto.normalize=function(){
- var v=this.elements;
- var c=v[0],d=v[1],e=v[2],g=Math.sqrt(c *c+d *d+e *e);
- if (g){
- if (g==1)
- return;
- }else {
- v[0]=0;
- v[1]=0;
- v[2]=0;
- return;
- }
- g=1 / g;
- v[0]=c *g;
- v[1]=d *g;
- v[2]=e *g;
- }
- /**计算矩阵的转置矩阵*/
- __proto.transpose=function(){
- var e,t;
- e=this.elements;
- t=e[1];
- e[1]=e[4];
- e[4]=t;
- t=e[2];
- e[2]=e[8];
- e[8]=t;
- t=e[3];
- e[3]=e[12];
- e[12]=t;
- t=e[6];
- e[6]=e[9];
- e[9]=t;
- t=e[7];
- e[7]=e[13];
- e[13]=t;
- t=e[11];
- e[11]=e[14];
- e[14]=t;
- return this;
- }
- /**
- *计算一个矩阵的逆矩阵
- *@param out 输出矩阵
- */
- __proto.invert=function(out){
- var ae=this.elements;
- var oe=out.elements;
- 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;
- if (Math.abs(det)===0.0){
- return;
- }
- det=1.0 / det;
- oe[0]=(a11 *b11-a12 *b10+a13 *b09)*det;
- oe[1]=(a02 *b10-a01 *b11-a03 *b09)*det;
- oe[2]=(a31 *b05-a32 *b04+a33 *b03)*det;
- oe[3]=(a22 *b04-a21 *b05-a23 *b03)*det;
- oe[4]=(a12 *b08-a10 *b11-a13 *b07)*det;
- oe[5]=(a00 *b11-a02 *b08+a03 *b07)*det;
- oe[6]=(a32 *b02-a30 *b05-a33 *b01)*det;
- oe[7]=(a20 *b05-a22 *b02+a23 *b01)*det;
- oe[8]=(a10 *b10-a11 *b08+a13 *b06)*det;
- oe[9]=(a01 *b08-a00 *b10-a03 *b06)*det;
- oe[10]=(a30 *b04-a31 *b02+a33 *b00)*det;
- oe[11]=(a21 *b02-a20 *b04-a23 *b00)*det;
- oe[12]=(a11 *b07-a10 *b09-a12 *b06)*det;
- oe[13]=(a00 *b09-a01 *b07+a02 *b06)*det;
- oe[14]=(a31 *b01-a30 *b03-a32 *b00)*det;
- oe[15]=(a20 *b03-a21 *b01+a22 *b00)*det;
- }
- /**设置矩阵为单位矩阵*/
- __proto.identity=function(){
- var e=this.elements;
- 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;
- e[0]=e[5]=e[10]=e[15]=1;
- }
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var i,s,d;
- s=this.elements;
- d=destObject.elements;
- if (s===d){
- return;
- }
- for (i=0;i < 16;++i){
- d[i]=s[i];
- }
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var dest=/*__JS__ */new this.constructor();
- this.cloneTo(dest);
- return dest;
- }
- /**
- *获取平移向量。
- *@param out 平移向量。
- */
- __proto.getTranslationVector=function(out){
- var me=this.elements;
- out.x=me[12];
- out.y=me[13];
- out.z=me[14];
- }
- /**
- *设置平移向量。
- *@param translate 平移向量。
- */
- __proto.setTranslationVector=function(translate){
- var me=this.elements;
- var ve=translate;
- me[12]=ve.x;
- me[13]=ve.y;
- me[14]=ve.z;
- }
- /**
- *获取前向量。
- *@param out 前向量。
- */
- __proto.getForward=function(out){
- var me=this.elements;
- out.x=-me[8];
- out.y=-me[9];
- out.z=-me[10];
- }
- /**
- *设置前向量。
- *@param forward 前向量。
- */
- __proto.setForward=function(forward){
- var me=this.elements;
- me[8]=-forward.x;
- me[9]=-forward.y;
- me[10]=-forward.z;
- }
- Matrix4x4.createRotationX=function(rad,out){
- var oe=out.elements;
- var s=Math.sin(rad),c=Math.cos(rad);
- oe[1]=oe[2]=oe[3]=oe[4]=oe[7]=oe[8]=oe[11]=oe[12]=oe[13]=oe[14]=0;
- oe[0]=oe[15]=1;
- oe[5]=oe[10]=c;
- oe[6]=s;
- oe[9]=-s;
- }
- Matrix4x4.createRotationY=function(rad,out){
- var oe=out.elements;
- var s=Math.sin(rad),c=Math.cos(rad);
- oe[1]=oe[3]=oe[4]=oe[6]=oe[7]=oe[9]=oe[11]=oe[12]=oe[13]=oe[14]=0;
- oe[5]=oe[15]=1;
- oe[0]=oe[10]=c;
- oe[2]=-s;
- oe[8]=s;
- }
- Matrix4x4.createRotationZ=function(rad,out){
- var oe=out.elements;
- var s=Math.sin(rad),c=Math.cos(rad);
- oe[2]=oe[3]=oe[6]=oe[7]=oe[8]=oe[9]=oe[11]=oe[12]=oe[13]=oe[14]=0;
- oe[10]=oe[15]=1;
- oe[0]=oe[5]=c;
- oe[1]=s;
- oe[4]=-s;
- }
- Matrix4x4.createRotationYawPitchRoll=function(yaw,pitch,roll,result){
- Quaternion.createFromYawPitchRoll(yaw,pitch,roll,Matrix4x4._tempQuaternion);
- Matrix4x4.createRotationQuaternion(Matrix4x4._tempQuaternion,result);
- }
- Matrix4x4.createRotationAxis=function(axis,angle,result){
- var x=axis.x;
- var y=axis.y;
- var z=axis.z;
- var cos=Math.cos(angle);
- var sin=Math.sin(angle);
- var xx=x *x;
- var yy=y *y;
- var zz=z *z;
- var xy=x *y;
- var xz=x *z;
- var yz=y *z;
- var resultE=result.elements;
- resultE[3]=resultE[7]=resultE[11]=resultE[12]=resultE[13]=resultE[14]=0;
- resultE[15]=1.0;
- resultE[0]=xx+(cos *(1.0-xx));
- resultE[1]=(xy-(cos *xy))+(sin *z);
- resultE[2]=(xz-(cos *xz))-(sin *y);
- resultE[4]=(xy-(cos *xy))-(sin *z);
- resultE[5]=yy+(cos *(1.0-yy));
- resultE[6]=(yz-(cos *yz))+(sin *x);
- resultE[8]=(xz-(cos *xz))+(sin *y);
- resultE[9]=(yz-(cos *yz))-(sin *x);
- resultE[10]=zz+(cos *(1.0-zz));
- }
- Matrix4x4.createRotationQuaternion=function(rotation,result){
- var resultE=result.elements;
- var rotationX=rotation.x;
- var rotationY=rotation.y;
- var rotationZ=rotation.z;
- var rotationW=rotation.w;
- var xx=rotationX *rotationX;
- var yy=rotationY *rotationY;
- var zz=rotationZ *rotationZ;
- var xy=rotationX *rotationY;
- var zw=rotationZ *rotationW;
- var zx=rotationZ *rotationX;
- var yw=rotationY *rotationW;
- var yz=rotationY *rotationZ;
- var xw=rotationX *rotationW;
- resultE[3]=resultE[7]=resultE[11]=resultE[12]=resultE[13]=resultE[14]=0;
- resultE[15]=1.0;
- resultE[0]=1.0-(2.0 *(yy+zz));
- resultE[1]=2.0 *(xy+zw);
- resultE[2]=2.0 *(zx-yw);
- resultE[4]=2.0 *(xy-zw);
- resultE[5]=1.0-(2.0 *(zz+xx));
- resultE[6]=2.0 *(yz+xw);
- resultE[8]=2.0 *(zx+yw);
- resultE[9]=2.0 *(yz-xw);
- resultE[10]=1.0-(2.0 *(yy+xx));
- }
- Matrix4x4.createTranslate=function(trans,out){
- var oe=out.elements;
- oe[4]=oe[8]=oe[1]=oe[9]=oe[2]=oe[6]=oe[3]=oe[7]=oe[11]=0;
- oe[0]=oe[5]=oe[10]=oe[15]=1;
- oe[12]=trans.x;
- oe[13]=trans.y;
- oe[14]=trans.z;
- }
- Matrix4x4.createScaling=function(scale,out){
- var oe=out.elements;
- oe[0]=scale.x;
- oe[5]=scale.y;
- oe[10]=scale.z;
- 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;
- oe[15]=1;
- }
- Matrix4x4.multiply=function(left,right,out){
- var i,e,a,b,ai0,ai1,ai2,ai3;
- e=out.elements;
- a=left.elements;
- b=right.elements;
- if (e===b){
- b=new Float32Array(16);
- for (i=0;i < 16;++i){
- b[i]=e[i];
- }
- };
- var b0=b[0],b1=b[1],b2=b[2],b3=b[3];
- var b4=b[4],b5=b[5],b6=b[6],b7=b[7];
- var b8=b[8],b9=b[9],b10=b[10],b11=b[11];
- var b12=b[12],b13=b[13],b14=b[14],b15=b[15];
- for (i=0;i < 4;i++){
- ai0=a[i];
- ai1=a[i+4];
- ai2=a[i+8];
- ai3=a[i+12];
- e[i]=ai0 *b0+ai1 *b1+ai2 *b2+ai3 *b3;
- e[i+4]=ai0 *b4+ai1 *b5+ai2 *b6+ai3 *b7;
- e[i+8]=ai0 *b8+ai1 *b9+ai2 *b10+ai3 *b11;
- e[i+12]=ai0 *b12+ai1 *b13+ai2 *b14+ai3 *b15;
- }
- }
- Matrix4x4.multiplyForNative=function(left,right,out){
- LayaGL.instance.matrix4x4Multiply(left.elements,right.elements,out.elements);
- }
- Matrix4x4.createFromQuaternion=function(rotation,out){
- var e=out.elements;
- var x=rotation.x,y=rotation.y,z=rotation.z,w=rotation.w;
- var x2=x+x;
- var y2=y+y;
- var z2=z+z;
- var xx=x *x2;
- var yx=y *x2;
- var yy=y *y2;
- var zx=z *x2;
- var zy=z *y2;
- var zz=z *z2;
- var wx=w *x2;
- var wy=w *y2;
- var wz=w *z2;
- e[0]=1-yy-zz;
- e[1]=yx+wz;
- e[2]=zx-wy;
- e[3]=0;
- e[4]=yx-wz;
- e[5]=1-xx-zz;
- e[6]=zy+wx;
- e[7]=0;
- e[8]=zx+wy;
- e[9]=zy-wx;
- e[10]=1-xx-yy;
- e[11]=0;
- e[12]=0;
- e[13]=0;
- e[14]=0;
- e[15]=1;
- }
- Matrix4x4.createAffineTransformation=function(trans,rot,scale,out){
- var oe=out.elements;
- var x=rot.x,y=rot.y,z=rot.z,w=rot.w,x2=x+x,y2=y+y,z2=z+z;
- var xx=x *x2,xy=x *y2,xz=x *z2,yy=y *y2,yz=y *z2,zz=z *z2;
- var wx=w *x2,wy=w *y2,wz=w *z2,sx=scale.x,sy=scale.y,sz=scale.z;
- oe[0]=(1-(yy+zz))*sx;
- oe[1]=(xy+wz)*sx;
- oe[2]=(xz-wy)*sx;
- oe[3]=0;
- oe[4]=(xy-wz)*sy;
- oe[5]=(1-(xx+zz))*sy;
- oe[6]=(yz+wx)*sy;
- oe[7]=0;
- oe[8]=(xz+wy)*sz;
- oe[9]=(yz-wx)*sz;
- oe[10]=(1-(xx+yy))*sz;
- oe[11]=0;
- oe[12]=trans.x;
- oe[13]=trans.y;
- oe[14]=trans.z;
- oe[15]=1;
- }
- Matrix4x4.createLookAt=function(eye,target,up,out){
- var oE=out.elements;
- var xaxis=Matrix4x4._tempVector0;
- var yaxis=Matrix4x4._tempVector1;
- var zaxis=Matrix4x4._tempVector2;
- Vector3.subtract(eye,target,zaxis);
- Vector3.normalize(zaxis,zaxis);
- Vector3.cross(up,zaxis,xaxis);
- Vector3.normalize(xaxis,xaxis);
- Vector3.cross(zaxis,xaxis,yaxis);
- out.identity();
- oE[0]=xaxis.x;
- oE[4]=xaxis.y;
- oE[8]=xaxis.z;
- oE[1]=yaxis.x;
- oE[5]=yaxis.y;
- oE[9]=yaxis.z;
- oE[2]=zaxis.x;
- oE[6]=zaxis.y;
- oE[10]=zaxis.z;
- oE[12]=-Vector3.dot(xaxis,eye);
- oE[13]=-Vector3.dot(yaxis,eye);
- oE[14]=-Vector3.dot(zaxis,eye);
- }
- Matrix4x4.createPerspective=function(fov,aspect,znear,zfar,out){
- var yScale=1.0 / Math.tan(fov *0.5);
- var xScale=yScale / aspect;
- var halfWidth=znear / xScale;
- var halfHeight=znear / yScale;
- Matrix4x4.createPerspectiveOffCenter(-halfWidth,halfWidth,-halfHeight,halfHeight,znear,zfar,out);
- }
- Matrix4x4.createPerspectiveOffCenter=function(left,right,bottom,top,znear,zfar,out){
- var oe=out.elements;
- var zRange=zfar / (zfar-znear);
- oe[1]=oe[2]=oe[3]=oe[4]=oe[6]=oe[7]=oe[12]=oe[13]=oe[15]=0;
- oe[0]=2.0 *znear / (right-left);
- oe[5]=2.0 *znear / (top-bottom);
- oe[8]=(left+right)/ (right-left);
- oe[9]=(top+bottom)/ (top-bottom);
- oe[10]=-zRange;
- oe[11]=-1.0;
- oe[14]=-znear *zRange;
- }
- Matrix4x4.createOrthoOffCenter=function(left,right,bottom,top,znear,zfar,out){
- var oe=out.elements;
- var zRange=1.0 / (zfar-znear);
- oe[1]=oe[2]=oe[3]=oe[4]=oe[6]=oe[8]=oe[7]=oe[9]=oe[11]=0;
- oe[15]=1;
- oe[0]=2.0 / (right-left);
- oe[5]=2.0 / (top-bottom);
- oe[10]=-zRange;
- oe[12]=(left+right)/ (left-right);
- oe[13]=(top+bottom)/ (bottom-top);
- oe[14]=-znear *zRange;
- }
- Matrix4x4.billboard=function(objectPosition,cameraPosition,cameraRight,cameraUp,cameraForward,mat){
- Vector3.subtract(objectPosition,cameraPosition,Matrix4x4._tempVector0);
- var lengthSq=Vector3.scalarLengthSquared(Matrix4x4._tempVector0);
- if (MathUtils3D.isZero(lengthSq)){
- Vector3.scale(cameraForward,-1,Matrix4x4._tempVector1);
- Matrix4x4._tempVector1.cloneTo(Matrix4x4._tempVector0);
- }else {
- Vector3.scale(Matrix4x4._tempVector0,1 / Math.sqrt(lengthSq),Matrix4x4._tempVector0);
- }
- Vector3.cross(cameraUp,Matrix4x4._tempVector0,Matrix4x4._tempVector2);
- Vector3.normalize(Matrix4x4._tempVector2,Matrix4x4._tempVector2);
- Vector3.cross(Matrix4x4._tempVector0,Matrix4x4._tempVector2,Matrix4x4._tempVector3);
- var crosse=Matrix4x4._tempVector2;
- var finale=Matrix4x4._tempVector3;
- var diffee=Matrix4x4._tempVector0;
- var obpose=objectPosition;
- var mate=mat.elements;
- mate[0]=crosse.x;
- mate[1]=crosse.y;
- mate[2]=crosse.z;
- mate[3]=0.0;
- mate[4]=finale.x;
- mate[5]=finale.y;
- mate[6]=finale.z;
- mate[7]=0.0;
- mate[8]=diffee.x;
- mate[9]=diffee.y;
- mate[10]=diffee.z;
- mate[11]=0.0;
- mate[12]=obpose.x;
- mate[13]=obpose.y;
- mate[14]=obpose.z;
- mate[15]=1.0;
- }
- Matrix4x4.translation=function(v3,out){
- var oe=out.elements;
- oe[0]=oe[5]=oe[10]=oe[15]=1;
- oe[12]=v3.x;
- oe[13]=v3.y;
- oe[14]=v3.z;
- }
- __static(Matrix4x4,
- ['_tempMatrix4x4',function(){return this._tempMatrix4x4=new Matrix4x4();},'_tempVector0',function(){return this._tempVector0=new Vector3();},'_tempVector1',function(){return this._tempVector1=new Vector3();},'_tempVector2',function(){return this._tempVector2=new Vector3();},'_tempVector3',function(){return this._tempVector3=new Vector3();},'_tempQuaternion',function(){return this._tempQuaternion=new Quaternion();},'DEFAULT',function(){return this.DEFAULT=new Matrix4x4();},'ZERO',function(){return this.ZERO=new Matrix4x4(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);}
- ]);
- return Matrix4x4;
- })()
- /**
- *<code>Simulation</code> 类用于创建物理模拟器。
- */
- //class laya.d3.physics.PhysicsSimulation
- var PhysicsSimulation=(function(){
- function PhysicsSimulation(configuration,flags){
- /**@private */
- this._nativeDiscreteDynamicsWorld=null;
- /**@private */
- this._nativeCollisionWorld=null;
- /**@private */
- this._nativeDispatcher=null;
- /**@private */
- this._nativeCollisionConfiguration=null;
- /**@private */
- this._nativeBroadphase=null;
- /**@private */
- this._nativeSolverInfo=null;
- /**@private */
- this._nativeDispatchInfo=null;
- /**@private */
- this._nativeClosestRayResultCallback=null;
- /**@private */
- this._nativeAllHitsRayResultCallback=null;
- /**@private */
- this._nativeClosestConvexResultCallback=null;
- /**@private */
- this._nativeAllConvexResultCallback=null;
- /**@private */
- this._updatedRigidbodies=0;
- /**物理引擎在一帧中用于补偿减速的最大次数:模拟器每帧允许的最大模拟次数,如果引擎运行缓慢,可能需要增加该次数,否则模拟器会丢失“时间",引擎间隔时间小于maxSubSteps*fixedTimeStep非常重要。*/
- this.maxSubSteps=1;
- /**物理模拟器帧的间隔时间:通过减少fixedTimeStep可增加模拟精度,默认是1.0 / 60.0。*/
- this.fixedTimeStep=1.0 / 60.0;
- this._gravity=new Vector3(0,-10,0);
- this._nativeVector3Zero=new Laya3D._physics3D.btVector3(0,0,0);
- this._nativeDefaultQuaternion=new Laya3D._physics3D.btQuaternion(0,0,0,-1);
- this._collisionsUtils=new CollisionTool();
- this._previousFrameCollisions=[];
- this._currentFrameCollisions=[];
- this._physicsUpdateList=new PhysicsUpdateList();
- this._characters=[];
- (flags===void 0)&& (flags=0);
- this.maxSubSteps=configuration.maxSubSteps;
- this.fixedTimeStep=configuration.fixedTimeStep;
- var physics3D=Laya3D._physics3D;
- this._nativeCollisionConfiguration=new physics3D.btDefaultCollisionConfiguration();
- this._nativeDispatcher=new physics3D.btCollisionDispatcher(this._nativeCollisionConfiguration);
- this._nativeBroadphase=new physics3D.btDbvtBroadphase();
- this._nativeBroadphase.getOverlappingPairCache().setInternalGhostPairCallback(new physics3D.btGhostPairCallback());
- var conFlags=configuration.flags;
- if (conFlags & 0x1){
- this._nativeCollisionWorld=new physics3D.btCollisionWorld(this._nativeDispatcher,this._nativeBroadphase,this._nativeCollisionConfiguration);
- }else if (conFlags & 0x2){
- throw "PhysicsSimulation:SoftBody processing is not yet available";
- }else {
- var solver=new physics3D.btSequentialImpulseConstraintSolver();
- this._nativeDiscreteDynamicsWorld=new physics3D.btDiscreteDynamicsWorld(this._nativeDispatcher,this._nativeBroadphase,solver,this._nativeCollisionConfiguration);
- this._nativeCollisionWorld=this._nativeDiscreteDynamicsWorld;
- }
- if (this._nativeDiscreteDynamicsWorld){
- this._nativeSolverInfo=this._nativeDiscreteDynamicsWorld.getSolverInfo();
- this._nativeDispatchInfo=this._nativeDiscreteDynamicsWorld.getDispatchInfo();
- }
- this._nativeClosestRayResultCallback=new physics3D.ClosestRayResultCallback(this._nativeVector3Zero,this._nativeVector3Zero);
- this._nativeAllHitsRayResultCallback=new physics3D.AllHitsRayResultCallback(this._nativeVector3Zero,this._nativeVector3Zero);
- this._nativeClosestConvexResultCallback=new physics3D.ClosestConvexResultCallback(this._nativeVector3Zero,this._nativeVector3Zero);
- this._nativeAllConvexResultCallback=new physics3D.AllConvexResultCallback(this._nativeVector3Zero,this._nativeVector3Zero);
- physics3D._btGImpactCollisionAlgorithm_RegisterAlgorithm(this._nativeDispatcher.a);
- }
- __class(PhysicsSimulation,'laya.d3.physics.PhysicsSimulation');
- var __proto=PhysicsSimulation.prototype;
- /**
- *@private
- */
- __proto._simulate=function(deltaTime){
- this._updatedRigidbodies=0;
- if (this._nativeDiscreteDynamicsWorld)
- this._nativeDiscreteDynamicsWorld.stepSimulation(deltaTime,this.maxSubSteps,this.fixedTimeStep);
- else
- this._nativeCollisionWorld.PerformDiscreteCollisionDetection();
- }
- /**
- *@private
- */
- __proto._destroy=function(){
- var physics3D=Laya3D._physics3D;
- if (this._nativeDiscreteDynamicsWorld){
- physics3D.destroy(this._nativeDiscreteDynamicsWorld);
- this._nativeDiscreteDynamicsWorld=null;
- }else {
- physics3D.destroy(this._nativeCollisionWorld);
- this._nativeCollisionWorld=null;
- }
- physics3D.destroy(this._nativeBroadphase);
- this._nativeBroadphase=null;
- physics3D.destroy(this._nativeDispatcher);
- this._nativeDispatcher=null;
- physics3D.destroy(this._nativeCollisionConfiguration);
- this._nativeCollisionConfiguration=null;
- }
- /**
- *@private
- */
- __proto._addPhysicsCollider=function(component,group,mask){
- this._nativeCollisionWorld.addCollisionObject(component._nativeColliderObject,group,mask);
- }
- /**
- *@private
- */
- __proto._removePhysicsCollider=function(component){
- this._nativeCollisionWorld.removeCollisionObject(component._nativeColliderObject);
- }
- /**
- *@private
- */
- __proto._addRigidBody=function(rigidBody,group,mask){
- if (!this._nativeDiscreteDynamicsWorld)
- throw "Simulation:Cannot perform this action when the physics engine is set to CollisionsOnly";
- this._nativeCollisionWorld.addRigidBody(rigidBody._nativeColliderObject,group,mask);
- }
- /**
- *@private
- */
- __proto._removeRigidBody=function(rigidBody){
- if (!this._nativeDiscreteDynamicsWorld)
- throw "Simulation:Cannot perform this action when the physics engine is set to CollisionsOnly";
- this._nativeCollisionWorld.removeRigidBody(rigidBody._nativeColliderObject);
- }
- /**
- *@private
- */
- __proto._addCharacter=function(character,group,mask){
- if (!this._nativeDiscreteDynamicsWorld)
- throw "Simulation:Cannot perform this action when the physics engine is set to CollisionsOnly";
- this._nativeCollisionWorld.addCollisionObject(character._nativeColliderObject,group,mask);
- this._nativeCollisionWorld.addAction(character._nativeKinematicCharacter);
- }
- /**
- *@private
- */
- __proto._removeCharacter=function(character){
- if (!this._nativeDiscreteDynamicsWorld)
- throw "Simulation:Cannot perform this action when the physics engine is set to CollisionsOnly";
- this._nativeCollisionWorld.removeCollisionObject(character._nativeColliderObject);
- this._nativeCollisionWorld.removeAction(character._nativeKinematicCharacter);
- }
- /**
- *射线检测第一个碰撞物体。
- *@param from 起始位置。
- *@param to 结束位置。
- *@param out 碰撞结果。
- *@param collisonGroup 射线所属碰撞组。
- *@param collisionMask 与射线可产生碰撞的组。
- *@return 是否成功。
- */
- __proto.raycastFromTo=function(from,to,out,collisonGroup,collisionMask){
- (collisonGroup===void 0)&& (collisonGroup=Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER);
- (collisionMask===void 0)&& (collisionMask=Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER);
- var rayResultCall=this._nativeClosestRayResultCallback;
- var rayFrom=PhysicsSimulation._nativeTempVector30;
- var rayTo=PhysicsSimulation._nativeTempVector31;
- rayFrom.setValue(-from.x,from.y,from.z);
- rayTo.setValue(-to.x,to.y,to.z);
- rayResultCall.set_m_rayFromWorld(rayFrom);
- rayResultCall.set_m_rayToWorld(rayTo);
- rayResultCall.set_m_collisionFilterGroup(collisonGroup);
- rayResultCall.set_m_collisionFilterMask(collisionMask);
- rayResultCall.set_m_collisionObject(null);
- rayResultCall.set_m_closestHitFraction(1);
- this._nativeCollisionWorld.rayTest(rayFrom,rayTo,rayResultCall);
- if (rayResultCall.hasHit()){
- if (out){
- out.succeeded=true;
- out.collider=PhysicsComponent._physicObjectsMap[rayResultCall.get_m_collisionObject().getUserIndex()];
- out.hitFraction=rayResultCall.get_m_closestHitFraction();
- var nativePoint=rayResultCall.get_m_hitPointWorld();
- var point=out.point;
- point.x=-nativePoint.x();
- point.y=nativePoint.y();
- point.z=nativePoint.z();
- var nativeNormal=rayResultCall.get_m_hitNormalWorld();
- var normal=out.normal;
- normal.x=-nativeNormal.x();
- normal.y=nativeNormal.y();
- normal.z=nativeNormal.z();
- }
- return true;
- }else {
- if (out)
- out.succeeded=false;
- return false;
- }
- }
- /**
- *射线检测所有碰撞的物体。
- *@param from 起始位置。
- *@param to 结束位置。
- *@param out 碰撞结果[数组元素会被回收]。
- *@param collisonGroup 射线所属碰撞组。
- *@param collisionMask 与射线可产生碰撞的组。
- *@return 是否成功。
- */
- __proto.raycastAllFromTo=function(from,to,out,collisonGroup,collisionMask){
- (collisonGroup===void 0)&& (collisonGroup=Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER);
- (collisionMask===void 0)&& (collisionMask=Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER);
- var rayResultCall=this._nativeAllHitsRayResultCallback;
- var rayFrom=PhysicsSimulation._nativeTempVector30;
- var rayTo=PhysicsSimulation._nativeTempVector31;
- out.length=0;
- rayFrom.setValue(-from.x,from.y,from.z);
- rayTo.setValue(-to.x,to.y,to.z);
- rayResultCall.set_m_rayFromWorld(rayFrom);
- rayResultCall.set_m_rayToWorld(rayTo);
- rayResultCall.set_m_collisionFilterGroup(collisonGroup);
- rayResultCall.set_m_collisionFilterMask(collisionMask);
- var collisionObjects=rayResultCall.get_m_collisionObjects();
- var nativePoints=rayResultCall.get_m_hitPointWorld();
- var nativeNormals=rayResultCall.get_m_hitNormalWorld();
- var nativeFractions=rayResultCall.get_m_hitFractions();
- collisionObjects.clear();
- nativePoints.clear();
- nativeNormals.clear();
- nativeFractions.clear();
- this._nativeCollisionWorld.rayTest(rayFrom,rayTo,rayResultCall);
- var count=collisionObjects.size();
- if (count > 0){
- this._collisionsUtils.recoverAllHitResultsPool();
- for (var i=0;i < count;i++){
- var hitResult=this._collisionsUtils.getHitResult();
- out.push(hitResult);
- hitResult.succeeded=true;
- hitResult.collider=PhysicsComponent._physicObjectsMap[collisionObjects.at(i).getUserIndex()];
- hitResult.hitFraction=nativeFractions.at(i);
- var nativePoint=nativePoints.at(i);
- var pointE=hitResult.point;
- pointE.x=-nativePoint.x();
- pointE.y=nativePoint.y();
- pointE.z=nativePoint.z();
- var nativeNormal=nativeNormals.at(i);
- var normalE=hitResult.normal;
- normalE.x=-nativeNormal.x();
- normalE.y=nativeNormal.y();
- normalE.z=nativeNormal.z();
- }
- return true;
- }else {
- return false;
- }
- }
- /**
- *射线检测第一个碰撞物体。
- *@param ray 射线
- *@param outHitInfo 与该射线发生碰撞的第一个碰撞器的碰撞信息
- *@param distance 射线长度,默认为最大值
- *@param collisonGroup 射线所属碰撞组。
- *@param collisionMask 与射线可产生碰撞的组。
- *@return 是否检测成功。
- */
- __proto.rayCast=function(ray,outHitResult,distance,collisonGroup,collisionMask){
- (distance===void 0)&& (distance=2147483647);
- (collisonGroup===void 0)&& (collisonGroup=Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER);
- (collisionMask===void 0)&& (collisionMask=Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER);
- var from=ray.origin;
- var to=PhysicsSimulation._tempVector30;
- Vector3.normalize(ray.direction,to);
- Vector3.scale(to,distance,to);
- Vector3.add(from,to,to);
- return this.raycastFromTo(from,to,outHitResult,collisonGroup,collisionMask);
- }
- /**
- *射线检测所有碰撞的物体。
- *@param ray 射线
- *@param out 碰撞结果[数组元素会被回收]。
- *@param distance 射线长度,默认为最大值
- *@param collisonGroup 射线所属碰撞组。
- *@param collisionMask 与射线可产生碰撞的组。
- *@return 是否检测成功。
- */
- __proto.rayCastAll=function(ray,out,distance,collisonGroup,collisionMask){
- (distance===void 0)&& (distance=2147483647);
- (collisonGroup===void 0)&& (collisonGroup=Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER);
- (collisionMask===void 0)&& (collisionMask=Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER);
- var from=ray.origin;
- var to=PhysicsSimulation._tempVector30;
- Vector3.normalize(ray.direction,to);
- Vector3.scale(to,distance,to);
- Vector3.add(from,to,to);
- return this.raycastAllFromTo(from,to,out,collisonGroup,collisionMask);
- }
- /**
- *形状检测第一个碰撞的物体。
- *@param shape 形状。
- *@param fromPosition 世界空间起始位置。
- *@param toPosition 世界空间结束位置。
- *@param out 碰撞结果。
- *@param fromRotation 起始旋转。
- *@param toRotation 结束旋转。
- *@param collisonGroup 射线所属碰撞组。
- *@param collisionMask 与射线可产生碰撞的组。
- *@return 是否成功。
- */
- __proto.shapeCast=function(shape,fromPosition,toPosition,out,fromRotation,toRotation,collisonGroup,collisionMask,allowedCcdPenetration){
- (collisonGroup===void 0)&& (collisonGroup=Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER);
- (collisionMask===void 0)&& (collisionMask=Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER);
- (allowedCcdPenetration===void 0)&& (allowedCcdPenetration=0.0);
- var convexResultCall=this._nativeClosestConvexResultCallback;
- var convexPosFrom=PhysicsSimulation._nativeTempVector30;
- var convexPosTo=PhysicsSimulation._nativeTempVector31;
- var convexRotFrom=PhysicsSimulation._nativeTempQuaternion0;
- var convexRotTo=PhysicsSimulation._nativeTempQuaternion1;
- var convexTransform=PhysicsSimulation._nativeTempTransform0;
- var convexTransTo=PhysicsSimulation._nativeTempTransform1;
- var sweepShape=shape._nativeShape;
- convexPosFrom.setValue(-fromPosition.x,fromPosition.y,fromPosition.z);
- convexPosTo.setValue(-toPosition.x,toPosition.y,toPosition.z);
- convexResultCall.set_m_collisionFilterGroup(collisonGroup);
- convexResultCall.set_m_collisionFilterMask(collisionMask);
- convexTransform.setOrigin(convexPosFrom);
- convexTransTo.setOrigin(convexPosTo);
- if (fromRotation){
- convexRotFrom.setValue(-fromRotation.x,fromRotation.y,fromRotation.z,-fromRotation.w);
- convexTransform.setRotation(convexRotFrom);
- }else {
- convexTransform.setRotation(this._nativeDefaultQuaternion);
- }
- if (toRotation){
- convexRotTo.setValue(-toRotation.x,toRotation.y,toRotation.z,-toRotation.w);
- convexTransTo.setRotation(convexRotTo);
- }else {
- convexTransTo.setRotation(this._nativeDefaultQuaternion);
- }
- convexResultCall.set_m_hitCollisionObject(null);
- convexResultCall.set_m_closestHitFraction(1);
- this._nativeCollisionWorld.convexSweepTest(sweepShape,convexTransform,convexTransTo,convexResultCall,allowedCcdPenetration);
- if (convexResultCall.hasHit()){
- if (out){
- out.succeeded=true;
- out.collider=PhysicsComponent._physicObjectsMap[convexResultCall.get_m_hitCollisionObject().getUserIndex()];
- out.hitFraction=convexResultCall.get_m_closestHitFraction();
- var nativePoint=convexResultCall.get_m_hitPointWorld();
- var nativeNormal=convexResultCall.get_m_hitNormalWorld();
- var point=out.point;
- var normal=out.normal;
- point.x=-nativePoint.x();
- point.y=nativePoint.y();
- point.z=nativePoint.z();
- normal.x=-nativeNormal.x();
- normal.y=nativeNormal.y();
- normal.z=nativeNormal.z();
- }
- return true;
- }else {
- if (out)
- out.succeeded=false;
- return false;
- }
- }
- /**
- *形状检测所有碰撞的物体。
- *@param shape 形状。
- *@param fromPosition 世界空间起始位置。
- *@param toPosition 世界空间结束位置。
- *@param out 碰撞结果[数组元素会被回收]。
- *@param fromRotation 起始旋转。
- *@param toRotation 结束旋转。
- *@param collisonGroup 射线所属碰撞组。
- *@param collisionMask 与射线可产生碰撞的组。
- *@return 是否成功。
- */
- __proto.shapeCastAll=function(shape,fromPosition,toPosition,out,fromRotation,toRotation,collisonGroup,collisionMask,allowedCcdPenetration){
- (collisonGroup===void 0)&& (collisonGroup=Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER);
- (collisionMask===void 0)&& (collisionMask=Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER);
- (allowedCcdPenetration===void 0)&& (allowedCcdPenetration=0.0);
- var convexResultCall=this._nativeAllConvexResultCallback;
- var convexPosFrom=PhysicsSimulation._nativeTempVector30;
- var convexPosTo=PhysicsSimulation._nativeTempVector31;
- var convexRotFrom=PhysicsSimulation._nativeTempQuaternion0;
- var convexRotTo=PhysicsSimulation._nativeTempQuaternion1;
- var convexTransform=PhysicsSimulation._nativeTempTransform0;
- var convexTransTo=PhysicsSimulation._nativeTempTransform1;
- var sweepShape=shape._nativeShape;
- out.length=0;
- convexPosFrom.setValue(-fromPosition.x,fromPosition.y,fromPosition.z);
- convexPosTo.setValue(-toPosition.x,toPosition.y,toPosition.z);
- convexResultCall.set_m_collisionFilterGroup(collisonGroup);
- convexResultCall.set_m_collisionFilterMask(collisionMask);
- convexTransform.setOrigin(convexPosFrom);
- convexTransTo.setOrigin(convexPosTo);
- if (fromRotation){
- convexRotFrom.setValue(-fromRotation.x,fromRotation.y,fromRotation.z,-fromRotation.w);
- convexTransform.setRotation(convexRotFrom);
- }else {
- convexTransform.setRotation(this._nativeDefaultQuaternion);
- }
- if (toRotation){
- convexRotTo.setValue(-toRotation.x,toRotation.y,toRotation.z,-toRotation.w);
- convexTransTo.setRotation(convexRotTo);
- }else {
- convexTransTo.setRotation(this._nativeDefaultQuaternion);
- };
- var collisionObjects=convexResultCall.get_m_collisionObjects();
- collisionObjects.clear();
- this._nativeCollisionWorld.convexSweepTest(sweepShape,convexTransform,convexTransTo,convexResultCall,allowedCcdPenetration);
- var count=collisionObjects.size();
- if (count > 0){
- var nativePoints=convexResultCall.get_m_hitPointWorld();
- var nativeNormals=convexResultCall.get_m_hitNormalWorld();
- var nativeFractions=convexResultCall.get_m_hitFractions();
- for (var i=0;i < count;i++){
- var hitResult=this._collisionsUtils.getHitResult();
- out.push(hitResult);
- hitResult.succeeded=true;
- hitResult.collider=PhysicsComponent._physicObjectsMap[collisionObjects.at(i).getUserIndex()];
- hitResult.hitFraction=nativeFractions.at(i);
- var nativePoint=nativePoints.at(i);
- var point=hitResult.point;
- point.x=-nativePoint.x();
- point.y=nativePoint.y();
- point.z=nativePoint.z();
- var nativeNormal=nativeNormals.at(i);
- var normal=hitResult.normal;
- normal.x=-nativeNormal.x();
- normal.y=nativeNormal.y();
- normal.z=nativeNormal.z();
- }
- return true;
- }else {
- return false;
- }
- }
- /**
- *添加刚体运动的约束条件。
- *@param constraint 约束。
- *@param disableCollisionsBetweenLinkedBodies 是否禁用
- */
- __proto.addConstraint=function(constraint,disableCollisionsBetweenLinkedBodies){
- (disableCollisionsBetweenLinkedBodies===void 0)&& (disableCollisionsBetweenLinkedBodies=false);
- if (!this._nativeDiscreteDynamicsWorld)
- throw "Cannot perform this action when the physics engine is set to CollisionsOnly";
- this._nativeDiscreteDynamicsWorld.addConstraint(constraint._nativeConstraint,disableCollisionsBetweenLinkedBodies);
- constraint._simulation=this;
- }
- /**
- *移除刚体运动的约束条件。
- */
- __proto.removeConstraint=function(constraint){
- if (!this._nativeDiscreteDynamicsWorld)
- throw "Cannot perform this action when the physics engine is set to CollisionsOnly";
- this._nativeDiscreteDynamicsWorld.removeConstraint(constraint._nativeConstraint);
- }
- /**
- *@private
- */
- __proto._updatePhysicsTransformFromRender=function(){
- var elements=this._physicsUpdateList.elements;
- for (var i=0,n=this._physicsUpdateList.length;i < n;i++){
- var physicCollider=elements[i];
- physicCollider._derivePhysicsTransformation(false);
- physicCollider._inPhysicUpdateListIndex=-1;
- }
- this._physicsUpdateList.length=0;
- }
- /**
- *@private
- */
- __proto._updateCharacters=function(){
- for (var i=0,n=this._characters.length;i < n;i++){
- var character=this._characters[i];
- character._updateTransformComponent(character._nativeColliderObject.getWorldTransform());
- }
- }
- /**
- *@private
- */
- __proto._updateCollisions=function(){
- this._collisionsUtils.recoverAllContactPointsPool();
- var previous=this._currentFrameCollisions;
- this._currentFrameCollisions=this._previousFrameCollisions;
- this._currentFrameCollisions.length=0;
- this._previousFrameCollisions=previous;
- var loopCount=Stat.loopCount;
- var numManifolds=this._nativeDispatcher.getNumManifolds();
- for (var i=0;i < numManifolds;i++){
- var contactManifold=this._nativeDispatcher.getManifoldByIndexInternal(i);
- var componentA=PhysicsComponent._physicObjectsMap[contactManifold.getBody0().getUserIndex()];
- var componentB=PhysicsComponent._physicObjectsMap[contactManifold.getBody1().getUserIndex()];
- var collision=null;
- var isFirstCollision=false;
- var contacts=null;
- var isTrigger=componentA.isTrigger || componentB.isTrigger;
- if (isTrigger && ((componentA.owner)._needProcessTriggers || (componentB.owner)._needProcessTriggers)){
- var numContacts=contactManifold.getNumContacts();
- for (var j=0;j < numContacts;j++){
- var pt=contactManifold.getContactPoint(j);
- var distance=pt.getDistance();
- if (distance <=0){
- collision=this._collisionsUtils.getCollision(componentA,componentB);
- contacts=collision.contacts;
- isFirstCollision=collision._updateFrame!==loopCount;
- if (isFirstCollision){
- collision._isTrigger=true;
- contacts.length=0;
- }
- break ;
- }
- }
- }else if ((componentA.owner)._needProcessCollisions || (componentB.owner)._needProcessCollisions){
- if (componentA._enableProcessCollisions || componentB._enableProcessCollisions){
- numContacts=contactManifold.getNumContacts();
- for (j=0;j < numContacts;j++){
- pt=contactManifold.getContactPoint(j);
- distance=pt.getDistance();
- if (distance <=0){
- var contactPoint=this._collisionsUtils.getContactPoints();
- contactPoint.colliderA=componentA;
- contactPoint.colliderB=componentB;
- contactPoint.distance=distance;
- var nativeNormal=pt.get_m_normalWorldOnB();
- var normal=contactPoint.normal;
- normal.x=-nativeNormal.x();
- normal.y=nativeNormal.y();
- normal.z=nativeNormal.z();
- var nativePostionA=pt.get_m_positionWorldOnA();
- var positionOnA=contactPoint.positionOnA;
- positionOnA.x=-nativePostionA.x();
- positionOnA.y=nativePostionA.y();
- positionOnA.z=nativePostionA.z();
- var nativePostionB=pt.get_m_positionWorldOnB();
- var positionOnB=contactPoint.positionOnB;
- positionOnB.x=-nativePostionB.x();
- positionOnB.y=nativePostionB.y();
- positionOnB.z=nativePostionB.z();
- if (!collision){
- collision=this._collisionsUtils.getCollision(componentA,componentB);
- contacts=collision.contacts;
- isFirstCollision=collision._updateFrame!==loopCount;
- if (isFirstCollision){
- collision._isTrigger=false;
- contacts.length=0;
- }
- }
- contacts.push(contactPoint);
- }
- }
- }
- }
- if (collision && isFirstCollision){
- this._currentFrameCollisions.push(collision);
- collision._setUpdateFrame(loopCount);
- }
- }
- }
- /**
- *@private
- */
- __proto._eventScripts=function(){
- var loopCount=Stat.loopCount;
- for (var i=0,n=this._currentFrameCollisions.length;i < n;i++){
- var curFrameCol=this._currentFrameCollisions[i];
- var colliderA=curFrameCol._colliderA;
- var colliderB=curFrameCol._colliderB;
- if (colliderA.destroyed || colliderB.destroyed)
- continue ;
- if (loopCount-curFrameCol._lastUpdateFrame===1){
- var ownerA=colliderA.owner;
- var scriptsA=ownerA._scripts;
- if (scriptsA){
- if (curFrameCol._isTrigger){
- if (ownerA._needProcessTriggers){
- for (var j=0,m=scriptsA.length;j < m;j++)
- scriptsA[j].onTriggerStay(colliderB);
- }
- }else {
- if (ownerA._needProcessCollisions){
- for (j=0,m=scriptsA.length;j < m;j++){
- curFrameCol.other=colliderB;
- scriptsA[j].onCollisionStay(curFrameCol);
- }
- }
- }
- };
- var ownerB=colliderB.owner;
- var scriptsB=ownerB._scripts;
- if (scriptsB){
- if (curFrameCol._isTrigger){
- if (ownerB._needProcessTriggers){
- for (j=0,m=scriptsB.length;j < m;j++)
- scriptsB[j].onTriggerStay(colliderA);
- }
- }else {
- if (ownerB._needProcessCollisions){
- for (j=0,m=scriptsB.length;j < m;j++){
- curFrameCol.other=colliderA;
- scriptsB[j].onCollisionStay(curFrameCol);
- }
- }
- }
- }
- }else {
- ownerA=colliderA.owner;
- scriptsA=ownerA._scripts;
- if (scriptsA){
- if (curFrameCol._isTrigger){
- if (ownerA._needProcessTriggers){
- for (j=0,m=scriptsA.length;j < m;j++)
- scriptsA[j].onTriggerEnter(colliderB);
- }
- }else {
- if (ownerA._needProcessCollisions){
- for (j=0,m=scriptsA.length;j < m;j++){
- curFrameCol.other=colliderB;
- scriptsA[j].onCollisionEnter(curFrameCol);
- }
- }
- }
- }
- ownerB=colliderB.owner;
- scriptsB=ownerB._scripts;
- if (scriptsB){
- if (curFrameCol._isTrigger){
- if (ownerB._needProcessTriggers){
- for (j=0,m=scriptsB.length;j < m;j++)
- scriptsB[j].onTriggerEnter(colliderA);
- }
- }else {
- if (ownerB._needProcessCollisions){
- for (j=0,m=scriptsB.length;j < m;j++){
- curFrameCol.other=colliderA;
- scriptsB[j].onCollisionEnter(curFrameCol);
- }
- }
- }
- }
- }
- }
- for (i=0,n=this._previousFrameCollisions.length;i < n;i++){
- var preFrameCol=this._previousFrameCollisions[i];
- var preColliderA=preFrameCol._colliderA;
- var preColliderB=preFrameCol._colliderB;
- if (preColliderA.destroyed || preColliderB.destroyed)
- continue ;
- if (loopCount-preFrameCol._updateFrame===1){
- this._collisionsUtils.recoverCollision(preFrameCol);
- ownerA=preColliderA.owner;
- scriptsA=ownerA._scripts;
- if (scriptsA){
- if (preFrameCol._isTrigger){
- if (ownerA._needProcessTriggers){
- for (j=0,m=scriptsA.length;j < m;j++)
- scriptsA[j].onTriggerExit(preColliderB);
- }
- }else {
- if (ownerA._needProcessCollisions){
- for (j=0,m=scriptsA.length;j < m;j++){
- preFrameCol.other=preColliderB;
- scriptsA[j].onCollisionExit(preFrameCol);
- }
- }
- }
- }
- ownerB=preColliderB.owner;
- scriptsB=ownerB._scripts;
- if (scriptsB){
- if (preFrameCol._isTrigger){
- if (ownerB._needProcessTriggers){
- for (j=0,m=scriptsB.length;j < m;j++)
- scriptsB[j].onTriggerExit(preColliderA);
- }
- }else {
- if (ownerB._needProcessCollisions){
- for (j=0,m=scriptsB.length;j < m;j++){
- preFrameCol.other=preColliderA;
- scriptsB[j].onCollisionExit(preFrameCol);
- }
- }
- }
- }
- }
- }
- }
- /**
- *清除力。
- */
- __proto.clearForces=function(){
- if (!this._nativeDiscreteDynamicsWorld)
- throw "Cannot perform this action when the physics engine is set to CollisionsOnly";
- this._nativeDiscreteDynamicsWorld.clearForces();
- }
- /**
- *设置重力。
- */
- /**
- *获取重力。
- */
- __getset(0,__proto,'gravity',function(){
- if (!this._nativeDiscreteDynamicsWorld)
- throw "Simulation:Cannot perform this action when the physics engine is set to CollisionsOnly";
- return this._gravity;
- },function(value){
- if (!this._nativeDiscreteDynamicsWorld)
- throw "Simulation:Cannot perform this action when the physics engine is set to CollisionsOnly";
- this._gravity=value;
- var nativeGravity=PhysicsSimulation._nativeTempVector30;
- nativeGravity.setValue(-value.x,value.y,value.z);
- this._nativeDiscreteDynamicsWorld.setGravity(nativeGravity);
- });
- /**
- *设置是否进行连续碰撞检测。
- *@param value 是否进行连续碰撞检测。
- */
- /**
- *获取是否进行连续碰撞检测。
- *@return 是否进行连续碰撞检测。
- */
- __getset(0,__proto,'continuousCollisionDetection',function(){
- return this._nativeDispatchInfo.get_m_useContinuous();
- },function(value){
- this._nativeDispatchInfo.set_m_useContinuous(value);
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'speculativeContactRestitution',function(){
- if (!this._nativeDiscreteDynamicsWorld)
- throw "Simulation:Cannot Cannot perform this action when the physics engine is set to CollisionsOnly";
- return this._nativeDiscreteDynamicsWorld.getApplySpeculativeContactRestitution();
- },function(value){
- if (!this._nativeDiscreteDynamicsWorld)
- throw "Simulation:Cannot Cannot perform this action when the physics engine is set to CollisionsOnly";
- this._nativeDiscreteDynamicsWorld.setApplySpeculativeContactRestitution(value);
- });
- PhysicsSimulation.createConstraint=function(){}
- PhysicsSimulation.PHYSICSENGINEFLAGS_NONE=0x0;
- PhysicsSimulation.PHYSICSENGINEFLAGS_COLLISIONSONLY=0x1;
- PhysicsSimulation.PHYSICSENGINEFLAGS_SOFTBODYSUPPORT=0x2;
- PhysicsSimulation.PHYSICSENGINEFLAGS_MULTITHREADED=0x4;
- PhysicsSimulation.PHYSICSENGINEFLAGS_USEHARDWAREWHENPOSSIBLE=0x8;
- PhysicsSimulation.SOLVERMODE_RANDMIZE_ORDER=1;
- PhysicsSimulation.SOLVERMODE_FRICTION_SEPARATE=2;
- PhysicsSimulation.SOLVERMODE_USE_WARMSTARTING=4;
- PhysicsSimulation.SOLVERMODE_USE_2_FRICTION_DIRECTIONS=16;
- PhysicsSimulation.SOLVERMODE_ENABLE_FRICTION_DIRECTION_CACHING=32;
- PhysicsSimulation.SOLVERMODE_DISABLE_VELOCITY_DEPENDENT_FRICTION_DIRECTION=64;
- PhysicsSimulation.SOLVERMODE_CACHE_FRIENDLY=128;
- PhysicsSimulation.SOLVERMODE_SIMD=256;
- PhysicsSimulation.SOLVERMODE_INTERLEAVE_CONTACT_AND_FRICTION_CONSTRAINTS=512;
- PhysicsSimulation.SOLVERMODE_ALLOW_ZERO_LENGTH_FRICTION_DIRECTIONS=1024;
- PhysicsSimulation.disableSimulation=false;
- __static(PhysicsSimulation,
- ['_nativeTempVector30',function(){return this._nativeTempVector30=new Laya3D._physics3D.btVector3(0,0,0);},'_nativeTempVector31',function(){return this._nativeTempVector31=new Laya3D._physics3D.btVector3(0,0,0);},'_nativeTempQuaternion0',function(){return this._nativeTempQuaternion0=new Laya3D._physics3D.btQuaternion(0,0,0,1);},'_nativeTempQuaternion1',function(){return this._nativeTempQuaternion1=new Laya3D._physics3D.btQuaternion(0,0,0,1);},'_nativeTempTransform0',function(){return this._nativeTempTransform0=new Laya3D._physics3D.btTransform();},'_nativeTempTransform1',function(){return this._nativeTempTransform1=new Laya3D._physics3D.btTransform();},'_tempVector30',function(){return this._tempVector30=new Vector3();}
- ]);
- return PhysicsSimulation;
- })()
- /**
- *<code>PhysicsComponent</code> 类用于创建物理组件的父类。
- */
- //class laya.d3.physics.PhysicsComponent extends laya.components.Component
- var PhysicsComponent=(function(_super){
- function PhysicsComponent(collisionGroup,canCollideWith){
- /**@private */
- this._restitution=0.0;
- /**@private */
- this._friction=0.5;
- /**@private */
- this._rollingFriction=0.0;
- /**@private */
- this._ccdMotionThreshold=0.0;
- /**@private */
- this._ccdSweptSphereRadius=0.0;
- /**@private */
- this._colliderShape=null;
- /**@private */
- this._transformFlag=2147483647;
- /**@private */
- //this._nativeColliderObject=null;
- /**@private */
- //this._simulation=null;
- /**@private */
- this._enableProcessCollisions=true;
- /**@private */
- this._inPhysicUpdateListIndex=-1;
- /**是否可以缩放Shape。 */
- this.canScaleShape=true;
- PhysicsComponent.__super.call(this);
- this._collisionGroup=/*laya.d3.utils.Physics3DUtils.COLLISIONFILTERGROUP_DEFAULTFILTER*/0x1;
- this._canCollideWith=Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER;
- this._collisionGroup=collisionGroup;
- this._canCollideWith=canCollideWith;
- PhysicsComponent._physicObjectsMap[this.id]=this;
- }
- __class(PhysicsComponent,'laya.d3.physics.PhysicsComponent',_super);
- var __proto=PhysicsComponent.prototype;
- /**
- *@private
- */
- __proto._isValid=function(){
- return this._simulation && this._colliderShape && this._enabled;
- }
- /**
- *@inheritDoc
- */
- __proto._parse=function(data){
- (data.collisionGroup !=null)&& (this.collisionGroup=data.collisionGroup);
- (data.canCollideWith !=null)&& (this.canCollideWith=data.canCollideWith);
- (data.ccdMotionThreshold !=null)&& (this.ccdMotionThreshold=data.ccdMotionThreshold);
- (data.ccdSweptSphereRadius !=null)&& (this.ccdSweptSphereRadius=data.ccdSweptSphereRadius);
- }
- /**
- *@private
- */
- __proto._parseShape=function(shapesData){
- var shapeCount=shapesData.length;
- if (shapeCount===1){
- var shape=ColliderShape._creatShape(shapesData[0]);
- this.colliderShape=shape;
- }else {
- var compoundShape=new CompoundColliderShape();
- for (var i=0;i < shapeCount;i++){
- shape=ColliderShape._creatShape(shapesData[i]);
- compoundShape.addChildShape(shape);
- }
- this.colliderShape=compoundShape;
- }
- }
- /**
- *@private
- */
- __proto._onScaleChange=function(scale){
- this._colliderShape._setScale(scale);
- }
- /**
- *@private
- */
- __proto._setTransformFlag=function(type,value){
- if (value)
- this._transformFlag |=type;
- else
- this._transformFlag &=~type;
- }
- /**
- *@private
- */
- __proto._getTransformFlag=function(type){
- return (this._transformFlag & type)!=0;
- }
- /**
- *@private
- */
- __proto._addToSimulation=function(){}
- /**
- *@private
- */
- __proto._removeFromSimulation=function(){}
- /**
- *@private
- */
- __proto._derivePhysicsTransformation=function(force){
- this._innerDerivePhysicsTransformation(this._nativeColliderObject.getWorldTransform(),force);
- }
- /**
- *@private
- *通过渲染矩阵更新物理矩阵。
- */
- __proto._innerDerivePhysicsTransformation=function(physicTransformOut,force){
- var transform=(this.owner)._transform;
- var rotation=transform.rotation;
- if (force || this._getTransformFlag(/*laya.d3.core.Transform3D.TRANSFORM_WORLDPOSITION*/0x08)){
- var shapeOffset=this._colliderShape.localOffset;
- var position=transform.position;
- var nativePosition=PhysicsComponent._nativeVector30;
- if (shapeOffset.x!==0 || shapeOffset.y!==0 || shapeOffset.z!==0){
- var physicPosition=PhysicsComponent._tempVector30;
- PhysicsComponent.physicVector3TransformQuat(shapeOffset,rotation.x,rotation.y,rotation.z,rotation.w,physicPosition);
- Vector3.add(position,physicPosition,physicPosition);
- nativePosition.setValue(-physicPosition.x,physicPosition.y,physicPosition.z);
- }else {
- nativePosition.setValue(-position.x,position.y,position.z);
- }
- physicTransformOut.setOrigin(nativePosition);
- this._setTransformFlag(/*laya.d3.core.Transform3D.TRANSFORM_WORLDPOSITION*/0x08,false);
- }
- if (force || this._getTransformFlag(/*laya.d3.core.Transform3D.TRANSFORM_WORLDQUATERNION*/0x10)){
- var shapeRotation=this._colliderShape.localRotation;
- var nativeRotation=PhysicsComponent._nativeQuaternion0;
- if (shapeRotation.x!==0 || shapeRotation.y!==0 || shapeRotation.z!==0 || shapeRotation.w!==1){
- var physicRotation=PhysicsComponent._tempQuaternion0;
- PhysicsComponent.physicQuaternionMultiply(rotation.x,rotation.y,rotation.z,rotation.w,shapeRotation,physicRotation);
- nativeRotation.setValue(-physicRotation.x,physicRotation.y,physicRotation.z,-physicRotation.w);
- }else {
- nativeRotation.setValue(-rotation.x,rotation.y,rotation.z,-rotation.w);
- }
- physicTransformOut.setRotation(nativeRotation);
- this._setTransformFlag(/*laya.d3.core.Transform3D.TRANSFORM_WORLDQUATERNION*/0x10,false);
- }
- if (force || this._getTransformFlag(/*laya.d3.core.Transform3D.TRANSFORM_WORLDSCALE*/0x20)){
- this._onScaleChange(transform.scale);
- this._setTransformFlag(/*laya.d3.core.Transform3D.TRANSFORM_WORLDSCALE*/0x20,false);
- }
- }
- /**
- *@private
- *通过物理矩阵更新渲染矩阵。
- */
- __proto._updateTransformComponent=function(physicsTransform){
- var localOffset=this._colliderShape.localOffset;
- var localRotation=this._colliderShape.localRotation;
- var transform=(this.owner)._transform;
- var position=transform.position;
- var rotation=transform.rotation;
- var nativePosition=physicsTransform.getOrigin();
- var nativeRotation=physicsTransform.getRotation();
- var nativeRotX=-nativeRotation.x();
- var nativeRotY=nativeRotation.y();
- var nativeRotZ=nativeRotation.z();
- var nativeRotW=-nativeRotation.w();
- if (localOffset.x!==0 || localOffset.y!==0 || localOffset.z!==0){
- var rotShapePosition=PhysicsComponent._tempVector30;
- PhysicsComponent.physicVector3TransformQuat(localOffset,nativeRotX,nativeRotY,nativeRotZ,nativeRotW,rotShapePosition);
- position.x=-nativePosition.x()-rotShapePosition.x;
- position.y=nativePosition.y()-rotShapePosition.y;
- position.z=nativePosition.z()-rotShapePosition.z;
- }else {
- position.x=-nativePosition.x();
- position.y=nativePosition.y();
- position.z=nativePosition.z();
- }
- transform.position=position;
- if (localRotation.x!==0 || localRotation.y!==0 || localRotation.z!==0 || localRotation.w!==1){
- var invertShapeRotaion=PhysicsComponent._tempQuaternion0;
- localRotation.invert(invertShapeRotaion);
- PhysicsComponent.physicQuaternionMultiply(nativeRotX,nativeRotY,nativeRotZ,nativeRotW,invertShapeRotaion,rotation);
- }else {
- rotation.x=nativeRotX;
- rotation.y=nativeRotY;
- rotation.z=nativeRotZ;
- rotation.w=nativeRotW;
- }
- transform.rotation=rotation;
- }
- /**
- *@inheritDoc
- */
- __proto._onEnable=function(){
- this._simulation=(this.owner._scene).physicsSimulation;
- this._nativeColliderObject.setContactProcessingThreshold(1e30);
- if (this._colliderShape && this._enabled){
- this._derivePhysicsTransformation(true);
- this._addToSimulation();
- }
- }
- /**
- *@inheritDoc
- */
- __proto._onDisable=function(){
- if (this._colliderShape && this._enabled){
- this._removeFromSimulation();
- (this._inPhysicUpdateListIndex!==-1)&& (this._simulation._physicsUpdateList.remove(this));
- }
- this._simulation=null;
- }
- /**
- *@private
- */
- __proto._onShapeChange=function(colShape){
- var btColObj=this._nativeColliderObject;
- var flags=btColObj.getCollisionFlags();
- if (colShape.needsCustomCollisionCallback){
- if ((flags & 8)===0)
- btColObj.setCollisionFlags(flags | 8);
- }else {
- if ((flags & 8)> 0)
- btColObj.setCollisionFlags(flags ^ 8);
- }
- }
- /**
- *@inheritDoc
- */
- __proto._onAdded=function(){
- this.enabled=this._enabled;
- this.restitution=this._restitution;
- this.friction=this._friction;
- this.rollingFriction=this._rollingFriction;
- this.ccdMotionThreshold=this._ccdMotionThreshold;
- this.ccdSweptSphereRadius=this._ccdSweptSphereRadius;
- (this.owner).transform.on(/*laya.events.Event.TRANSFORM_CHANGED*/"transformchanged",this,this._onTransformChanged);
- }
- /**
- *@inheritDoc
- */
- __proto._onDestroy=function(){
- var physics3D=Laya3D._physics3D;
- delete PhysicsComponent._physicObjectsMap[this.id];
- physics3D.destroy(this._nativeColliderObject);
- this._colliderShape.destroy();
- _super.prototype._onDestroy.call(this);
- this._nativeColliderObject=null;
- this._colliderShape=null;
- this._simulation=null;
- (this.owner).transform.off(/*laya.events.Event.TRANSFORM_CHANGED*/"transformchanged",this,this._onTransformChanged);
- }
- /**
- *@private
- */
- __proto._onTransformChanged=function(flag){
- if (PhysicsComponent._addUpdateList){
- flag &=/*laya.d3.core.Transform3D.TRANSFORM_WORLDPOSITION*/0x08 | /*laya.d3.core.Transform3D.TRANSFORM_WORLDQUATERNION*/0x10 | /*laya.d3.core.Transform3D.TRANSFORM_WORLDSCALE*/0x20;
- if (flag){
- this._transformFlag |=flag;
- if (this._isValid()&& this._inPhysicUpdateListIndex===-1)
- this._simulation._physicsUpdateList.add(this);
- }
- }
- }
- /**
- *@inheritDoc
- */
- __proto._cloneTo=function(dest){
- var destPhysicsComponent=dest;
- destPhysicsComponent.restitution=this._restitution;
- destPhysicsComponent.friction=this._friction;
- destPhysicsComponent.rollingFriction=this._rollingFriction;
- destPhysicsComponent.ccdMotionThreshold=this._ccdMotionThreshold;
- destPhysicsComponent.ccdSweptSphereRadius=this._ccdSweptSphereRadius;
- destPhysicsComponent.collisionGroup=this._collisionGroup;
- destPhysicsComponent.canCollideWith=this._canCollideWith;
- destPhysicsComponent.canScaleShape=this.canScaleShape;
- (this._colliderShape)&& (destPhysicsComponent.colliderShape=this._colliderShape.clone());
- }
- /**
- *获取是否激活。
- */
- __getset(0,__proto,'isActive',function(){
- return this._nativeColliderObject ? this._nativeColliderObject.isActive():false;
- });
- /**
- *设置弹力。
- *@param 弹力。
- */
- /**
- *获取弹力。
- *@return 弹力。
- */
- __getset(0,__proto,'restitution',function(){
- return this._restitution;
- },function(value){
- this._restitution=value;
- this._nativeColliderObject && this._nativeColliderObject.setRestitution(value);
- });
- /**
- *设置摩擦力。
- *@param value 摩擦力。
- */
- /**
- *获取摩擦力。
- *@return 摩擦力。
- */
- __getset(0,__proto,'friction',function(){
- return this._friction;
- },function(value){
- this._friction=value;
- this._nativeColliderObject && this._nativeColliderObject.setFriction(value);
- });
- /**
- *设置滚动摩擦力。
- *@param 滚动摩擦力。
- */
- /**
- *获取滚动摩擦力。
- *@return 滚动摩擦力。
- */
- __getset(0,__proto,'rollingFriction',function(){
- return this._nativeColliderObject.getRollingFriction();
- },function(value){
- this._rollingFriction=value;
- this._nativeColliderObject && this._nativeColliderObject.setRollingFriction(value);
- });
- /**
- *设置用于连续碰撞检测(CCD)的速度阈值,当物体移动速度小于该值时不进行CCD检测,防止快速移动物体(例如:子弹)错误的穿过其它物体,0表示禁止。
- *@param value 连续碰撞检测(CCD)的速度阈值。
- */
- /**
- *获取用于连续碰撞检测(CCD)的速度阈值,当物体移动速度小于该值时不进行CCD检测,防止快速移动物体(例如:子弹)错误的穿过其它物体,0表示禁止。
- *@return 连续碰撞检测(CCD)的速度阈值。
- */
- __getset(0,__proto,'ccdMotionThreshold',function(){
- return this._ccdMotionThreshold;
- },function(value){
- this._ccdMotionThreshold=value;
- this._nativeColliderObject && this._nativeColliderObject.setCcdMotionThreshold(value);
- });
- /**
- *设置用于进入连续碰撞检测(CCD)范围的球半径。
- *@param 球半径。
- */
- /**
- *获取用于进入连续碰撞检测(CCD)范围的球半径。
- *@return 球半径。
- */
- __getset(0,__proto,'ccdSweptSphereRadius',function(){
- return this._ccdSweptSphereRadius;
- },function(value){
- this._ccdSweptSphereRadius=value;
- this._nativeColliderObject && this._nativeColliderObject.setCcdSweptSphereRadius(value);
- });
- /**
- *设置所属碰撞组。
- *@param 所属碰撞组。
- */
- /**
- *获取所属碰撞组。
- *@return 所属碰撞组。
- */
- __getset(0,__proto,'collisionGroup',function(){
- return this._collisionGroup;
- },function(value){
- if (this._collisionGroup!==value){
- this._collisionGroup=value;
- if (this._simulation && this._colliderShape && this._enabled){
- this._removeFromSimulation();
- this._addToSimulation();
- }
- }
- });
- /**
- *获取模拟器。
- *@return 模拟器。
- */
- __getset(0,__proto,'simulation',function(){
- return this._simulation;
- });
- /**
- *设置碰撞形状。
- */
- /**
- *获取碰撞形状。
- */
- __getset(0,__proto,'colliderShape',function(){
- return this._colliderShape;
- },function(value){
- var lastColliderShape=this._colliderShape;
- if (lastColliderShape){
- lastColliderShape._attatched=false;
- lastColliderShape._attatchedCollisionObject=null;
- }
- this._colliderShape=value;
- if (value){
- if (value._attatched){
- throw "PhysicsComponent: this shape has attatched to other entity.";
- }else {
- value._attatched=true;
- value._attatchedCollisionObject=this;
- }
- if (this._nativeColliderObject){
- this._nativeColliderObject.setCollisionShape(value._nativeShape);
- var canInSimulation=this._simulation && this._enabled;
- (canInSimulation && lastColliderShape)&& (this._removeFromSimulation());
- this._onShapeChange(value);
- if (canInSimulation){
- this._derivePhysicsTransformation(true);
- this._addToSimulation();
- }
- }
- }else {
- if (this._simulation && this._enabled)
- lastColliderShape && this._removeFromSimulation();
- }
- });
- /**
- *@inheritDoc
- */
- __getset(0,__proto,'enabled',_super.prototype._$get_enabled,function(value){
- if (this._simulation && this._colliderShape){
- if (value){
- this._derivePhysicsTransformation(true);
- this._addToSimulation();
- }else {
- this._removeFromSimulation();
- }
- }
- Laya.superSet(Component,this,'enabled',value);
- });
- /**
- *设置可碰撞的碰撞组。
- *@param 可碰撞组。
- */
- /**
- *获取可碰撞的碰撞组。
- *@return 可碰撞组。
- */
- __getset(0,__proto,'canCollideWith',function(){
- return this._canCollideWith;
- },function(value){
- if (this._canCollideWith!==value){
- this._canCollideWith=value;
- if (this._simulation && this._colliderShape && this._enabled){
- this._removeFromSimulation();
- this._addToSimulation();
- }
- }
- });
- PhysicsComponent._createAffineTransformationArray=function(tranX,tranY,tranZ,rotX,rotY,rotZ,rotW,scale,outE){
- var x2=rotX+rotX,y2=rotY+rotY,z2=rotZ+rotZ;
- var xx=rotX *x2,xy=rotX *y2,xz=rotX *z2,yy=rotY *y2,yz=rotY *z2,zz=rotZ *z2;
- var wx=rotW *x2,wy=rotW *y2,wz=rotW *z2,sx=scale[0],sy=scale[1],sz=scale[2];
- outE[0]=(1-(yy+zz))*sx;
- outE[1]=(xy+wz)*sx;
- outE[2]=(xz-wy)*sx;
- outE[3]=0;
- outE[4]=(xy-wz)*sy;
- outE[5]=(1-(xx+zz))*sy;
- outE[6]=(yz+wx)*sy;
- outE[7]=0;
- outE[8]=(xz+wy)*sz;
- outE[9]=(yz-wx)*sz;
- outE[10]=(1-(xx+yy))*sz;
- outE[11]=0;
- outE[12]=tranX;
- outE[13]=tranY;
- outE[14]=tranZ;
- outE[15]=1;
- }
- PhysicsComponent.physicVector3TransformQuat=function(source,qx,qy,qz,qw,out){
- 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;
- out.x=ix *qw+iw *-qx+iy *-qz-iz *-qy;
- out.y=iy *qw+iw *-qy+iz *-qx-ix *-qz;
- out.z=iz *qw+iw *-qz+ix *-qy-iy *-qx;
- }
- PhysicsComponent.physicQuaternionMultiply=function(lx,ly,lz,lw,right,out){
- var rx=right.x;
- var ry=right.y;
- var rz=right.z;
- var rw=right.w;
- var a=(ly *rz-lz *ry);
- var b=(lz *rx-lx *rz);
- var c=(lx *ry-ly *rx);
- var d=(lx *rx+ly *ry+lz *rz);
- out.x=(lx *rw+rx *lw)+a;
- out.y=(ly *rw+ry *lw)+b;
- out.z=(lz *rw+rz *lw)+c;
- out.w=lw *rw-d;
- }
- PhysicsComponent.ACTIVATIONSTATE_ACTIVE_TAG=1;
- PhysicsComponent.ACTIVATIONSTATE_ISLAND_SLEEPING=2;
- PhysicsComponent.ACTIVATIONSTATE_WANTS_DEACTIVATION=3;
- PhysicsComponent.ACTIVATIONSTATE_DISABLE_DEACTIVATION=4;
- PhysicsComponent.ACTIVATIONSTATE_DISABLE_SIMULATION=5;
- PhysicsComponent.COLLISIONFLAGS_STATIC_OBJECT=1;
- PhysicsComponent.COLLISIONFLAGS_KINEMATIC_OBJECT=2;
- PhysicsComponent.COLLISIONFLAGS_NO_CONTACT_RESPONSE=4;
- PhysicsComponent.COLLISIONFLAGS_CUSTOM_MATERIAL_CALLBACK=8;
- PhysicsComponent.COLLISIONFLAGS_CHARACTER_OBJECT=16;
- PhysicsComponent.COLLISIONFLAGS_DISABLE_VISUALIZE_OBJECT=32;
- PhysicsComponent.COLLISIONFLAGS_DISABLE_SPU_COLLISION_PROCESSING=64;
- PhysicsComponent._physicObjectsMap={};
- PhysicsComponent._addUpdateList=true;
- __static(PhysicsComponent,
- ['_tempVector30',function(){return this._tempVector30=new Vector3();},'_tempQuaternion0',function(){return this._tempQuaternion0=new Quaternion();},'_tempQuaternion1',function(){return this._tempQuaternion1=new Quaternion();},'_tempMatrix4x40',function(){return this._tempMatrix4x40=new Matrix4x4();},'_nativeVector30',function(){return this._nativeVector30=new Laya3D._physics3D.btVector3(0,0,0);},'_nativeQuaternion0',function(){return this._nativeQuaternion0=new Laya3D._physics3D.btQuaternion(0,0,0,1);}
- ]);
- return PhysicsComponent;
- })(Component)
- /**
- *<code>Render</code> 类用于渲染器的父类,抽象类不允许实例。
- */
- //class laya.d3.core.render.BaseRender extends laya.events.EventDispatcher
- var BaseRender=(function(_super){
- function BaseRender(owner){
- /**@private */
- //this._id=0;
- /**@private */
- //this._lightmapScaleOffset=null;
- /**@private */
- //this._lightmapIndex=0;
- /**@private */
- //this._receiveShadow=false;
- /**@private */
- //this._materialsInstance=null;
- /**@private */
- //this._castShadow=false;
- /**@private [实现IListPool接口]*/
- this._indexInList=-1;
- /**@private */
- this._indexInCastShadowList=-1;
- /**@private */
- //this._bounds=null;
- /**@private */
- this._boundsChange=true;
- /**@private */
- //this._enable=false;
- /**@private */
- //this._shaderValues=null;
- /**@private */
- //this._defineDatas=null;
- /**@private */
- //this._scene=null;
- /**@private */
- //this._owner=null;
- /**@private */
- //this._renderElements=null;
- /**@private */
- //this._distanceForSort=NaN;
- /**@private */
- this._visible=true;
- /**@private */
- //this._octreeNode=null;
- /**@private */
- this._indexInOctreeMotionList=-1;
- /**@private */
- this._updateMark=-1;
- /**@private */
- this._updateRenderType=-1;
- /**@private */
- this._isPartOfStaticBatch=false;
- /**@private */
- this._staticBatch=null;
- /**排序矫正值。*/
- //this.sortingFudge=NaN;
- /**@private [NATIVE]*/
- //this._cullingBufferIndex=0;
- BaseRender.__super.call(this);
- this._sharedMaterials=[];
- this._id=++BaseRender._uniqueIDCounter;
- this._indexInCastShadowList=-1;
- this._bounds=new Bounds(Vector3._ZERO,Vector3._ZERO);
- if (Render.supportWebGLPlusCulling){
- var length=FrustumCulling._cullingBufferLength;
- this._cullingBufferIndex=length;
- var cullingBuffer=FrustumCulling._cullingBuffer;
- var resizeLength=length+7;
- if (resizeLength >=cullingBuffer.length){
- var temp=cullingBuffer;
- cullingBuffer=FrustumCulling._cullingBuffer=new Float32Array(cullingBuffer.length+4096);
- cullingBuffer.set(temp,0);
- }
- cullingBuffer[length]=2;
- FrustumCulling._cullingBufferLength=resizeLength;
- }
- this._renderElements=[];
- this._owner=owner;
- this._enable=true;
- this._materialsInstance=[];
- this._shaderValues=new ShaderData(null);
- this._defineDatas=new DefineDatas();
- this.lightmapIndex=-1;
- this._castShadow=false;
- this.receiveShadow=false;
- this.sortingFudge=0.0;
- (owner)&& (this._owner.transform.on(/*laya.events.Event.TRANSFORM_CHANGED*/"transformchanged",this,this._onWorldMatNeedChange));
- }
- __class(BaseRender,'laya.d3.core.render.BaseRender',_super);
- var __proto=BaseRender.prototype;
- Laya.imps(__proto,{"laya.resource.ISingletonElement":true,"laya.d3.core.scene.IOctreeObject":true})
- /**
- *@private
- */
- __proto._getOctreeNode=function(){
- return this._octreeNode;
- }
- /**
- *@private
- */
- __proto._setOctreeNode=function(value){
- this._octreeNode=value;
- }
- /**
- *@private
- */
- __proto._getIndexInMotionList=function(){
- return this._indexInOctreeMotionList;
- }
- /**
- *@private
- */
- __proto._setIndexInMotionList=function(value){
- this._indexInOctreeMotionList=value;
- }
- /**
- *@private
- */
- __proto._changeMaterialReference=function(lastValue,value){
- (lastValue)&& (lastValue._removeReference());
- value._addReference();
- }
- /**
- *@private
- */
- __proto._getInstanceMaterial=function(material,index){
- var insMat=/*__JS__ */new material.constructor();
- material.cloneTo(insMat);
- insMat.name=insMat.name+"(Instance)";
- this._materialsInstance[index]=true;
- this._changeMaterialReference(this._sharedMaterials[index],insMat);
- this._sharedMaterials[index]=insMat;
- return insMat;
- }
- /**
- *@private
- */
- __proto._applyLightMapParams=function(){
- if (this._scene && this._lightmapIndex >=0){
- var lightMaps=this._scene.getlightmaps();
- if (this._lightmapIndex < lightMaps.length){
- this._defineDatas.add(RenderableSprite3D.SAHDERDEFINE_LIGHTMAP);
- this._shaderValues.setTexture(RenderableSprite3D.LIGHTMAP,lightMaps[this._lightmapIndex]);
- }else {
- this._defineDatas.remove(RenderableSprite3D.SAHDERDEFINE_LIGHTMAP);
- }
- }else {
- this._defineDatas.remove(RenderableSprite3D.SAHDERDEFINE_LIGHTMAP);
- }
- }
- /**
- *@private
- */
- __proto._onWorldMatNeedChange=function(flag){
- this._boundsChange=true;
- if (this._octreeNode){
- flag &=/*laya.d3.core.Transform3D.TRANSFORM_WORLDPOSITION*/0x08 | /*laya.d3.core.Transform3D.TRANSFORM_WORLDQUATERNION*/0x10 | /*laya.d3.core.Transform3D.TRANSFORM_WORLDSCALE*/0x20;
- if (flag){
- if (this._indexInOctreeMotionList===-1)
- this._octreeNode._octree.addMotionObject(this);
- }
- }
- }
- /**
- *@private
- */
- __proto._calculateBoundingBox=function(){
- throw("BaseRender: must override it.");
- }
- /**
- *@private [实现ISingletonElement接口]
- */
- __proto._getIndexInList=function(){
- return this._indexInList;
- }
- /**
- *@private [实现ISingletonElement接口]
- */
- __proto._setIndexInList=function(index){
- this._indexInList=index;
- }
- /**
- *@private
- */
- __proto._setBelongScene=function(scene){
- if (this._scene!==scene){
- this._scene=scene;
- this._applyLightMapParams();
- }
- }
- /**
- *@private
- *@param boundFrustum 如果boundFrustum为空则为摄像机不裁剪模式。
- */
- __proto._needRender=function(boundFrustum){
- return true;
- }
- /**
- *@private
- */
- __proto._renderUpdate=function(context,transform){}
- /**
- *@private
- */
- __proto._renderUpdateWithCamera=function(context,transform){}
- /**
- *@private
- */
- __proto._revertBatchRenderUpdate=function(context){}
- /**
- *@private
- */
- __proto._destroy=function(){
- (this._indexInOctreeMotionList!==-1)&& (this._octreeNode._octree.removeMotionObject(this));
- this.offAll();
- var i=0,n=0;
- for (i=0,n=this._renderElements.length;i < n;i++)
- this._renderElements[i].destroy();
- for (i=0,n=this._sharedMaterials.length;i < n;i++)
- (this._sharedMaterials[i].destroyed)|| (this._sharedMaterials[i]._removeReference());
- this._renderElements=null;
- this._owner=null;
- this._sharedMaterials=null;
- this._bounds=null;
- this._lightmapScaleOffset=null;
- }
- /**
- *获取包围盒,只读,不允许修改其值。
- *@return 包围盒。
- */
- __getset(0,__proto,'bounds',function(){
- if (this._boundsChange){
- this._calculateBoundingBox();
- this._boundsChange=false;
- }
- return this._bounds;
- });
- /**
- *获取唯一标识ID,通常用于识别。
- */
- __getset(0,__proto,'id',function(){
- return this._id;
- });
- /**
- *设置第一个实例材质。
- *@param value 第一个实例材质。
- */
- /**
- *返回第一个实例材质,第一次使用会拷贝实例对象。
- *@return 第一个实例材质。
- */
- __getset(0,__proto,'material',function(){
- var material=this._sharedMaterials[0];
- if (material && !this._materialsInstance[0]){
- var insMat=this._getInstanceMaterial(material,0);
- var renderElement=this._renderElements[0];
- (renderElement)&& (renderElement.material=insMat);
- }
- return this._sharedMaterials[0];
- },function(value){
- this.sharedMaterial=value;
- });
- /**
- *是否是静态的一部分。
- */
- __getset(0,__proto,'isPartOfStaticBatch',function(){
- return this._isPartOfStaticBatch;
- });
- /**
- *设置第一个材质。
- *@param value 第一个材质。
- */
- /**
- *返回第一个材质。
- *@return 第一个材质。
- */
- __getset(0,__proto,'sharedMaterial',function(){
- return this._sharedMaterials[0];
- },function(value){
- var lastValue=this._sharedMaterials[0];
- if (lastValue!==value){
- this._sharedMaterials[0]=value;
- this._materialsInstance[0]=false;
- this._changeMaterialReference(lastValue,value);
- var renderElement=this._renderElements[0];
- (renderElement)&& (renderElement.material=value);
- }
- });
- /**
- *设置光照贴图的索引。
- *@param value 光照贴图的索引。
- */
- /**
- *获取光照贴图的索引。
- *@return 光照贴图的索引。
- */
- __getset(0,__proto,'lightmapIndex',function(){
- return this._lightmapIndex;
- },function(value){
- if (this._lightmapIndex!==value){
- this._lightmapIndex=value;
- this._applyLightMapParams();
- }
- });
- /**
- *设置光照贴图的缩放和偏移。
- *@param 光照贴图的缩放和偏移。
- */
- /**
- *获取光照贴图的缩放和偏移。
- *@return 光照贴图的缩放和偏移。
- */
- __getset(0,__proto,'lightmapScaleOffset',function(){
- return this._lightmapScaleOffset;
- },function(value){
- this._lightmapScaleOffset=value;
- this._shaderValues.setVector(RenderableSprite3D.LIGHTMAPSCALEOFFSET,value);
- this._defineDatas.add(RenderableSprite3D.SHADERDEFINE_SCALEOFFSETLIGHTINGMAPUV);
- });
- /**
- *设置是否产生阴影。
- *@param value 是否产生阴影。
- */
- /**
- *获取是否产生阴影。
- *@return 是否产生阴影。
- */
- __getset(0,__proto,'castShadow',function(){
- return this._castShadow;
- },function(value){
- if (this._castShadow!==value){
- if (this._owner.activeInHierarchy){
- if (value)
- this._scene._addShadowCastRenderObject(this);
- else
- this._scene._removeShadowCastRenderObject(this);
- }
- this._castShadow=value;
- }
- });
- /**
- *设置是否可用。
- *@param value 是否可用。
- */
- /**
- *获取是否可用。
- *@return 是否可用。
- */
- __getset(0,__proto,'enable',function(){
- return this._enable;
- },function(value){
- this._enable=!!value;
- });
- /**
- *设置实例材质列表。
- *@param value 实例材质列表。
- */
- /**
- *获取潜拷贝实例材质列表,第一次使用会拷贝实例对象。
- *@return 浅拷贝实例材质列表。
- */
- __getset(0,__proto,'materials',function(){
- for (var i=0,n=this._sharedMaterials.length;i < n;i++){
- if (!this._materialsInstance[i]){
- var insMat=this._getInstanceMaterial(this._sharedMaterials[i],i);
- var renderElement=this._renderElements[i];
- (renderElement)&& (renderElement.material=insMat);
- }
- }
- return this._sharedMaterials.slice();
- },function(value){
- this.sharedMaterials=value;
- });
- /**
- *设置材质列表。
- *@param value 材质列表。
- */
- /**
- *获取浅拷贝材质列表。
- *@return 浅拷贝材质列表。
- */
- __getset(0,__proto,'sharedMaterials',function(){
- return this._sharedMaterials.slice();
- },function(value){
- var mats=this._sharedMaterials;
- for (var i=0,n=mats.length;i < n;i++)
- mats[i]._removeReference();
- if (value){
- var count=value.length;
- this._materialsInstance.length=count;
- mats.length=count;
- for (i=0;i < count;i++){
- var lastMat=mats[i];
- var mat=value[i];
- if (lastMat!==mat){
- this._materialsInstance[i]=false;
- var renderElement=this._renderElements[i];
- (renderElement)&& (renderElement.material=mat);
- }
- mat._addReference();
- mats[i]=mat;
- }
- }else {
- throw new Error("BaseRender: shadredMaterials value can't be null.");
- }
- });
- /**
- *设置是否接收阴影属性
- */
- /**
- *获得是否接收阴影属性
- */
- __getset(0,__proto,'receiveShadow',function(){
- return this._receiveShadow;
- },function(value){
- if (this._receiveShadow!==value){
- this._receiveShadow=value;
- if (value)
- this._defineDatas.add(RenderableSprite3D.SHADERDEFINE_RECEIVE_SHADOW);
- else
- this._defineDatas.remove(RenderableSprite3D.SHADERDEFINE_RECEIVE_SHADOW);
- }
- });
- BaseRender._uniqueIDCounter=0;
- __static(BaseRender,
- ['_tempBoundBoxCorners',function(){return this._tempBoundBoxCorners=/*new vector.<>*/[new Vector3(),new Vector3(),new Vector3(),new Vector3(),new Vector3(),new Vector3(),new Vector3(),new Vector3()];}
- ]);
- return BaseRender;
- })(EventDispatcher)
- /**
- *<code>Script3D</code> 类用于创建脚本的父类,该类为抽象类,不允许实例。
- */
- //class laya.d3.component.Script3D extends laya.components.Component
- var Script3D=(function(_super){
- function Script3D(){
- Script3D.__super.call(this);;
- }
- __class(Script3D,'laya.d3.component.Script3D',_super);
- var __proto=Script3D.prototype;
- /**
- *@private
- */
- __proto._checkProcessTriggers=function(){
- var prototype=laya.d3.component.Script3D.prototype;
- if (this.onTriggerEnter!==prototype.onTriggerEnter)
- return true;
- if (this.onTriggerStay!==prototype.onTriggerStay)
- return true;
- if (this.onTriggerExit!==prototype.onTriggerExit)
- return true;
- return false;
- }
- /**
- *@private
- */
- __proto._checkProcessCollisions=function(){
- var prototype=laya.d3.component.Script3D.prototype;
- if (this.onCollisionEnter!==prototype.onCollisionEnter)
- return true;
- if (this.onCollisionStay!==prototype.onCollisionStay)
- return true;
- if (this.onCollisionExit!==prototype.onCollisionExit)
- return true;
- return false;
- }
- /**
- *@inheritDoc
- */
- __proto._onAwake=function(){
- this.onAwake();
- if (this.onStart!==laya.d3.component.Script3D.prototype.onStart)
- Laya.startTimer.callLater(this,this.onStart);
- }
- /**
- *@inheritDoc
- */
- __proto._onEnable=function(){
- (this.owner)._scene._scriptPool.add(this);
- var proto=laya.d3.component.Script3D.prototype;
- if (this.onKeyDown!==proto.onKeyDown){
- Laya.stage.on(/*laya.events.Event.KEY_DOWN*/"keydown",this,this.onKeyDown);
- }
- if (this.onKeyPress!==proto.onKeyPress){
- Laya.stage.on(/*laya.events.Event.KEY_PRESS*/"keypress",this,this.onKeyUp);
- }
- if (this.onKeyUp!==proto.onKeyUp){
- Laya.stage.on(/*laya.events.Event.KEY_UP*/"keyup",this,this.onKeyUp);
- }
- }
- /**
- *@inheritDoc
- */
- __proto._onDisable=function(){
- (this.owner)._scene._scriptPool.remove(this);
- this.owner.offAllCaller(this);
- Laya.stage.offAllCaller(this);
- }
- /**
- *@inheritDoc
- */
- __proto._isScript=function(){
- return true;
- }
- /**
- *@inheritDoc
- */
- __proto._onAdded=function(){
- var sprite=this.owner;
- var scripts=sprite._scripts;
- scripts || (sprite._scripts=scripts=[]);
- scripts.push(this);
- if (!sprite._needProcessCollisions)
- sprite._needProcessCollisions=this._checkProcessCollisions();
- if (!sprite._needProcessTriggers)
- sprite._needProcessTriggers=this._checkProcessTriggers();
- }
- /**
- *@inheritDoc
- */
- __proto._onDestroy=function(){
- var scripts=(this.owner)._scripts;
- scripts.splice(scripts.indexOf(this),1);
- var sprite=this.owner;
- sprite._needProcessTriggers=false;
- for (var i=0,n=scripts.length;i < n;i++){
- if (scripts[i]._checkProcessTriggers()){
- sprite._needProcessTriggers=true;
- break ;
- }
- }
- sprite._needProcessCollisions=false;
- for (i=0,n=scripts.length;i < n;i++){
- if (scripts[i]._checkProcessCollisions()){
- sprite._needProcessCollisions=true;
- break ;
- }
- }
- this.onDestroy();
- }
- /**
- *创建后只执行一次
- *此方法为虚方法,使用时重写覆盖即可
- */
- __proto.onAwake=function(){}
- /**
- *每次启动后执行
- *此方法为虚方法,使用时重写覆盖即可
- */
- __proto.onEnable=function(){}
- /**
- *第一次执行update之前执行,只会执行一次
- *此方法为虚方法,使用时重写覆盖即可
- */
- __proto.onStart=function(){}
- /**
- *开始触发时执行
- *此方法为虚方法,使用时重写覆盖即可
- */
- __proto.onTriggerEnter=function(other){}
- /**
- *持续触发时执行
- *此方法为虚方法,使用时重写覆盖即可
- */
- __proto.onTriggerStay=function(other){}
- /**
- *结束触发时执行
- *此方法为虚方法,使用时重写覆盖即可
- */
- __proto.onTriggerExit=function(other){}
- /**
- *开始碰撞时执行
- *此方法为虚方法,使用时重写覆盖即可
- */
- __proto.onCollisionEnter=function(collision){}
- /**
- *持续碰撞时执行
- *此方法为虚方法,使用时重写覆盖即可
- */
- __proto.onCollisionStay=function(collision){}
- /**
- *结束碰撞时执行
- *此方法为虚方法,使用时重写覆盖即可
- */
- __proto.onCollisionExit=function(collision){}
- /**
- *鼠标按下时执行
- *此方法为虚方法,使用时重写覆盖即可
- */
- __proto.onMouseDown=function(){}
- /**
- *鼠标拖拽时执行
- *此方法为虚方法,使用时重写覆盖即可
- */
- __proto.onMouseDrag=function(){}
- /**
- *鼠标点击时执行
- *此方法为虚方法,使用时重写覆盖即可
- */
- __proto.onMouseClick=function(){}
- /**
- *鼠标弹起时执行
- *此方法为虚方法,使用时重写覆盖即可
- */
- __proto.onMouseUp=function(){}
- /**
- *鼠标进入时执行
- *此方法为虚方法,使用时重写覆盖即可
- */
- __proto.onMouseEnter=function(){}
- /**
- *鼠标经过时执行
- *此方法为虚方法,使用时重写覆盖即可
- */
- __proto.onMouseOver=function(){}
- /**
- *鼠标离开时执行
- *此方法为虚方法,使用时重写覆盖即可
- */
- __proto.onMouseOut=function(){}
- /**
- *键盘按下时执行
- *此方法为虚方法,使用时重写覆盖即可
- */
- __proto.onKeyDown=function(e){}
- /**
- *键盘产生一个字符时执行
- *此方法为虚方法,使用时重写覆盖即可
- */
- __proto.onKeyPress=function(e){}
- /**
- *键盘抬起时执行
- *此方法为虚方法,使用时重写覆盖即可
- */
- __proto.onKeyUp=function(e){}
- /**
- *每帧更新时执行
- *此方法为虚方法,使用时重写覆盖即可
- */
- __proto.onUpdate=function(){}
- /**
- *每帧更新时执行,在update之后执行
- *此方法为虚方法,使用时重写覆盖即可
- */
- __proto.onLateUpdate=function(){}
- /**
- *渲染之前执行
- *此方法为虚方法,使用时重写覆盖即可
- */
- __proto.onPreRender=function(){}
- /**
- *渲染之后执行
- *此方法为虚方法,使用时重写覆盖即可
- */
- __proto.onPostRender=function(){}
- /**
- *禁用时执行
- *此方法为虚方法,使用时重写覆盖即可
- */
- __proto.onDisable=function(){}
- /**
- *销毁时执行
- *此方法为虚方法,使用时重写覆盖即可
- */
- __proto.onDestroy=function(){}
- /**
- *@inheritDoc
- */
- __getset(0,__proto,'isSingleton',function(){
- return false;
- });
- return Script3D;
- })(Component)
- /**
- *<code>Transform3D</code> 类用于实现3D变换。
- */
- //class laya.d3.core.Transform3D extends laya.events.EventDispatcher
- var Transform3D=(function(_super){
- function Transform3D(owner){
- /**@private */
- this._owner=null;
- /**@private */
- this._children=null;
- /**@private */
- this._parent=null;
- /**@private */
- this._dummy=null;
- /**@private */
- this._transformFlag=0;
- Transform3D.__super.call(this);
- this._localPosition=new Vector3(0,0,0);
- this._localRotation=new Quaternion(0,0,0,1);
- this._localScale=new Vector3(1,1,1);
- this._localRotationEuler=new Vector3(0,0,0);
- this._localMatrix=new Matrix4x4();
- this._position=new Vector3(0,0,0);
- this._rotation=new Quaternion(0,0,0,1);
- this._scale=new Vector3(1,1,1);
- this._rotationEuler=new Vector3(0,0,0);
- this._worldMatrix=new Matrix4x4();
- this._owner=owner;
- this._children=[];
- this._setTransformFlag(0x01 | 0x02 | 0x04,false);
- this._setTransformFlag(0x08 | 0x10 | 0x80 | 0x20 | 0x40,true);
- }
- __class(Transform3D,'laya.d3.core.Transform3D',_super);
- var __proto=Transform3D.prototype;
- /**
- *@private
- */
- __proto._setTransformFlag=function(type,value){
- if (value)
- this._transformFlag |=type;
- else
- this._transformFlag &=~type;
- }
- /**
- *@private
- */
- __proto._getTransformFlag=function(type){
- return (this._transformFlag & type)!=0;
- }
- /**
- *@private
- */
- __proto._setParent=function(value){
- if (this._parent!==value){
- if (this._parent){
- var parentChilds=this._parent._children;
- var index=parentChilds.indexOf(this);
- parentChilds.splice(index,1);
- }
- if (value){
- value._children.push(this);
- (value)&& (this._onWorldTransform());
- }
- this._parent=value;
- }
- }
- /**
- *@private
- */
- __proto._updateLocalMatrix=function(){
- Matrix4x4.createAffineTransformation(this._localPosition,this.localRotation,this._localScale,this._localMatrix);
- }
- /**
- *@private
- */
- __proto._onWorldPositionRotationTransform=function(){
- if (!this._getTransformFlag(0x40)|| !this._getTransformFlag(0x08)|| !this._getTransformFlag(0x10)|| !this._getTransformFlag(0x80)){
- this._setTransformFlag(0x40 | 0x08 | 0x10 | 0x80,true);
- this.event(/*laya.events.Event.TRANSFORM_CHANGED*/"transformchanged",this._transformFlag);
- for (var i=0,n=this._children.length;i < n;i++)
- this._children[i]._onWorldPositionRotationTransform();
- }
- }
- /**
- *@private
- */
- __proto._onWorldPositionScaleTransform=function(){
- if (!this._getTransformFlag(0x40)|| !this._getTransformFlag(0x08)|| !this._getTransformFlag(0x20)){
- this._setTransformFlag(0x40 | 0x08 | 0x20,true);
- this.event(/*laya.events.Event.TRANSFORM_CHANGED*/"transformchanged",this._transformFlag);
- for (var i=0,n=this._children.length;i < n;i++)
- this._children[i]._onWorldPositionScaleTransform();
- }
- }
- /**
- *@private
- */
- __proto._onWorldPositionTransform=function(){
- if (!this._getTransformFlag(0x40)|| !this._getTransformFlag(0x08)){
- this._setTransformFlag(0x40 | 0x08,true);
- this.event(/*laya.events.Event.TRANSFORM_CHANGED*/"transformchanged",this._transformFlag);
- for (var i=0,n=this._children.length;i < n;i++)
- this._children[i]._onWorldPositionTransform();
- }
- }
- /**
- *@private
- */
- __proto._onWorldRotationTransform=function(){
- if (!this._getTransformFlag(0x40)|| !this._getTransformFlag(0x10)|| !this._getTransformFlag(0x80)){
- this._setTransformFlag(0x40 | 0x10 | 0x80,true);
- this.event(/*laya.events.Event.TRANSFORM_CHANGED*/"transformchanged",this._transformFlag);
- for (var i=0,n=this._children.length;i < n;i++)
- this._children[i]._onWorldPositionRotationTransform();
- }
- }
- /**
- *@private
- */
- __proto._onWorldScaleTransform=function(){
- if (!this._getTransformFlag(0x40)|| !this._getTransformFlag(0x20)){
- this._setTransformFlag(0x40 | 0x20,true);
- this.event(/*laya.events.Event.TRANSFORM_CHANGED*/"transformchanged",this._transformFlag);
- for (var i=0,n=this._children.length;i < n;i++)
- this._children[i]._onWorldPositionScaleTransform();
- }
- }
- /**
- *@private
- */
- __proto._onWorldTransform=function(){
- if (!this._getTransformFlag(0x40)|| !this._getTransformFlag(0x08)|| !this._getTransformFlag(0x10)|| !this._getTransformFlag(0x80)|| !this._getTransformFlag(0x20)){
- this._setTransformFlag(0x40 | 0x08 | 0x10 | 0x80 | 0x20,true);
- this.event(/*laya.events.Event.TRANSFORM_CHANGED*/"transformchanged",this._transformFlag);
- for (var i=0,n=this._children.length;i < n;i++)
- this._children[i]._onWorldTransform();
- }
- }
- /**
- *平移变换。
- *@param translation 移动距离。
- *@param isLocal 是否局部空间。
- */
- __proto.translate=function(translation,isLocal){
- (isLocal===void 0)&& (isLocal=true);
- if (isLocal){
- Matrix4x4.createFromQuaternion(this.localRotation,Transform3D._tempMatrix0);
- Vector3.transformCoordinate(translation,Transform3D._tempMatrix0,Transform3D._tempVector30);
- Vector3.add(this.localPosition,Transform3D._tempVector30,this._localPosition);
- this.localPosition=this._localPosition;
- }else {
- Vector3.add(this.position,translation,this._position);
- this.position=this._position;
- }
- }
- /**
- *旋转变换。
- *@param rotations 旋转幅度。
- *@param isLocal 是否局部空间。
- *@param isRadian 是否弧度制。
- */
- __proto.rotate=function(rotation,isLocal,isRadian){
- (isLocal===void 0)&& (isLocal=true);
- (isRadian===void 0)&& (isRadian=true);
- var rot;
- if (isRadian){
- rot=rotation;
- }else {
- Vector3.scale(rotation,Math.PI / 180.0,Transform3D._tempVector30);
- rot=Transform3D._tempVector30;
- }
- Quaternion.createFromYawPitchRoll(rot.y,rot.x,rot.z,Transform3D._tempQuaternion0);
- if (isLocal){
- Quaternion.multiply(this._localRotation,Transform3D._tempQuaternion0,this._localRotation);
- this.localRotation=this._localRotation;
- }else {
- Quaternion.multiply(Transform3D._tempQuaternion0,this.rotation,this._rotation);
- this.rotation=this._rotation;
- }
- }
- /**
- *获取向前方向。
- *@param 前方向。
- */
- __proto.getForward=function(forward){
- var worldMatElem=this.worldMatrix.elements;
- forward.x=-worldMatElem[8];
- forward.y=-worldMatElem[9];
- forward.z=-worldMatElem[10];
- }
- /**
- *获取向上方向。
- *@param 上方向。
- */
- __proto.getUp=function(up){
- var worldMatElem=this.worldMatrix.elements;
- up.x=worldMatElem[4];
- up.y=worldMatElem[5];
- up.z=worldMatElem[6];
- }
- /**
- *获取向右方向。
- *@param 右方向。
- */
- __proto.getRight=function(right){
- var worldMatElem=this.worldMatrix.elements;
- right.x=worldMatElem[0];
- right.y=worldMatElem[1];
- right.z=worldMatElem[2];
- }
- /**
- *观察目标位置。
- *@param target 观察目标。
- *@param up 向上向量。
- *@param isLocal 是否局部空间。
- */
- __proto.lookAt=function(target,up,isLocal){
- (isLocal===void 0)&& (isLocal=false);
- var eye;
- if (isLocal){
- eye=this._localPosition;
- 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)
- return;
- Quaternion.lookAt(this._localPosition,target,up,this._localRotation);
- this._localRotation.invert(this._localRotation);
- this.localRotation=this._localRotation;
- }else {
- var worldPosition=this.position;
- eye=worldPosition;
- 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)
- return;
- Quaternion.lookAt(worldPosition,target,up,this._rotation);
- this._rotation.invert(this._rotation);
- this.rotation=this._rotation;
- }
- }
- /**
- *@private
- */
- __getset(0,__proto,'_isFrontFaceInvert',function(){
- var scale=this.scale;
- var isInvert=scale.x < 0;
- (scale.y < 0)&& (isInvert=!isInvert);
- (scale.z < 0)&& (isInvert=!isInvert);
- return isInvert;
- });
- /**
- *获取所属精灵。
- */
- __getset(0,__proto,'owner',function(){
- return this._owner;
- });
- /**
- *设置局部位置Y轴分量。
- *@param y 局部位置Y轴分量。
- */
- /**
- *获取局部位置Y轴分量。
- *@return 局部位置Y轴分量。
- */
- __getset(0,__proto,'localPositionY',function(){
- return this._localPosition.y;
- },function(y){
- this._localPosition.y=y;
- this.localPosition=this._localPosition;
- });
- /**
- *设置局部缩放X。
- *@param value 局部缩放X。
- */
- /**
- *获取局部缩放X。
- *@return 局部缩放X。
- */
- __getset(0,__proto,'localScaleX',function(){
- return this._localScale.x;
- },function(value){
- this._localScale.x=value;
- this.localScale=this._localScale;
- });
- /**
- *获取世界矩阵是否需要更新。
- *@return 世界矩阵是否需要更新。
- */
- __getset(0,__proto,'worldNeedUpdate',function(){
- return this._getTransformFlag(0x40);
- });
- /**
- *设置局部位置X轴分量。
- *@param x 局部位置X轴分量。
- */
- /**
- *获取局部位置X轴分量。
- *@return 局部位置X轴分量。
- */
- __getset(0,__proto,'localPositionX',function(){
- return this._localPosition.x;
- },function(x){
- this._localPosition.x=x;
- this.localPosition=this._localPosition;
- });
- /**
- *设置局部位置。
- *@param value 局部位置。
- */
- /**
- *获取局部位置。
- *@return 局部位置。
- */
- __getset(0,__proto,'localPosition',function(){
- return this._localPosition;
- },function(value){
- if (this._localPosition!==value)
- value.cloneTo(this._localPosition);
- this._setTransformFlag(0x04,true);
- this._onWorldPositionTransform();
- });
- /**
- *设置局部位置Z轴分量。
- *@param z 局部位置Z轴分量。
- */
- /**
- *获取局部位置Z轴分量。
- *@return 局部位置Z轴分量。
- */
- __getset(0,__proto,'localPositionZ',function(){
- return this._localPosition.z;
- },function(z){
- this._localPosition.z=z;
- this.localPosition=this._localPosition;
- });
- /**
- *设置局部旋转四元数X分量。
- *@param x 局部旋转四元数X分量。
- */
- /**
- *获取局部旋转四元数X分量。
- *@return 局部旋转四元数X分量。
- */
- __getset(0,__proto,'localRotationX',function(){
- return this.localRotation.x;
- },function(x){
- this._localRotation.x=x;
- this.localRotation=this._localRotation;
- });
- /**
- *设置局部旋转四元数Y分量。
- *@param y 局部旋转四元数Y分量。
- */
- /**
- *获取局部旋转四元数Y分量。
- *@return 局部旋转四元数Y分量。
- */
- __getset(0,__proto,'localRotationY',function(){
- return this.localRotation.y;
- },function(y){
- this._localRotation.y=y;
- this.localRotation=this._localRotation;
- });
- /**
- *设置局部旋转四元数Z分量。
- *@param z 局部旋转四元数Z分量。
- */
- /**
- *获取局部旋转四元数Z分量。
- *@return 局部旋转四元数Z分量。
- */
- __getset(0,__proto,'localRotationZ',function(){
- return this.localRotation.z;
- },function(z){
- this._localRotation.z=z;
- this.localRotation=this._localRotation;
- });
- /**
- *设置局部旋转四元数W分量。
- *@param w 局部旋转四元数W分量。
- */
- /**
- *获取局部旋转四元数W分量。
- *@return 局部旋转四元数W分量。
- */
- __getset(0,__proto,'localRotationW',function(){
- return this.localRotation.w;
- },function(w){
- this._localRotation.w=w;
- this.localRotation=this._localRotation;
- });
- /**
- *设置局部旋转。
- *@param value 局部旋转。
- */
- /**
- *获取局部旋转。
- *@return 局部旋转。
- */
- __getset(0,__proto,'localRotation',function(){
- if (this._getTransformFlag(0x01)){
- var eulerE=this._localRotationEuler;
- Quaternion.createFromYawPitchRoll(eulerE.y / Transform3D._angleToRandin,eulerE.x / Transform3D._angleToRandin,eulerE.z / Transform3D._angleToRandin,this._localRotation);
- this._setTransformFlag(0x01,false);
- }
- return this._localRotation;
- },function(value){
- if (this._localRotation!==value)
- value.cloneTo(this._localRotation);
- this._localRotation.normalize(this._localRotation);
- this._setTransformFlag(0x02 | 0x04,true);
- this._setTransformFlag(0x01,false);
- this._onWorldRotationTransform();
- });
- /**
- *设置局部缩放Y。
- *@param value 局部缩放Y。
- */
- /**
- *获取局部缩放Y。
- *@return 局部缩放Y。
- */
- __getset(0,__proto,'localScaleY',function(){
- return this._localScale.y;
- },function(value){
- this._localScale.y=value;
- this.localScale=this._localScale;
- });
- /**
- *设置局部缩放Z。
- *@param value 局部缩放Z。
- */
- /**
- *获取局部缩放Z。
- *@return 局部缩放Z。
- */
- __getset(0,__proto,'localScaleZ',function(){
- return this._localScale.z;
- },function(value){
- this._localScale.z=value;
- this.localScale=this._localScale;
- });
- /**
- *设置世界位置。
- *@param value 世界位置。
- */
- /**
- *获取世界位置。
- *@return 世界位置。
- */
- __getset(0,__proto,'position',function(){
- if (this._getTransformFlag(0x08)){
- if (this._parent !=null){
- var parentPosition=this._parent.position;
- Vector3.multiply(this._localPosition,this._parent.scale,Transform3D._tempVector30);
- Vector3.transformQuat(Transform3D._tempVector30,this._parent.rotation,Transform3D._tempVector30);
- Vector3.add(parentPosition,Transform3D._tempVector30,this._position);
- }else {
- this._localPosition.cloneTo(this._position);
- }
- this._setTransformFlag(0x08,false);
- }
- return this._position;
- },function(value){
- if (this._parent !=null){
- Vector3.subtract(value,this._parent.position,this._localPosition);
- var parentScale=this._parent.scale;
- var psX=parentScale.x,psY=parentScale.y,psZ=parentScale.z;
- if (psX!==1.0 || psY!==1.0 || psZ!==1.0){
- var invertScale=Transform3D._tempVector30;
- invertScale.x=1.0 / psX;
- invertScale.y=1.0 / psY;
- invertScale.z=1.0 / psZ;
- Vector3.multiply(this._localPosition,invertScale,this._localPosition);
- };
- var parentRotation=this._parent.rotation;
- parentRotation.invert(Transform3D._tempQuaternion0);
- Vector3.transformQuat(this._localPosition,Transform3D._tempQuaternion0,this._localPosition);
- }else {
- value.cloneTo(this._localPosition);
- }
- this.localPosition=this._localPosition;
- if (this._position!==value)
- value.cloneTo(this._position);
- this._setTransformFlag(0x08,false);
- });
- /**
- *设置局部空间的Y轴欧拉角。
- *@param value 局部空间的Y轴欧拉角。
- */
- /**
- *获取局部空间的Y轴欧拉角。
- *@return 局部空间的Y轴欧拉角。
- */
- __getset(0,__proto,'localRotationEulerY',function(){
- return this.localRotationEuler.y;
- },function(value){
- this._localRotationEuler.y=value;
- this.localRotationEuler=this._localRotationEuler;
- });
- /**
- *设置局部缩放。
- *@param value 局部缩放。
- */
- /**
- *获取局部缩放。
- *@return 局部缩放。
- */
- __getset(0,__proto,'localScale',function(){
- return this._localScale;
- },function(value){
- if (this._localScale!==value)
- value.cloneTo(this._localScale);
- this._setTransformFlag(0x04,true);
- this._onWorldScaleTransform();
- });
- /**
- *设置局部空间的X轴欧拉角。
- *@param value 局部空间的X轴欧拉角。
- */
- /**
- *获取局部空间的X轴欧拉角。
- *@return 局部空间的X轴欧拉角。
- */
- __getset(0,__proto,'localRotationEulerX',function(){
- return this.localRotationEuler.x;
- },function(value){
- this._localRotationEuler.x=value;
- this.localRotationEuler=this._localRotationEuler;
- });
- /**
- *设置局部空间的Z轴欧拉角。
- *@param value 局部空间的Z轴欧拉角。
- */
- /**
- *获取局部空间的Z轴欧拉角。
- *@return 局部空间的Z轴欧拉角。
- */
- __getset(0,__proto,'localRotationEulerZ',function(){
- return this.localRotationEuler.z;
- },function(value){
- this._localRotationEuler.z=value;
- this.localRotationEuler=this._localRotationEuler;
- });
- /**
- *设置局部空间的欧拉角。
- *@param value 欧拉角的旋转值。
- */
- /**
- *获取局部空间欧拉角。
- *@return 欧拉角的旋转值。
- */
- __getset(0,__proto,'localRotationEuler',function(){
- if (this._getTransformFlag(0x02)){
- this._localRotation.getYawPitchRoll(Transform3D._tempVector30);
- var euler=Transform3D._tempVector30;
- var localRotationEuler=this._localRotationEuler;
- localRotationEuler.x=euler.y *Transform3D._angleToRandin;
- localRotationEuler.y=euler.x *Transform3D._angleToRandin;
- localRotationEuler.z=euler.z *Transform3D._angleToRandin;
- this._setTransformFlag(0x02,false);
- }
- return this._localRotationEuler;
- },function(value){
- if (this._localRotationEuler!==value)
- value.cloneTo(this._localRotationEuler);
- this._setTransformFlag(0x02,false);
- this._setTransformFlag(0x01 | 0x04,true);
- this._onWorldRotationTransform();
- });
- /**
- *设置局部矩阵。
- *@param value 局部矩阵。
- */
- /**
- *获取局部矩阵。
- *@return 局部矩阵。
- */
- __getset(0,__proto,'localMatrix',function(){
- if (this._getTransformFlag(0x04)){
- this._updateLocalMatrix();
- this._setTransformFlag(0x04,false);
- }
- return this._localMatrix;
- },function(value){
- if (this._localMatrix!==value)
- value.cloneTo(this._localMatrix);
- this._localMatrix.decomposeTransRotScale(this._localPosition,this._localRotation,this._localScale);
- this._setTransformFlag(0x04,false);
- this._onWorldTransform();
- });
- /**
- *设置世界旋转。
- *@param value 世界旋转。
- */
- /**
- *获取世界旋转。
- *@return 世界旋转。
- */
- __getset(0,__proto,'rotation',function(){
- if (this._getTransformFlag(0x10)){
- if (this._parent !=null)
- Quaternion.multiply(this._parent.rotation,this.localRotation,this._rotation);
- else
- this.localRotation.cloneTo(this._rotation);
- this._setTransformFlag(0x10,false);
- }
- return this._rotation;
- },function(value){
- if (this._parent !=null){
- this._parent.rotation.invert(Transform3D._tempQuaternion0);
- Quaternion.multiply(Transform3D._tempQuaternion0,value,this._localRotation);
- }else {
- value.cloneTo(this._localRotation);
- }
- this.localRotation=this._localRotation;
- if (value!==this._rotation)
- value.cloneTo(this._rotation);
- this._setTransformFlag(0x10,false);
- });
- /**
- *设置世界缩放。
- *@param value 世界缩放。
- */
- /**
- *获取世界缩放。
- *@return 世界缩放。
- */
- __getset(0,__proto,'scale',function(){
- if (!this._getTransformFlag(0x20))
- return this._scale;
- if (this._parent!==null)
- Vector3.multiply(this._parent.scale,this._localScale,this._scale);
- else
- this._localScale.cloneTo(this._scale);
- this._setTransformFlag(0x20,false);
- return this._scale;
- },function(value){
- if (this._parent!==null){
- var parScale=this._parent.scale;
- var invParScale=Transform3D._tempVector30;
- invParScale.x=1.0 / parScale.x;
- invParScale.y=1.0 / parScale.y;
- invParScale.z=1.0 / parScale.z;
- Vector3.multiply(value,Transform3D._tempVector30,this._localScale);
- }else {
- value.cloneTo(this._localScale);
- }
- this.localScale=this._localScale;
- if (this._scale!==value)
- value.cloneTo(this._scale);
- this._setTransformFlag(0x20,false);
- });
- /**
- *设置世界空间的旋转角度。
- *@param 欧拉角的旋转值,顺序为x、y、z。
- */
- /**
- *获取世界空间的旋转角度。
- *@return 欧拉角的旋转值,顺序为x、y、z。
- */
- __getset(0,__proto,'rotationEuler',function(){
- if (this._getTransformFlag(0x80)){
- this.rotation.getYawPitchRoll(Transform3D._tempVector30);
- var eulerE=Transform3D._tempVector30;
- var rotationEulerE=this._rotationEuler;
- rotationEulerE.x=eulerE.y *Transform3D._angleToRandin;
- rotationEulerE.y=eulerE.x *Transform3D._angleToRandin;
- rotationEulerE.z=eulerE.z *Transform3D._angleToRandin;
- this._setTransformFlag(0x80,false);
- }
- return this._rotationEuler;
- },function(value){
- Quaternion.createFromYawPitchRoll(value.y / Transform3D._angleToRandin,value.x / Transform3D._angleToRandin,value.z / Transform3D._angleToRandin,this._rotation);
- this.rotation=this._rotation;
- if (this._rotationEuler!==value)
- value.cloneTo(this._rotationEuler);
- this._setTransformFlag(0x80,false);
- });
- /**
- *设置世界矩阵。
- *@param value 世界矩阵。
- */
- /**
- *获取世界矩阵。
- *@return 世界矩阵。
- */
- __getset(0,__proto,'worldMatrix',function(){
- if (this._getTransformFlag(0x40)){
- if (this._parent !=null)
- Matrix4x4.multiply(this._parent.worldMatrix,this.localMatrix,this._worldMatrix);
- else
- this.localMatrix.cloneTo(this._worldMatrix);
- this._setTransformFlag(0x40,false);
- }
- return this._worldMatrix;
- },function(value){
- if (this._parent===null){
- value.cloneTo(this._localMatrix);
- }else {
- this._parent.worldMatrix.invert(this._localMatrix);
- Matrix4x4.multiply(this._localMatrix,value,this._localMatrix);
- }
- this.localMatrix=this._localMatrix;
- if (this._worldMatrix!==value)
- value.cloneTo(this._worldMatrix);
- this._setTransformFlag(0x40,false);
- });
- Transform3D.TRANSFORM_LOCALQUATERNION=0x01;
- Transform3D.TRANSFORM_LOCALEULER=0x02;
- Transform3D.TRANSFORM_LOCALMATRIX=0x04;
- Transform3D.TRANSFORM_WORLDPOSITION=0x08;
- Transform3D.TRANSFORM_WORLDQUATERNION=0x10;
- Transform3D.TRANSFORM_WORLDSCALE=0x20;
- Transform3D.TRANSFORM_WORLDMATRIX=0x40;
- Transform3D.TRANSFORM_WORLDEULER=0x80;
- __static(Transform3D,
- ['_tempVector30',function(){return this._tempVector30=new Vector3();},'_tempVector31',function(){return this._tempVector31=new Vector3();},'_tempVector32',function(){return this._tempVector32=new Vector3();},'_tempVector33',function(){return this._tempVector33=new Vector3();},'_tempQuaternion0',function(){return this._tempQuaternion0=new Quaternion();},'_tempMatrix0',function(){return this._tempMatrix0=new Matrix4x4();},'_angleToRandin',function(){return this._angleToRandin=180 / Math.PI;}
- ]);
- return Transform3D;
- })(EventDispatcher)
- /**
- *<code>Animator</code> 类用于创建动画组件。
- */
- //class laya.d3.component.Animator extends laya.components.Component
- var Animator=(function(_super){
- function Animator(){
- /**@private */
- //this._speed=NaN;
- /**@private */
- //this._keyframeNodeOwnerMap=null;
- /**@private */
- //this._updateMark=0;
- /**@private */
- //this._controllerLayers=null;
- /**@private */
- //this._linkSprites=null;
- /**@private */
- //this._avatarNodeMap=null;
- /**@private */
- this._linkAvatarSpritesData={};
- /**@private [NATIVE]*/
- //this._animationNodeLocalPositions=null;
- /**@private [NATIVE]*/
- //this._animationNodeLocalRotations=null;
- /**@private [NATIVE]*/
- //this._animationNodeLocalScales=null;
- /**@private [NATIVE]*/
- //this._animationNodeWorldMatrixs=null;
- /**@private [NATIVE]*/
- //this._animationNodeParentIndices=null;
- /**@private */
- //this._avatar=null;
- this._keyframeNodeOwners=[];
- this._linkAvatarSprites=[];
- this._renderableSprites=[];
- this.cullingMode=2;
- Animator.__super.call(this);
- this._controllerLayers=[];
- this._linkSprites={};
- this._speed=1.0;
- this._keyframeNodeOwnerMap={};
- this._updateMark=0;
- }
- __class(Animator,'laya.d3.component.Animator',_super);
- var __proto=Animator.prototype;
- /**
- *@private
- */
- __proto._linkToSprites=function(linkSprites){
- for (var k in linkSprites){
- var nodeOwner=this.owner;
- var path=linkSprites[k];
- for (var j=0,m=path.length;j < m;j++){
- var p=path[j];
- if (p===""){
- break ;
- }else {
- nodeOwner=nodeOwner.getChildByName(p);
- if (!nodeOwner)
- break ;
- }
- }
- (nodeOwner)&& (this.linkSprite3DToAvatarNode(k,nodeOwner));
- }
- }
- /**
- *@private
- */
- __proto._addKeyframeNodeOwner=function(clipOwners,node,propertyOwner){
- var nodeIndex=node._indexInList;
- var fullPath=node.fullPath;
- var keyframeNodeOwner=this._keyframeNodeOwnerMap[fullPath];
- if (keyframeNodeOwner){
- keyframeNodeOwner.referenceCount++;
- clipOwners[nodeIndex]=keyframeNodeOwner;
- }else {
- var property=propertyOwner;
- for (var i=0,n=node.propertyCount;i < n;i++){
- property=property[node.getPropertyByIndex(i)];
- if (!property)
- break ;
- }
- keyframeNodeOwner=this._keyframeNodeOwnerMap[fullPath]=new KeyframeNodeOwner();
- keyframeNodeOwner.fullPath=fullPath;
- keyframeNodeOwner.indexInList=this._keyframeNodeOwners.length;
- keyframeNodeOwner.referenceCount=1;
- keyframeNodeOwner.propertyOwner=propertyOwner;
- var propertyCount=node.propertyCount;
- var propertys=__newvec(propertyCount);
- for (i=0;i < propertyCount;i++)
- propertys[i]=node.getPropertyByIndex(i);
- keyframeNodeOwner.property=propertys;
- keyframeNodeOwner.type=node.type;
- if (property){
- if (node.type===0){
- keyframeNodeOwner.defaultValue=property;
- }else {
- var defaultValue=new property.constructor();
- property.cloneTo(defaultValue);
- keyframeNodeOwner.defaultValue=defaultValue;
- }
- }
- this._keyframeNodeOwners.push(keyframeNodeOwner);
- clipOwners[nodeIndex]=keyframeNodeOwner;
- }
- }
- /**
- *@private
- */
- __proto._removeKeyframeNodeOwner=function(nodeOwners,node){
- var fullPath=node.fullPath;
- var keyframeNodeOwner=this._keyframeNodeOwnerMap[fullPath];
- if (keyframeNodeOwner){
- keyframeNodeOwner.referenceCount--;
- if (keyframeNodeOwner.referenceCount===0){
- delete this._keyframeNodeOwnerMap[fullPath];
- this._keyframeNodeOwners.splice(this._keyframeNodeOwners.indexOf(keyframeNodeOwner),1);
- }
- nodeOwners[node._indexInList]=null;
- }
- }
- /**
- *@private
- */
- __proto._getOwnersByClip=function(clipStateInfo){
- var frameNodes=clipStateInfo._clip._nodes;
- var frameNodesCount=frameNodes.count;
- var nodeOwners=clipStateInfo._nodeOwners;
- nodeOwners.length=frameNodesCount;
- for (var i=0;i < frameNodesCount;i++){
- var node=frameNodes.getNodeByIndex(i);
- var property=this._avatar ? this._avatarNodeMap[this._avatar._rootNode.name] :this.owner;
- for (var j=0,m=node.ownerPathCount;j < m;j++){
- var ownPat=node.getOwnerPathByIndex(j);
- if (ownPat===""){
- break ;
- }else {
- property=property.getChildByName(ownPat);
- if (!property)
- break ;
- }
- }
- if (property){
- var propertyOwner=node.propertyOwner;
- (propertyOwner)&& (property=property[propertyOwner]);
- property && this._addKeyframeNodeOwner(nodeOwners,node,property);
- }
- }
- }
- /**
- *@private
- */
- __proto._updatePlayer=function(animatorState,playState,elapsedTime,islooping){
- var clipDuration=animatorState._clip._duration *(animatorState.clipEnd-animatorState.clipStart);
- var lastElapsedTime=playState._elapsedTime;
- var elapsedPlaybackTime=lastElapsedTime+elapsedTime;
- playState._lastElapsedTime=lastElapsedTime;
- playState._elapsedTime=elapsedPlaybackTime;
- var normalizedTime=elapsedPlaybackTime / clipDuration;
- playState._normalizedTime=normalizedTime;
- var playTime=normalizedTime % 1.0;
- playState._normalizedPlayTime=playTime < 0 ? playTime+1.0 :playTime;
- playState._duration=clipDuration;
- var scripts=animatorState._scripts;
- if ((!islooping && elapsedPlaybackTime >=clipDuration)){
- playState._finish=true;
- playState._elapsedTime=clipDuration;
- playState._normalizedPlayTime=1.0;
- if (scripts){
- for (var i=0,n=scripts.length;i < n;i++)
- scripts[i].onStateExit();
- }
- return;
- }
- if (scripts){
- for (i=0,n=scripts.length;i < n;i++)
- scripts[i].onStateUpdate();
- }
- }
- /**
- *@private
- */
- __proto._eventScript=function(scripts,events,eventIndex,endTime,front){
- if (front){
- for (var n=events.length;eventIndex < n;eventIndex++){
- var event=events[eventIndex];
- if (event.time <=endTime){
- for (var j=0,m=scripts.length;j < m;j++){
- var script=scripts[j];
- var fun=script[event.eventName];
- (fun)&& (fun.apply(script,event.params));
- }
- }else {
- break ;
- }
- }
- }else {
- for (;eventIndex >=0;eventIndex--){
- event=events[eventIndex];
- if (event.time >=endTime){
- for (j=0,m=scripts.length;j < m;j++){
- script=scripts[j];
- fun=script[event.eventName];
- (fun)&& (fun.apply(script,event.params));
- }
- }else {
- break ;
- }
- }
- }
- return eventIndex;
- }
- /**
- *@private
- */
- __proto._updateEventScript=function(stateInfo,playStateInfo){
- var scripts=(this.owner)._scripts;
- if (scripts){
- var clip=stateInfo._clip;
- var events=clip._events;
- var clipDuration=clip._duration;
- var elapsedTime=playStateInfo._elapsedTime;
- var time=elapsedTime % clipDuration;
- var loopCount=Math.abs(Math.floor(elapsedTime / clipDuration)-Math.floor(playStateInfo._lastElapsedTime / clipDuration));
- var frontPlay=playStateInfo._elapsedTime >=playStateInfo._lastElapsedTime;
- if (playStateInfo._lastIsFront!==frontPlay){
- if (frontPlay)
- playStateInfo._playEventIndex++;
- else
- playStateInfo._playEventIndex--;
- playStateInfo._lastIsFront=frontPlay;
- }
- if (loopCount==0){
- playStateInfo._playEventIndex=this._eventScript(scripts,events,playStateInfo._playEventIndex,time,frontPlay);
- }else {
- if (frontPlay){
- this._eventScript(scripts,events,playStateInfo._playEventIndex,clipDuration,true);
- for (var i=0,n=loopCount-1;i < n;i++)
- this._eventScript(scripts,events,0,clipDuration,true);
- playStateInfo._playEventIndex=this._eventScript(scripts,events,0,time,true);
- }else {
- this._eventScript(scripts,events,playStateInfo._playEventIndex,0,false);
- var eventIndex=events.length-1;
- for (i=0,n=loopCount-1;i < n;i++)
- this._eventScript(scripts,events,eventIndex,0,false);
- playStateInfo._playEventIndex=this._eventScript(scripts,events,eventIndex,time,false);
- }
- }
- }
- }
- /**
- *@private
- */
- __proto._updateClipDatas=function(animatorState,addtive,playStateInfo,scale){
- var clip=animatorState._clip;
- var clipDuration=clip._duration;
- var curPlayTime=animatorState.clipStart *clipDuration+playStateInfo._normalizedPlayTime *playStateInfo._duration;
- var currentFrameIndices=animatorState._currentFrameIndices;
- var frontPlay=playStateInfo._elapsedTime > playStateInfo._lastElapsedTime;
- clip._evaluateClipDatasRealTime(clip._nodes,curPlayTime,currentFrameIndices,addtive,frontPlay);
- }
- /**
- *@private
- */
- __proto._applyFloat=function(pro,proName,nodeOwner,additive,weight,isFirstLayer,data){
- if (nodeOwner.updateMark===this._updateMark){
- if (additive){
- pro[proName]+=weight *(data);
- }else {
- var oriValue=pro[proName];
- pro[proName]=oriValue+weight *(data-oriValue);
- }
- }else {
- if (isFirstLayer){
- if (additive)
- pro[proName]=nodeOwner.defaultValue+data;
- else
- pro[proName]=data;
- }else {
- if (additive){
- pro[proName]=nodeOwner.defaultValue+weight *(data);
- }else {
- var defValue=nodeOwner.defaultValue;
- pro[proName]=defValue+weight *(data-defValue);
- }
- }
- }
- }
- /**
- *@private
- */
- __proto._applyPositionAndRotationEuler=function(nodeOwner,additive,weight,isFirstLayer,data,out){
- if (nodeOwner.updateMark===this._updateMark){
- if (additive){
- out.x+=weight *data.x;
- out.y+=weight *data.y;
- out.z+=weight *data.z;
- }else {
- var oriX=out.x;
- var oriY=out.y;
- var oriZ=out.z;
- out.x=oriX+weight *(data.x-oriX);
- out.y=oriY+weight *(data.y-oriY);
- out.z=oriZ+weight *(data.z-oriZ);
- }
- }else {
- if (isFirstLayer){
- if (additive){
- var defValue=nodeOwner.defaultValue;
- out.x=defValue.x+data.x;
- out.y=defValue.y+data.y;
- out.z=defValue.z+data.z;
- }else {
- out.x=data.x;
- out.y=data.y;
- out.z=data.z;
- }
- }else {
- defValue=nodeOwner.defaultValue;
- if (additive){
- out.x=defValue.x+weight *data.x;
- out.y=defValue.y+weight *data.y;
- out.z=defValue.z+weight *data.z;
- }else {
- var defX=defValue.x;
- var defY=defValue.y;
- var defZ=defValue.z;
- out.x=defX+weight *(data.x-defX);
- out.y=defY+weight *(data.y-defY);
- out.z=defZ+weight *(data.z-defZ);
- }
- }
- }
- }
- /**
- *@private
- */
- __proto._applyRotation=function(nodeOwner,additive,weight,isFirstLayer,clipRot,localRotation){
- if (nodeOwner.updateMark===this._updateMark){
- if (additive){
- var tempQuat=Animator._tempQuaternion1;
- Utils3D.quaternionWeight(clipRot,weight,tempQuat);
- tempQuat.normalize(tempQuat);
- Quaternion.multiply(localRotation,tempQuat,localRotation);
- }else {
- Quaternion.lerp(localRotation,clipRot,weight,localRotation);
- }
- }else {
- if (isFirstLayer){
- if (additive){
- var defaultRot=nodeOwner.defaultValue;
- Quaternion.multiply(defaultRot,clipRot,localRotation);
- }else {
- localRotation.x=clipRot.x;
- localRotation.y=clipRot.y;
- localRotation.z=clipRot.z;
- localRotation.w=clipRot.w;
- }
- }else {
- defaultRot=nodeOwner.defaultValue;
- if (additive){
- tempQuat=Animator._tempQuaternion1;
- Utils3D.quaternionWeight(clipRot,weight,tempQuat);
- tempQuat.normalize(tempQuat);
- Quaternion.multiply(defaultRot,tempQuat,localRotation);
- }else {
- Quaternion.lerp(defaultRot,clipRot,weight,localRotation);
- }
- }
- }
- }
- /**
- *@private
- */
- __proto._applyScale=function(nodeOwner,additive,weight,isFirstLayer,clipSca,localScale){
- if (nodeOwner.updateMark===this._updateMark){
- if (additive){
- var scale=Animator._tempVector31;
- Utils3D.scaleWeight(clipSca,weight,scale);
- localScale.x=localScale.x *scale.x;
- localScale.y=localScale.y *scale.y;
- localScale.z=localScale.z *scale.z;
- }else {
- Utils3D.scaleBlend(localScale,clipSca,weight,localScale);
- }
- }else {
- if (isFirstLayer){
- if (additive){
- var defaultSca=nodeOwner.defaultValue;
- localScale.x=defaultSca.x *clipSca.x;
- localScale.y=defaultSca.y *clipSca.y;
- localScale.z=defaultSca.z *clipSca.z;
- }else {
- localScale.x=clipSca.x;
- localScale.y=clipSca.y;
- localScale.z=clipSca.z;
- }
- }else {
- defaultSca=nodeOwner.defaultValue;
- if (additive){
- scale=Animator._tempVector31;
- Utils3D.scaleWeight(clipSca,weight,scale);
- localScale.x=defaultSca.x *scale.x;
- localScale.y=defaultSca.y *scale.y;
- localScale.z=defaultSca.z *scale.z;
- }else {
- Utils3D.scaleBlend(defaultSca,clipSca,weight,localScale);
- }
- }
- }
- }
- /**
- *@private
- */
- __proto._applyCrossData=function(nodeOwner,additive,weight,isFirstLayer,srcValue,desValue,crossWeight){
- var pro=nodeOwner.propertyOwner;
- if (pro){
- switch (nodeOwner.type){
- case 0:;
- var proPat=nodeOwner.property;
- var m=proPat.length-1;
- for (var j=0;j < m;j++){
- pro=pro[proPat[j]];
- if (!pro)
- break ;
- };
- var crossValue=srcValue+crossWeight *(desValue-srcValue);
- this._applyFloat(pro,proPat[m],nodeOwner,additive,weight,isFirstLayer,crossValue);
- break ;
- case 1:;
- var localPos=pro.localPosition;
- var position=Animator._tempVector30;
- var srcX=srcValue.x,srcY=srcValue.y,srcZ=srcValue.z;
- position.x=srcX+crossWeight *(desValue.x-srcX);
- position.y=srcY+crossWeight *(desValue.y-srcY);
- position.z=srcZ+crossWeight *(desValue.z-srcZ);
- this._applyPositionAndRotationEuler(nodeOwner,additive,weight,isFirstLayer,position,localPos);
- pro.localPosition=localPos;
- break ;
- case 2:;
- var localRot=pro.localRotation;
- var rotation=Animator._tempQuaternion0;
- Quaternion.lerp(srcValue,desValue,crossWeight,rotation);
- this._applyRotation(nodeOwner,additive,weight,isFirstLayer,rotation,localRot);
- pro.localRotation=localRot;
- break ;
- case 3:;
- var localSca=pro.localScale;
- var scale=Animator._tempVector30;
- Utils3D.scaleBlend(srcValue,desValue,crossWeight,scale);
- this._applyScale(nodeOwner,additive,weight,isFirstLayer,scale,localSca);
- pro.localScale=localSca;
- break ;
- case 4:;
- var localEuler=pro.localRotationEuler;
- var rotationEuler=Animator._tempVector30;
- srcX=srcValue.x,srcY=srcValue.y,srcZ=srcValue.z;
- rotationEuler.x=srcX+crossWeight *(desValue.x-srcX);
- rotationEuler.y=srcY+crossWeight *(desValue.y-srcY);
- rotationEuler.z=srcZ+crossWeight *(desValue.z-srcZ);
- this._applyPositionAndRotationEuler(nodeOwner,additive,weight,isFirstLayer,rotationEuler,localEuler);
- pro.localRotationEuler=localEuler;
- break ;
- }
- nodeOwner.updateMark=this._updateMark;
- }
- }
- /**
- *@private
- */
- __proto._setClipDatasToNode=function(stateInfo,additive,weight,isFirstLayer){
- var nodes=stateInfo._clip._nodes;
- var nodeOwners=stateInfo._nodeOwners;
- for (var i=0,n=nodes.count;i < n;i++){
- var nodeOwner=nodeOwners[i];
- if (nodeOwner){
- var pro=nodeOwner.propertyOwner;
- if (pro){
- switch (nodeOwner.type){
- case 0:;
- var proPat=nodeOwner.property;
- var m=proPat.length-1;
- for (var j=0;j < m;j++){
- pro=pro[proPat[j]];
- if (!pro)
- break ;
- }
- this._applyFloat(pro,proPat[m],nodeOwner,additive,weight,isFirstLayer,nodes.getNodeByIndex(i).data);
- break ;
- case 1:;
- var localPos=pro.localPosition;
- this._applyPositionAndRotationEuler(nodeOwner,additive,weight,isFirstLayer,nodes.getNodeByIndex(i).data,localPos);
- pro.localPosition=localPos;
- break ;
- case 2:;
- var localRot=pro.localRotation;
- this._applyRotation(nodeOwner,additive,weight,isFirstLayer,nodes.getNodeByIndex(i).data,localRot);
- pro.localRotation=localRot;
- break ;
- case 3:;
- var localSca=pro.localScale;
- this._applyScale(nodeOwner,additive,weight,isFirstLayer,nodes.getNodeByIndex(i).data,localSca);
- pro.localScale=localSca;
- break ;
- case 4:;
- var localEuler=pro.localRotationEuler;
- this._applyPositionAndRotationEuler(nodeOwner,additive,weight,isFirstLayer,nodes.getNodeByIndex(i).data,localEuler);
- pro.localRotationEuler=localEuler;
- break ;
- }
- nodeOwner.updateMark=this._updateMark;
- }
- }
- }
- }
- /**
- *@private
- */
- __proto._setCrossClipDatasToNode=function(controllerLayer,srcState,destState,crossWeight,isFirstLayer){
- var nodeOwners=controllerLayer._crossNodesOwners;
- var ownerCount=controllerLayer._crossNodesOwnersCount;
- var additive=controllerLayer.blendingMode!==AnimatorControllerLayer.BLENDINGMODE_OVERRIDE;
- var weight=controllerLayer.defaultWeight;
- var destDataIndices=controllerLayer._destCrossClipNodeIndices;
- var destNodes=destState._clip._nodes;
- var destNodeOwners=destState._nodeOwners;
- var srcDataIndices=controllerLayer._srcCrossClipNodeIndices;
- var srcNodeOwners=srcState._nodeOwners;
- var srcNodes=srcState._clip._nodes;
- for (var i=0;i < ownerCount;i++){
- var nodeOwner=nodeOwners[i];
- if (nodeOwner){
- var srcIndex=srcDataIndices[i];
- var destIndex=destDataIndices[i];
- var srcValue=srcIndex!==-1 ? srcNodes.getNodeByIndex(srcIndex).data :destNodeOwners[destIndex].defaultValue;
- var desValue=destIndex!==-1 ? destNodes.getNodeByIndex(destIndex).data :srcNodeOwners[srcIndex].defaultValue;
- this._applyCrossData(nodeOwner,additive,weight,isFirstLayer,srcValue,desValue,crossWeight);
- }
- }
- }
- /**
- *@private
- */
- __proto._setFixedCrossClipDatasToNode=function(controllerLayer,destState,crossWeight,isFirstLayer){
- var nodeOwners=controllerLayer._crossNodesOwners;
- var ownerCount=controllerLayer._crossNodesOwnersCount;
- var additive=controllerLayer.blendingMode!==AnimatorControllerLayer.BLENDINGMODE_OVERRIDE;
- var weight=controllerLayer.defaultWeight;
- var destDataIndices=controllerLayer._destCrossClipNodeIndices;
- var destNodes=destState._clip._nodes;
- for (var i=0;i < ownerCount;i++){
- var nodeOwner=nodeOwners[i];
- if (nodeOwner){
- var destIndex=destDataIndices[i];
- var srcValue=nodeOwner.crossFixedValue;
- var desValue=destIndex!==-1 ? destNodes.getNodeByIndex(destIndex).data :nodeOwner.defaultValue;
- this._applyCrossData(nodeOwner,additive,weight,isFirstLayer,srcValue,desValue,crossWeight);
- }
- }
- }
- /**
- *@private
- */
- __proto._revertDefaultKeyframeNodes=function(clipStateInfo){
- var nodeOwners=clipStateInfo._nodeOwners;
- for (var i=0,n=nodeOwners.length;i < n;i++){
- var nodeOwner=nodeOwners[i];
- if (nodeOwner){
- var pro=nodeOwner.propertyOwner;
- if (pro){
- switch (nodeOwner.type){
- case 0:;
- var proPat=nodeOwner.property;
- var m=proPat.length-1;
- for (var j=0;j < m;j++){
- pro=pro[proPat[j]];
- if (!pro)
- break ;
- }
- pro[proPat[m]]=nodeOwner.defaultValue;
- break ;
- case 1:;
- var locPos=pro.localPosition;
- var def=nodeOwner.defaultValue;
- locPos.x=def.x;
- locPos.y=def.y;
- locPos.z=def.z;
- pro.localPosition=locPos;
- break ;
- case 2:;
- var locRot=pro.localRotation;
- var defQua=nodeOwner.defaultValue;
- locRot.x=defQua.x;
- locRot.y=defQua.y;
- locRot.z=defQua.z;
- locRot.w=defQua.w;
- pro.localRotation=locRot;
- break ;
- case 3:;
- var locSca=pro.localScale;
- def=nodeOwner.defaultValue;
- locSca.x=def.x;
- locSca.y=def.y;
- locSca.z=def.z;
- pro.localScale=locSca;
- break ;
- case 4:;
- var locEul=pro.localRotationEuler;
- def=nodeOwner.defaultValue;
- locEul.x=def.x;
- locEul.y=def.y;
- locEul.z=def.z;
- pro.localRotationEuler=locEul;
- break ;
- default :
- throw "Animator:unknown type.";
- }
- }
- }
- }
- }
- /**
- *@private
- */
- __proto._removeClip=function(clipStateInfos,statesMap,index,state){
- var clip=state._clip;
- clip._removeReference();
- clipStateInfos.splice(index,1);
- delete statesMap[state.name];
- var clipStateInfo=clipStateInfos[index];
- var frameNodes=clip._nodes;
- var nodeOwners=clipStateInfo._nodeOwners;
- for (var i=0,n=frameNodes.count;i < n;i++)
- this._removeKeyframeNodeOwner(nodeOwners,frameNodes.getNodeByIndex(i));
- }
- /**
- *@inheritDoc
- */
- __proto._onAdded=function(){
- var parent=this.owner._parent;
- (this.owner)._setHierarchyAnimator(this,parent ? (parent)._hierarchyAnimator :null);
- (this.owner)._changeAnimatorToLinkSprite3DNoAvatar(this,true,/*new vector.<>*/[]);
- }
- /**
- *@inheritDoc
- */
- __proto._onDestroy=function(){
- for (var i=0,n=this._controllerLayers.length;i < n;i++){
- var clipStateInfos=this._controllerLayers[i]._states;
- for (var j=0,m=clipStateInfos.length;j < m;j++)
- clipStateInfos[j]._clip._removeReference();
- };
- var parent=this.owner._parent;
- (this.owner)._clearHierarchyAnimator(this,parent ? (parent)._hierarchyAnimator :null);
- }
- /**
- *@inheritDoc
- */
- __proto._onEnableInScene=function(){
- (this.owner._scene)._animatorPool.add(this);
- }
- /**
- *@inheritDoc
- */
- __proto._onDisableInScene=function(){
- (this.owner._scene)._animatorPool.remove(this);
- }
- /**
- *@inheritDoc
- */
- __proto._onEnable=function(){
- for (var i=0,n=this._controllerLayers.length;i < n;i++){
- if (this._controllerLayers[i].playOnWake){
- var defaultClip=this.getDefaultState(i);
- (defaultClip)&& (this.play(null,i,0));
- }
- }
- }
- /**
- *@private
- */
- __proto._handleSpriteOwnersBySprite=function(isLink,path,sprite){
- for (var i=0,n=this._controllerLayers.length;i < n;i++){
- var clipStateInfos=this._controllerLayers[i]._states;
- for (var j=0,m=clipStateInfos.length;j < m;j++){
- var clipStateInfo=clipStateInfos[j];
- var clip=clipStateInfo._clip;
- var nodePath=path.join("/");
- var ownersNodes=clip._nodesMap[nodePath];
- if (ownersNodes){
- var nodeOwners=clipStateInfo._nodeOwners;
- for (var k=0,p=ownersNodes.length;k < p;k++){
- if (isLink)
- this._addKeyframeNodeOwner(nodeOwners,ownersNodes[k],sprite);
- else
- this._removeKeyframeNodeOwner(nodeOwners,ownersNodes[k]);
- }
- }
- }
- }
- }
- /**
- *@inheritDoc
- */
- __proto._parse=function(data){
- var avatarData=data.avatar;
- if (avatarData){
- this.avatar=Loader.getRes(avatarData.path);
- var linkSprites=avatarData.linkSprites;
- this._linkSprites=linkSprites;
- this._linkToSprites(linkSprites);
- };
- var clipPaths=data.clipPaths;
- var play=data.playOnWake;
- var layersData=data.layers;
- for (var i=0;i < layersData.length;i++){
- var layerData=layersData[i];
- var animatorLayer=new AnimatorControllerLayer(layerData.name);
- if (i===0)
- animatorLayer.defaultWeight=1.0;
- else
- animatorLayer.defaultWeight=layerData.weight;
- var blendingModeData=layerData.blendingMode;
- (blendingModeData)&& (animatorLayer.blendingMode=blendingModeData);
- this.addControllerLayer(animatorLayer);
- var states=layerData.states;
- for (var j=0,m=states.length;j < m;j++){
- var state=states[j];
- var clipPath=state.clipPath;
- if (clipPath){
- var name=state.name;
- var motion;
- motion=Loader.getRes(clipPath);
- if (motion){
- var animatorState=new AnimatorState();
- animatorState.name=name;
- animatorState.clip=motion;
- this.addState(animatorState,i);
- (j===0)&& (this.getControllerLayer(i).defaultState=animatorState);
- }
- }
- }
- (play!==undefined)&& (animatorLayer.playOnWake=play);
- };
- var cullingModeData=data.cullingMode;
- (cullingModeData!==undefined)&& (this.cullingMode=cullingModeData);
- }
- /**
- *@private
- */
- __proto._update=function(){
- if (this._speed===0)
- return;
- var needRender=false;
- if (this.cullingMode===2){
- needRender=false;
- for (var i=0,n=this._renderableSprites.length;i < n;i++){
- if (this._renderableSprites[i]._render._visible){
- needRender=true;
- break ;
- }
- }
- }else {
- needRender=true;
- }
- this._updateMark++;
- var timer=(this.owner._scene).timer;
- var delta=timer._delta / 1000.0;
- var timerScale=timer.scale;
- for (i=0,n=this._controllerLayers.length;i < n;i++){
- var controllerLayer=this._controllerLayers[i];
- var playStateInfo=controllerLayer._playStateInfo;
- var crossPlayStateInfo=controllerLayer._crossPlayStateInfo;
- addtive=controllerLayer.blendingMode!==AnimatorControllerLayer.BLENDINGMODE_OVERRIDE;
- switch (controllerLayer._playType){
- case 0:;
- var animatorState=controllerLayer._currentPlayState;
- var clip=animatorState._clip;
- var speed=this._speed *animatorState.speed;
- var finish=playStateInfo._finish;
- finish || this._updatePlayer(animatorState,playStateInfo,delta *speed,clip.islooping);
- if (needRender){
- var addtive=controllerLayer.blendingMode!==AnimatorControllerLayer.BLENDINGMODE_OVERRIDE;
- this._updateClipDatas(animatorState,addtive,playStateInfo,timerScale *speed);
- this._setClipDatasToNode(animatorState,addtive,controllerLayer.defaultWeight,i===0);
- finish || this._updateEventScript(animatorState,playStateInfo);
- }
- break ;
- case 1:
- animatorState=controllerLayer._currentPlayState;
- clip=animatorState._clip;
- var crossClipState=controllerLayer._crossPlayState;
- var crossClip=crossClipState._clip;
- var crossDuratuion=controllerLayer._crossDuration;
- var startPlayTime=crossPlayStateInfo._startPlayTime;
- var crossClipDuration=crossClip._duration-startPlayTime;
- var crossScale=crossDuratuion > crossClipDuration ? crossClipDuration / crossDuratuion :1.0;
- var crossSpeed=this._speed *crossClipState.speed;
- this._updatePlayer(crossClipState,crossPlayStateInfo,delta *crossScale *crossSpeed,crossClip.islooping);
- var crossWeight=((crossPlayStateInfo._elapsedTime-startPlayTime)/ crossScale)/ crossDuratuion;
- if (crossWeight >=1.0){
- if (needRender){
- this._updateClipDatas(crossClipState,addtive,crossPlayStateInfo,timerScale *crossSpeed);
- this._setClipDatasToNode(crossClipState,addtive,controllerLayer.defaultWeight,i===0);
- controllerLayer._playType=0;
- controllerLayer._currentPlayState=crossClipState;
- crossPlayStateInfo._cloneTo(playStateInfo);
- }
- }else {
- if (!playStateInfo._finish){
- speed=this._speed *animatorState.speed;
- this._updatePlayer(animatorState,playStateInfo,delta *speed,clip.islooping);
- if (needRender){
- this._updateClipDatas(animatorState,addtive,playStateInfo,timerScale *speed);
- }
- }
- if (needRender){
- this._updateClipDatas(crossClipState,addtive,crossPlayStateInfo,timerScale *crossScale *crossSpeed);
- this._setCrossClipDatasToNode(controllerLayer,animatorState,crossClipState,crossWeight,i===0);
- }
- }
- if (needRender){
- this._updateEventScript(animatorState,playStateInfo);
- this._updateEventScript(crossClipState,crossPlayStateInfo);
- }
- break ;
- case 2:
- crossClipState=controllerLayer._crossPlayState;
- crossClip=crossClipState._clip;
- crossDuratuion=controllerLayer._crossDuration;
- startPlayTime=crossPlayStateInfo._startPlayTime;
- crossClipDuration=crossClip._duration-startPlayTime;
- crossScale=crossDuratuion > crossClipDuration ? crossClipDuration / crossDuratuion :1.0;
- crossSpeed=this._speed *crossClipState.speed;
- this._updatePlayer(crossClipState,crossPlayStateInfo,delta *crossScale *crossSpeed,crossClip.islooping);
- if (needRender){
- crossWeight=((crossPlayStateInfo._elapsedTime-startPlayTime)/ crossScale)/ crossDuratuion;
- if (crossWeight >=1.0){
- this._updateClipDatas(crossClipState,addtive,crossPlayStateInfo,timerScale *crossSpeed);
- this._setClipDatasToNode(crossClipState,addtive,1.0,i===0);
- controllerLayer._playType=0;
- controllerLayer._currentPlayState=crossClipState;
- crossPlayStateInfo._cloneTo(playStateInfo);
- }else {
- this._updateClipDatas(crossClipState,addtive,crossPlayStateInfo,timerScale *crossScale *crossSpeed);
- this._setFixedCrossClipDatasToNode(controllerLayer,crossClipState,crossWeight,i===0);
- }
- this._updateEventScript(crossClipState,crossPlayStateInfo);
- }
- break ;
- }
- }
- if (needRender){
- if (this._avatar){
- Render.supportWebGLPlusAnimation && this._updateAnimationNodeWorldMatix(this._animationNodeLocalPositions,this._animationNodeLocalRotations,this._animationNodeLocalScales,this._animationNodeWorldMatrixs,this._animationNodeParentIndices);
- this._updateAvatarNodesToSprite();
- }
- }
- }
- /**
- *@private
- */
- __proto._cloneTo=function(dest){
- var animator=dest;
- animator.avatar=this.avatar;
- for (var i=0,n=this._controllerLayers.length;i < n;i++){
- var controllLayer=this._controllerLayers[i];
- animator.addControllerLayer(controllLayer.clone());
- var animatorStates=controllLayer._states;
- for (var j=0,m=animatorStates.length;j < m;j++){
- var state=animatorStates[j].clone();
- animator.addState(state,i);
- (j==0)&& (animator.getControllerLayer(i).defaultState=state);
- }
- }
- animator._linkSprites=this._linkSprites;
- animator._linkToSprites(this._linkSprites);
- }
- /**
- *获取默认动画状态。
- *@param layerIndex 层索引。
- *@return 默认动画状态。
- */
- __proto.getDefaultState=function(layerIndex){
- (layerIndex===void 0)&& (layerIndex=0);
- var controllerLayer=this._controllerLayers[layerIndex];
- return controllerLayer.defaultState;
- }
- /**
- *添加动画状态。
- *@param state 动画状态。
- *@param layerIndex 层索引。
- */
- __proto.addState=function(state,layerIndex){
- (layerIndex===void 0)&& (layerIndex=0);
- var stateName=state.name;
- var controllerLayer=this._controllerLayers[layerIndex];
- var statesMap=controllerLayer._statesMap;
- var states=controllerLayer._states;
- if (statesMap[stateName]){
- throw "Animator:this stat's name has exist.";
- }else {
- statesMap[stateName]=state;
- states.push(state);
- state._clip._addReference();
- this._getOwnersByClip(state);
- }
- }
- /**
- *移除动画状态。
- *@param state 动画状态。
- *@param layerIndex 层索引。
- */
- __proto.removeState=function(state,layerIndex){
- (layerIndex===void 0)&& (layerIndex=0);
- var controllerLayer=this._controllerLayers[layerIndex];
- var clipStateInfos=controllerLayer._states;
- var statesMap=controllerLayer._statesMap;
- var index=-1;
- for (var i=0,n=clipStateInfos.length;i < n;i++){
- if (clipStateInfos[i]===state){
- index=i;
- break ;
- }
- }
- if (index!==-1)
- this._removeClip(clipStateInfos,statesMap,index,state);
- }
- /**
- *添加控制器层。
- */
- __proto.addControllerLayer=function(controllderLayer){
- this._controllerLayers.push(controllderLayer);
- }
- /**
- *获取控制器层。
- */
- __proto.getControllerLayer=function(layerInex){
- (layerInex===void 0)&& (layerInex=0);
- return this._controllerLayers[layerInex];
- }
- /**
- *获取当前的播放状态。
- *@param layerIndex 层索引。
- *@return 动画播放状态。
- */
- __proto.getCurrentAnimatorPlayState=function(layerInex){
- (layerInex===void 0)&& (layerInex=0);
- return this._controllerLayers[layerInex]._playStateInfo;
- }
- /**
- *播放动画。
- *@param name 如果为null则播放默认动画,否则按名字播放动画片段。
- *@param layerIndex 层索引。
- *@param normalizedTime 归一化的播放起始时间。
- */
- __proto.play=function(name,layerIndex,normalizedTime){
- (layerIndex===void 0)&& (layerIndex=0);
- (normalizedTime===void 0)&& (normalizedTime=Number.NEGATIVE_INFINITY);
- var controllerLayer=this._controllerLayers[layerIndex];
- var defaultState=controllerLayer.defaultState;
- if (!name && !defaultState)
- throw new Error("Animator:must have default clip value,please set clip property.");
- var curPlayState=controllerLayer._currentPlayState;
- var playStateInfo=controllerLayer._playStateInfo;
- var animatorState=name ? controllerLayer._statesMap[name] :defaultState;
- var clipDuration=animatorState._clip._duration;
- if (curPlayState!==animatorState){
- if (normalizedTime!==Number.NEGATIVE_INFINITY)
- playStateInfo._resetPlayState(clipDuration *normalizedTime);
- else
- playStateInfo._resetPlayState(0.0);
- (curPlayState!==null && curPlayState!==animatorState)&& (this._revertDefaultKeyframeNodes(curPlayState));
- controllerLayer._playType=0;
- controllerLayer._currentPlayState=animatorState;
- }else {
- if (normalizedTime!==Number.NEGATIVE_INFINITY){
- playStateInfo._resetPlayState(clipDuration *normalizedTime);
- controllerLayer._playType=0;
- }
- };
- var scripts=animatorState._scripts;
- if (scripts){
- for (var i=0,n=scripts.length;i < n;i++)
- scripts[i].onStateEnter();
- }
- }
- /**
- *在当前动画状态和目标动画状态之间进行融合过渡播放。
- *@param name 目标动画状态。
- *@param transitionDuration 过渡时间,该值为当前动画状态的归一化时间,值在0.0~1.0之间。
- *@param layerIndex 层索引。
- *@param normalizedTime 归一化的播放起始时间。
- */
- __proto.crossFade=function(name,transitionDuration,layerIndex,normalizedTime){
- (layerIndex===void 0)&& (layerIndex=0);
- (normalizedTime===void 0)&& (normalizedTime=Number.NEGATIVE_INFINITY);
- var controllerLayer=this._controllerLayers[layerIndex];
- var destAnimatorState=controllerLayer._statesMap[name];
- if (destAnimatorState){
- var playType=controllerLayer._playType;
- if (playType===-1){
- this.play(name,layerIndex,normalizedTime);
- return;
- };
- var crossPlayStateInfo=controllerLayer._crossPlayStateInfo;
- var crossNodeOwners=controllerLayer._crossNodesOwners;
- var crossNodeOwnerIndicesMap=controllerLayer._crossNodesOwnersIndicesMap;
- var srcAnimatorState=controllerLayer._currentPlayState;
- var destNodeOwners=destAnimatorState._nodeOwners;
- var destCrossClipNodeIndices=controllerLayer._destCrossClipNodeIndices;
- var destClip=destAnimatorState._clip;
- var destNodes=destClip._nodes;
- var destNodesMap=destClip._nodesDic;
- switch (playType){
- case 0:;
- var srcNodeOwners=srcAnimatorState._nodeOwners;
- var scrCrossClipNodeIndices=controllerLayer._srcCrossClipNodeIndices;
- var srcClip=srcAnimatorState._clip;
- var srcNodes=srcClip._nodes;
- var srcNodesMap=srcClip._nodesDic;
- controllerLayer._playType=1;
- var crossMark=++controllerLayer._crossMark;
- var crossCount=controllerLayer._crossNodesOwnersCount=0;
- for (var i=0,n=srcNodes.count;i < n;i++){
- var srcNode=srcNodes.getNodeByIndex(i);
- var srcIndex=srcNode._indexInList;
- var srcNodeOwner=srcNodeOwners[srcIndex];
- if (srcNodeOwner){
- var srcFullPath=srcNode.fullPath;
- scrCrossClipNodeIndices[crossCount]=srcIndex;
- var destNode=destNodesMap[srcFullPath];
- if (destNode)
- destCrossClipNodeIndices[crossCount]=destNode._indexInList;
- else
- destCrossClipNodeIndices[crossCount]=-1;
- crossNodeOwnerIndicesMap[srcFullPath]=crossMark;
- crossNodeOwners[crossCount]=srcNodeOwner;
- crossCount++;
- }
- }
- for (i=0,n=destNodes.count;i < n;i++){
- destNode=destNodes.getNodeByIndex(i);
- var destIndex=destNode._indexInList;
- var destNodeOwner=destNodeOwners[destIndex];
- if (destNodeOwner){
- var destFullPath=destNode.fullPath;
- if (!srcNodesMap[destFullPath]){
- scrCrossClipNodeIndices[crossCount]=-1;
- destCrossClipNodeIndices[crossCount]=destIndex;
- crossNodeOwnerIndicesMap[destFullPath]=crossMark;
- crossNodeOwners[crossCount]=destNodeOwner;
- crossCount++;
- }
- }
- }
- break ;
- case 1:
- case 2:
- controllerLayer._playType=2;
- for (i=0,n=crossNodeOwners.length;i < n;i++){
- var nodeOwner=crossNodeOwners[i];
- nodeOwner.saveCrossFixedValue();
- destNode=destNodesMap[nodeOwner.fullPath];
- if (destNode)
- destCrossClipNodeIndices[i]=destNode._indexInList;
- else
- destCrossClipNodeIndices[i]=-1;
- }
- crossCount=controllerLayer._crossNodesOwnersCount;
- crossMark=controllerLayer._crossMark;
- for (i=0,n=destNodes.count;i < n;i++){
- destNode=destNodes.getNodeByIndex(i);
- destIndex=destNode._indexInList;
- destNodeOwner=destNodeOwners[destIndex];
- if (destNodeOwner){
- destFullPath=destNode.fullPath;
- if (crossNodeOwnerIndicesMap[destFullPath]!==crossMark){
- destCrossClipNodeIndices[crossCount]=destIndex;
- crossNodeOwnerIndicesMap[destFullPath]=crossMark;
- nodeOwner=destNodeOwners[destIndex];
- crossNodeOwners[crossCount]=nodeOwner;
- nodeOwner.saveCrossFixedValue();
- crossCount++;
- }
- }
- }
- break ;
- default :
- }
- controllerLayer._crossNodesOwnersCount=crossCount;
- controllerLayer._crossPlayState=destAnimatorState;
- controllerLayer._crossDuration=srcAnimatorState._clip._duration *transitionDuration;
- if (normalizedTime!==Number.NEGATIVE_INFINITY)
- crossPlayStateInfo._resetPlayState(destClip._duration *normalizedTime);
- else
- crossPlayStateInfo._resetPlayState(0.0);
- };
- var scripts=destAnimatorState._scripts;
- if (scripts){
- for (i=0,n=scripts.length;i < n;i++)
- scripts[i].onStateEnter();
- }
- }
- /**
- *@private
- */
- __proto._getAvatarOwnersAndInitDatasAsync=function(){
- for (var i=0,n=this._controllerLayers.length;i < n;i++){
- var clipStateInfos=this._controllerLayers[i]._states;
- for (var j=0,m=clipStateInfos.length;j < m;j++)
- this._getOwnersByClip(clipStateInfos[j]);
- }
- this._avatar._cloneDatasToAnimator(this);
- for (var k in this._linkAvatarSpritesData){
- var sprites=this._linkAvatarSpritesData[k];
- if (sprites){
- for (var c=0,p=sprites.length;c < p;c++)
- this._isLinkSpriteToAnimationNode(sprites[c],k,true);
- }
- }
- }
- /**
- *@private
- */
- __proto._isLinkSpriteToAnimationNode=function(sprite,nodeName,isLink){
- if (this._avatar){
- var node=this._avatarNodeMap[nodeName];
- if (node){
- if (isLink){
- sprite._transform._dummy=node.transform;
- this._linkAvatarSprites.push(sprite);
- var nodeTransform=node.transform;
- var spriteTransform=sprite.transform;
- if (!spriteTransform.owner.isStatic && nodeTransform){
- var spriteWorldMatrix=spriteTransform.worldMatrix;
- var ownParTra=(this.owner)._transform._parent;
- if (ownParTra){
- Utils3D.matrix4x4MultiplyMFM(ownParTra.worldMatrix,nodeTransform.getWorldMatrix(),spriteWorldMatrix);
- }else {
- var sprWorE=spriteWorldMatrix.elements;
- var nodWorE=nodeTransform.getWorldMatrix();
- for (var i=0;i < 16;i++)
- sprWorE[i]=nodWorE[i];
- }
- spriteTransform.worldMatrix=spriteWorldMatrix;
- }
- }else {
- sprite._transform._dummy=null;
- this._linkAvatarSprites.splice(this._linkAvatarSprites.indexOf(sprite),1);
- }
- }
- }
- }
- /**
- *@private
- */
- __proto._isLinkSpriteToAnimationNodeData=function(sprite,nodeName,isLink){
- var linkSprites=this._linkAvatarSpritesData[nodeName];
- if (isLink){
- linkSprites || (this._linkAvatarSpritesData[nodeName]=linkSprites=[]);
- linkSprites.push(sprite);
- }else {
- linkSprites.splice(sprite,1);
- }
- }
- /**
- *@private
- */
- __proto._updateAvatarNodesToSprite=function(){
- for (var i=0,n=this._linkAvatarSprites.length;i < n;i++){
- var sprite=this._linkAvatarSprites[i];
- var nodeTransform=sprite.transform._dummy;
- var spriteTransform=sprite.transform;
- if (!spriteTransform.owner.isStatic && nodeTransform){
- var spriteWorldMatrix=spriteTransform.worldMatrix;
- var ownTra=(this.owner)._transform;
- Utils3D.matrix4x4MultiplyMFM(ownTra.worldMatrix,nodeTransform.getWorldMatrix(),spriteWorldMatrix);
- spriteTransform.worldMatrix=spriteWorldMatrix;
- }
- }
- }
- /**
- *关联精灵节点到Avatar节点,此Animator必须有Avatar文件。
- *@param nodeName 关联节点的名字。
- *@param sprite3D 精灵节点。
- *@return 是否关联成功。
- */
- __proto.linkSprite3DToAvatarNode=function(nodeName,sprite3D){
- this._isLinkSpriteToAnimationNodeData(sprite3D,nodeName,true);
- this._isLinkSpriteToAnimationNode(sprite3D,nodeName,true);
- return true;
- }
- /**
- *解除精灵节点到Avatar节点的关联,此Animator必须有Avatar文件。
- *@param sprite3D 精灵节点。
- *@return 是否解除关联成功。
- */
- __proto.unLinkSprite3DToAvatarNode=function(sprite3D){
- if (sprite3D._hierarchyAnimator===this){
- var dummy=sprite3D.transform._dummy;
- if (dummy){
- var nodeName=dummy._owner.name;
- this._isLinkSpriteToAnimationNodeData(sprite3D,nodeName,false);
- this._isLinkSpriteToAnimationNode(sprite3D,nodeName,false);
- return true;
- }else {
- return false;
- }
- }else {
- throw("Animator:sprite3D must belong to this Animator");
- return false;
- }
- }
- /**
- *@private
- *[NATIVE]
- */
- __proto._updateAnimationNodeWorldMatix=function(localPositions,localRotations,localScales,worldMatrixs,parentIndices){
- LayaGL.instance.updateAnimationNodeWorldMatix(localPositions,localRotations,localScales,parentIndices,worldMatrixs);
- }
- /**
- *设置动画的播放速度,1.0为正常播放速度。
- *@param 动画的播放速度。
- */
- /**
- *获取动画的播放速度,1.0为正常播放速度。
- *@return 动画的播放速度。
- */
- __getset(0,__proto,'speed',function(){
- return this._speed;
- },function(value){
- this._speed=value;
- });
- /**
- *设置avatar。
- *@param value avatar。
- */
- /**
- *获取avatar。
- *@return avator。
- */
- __getset(0,__proto,'avatar',function(){
- return this._avatar;
- },function(value){
- if (this._avatar!==value){
- this._avatar=value;
- if (value){
- this._getAvatarOwnersAndInitDatasAsync();
- (this.owner)._changeHierarchyAnimatorAvatar(this,value);
- }else {
- var parent=this.owner._parent;
- (this.owner)._changeHierarchyAnimatorAvatar(this,parent ? (parent)._hierarchyAnimator._avatar :null);
- }
- }
- });
- Animator._update=function(scene){
- var pool=scene._animatorPool;
- var elements=pool.elements;
- for (var i=0,n=pool.length;i < n;i++){
- var animator=elements[i];
- (animator && animator.enabled)&& (animator._update());
- }
- }
- Animator._tempVector3Array0=new Float32Array(3);
- Animator._tempVector3Array1=new Float32Array(3);
- Animator._tempQuaternionArray0=new Float32Array(4);
- Animator._tempQuaternionArray1=new Float32Array(4);
- Animator.CULLINGMODE_ALWAYSANIMATE=0;
- Animator.CULLINGMODE_CULLCOMPLETELY=2;
- __static(Animator,
- ['_tempVector30',function(){return this._tempVector30=new Vector3();},'_tempVector31',function(){return this._tempVector31=new Vector3();},'_tempQuaternion0',function(){return this._tempQuaternion0=new Quaternion();},'_tempQuaternion1',function(){return this._tempQuaternion1=new Quaternion();}
- ]);
- return Animator;
- })(Component)
- /**
- *<code>AnimationTransform3D</code> 类用于实现3D变换。
- */
- //class laya.d3.animation.AnimationTransform3D extends laya.events.EventDispatcher
- var AnimationTransform3D=(function(_super){
- function AnimationTransform3D(owner,localPosition,localRotation,localScale,worldMatrix){
- /**@private */
- //this._localMatrix=null;
- /**@private */
- //this._worldMatrix=null;
- /**@private */
- //this._localPosition=null;
- /**@private */
- //this._localRotation=null;
- /**@private */
- //this._localScale=null;
- /**@private */
- //this._localQuaternionUpdate=false;
- /**@private */
- //this._locaEulerlUpdate=false;
- /**@private */
- //this._localUpdate=false;
- /**@private */
- //this._parent=null;
- /**@private */
- //this._children=null;
- /**@private */
- //this._localRotationEuler=null;
- /**@private */
- //this._owner=null;
- /**@private */
- //this._worldUpdate=false;
- AnimationTransform3D.__super.call(this);
- this._owner=owner;
- this._children=[];
- this._localMatrix=new Float32Array(16);
- if (Render.supportWebGLPlusAnimation){
- /*__JS__ */this._localPosition=new ConchVector3(0,0,0,localPosition);
- /*__JS__ */this._localRotation=new ConchQuaternion(0,0,0,1,localRotation);
- /*__JS__ */this._localScale=new ConchVector3(0,0,0,localScale);
- this._worldMatrix=worldMatrix;
- }else {
- this._localPosition=new Vector3();
- this._localRotation=new Quaternion();
- this._localScale=new Vector3();
- this._worldMatrix=new Float32Array(16);
- }
- this._localQuaternionUpdate=false;
- this._locaEulerlUpdate=false;
- this._localUpdate=false;
- this._worldUpdate=true;
- }
- __class(AnimationTransform3D,'laya.d3.animation.AnimationTransform3D',_super);
- var __proto=AnimationTransform3D.prototype;
- /**
- *@private
- */
- __proto._getlocalMatrix=function(){
- if (this._localUpdate){
- Utils3D._createAffineTransformationArray(this._localPosition,this._localRotation,this._localScale,this._localMatrix);
- this._localUpdate=false;
- }
- return this._localMatrix;
- }
- /**
- *@private
- */
- __proto._onWorldTransform=function(){
- if (!this._worldUpdate){
- this._worldUpdate=true;
- this.event(/*laya.events.Event.TRANSFORM_CHANGED*/"transformchanged");
- for (var i=0,n=this._children.length;i < n;i++)
- this._children[i]._onWorldTransform();
- }
- }
- /**
- *获取世界矩阵。
- *@return 世界矩阵。
- */
- __proto.getWorldMatrix=function(){
- if (!Render.supportWebGLPlusAnimation && this._worldUpdate){
- if (this._parent !=null){
- Utils3D.matrix4x4MultiplyFFF(this._parent.getWorldMatrix(),this._getlocalMatrix(),this._worldMatrix);
- }else {
- var e=this._worldMatrix;
- 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;
- e[0]=e[5]=e[10]=e[15]=1;
- }
- this._worldUpdate=false;
- }
- if (Render.supportWebGLPlusAnimation && this._worldUpdate){
- this._worldUpdate=false;
- }
- return this._worldMatrix;
- }
- /**
- *设置父3D变换。
- *@param value 父3D变换。
- */
- __proto.setParent=function(value){
- if (this._parent!==value){
- if (this._parent){
- var parentChilds=this._parent._children;
- var index=parentChilds.indexOf(this);
- parentChilds.splice(index,1);
- }
- if (value){
- value._children.push(this);
- (value)&& (this._onWorldTransform());
- }
- this._parent=value;
- }
- }
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'localPosition',function(){
- return this._localPosition;
- },function(value){
- this._localPosition=value;
- this._localUpdate=true;
- this._onWorldTransform();
- });
- /*
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'localRotation',function(){
- if (this._localQuaternionUpdate){
- var euler=this._localRotationEuler;
- Quaternion.createFromYawPitchRoll(euler.y / AnimationTransform3D._angleToRandin,euler.x / AnimationTransform3D._angleToRandin,euler.z / AnimationTransform3D._angleToRandin,this._localRotation);
- this._localQuaternionUpdate=false;
- }
- return this._localRotation;
- },function(value){
- this._localRotation=value;
- this._locaEulerlUpdate=true;
- this._localQuaternionUpdate=false;
- this._localUpdate=true;
- this._onWorldTransform();
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'localScale',function(){
- return this._localScale;
- },function(value){
- this._localScale=value;
- this._localUpdate=true;
- this._onWorldTransform();
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'localRotationEuler',function(){
- if (this._locaEulerlUpdate){
- this._localRotation.getYawPitchRoll(AnimationTransform3D._tempVector3);
- var euler=AnimationTransform3D._tempVector3;
- var localRotationEuler=this._localRotationEuler;
- localRotationEuler.x=euler.y *AnimationTransform3D._angleToRandin;
- localRotationEuler.y=euler.x *AnimationTransform3D._angleToRandin;
- localRotationEuler.z=euler.z *AnimationTransform3D._angleToRandin;
- this._locaEulerlUpdate=false;
- }
- return this._localRotationEuler;
- },function(value){
- this._localRotationEuler=value;
- this._locaEulerlUpdate=false;
- this._localQuaternionUpdate=true;
- this._localUpdate=true;
- this._onWorldTransform();
- });
- __static(AnimationTransform3D,
- ['_tempVector3',function(){return this._tempVector3=new Vector3();},'_angleToRandin',function(){return this._angleToRandin=180 / Math.PI;}
- ]);
- return AnimationTransform3D;
- })(EventDispatcher)
- /**
- *<code>VertexBuffer3D</code> 类用于创建顶点缓冲。
- */
- //class laya.d3.graphics.VertexBuffer3D extends laya.webgl.utils.Buffer
- var VertexBuffer3D=(function(_super){
- function VertexBuffer3D(byteLength,bufferUsage,canRead,dateType){
- /**@private */
- this._vertexCount=0;
- /**@private */
- this._canRead=false;
- /**@private */
- this._dataType=0;
- /**@private */
- this._vertexDeclaration=null;
- (canRead===void 0)&& (canRead=false);
- (dateType===void 0)&& (dateType=0);
- VertexBuffer3D.__super.call(this);
- this._vertexCount=-1;
- this._bufferUsage=bufferUsage;
- this._bufferType=/*laya.webgl.WebGLContext.ARRAY_BUFFER*/0x8892;
- this._canRead=canRead;
- this._dataType=dateType;
- this._byteLength=byteLength;
- this.bind();
- LayaGL.instance.bufferData(this._bufferType,this._byteLength,this._bufferUsage);
- if (canRead){
- switch (dateType){
- case 0:
- this._buffer=new Float32Array(byteLength / 4);
- break ;
- case 1:
- this._buffer=new Uint8Array(byteLength);
- break ;
- }
- }
- }
- __class(VertexBuffer3D,'laya.d3.graphics.VertexBuffer3D',_super);
- var __proto=VertexBuffer3D.prototype;
- /**
- *@inheritDoc
- */
- __proto.bind=function(){
- if (Buffer._bindedVertexBuffer!==this._glBuffer){
- LayaGL.instance.bindBuffer(/*laya.webgl.WebGLContext.ARRAY_BUFFER*/0x8892,this._glBuffer);
- Buffer._bindedVertexBuffer=this._glBuffer;
- return true;
- }else {
- return false;
- }
- }
- /**
- *设置数据。
- *@param data 顶点数据。
- *@param bufferOffset 顶点缓冲中的偏移。
- *@param dataStartIndex 顶点数据的偏移。
- *@param dataCount 顶点数据的数量。
- */
- __proto.setData=function(data,bufferOffset,dataStartIndex,dataCount){
- (bufferOffset===void 0)&& (bufferOffset=0);
- (dataStartIndex===void 0)&& (dataStartIndex=0);
- (dataCount===void 0)&& (dataCount=4294967295);
- this.bind();
- var needSubData=dataStartIndex!==0 || dataCount!==4294967295;
- if (needSubData){
- switch (this._dataType){
- case 0:
- data=new Float32Array(data.buffer,dataStartIndex *4,dataCount);
- break ;
- case 1:
- data=new Uint8Array(data.buffer,dataStartIndex,dataCount);
- break ;
- }
- }
- switch (this._dataType){
- case 0:
- LayaGL.instance.bufferSubData(this._bufferType,bufferOffset *4,data);
- break ;
- case 1:
- LayaGL.instance.bufferSubData(this._bufferType,bufferOffset,data);
- break ;
- }
- if (this._canRead)
- this._buffer.set(data,bufferOffset);
- }
- /**
- *获取顶点数据。
- *@return 顶点数据。
- */
- __proto.getData=function(){
- if (this._canRead)
- return this._buffer;
- else
- throw new Error("Can't read data from VertexBuffer with only write flag!");
- }
- /**
- *@inheritDoc
- */
- __proto.destroy=function(){
- _super.prototype.destroy.call(this);
- this._buffer=null;
- this._vertexDeclaration=null;
- }
- /**
- *获取顶点声明。
- */
- /**
- *获取顶点声明。
- */
- __getset(0,__proto,'vertexDeclaration',function(){
- return this._vertexDeclaration;
- },function(value){
- if (this._vertexDeclaration!==value){
- this._vertexDeclaration=value;
- this._vertexCount=value ? this._byteLength / value.vertexStride :-1;
- }
- });
- /**
- *获取顶点个数。
- *@return 顶点个数。
- */
- __getset(0,__proto,'vertexCount',function(){
- return this._vertexCount;
- });
- /**
- *获取是否可读。
- *@return 是否可读。
- */
- __getset(0,__proto,'canRead',function(){
- return this._canRead;
- });
- VertexBuffer3D.DATATYPE_FLOAT32ARRAY=0;
- VertexBuffer3D.DATATYPE_UINT8ARRAY=1;
- return VertexBuffer3D;
- })(Buffer)
- /**
- *<code>ConstraintComponent</code> 类用于创建约束的父类。
- */
- //class laya.d3.physics.constraints.ConstraintComponent extends laya.components.Component
- var ConstraintComponent=(function(_super){
- function ConstraintComponent(){
- /**@private */
- this._nativeConstraint=null;
- /**@private */
- this._breakingImpulseThreshold=NaN;
- /**@private */
- this._connectedBody=null;
- /**@private */
- this._feedbackEnabled=false;
- ConstraintComponent.__super.call(this);
- }
- __class(ConstraintComponent,'laya.d3.physics.constraints.ConstraintComponent',_super);
- var __proto=ConstraintComponent.prototype;
- /**
- *@inheritDoc
- */
- __proto._onDestroy=function(){
- var physics3D=Laya3D._physics3D;
- physics3D.destroy(this._nativeConstraint);
- this._nativeConstraint=null;
- }
- /**
- *设置打破冲力阈值。
- *@param value 打破冲力阈值。
- */
- /**
- *获取打破冲力阈值。
- *@return 打破冲力阈值。
- */
- __getset(0,__proto,'breakingImpulseThreshold',function(){
- return this._breakingImpulseThreshold;
- },function(value){
- this._nativeConstraint.BreakingImpulseThreshold=value;
- this._breakingImpulseThreshold=value;
- });
- /**
- *@inheritDoc
- */
- /**
- *@inheritDoc
- */
- __getset(0,__proto,'enabled',function(){
- return Laya.superGet(Component,this,'enabled');
- },function(value){
- this._nativeConstraint.IsEnabled=value;
- Laya.superSet(Component,this,'enabled',value);
- });
- /**
- *获取应用的冲力。
- */
- __getset(0,__proto,'appliedImpulse',function(){
- if (!this._feedbackEnabled){
- this._nativeConstraint.EnableFeedback(true);
- this._feedbackEnabled=true;
- }
- return this._nativeConstraint.AppliedImpulse;
- });
- /**
- *设置已连接刚体。
- *@param value 已连接刚体。
- */
- /**
- *获取已连接的刚体。
- *@return 已连接刚体。
- */
- __getset(0,__proto,'connectedBody',function(){
- return this._connectedBody;
- },function(value){
- this._connectedBody=value;
- });
- return ConstraintComponent;
- })(Component)
- /**
- *<code>IndexBuffer3D</code> 类用于创建索引缓冲。
- */
- //class laya.d3.graphics.IndexBuffer3D extends laya.webgl.utils.Buffer
- var IndexBuffer3D=(function(_super){
- function IndexBuffer3D(indexType,indexCount,bufferUsage,canRead){
- /**@private */
- this._indexType=null;
- /**@private */
- this._indexTypeByteCount=0;
- /**@private */
- this._indexCount=0;
- /**@private */
- this._canRead=false;
- (bufferUsage===void 0)&& (bufferUsage=0x88E4);
- (canRead===void 0)&& (canRead=false);
- IndexBuffer3D.__super.call(this);
- this._indexType=indexType;
- this._indexCount=indexCount;
- this._bufferUsage=bufferUsage;
- this._bufferType=/*laya.webgl.WebGLContext.ELEMENT_ARRAY_BUFFER*/0x8893;
- this._canRead=canRead;
- var byteLength=0;
- if (indexType==/*CLASS CONST:laya.d3.graphics.IndexBuffer3D.INDEXTYPE_USHORT*/"ushort")
- this._indexTypeByteCount=2;
- else if (indexType==/*CLASS CONST:laya.d3.graphics.IndexBuffer3D.INDEXTYPE_UBYTE*/"ubyte")
- this._indexTypeByteCount=1;
- else
- throw new Error("unidentification index type.");
- byteLength=this._indexTypeByteCount *indexCount;
- this._byteLength=byteLength;
- var curBufSta=BufferStateBase._curBindedBufferState;
- if (curBufSta){
- if (curBufSta._bindedIndexBuffer===this){
- LayaGL.instance.bufferData(this._bufferType,byteLength,this._bufferUsage);
- }else {
- curBufSta.unBind();
- this.bind();
- LayaGL.instance.bufferData(this._bufferType,byteLength,this._bufferUsage);
- curBufSta.bind();
- }
- }else {
- this.bind();
- LayaGL.instance.bufferData(this._bufferType,byteLength,this._bufferUsage);
- }
- if (canRead){
- if (indexType==/*CLASS CONST:laya.d3.graphics.IndexBuffer3D.INDEXTYPE_USHORT*/"ushort")
- this._buffer=new Uint16Array(indexCount);
- else if (indexType==/*CLASS CONST:laya.d3.graphics.IndexBuffer3D.INDEXTYPE_UBYTE*/"ubyte")
- this._buffer=new Uint8Array(indexCount);
- }
- }
- __class(IndexBuffer3D,'laya.d3.graphics.IndexBuffer3D',_super);
- var __proto=IndexBuffer3D.prototype;
- /**
- *@inheritDoc
- */
- __proto._bindForVAO=function(){
- if (BufferStateBase._curBindedBufferState){
- LayaGL.instance.bindBuffer(/*laya.webgl.WebGLContext.ELEMENT_ARRAY_BUFFER*/0x8893,this._glBuffer);
- }else {
- throw "IndexBuffer3D: must bind current BufferState.";
- }
- }
- /**
- *@inheritDoc
- */
- __proto.bind=function(){
- if (BufferStateBase._curBindedBufferState){
- throw "IndexBuffer3D: must unbind current BufferState.";
- }else {
- if (Buffer._bindedIndexBuffer!==this._glBuffer){
- LayaGL.instance.bindBuffer(/*laya.webgl.WebGLContext.ELEMENT_ARRAY_BUFFER*/0x8893,this._glBuffer);
- Buffer._bindedIndexBuffer=this._glBuffer;
- return true;
- }else {
- return false;
- }
- }
- }
- /**
- *设置数据。
- *@param data 索引数据。
- *@param bufferOffset 索引缓冲中的偏移。
- *@param dataStartIndex 索引数据的偏移。
- *@param dataCount 索引数据的数量。
- */
- __proto.setData=function(data,bufferOffset,dataStartIndex,dataCount){
- (bufferOffset===void 0)&& (bufferOffset=0);
- (dataStartIndex===void 0)&& (dataStartIndex=0);
- (dataCount===void 0)&& (dataCount=4294967295);
- var byteCount=0;
- if (this._indexType==/*CLASS CONST:laya.d3.graphics.IndexBuffer3D.INDEXTYPE_USHORT*/"ushort"){
- byteCount=2;
- if (dataStartIndex!==0 || dataCount!==4294967295)
- data=new Uint16Array(data.buffer,dataStartIndex *byteCount,dataCount);
- }else if (this._indexType==/*CLASS CONST:laya.d3.graphics.IndexBuffer3D.INDEXTYPE_UBYTE*/"ubyte"){
- byteCount=1;
- if (dataStartIndex!==0 || dataCount!==4294967295)
- data=new Uint8Array(data.buffer,dataStartIndex *byteCount,dataCount);
- };
- var curBufSta=BufferStateBase._curBindedBufferState;
- if (curBufSta){
- if (curBufSta._bindedIndexBuffer===this){
- LayaGL.instance.bufferSubData(this._bufferType,bufferOffset *byteCount,data);
- }else {
- curBufSta.unBind();
- this.bind();
- LayaGL.instance.bufferSubData(this._bufferType,bufferOffset *byteCount,data);
- curBufSta.bind();
- }
- }else {
- this.bind();
- LayaGL.instance.bufferSubData(this._bufferType,bufferOffset *byteCount,data);
- }
- if (this._canRead){
- if (bufferOffset!==0 || dataStartIndex!==0 || dataCount!==4294967295){
- var maxLength=this._buffer.length-bufferOffset;
- if (dataCount > maxLength)
- dataCount=maxLength;
- for (var i=0;i < dataCount;i++)
- this._buffer[bufferOffset+i]=data[i];
- }else {
- this._buffer=data;
- }
- }
- }
- /**
- *获取索引数据。
- *@return 索引数据。
- */
- __proto.getData=function(){
- if (this._canRead)
- return this._buffer;
- else
- throw new Error("Can't read data from VertexBuffer with only write flag!");
- }
- /**
- *@inheritDoc
- */
- __proto.destroy=function(){
- _super.prototype.destroy.call(this);
- this._buffer=null;
- }
- /**
- *获取索引类型。
- *@return 索引类型。
- */
- __getset(0,__proto,'indexType',function(){
- return this._indexType;
- });
- /**
- *获取索引类型字节数量。
- *@return 索引类型字节数量。
- */
- __getset(0,__proto,'indexTypeByteCount',function(){
- return this._indexTypeByteCount;
- });
- /**
- *获取索引个数。
- *@return 索引个数。
- */
- __getset(0,__proto,'indexCount',function(){
- return this._indexCount;
- });
- /**
- *获取是否可读。
- *@return 是否可读。
- */
- __getset(0,__proto,'canRead',function(){
- return this._canRead;
- });
- IndexBuffer3D.INDEXTYPE_UBYTE="ubyte";
- IndexBuffer3D.INDEXTYPE_USHORT="ushort";
- return IndexBuffer3D;
- })(Buffer)
- /**
- *<code>ShaderPass</code> 类用于实现ShaderPass。
- */
- //class laya.d3.shader.ShaderPass extends laya.webgl.utils.ShaderCompile
- var ShaderPass=(function(_super){
- function ShaderPass(owner,vs,ps,stateMap){
- /**@private */
- //this._owner=null;
- /**@private */
- //this._stateMap=null;
- /**@private */
- //this._cacheSharders=null;
- /**@private */
- //this._publicValidDefine=0;
- /**@private */
- //this._spriteValidDefine=0;
- /**@private */
- //this._materialValidDefine=0;
- /**@private */
- //this._validDefineMap=null;
- this._renderState=new RenderState();
- this._owner=owner;
- this._cacheSharders=[];
- this._publicValidDefine=0;
- this._spriteValidDefine=0;
- this._materialValidDefine=0;
- this._validDefineMap={};
- ShaderPass.__super.call(this,vs,ps,null,this._validDefineMap);
- var publicDefineMap=this._owner._publicDefinesMap;
- var spriteDefineMap=this._owner._spriteDefinesMap;
- var materialDefineMap=this._owner._materialDefinesMap;
- for (var k in this._validDefineMap){
- if (publicDefineMap[k] !=null)
- this._publicValidDefine |=publicDefineMap[k];
- else if (spriteDefineMap[k] !=null)
- this._spriteValidDefine |=spriteDefineMap[k];
- else if (materialDefineMap[k] !=null)
- this._materialValidDefine |=materialDefineMap[k];
- }
- this._stateMap=stateMap;
- }
- __class(ShaderPass,'laya.d3.shader.ShaderPass',_super);
- var __proto=ShaderPass.prototype;
- /**
- *@private
- */
- __proto._definesToNameDic=function(value,int2Name){
- var o={};
- var d=1;
- for (var i=0;i < 32;i++){
- d=1 << i;
- if (d > value)break ;
- if (value & d){
- var name=int2Name[d];
- o[name]="";
- }
- }
- return o;
- }
- /**
- *@inheritDoc
- */
- __proto._compileToTree=function(parent,lines,start,includefiles,defs){
- var node,preNode;
- var text,name,fname;
- var ofs=0,words,noUseNode;
- var i=0,n=0,j=0;
- for (i=start;i < lines.length;i++){
- text=lines[i];
- if (text.length < 1)continue ;
- ofs=text.indexOf("//");
- if (ofs===0)continue ;
- if (ofs >=0)text=text.substr(0,ofs);
- node=noUseNode || new ShaderNode(includefiles);
- noUseNode=null;
- node.text=text;
- if ((ofs=text.indexOf("#"))>=0){
- name="#";
- for (j=ofs+1,n=text.length;j < n;j++){
- var c=text.charAt(j);
- if (c===' ' || c==='\t' || c==='?')break ;
- name+=c;
- }
- node.name=name;
- switch (name){
- case "#ifdef":
- case "#ifndef":
- node.setParent(parent);
- parent=node;
- if (defs){
- words=text.substr(j).split(ShaderCompile._splitToWordExps3);
- for (j=0;j < words.length;j++){
- text=words[j];
- text.length && (defs[text]=true);
- }
- }
- continue ;
- case "#if":
- case "#elif":
- node.setParent(parent);
- parent=node;
- if (defs){
- words=text.substr(j).split(ShaderCompile._splitToWordExps3);
- for (j=0;j < words.length;j++){
- text=words[j];
- text.length && text !="defined" && (defs[text]=true);
- }
- }
- continue ;
- case "#else":
- parent=parent.parent;
- preNode=parent.childs[parent.childs.length-1];
- node.setParent(parent);
- parent=node;
- continue ;
- case "#endif":
- parent=parent.parent;
- preNode=parent.childs[parent.childs.length-1];
- node.setParent(parent);
- continue ;
- case "#include":
- words=ShaderCompile.splitToWords(text,null);
- var inlcudeFile=ShaderCompile.includes[words[1]];
- if (!inlcudeFile){
- throw "ShaderCompile error no this include file:"+words[1];
- }
- if ((ofs=words[0].indexOf("?"))< 0){
- node.setParent(parent);
- text=inlcudeFile.getWith(words[2]=='with' ? words[3] :null);
- this._compileToTree(node,text.split('\n'),0,includefiles,defs);
- node.text="";
- continue ;
- }
- node.setCondition(words[0].substr(ofs+1),1);
- node.text=inlcudeFile.getWith(words[2]=='with' ? words[3] :null);
- break ;
- case "#import":
- words=ShaderCompile.splitToWords(text,null);
- fname=words[1];
- includefiles.push({node:node,file:ShaderCompile.includes[fname],ofs:node.text.length});
- continue ;
- }
- }else {
- preNode=parent.childs[parent.childs.length-1];
- if (preNode && !preNode.name){
- includefiles.length > 0 && ShaderCompile.splitToWords(text,preNode);
- noUseNode=node;
- preNode.text+="\n"+text;
- continue ;
- }
- includefiles.length > 0 && ShaderCompile.splitToWords(text,node);
- }
- node.setParent(parent);
- }
- }
- /**
- *@private
- */
- __proto.withCompile=function(publicDefine,spriteDefine,materialDefine){
- publicDefine &=this._publicValidDefine;
- spriteDefine &=this._spriteValidDefine;
- materialDefine &=this._materialValidDefine;
- var shader;
- var spriteDefShaders,materialDefShaders;
- spriteDefShaders=this._cacheSharders[publicDefine];
- if (spriteDefShaders){
- materialDefShaders=spriteDefShaders[spriteDefine];
- if (materialDefShaders){
- shader=materialDefShaders[materialDefine];
- if (shader)
- return shader;
- }else {
- materialDefShaders=spriteDefShaders[spriteDefine]=[];
- }
- }else {
- spriteDefShaders=this._cacheSharders[publicDefine]=[];
- materialDefShaders=spriteDefShaders[spriteDefine]=[];
- };
- var publicDefGroup=this._definesToNameDic(publicDefine,this._owner._publicDefines);
- var spriteDefGroup=this._definesToNameDic(spriteDefine,this._owner._spriteDefines);
- var materialDefGroup=this._definesToNameDic(materialDefine,this._owner._materialDefines);
- var key;
- if (Shader3D.debugMode){
- var publicDefGroupStr="";
- for (key in publicDefGroup)
- publicDefGroupStr+=key+" ";
- var spriteDefGroupStr="";
- for (key in spriteDefGroup)
- spriteDefGroupStr+=key+" ";
- var materialDefGroupStr="";
- for (key in materialDefGroup)
- materialDefGroupStr+=key+" ";
- if (!WebGL.shaderHighPrecision)
- publicDefine+=Shader3D.SHADERDEFINE_HIGHPRECISION;
- console.log("%cShader3DDebugMode---(Name:"+this._owner._owner._name+" PassIndex:"+this._owner._passes.indexOf(this)+" PublicDefine:"+publicDefine+" SpriteDefine:"+spriteDefine+" MaterialDefine:"+materialDefine+" PublicDefineGroup:"+publicDefGroupStr+" SpriteDefineGroup:"+spriteDefGroupStr+"MaterialDefineGroup: "+materialDefGroupStr+")---ShaderCompile3DDebugMode","color:green");
- };
- var defMap={};
- var defineStr="";
- if (publicDefGroup){
- for (key in publicDefGroup){
- defineStr+="#define "+key+"\n";
- defMap[key]=true;
- }
- }
- if (spriteDefGroup){
- for (key in spriteDefGroup){
- defineStr+="#define "+key+"\n";
- defMap[key]=true;
- }
- }
- if (materialDefGroup){
- for (key in materialDefGroup){
- defineStr+="#define "+key+"\n";
- defMap[key]=true;
- }
- };
- var vs=this._VS.toscript(defMap,[]);
- var vsVersion='';
- if (vs[0].indexOf('#version')==0){
- vsVersion=vs[0]+'\n';
- vs.shift();
- };
- var ps=this._PS.toscript(defMap,[]);
- var psVersion='';
- if (ps[0].indexOf('#version')==0){
- psVersion=ps[0]+'\n';
- ps.shift();
- }
- 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);
- materialDefShaders[materialDefine]=shader;
- return shader;
- }
- /**
- *获取渲染状态。
- *@return 渲染状态。
- */
- __getset(0,__proto,'renderState',function(){
- return this._renderState;
- });
- return ShaderPass;
- })(ShaderCompile)
- /**
- *@private
- *<code>BufferState</code> 类用于实现渲染所需的Buffer状态集合。
- */
- //class laya.d3.core.BufferState extends laya.webgl.BufferStateBase
- var BufferState=(function(_super){
- /**
- *创建一个 <code>BufferState</code> 实例。
- */
- function BufferState(){
- BufferState.__super.call(this);
- }
- __class(BufferState,'laya.d3.core.BufferState',_super);
- var __proto=BufferState.prototype;
- /**
- *@private
- *vertexBuffer的vertexDeclaration不能为空,该函数比较消耗性能,建议初始化时使用。
- */
- __proto.applyVertexBuffer=function(vertexBuffer){
- if (BufferStateBase._curBindedBufferState===this){
- var gl=LayaGL.instance;
- var verDec=vertexBuffer.vertexDeclaration;
- var valueData=null;
- if (Render.supportWebGLPlusRendering)
- valueData=verDec._shaderValues._nativeArray;
- else
- valueData=verDec._shaderValues.getData();
- vertexBuffer.bind();
- for (var k in valueData){
- var loc=parseInt(k);
- var attribute=valueData[k];
- gl.enableVertexAttribArray(loc);
- gl.vertexAttribPointer(loc,attribute[0],attribute[1],!!attribute[2],attribute[3],attribute[4]);
- }
- }else {
- throw "BufferState: must call bind() function first.";
- }
- }
- /**
- *@private
- *vertexBuffers中的vertexDeclaration不能为空,该函数比较消耗性能,建议初始化时使用。
- */
- __proto.applyVertexBuffers=function(vertexBuffers){
- if (BufferStateBase._curBindedBufferState===this){
- var gl=LayaGL.instance;
- for (var i=0,n=vertexBuffers.length;i < n;i++){
- var verBuf=vertexBuffers[i];
- var verDec=verBuf.vertexDeclaration;
- var valueData=null;
- if (Render.supportWebGLPlusRendering)
- valueData=verDec._shaderValues._nativeArray;
- else
- valueData=verDec._shaderValues.getData();
- verBuf.bind();
- for (var k in valueData){
- var loc=parseInt(k);
- var attribute=valueData[k];
- gl.enableVertexAttribArray(loc);
- gl.vertexAttribPointer(loc,attribute[0],attribute[1],!!attribute[2],attribute[3],attribute[4]);
- }
- }
- }else {
- throw "BufferState: must call bind() function first.";
- }
- }
- /**
- *@private
- */
- __proto.applyInstanceVertexBuffer=function(vertexBuffer){
- if (WebGLContext._angleInstancedArrays){
- if (BufferStateBase._curBindedBufferState===this){
- var gl=LayaGL.instance;
- var verDec=vertexBuffer.vertexDeclaration;
- var valueData=null;
- if (Render.supportWebGLPlusRendering)
- valueData=verDec._shaderValues._nativeArray;
- else
- valueData=verDec._shaderValues.getData();
- vertexBuffer.bind();
- for (var k in valueData){
- var loc=parseInt(k);
- var attribute=valueData[k];
- gl.enableVertexAttribArray(loc);
- gl.vertexAttribPointer(loc,attribute[0],attribute[1],!!attribute[2],attribute[3],attribute[4]);
- WebGLContext._angleInstancedArrays.vertexAttribDivisorANGLE(loc,1);
- }
- }else {
- throw "BufferState: must call bind() function first.";
- }
- }
- }
- /**
- *@private
- */
- __proto.applyIndexBuffer=function(indexBuffer){
- if (BufferStateBase._curBindedBufferState===this){
- if (this._bindedIndexBuffer!==indexBuffer){
- indexBuffer._bindForVAO();
- this._bindedIndexBuffer=indexBuffer;
- }
- }else {
- throw "BufferState: must call bind() function first.";
- }
- }
- return BufferState;
- })(BufferStateBase)
- /**
- *<code>ConeShape</code> 类用于创建锥形粒子形状。
- */
- //class laya.d3.core.particleShuriKen.module.shape.ConeShape extends laya.d3.core.particleShuriKen.module.shape.BaseShape
- var ConeShape=(function(_super){
- function ConeShape(){
- /**发射角度。*/
- this.angle=NaN;
- /**发射器半径。*/
- this.radius=NaN;
- /**椎体长度。*/
- this.length=NaN;
- /**发射类型,0为Base,1为BaseShell,2为Volume,3为VolumeShell。*/
- this.emitType=0;
- ConeShape.__super.call(this);
- this.angle=25.0 / 180.0 *Math.PI;
- this.radius=1.0;
- this.length=5.0;
- this.emitType=0;
- this.randomDirection=false;
- }
- __class(ConeShape,'laya.d3.core.particleShuriKen.module.shape.ConeShape',_super);
- var __proto=ConeShape.prototype;
- /**
- *@inheritDoc
- */
- __proto._getShapeBoundBox=function(boundBox){
- var coneRadius2=this.radius+this.length *Math.sin(this.angle);
- var coneLength=this.length *Math.cos(this.angle);
- var min=boundBox.min;
- min.x=min.y=-coneRadius2;
- min.z=0;
- var max=boundBox.max;
- max.x=max.y=coneRadius2;
- max.z=coneLength;
- }
- /**
- *@inheritDoc
- */
- __proto._getSpeedBoundBox=function(boundBox){
- var sinA=Math.sin(this.angle);
- var min=boundBox.min;
- min.x=min.y=-sinA;
- min.z=0;
- var max=boundBox.max;
- max.x=max.y=sinA;
- max.z=1;
- }
- /**
- *用于生成粒子初始位置和方向。
- *@param position 粒子位置。
- *@param direction 粒子方向。
- */
- __proto.generatePositionAndDirection=function(position,direction,rand,randomSeeds){
- var positionPointE=ConeShape._tempPositionPoint;
- var positionX=NaN;
- var positionY=NaN;
- var directionPointE;
- var dirCosA=Math.cos(this.angle);
- var dirSinA=Math.sin(this.angle);
- switch (this.emitType){
- case 0:
- if (rand){
- rand.seed=randomSeeds[16];
- ShapeUtils._randomPointInsideUnitCircle(ConeShape._tempPositionPoint,rand);
- randomSeeds[16]=rand.seed;
- }else {
- ShapeUtils._randomPointInsideUnitCircle(ConeShape._tempPositionPoint);
- }
- positionX=positionPointE.x;
- positionY=positionPointE.y;
- position.x=positionX *this.radius;
- position.y=positionY *this.radius;
- position.z=0;
- if (this.randomDirection){
- if (rand){
- rand.seed=randomSeeds[17];
- ShapeUtils._randomPointInsideUnitCircle(ConeShape._tempDirectionPoint,rand);
- randomSeeds[17]=rand.seed;
- }else {
- ShapeUtils._randomPointInsideUnitCircle(ConeShape._tempDirectionPoint);
- }
- directionPointE=ConeShape._tempDirectionPoint;
- direction.x=directionPointE.x *dirSinA;
- direction.y=directionPointE.y *dirSinA;
- }else {
- direction.x=positionX *dirSinA;
- direction.y=positionY *dirSinA;
- }
- direction.z=dirCosA;
- break ;
- case 1:
- if (rand){
- rand.seed=randomSeeds[16];
- ShapeUtils._randomPointUnitCircle(ConeShape._tempPositionPoint,rand);
- randomSeeds[16]=rand.seed;
- }else {
- ShapeUtils._randomPointUnitCircle(ConeShape._tempPositionPoint);
- }
- positionX=positionPointE.x;
- positionY=positionPointE.y;
- position.x=positionX *this.radius;
- position.y=positionY *this.radius;
- position.z=0;
- if (this.randomDirection){
- if (rand){
- rand.seed=randomSeeds[17];
- ShapeUtils._randomPointInsideUnitCircle(ConeShape._tempDirectionPoint,rand);
- randomSeeds[17]=rand.seed;
- }else {
- ShapeUtils._randomPointInsideUnitCircle(ConeShape._tempDirectionPoint);
- }
- directionPointE=ConeShape._tempDirectionPoint;
- direction.x=directionPointE.x *dirSinA;
- direction.y=directionPointE.y *dirSinA;
- }else {
- direction.x=positionX *dirSinA;
- direction.y=positionY *dirSinA;
- }
- direction.z=dirCosA;
- break ;
- case 2:
- if (rand){
- rand.seed=randomSeeds[16];
- ShapeUtils._randomPointInsideUnitCircle(ConeShape._tempPositionPoint,rand);
- }else {
- ShapeUtils._randomPointInsideUnitCircle(ConeShape._tempPositionPoint);
- }
- positionX=positionPointE.x;
- positionY=positionPointE.y;
- position.x=positionX *this.radius;
- position.y=positionY *this.radius;
- position.z=0;
- direction.x=positionX *dirSinA;
- direction.y=positionY *dirSinA;
- direction.z=dirCosA;
- Vector3.normalize(direction,direction);
- if (rand){
- Vector3.scale(direction,this.length *rand.getFloat(),direction);
- randomSeeds[16]=rand.seed;
- }else {
- Vector3.scale(direction,this.length *Math.random(),direction);
- }
- Vector3.add(position,direction,position);
- if (this.randomDirection){
- if (rand){
- rand.seed=randomSeeds[17];
- ShapeUtils._randomPointUnitSphere(direction,rand);
- randomSeeds[17]=rand.seed;
- }else {
- ShapeUtils._randomPointUnitSphere(direction);
- }
- }
- break ;
- case 3:
- if (rand){
- rand.seed=randomSeeds[16];
- ShapeUtils._randomPointUnitCircle(ConeShape._tempPositionPoint,rand);
- }else {
- ShapeUtils._randomPointUnitCircle(ConeShape._tempPositionPoint);
- }
- positionX=positionPointE.x;
- positionY=positionPointE.y;
- position.x=positionX *this.radius;
- position.y=positionY *this.radius;
- position.z=0;
- direction.x=positionX *dirSinA;
- direction.y=positionY *dirSinA;
- direction.z=dirCosA;
- Vector3.normalize(direction,direction);
- if (rand){
- Vector3.scale(direction,this.length *rand.getFloat(),direction);
- randomSeeds[16]=rand.seed;
- }else {
- Vector3.scale(direction,this.length *Math.random(),direction);
- }
- Vector3.add(position,direction,position);
- if (this.randomDirection){
- if (rand){
- rand.seed=randomSeeds[17];
- ShapeUtils._randomPointUnitSphere(direction,rand);
- randomSeeds[17]=rand.seed;
- }else {
- ShapeUtils._randomPointUnitSphere(direction);
- }
- }
- break ;
- default :
- throw new Error("ConeShape:emitType is invalid.");
- }
- }
- __proto.cloneTo=function(destObject){
- _super.prototype.cloneTo.call(this,destObject);
- var destShape=destObject;
- destShape.angle=this.angle;
- destShape.radius=this.radius;
- destShape.length=this.length;
- destShape.emitType=this.emitType;
- destShape.randomDirection=this.randomDirection;
- }
- __static(ConeShape,
- ['_tempPositionPoint',function(){return this._tempPositionPoint=new Vector2();},'_tempDirectionPoint',function(){return this._tempDirectionPoint=new Vector2();}
- ]);
- return ConeShape;
- })(BaseShape)
- /**
- *<code>SphereColliderShape</code> 类用于创建球形碰撞器。
- */
- //class laya.d3.physics.shape.SphereColliderShape extends laya.d3.physics.shape.ColliderShape
- var SphereColliderShape=(function(_super){
- function SphereColliderShape(radius){
- /**@private */
- //this._radius=NaN;
- SphereColliderShape.__super.call(this);
- (radius===void 0)&& (radius=0.5);
- this._radius=radius;
- this._type=/*laya.d3.physics.shape.ColliderShape.SHAPETYPES_SPHERE*/1;
- this._nativeShape=new Laya3D._physics3D.btSphereShape(radius);
- }
- __class(SphereColliderShape,'laya.d3.physics.shape.SphereColliderShape',_super);
- var __proto=SphereColliderShape.prototype;
- /**
- *@inheritDoc
- */
- __proto.clone=function(){
- var dest=new SphereColliderShape(this._radius);
- this.cloneTo(dest);
- return dest;
- }
- /**
- *获取半径。
- */
- __getset(0,__proto,'radius',function(){
- return this._radius;
- });
- return SphereColliderShape;
- })(ColliderShape)
- /**
- *<code>CircleShape</code> 类用于创建环形粒子形状。
- */
- //class laya.d3.core.particleShuriKen.module.shape.CircleShape extends laya.d3.core.particleShuriKen.module.shape.BaseShape
- var CircleShape=(function(_super){
- function CircleShape(){
- /**发射器半径。*/
- this.radius=NaN;
- /**环形弧度。*/
- this.arc=NaN;
- /**从边缘发射。*/
- this.emitFromEdge=false;
- CircleShape.__super.call(this);
- this.radius=1.0;
- this.arc=360.0 / 180.0 *Math.PI;
- this.emitFromEdge=false;
- this.randomDirection=false;
- }
- __class(CircleShape,'laya.d3.core.particleShuriKen.module.shape.CircleShape',_super);
- var __proto=CircleShape.prototype;
- /**
- *@inheritDoc
- */
- __proto._getShapeBoundBox=function(boundBox){
- var min=boundBox.min;
- min.x=min.z=-this.radius;
- min.y=0;
- var max=boundBox.max;
- max.x=max.z=this.radius;
- max.y=0;
- }
- /**
- *@inheritDoc
- */
- __proto._getSpeedBoundBox=function(boundBox){
- var min=boundBox.min;
- min.x=min.y=-1;
- min.z=0;
- var max=boundBox.max;
- max.x=max.y=1;
- max.z=0;
- }
- /**
- *用于生成粒子初始位置和方向。
- *@param position 粒子位置。
- *@param direction 粒子方向。
- */
- __proto.generatePositionAndDirection=function(position,direction,rand,randomSeeds){
- var positionPoint=CircleShape._tempPositionPoint;
- if (rand){
- rand.seed=randomSeeds[16];
- if (this.emitFromEdge)
- ShapeUtils._randomPointUnitArcCircle(this.arc,CircleShape._tempPositionPoint,rand);
- else
- ShapeUtils._randomPointInsideUnitArcCircle(this.arc,CircleShape._tempPositionPoint,rand);
- randomSeeds[16]=rand.seed;
- }else {
- if (this.emitFromEdge)
- ShapeUtils._randomPointUnitArcCircle(this.arc,CircleShape._tempPositionPoint);
- else
- ShapeUtils._randomPointInsideUnitArcCircle(this.arc,CircleShape._tempPositionPoint);
- }
- position.x=-positionPoint.x;
- position.y=positionPoint.y;
- position.z=0;
- Vector3.scale(position,this.radius,position);
- if (this.randomDirection){
- if (rand){
- rand.seed=randomSeeds[17];
- ShapeUtils._randomPointUnitSphere(direction,rand);
- randomSeeds[17]=rand.seed;
- }else {
- ShapeUtils._randomPointUnitSphere(direction);
- }
- }else {
- position.cloneTo(direction);
- }
- }
- __proto.cloneTo=function(destObject){
- _super.prototype.cloneTo.call(this,destObject);
- var destShape=destObject;
- destShape.radius=this.radius;
- destShape.arc=this.arc;
- destShape.emitFromEdge=this.emitFromEdge;
- destShape.randomDirection=this.randomDirection;
- }
- __static(CircleShape,
- ['_tempPositionPoint',function(){return this._tempPositionPoint=new Vector2();}
- ]);
- return CircleShape;
- })(BaseShape)
- /**
- *@private
- *<code>BlitCMD</code> 类用于创建从一张渲染目标输出到另外一张渲染目标指令。
- */
- //class laya.d3.core.render.command.BlitCMD extends laya.d3.core.render.command.Command
- var BlitCMD=(function(_super){
- function BlitCMD(){
- /**@private */
- this._source=null;
- /**@private */
- this._dest=null;
- /**@private */
- this._shader=null;
- /**@private */
- this._shaderData=null;
- /**@private */
- this._subShader=0;
- BlitCMD.__super.call(this);
- }
- __class(BlitCMD,'laya.d3.core.render.command.BlitCMD',_super);
- var __proto=BlitCMD.prototype;
- /**
- *@inheritDoc
- */
- __proto.run=function(){
- this._shaderData.setTexture(CommandBuffer.SCREENTEXTURE_ID,this._source);
- var dest=this._dest;
- if (dest)
- dest._start();
- var subShader=this._shader.getSubShaderAt(this._subShader);
- var passes=subShader._passes;
- for (var i=0,n=passes.length;i < n;i++){
- var shaderPass=passes[i].withCompile(0,0,0);
- shaderPass.bind();
- (this._shaderData)&& (shaderPass.uploadUniforms(shaderPass._materialUniformParamsMap,this._shaderData,true));
- shaderPass.uploadRenderStateBlendDepth(this._shaderData);
- shaderPass.uploadRenderStateFrontFace(this._shaderData,true,null);
- ScreenQuad.instance.render();
- }
- if (dest)
- dest._end();
- }
- /**
- *@inheritDoc
- */
- __proto.recover=function(){
- BlitCMD._pool.push(this);
- this._dest=null;
- this._shader=null;
- this._shaderData=null;
- }
- BlitCMD.create=function(source,dest,shader,shaderData,subShader){
- (subShader===void 0)&& (subShader=0);
- var cmd;
- cmd=BlitCMD._pool.length > 0 ? BlitCMD._pool.pop():new BlitCMD();
- cmd._source=source;
- cmd._dest=dest;
- cmd._shader=shader;
- cmd._shaderData=shaderData;
- cmd._subShader=subShader;
- return cmd;
- }
- BlitCMD._pool=[];
- return BlitCMD;
- })(Command)
- /**
- *<code>CastShadowList</code> 类用于实现产生阴影者队列。
- */
- //class laya.d3.CastShadowList extends laya.d3.component.SingletonList
- var CastShadowList=(function(_super){
- /**
- *创建一个新的 <code>CastShadowList</code> 实例。
- */
- function CastShadowList(){
- CastShadowList.__super.call(this);
- }
- __class(CastShadowList,'laya.d3.CastShadowList',_super);
- var __proto=CastShadowList.prototype;
- /**
- *@private
- */
- __proto.add=function(element){
- var index=element._indexInCastShadowList;
- if (index!==-1)
- throw "CastShadowList:element has in CastShadowList.";
- this._add(element);
- element._indexInCastShadowList=this.length++;
- }
- /**
- *@private
- */
- __proto.remove=function(element){
- var index=element._indexInCastShadowList;
- this.length--;
- if (index!==this.length){
- var end=this.elements[this.length];
- this.elements[index]=end;
- end._indexInCastShadowList=index;
- }
- element._indexInCastShadowList=-1;
- }
- return CastShadowList;
- })(SingletonList)
- /**
- *<code>CapsuleColliderShape</code> 类用于创建胶囊形状碰撞器。
- */
- //class laya.d3.physics.shape.CapsuleColliderShape extends laya.d3.physics.shape.ColliderShape
- var CapsuleColliderShape=(function(_super){
- function CapsuleColliderShape(radius,length,orientation){
- /**@private */
- //this._radius=NaN;
- /**@private */
- //this._length=NaN;
- /**@private */
- //this._orientation=0;
- CapsuleColliderShape.__super.call(this);
- (radius===void 0)&& (radius=0.5);
- (length===void 0)&& (length=1.25);
- (orientation===void 0)&& (orientation=/*laya.d3.physics.shape.ColliderShape.SHAPEORIENTATION_UPY*/1);
- this._radius=radius;
- this._length=length;
- this._orientation=orientation;
- this._type=/*laya.d3.physics.shape.ColliderShape.SHAPETYPES_CAPSULE*/3;
- switch (orientation){
- case /*laya.d3.physics.shape.ColliderShape.SHAPEORIENTATION_UPX*/0:
- this._nativeShape=new Laya3D._physics3D.btCapsuleShapeX(radius,length-radius *2);
- break ;
- case /*laya.d3.physics.shape.ColliderShape.SHAPEORIENTATION_UPY*/1:
- this._nativeShape=new Laya3D._physics3D.btCapsuleShape(radius,length-radius *2);
- break ;
- case /*laya.d3.physics.shape.ColliderShape.SHAPEORIENTATION_UPZ*/2:
- this._nativeShape=new Laya3D._physics3D.btCapsuleShapeZ(radius,length-radius *2);
- break ;
- default :
- throw "CapsuleColliderShape:unknown orientation.";
- }
- }
- __class(CapsuleColliderShape,'laya.d3.physics.shape.CapsuleColliderShape',_super);
- var __proto=CapsuleColliderShape.prototype;
- /**
- *@inheritDoc
- */
- __proto._setScale=function(value){
- var fixScale=CapsuleColliderShape._tempVector30;
- switch (this.orientation){
- case /*laya.d3.physics.shape.ColliderShape.SHAPEORIENTATION_UPX*/0:
- fixScale.x=value.x;
- fixScale.y=fixScale.z=Math.max(value.y,value.z);
- break ;
- case /*laya.d3.physics.shape.ColliderShape.SHAPEORIENTATION_UPY*/1:
- fixScale.y=value.y;
- fixScale.x=fixScale.z=Math.max(value.x,value.z);
- break ;
- case /*laya.d3.physics.shape.ColliderShape.SHAPEORIENTATION_UPZ*/2:
- fixScale.z=value.z;
- fixScale.x=fixScale.y=Math.max(value.x,value.y);
- break ;
- default :
- throw "CapsuleColliderShape:unknown orientation.";
- }
- _super.prototype._setScale.call(this,fixScale);
- }
- /**
- *@inheritDoc
- */
- __proto.clone=function(){
- var dest=new CapsuleColliderShape(this._radius,this._length,this._orientation);
- this.cloneTo(dest);
- return dest;
- }
- /**
- *获取半径。
- */
- __getset(0,__proto,'radius',function(){
- return this._radius;
- });
- /**
- *获取长度。
- */
- __getset(0,__proto,'length',function(){
- return this._length;
- });
- /**
- *获取方向。
- */
- __getset(0,__proto,'orientation',function(){
- return this._orientation;
- });
- __static(CapsuleColliderShape,
- ['_tempVector30',function(){return this._tempVector30=new Vector3();}
- ]);
- return CapsuleColliderShape;
- })(ColliderShape)
- /**
- *<code>SubMesh</code> 类用于创建子网格数据模板。
- */
- //class laya.d3.resource.models.SubMesh extends laya.d3.core.GeometryElement
- var SubMesh=(function(_super){
- function SubMesh(mesh){
- /**@private */
- this._mesh=null;
- /**@private */
- this._boneIndicesList=null;
- /**@private */
- this._subIndexBufferStart=null;
- /**@private */
- this._subIndexBufferCount=null;
- /**@private */
- this._skinAnimationDatas=null;
- /**@private */
- this._indexInMesh=0;
- /**@private */
- this._vertexStart=0;
- /**@private */
- this._indexStart=0;
- /**@private */
- this._indexCount=0;
- /**@private */
- this._indices=null;
- /**@private [只读]*/
- this._vertexBuffer=null;
- /**@private [只读]*/
- this._indexBuffer=null;
- /**@private */
- this._id=0;
- SubMesh.__super.call(this);
- this._id=++SubMesh._uniqueIDCounter;
- this._mesh=mesh;
- this._boneIndicesList=[];
- this._subIndexBufferStart=[];
- this._subIndexBufferCount=[];
- }
- __class(SubMesh,'laya.d3.resource.models.SubMesh',_super);
- var __proto=SubMesh.prototype;
- /**
- *@inheritDoc
- */
- __proto._getType=function(){
- return SubMesh._type;
- }
- /**
- *@inheritDoc
- */
- __proto._render=function(state){
- this._mesh._bufferState.bind();
- var skinnedDatas=(state.renderElement.render)._skinnedData;
- if (skinnedDatas){
- var subSkinnedDatas=skinnedDatas[this._indexInMesh];
- var boneIndicesListCount=this._boneIndicesList.length;
- for (var i=0;i < boneIndicesListCount;i++){
- state.shader.uploadCustomUniform(SkinnedMeshSprite3D.BONES,subSkinnedDatas[i]);
- LayaGL.instance.drawElements(/*laya.webgl.WebGLContext.TRIANGLES*/0x0004,this._subIndexBufferCount[i],/*laya.webgl.WebGLContext.UNSIGNED_SHORT*/0x1403,this._subIndexBufferStart[i] *2);
- }
- }else {
- LayaGL.instance.drawElements(/*laya.webgl.WebGLContext.TRIANGLES*/0x0004,this._indexCount,/*laya.webgl.WebGLContext.UNSIGNED_SHORT*/0x1403,this._indexStart *2);
- }
- Stat.trianglesFaces+=this._indexCount / 3;
- Stat.renderBatches++;
- }
- /**
- *@private
- */
- __proto.getIndices=function(){
- return this._indices;
- }
- /**
- *@inheritDoc
- */
- __proto.destroy=function(){
- if (this._destroyed)
- return;
- _super.prototype.destroy.call(this);
- this._indexBuffer.destroy();
- this._indexBuffer=null;
- this._mesh=null;
- this._boneIndicesList=null;
- this._subIndexBufferStart=null;
- this._subIndexBufferCount=null;
- this._skinAnimationDatas=null;
- }
- SubMesh._uniqueIDCounter=0;
- __static(SubMesh,
- ['_type',function(){return this._type=GeometryElement._typeCounter++;}
- ]);
- return SubMesh;
- })(GeometryElement)
- /**
- *<code>ShurikenParticleSystem</code> 类用于创建3D粒子数据模板。
- */
- //class laya.d3.core.particleShuriKen.ShurikenParticleSystem extends laya.d3.core.GeometryElement
- var ShurikenParticleSystem=(function(_super){
- function ShurikenParticleSystem(owner){
- /**@private */
- //this._boundingSphere=null;
- /**@private */
- //this._boundingBox=null;
- /**@private */
- //this._boundingBoxCorners=null;
- /**@private */
- //this._owner=null;
- /**@private */
- //this._ownerRender=null;
- /**@private */
- //this._vertices=null;
- /**@private */
- //this._floatCountPerVertex=0;
- /**@private */
- //this._startLifeTimeIndex=0;
- /**@private */
- //this._timeIndex=0;
- /**@private */
- //this._simulateUpdate=false;
- /**@private */
- //this._firstActiveElement=0;
- /**@private */
- //this._firstNewElement=0;
- /**@private */
- //this._firstFreeElement=0;
- /**@private */
- //this._firstRetiredElement=0;
- /**@private */
- //this._drawCounter=0;
- /**@private */
- //this._bufferMaxParticles=0;
- /**@private */
- //this._emission=null;
- /**@private */
- //this._shape=null;
- /**@private */
- //this._isEmitting=false;
- /**@private */
- //this._isPlaying=false;
- /**@private */
- //this._isPaused=false;
- /**@private */
- //this._playStartDelay=NaN;
- /**@private 发射的累计时间。*/
- //this._frameRateTime=NaN;
- /**@private 一次循环内的累计时间。*/
- //this._emissionTime=NaN;
- /**@private */
- //this._totalDelayTime=NaN;
- /**@private */
- //this._burstsIndex=0;
- /**@private */
- //this._velocityOverLifetime=null;
- /**@private */
- //this._colorOverLifetime=null;
- /**@private */
- //this._sizeOverLifetime=null;
- /**@private */
- //this._rotationOverLifetime=null;
- /**@private */
- //this._textureSheetAnimation=null;
- /**@private */
- //this._startLifetimeType=0;
- /**@private */
- //this._startLifetimeConstant=NaN;
- /**@private */
- //this._startLifeTimeGradient=null;
- /**@private */
- //this._startLifetimeConstantMin=NaN;
- /**@private */
- //this._startLifetimeConstantMax=NaN;
- /**@private */
- //this._startLifeTimeGradientMin=null;
- /**@private */
- //this._startLifeTimeGradientMax=null;
- /**@private */
- //this._maxStartLifetime=NaN;
- /**@private */
- //this._vertexStride=0;
- /**@private */
- //this._indexStride=0;
- /**@private */
- //this._vertexBuffer=null;
- /**@private */
- //this._indexBuffer=null;
- /**@private */
- //this._currentTime=NaN;
- /**@private */
- //this._startUpdateLoopCount=0;
- /**@private */
- //this._rand=null;
- /**@private */
- //this._randomSeeds=null;
- /**粒子运行的总时长,单位为秒。*/
- //this.duration=NaN;
- /**是否循环。*/
- //this.looping=false;
- /**是否预热。暂不支持*/
- //this.prewarm=false;
- /**开始延迟类型,0为常量模式,1为随机随机双常量模式,不能和prewarm一起使用。*/
- //this.startDelayType=0;
- /**开始播放延迟,不能和prewarm一起使用。*/
- //this.startDelay=NaN;
- /**开始播放最小延迟,不能和prewarm一起使用。*/
- //this.startDelayMin=NaN;
- /**开始播放最大延迟,不能和prewarm一起使用。*/
- //this.startDelayMax=NaN;
- /**开始速度模式,0为恒定速度,2为两个恒定速度的随机插值。缺少1、3模式*/
- //this.startSpeedType=0;
- /**开始速度,0模式。*/
- //this.startSpeedConstant=NaN;
- /**最小开始速度,1模式。*/
- //this.startSpeedConstantMin=NaN;
- /**最大开始速度,1模式。*/
- //this.startSpeedConstantMax=NaN;
- /**开始尺寸是否为3D模式。*/
- //this.threeDStartSize=false;
- /**开始尺寸模式,0为恒定尺寸,2为两个恒定尺寸的随机插值。缺少1、3模式和对应的二种3D模式*/
- //this.startSizeType=0;
- /**开始尺寸,0模式。*/
- //this.startSizeConstant=NaN;
- /**开始三维尺寸,0模式。*/
- //this.startSizeConstantSeparate=null;
- /**最小开始尺寸,2模式。*/
- //this.startSizeConstantMin=NaN;
- /**最大开始尺寸,2模式。*/
- //this.startSizeConstantMax=NaN;
- /**最小三维开始尺寸,2模式。*/
- //this.startSizeConstantMinSeparate=null;
- /**最大三维开始尺寸,2模式。*/
- //this.startSizeConstantMaxSeparate=null;
- /**3D开始旋转,暂不支持*/
- //this.threeDStartRotation=false;
- /**开始旋转模式,0为恒定尺寸,2为两个恒定旋转的随机插值,缺少2种模式,和对应的四种3D模式。*/
- //this.startRotationType=0;
- /**开始旋转,0模式。*/
- //this.startRotationConstant=NaN;
- /**开始三维旋转,0模式。*/
- //this.startRotationConstantSeparate=null;
- /**最小开始旋转,1模式。*/
- //this.startRotationConstantMin=NaN;
- /**最大开始旋转,1模式。*/
- //this.startRotationConstantMax=NaN;
- /**最小开始三维旋转,1模式。*/
- //this.startRotationConstantMinSeparate=null;
- /**最大开始三维旋转,1模式。*/
- //this.startRotationConstantMaxSeparate=null;
- /**随机旋转方向,范围为0.0到1.0*/
- //this.randomizeRotationDirection=NaN;
- /**开始颜色模式,0为恒定颜色,2为两个恒定颜色的随机插值,缺少2种模式。*/
- //this.startColorType=0;
- /**开始颜色,0模式。*/
- //this.startColorConstant=null;
- /**最小开始颜色,1模式。*/
- //this.startColorConstantMin=null;
- /**最大开始颜色,1模式。*/
- //this.startColorConstantMax=null;
- /**重力敏感度。*/
- //this.gravityModifier=NaN;
- /**模拟器空间,0为World,1为Local。暂不支持Custom。*/
- //this.simulationSpace=0;
- /**缩放模式,0为Hiercachy,1为Local,2为World。*/
- //this.scaleMode=0;
- /**激活时是否自动播放。*/
- //this.playOnAwake=false;
- /**随机种子,注:play()前设置有效。*/
- //this.randomSeed=null;
- /**是否使用随机种子。 */
- //this.autoRandomSeed=false;
- /**是否为性能模式,性能模式下会延迟粒子释放。*/
- //this.isPerformanceMode=false;
- ShurikenParticleSystem.__super.call(this);
- this._tempRotationMatrix=new Matrix4x4();
- this._uvLength=new Vector2();
- this._bufferState=new BufferState();
- this._firstActiveElement=0;
- this._firstNewElement=0;
- this._firstFreeElement=0;
- this._firstRetiredElement=0;
- this._owner=owner;
- this._ownerRender=owner.particleRenderer;
- this._boundingBoxCorners=__newvec(8,null);
- this._boundingSphere=new BoundSphere(new Vector3(),Number.MAX_VALUE);
- 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));
- this._currentTime=0;
- this._isEmitting=false;
- this._isPlaying=false;
- this._isPaused=false;
- this._burstsIndex=0;
- this._frameRateTime=0;
- this._emissionTime=0;
- this._totalDelayTime=0;
- this._simulateUpdate=false;
- this._bufferMaxParticles=1;
- this.duration=5.0;
- this.looping=true;
- this.prewarm=false;
- this.startDelayType=0;
- this.startDelay=0.0;
- this.startDelayMin=0.0;
- this.startDelayMax=0.0;
- this._startLifetimeType=0;
- this._startLifetimeConstant=5.0;
- this._startLifeTimeGradient=new GradientDataNumber();
- this._startLifetimeConstantMin=0.0;
- this._startLifetimeConstantMax=5.0;
- this._startLifeTimeGradientMin=new GradientDataNumber();
- this._startLifeTimeGradientMax=new GradientDataNumber();
- this._maxStartLifetime=5.0;
- this.startSpeedType=0;
- this.startSpeedConstant=5.0;
- this.startSpeedConstantMin=0.0;
- this.startSpeedConstantMax=5.0;
- this.threeDStartSize=false;
- this.startSizeType=0;
- this.startSizeConstant=1;
- this.startSizeConstantSeparate=new Vector3(1,1,1);
- this.startSizeConstantMin=0;
- this.startSizeConstantMax=1;
- this.startSizeConstantMinSeparate=new Vector3(0,0,0);
- this.startSizeConstantMaxSeparate=new Vector3(1,1,1);
- this.threeDStartRotation=false;
- this.startRotationType=0;
- this.startRotationConstant=0;
- this.startRotationConstantSeparate=new Vector3(0,0,0);
- this.startRotationConstantMin=0.0;
- this.startRotationConstantMax=0.0;
- this.startRotationConstantMinSeparate=new Vector3(0,0,0);
- this.startRotationConstantMaxSeparate=new Vector3(0,0,0);
- this.randomizeRotationDirection=0.0;
- this.startColorType=0;
- this.startColorConstant=new Vector4(1,1,1,1);
- this.startColorConstantMin=new Vector4(1,1,1,1);
- this.startColorConstantMax=new Vector4(1,1,1,1);
- this.gravityModifier=0.0;
- this.simulationSpace=1;
- this.scaleMode=0;
- this.playOnAwake=true;
- this._rand=new Rand(0);
- this.autoRandomSeed=true;
- this.randomSeed=new Uint32Array(1);
- this._randomSeeds=new Uint32Array(ShurikenParticleSystem._RANDOMOFFSET.length);
- this.isPerformanceMode=true;
- this._emission=new Emission();
- this._emission.enbale=true;
- }
- __class(ShurikenParticleSystem,'laya.d3.core.particleShuriKen.ShurikenParticleSystem',_super);
- var __proto=ShurikenParticleSystem.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- __proto._getVertexBuffer=function(index){
- (index===void 0)&& (index=0);
- if (index===0)
- return this._vertexBuffer;
- else
- return null;
- }
- __proto._getIndexBuffer=function(){
- return this._indexBuffer;
- }
- /**
- *@private
- */
- __proto._generateBoundingSphere=function(){
- var centerE=this._boundingSphere.center;
- centerE.x=0;
- centerE.y=0;
- centerE.z=0;
- this._boundingSphere.radius=Number.MAX_VALUE;
- }
- /**
- *@private
- */
- __proto._generateBoundingBox=function(){
- var particle=this._owner;
- var particleRender=particle.particleRenderer;
- var boundMin=this._boundingBox.min;
- var boundMax=this._boundingBox.max;
- var i=0,n=0;
- var maxStartLifeTime=NaN;
- switch (this.startLifetimeType){
- case 0:
- maxStartLifeTime=this.startLifetimeConstant;
- break ;
- case 1:
- maxStartLifeTime=-Number.MAX_VALUE;
- var startLifeTimeGradient=startLifeTimeGradient;
- for (i=0,n=startLifeTimeGradient.gradientCount;i < n;i++)
- maxStartLifeTime=Math.max(maxStartLifeTime,startLifeTimeGradient.getValueByIndex(i));
- break ;
- case 2:
- maxStartLifeTime=Math.max(this.startLifetimeConstantMin,this.startLifetimeConstantMax);
- break ;
- case 3:
- maxStartLifeTime=-Number.MAX_VALUE;
- var startLifeTimeGradientMin=startLifeTimeGradientMin;
- for (i=0,n=startLifeTimeGradientMin.gradientCount;i < n;i++)
- maxStartLifeTime=Math.max(maxStartLifeTime,startLifeTimeGradientMin.getValueByIndex(i));
- var startLifeTimeGradientMax=startLifeTimeGradientMax;
- for (i=0,n=startLifeTimeGradientMax.gradientCount;i < n;i++)
- maxStartLifeTime=Math.max(maxStartLifeTime,startLifeTimeGradientMax.getValueByIndex(i));
- break ;
- };
- var minStartSpeed=NaN,maxStartSpeed=NaN;
- switch (this.startSpeedType){
- case 0:
- minStartSpeed=maxStartSpeed=this.startSpeedConstant;
- break ;
- case 1:
- break ;
- case 2:
- minStartSpeed=this.startLifetimeConstantMin;
- maxStartSpeed=this.startLifetimeConstantMax;
- break ;
- case 3:
- break ;
- };
- var minPosition,maxPosition,minDirection,maxDirection;
- if (this._shape && this._shape.enable){
- }else {
- minPosition=maxPosition=Vector3._ZERO;
- minDirection=Vector3._ZERO;
- maxDirection=Vector3._UnitZ;
- };
- var startMinVelocity=new Vector3(minDirection.x *minStartSpeed,minDirection.y *minStartSpeed,minDirection.z *minStartSpeed);
- var startMaxVelocity=new Vector3(maxDirection.x *maxStartSpeed,maxDirection.y *maxStartSpeed,maxDirection.z *maxStartSpeed);
- if (this._velocityOverLifetime && this._velocityOverLifetime.enbale){
- var lifeMinVelocity;
- var lifeMaxVelocity;
- var velocity=this._velocityOverLifetime.velocity;
- switch (velocity.type){
- case 0:
- lifeMinVelocity=lifeMaxVelocity=velocity.constant;
- break ;
- case 1:
- lifeMinVelocity=lifeMaxVelocity=new Vector3(velocity.gradientX.getAverageValue(),velocity.gradientY.getAverageValue(),velocity.gradientZ.getAverageValue());
- break ;
- case 2:
- lifeMinVelocity=velocity.constantMin;
- lifeMaxVelocity=velocity.constantMax;
- break ;
- case 3:
- lifeMinVelocity=new Vector3(velocity.gradientXMin.getAverageValue(),velocity.gradientYMin.getAverageValue(),velocity.gradientZMin.getAverageValue());
- lifeMaxVelocity=new Vector3(velocity.gradientXMax.getAverageValue(),velocity.gradientYMax.getAverageValue(),velocity.gradientZMax.getAverageValue());
- break ;
- }
- };
- var positionScale,velocityScale;
- var transform=this._owner.transform;
- var worldPosition=transform.position;
- var sizeScale=ShurikenParticleSystem._tempVector39;
- var renderMode=particleRender.renderMode;
- switch (this.scaleMode){
- case 0:;
- var scale=transform.scale;
- positionScale=scale;
- sizeScale.x=scale.x;
- sizeScale.y=scale.z;
- sizeScale.z=scale.y;
- (renderMode===1)&& (velocityScale=scale);
- break ;
- case 1:;
- var localScale=transform.localScale;
- positionScale=localScale;
- sizeScale.x=localScale.x;
- sizeScale.y=localScale.z;
- sizeScale.z=localScale.y;
- (renderMode===1)&& (velocityScale=localScale);
- break ;
- case 2:
- positionScale=transform.scale;
- sizeScale.x=sizeScale.y=sizeScale.z=1;
- (renderMode===1)&& (velocityScale=Vector3._ONE);
- break ;
- };
- var minStratPosition,maxStratPosition;
- if (this._velocityOverLifetime && this._velocityOverLifetime.enbale){
- }else {
- minStratPosition=new Vector3(startMinVelocity.x *maxStartLifeTime,startMinVelocity.y *maxStartLifeTime,startMinVelocity.z *maxStartLifeTime);
- maxStratPosition=new Vector3(startMaxVelocity.x *maxStartLifeTime,startMaxVelocity.y *maxStartLifeTime,startMaxVelocity.z *maxStartLifeTime);
- if (this.scaleMode !=2){
- Vector3.add(minPosition,minStratPosition,boundMin);
- Vector3.multiply(positionScale,boundMin,boundMin);
- Vector3.add(maxPosition,maxStratPosition,boundMax);
- Vector3.multiply(positionScale,boundMax,boundMax);
- }else {
- Vector3.multiply(positionScale,minPosition,boundMin);
- Vector3.add(boundMin,minStratPosition,boundMin);
- Vector3.multiply(positionScale,maxPosition,boundMax);
- Vector3.add(boundMax,maxStratPosition,boundMax);
- }
- }
- switch (this.simulationSpace){
- case 0:
- break ;
- case 1:
- Vector3.add(boundMin,worldPosition,boundMin);
- Vector3.add(boundMax,worldPosition,boundMax);
- break ;
- };
- var maxSize=NaN,maxSizeY=NaN;
- switch (this.startSizeType){
- case 0:
- if (this.threeDStartSize){
- var startSizeConstantSeparate=startSizeConstantSeparate;
- maxSize=Math.max(startSizeConstantSeparate.x,startSizeConstantSeparate.y);
- if (renderMode===1)
- maxSizeY=startSizeConstantSeparate.y;
- }else {
- maxSize=this.startSizeConstant;
- if (renderMode===1)
- maxSizeY=this.startSizeConstant;
- }
- break ;
- case 1:
- break ;
- case 2:
- if (this.threeDStartSize){
- var startSizeConstantMaxSeparate=startSizeConstantMaxSeparate;
- maxSize=Math.max(startSizeConstantMaxSeparate.x,startSizeConstantMaxSeparate.y);
- if (renderMode===1)
- maxSizeY=startSizeConstantMaxSeparate.y;
- }else {
- maxSize=this.startSizeConstantMax;
- if (renderMode===1)
- maxSizeY=this.startSizeConstantMax;
- }
- break ;
- case 3:
- break ;
- }
- if (this._sizeOverLifetime && this._sizeOverLifetime.enbale){
- var size=this._sizeOverLifetime.size;
- maxSize *=this._sizeOverLifetime.size.getMaxSizeInGradient();
- };
- var threeDMaxSize=ShurikenParticleSystem._tempVector30;
- var rotSize=NaN,nonRotSize=NaN;
- switch (renderMode){
- case 0:
- rotSize=maxSize *ShurikenParticleSystem.halfKSqrtOf2;
- Vector3.scale(sizeScale,maxSize,threeDMaxSize);
- Vector3.subtract(boundMin,threeDMaxSize,boundMin);
- Vector3.add(boundMax,threeDMaxSize,boundMax);
- break ;
- case 1:;
- var maxStretchPosition=ShurikenParticleSystem._tempVector31;
- var maxStretchVelocity=ShurikenParticleSystem._tempVector32;
- var minStretchVelocity=ShurikenParticleSystem._tempVector33;
- var minStretchPosition=ShurikenParticleSystem._tempVector34;
- if (this._velocityOverLifetime && this._velocityOverLifetime.enbale){
- }else {
- Vector3.multiply(velocityScale,startMaxVelocity,maxStretchVelocity);
- Vector3.multiply(velocityScale,startMinVelocity,minStretchVelocity);
- };
- var sizeStretch=maxSizeY *particleRender.stretchedBillboardLengthScale;
- var maxStretchLength=Vector3.scalarLength(maxStretchVelocity)*particleRender.stretchedBillboardSpeedScale+sizeStretch;
- var minStretchLength=Vector3.scalarLength(minStretchVelocity)*particleRender.stretchedBillboardSpeedScale+sizeStretch;
- var norMaxStretchVelocity=ShurikenParticleSystem._tempVector35;
- var norMinStretchVelocity=ShurikenParticleSystem._tempVector36;
- Vector3.normalize(maxStretchVelocity,norMaxStretchVelocity);
- Vector3.scale(norMaxStretchVelocity,maxStretchLength,minStretchPosition);
- Vector3.subtract(maxStratPosition,minStretchPosition,minStretchPosition);
- Vector3.normalize(minStretchVelocity,norMinStretchVelocity);
- Vector3.scale(norMinStretchVelocity,minStretchLength,maxStretchPosition);
- Vector3.add(minStratPosition,maxStretchPosition,maxStretchPosition);
- rotSize=maxSize *ShurikenParticleSystem.halfKSqrtOf2;
- Vector3.scale(sizeScale,rotSize,threeDMaxSize);
- var halfNorMaxStretchVelocity=ShurikenParticleSystem._tempVector37;
- var halfNorMinStretchVelocity=ShurikenParticleSystem._tempVector38;
- Vector3.scale(norMaxStretchVelocity,0.5,halfNorMaxStretchVelocity);
- Vector3.scale(norMinStretchVelocity,0.5,halfNorMinStretchVelocity);
- Vector3.multiply(halfNorMaxStretchVelocity,sizeScale,halfNorMaxStretchVelocity);
- Vector3.multiply(halfNorMinStretchVelocity,sizeScale,halfNorMinStretchVelocity);
- Vector3.add(boundMin,halfNorMinStretchVelocity,boundMin);
- Vector3.min(boundMin,minStretchPosition,boundMin);
- Vector3.subtract(boundMin,threeDMaxSize,boundMin);
- Vector3.subtract(boundMax,halfNorMaxStretchVelocity,boundMax);
- Vector3.max(boundMax,maxStretchPosition,boundMax);
- Vector3.add(boundMax,threeDMaxSize,boundMax);
- break ;
- case 2:
- maxSize *=Math.cos(0.78539816339744830961566084581988);
- nonRotSize=maxSize *0.5;
- threeDMaxSize.x=sizeScale.x *nonRotSize;
- threeDMaxSize.y=sizeScale.z *nonRotSize;
- Vector3.subtract(boundMin,threeDMaxSize,boundMin);
- Vector3.add(boundMax,threeDMaxSize,boundMax);
- break ;
- case 3:
- maxSize *=Math.cos(0.78539816339744830961566084581988);
- nonRotSize=maxSize *0.5;
- Vector3.scale(sizeScale,nonRotSize,threeDMaxSize);
- Vector3.subtract(boundMin,threeDMaxSize,boundMin);
- Vector3.add(boundMax,threeDMaxSize,boundMax);
- break ;
- }
- this._boundingBox.getCorners(this._boundingBoxCorners);
- }
- /**
- *@private
- */
- __proto._updateEmission=function(){
- if (!this.isAlive)
- return;
- if (this._simulateUpdate){
- this._simulateUpdate=false;
- }
- else{
- var elapsedTime=(this._startUpdateLoopCount!==Stat.loopCount && !this._isPaused)?(this._owner._scene).timer._delta / 1000.0:0;
- elapsedTime=Math.min(ShurikenParticleSystem._maxElapsedTime,elapsedTime);
- this._updateParticles(elapsedTime);
- }
- }
- /**
- *@private
- */
- __proto._updateParticles=function(elapsedTime){
- if (this._ownerRender.renderMode===4 && !this._ownerRender.mesh)
- return;
- this._currentTime+=elapsedTime;
- this._retireActiveParticles();
- this._freeRetiredParticles();
- this._totalDelayTime+=elapsedTime;
- if (this._totalDelayTime < this._playStartDelay){
- return;
- }
- if (this._emission.enbale&&this._isEmitting &&!this._isPaused)
- this._advanceTime(elapsedTime,this._currentTime);
- }
- /**
- *@private
- */
- __proto._updateParticlesSimulationRestart=function(time){
- this._firstActiveElement=0;
- this._firstNewElement=0;
- this._firstFreeElement=0;
- this._firstRetiredElement=0;
- this._burstsIndex=0;
- this._frameRateTime=time;
- this._emissionTime=0;
- this._totalDelayTime=0;
- this._currentTime=time;
- var delayTime=time;
- if (delayTime < this._playStartDelay){
- this._totalDelayTime=delayTime;
- return;
- }
- if (this._emission.enbale)
- this._advanceTime(time,time);
- }
- /**
- *@private
- */
- __proto._retireActiveParticles=function(){
- var epsilon=0.0001;
- while (this._firstActiveElement !=this._firstNewElement){
- var index=this._firstActiveElement *this._floatCountPerVertex *this._vertexStride;
- var timeIndex=index+this._timeIndex;
- var particleAge=this._currentTime-this._vertices[timeIndex];
- if (particleAge+epsilon < this._vertices[index+this._startLifeTimeIndex])
- break ;
- this._vertices[timeIndex]=this._drawCounter;
- this._firstActiveElement++;
- if (this._firstActiveElement >=this._bufferMaxParticles)
- this._firstActiveElement=0;
- }
- }
- /**
- *@private
- */
- __proto._freeRetiredParticles=function(){
- while (this._firstRetiredElement !=this._firstActiveElement){
- var age=this._drawCounter-this._vertices[this._firstRetiredElement *this._floatCountPerVertex *this._vertexStride+this._timeIndex];
- if (this.isPerformanceMode)
- if (age < 3)
- break ;
- this._firstRetiredElement++;
- if (this._firstRetiredElement >=this._bufferMaxParticles)
- this._firstRetiredElement=0;
- }
- }
- /**
- *@private
- */
- __proto._burst=function(fromTime,toTime){
- var totalEmitCount=0;
- var bursts=this._emission._bursts;
- for (var n=bursts.length;this._burstsIndex < n;this._burstsIndex++){
- var burst=bursts[this._burstsIndex];
- var burstTime=burst.time;
- if (fromTime<=burstTime && burstTime < toTime){
- var emitCount=0;
- if (this.autoRandomSeed){
- emitCount=MathUtil.lerp(burst.minCount,burst.maxCount,Math.random());
- }else {
- this._rand.seed=this._randomSeeds[0];
- emitCount=MathUtil.lerp(burst.minCount,burst.maxCount,this._rand.getFloat());
- this._randomSeeds[0]=this._rand.seed;
- }
- totalEmitCount+=emitCount;
- }else {
- break ;
- }
- }
- return totalEmitCount;
- }
- /**
- *@private
- */
- __proto._advanceTime=function(elapsedTime,emitTime){
- var i=0;
- var lastEmissionTime=this._emissionTime;
- this._emissionTime+=elapsedTime;
- var totalEmitCount=0;
- if (this._emissionTime > this.duration){
- if (this.looping){
- totalEmitCount+=this._burst(lastEmissionTime,this._emissionTime);
- this._emissionTime-=this.duration;
- this._burstsIndex=0;
- totalEmitCount+=this._burst(0,this._emissionTime);
- }else {
- totalEmitCount=Math.min(this.maxParticles-this.aliveParticleCount,totalEmitCount);
- for (i=0;i < totalEmitCount;i++)
- this.emit(emitTime);
- this._isPlaying=false;
- this.stop();
- return;
- }
- }else {
- totalEmitCount+=this._burst(lastEmissionTime,this._emissionTime);
- }
- totalEmitCount=Math.min(this.maxParticles-this.aliveParticleCount,totalEmitCount);
- for (i=0;i < totalEmitCount;i++)
- this.emit(emitTime);
- var emissionRate=this.emission.emissionRate;
- if (emissionRate>0){
- var minEmissionTime=1/emissionRate;
- this._frameRateTime+=minEmissionTime;
- this._frameRateTime=this._currentTime-(this._currentTime-this._frameRateTime)% this._maxStartLifetime;
- while (this._frameRateTime <=emitTime){
- if (this.emit(this._frameRateTime))
- this._frameRateTime+=minEmissionTime;
- else
- break ;
- }
- this._frameRateTime=Math.floor(emitTime / minEmissionTime)*minEmissionTime;
- }
- }
- /**
- *@private
- */
- __proto._initBufferDatas=function(){
- if (this._vertexBuffer){
- this._vertexBuffer.destroy();
- this._indexBuffer.destroy();
- };
- var render=this._ownerRender;
- var renderMode=render.renderMode;
- if (renderMode!==-1 && this.maxParticles > 0){
- var indices,i=0,j=0,m=0,indexOffset=0,perPartOffset=0,vertexDeclaration;;
- var vbMemorySize=0,memorySize=0;
- var mesh=render.mesh;
- if (renderMode===4){
- if(mesh){
- var vertexBufferCount=mesh._vertexBuffers.length;
- if (vertexBufferCount > 1){
- throw new Error("ShurikenParticleSystem: submesh Count mesh be One or all subMeshes have the same vertexDeclaration.");
- }else {
- vertexDeclaration=VertexShurikenParticleMesh.vertexDeclaration;
- this._floatCountPerVertex=vertexDeclaration.vertexStride/4;
- this._startLifeTimeIndex=12;
- this._timeIndex=16;
- this._vertexStride=mesh._vertexBuffers[0].vertexCount;
- var totalVertexCount=this._bufferMaxParticles *this._vertexStride;
- var vbCount=Math.floor(totalVertexCount / 65535)+1;
- var lastVBVertexCount=totalVertexCount % 65535;
- if (vbCount > 1){
- throw new Error("ShurikenParticleSystem:the maxParticleCount multiply mesh vertexCount is large than 65535.");
- }
- vbMemorySize=vertexDeclaration.vertexStride *lastVBVertexCount;
- this._vertexBuffer=new VertexBuffer3D(vbMemorySize,/*laya.webgl.WebGLContext.DYNAMIC_DRAW*/0x88E8);
- this._vertexBuffer.vertexDeclaration=vertexDeclaration;
- this._vertices=new Float32Array(this._floatCountPerVertex *lastVBVertexCount);
- this._indexStride=mesh._indexBuffer.indexCount;
- var indexDatas=mesh._indexBuffer.getData();
- var indexCount=this._bufferMaxParticles *this._indexStride;
- this._indexBuffer=new IndexBuffer3D(/*laya.d3.graphics.IndexBuffer3D.INDEXTYPE_USHORT*/"ushort",indexCount,/*laya.webgl.WebGLContext.STATIC_DRAW*/0x88E4);
- indices=new Uint16Array(indexCount);
- memorySize=vbMemorySize+indexCount *2;
- indexOffset=0;
- for (i=0;i < this._bufferMaxParticles;i++){
- var indexValueOffset=i *this._vertexStride;
- for (j=0,m=indexDatas.length;j < m;j++)
- indices[indexOffset++]=indexValueOffset+indexDatas[j];
- }
- this._indexBuffer.setData(indices);
- this._bufferState.bind();
- this._bufferState.applyVertexBuffer(this._vertexBuffer);
- this._bufferState.applyIndexBuffer(this._indexBuffer);
- this._bufferState.unBind();
- }
- }
- }else {
- vertexDeclaration=VertexShurikenParticleBillboard.vertexDeclaration;
- this._floatCountPerVertex=vertexDeclaration.vertexStride/4;
- this._startLifeTimeIndex=7;
- this._timeIndex=11;
- this._vertexStride=4;
- vbMemorySize=vertexDeclaration.vertexStride *this._bufferMaxParticles *this._vertexStride;
- this._vertexBuffer=new VertexBuffer3D(vbMemorySize,/*laya.webgl.WebGLContext.DYNAMIC_DRAW*/0x88E8);
- this._vertexBuffer.vertexDeclaration=vertexDeclaration;
- this._vertices=new Float32Array(this._floatCountPerVertex *this._bufferMaxParticles *this._vertexStride);
- for (i=0;i < this._bufferMaxParticles;i++){
- perPartOffset=i *this._floatCountPerVertex *this._vertexStride;
- this._vertices[perPartOffset]=-0.5;
- this._vertices[perPartOffset+1]=-0.5;
- this._vertices[perPartOffset+2]=0;
- this._vertices[perPartOffset+3]=1;
- perPartOffset+=this._floatCountPerVertex;
- this._vertices[perPartOffset]=0.5;
- this._vertices[perPartOffset+1]=-0.5;
- this._vertices[perPartOffset+2]=1;
- this._vertices[perPartOffset+3]=1;
- perPartOffset+=this._floatCountPerVertex
- this._vertices[perPartOffset]=0.5;
- this._vertices[perPartOffset+1]=0.5;
- this._vertices[perPartOffset+2]=1;
- this._vertices[perPartOffset+3]=0;
- perPartOffset+=this._floatCountPerVertex
- this._vertices[perPartOffset]=-0.5;
- this._vertices[perPartOffset+1]=0.5;
- this._vertices[perPartOffset+2]=0;
- this._vertices[perPartOffset+3]=0;
- }
- this._indexStride=6;
- this._indexBuffer=new IndexBuffer3D(/*laya.d3.graphics.IndexBuffer3D.INDEXTYPE_USHORT*/"ushort",this._bufferMaxParticles *6,/*laya.webgl.WebGLContext.STATIC_DRAW*/0x88E4);
- indices=new Uint16Array(this._bufferMaxParticles *6);
- for (i=0;i < this._bufferMaxParticles;i++){
- indexOffset=i *6;
- var firstVertex=i *this._vertexStride,secondVertex=firstVertex+2;
- indices[indexOffset++]=firstVertex;
- indices[indexOffset++]=secondVertex;
- indices[indexOffset++]=firstVertex+1;
- indices[indexOffset++]=firstVertex;
- indices[indexOffset++]=firstVertex+3;
- indices[indexOffset++]=secondVertex;
- }
- this._indexBuffer.setData(indices);
- memorySize=vbMemorySize+this._bufferMaxParticles *6 *2;
- this._bufferState.bind();
- this._bufferState.applyVertexBuffer(this._vertexBuffer);
- this._bufferState.applyIndexBuffer(this._indexBuffer);
- this._bufferState.unBind();
- }
- Resource._addMemory(memorySize,memorySize);
- }
- }
- /**
- *@private
- */
- __proto.destroy=function(){
- _super.prototype.destroy.call(this);
- var memorySize=this._vertexBuffer._byteLength+this._indexBuffer.indexCount *2;
- Resource._addMemory(-memorySize,-memorySize);
- this._bufferState.destroy();
- this._vertexBuffer.destroy();
- this._indexBuffer.destroy();
- this._emission.destroy();
- this._bufferState=null;
- this._vertexBuffer=null;
- this._indexBuffer=null;
- this._owner=null;
- this._vertices=null;
- this._indexBuffer=null;
- this._emission=null;
- this._shape=null;
- this.startLifeTimeGradient=null;
- this.startLifeTimeGradientMin=null;
- this.startLifeTimeGradientMax=null;
- this.startSizeConstantSeparate=null;
- this.startSizeConstantMinSeparate=null;
- this.startSizeConstantMaxSeparate=null;
- this.startRotationConstantSeparate=null;
- this.startRotationConstantMinSeparate=null;
- this.startRotationConstantMaxSeparate=null;
- this.startColorConstant=null;
- this.startColorConstantMin=null;
- this.startColorConstantMax=null;
- this._velocityOverLifetime=null;
- this._colorOverLifetime=null;
- this._sizeOverLifetime=null;
- this._rotationOverLifetime=null;
- this._textureSheetAnimation=null;
- }
- /**
- *发射一个粒子。
- */
- __proto.emit=function(time){
- var position=ShurikenParticleSystem._tempPosition;
- var direction=ShurikenParticleSystem._tempDirection;
- if (this._shape&&this._shape.enable){
- if (this.autoRandomSeed)
- this._shape.generatePositionAndDirection(position,direction);
- else
- this._shape.generatePositionAndDirection(position,direction,this._rand,this._randomSeeds);
- }else {
- position.x=position.y=position.z=0;
- direction.x=direction.y=0;
- direction.z=1;
- }
- return this.addParticle(position,direction,time);
- }
- //TODO:提前判断优化
- __proto.addParticle=function(position,direction,time){
- Vector3.normalize(direction,direction);
- var nextFreeParticle=this._firstFreeElement+1;
- if (nextFreeParticle >=this._bufferMaxParticles)
- nextFreeParticle=0;
- if (nextFreeParticle===this._firstRetiredElement)
- return false;
- ShurikenParticleData.create(this,this._ownerRender,this._owner.transform);
- var particleAge=this._currentTime-time;
- if (particleAge >=ShurikenParticleData.startLifeTime)
- return true;
- var randomVelocityX=NaN,randomVelocityY=NaN,randomVelocityZ=NaN,randomColor=NaN,randomSize=NaN,randomRotation=NaN,randomTextureAnimation=NaN;
- var needRandomVelocity=this._velocityOverLifetime && this._velocityOverLifetime.enbale;
- if (needRandomVelocity){
- var velocityType=this._velocityOverLifetime.velocity.type;
- if (velocityType===2 || velocityType===3){
- if (this.autoRandomSeed){
- randomVelocityX=Math.random();
- randomVelocityY=Math.random();
- randomVelocityZ=Math.random();
- }else {
- this._rand.seed=this._randomSeeds[9];
- randomVelocityX=this._rand.getFloat();
- randomVelocityY=this._rand.getFloat();
- randomVelocityZ=this._rand.getFloat();
- this._randomSeeds[9]=this._rand.seed;
- }
- }else {
- needRandomVelocity=false;
- }
- }else {
- needRandomVelocity=false;
- };
- var needRandomColor=this._colorOverLifetime && this._colorOverLifetime.enbale;
- if (needRandomColor){
- var colorType=this._colorOverLifetime.color.type;
- if (colorType===3){
- if (this.autoRandomSeed){
- randomColor=Math.random();
- }else {
- this._rand.seed=this._randomSeeds[10];
- randomColor=this._rand.getFloat();
- this._randomSeeds[10]=this._rand.seed;
- }
- }else {
- needRandomColor=false;
- }
- }else {
- needRandomColor=false;
- };
- var needRandomSize=this._sizeOverLifetime && this._sizeOverLifetime.enbale;
- if (needRandomSize){
- var sizeType=this._sizeOverLifetime.size.type;
- if (sizeType===3){
- if (this.autoRandomSeed){
- randomSize=Math.random();
- }else {
- this._rand.seed=this._randomSeeds[11];
- randomSize=this._rand.getFloat();
- this._randomSeeds[11]=this._rand.seed;
- }
- }else {
- needRandomSize=false;
- }
- }else {
- needRandomSize=false;
- };
- var needRandomRotation=this._rotationOverLifetime && this._rotationOverLifetime.enbale;
- if (needRandomRotation){
- var rotationType=this._rotationOverLifetime.angularVelocity.type;
- if (rotationType===2 || rotationType===3){
- if (this.autoRandomSeed){
- randomRotation=Math.random();
- }else {
- this._rand.seed=this._randomSeeds[12];
- randomRotation=this._rand.getFloat();
- this._randomSeeds[12]=this._rand.seed;
- }
- }else {
- needRandomRotation=false;
- }
- }else {
- needRandomRotation=false;
- };
- var needRandomTextureAnimation=this._textureSheetAnimation && this._textureSheetAnimation.enable;
- if (needRandomTextureAnimation){
- var textureAnimationType=this._textureSheetAnimation.frame.type;
- if (textureAnimationType===3){
- if (this.autoRandomSeed){
- randomTextureAnimation=Math.random();
- }else {
- this._rand.seed=this._randomSeeds[15];
- randomTextureAnimation=this._rand.getFloat();
- this._randomSeeds[15]=this._rand.seed;
- }
- }else {
- needRandomTextureAnimation=false;
- }
- }else {
- needRandomTextureAnimation=false;
- };
- var startIndex=this._firstFreeElement *this._floatCountPerVertex *this._vertexStride;
- var subU=ShurikenParticleData.startUVInfo[0];
- var subV=ShurikenParticleData.startUVInfo[1];
- var startU=ShurikenParticleData.startUVInfo[2];
- var startV=ShurikenParticleData.startUVInfo[3];
- var meshVertices,meshVertexStride=0,meshPosOffset=0,meshCorOffset=0,meshUVOffset=0,meshVertexIndex=0;
- var render=this._ownerRender;
- if (render.renderMode===4){
- var meshVB=render.mesh._vertexBuffers[0];
- meshVertices=meshVB.getData();
- var meshVertexDeclaration=meshVB.vertexDeclaration;
- meshPosOffset=meshVertexDeclaration.getVertexElementByUsage(/*laya.d3.graphics.Vertex.VertexMesh.MESH_POSITION0*/0).offset / 4;
- var colorElement=meshVertexDeclaration.getVertexElementByUsage(/*laya.d3.graphics.Vertex.VertexMesh.MESH_COLOR0*/1);
- meshCorOffset=colorElement?colorElement.offset / 4:-1;
- var uvElement=meshVertexDeclaration.getVertexElementByUsage(/*laya.d3.graphics.Vertex.VertexMesh.MESH_TEXTURECOORDINATE0*/2);
- meshUVOffset=uvElement?uvElement.offset / 4:-1;
- meshVertexStride=meshVertexDeclaration.vertexStride / 4;
- meshVertexIndex=0;
- }else {
- this._vertices[startIndex+2]=startU;
- this._vertices[startIndex+3]=startV+subV;
- var secondOffset=startIndex+this._floatCountPerVertex;
- this._vertices[secondOffset+2]=startU+subU;
- this._vertices[secondOffset+3]=startV+subV;
- var thirdOffset=secondOffset+this._floatCountPerVertex;
- this._vertices[thirdOffset+2]=startU+subU;
- this._vertices[thirdOffset+3]=startV;
- var fourthOffset=thirdOffset+this._floatCountPerVertex;
- this._vertices[fourthOffset+2]=startU;
- this._vertices[fourthOffset+3]=startV;
- }
- for (var i=startIndex,n=startIndex+this._floatCountPerVertex *this._vertexStride;i < n;i+=this._floatCountPerVertex){
- var offset=0;
- if (render.renderMode===4){
- offset=i;
- var vertexOffset=meshVertexStride *(meshVertexIndex++);
- var meshOffset=vertexOffset+meshPosOffset;
- this._vertices[offset++]=meshVertices[meshOffset++];
- this._vertices[offset++]=meshVertices[meshOffset++];
- this._vertices[offset++]=meshVertices[meshOffset];
- if (meshCorOffset===-1){
- this._vertices[offset++]=1.0;
- this._vertices[offset++]=1.0;
- this._vertices[offset++]=1.0;
- this._vertices[offset++]=1.0;
- }
- else{
- meshOffset=vertexOffset+meshCorOffset;
- this._vertices[offset++]=meshVertices[meshOffset++];
- this._vertices[offset++]=meshVertices[meshOffset++];
- this._vertices[offset++]=meshVertices[meshOffset++];
- this._vertices[offset++]=meshVertices[meshOffset];
- }
- if (meshUVOffset===-1){
- this._vertices[offset++]=0.0;
- this._vertices[offset++]=0.0;
- }
- else{
- meshOffset=vertexOffset+meshUVOffset;
- this._vertices[offset++]=startU+meshVertices[meshOffset++] *subU;
- this._vertices[offset++]=startV+meshVertices[meshOffset] *subV;
- }
- }else {
- offset=i+4;
- }
- this._vertices[offset++]=position.x;
- this._vertices[offset++]=position.y;
- this._vertices[offset++]=position.z;
- this._vertices[offset++]=ShurikenParticleData.startLifeTime;
- this._vertices[offset++]=direction.x;
- this._vertices[offset++]=direction.y;
- this._vertices[offset++]=direction.z;
- this._vertices[offset++]=time;
- this._vertices[offset++]=ShurikenParticleData.startColor.x;
- this._vertices[offset++]=ShurikenParticleData.startColor.y;
- this._vertices[offset++]=ShurikenParticleData.startColor.z;
- this._vertices[offset++]=ShurikenParticleData.startColor.w;
- this._vertices[offset++]=ShurikenParticleData.startSize[0];
- this._vertices[offset++]=ShurikenParticleData.startSize[1];
- this._vertices[offset++]=ShurikenParticleData.startSize[2];
- this._vertices[offset++]=ShurikenParticleData.startRotation[0];
- this._vertices[offset++]=ShurikenParticleData.startRotation[1];
- this._vertices[offset++]=ShurikenParticleData.startRotation[2];
- this._vertices[offset++]=ShurikenParticleData.startSpeed;
- needRandomColor && (this._vertices[offset+1]=randomColor);
- needRandomSize && (this._vertices[offset+2]=randomSize);
- needRandomRotation && (this._vertices[offset+3]=randomRotation);
- needRandomTextureAnimation && (this._vertices[offset+4]=randomTextureAnimation);
- if (needRandomVelocity){
- this._vertices[offset+5]=randomVelocityX;
- this._vertices[offset+6]=randomVelocityY;
- this._vertices[offset+7]=randomVelocityZ;
- }
- switch(this.simulationSpace){
- case 0:
- offset+=8;
- this._vertices[offset++]=ShurikenParticleData.simulationWorldPostion[0];
- this._vertices[offset++]=ShurikenParticleData.simulationWorldPostion[1];
- this._vertices[offset++]=ShurikenParticleData.simulationWorldPostion[2];
- this._vertices[offset++]=ShurikenParticleData.simulationWorldRotation[0];
- this._vertices[offset++]=ShurikenParticleData.simulationWorldRotation[1];
- this._vertices[offset++]=ShurikenParticleData.simulationWorldRotation[2];
- this._vertices[offset++]=ShurikenParticleData.simulationWorldRotation[3];
- break ;
- case 1:
- break ;
- default :
- throw new Error("ShurikenParticleMaterial: SimulationSpace value is invalid.");
- }
- }
- this._firstFreeElement=nextFreeParticle;
- return true;
- }
- __proto.addNewParticlesToVertexBuffer=function(){
- var start=0;
- if (this._firstNewElement < this._firstFreeElement){
- start=this._firstNewElement *this._vertexStride *this._floatCountPerVertex;
- this._vertexBuffer.setData(this._vertices,start,start,(this._firstFreeElement-this._firstNewElement)*this._vertexStride *this._floatCountPerVertex);
- }else {
- start=this._firstNewElement *this._vertexStride *this._floatCountPerVertex;
- this._vertexBuffer.setData(this._vertices,start,start,(this._bufferMaxParticles-this._firstNewElement)*this._vertexStride *this._floatCountPerVertex);
- if (this._firstFreeElement > 0){
- this._vertexBuffer.setData(this._vertices,0,0,this._firstFreeElement *this._vertexStride *this._floatCountPerVertex);
- }
- }
- this._firstNewElement=this._firstFreeElement;
- }
- /**
- *@inheritDoc
- */
- __proto._getType=function(){
- return ShurikenParticleSystem._type;
- }
- /**
- *@inheritDoc
- */
- __proto._prepareRender=function(state){
- this._updateEmission();
- if (this._firstNewElement !=this._firstFreeElement)
- this.addNewParticlesToVertexBuffer();
- this._drawCounter++;
- if (this._firstActiveElement !=this._firstFreeElement)
- return true;
- else
- return false;
- }
- /**
- *@private
- */
- __proto._render=function(state){
- this._bufferState.bind();
- var indexCount=0;
- var gl=LayaGL.instance;
- if (this._firstActiveElement < this._firstFreeElement){
- indexCount=(this._firstFreeElement-this._firstActiveElement)*this._indexStride;
- gl.drawElements(/*laya.webgl.WebGLContext.TRIANGLES*/0x0004,indexCount,/*laya.webgl.WebGLContext.UNSIGNED_SHORT*/0x1403,2 *this._firstActiveElement *this._indexStride);
- Stat.trianglesFaces+=indexCount / 3;
- Stat.renderBatches++;
- }else {
- indexCount=(this._bufferMaxParticles-this._firstActiveElement)*this._indexStride;
- gl.drawElements(/*laya.webgl.WebGLContext.TRIANGLES*/0x0004,indexCount,/*laya.webgl.WebGLContext.UNSIGNED_SHORT*/0x1403,2 *this._firstActiveElement *this._indexStride);
- Stat.trianglesFaces+=indexCount / 3;
- Stat.renderBatches++;
- if (this._firstFreeElement > 0){
- indexCount=this._firstFreeElement *this._indexStride;
- gl.drawElements(/*laya.webgl.WebGLContext.TRIANGLES*/0x0004,indexCount,/*laya.webgl.WebGLContext.UNSIGNED_SHORT*/0x1403,0);
- Stat.trianglesFaces+=indexCount / 3;
- Stat.renderBatches++;
- }
- }
- }
- /**
- *开始发射粒子。
- */
- __proto.play=function(){
- this._burstsIndex=0;
- this._isEmitting=true;
- this._isPlaying=true;
- this._isPaused=false;
- this._emissionTime=0;
- this._totalDelayTime=0;
- if (!this.autoRandomSeed){
- for (var i=0,n=this._randomSeeds.length;i < n;i++)
- this._randomSeeds[i]=this.randomSeed[0]+ShurikenParticleSystem._RANDOMOFFSET[i];
- }
- switch (this.startDelayType){
- case 0:
- this._playStartDelay=this.startDelay;
- break ;
- case 1:
- if (this.autoRandomSeed){
- this._playStartDelay=MathUtil.lerp(this.startDelayMin,this.startDelayMax,Math.random());
- }else {
- this._rand.seed=this._randomSeeds[2];
- this._playStartDelay=MathUtil.lerp(this.startDelayMin,this.startDelayMax,this._rand.getFloat());
- this._randomSeeds[2]=this._rand.seed;
- }
- break ;
- default :
- throw new Error("Utils3D: startDelayType is invalid.");
- }
- this._frameRateTime=this._currentTime+this._playStartDelay;
- this._startUpdateLoopCount=Stat.loopCount;
- }
- /**
- *暂停发射粒子。
- */
- __proto.pause=function(){
- this._isPaused=true;
- }
- /**
- *通过指定时间增加粒子播放进度,并暂停播放。
- *@param time 进度时间.如果restart为true,粒子播放时间会归零后再更新进度。
- *@param restart 是否重置播放状态。
- */
- __proto.simulate=function(time,restart){
- (restart===void 0)&& (restart=true);
- this._simulateUpdate=true;
- if (restart){
- this._updateParticlesSimulationRestart(time);
- }
- else{
- this._isPaused=false;
- this._updateParticles(time);
- }
- this.pause();
- }
- /**
- *停止发射粒子。
- */
- __proto.stop=function(){
- this._burstsIndex=0;
- this._isEmitting=false;
- this._emissionTime=0;
- }
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var dest=destObject;
- dest.duration=this.duration;
- dest.looping=this.looping;
- dest.prewarm=this.prewarm;
- dest.startDelayType=this.startDelayType;
- dest.startDelay=this.startDelay;
- dest.startDelayMin=this.startDelayMin;
- dest.startDelayMax=this.startDelayMax;
- dest._maxStartLifetime=this._maxStartLifetime;
- dest.startLifetimeType=this.startLifetimeType;
- dest.startLifetimeConstant=this.startLifetimeConstant;
- this.startLifeTimeGradient.cloneTo(dest.startLifeTimeGradient);
- dest.startLifetimeConstantMin=this.startLifetimeConstantMin;
- dest.startLifetimeConstantMax=this.startLifetimeConstantMax;
- this.startLifeTimeGradientMin.cloneTo(dest.startLifeTimeGradientMin);
- this.startLifeTimeGradientMax.cloneTo(dest.startLifeTimeGradientMax);
- dest.startSpeedType=this.startSpeedType;
- dest.startSpeedConstant=this.startSpeedConstant;
- dest.startSpeedConstantMin=this.startSpeedConstantMin;
- dest.startSpeedConstantMax=this.startSpeedConstantMax;
- dest.threeDStartSize=this.threeDStartSize;
- dest.startSizeType=this.startSizeType;
- dest.startSizeConstant=this.startSizeConstant;
- this.startSizeConstantSeparate.cloneTo(dest.startSizeConstantSeparate);
- dest.startSizeConstantMin=this.startSizeConstantMin;
- dest.startSizeConstantMax=this.startSizeConstantMax;
- this.startSizeConstantMinSeparate.cloneTo(dest.startSizeConstantMinSeparate);
- this.startSizeConstantMaxSeparate.cloneTo(dest.startSizeConstantMaxSeparate);
- dest.threeDStartRotation=this.threeDStartRotation;
- dest.startRotationType=this.startRotationType;
- dest.startRotationConstant=this.startRotationConstant;
- this.startRotationConstantSeparate.cloneTo(dest.startRotationConstantSeparate);
- dest.startRotationConstantMin=this.startRotationConstantMin;
- dest.startRotationConstantMax=this.startRotationConstantMax;
- this.startRotationConstantMinSeparate.cloneTo(dest.startRotationConstantMinSeparate);
- this.startRotationConstantMaxSeparate.cloneTo(dest.startRotationConstantMaxSeparate);
- dest.randomizeRotationDirection=this.randomizeRotationDirection;
- dest.startColorType=this.startColorType;
- this.startColorConstant.cloneTo(dest.startColorConstant);
- this.startColorConstantMin.cloneTo(dest.startColorConstantMin);
- this.startColorConstantMax.cloneTo(dest.startColorConstantMax);
- dest.gravityModifier=this.gravityModifier;
- dest.simulationSpace=this.simulationSpace;
- dest.scaleMode=this.scaleMode;
- dest.playOnAwake=this.playOnAwake;
- dest.maxParticles=this.maxParticles;
- (this._emission)&& (dest._emission=this._emission.clone());
- (this.shape)&& (dest.shape=this.shape.clone());
- (this.velocityOverLifetime)&& (dest.velocityOverLifetime=this.velocityOverLifetime.clone());
- (this.colorOverLifetime)&& (dest.colorOverLifetime=this.colorOverLifetime.clone());
- (this.sizeOverLifetime)&& (dest.sizeOverLifetime=this.sizeOverLifetime.clone());
- (this.rotationOverLifetime)&& (dest.rotationOverLifetime=this.rotationOverLifetime.clone());
- (this.textureSheetAnimation)&& (dest.textureSheetAnimation=this.textureSheetAnimation.clone());
- dest.isPerformanceMode=this.isPerformanceMode;
- dest._isEmitting=this._isEmitting;
- dest._isPlaying=this._isPlaying;
- dest._isPaused=this._isPaused;
- dest._playStartDelay=this._playStartDelay;
- dest._frameRateTime=this._frameRateTime;
- dest._emissionTime=this._emissionTime;
- dest._totalDelayTime=this._totalDelayTime;
- dest._burstsIndex=this._burstsIndex;
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var dest=/*__JS__ */new this.constructor();
- this.cloneTo(dest);
- return dest;
- }
- /**设置最大粒子数,注意:谨慎修改此属性,有性能损耗。*/
- /**获取最大粒子数。*/
- __getset(0,__proto,'maxParticles',function(){
- return this._bufferMaxParticles-1;
- },function(value){
- var newMaxParticles=value+1;
- if (newMaxParticles!==this._bufferMaxParticles){
- this._bufferMaxParticles=newMaxParticles;
- this._initBufferDatas();
- }
- });
- /**
- *是否正在发射。
- */
- __getset(0,__proto,'isEmitting',function(){
- return this._isEmitting;
- });
- /**
- *是否存活。
- */
- __getset(0,__proto,'isAlive',function(){
- if (this._isPlaying || this.aliveParticleCount > 0)
- return true;
- return false;
- });
- /**
- *设置形状。
- */
- /**
- *获取形状。
- */
- __getset(0,__proto,'shape',function(){
- return this._shape;
- },function(value){
- if (this._shape!==value){
- if (value&&value.enable)
- this._owner._render._defineDatas.add(ShuriKenParticle3D.SHADERDEFINE_SHAPE);
- else
- this._owner._render._defineDatas.remove(ShuriKenParticle3D.SHADERDEFINE_SHAPE);
- this._shape=value;
- }
- });
- /**
- *设置生命周期旋转,注意:如修改该值的某些属性,需重新赋值此属性才可生效。
- *@param value 生命周期旋转。
- */
- /**
- *获取生命周期旋转,注意:如修改该值的某些属性,需重新赋值此属性才可生效。
- *@return 生命周期旋转。
- */
- __getset(0,__proto,'rotationOverLifetime',function(){
- return this._rotationOverLifetime;
- },function(value){
- var defDat=this._owner._render._defineDatas;
- var shaDat=this._owner._render._shaderValues;
- if (value){
- var rotation=value.angularVelocity;
- if (!rotation)
- return;
- var rotationSeparate=rotation.separateAxes;
- var rotationType=rotation.type;
- if (value.enbale){
- if (rotationSeparate)
- defDat.add(ShuriKenParticle3D.SHADERDEFINE_ROTATIONOVERLIFETIMESEPERATE);
- else
- defDat.add(ShuriKenParticle3D.SHADERDEFINE_ROTATIONOVERLIFETIME);
- switch (rotationType){
- case 0:
- defDat.add(ShuriKenParticle3D.SHADERDEFINE_ROTATIONOVERLIFETIMECONSTANT);
- break ;
- case 1:
- defDat.add(ShuriKenParticle3D.SHADERDEFINE_ROTATIONOVERLIFETIMECURVE);
- break ;
- case 2:
- defDat.add(ShuriKenParticle3D.SHADERDEFINE_ROTATIONOVERLIFETIMERANDOMCONSTANTS);
- break ;
- case 3:
- defDat.add(ShuriKenParticle3D.SHADERDEFINE_ROTATIONOVERLIFETIMERANDOMCURVES);
- break ;
- }
- }else {
- defDat.remove(ShuriKenParticle3D.SHADERDEFINE_ROTATIONOVERLIFETIME);
- defDat.remove(ShuriKenParticle3D.SHADERDEFINE_ROTATIONOVERLIFETIMESEPERATE);
- defDat.remove(ShuriKenParticle3D.SHADERDEFINE_ROTATIONOVERLIFETIMECONSTANT);
- defDat.remove(ShuriKenParticle3D.SHADERDEFINE_ROTATIONOVERLIFETIMECURVE);
- defDat.remove(ShuriKenParticle3D.SHADERDEFINE_ROTATIONOVERLIFETIMERANDOMCONSTANTS);
- defDat.remove(ShuriKenParticle3D.SHADERDEFINE_ROTATIONOVERLIFETIMERANDOMCURVES);
- }
- switch (rotationType){
- case 0:
- if (rotationSeparate){
- shaDat.setVector3(ShuriKenParticle3D.ROLANGULARVELOCITYCONSTSEPRARATE,rotation.constantSeparate);
- }else {
- shaDat.setNumber(ShuriKenParticle3D.ROLANGULARVELOCITYCONST,rotation.constant);
- }
- break ;
- case 1:
- if (rotationSeparate){
- shaDat.setBuffer(ShuriKenParticle3D.ROLANGULARVELOCITYGRADIENTX,rotation.gradientX._elements);
- shaDat.setBuffer(ShuriKenParticle3D.ROLANGULARVELOCITYGRADIENTY,rotation.gradientY._elements);
- shaDat.setBuffer(ShuriKenParticle3D.ROLANGULARVELOCITYGRADIENTZ,rotation.gradientZ._elements);
- }else {
- shaDat.setBuffer(ShuriKenParticle3D.ROLANGULARVELOCITYGRADIENT,rotation.gradient._elements);
- }
- break ;
- case 2:
- if (rotationSeparate){
- shaDat.setVector3(ShuriKenParticle3D.ROLANGULARVELOCITYCONSTSEPRARATE,rotation.constantMinSeparate);
- shaDat.setVector3(ShuriKenParticle3D.ROLANGULARVELOCITYCONSTMAXSEPRARATE,rotation.constantMaxSeparate);
- }else {
- shaDat.setNumber(ShuriKenParticle3D.ROLANGULARVELOCITYCONST,rotation.constantMin);
- shaDat.setNumber(ShuriKenParticle3D.ROLANGULARVELOCITYCONSTMAX,rotation.constantMax);
- }
- break ;
- case 3:
- if (rotationSeparate){
- shaDat.setBuffer(ShuriKenParticle3D.ROLANGULARVELOCITYGRADIENTX,rotation.gradientXMin._elements);
- shaDat.setBuffer(ShuriKenParticle3D.ROLANGULARVELOCITYGRADIENTXMAX,rotation.gradientXMax._elements);
- shaDat.setBuffer(ShuriKenParticle3D.ROLANGULARVELOCITYGRADIENTY,rotation.gradientYMin._elements);
- shaDat.setBuffer(ShuriKenParticle3D.ROLANGULARVELOCITYGRADIENTYMAX,rotation.gradientYMax._elements);
- shaDat.setBuffer(ShuriKenParticle3D.ROLANGULARVELOCITYGRADIENTZ,rotation.gradientZMin._elements);
- shaDat.setBuffer(ShuriKenParticle3D.ROLANGULARVELOCITYGRADIENTZMAX,rotation.gradientZMax._elements);
- }else {
- shaDat.setBuffer(ShuriKenParticle3D.ROLANGULARVELOCITYGRADIENT,rotation.gradientMin._elements);
- shaDat.setBuffer(ShuriKenParticle3D.ROLANGULARVELOCITYGRADIENTMAX,rotation.gradientMax._elements);
- }
- break ;
- }
- }else {
- defDat.remove(ShuriKenParticle3D.SHADERDEFINE_ROTATIONOVERLIFETIME);
- defDat.remove(ShuriKenParticle3D.SHADERDEFINE_ROTATIONOVERLIFETIMESEPERATE);
- defDat.remove(ShuriKenParticle3D.SHADERDEFINE_ROTATIONOVERLIFETIMECONSTANT);
- defDat.remove(ShuriKenParticle3D.SHADERDEFINE_ROTATIONOVERLIFETIMECURVE);
- defDat.remove(ShuriKenParticle3D.SHADERDEFINE_ROTATIONOVERLIFETIMERANDOMCONSTANTS);
- defDat.remove(ShuriKenParticle3D.SHADERDEFINE_ROTATIONOVERLIFETIMERANDOMCURVES);
- shaDat.setVector(ShuriKenParticle3D.ROLANGULARVELOCITYCONSTSEPRARATE,null);
- shaDat.setVector(ShuriKenParticle3D.ROLANGULARVELOCITYCONSTMAXSEPRARATE,null);
- shaDat.setNumber(ShuriKenParticle3D.ROLANGULARVELOCITYCONST,undefined);
- shaDat.setNumber(ShuriKenParticle3D.ROLANGULARVELOCITYCONSTMAX,undefined);
- shaDat.setBuffer(ShuriKenParticle3D.ROLANGULARVELOCITYGRADIENTX,null);
- shaDat.setBuffer(ShuriKenParticle3D.ROLANGULARVELOCITYGRADIENTXMAX,null);
- shaDat.setBuffer(ShuriKenParticle3D.ROLANGULARVELOCITYGRADIENTY,null);
- shaDat.setBuffer(ShuriKenParticle3D.ROLANGULARVELOCITYGRADIENTYMAX,null);
- shaDat.setBuffer(ShuriKenParticle3D.ROLANGULARVELOCITYGRADIENTZ,null);
- shaDat.setBuffer(ShuriKenParticle3D.ROLANGULARVELOCITYGRADIENTZMAX,null);
- shaDat.setBuffer(ShuriKenParticle3D.ROLANGULARVELOCITYGRADIENTWMAX,null);
- shaDat.setBuffer(ShuriKenParticle3D.ROLANGULARVELOCITYGRADIENT,null);
- shaDat.setBuffer(ShuriKenParticle3D.ROLANGULARVELOCITYGRADIENTMAX,null);
- }
- this._rotationOverLifetime=value;
- });
- /**
- *获取发射器。
- */
- __getset(0,__proto,'emission',function(){
- return this._emission;
- });
- /**
- *获取一次循环内的累计时间。
- *@return 一次循环内的累计时间。
- */
- __getset(0,__proto,'emissionTime',function(){
- return this._emissionTime > this.duration ? this.duration :this._emissionTime;
- });
- /**
- *粒子存活个数。
- */
- __getset(0,__proto,'aliveParticleCount',function(){
- if (this._firstNewElement >=this._firstRetiredElement)
- return this._firstNewElement-this._firstRetiredElement;
- else
- return this._bufferMaxParticles-this._firstRetiredElement+this._firstNewElement;
- });
- /**
- *是否正在播放。
- */
- __getset(0,__proto,'isPlaying',function(){
- return this._isPlaying;
- });
- /**
- *是否已暂停。
- */
- __getset(0,__proto,'isPaused',function(){
- return this._isPaused;
- });
- /**
- *设置开始生命周期模式,0为固定时间,1为渐变时间,2为两个固定之间的随机插值,3为两个渐变时间的随机插值。
- */
- /**
- *获取开始生命周期模式,0为固定时间,1为渐变时间,2为两个固定之间的随机插值,3为两个渐变时间的随机插值。
- */
- __getset(0,__proto,'startLifetimeType',function(){
- return this._startLifetimeType;
- },function(value){
- var i=0,n=0;
- switch (this.startLifetimeType){
- case 0:
- this._maxStartLifetime=this.startLifetimeConstant;
- break ;
- case 1:
- this._maxStartLifetime=-Number.MAX_VALUE;
- var startLifeTimeGradient=startLifeTimeGradient;
- for (i=0,n=startLifeTimeGradient.gradientCount;i < n;i++)
- this._maxStartLifetime=Math.max(this._maxStartLifetime,startLifeTimeGradient.getValueByIndex(i));
- break ;
- case 2:
- this._maxStartLifetime=Math.max(this.startLifetimeConstantMin,this.startLifetimeConstantMax);
- break ;
- case 3:
- this._maxStartLifetime=-Number.MAX_VALUE;
- var startLifeTimeGradientMin=startLifeTimeGradientMin;
- for (i=0,n=startLifeTimeGradientMin.gradientCount;i < n;i++)
- this._maxStartLifetime=Math.max(this._maxStartLifetime,startLifeTimeGradientMin.getValueByIndex(i));
- var startLifeTimeGradientMax=startLifeTimeGradientMax;
- for (i=0,n=startLifeTimeGradientMax.gradientCount;i < n;i++)
- this._maxStartLifetime=Math.max(this._maxStartLifetime,startLifeTimeGradientMax.getValueByIndex(i));
- break ;
- }
- this._startLifetimeType=value;
- });
- /**
- *设置开始生命周期,0模式,单位为秒。
- */
- /**
- *获取开始生命周期,0模式,单位为秒。
- */
- __getset(0,__proto,'startLifetimeConstant',function(){
- return this._startLifetimeConstant;
- },function(value){
- if(this._startLifetimeType===0)
- this._maxStartLifetime=value;
- this._startLifetimeConstant=value;
- });
- /**
- *设置最小开始生命周期,2模式,单位为秒。
- */
- /**
- *获取最小开始生命周期,2模式,单位为秒。
- */
- __getset(0,__proto,'startLifetimeConstantMin',function(){
- return this._startLifetimeConstantMin;
- },function(value){
- if (this._startLifetimeType===2)
- this._maxStartLifetime=Math.max(value,this._startLifetimeConstantMax);
- this._startLifetimeConstantMin=value;
- });
- /**
- *设置开始渐变生命周期,1模式,单位为秒。
- */
- /**
- *获取开始渐变生命周期,1模式,单位为秒。
- */
- __getset(0,__proto,'startLifeTimeGradient',function(){
- return this._startLifeTimeGradient;
- },function(value){
- if (this._startLifetimeType===1){
- this._maxStartLifetime=-Number.MAX_VALUE;
- for (var i=0,n=value.gradientCount;i < n;i++)
- this._maxStartLifetime=Math.max(this._maxStartLifetime,value.getValueByIndex(i));
- }
- this._startLifeTimeGradient=value;
- });
- /**
- *设置最大开始生命周期,2模式,单位为秒。
- */
- /**
- *获取最大开始生命周期,2模式,单位为秒。
- */
- __getset(0,__proto,'startLifetimeConstantMax',function(){
- return this._startLifetimeConstantMax;
- },function(value){
- if (this._startLifetimeType===2)
- this._maxStartLifetime=Math.max(this._startLifetimeConstantMin,value);
- this._startLifetimeConstantMax=value;
- });
- /**
- *设置开始渐变最小生命周期,3模式,单位为秒。
- */
- /**
- *获取开始渐变最小生命周期,3模式,单位为秒。
- */
- __getset(0,__proto,'startLifeTimeGradientMin',function(){
- return this._startLifeTimeGradientMin;
- },function(value){
- if (this._startLifetimeType===3){
- var i=0,n=0;
- this._maxStartLifetime=-Number.MAX_VALUE;
- for (i=0,n=value.gradientCount;i < n;i++)
- this._maxStartLifetime=Math.max(this._maxStartLifetime,value.getValueByIndex(i));
- for (i=0,n=this._startLifeTimeGradientMax.gradientCount;i < n;i++)
- this._maxStartLifetime=Math.max(this._maxStartLifetime,this._startLifeTimeGradientMax.getValueByIndex(i));
- }
- this._startLifeTimeGradientMin=value;
- });
- /**
- *设置开始渐变最大生命周期,3模式,单位为秒。
- */
- /**
- *获取开始渐变最大生命周期,3模式,单位为秒。
- */
- __getset(0,__proto,'startLifeTimeGradientMax',function(){
- return this._startLifeTimeGradientMax;
- },function(value){
- if (this._startLifetimeType===3){
- var i=0,n=0;
- this._maxStartLifetime=-Number.MAX_VALUE;
- for (i=0,n=this._startLifeTimeGradientMin.gradientCount;i < n;i++)
- this._maxStartLifetime=Math.max(this._maxStartLifetime,this._startLifeTimeGradientMin.getValueByIndex(i));
- for (i=0,n=value.gradientCount;i < n;i++)
- this._maxStartLifetime=Math.max(this._maxStartLifetime,value.getValueByIndex(i));
- }
- this._startLifeTimeGradientMax=value;
- });
- /**
- *设置生命周期速度,注意:如修改该值的某些属性,需重新赋值此属性才可生效。
- *@param value 生命周期速度.
- */
- /**
- *获取生命周期速度,注意:如修改该值的某些属性,需重新赋值此属性才可生效。
- *@return 生命周期速度.
- */
- __getset(0,__proto,'velocityOverLifetime',function(){
- return this._velocityOverLifetime;
- },function(value){
- var defDat=this._owner._render._defineDatas;
- var shaDat=this._owner._render._shaderValues;
- if (value){
- var velocity=value.velocity;
- var velocityType=velocity.type;
- if (value.enbale){
- switch (velocityType){
- case 0:
- defDat.add(ShuriKenParticle3D.SHADERDEFINE_VELOCITYOVERLIFETIMECONSTANT);
- break ;
- case 1:
- defDat.add(ShuriKenParticle3D.SHADERDEFINE_VELOCITYOVERLIFETIMECURVE);
- break ;
- case 2:
- defDat.add(ShuriKenParticle3D.SHADERDEFINE_VELOCITYOVERLIFETIMERANDOMCONSTANT);
- break ;
- case 3:
- defDat.add(ShuriKenParticle3D.SHADERDEFINE_VELOCITYOVERLIFETIMERANDOMCURVE);
- break ;
- }
- }else {
- defDat.remove(ShuriKenParticle3D.SHADERDEFINE_VELOCITYOVERLIFETIMECONSTANT);
- defDat.remove(ShuriKenParticle3D.SHADERDEFINE_VELOCITYOVERLIFETIMECURVE);
- defDat.remove(ShuriKenParticle3D.SHADERDEFINE_VELOCITYOVERLIFETIMERANDOMCONSTANT);
- defDat.remove(ShuriKenParticle3D.SHADERDEFINE_VELOCITYOVERLIFETIMERANDOMCURVE);
- }
- switch (velocityType){
- case 0:
- shaDat.setVector3(ShuriKenParticle3D.VOLVELOCITYCONST,velocity.constant);
- break ;
- case 1:
- shaDat.setBuffer(ShuriKenParticle3D.VOLVELOCITYGRADIENTX,velocity.gradientX._elements);
- shaDat.setBuffer(ShuriKenParticle3D.VOLVELOCITYGRADIENTY,velocity.gradientY._elements);
- shaDat.setBuffer(ShuriKenParticle3D.VOLVELOCITYGRADIENTZ,velocity.gradientZ._elements);
- break ;
- case 2:
- shaDat.setVector3(ShuriKenParticle3D.VOLVELOCITYCONST,velocity.constantMin);
- shaDat.setVector3(ShuriKenParticle3D.VOLVELOCITYCONSTMAX,velocity.constantMax);
- break ;
- case 3:
- shaDat.setBuffer(ShuriKenParticle3D.VOLVELOCITYGRADIENTX,velocity.gradientXMin._elements);
- shaDat.setBuffer(ShuriKenParticle3D.VOLVELOCITYGRADIENTXMAX,velocity.gradientXMax._elements);
- shaDat.setBuffer(ShuriKenParticle3D.VOLVELOCITYGRADIENTY,velocity.gradientYMin._elements);
- shaDat.setBuffer(ShuriKenParticle3D.VOLVELOCITYGRADIENTYMAX,velocity.gradientYMax._elements);
- shaDat.setBuffer(ShuriKenParticle3D.VOLVELOCITYGRADIENTZ,velocity.gradientZMin._elements);
- shaDat.setBuffer(ShuriKenParticle3D.VOLVELOCITYGRADIENTZMAX,velocity.gradientZMax._elements);
- break ;
- }
- shaDat.setInt(ShuriKenParticle3D.VOLSPACETYPE,value.space);
- }else {
- defDat.remove(ShuriKenParticle3D.SHADERDEFINE_VELOCITYOVERLIFETIMECONSTANT);
- defDat.remove(ShuriKenParticle3D.SHADERDEFINE_VELOCITYOVERLIFETIMECURVE);
- defDat.remove(ShuriKenParticle3D.SHADERDEFINE_VELOCITYOVERLIFETIMERANDOMCONSTANT);
- defDat.remove(ShuriKenParticle3D.SHADERDEFINE_VELOCITYOVERLIFETIMERANDOMCURVE);
- shaDat.setVector(ShuriKenParticle3D.VOLVELOCITYCONST,null);
- shaDat.setBuffer(ShuriKenParticle3D.VOLVELOCITYGRADIENTX,null);
- shaDat.setBuffer(ShuriKenParticle3D.VOLVELOCITYGRADIENTY,null);
- shaDat.setBuffer(ShuriKenParticle3D.VOLVELOCITYGRADIENTZ,null);
- shaDat.setVector(ShuriKenParticle3D.VOLVELOCITYCONST,null);
- shaDat.setVector(ShuriKenParticle3D.VOLVELOCITYCONSTMAX,null);
- shaDat.setBuffer(ShuriKenParticle3D.VOLVELOCITYGRADIENTX,null);
- shaDat.setBuffer(ShuriKenParticle3D.VOLVELOCITYGRADIENTXMAX,null);
- shaDat.setBuffer(ShuriKenParticle3D.VOLVELOCITYGRADIENTY,null);
- shaDat.setBuffer(ShuriKenParticle3D.VOLVELOCITYGRADIENTYMAX,null);
- shaDat.setBuffer(ShuriKenParticle3D.VOLVELOCITYGRADIENTZ,null);
- shaDat.setBuffer(ShuriKenParticle3D.VOLVELOCITYGRADIENTZMAX,null);
- shaDat.setInt(ShuriKenParticle3D.VOLSPACETYPE,undefined);
- }
- this._velocityOverLifetime=value;
- });
- /**
- *设置生命周期颜色,注意:如修改该值的某些属性,需重新赋值此属性才可生效。
- *@param value 生命周期颜色
- */
- /**
- *获取生命周期颜色,注意:如修改该值的某些属性,需重新赋值此属性才可生效。
- *@return 生命周期颜色
- */
- __getset(0,__proto,'colorOverLifetime',function(){
- return this._colorOverLifetime;
- },function(value){
- var defDat=this._owner._render._defineDatas;
- var shaDat=this._owner._render._shaderValues;
- if (value){
- var color=value.color;
- if (value.enbale){
- switch (color.type){
- case 1:
- defDat.add(ShuriKenParticle3D.SHADERDEFINE_COLOROVERLIFETIME);
- break ;
- case 3:
- defDat.add(ShuriKenParticle3D.SHADERDEFINE_RANDOMCOLOROVERLIFETIME);
- break ;
- }
- }else {
- defDat.remove(ShuriKenParticle3D.SHADERDEFINE_COLOROVERLIFETIME);
- defDat.remove(ShuriKenParticle3D.SHADERDEFINE_RANDOMCOLOROVERLIFETIME);
- }
- switch (color.type){
- case 1:;
- var gradientColor=color.gradient;
- shaDat.setBuffer(ShuriKenParticle3D.COLOROVERLIFEGRADIENTALPHAS,gradientColor._alphaElements);
- shaDat.setBuffer(ShuriKenParticle3D.COLOROVERLIFEGRADIENTCOLORS,gradientColor._rgbElements);
- break ;
- case 3:;
- var minGradientColor=color.gradientMin;
- var maxGradientColor=color.gradientMax;
- shaDat.setBuffer(ShuriKenParticle3D.COLOROVERLIFEGRADIENTALPHAS,minGradientColor._alphaElements);
- shaDat.setBuffer(ShuriKenParticle3D.COLOROVERLIFEGRADIENTCOLORS,minGradientColor._rgbElements);
- shaDat.setBuffer(ShuriKenParticle3D.MAXCOLOROVERLIFEGRADIENTALPHAS,maxGradientColor._alphaElements);
- shaDat.setBuffer(ShuriKenParticle3D.MAXCOLOROVERLIFEGRADIENTCOLORS,maxGradientColor._rgbElements);
- break ;
- }
- }else {
- defDat.remove(ShuriKenParticle3D.SHADERDEFINE_COLOROVERLIFETIME);
- defDat.remove(ShuriKenParticle3D.SHADERDEFINE_RANDOMCOLOROVERLIFETIME);
- shaDat.setBuffer(ShuriKenParticle3D.COLOROVERLIFEGRADIENTALPHAS,gradientColor._alphaElements);
- shaDat.setBuffer(ShuriKenParticle3D.COLOROVERLIFEGRADIENTCOLORS,gradientColor._rgbElements);
- shaDat.setBuffer(ShuriKenParticle3D.COLOROVERLIFEGRADIENTALPHAS,minGradientColor._alphaElements);
- shaDat.setBuffer(ShuriKenParticle3D.COLOROVERLIFEGRADIENTCOLORS,minGradientColor._rgbElements);
- shaDat.setBuffer(ShuriKenParticle3D.MAXCOLOROVERLIFEGRADIENTALPHAS,maxGradientColor._alphaElements);
- shaDat.setBuffer(ShuriKenParticle3D.MAXCOLOROVERLIFEGRADIENTCOLORS,maxGradientColor._rgbElements);
- }
- this._colorOverLifetime=value;
- });
- /**
- *设置生命周期尺寸,注意:如修改该值的某些属性,需重新赋值此属性才可生效。
- *@param value 生命周期尺寸
- */
- /**
- *获取生命周期尺寸,注意:如修改该值的某些属性,需重新赋值此属性才可生效。
- *@return 生命周期尺寸
- */
- __getset(0,__proto,'sizeOverLifetime',function(){
- return this._sizeOverLifetime;
- },function(value){
- var defDat=this._owner._render._defineDatas;
- var shaDat=this._owner._render._shaderValues;
- if (value){
- var size=value.size;
- var sizeSeparate=size.separateAxes;
- var sizeType=size.type;
- if (value.enbale){
- switch (sizeType){
- case 0:
- if (sizeSeparate)
- defDat.add(ShuriKenParticle3D.SHADERDEFINE_SIZEOVERLIFETIMECURVESEPERATE);
- else
- defDat.add(ShuriKenParticle3D.SHADERDEFINE_SIZEOVERLIFETIMECURVE);
- break ;
- case 2:
- if (sizeSeparate)
- defDat.add(ShuriKenParticle3D.SHADERDEFINE_SIZEOVERLIFETIMERANDOMCURVESSEPERATE);
- else
- defDat.add(ShuriKenParticle3D.SHADERDEFINE_SIZEOVERLIFETIMERANDOMCURVES);
- break ;
- }
- }else {
- defDat.remove(ShuriKenParticle3D.SHADERDEFINE_SIZEOVERLIFETIMECURVE);
- defDat.remove(ShuriKenParticle3D.SHADERDEFINE_SIZEOVERLIFETIMECURVESEPERATE);
- defDat.remove(ShuriKenParticle3D.SHADERDEFINE_SIZEOVERLIFETIMERANDOMCURVES);
- defDat.remove(ShuriKenParticle3D.SHADERDEFINE_SIZEOVERLIFETIMERANDOMCURVESSEPERATE);
- }
- switch (sizeType){
- case 0:
- if (sizeSeparate){
- shaDat.setBuffer(ShuriKenParticle3D.SOLSIZEGRADIENTX,size.gradientX._elements);
- shaDat.setBuffer(ShuriKenParticle3D.SOLSIZEGRADIENTY,size.gradientY._elements);
- shaDat.setBuffer(ShuriKenParticle3D.SOLSizeGradientZ,size.gradientZ._elements);
- }else {
- shaDat.setBuffer(ShuriKenParticle3D.SOLSIZEGRADIENT,size.gradient._elements);
- }
- break ;
- case 2:
- if (sizeSeparate){
- shaDat.setBuffer(ShuriKenParticle3D.SOLSIZEGRADIENTX,size.gradientXMin._elements);
- shaDat.setBuffer(ShuriKenParticle3D.SOLSIZEGRADIENTXMAX,size.gradientXMax._elements);
- shaDat.setBuffer(ShuriKenParticle3D.SOLSIZEGRADIENTY,size.gradientYMin._elements);
- shaDat.setBuffer(ShuriKenParticle3D.SOLSIZEGRADIENTYMAX,size.gradientYMax._elements);
- shaDat.setBuffer(ShuriKenParticle3D.SOLSizeGradientZ,size.gradientZMin._elements);
- shaDat.setBuffer(ShuriKenParticle3D.SOLSizeGradientZMAX,size.gradientZMax._elements);
- }else {
- shaDat.setBuffer(ShuriKenParticle3D.SOLSIZEGRADIENT,size.gradientMin._elements);
- shaDat.setBuffer(ShuriKenParticle3D.SOLSizeGradientMax,size.gradientMax._elements);
- }
- break ;
- }
- }else {
- defDat.remove(ShuriKenParticle3D.SHADERDEFINE_SIZEOVERLIFETIMECURVE);
- defDat.remove(ShuriKenParticle3D.SHADERDEFINE_SIZEOVERLIFETIMECURVESEPERATE);
- defDat.remove(ShuriKenParticle3D.SHADERDEFINE_SIZEOVERLIFETIMERANDOMCURVES);
- defDat.remove(ShuriKenParticle3D.SHADERDEFINE_SIZEOVERLIFETIMERANDOMCURVESSEPERATE);
- shaDat.setBuffer(ShuriKenParticle3D.SOLSIZEGRADIENTX,null);
- shaDat.setBuffer(ShuriKenParticle3D.SOLSIZEGRADIENTXMAX,null);
- shaDat.setBuffer(ShuriKenParticle3D.SOLSIZEGRADIENTY,null);
- shaDat.setBuffer(ShuriKenParticle3D.SOLSIZEGRADIENTYMAX,null);
- shaDat.setBuffer(ShuriKenParticle3D.SOLSizeGradientZ,null);
- shaDat.setBuffer(ShuriKenParticle3D.SOLSizeGradientZMAX,null);
- shaDat.setBuffer(ShuriKenParticle3D.SOLSIZEGRADIENT,null);
- shaDat.setBuffer(ShuriKenParticle3D.SOLSizeGradientMax,null);
- }
- this._sizeOverLifetime=value;
- });
- /**
- *设置生命周期纹理动画,注意:如修改该值的某些属性,需重新赋值此属性才可生效。
- *@param value 生命周期纹理动画。
- */
- /**
- *获取生命周期纹理动画,注意:如修改该值的某些属性,需重新赋值此属性才可生效。
- *@return 生命周期纹理动画。
- */
- __getset(0,__proto,'textureSheetAnimation',function(){
- return this._textureSheetAnimation;
- },function(value){
- var defDat=this._owner._render._defineDatas;
- var shaDat=this._owner._render._shaderValues;
- if (value){
- var frameOverTime=value.frame;
- var textureAniType=frameOverTime.type;
- if (value.enable){
- switch (textureAniType){
- case 1:
- defDat.add(ShuriKenParticle3D.SHADERDEFINE_TEXTURESHEETANIMATIONCURVE);
- break ;
- case 3:
- defDat.add(ShuriKenParticle3D.SHADERDEFINE_TEXTURESHEETANIMATIONRANDOMCURVE);
- break ;
- }
- }else {
- defDat.remove(ShuriKenParticle3D.SHADERDEFINE_TEXTURESHEETANIMATIONCURVE);
- defDat.remove(ShuriKenParticle3D.SHADERDEFINE_TEXTURESHEETANIMATIONRANDOMCURVE);
- }
- if (textureAniType===1 || textureAniType===3){
- shaDat.setNumber(ShuriKenParticle3D.TEXTURESHEETANIMATIONCYCLES,value.cycles);
- var title=value.tiles;
- var _uvLengthE=this._uvLength;
- _uvLengthE.x=1.0 / title.x;
- _uvLengthE.y=1.0 / title.y;
- shaDat.setVector2(ShuriKenParticle3D.TEXTURESHEETANIMATIONSUBUVLENGTH,this._uvLength);
- }
- switch (textureAniType){
- case 1:
- shaDat.setBuffer(ShuriKenParticle3D.TEXTURESHEETANIMATIONGRADIENTUVS,frameOverTime.frameOverTimeData._elements);
- break ;
- case 3:
- shaDat.setBuffer(ShuriKenParticle3D.TEXTURESHEETANIMATIONGRADIENTUVS,frameOverTime.frameOverTimeDataMin._elements);
- shaDat.setBuffer(ShuriKenParticle3D.TEXTURESHEETANIMATIONGRADIENTMAXUVS,frameOverTime.frameOverTimeDataMax._elements);
- break ;
- }
- }else {
- defDat.remove(ShuriKenParticle3D.SHADERDEFINE_TEXTURESHEETANIMATIONCURVE);
- defDat.remove(ShuriKenParticle3D.SHADERDEFINE_TEXTURESHEETANIMATIONRANDOMCURVE);
- shaDat.setNumber(ShuriKenParticle3D.TEXTURESHEETANIMATIONCYCLES,undefined);
- shaDat.setVector(ShuriKenParticle3D.TEXTURESHEETANIMATIONSUBUVLENGTH,null);
- shaDat.setBuffer(ShuriKenParticle3D.TEXTURESHEETANIMATIONGRADIENTUVS,null);
- shaDat.setBuffer(ShuriKenParticle3D.TEXTURESHEETANIMATIONGRADIENTMAXUVS,null);
- }
- this._textureSheetAnimation=value;
- });
- ShurikenParticleSystem.halfKSqrtOf2=1.42 *0.5;
- __static(ShurikenParticleSystem,
- ['_RANDOMOFFSET',function(){return this._RANDOMOFFSET=new Uint32Array([0x23571a3e,0xc34f56fe,0x13371337,0x12460f3b,0x6aed452e,0xdec4aea1,0x96aa4de3,0x8d2c8431,0xf3857f6f,0xe0fbd834,0x13740583,0x591bc05c,0x40eb95e4,0xbc524e5f,0xaf502044,0xa614b381,0x1034e524,0xfc524e5f]);},'_maxElapsedTime',function(){return this._maxElapsedTime=1.0 / 3.0;},'_tempVector30',function(){return this._tempVector30=new Vector3();},'_tempVector31',function(){return this._tempVector31=new Vector3();},'_tempVector32',function(){return this._tempVector32=new Vector3();},'_tempVector33',function(){return this._tempVector33=new Vector3();},'_tempVector34',function(){return this._tempVector34=new Vector3();},'_tempVector35',function(){return this._tempVector35=new Vector3();},'_tempVector36',function(){return this._tempVector36=new Vector3();},'_tempVector37',function(){return this._tempVector37=new Vector3();},'_tempVector38',function(){return this._tempVector38=new Vector3();},'_tempVector39',function(){return this._tempVector39=new Vector3();},'_tempPosition',function(){return this._tempPosition=new Vector3();},'_tempDirection',function(){return this._tempDirection=new Vector3();},'_type',function(){return this._type=GeometryElement._typeCounter++;}
- ]);
- return ShurikenParticleSystem;
- })(GeometryElement)
- /**
- *<code>StaticPlaneColliderShape</code> 类用于创建静态平面碰撞器。
- */
- //class laya.d3.physics.shape.StaticPlaneColliderShape extends laya.d3.physics.shape.ColliderShape
- var StaticPlaneColliderShape=(function(_super){
- function StaticPlaneColliderShape(normal,offset){
- /**@private */
- //this._offset=NaN;
- /**@private */
- //this._normal=null;
- StaticPlaneColliderShape.__super.call(this);
- this._normal=normal;
- this._offset=offset;
- this._type=/*laya.d3.physics.shape.ColliderShape.SHAPETYPES_STATICPLANE*/6;
- StaticPlaneColliderShape._nativeNormal.setValue(-normal.x,normal.y,normal.z);
- this._nativeShape=new Laya3D._physics3D.btStaticPlaneShape(StaticPlaneColliderShape._nativeNormal,offset);
- }
- __class(StaticPlaneColliderShape,'laya.d3.physics.shape.StaticPlaneColliderShape',_super);
- var __proto=StaticPlaneColliderShape.prototype;
- /**
- *@inheritDoc
- */
- __proto.clone=function(){
- var dest=new StaticPlaneColliderShape(this._normal,this._offset);
- this.cloneTo(dest);
- return dest;
- }
- __static(StaticPlaneColliderShape,
- ['_nativeNormal',function(){return this._nativeNormal=new Laya3D._physics3D.btVector3(0,0,0);}
- ]);
- return StaticPlaneColliderShape;
- })(ColliderShape)
- /**
- *@private
- *<code>MeshSprite3DDynamicBatchManager</code> 类用于网格精灵动态批处理管理。
- */
- //class laya.d3.graphics.MeshRenderDynamicBatchManager extends laya.d3.graphics.DynamicBatchManager
- var MeshRenderDynamicBatchManager=(function(_super){
- function MeshRenderDynamicBatchManager(){
- /**@private [只读]*/
- //this._updateCountMark=0;
- this._instanceBatchOpaqueMarks=[];
- this._vertexBatchOpaqueMarks=[];
- this._cacheBufferStates=[];
- MeshRenderDynamicBatchManager.__super.call(this);
- SubMeshDynamicBatch.instance=new SubMeshDynamicBatch();
- this._updateCountMark=0;
- }
- __class(MeshRenderDynamicBatchManager,'laya.d3.graphics.MeshRenderDynamicBatchManager',_super);
- var __proto=MeshRenderDynamicBatchManager.prototype;
- /**
- *@private
- */
- __proto.getInstanceBatchOpaquaMark=function(lightMapIndex,receiveShadow,materialID,subMeshID){
- var instanceLightMapMarks=(this._instanceBatchOpaqueMarks[lightMapIndex])|| (this._instanceBatchOpaqueMarks[lightMapIndex]=[]);
- var instanceReceiveShadowMarks=(instanceLightMapMarks[receiveShadow ? 0 :1])|| (instanceLightMapMarks[receiveShadow ? 0 :1]=[]);
- var instanceMaterialMarks=(instanceReceiveShadowMarks[materialID])|| (instanceReceiveShadowMarks[materialID]=[]);
- return instanceMaterialMarks[subMeshID] || (instanceMaterialMarks[subMeshID]=new BatchMark());
- }
- /**
- *@private
- */
- __proto.getVertexBatchOpaquaMark=function(lightMapIndex,receiveShadow,materialID,verDecID){
- var dynLightMapMarks=(this._vertexBatchOpaqueMarks[lightMapIndex])|| (this._vertexBatchOpaqueMarks[lightMapIndex]=[]);
- var dynReceiveShadowMarks=(dynLightMapMarks[receiveShadow ? 0 :1])|| (dynLightMapMarks[receiveShadow ? 0 :1]=[]);
- var dynMaterialMarks=(dynReceiveShadowMarks[materialID])|| (dynReceiveShadowMarks[materialID]=[]);
- return dynMaterialMarks[verDecID] || (dynMaterialMarks[verDecID]=new BatchMark());
- }
- /**
- *@private
- */
- __proto._getBufferState=function(vertexDeclaration){
- var bufferState=this._cacheBufferStates[vertexDeclaration.id];
- if (!bufferState){
- var instance=SubMeshDynamicBatch.instance;
- bufferState=new BufferState();
- bufferState.bind();
- var vertexBuffer=instance._vertexBuffer;
- vertexBuffer.vertexDeclaration=vertexDeclaration;
- bufferState.applyVertexBuffer(vertexBuffer);
- bufferState.applyIndexBuffer(instance._indexBuffer);
- bufferState.unBind();
- this._cacheBufferStates[vertexDeclaration.id]=bufferState;
- }
- return bufferState;
- }
- /**
- *@inheritDoc
- */
- __proto._getBatchRenderElementFromPool=function(){
- var renderElement=this._batchRenderElementPool [this._batchRenderElementPoolIndex++];
- if (!renderElement){
- renderElement=new SubMeshRenderElement();
- this._batchRenderElementPool[this._batchRenderElementPoolIndex-1]=renderElement;
- renderElement.vertexBatchElementList=[];
- renderElement.instanceBatchElementList=[];
- }
- return renderElement;
- }
- /**
- *@inheritDoc
- */
- __proto._clear=function(){
- _super.prototype._clear.call(this);
- this._updateCountMark++;
- }
- __static(MeshRenderDynamicBatchManager,
- ['instance',function(){return this.instance=new MeshRenderDynamicBatchManager();}
- ]);
- return MeshRenderDynamicBatchManager;
- })(DynamicBatchManager)
- /**
- *<code>BoxColliderShape</code> 类用于创建盒子形状碰撞器。
- */
- //class laya.d3.physics.shape.BoxColliderShape extends laya.d3.physics.shape.ColliderShape
- var BoxColliderShape=(function(_super){
- function BoxColliderShape(sizeX,sizeY,sizeZ){
- /**@private */
- //this._sizeX=NaN;
- /**@private */
- //this._sizeY=NaN;
- /**@private */
- //this._sizeZ=NaN;
- BoxColliderShape.__super.call(this);
- (sizeX===void 0)&& (sizeX=1.0);
- (sizeY===void 0)&& (sizeY=1.0);
- (sizeZ===void 0)&& (sizeZ=1.0);
- this._sizeX=sizeX;
- this._sizeY=sizeY;
- this._sizeZ=sizeZ;
- this._type=/*laya.d3.physics.shape.ColliderShape.SHAPETYPES_BOX*/0;
- BoxColliderShape._nativeSize.setValue(sizeX / 2,sizeY / 2,sizeZ / 2);
- this._nativeShape=new Laya3D._physics3D.btBoxShape(BoxColliderShape._nativeSize);
- }
- __class(BoxColliderShape,'laya.d3.physics.shape.BoxColliderShape',_super);
- var __proto=BoxColliderShape.prototype;
- /**
- *@inheritDoc
- */
- __proto.clone=function(){
- var dest=new BoxColliderShape(this._sizeX,this._sizeY,this._sizeZ);
- this.cloneTo(dest);
- return dest;
- }
- /**
- *获取X轴尺寸。
- */
- __getset(0,__proto,'sizeX',function(){
- return this._sizeX;
- });
- /**
- *获取Y轴尺寸。
- */
- __getset(0,__proto,'sizeY',function(){
- return this._sizeY;
- });
- /**
- *获取Z轴尺寸。
- */
- __getset(0,__proto,'sizeZ',function(){
- return this._sizeZ;
- });
- __static(BoxColliderShape,
- ['_nativeSize',function(){return this._nativeSize=new Laya3D._physics3D.btVector3(0,0,0);}
- ]);
- return BoxColliderShape;
- })(ColliderShape)
- /**
- *<code>SimpleSingletonList</code> 类用于实现单例队列。
- */
- //class laya.d3.component.SimpleSingletonList extends laya.d3.component.SingletonList
- var SimpleSingletonList=(function(_super){
- /**
- *创建一个新的 <code>SimpleSingletonList</code> 实例。
- */
- function SimpleSingletonList(){
- SimpleSingletonList.__super.call(this);
- }
- __class(SimpleSingletonList,'laya.d3.component.SimpleSingletonList',_super);
- var __proto=SimpleSingletonList.prototype;
- /**
- *@private
- */
- __proto.add=function(element){
- var index=element._getIndexInList();
- if (index!==-1)
- throw "SimpleSingletonList:"+element+" has in SingletonList.";
- this._add(element);
- element._setIndexInList(this.length++);
- }
- /**
- *@private
- */
- __proto.remove=function(element){
- var index=element._getIndexInList();
- this.length--;
- if (index!==this.length){
- var end=this.elements[this.length];
- this.elements[index]=end;
- end._setIndexInList(index);
- }
- element._setIndexInList(-1);
- }
- return SimpleSingletonList;
- })(SingletonList)
- /**
- *<code>PhysicsUpdateList</code> 类用于实现物理更新队列。
- */
- //class laya.d3.physics.PhysicsUpdateList extends laya.d3.component.SingletonList
- var PhysicsUpdateList=(function(_super){
- /**
- *创建一个新的 <code>PhysicsUpdateList</code> 实例。
- */
- function PhysicsUpdateList(){
- PhysicsUpdateList.__super.call(this);
- }
- __class(PhysicsUpdateList,'laya.d3.physics.PhysicsUpdateList',_super);
- var __proto=PhysicsUpdateList.prototype;
- /**
- *@private
- */
- __proto.add=function(element){
- var index=element._inPhysicUpdateListIndex;
- if (index!==-1)
- throw "PhysicsUpdateList:element has in PhysicsUpdateList.";
- this._add(element);
- element._inPhysicUpdateListIndex=this.length++;
- }
- /**
- *@private
- */
- __proto.remove=function(element){
- var index=element._inPhysicUpdateListIndex;
- this.length--;
- if (index!==this.length){
- var end=this.elements[this.length];
- this.elements[index]=end;
- end._inPhysicUpdateListIndex=index;
- }
- element._inPhysicUpdateListIndex=-1;
- }
- return PhysicsUpdateList;
- })(SingletonList)
- /**
- *@private
- *<code>SubMeshStaticBatch</code> 类用于网格静态合并。
- */
- //class laya.d3.graphics.SubMeshStaticBatch extends laya.d3.core.GeometryElement
- var SubMeshStaticBatch=(function(_super){
- function SubMeshStaticBatch(batchOwner,number,vertexDeclaration){
- /**@private */
- //this._currentBatchVertexCount=0;
- /**@private */
- //this._currentBatchIndexCount=0;
- /**@private */
- //this._vertexDeclaration=null;
- /**@private */
- //this._vertexBuffer=null;
- /**@private */
- //this._indexBuffer=null;
- /**@private */
- //this._batchElements=null;
- /**@private */
- //this._batchID=0;
- /**@private [只读]*/
- //this.batchOwner=null;
- /**@private [只读]*/
- //this.number=0;
- SubMeshStaticBatch.__super.call(this);
- this._bufferState=new BufferState();
- this._batchID=SubMeshStaticBatch._batchIDCounter++;
- this._batchElements=[];
- this._currentBatchVertexCount=0;
- this._currentBatchIndexCount=0;
- this._vertexDeclaration=vertexDeclaration;
- this.batchOwner=batchOwner;
- this.number=number;
- }
- __class(SubMeshStaticBatch,'laya.d3.graphics.SubMeshStaticBatch',_super);
- var __proto=SubMeshStaticBatch.prototype;
- Laya.imps(__proto,{"laya.resource.IDispose":true})
- /**
- *@private
- */
- __proto._getStaticBatchBakedVertexs=function(batchVertices,batchOffset,batchOwnerTransform,transform,render,mesh){
- var vertexBuffer=mesh._vertexBuffers[0];
- var vertexDeclaration=vertexBuffer.vertexDeclaration;
- var positionOffset=vertexDeclaration.getVertexElementByUsage(/*laya.d3.graphics.Vertex.VertexMesh.MESH_POSITION0*/0).offset / 4;
- var normalElement=vertexDeclaration.getVertexElementByUsage(/*laya.d3.graphics.Vertex.VertexMesh.MESH_NORMAL0*/3);
- var normalOffset=normalElement ? normalElement.offset / 4 :-1;
- var colorElement=vertexDeclaration.getVertexElementByUsage(/*laya.d3.graphics.Vertex.VertexMesh.MESH_COLOR0*/1);
- var colorOffset=colorElement ? colorElement.offset / 4 :-1;
- var uv0Element=vertexDeclaration.getVertexElementByUsage(/*laya.d3.graphics.Vertex.VertexMesh.MESH_TEXTURECOORDINATE0*/2);
- var uv0Offset=uv0Element ? uv0Element.offset / 4 :-1;
- var uv1Element=vertexDeclaration.getVertexElementByUsage(/*laya.d3.graphics.Vertex.VertexMesh.MESH_TEXTURECOORDINATE1*/7);
- var uv1Offset=uv1Element ? uv1Element.offset / 4 :-1;
- var tangentElement=vertexDeclaration.getVertexElementByUsage(/*laya.d3.graphics.Vertex.VertexMesh.MESH_TANGENT0*/4);
- var sTangentOffset=tangentElement ? tangentElement.offset / 4 :-1;
- var bakeVertexFloatCount=18;
- var oriVertexFloatCount=vertexDeclaration.vertexStride / 4;
- var oriVertexes=vertexBuffer.getData();
- var worldMat;
- if (batchOwnerTransform){
- var rootMat=batchOwnerTransform.worldMatrix;
- rootMat.invert(SubMeshStaticBatch._tempMatrix4x40);
- worldMat=SubMeshStaticBatch._tempMatrix4x41;
- Matrix4x4.multiply(SubMeshStaticBatch._tempMatrix4x40,transform.worldMatrix,worldMat);
- }else {
- worldMat=transform.worldMatrix;
- };
- var rotation=SubMeshStaticBatch._tempQuaternion0;
- worldMat.decomposeTransRotScale(SubMeshStaticBatch._tempVector30,rotation,SubMeshStaticBatch._tempVector31);
- var lightmapScaleOffset=render.lightmapScaleOffset;
- var vertexCount=mesh.vertexCount;
- for (var i=0;i < vertexCount;i++){
- var oriOffset=i *oriVertexFloatCount;
- var bakeOffset=(i+batchOffset)*bakeVertexFloatCount;
- Utils3D.transformVector3ArrayToVector3ArrayCoordinate(oriVertexes,oriOffset+positionOffset,worldMat,batchVertices,bakeOffset+0);
- if (normalOffset!==-1)
- Utils3D.transformVector3ArrayByQuat(oriVertexes,oriOffset+normalOffset,rotation,batchVertices,bakeOffset+3);
- var j=0,m=0;
- var bakOff=bakeOffset+6;
- if (colorOffset!==-1){
- var oriOff=oriOffset+colorOffset;
- for (j=0,m=4;j < m;j++)
- batchVertices[bakOff+j]=oriVertexes[oriOff+j];
- }else {
- for (j=0,m=4;j < m;j++)
- batchVertices[bakOff+j]=1.0;
- }
- if (uv0Offset!==-1){
- var absUv0Offset=oriOffset+uv0Offset;
- batchVertices[bakeOffset+10]=oriVertexes[absUv0Offset];
- batchVertices[bakeOffset+11]=oriVertexes[absUv0Offset+1];
- }
- if (lightmapScaleOffset){
- if (uv1Offset!==-1)
- Utils3D.transformLightingMapTexcoordArray(oriVertexes,oriOffset+uv1Offset,lightmapScaleOffset,batchVertices,bakeOffset+12);
- else
- Utils3D.transformLightingMapTexcoordArray(oriVertexes,oriOffset+uv0Offset,lightmapScaleOffset,batchVertices,bakeOffset+12);
- }
- if (sTangentOffset!==-1){
- var absSTanegntOffset=oriOffset+sTangentOffset;
- batchVertices[bakeOffset+14]=oriVertexes[absSTanegntOffset];
- batchVertices[bakeOffset+15]=oriVertexes[absSTanegntOffset+1];
- batchVertices[bakeOffset+16]=oriVertexes[absSTanegntOffset+2];
- batchVertices[bakeOffset+17]=oriVertexes[absSTanegntOffset+3];
- }
- }
- return vertexCount;
- }
- /**
- *@private
- */
- __proto.addTest=function(sprite){
- var vertexCount=0;
- var subMeshVertexCount=((sprite).meshFilter.sharedMesh).vertexCount;
- vertexCount=this._currentBatchVertexCount+subMeshVertexCount;
- if (vertexCount > 65535)
- return false;
- return true;
- }
- /**
- *@private
- */
- __proto.add=function(sprite){
- var oldStaticBatch=sprite._render._staticBatch;
- (oldStaticBatch)&& (oldStaticBatch.remove(sprite));
- var mesh=(sprite).meshFilter.sharedMesh;
- var subMeshVertexCount=mesh.vertexCount;
- this._batchElements.push(sprite);
- var render=sprite._render;
- render._isPartOfStaticBatch=true;
- render._staticBatch=this;
- var renderElements=render._renderElements;
- for (var i=0,n=renderElements.length;i < n;i++)
- renderElements[i].staticBatch=this;
- this._currentBatchIndexCount+=mesh._indexBuffer.indexCount;
- this._currentBatchVertexCount+=subMeshVertexCount;
- }
- /**
- *@private
- */
- __proto.remove=function(sprite){
- var mesh=(sprite).meshFilter.sharedMesh;
- var index=this._batchElements.indexOf(sprite);
- if (index!==-1){
- this._batchElements.splice(index,1);
- var render=sprite._render;
- var renderElements=sprite._render._renderElements;
- for (var i=0,n=renderElements.length;i < n;i++)
- renderElements[i].staticBatch=null;
- var meshVertexCount=mesh.vertexCount;
- this._currentBatchIndexCount=this._currentBatchIndexCount-mesh._indexBuffer.indexCount;
- this._currentBatchVertexCount=this._currentBatchVertexCount-meshVertexCount;
- sprite._render._isPartOfStaticBatch=false;
- }
- }
- /**
- *@private
- */
- __proto.finishInit=function(){
- if (this._vertexBuffer){
- this._vertexBuffer.destroy();
- this._indexBuffer.destroy();
- Resource._addGPUMemory(-(this._vertexBuffer._byteLength+this._indexBuffer._byteLength));
- };
- var batchVertexCount=0;
- var batchIndexCount=0;
- var rootOwner=this.batchOwner;
- var floatStride=this._vertexDeclaration.vertexStride / 4;
- var vertexDatas=new Float32Array(floatStride *this._currentBatchVertexCount);
- var indexDatas=new Uint16Array(this._currentBatchIndexCount);
- this._vertexBuffer=new VertexBuffer3D(this._vertexDeclaration.vertexStride *this._currentBatchVertexCount,/*laya.webgl.WebGLContext.STATIC_DRAW*/0x88E4);
- this._vertexBuffer.vertexDeclaration=this._vertexDeclaration;
- this._indexBuffer=new IndexBuffer3D(/*laya.d3.graphics.IndexBuffer3D.INDEXTYPE_USHORT*/"ushort",this._currentBatchIndexCount,/*laya.webgl.WebGLContext.STATIC_DRAW*/0x88E4);
- for (var i=0,n=this._batchElements.length;i < n;i++){
- var sprite=this._batchElements [i];
- var mesh=sprite.meshFilter.sharedMesh;
- var meshVerCount=this._getStaticBatchBakedVertexs(vertexDatas,batchVertexCount,rootOwner ? rootOwner._transform :null,sprite._transform,(sprite._render),mesh);
- var indices=mesh._indexBuffer.getData();
- var indexOffset=batchVertexCount;
- var indexEnd=batchIndexCount+indices.length;
- var elements=sprite._render._renderElements;
- for (var j=0,m=mesh.subMeshCount;j < m;j++){
- var subMesh=mesh._subMeshes[j];
- var start=batchIndexCount+subMesh._indexStart;
- var element=elements [j];
- element.staticBatchIndexStart=start;
- element.staticBatchIndexEnd=start+subMesh._indexCount;
- }
- indexDatas.set(indices,batchIndexCount);
- var k=0;
- var isInvert=rootOwner ? (sprite._transform._isFrontFaceInvert!==rootOwner.transform._isFrontFaceInvert):sprite._transform._isFrontFaceInvert;
- if (isInvert){
- for (k=batchIndexCount;k < indexEnd;k+=3){
- indexDatas[k]=indexOffset+indexDatas[k];
- var index1=indexDatas[k+1];
- var index2=indexDatas[k+2];
- indexDatas[k+1]=indexOffset+index2;
- indexDatas[k+2]=indexOffset+index1;
- }
- }else {
- for (k=batchIndexCount;k < indexEnd;k+=3){
- indexDatas[k]=indexOffset+indexDatas[k];
- indexDatas[k+1]=indexOffset+indexDatas[k+1];
- indexDatas[k+2]=indexOffset+indexDatas[k+2];
- }
- }
- batchIndexCount+=indices.length;
- batchVertexCount+=meshVerCount;
- }
- this._vertexBuffer.setData(vertexDatas);
- this._indexBuffer.setData(indexDatas);
- var memorySize=this._vertexBuffer._byteLength+this._indexBuffer._byteLength;
- Resource._addGPUMemory(memorySize);
- this._bufferState.bind();
- this._bufferState.applyVertexBuffer(this._vertexBuffer);
- this._bufferState.applyIndexBuffer(this._indexBuffer);
- this._bufferState.unBind();
- }
- /**
- *@inheritDoc
- */
- __proto._render=function(state){
- this._bufferState.bind();
- var element=state.renderElement;
- var batchElementList=(element).staticBatchElementList;
- var from=0;
- var end=0;
- var count=batchElementList.length;
- for (var i=1;i < count;i++){
- var lastElement=batchElementList[i-1];
- if (lastElement.staticBatchIndexEnd===batchElementList[i].staticBatchIndexStart){
- end++;
- continue ;
- }else {
- var start=batchElementList[from].staticBatchIndexStart;
- var indexCount=batchElementList[end].staticBatchIndexEnd-start;
- LayaGL.instance.drawElements(/*laya.webgl.WebGLContext.TRIANGLES*/0x0004,indexCount,/*laya.webgl.WebGLContext.UNSIGNED_SHORT*/0x1403,start *2);
- from=++end;
- Stat.trianglesFaces+=indexCount / 3;
- }
- }
- start=batchElementList[from].staticBatchIndexStart;
- indexCount=batchElementList[end].staticBatchIndexEnd-start;
- LayaGL.instance.drawElements(/*laya.webgl.WebGLContext.TRIANGLES*/0x0004,indexCount,/*laya.webgl.WebGLContext.UNSIGNED_SHORT*/0x1403,start *2);
- Stat.renderBatches++;
- Stat.savedRenderBatches+=count-1;
- Stat.trianglesFaces+=indexCount / 3;
- }
- /**
- *@private
- */
- __proto.dispose=function(){
- var memorySize=this._vertexBuffer._byteLength+this._indexBuffer._byteLength;
- Resource._addGPUMemory(-memorySize);
- this._batchElements=null;
- this.batchOwner=null;
- this._vertexDeclaration=null;
- this._bufferState.destroy();
- this._vertexBuffer.destroy();
- this._indexBuffer.destroy();
- this._vertexBuffer=null;
- this._indexBuffer=null;
- this._bufferState=null;
- }
- SubMeshStaticBatch.maxBatchVertexCount=65535;
- SubMeshStaticBatch._batchIDCounter=0;
- __static(SubMeshStaticBatch,
- ['_tempVector30',function(){return this._tempVector30=new Vector3();},'_tempVector31',function(){return this._tempVector31=new Vector3();},'_tempQuaternion0',function(){return this._tempQuaternion0=new Quaternion();},'_tempMatrix4x40',function(){return this._tempMatrix4x40=new Matrix4x4();},'_tempMatrix4x41',function(){return this._tempMatrix4x41=new Matrix4x4();}
- ]);
- return SubMeshStaticBatch;
- })(GeometryElement)
- /**
- *<code>TrailGeometry</code> 类用于创建拖尾渲染单元。
- */
- //class laya.d3.core.trail.TrailGeometry extends laya.d3.core.GeometryElement
- var TrailGeometry=(function(_super){
- function TrailGeometry(owner){
- /**@private */
- this._floatCountPerVertices1=8;
- /**@private */
- this._floatCountPerVertices2=1;
- /**@private */
- this._increaseSegementCount=128;
- /**@private */
- this._activeIndex=0;
- /**@private */
- this._endIndex=0;
- /**@private */
- this._needAddFirstVertex=false;
- /**@private */
- this._isTempEndVertex=false;
- /**@private */
- this._subBirthTime=null;
- /**@private */
- this._subDistance=null;
- /**@private */
- this._segementCount=0;
- /**@private */
- this._vertices1=null;
- /**@private */
- this._vertices2=null;
- /**@private */
- this._vertexBuffer1=null;
- /**@private */
- this._vertexBuffer2=null;
- /**@private */
- this._owner=null;
- TrailGeometry.__super.call(this);
- this._lastFixedVertexPosition=new Vector3();
- this._bufferState=new BufferState();
- this._owner=owner;;
- this._resizeData(this._increaseSegementCount,this._bufferState);
- }
- __class(TrailGeometry,'laya.d3.core.trail.TrailGeometry',_super);
- var __proto=TrailGeometry.prototype;
- /**
- *@private
- */
- __proto._resizeData=function(segementCount,bufferState){
- this._segementCount=this._increaseSegementCount;
- this._subBirthTime=new Float32Array(segementCount);
- this._subDistance=new Float32Array(segementCount);
- var vertexCount=segementCount *2;
- var vertexDeclaration1=VertexTrail.vertexDeclaration1;
- var vertexDeclaration2=VertexTrail.vertexDeclaration2;
- var vertexBuffers=[];
- var vertexbuffer1Size=vertexCount *vertexDeclaration1.vertexStride;
- var vertexbuffer2Size=vertexCount *vertexDeclaration2.vertexStride;
- var memorySize=vertexbuffer1Size+vertexbuffer2Size;
- this._vertices1=new Float32Array(vertexCount *this._floatCountPerVertices1);
- this._vertexBuffer1=new VertexBuffer3D(vertexbuffer1Size,/*laya.webgl.WebGLContext.STATIC_DRAW*/0x88E4,false);
- this._vertexBuffer1.vertexDeclaration=vertexDeclaration1;
- this._vertices2=new Float32Array(vertexCount *this._floatCountPerVertices2);
- this._vertexBuffer2=new VertexBuffer3D(vertexbuffer2Size,/*laya.webgl.WebGLContext.DYNAMIC_DRAW*/0x88E8,false);
- this._vertexBuffer2.vertexDeclaration=vertexDeclaration2;
- vertexBuffers.push(this._vertexBuffer1);
- vertexBuffers.push(this._vertexBuffer2);
- bufferState.bind();
- bufferState.applyVertexBuffers(vertexBuffers);
- bufferState.unBind();
- Resource._addMemory(memorySize,memorySize);
- }
- /**
- *@private
- */
- __proto._resetData=function(){
- var count=this._endIndex-this._activeIndex;
- if (count==this._segementCount){
- this._vertexBuffer1.destroy();
- this._vertexBuffer2.destroy();
- this._segementCount+=this._increaseSegementCount;
- this._resizeData(this._segementCount,this._bufferState);
- }
- this._vertexBuffer1.setData(this._vertices1,0,this._floatCountPerVertices1 *2 *this._activeIndex,this._floatCountPerVertices1 *2 *count);
- this._vertexBuffer2.setData(this._vertices2,0,this._floatCountPerVertices2 *2 *this._activeIndex,this._floatCountPerVertices2 *2 *count);
- var offset=this._activeIndex *4;
- var rightSubDistance=new Float32Array(this._subDistance.buffer,offset,count);
- var rightSubBirthTime=new Float32Array(this._subBirthTime.buffer,offset,count);
- this._subDistance.set(rightSubDistance,0);
- this._subBirthTime.set(rightSubBirthTime,0);
- this._endIndex=count;
- this._activeIndex=0;
- }
- /**
- *@private
- *更新Trail数据
- */
- __proto._updateTrail=function(camera,lastPosition,position){
- if (!Vector3.equals(lastPosition,position)){
- if ((this._endIndex-this._activeIndex)===0)
- this._addTrailByFirstPosition(camera,position);
- else
- this._addTrailByNextPosition(camera,position);
- }
- }
- /**
- *@private
- *通过起始位置添加TrailRenderElement起始数据
- */
- __proto._addTrailByFirstPosition=function(camera,position){
- (this._endIndex===this._segementCount)&& (this._resetData());
- this._subDistance[this._endIndex]=0;
- this._subBirthTime[this._endIndex]=this._owner._curtime;
- this._endIndex++;
- position.cloneTo(this._lastFixedVertexPosition);
- this._needAddFirstVertex=true;
- }
- /**
- *@private
- *通过位置更新TrailRenderElement数据
- */
- __proto._addTrailByNextPosition=function(camera,position){
- var delVector3=TrailGeometry._tempVector30;
- var pointAtoBVector3=TrailGeometry._tempVector31;
- Vector3.subtract(position,this._lastFixedVertexPosition,delVector3);
- var forward=TrailGeometry._tempVector32;
- switch (this._owner.alignment){
- case /*laya.d3.core.trail.TrailFilter.ALIGNMENT_VIEW*/0:
- camera.transform.getForward(forward);
- Vector3.cross(delVector3,forward,pointAtoBVector3);
- break ;
- case /*laya.d3.core.trail.TrailFilter.ALIGNMENT_TRANSFORM_Z*/1:
- this._owner._owner.transform.getForward(forward);
- Vector3.cross(delVector3,forward,pointAtoBVector3);
- break ;
- }
- Vector3.normalize(pointAtoBVector3,pointAtoBVector3);
- Vector3.scale(pointAtoBVector3,this._owner.widthMultiplier / 2,pointAtoBVector3);
- var delLength=Vector3.scalarLength(delVector3);
- var tempEndIndex=0;
- var offset=NaN;
- if (this._needAddFirstVertex){
- this._updateVerticesByPositionData(position,pointAtoBVector3,this._endIndex-1);
- this._needAddFirstVertex=false;
- }
- if (delLength-this._owner.minVertexDistance >=MathUtils3D.zeroTolerance){
- if (this._isTempEndVertex){
- tempEndIndex=this._endIndex-1;
- offset=delLength-this._subDistance[tempEndIndex];
- this._updateVerticesByPosition(position,pointAtoBVector3,delLength,tempEndIndex);
- this._owner._totalLength+=offset;
- }else {
- (this._endIndex===this._segementCount)&& (this._resetData());
- this._updateVerticesByPosition(position,pointAtoBVector3,delLength,this._endIndex);
- this._owner._totalLength+=delLength;
- this._endIndex++;
- }
- position.cloneTo(this._lastFixedVertexPosition);
- this._isTempEndVertex=false;
- }else {
- if (this._isTempEndVertex){
- tempEndIndex=this._endIndex-1;
- offset=delLength-this._subDistance[tempEndIndex];
- this._updateVerticesByPosition(position,pointAtoBVector3,delLength,tempEndIndex);
- this._owner._totalLength+=offset;
- }else {
- (this._endIndex===this._segementCount)&& (this._resetData());
- this._updateVerticesByPosition(position,pointAtoBVector3,delLength,this._endIndex);
- this._owner._totalLength+=delLength;
- this._endIndex++;
- }
- this._isTempEndVertex=true;
- }
- }
- /**
- *@private
- *通过位置更新顶点数据
- */
- __proto._updateVerticesByPositionData=function(position,pointAtoBVector3,index){
- var vertexOffset=this._floatCountPerVertices1 *2 *index;
- var curtime=this._owner._curtime;
- this._vertices1[vertexOffset]=position.x;
- this._vertices1[vertexOffset+1]=position.y;
- this._vertices1[vertexOffset+2]=position.z;
- this._vertices1[vertexOffset+3]=-pointAtoBVector3.x;
- this._vertices1[vertexOffset+4]=-pointAtoBVector3.y;
- this._vertices1[vertexOffset+5]=-pointAtoBVector3.z;
- this._vertices1[vertexOffset+6]=curtime;
- this._vertices1[vertexOffset+7]=1.0;
- this._vertices1[vertexOffset+8]=position.x;
- this._vertices1[vertexOffset+9]=position.y;
- this._vertices1[vertexOffset+10]=position.z;
- this._vertices1[vertexOffset+11]=pointAtoBVector3.x;
- this._vertices1[vertexOffset+12]=pointAtoBVector3.y;
- this._vertices1[vertexOffset+13]=pointAtoBVector3.z;
- this._vertices1[vertexOffset+14]=curtime;
- this._vertices1[vertexOffset+15]=0.0;
- var floatCount=this._floatCountPerVertices1 *2;
- this._vertexBuffer1.setData(this._vertices1,vertexOffset,vertexOffset,floatCount);
- }
- /**
- *@private
- *通过位置更新顶点数据、距离、出生时间
- */
- __proto._updateVerticesByPosition=function(position,pointAtoBVector3,delDistance,index){
- this._updateVerticesByPositionData(position,pointAtoBVector3,index);
- this._subDistance[index]=delDistance;
- this._subBirthTime[index]=this._owner._curtime;
- }
- /**
- *@private
- *更新VertexBuffer2数据
- */
- __proto._updateVertexBufferUV=function(){
- var vertexCount=this._endIndex;
- var curLength=0;
- for (var i=this._activeIndex,j=vertexCount;i < j;i++){
- (i!==this._activeIndex)&& (curLength+=this._subDistance[i]);
- var uvX=NaN;
- if (this._owner.textureMode==/*laya.d3.core.TextureMode.Stretch*/0)
- uvX=1.0-curLength / this._owner._totalLength;
- else
- uvX=1.0-(this._owner._totalLength-curLength);
- this._vertices2[i *2]=uvX;
- this._vertices2[i *2+1]=uvX;
- };
- var offset=this._activeIndex *2;
- this._vertexBuffer2.setData(this._vertices2,offset,offset,vertexCount *2-offset);
- }
- /**
- *@private
- */
- __proto._updateDisappear=function(){
- var count=this._endIndex;
- for (var i=this._activeIndex;i < count;i++){
- if (this._owner._curtime-this._subBirthTime[i] >=this._owner.time+MathUtils3D.zeroTolerance){
- var nextIndex=i+1;
- if (nextIndex!==count)
- this._owner._totalLength-=this._subDistance[nextIndex];
- if (this._isTempEndVertex && (nextIndex===count-1)){
- var offset=this._floatCountPerVertices1 *i *2;
- var fixedPos=this._lastFixedVertexPosition;
- fixedPos.x=this._vertices1[0];
- fixedPos.y=this._vertices1[1];
- fixedPos.z=this._vertices1[2];
- this._isTempEndVertex=false;
- }
- this._activeIndex++;
- }else {
- break ;
- }
- }
- }
- /**
- *@inheritDoc
- */
- __proto._getType=function(){
- return TrailGeometry._type;
- }
- /**
- *@inheritDoc
- */
- __proto._prepareRender=function(state){
- return this._endIndex-this._activeIndex > 1;
- }
- /**
- *@inheritDoc
- */
- __proto._render=function(state){
- this._bufferState.bind();
- var start=this._activeIndex *2;
- var count=this._endIndex *2-start;
- LayaGL.instance.drawArrays(/*laya.webgl.WebGLContext.TRIANGLE_STRIP*/0x0005,start,count);
- Stat.renderBatches++;
- Stat.trianglesFaces+=count-2;
- }
- /**
- *@inheritDoc
- */
- __proto.destroy=function(){
- _super.prototype.destroy.call(this);
- var memorySize=this._vertexBuffer1._byteLength+this._vertexBuffer2._byteLength;
- Resource._addMemory(-memorySize,-memorySize);
- this._bufferState.destroy();
- this._vertexBuffer1.destroy();
- this._vertexBuffer2.destroy();
- this._bufferState=null;
- this._vertices1=null;
- this._vertexBuffer1=null;
- this._vertices2=null;
- this._vertexBuffer2=null;
- this._subBirthTime=null;
- this._subDistance=null;
- this._lastFixedVertexPosition=null;
- }
- __static(TrailGeometry,
- ['_tempVector30',function(){return this._tempVector30=new Vector3();},'_tempVector31',function(){return this._tempVector31=new Vector3();},'_tempVector32',function(){return this._tempVector32=new Vector3();},'_type',function(){return this._type=GeometryElement._typeCounter++;}
- ]);
- return TrailGeometry;
- })(GeometryElement)
- /**
- *<code>CompoundColliderShape</code> 类用于创建盒子形状碰撞器。
- */
- //class laya.d3.physics.shape.CompoundColliderShape extends laya.d3.physics.shape.ColliderShape
- var CompoundColliderShape=(function(_super){
- function CompoundColliderShape(){
- CompoundColliderShape.__super.call(this);
- this._childColliderShapes=[];
- this._type=/*laya.d3.physics.shape.ColliderShape.SHAPETYPES_COMPOUND*/5;
- this._nativeShape=new Laya3D._physics3D.btCompoundShape();
- }
- __class(CompoundColliderShape,'laya.d3.physics.shape.CompoundColliderShape',_super);
- var __proto=CompoundColliderShape.prototype;
- /**
- *@private
- */
- __proto._clearChildShape=function(shape){
- shape._attatched=false;
- shape._compoundParent=null;
- shape._indexInCompound=-1;
- }
- /**
- *@inheritDoc
- */
- __proto._addReference=function(){}
- /**
- *@inheritDoc
- */
- __proto._removeReference=function(){}
- /**
- *@private
- */
- __proto._updateChildTransform=function(shape){
- var offset=shape.localOffset;
- var rotation=shape.localRotation;
- var nativeOffset=ColliderShape._nativeVector30;
- var nativeQuaternion=ColliderShape._nativQuaternion0;
- var nativeTransform=ColliderShape._nativeTransform0;
- nativeOffset.setValue(-offset.x,offset.y,offset.z);
- nativeQuaternion.setValue(-rotation.x,rotation.y,rotation.z,-rotation.w);
- nativeTransform.setOrigin(nativeOffset);
- nativeTransform.setRotation(nativeQuaternion);
- this._nativeShape.updateChildTransform(shape._indexInCompound,nativeTransform,true);
- }
- /**
- *添加子碰撞器形状。
- *@param shape 子碰撞器形状。
- */
- __proto.addChildShape=function(shape){
- if (shape._attatched)
- throw "CompoundColliderShape: this shape has attatched to other entity.";
- shape._attatched=true;
- shape._compoundParent=this;
- shape._indexInCompound=this._childColliderShapes.length;
- this._childColliderShapes.push(shape);
- var offset=shape.localOffset;
- var rotation=shape.localRotation;
- CompoundColliderShape._nativeOffset.setValue(-offset.x,offset.y,offset.z);
- CompoundColliderShape._nativRotation.setValue(-rotation.x,rotation.y,rotation.z,-rotation.w);
- CompoundColliderShape._nativeTransform.setOrigin(CompoundColliderShape._nativeOffset);
- CompoundColliderShape._nativeTransform.setRotation(CompoundColliderShape._nativRotation);
- var nativeScale=this._nativeShape.getLocalScaling();
- this._nativeShape.setLocalScaling(CompoundColliderShape._nativeVector3One);
- this._nativeShape.addChildShape(CompoundColliderShape._nativeTransform,shape._nativeShape);
- this._nativeShape.setLocalScaling(nativeScale);
- (this._attatchedCollisionObject)&& (this._attatchedCollisionObject.colliderShape=this);
- }
- /**
- *移除子碰撞器形状。
- *@param shape 子碰撞器形状。
- */
- __proto.removeChildShape=function(shape){
- if (shape._compoundParent===this){
- var index=shape._indexInCompound;
- this._clearChildShape(shape);
- var endShape=this._childColliderShapes[this._childColliderShapes.length-1];
- endShape._indexInCompound=index;
- this._childColliderShapes[index]=endShape;
- this._childColliderShapes.pop();
- this._nativeShape.removeChildShapeByIndex(index);
- }
- }
- /**
- *清空子碰撞器形状。
- */
- __proto.clearChildShape=function(){
- for (var i=0,n=this._childColliderShapes.length;i < n;i++){
- this._clearChildShape(this._childColliderShapes[i]);
- this._nativeShape.removeChildShapeByIndex(0);
- }
- this._childColliderShapes.length=0;
- }
- /**
- *获取子形状数量。
- *@return
- */
- __proto.getChildShapeCount=function(){
- return this._childColliderShapes.length;
- }
- /**
- *@inheritDoc
- */
- __proto.cloneTo=function(destObject){
- var destCompoundColliderShape=destObject;
- destCompoundColliderShape.clearChildShape();
- for (var i=0,n=this._childColliderShapes.length;i < n;i++)
- destCompoundColliderShape.addChildShape(this._childColliderShapes[i].clone());
- }
- /**
- *@inheritDoc
- */
- __proto.clone=function(){
- var dest=new CompoundColliderShape();
- this.cloneTo(dest);
- return dest;
- }
- /**
- *@inheritDoc
- */
- __proto.destroy=function(){
- _super.prototype.destroy.call(this);
- for (var i=0,n=this._childColliderShapes.length;i < n;i++){
- var childShape=this._childColliderShapes[i];
- if (childShape._referenceCount===0)
- childShape.destroy();
- }
- }
- __static(CompoundColliderShape,
- ['_nativeVector3One',function(){return this._nativeVector3One=new Laya3D._physics3D.btVector3(1,1,1);},'_nativeTransform',function(){return this._nativeTransform=new Laya3D._physics3D.btTransform();},'_nativeOffset',function(){return this._nativeOffset=new Laya3D._physics3D.btVector3(0,0,0);},'_nativRotation',function(){return this._nativRotation=new Laya3D._physics3D.btQuaternion(0,0,0,1);}
- ]);
- return CompoundColliderShape;
- })(ColliderShape)
- /**
- *<code>PixelLineFilter</code> 类用于线过滤器。
- */
- //class laya.d3.core.pixelLine.PixelLineFilter extends laya.d3.core.GeometryElement
- var PixelLineFilter=(function(_super){
- function PixelLineFilter(owner,maxLineCount){
- /**@private */
- this._floatCountPerVertices=7;
- /**@private */
- this._owner=null;
- /**@private */
- this._vertexBuffer=null;
- /**@private */
- this._vertices=null;
- /**@private */
- this._maxLineCount=0;
- /**@private */
- this._lineCount=0;
- PixelLineFilter.__super.call(this);
- this._minUpdate=Number.MAX_VALUE;
- this._maxUpdate=Number.MIN_VALUE;
- this._bufferState=new BufferState();
- var pointCount=maxLineCount *2;
- this._owner=owner;
- this._maxLineCount=maxLineCount;
- this._vertices=new Float32Array(pointCount *this._floatCountPerVertices);
- this._vertexBuffer=new VertexBuffer3D(PixelLineVertex.vertexDeclaration.vertexStride *pointCount,/*laya.webgl.WebGLContext.STATIC_DRAW*/0x88E4,false);
- this._vertexBuffer.vertexDeclaration=PixelLineVertex.vertexDeclaration;
- this._bufferState.bind();
- this._bufferState.applyVertexBuffer(this._vertexBuffer);
- this._bufferState.unBind();
- }
- __class(PixelLineFilter,'laya.d3.core.pixelLine.PixelLineFilter',_super);
- var __proto=PixelLineFilter.prototype;
- /**
- *@inheritDoc
- */
- __proto._getType=function(){
- return PixelLineFilter._type;
- }
- /**
- *@private
- */
- __proto._resizeLineData=function(maxCount){
- var pointCount=maxCount *2;
- var lastVertices=this._vertices;
- this._vertexBuffer.destroy();
- this._maxLineCount=maxCount;
- var vertexCount=pointCount *this._floatCountPerVertices;
- this._vertices=new Float32Array(vertexCount);
- this._vertexBuffer=new VertexBuffer3D(PixelLineVertex.vertexDeclaration.vertexStride *pointCount,/*laya.webgl.WebGLContext.STATIC_DRAW*/0x88E4,false);
- this._vertexBuffer.vertexDeclaration=PixelLineVertex.vertexDeclaration;
- if (vertexCount < lastVertices.length){
- this._vertices.set(new Float32Array(lastVertices.buffer,0,vertexCount));
- this._vertexBuffer.setData(this._vertices,0,0,vertexCount);
- }else {
- this._vertices.set(lastVertices);
- this._vertexBuffer.setData(this._vertices,0,0,lastVertices.length);
- }
- this._bufferState.bind();
- this._bufferState.applyVertexBuffer(this._vertexBuffer);
- this._bufferState.unBind();
- }
- /**
- *@private
- */
- __proto._updateLineVertices=function(offset,startPosition,endPosition,startColor,endColor){
- if (startPosition){
- this._vertices[offset+0]=startPosition.x;
- this._vertices[offset+1]=startPosition.y;
- this._vertices[offset+2]=startPosition.z;
- }
- if (startColor){
- this._vertices[offset+3]=startColor.r;
- this._vertices[offset+4]=startColor.g;
- this._vertices[offset+5]=startColor.b;
- this._vertices[offset+6]=startColor.a;
- }
- if (endPosition){
- this._vertices[offset+7]=endPosition.x;
- this._vertices[offset+8]=endPosition.y;
- this._vertices[offset+9]=endPosition.z;
- }
- if (endColor){
- this._vertices[offset+10]=endColor.r;
- this._vertices[offset+11]=endColor.g;
- this._vertices[offset+12]=endColor.b;
- this._vertices[offset+13]=endColor.a;
- }
- this._minUpdate=Math.min(this._minUpdate,offset);
- this._maxUpdate=Math.max(this._maxUpdate,offset+this._floatCountPerVertices *2);
- }
- /**
- *@private
- */
- __proto._removeLineData=function(index){
- var floatCount=this._floatCountPerVertices *2;
- var nextIndex=index+1;
- var offset=index *floatCount;
- var nextOffset=nextIndex *floatCount;
- var rightPartVertices=new Float32Array(this._vertices.buffer,nextIndex *floatCount *4,(this._lineCount-nextIndex)*floatCount);
- this._vertices.set(rightPartVertices,offset);
- this._minUpdate=offset;
- this._maxUpdate=offset+this._floatCountPerVertices *2;
- this._lineCount--;
- }
- /**
- *@private
- */
- __proto._updateLineData=function(index,startPosition,endPosition,startColor,endColor){
- var floatCount=this._floatCountPerVertices *2;
- var offset=index *floatCount;
- this._updateLineVertices(offset,startPosition,endPosition,startColor,endColor);
- }
- /**
- *@private
- */
- __proto._updateLineDatas=function(index,data){
- var floatCount=this._floatCountPerVertices *2;
- var offset=index *floatCount;
- var count=data.length;
- for (var i=0;i < count;i++){
- var line=data[i];
- this._updateLineVertices((index+i)*floatCount,line.startPosition,line.endPosition,line.startColor,line.endColor);
- }
- }
- /**
- *获取线段数据
- *@return 线段数据。
- */
- __proto._getLineData=function(index,out){
- var startPosition=out.startPosition;
- var startColor=out.startColor;
- var endPosition=out.endPosition;
- var endColor=out.endColor;
- var vertices=this._vertices;
- var offset=index *this._floatCountPerVertices *2;
- startPosition.x=vertices[offset+0];
- startPosition.y=vertices[offset+1];
- startPosition.z=vertices[offset+2];
- startColor.r=vertices[offset+3];
- startColor.g=vertices[offset+4];
- startColor.b=vertices[offset+5];
- startColor.a=vertices[offset+6];
- endPosition.x=vertices[offset+7];
- endPosition.y=vertices[offset+8];
- endPosition.z=vertices[offset+9];
- endColor.r=vertices[offset+10];
- endColor.g=vertices[offset+11];
- endColor.b=vertices[offset+12];
- endColor.a=vertices[offset+13];
- }
- /**
- *@inheritDoc
- */
- __proto._prepareRender=function(state){
- return true;
- }
- /**
- *@inheritDoc
- */
- __proto._render=function(state){
- if (this._minUpdate!==Number.MAX_VALUE && this._maxUpdate!==Number.MIN_VALUE){
- this._vertexBuffer.setData(this._vertices,this._minUpdate,this._minUpdate,this._maxUpdate-this._minUpdate);
- this._minUpdate=Number.MAX_VALUE;
- this._maxUpdate=Number.MIN_VALUE;
- }
- if (this._lineCount > 0){
- this._bufferState.bind();
- LayaGL.instance.drawArrays(/*laya.webgl.WebGLContext.LINES*/0x0001,0,this._lineCount *2);
- Stat.renderBatches++;
- }
- }
- /**
- *@inheritDoc
- */
- __proto.destroy=function(){
- if (this._destroyed)
- return;
- _super.prototype.destroy.call(this);
- this._bufferState.destroy();
- this._vertexBuffer.destroy();
- this._bufferState=null;
- this._vertexBuffer=null;
- this._vertices=null;
- }
- __static(PixelLineFilter,
- ['_type',function(){return this._type=GeometryElement._typeCounter++;}
- ]);
- return PixelLineFilter;
- })(GeometryElement)
- /**
- *<code>CylinderColliderShape</code> 类用于创建圆柱碰撞器。
- */
- //class laya.d3.physics.shape.CylinderColliderShape extends laya.d3.physics.shape.ColliderShape
- var CylinderColliderShape=(function(_super){
- function CylinderColliderShape(radius,height,orientation){
- /**@private */
- //this._orientation=0;
- /**@private */
- this._radius=1;
- /**@private */
- this._height=0.5;
- CylinderColliderShape.__super.call(this);
- (radius===void 0)&& (radius=0.5);
- (height===void 0)&& (height=1.0);
- (orientation===void 0)&& (orientation=/*laya.d3.physics.shape.ColliderShape.SHAPEORIENTATION_UPY*/1);
- this._radius=radius;
- this._height=height;
- this._orientation=orientation;
- this._type=/*laya.d3.physics.shape.ColliderShape.SHAPETYPES_CYLINDER*/2;
- switch (orientation){
- case /*laya.d3.physics.shape.ColliderShape.SHAPEORIENTATION_UPX*/0:
- CylinderColliderShape._nativeSize.setValue(height / 2,radius,radius);
- this._nativeShape=new Laya3D._physics3D.btCylinderShapeX(CylinderColliderShape._nativeSize);
- break ;
- case /*laya.d3.physics.shape.ColliderShape.SHAPEORIENTATION_UPY*/1:
- CylinderColliderShape._nativeSize.setValue(radius,height / 2,radius);
- this._nativeShape=new Laya3D._physics3D.btCylinderShape(CylinderColliderShape._nativeSize);
- break ;
- case /*laya.d3.physics.shape.ColliderShape.SHAPEORIENTATION_UPZ*/2:
- CylinderColliderShape._nativeSize.setValue(radius,radius,height / 2);
- this._nativeShape=new Laya3D._physics3D.btCylinderShapeZ(CylinderColliderShape._nativeSize);
- break ;
- default :
- throw "CapsuleColliderShape:unknown orientation.";
- }
- }
- __class(CylinderColliderShape,'laya.d3.physics.shape.CylinderColliderShape',_super);
- var __proto=CylinderColliderShape.prototype;
- /**
- *@inheritDoc
- */
- __proto.clone=function(){
- var dest=new CylinderColliderShape(this._radius,this._height,this._orientation);
- this.cloneTo(dest);
- return dest;
- }
- /**
- *获取半径。
- */
- __getset(0,__proto,'radius',function(){
- return this._radius;
- });
- /**
- *获取高度。
- */
- __getset(0,__proto,'height',function(){
- return this._height;
- });
- /**
- *获取方向。
- */
- __getset(0,__proto,'orientation',function(){
- return this._orientation;
- });
- __static(CylinderColliderShape,
- ['_nativeSize',function(){return this._nativeSize=new Laya3D._physics3D.btVector3(0,0,0);}
- ]);
- return CylinderColliderShape;
- })(ColliderShape)
- /**
- *<code>FloatKeyFrame</code> 类用于创建浮点关键帧实例。
- */
- //class laya.d3.core.FloatKeyframe extends laya.d3.core.Keyframe
- var FloatKeyframe=(function(_super){
- function FloatKeyframe(){
- //this.inTangent=NaN;
- //this.outTangent=NaN;
- //this.value=NaN;
- FloatKeyframe.__super.call(this);
- }
- __class(FloatKeyframe,'laya.d3.core.FloatKeyframe',_super);
- var __proto=FloatKeyframe.prototype;
- /**
- *@inheritDoc
- */
- __proto.cloneTo=function(destObject){
- _super.prototype.cloneTo.call(this,destObject);
- var destKeyFrame=destObject;
- destKeyFrame.inTangent=this.inTangent;
- destKeyFrame.outTangent=this.outTangent;
- destKeyFrame.value=this.value;
- }
- return FloatKeyframe;
- })(Keyframe)
- /**
- *@private
- */
- //class laya.d3.graphics.SubMeshInstanceBatch extends laya.d3.core.GeometryElement
- var SubMeshInstanceBatch=(function(_super){
- function SubMeshInstanceBatch(){
- /**@private */
- this.maxInstanceCount=1024;
- SubMeshInstanceBatch.__super.call(this);
- this.instanceWorldMatrixData=new Float32Array(this.maxInstanceCount *16);
- this.instanceMVPMatrixData=new Float32Array(this.maxInstanceCount *16);
- this.instanceWorldMatrixBuffer=new VertexBuffer3D(this.instanceWorldMatrixData.length *4,/*laya.webgl.WebGLContext.DYNAMIC_DRAW*/0x88E8);
- this.instanceMVPMatrixBuffer=new VertexBuffer3D(this.instanceMVPMatrixData.length *4,/*laya.webgl.WebGLContext.DYNAMIC_DRAW*/0x88E8);
- this.instanceWorldMatrixBuffer.vertexDeclaration=VertexMesh.instanceWorldMatrixDeclaration;
- this.instanceMVPMatrixBuffer.vertexDeclaration=VertexMesh.instanceMVPMatrixDeclaration;
- }
- __class(SubMeshInstanceBatch,'laya.d3.graphics.SubMeshInstanceBatch',_super);
- var __proto=SubMeshInstanceBatch.prototype;
- /**
- *@inheritDoc
- */
- __proto._render=function(state){
- var element=state.renderElement;
- var subMesh=element.instanceSubMesh;
- var count=element.instanceBatchElementList.length;
- var indexCount=subMesh._indexCount;
- subMesh._mesh._instanceBufferState.bind();
- WebGLContext._angleInstancedArrays.drawElementsInstancedANGLE(/*laya.webgl.WebGLContext.TRIANGLES*/0x0004,indexCount,/*laya.webgl.WebGLContext.UNSIGNED_SHORT*/0x1403,subMesh._indexStart *2,count);
- Stat.renderBatches++;
- Stat.savedRenderBatches+=count-1;
- Stat.trianglesFaces+=indexCount *count / 3;
- }
- __static(SubMeshInstanceBatch,
- ['instance',function(){return this.instance=new SubMeshInstanceBatch();}
- ]);
- return SubMeshInstanceBatch;
- })(GeometryElement)
- /**
- *<code>OctreeMotionList</code> 类用于实现物理更新队列。
- */
- //class laya.d3.core.scene.OctreeMotionList extends laya.d3.component.SingletonList
- var OctreeMotionList=(function(_super){
- /**
- *创建一个新的 <code>OctreeMotionList</code> 实例。
- */
- function OctreeMotionList(){
- OctreeMotionList.__super.call(this);
- }
- __class(OctreeMotionList,'laya.d3.core.scene.OctreeMotionList',_super);
- var __proto=OctreeMotionList.prototype;
- /**
- *@private
- */
- __proto.add=function(element){
- var index=element._getIndexInMotionList();
- if (index!==-1)
- throw "OctreeMotionList:element has in PhysicsUpdateList.";
- this._add(element);
- element._setIndexInMotionList(this.length++);
- }
- /**
- *@private
- */
- __proto.remove=function(element){
- var index=element._getIndexInMotionList();
- this.length--;
- if (index!==this.length){
- var end=this.elements[this.length];
- this.elements[index]=end;
- end._inPhysicUpdateListIndex=index;
- }
- element._setIndexInMotionList(-1);
- }
- return OctreeMotionList;
- })(SingletonList)
- /**
- *@private
- *<code>SetRenderTargetCMD</code> 类用于创建设置渲染目标指令。
- */
- //class laya.d3.core.render.command.SetRenderTargetCMD extends laya.d3.core.render.command.Command
- var SetRenderTargetCMD=(function(_super){
- function SetRenderTargetCMD(){
- /**@private */
- this._renderTexture=null;
- SetRenderTargetCMD.__super.call(this);
- }
- __class(SetRenderTargetCMD,'laya.d3.core.render.command.SetRenderTargetCMD',_super);
- var __proto=SetRenderTargetCMD.prototype;
- /**
- *@inheritDoc
- */
- __proto.run=function(){
- this._renderTexture._start();
- }
- /**
- *@inheritDoc
- */
- __proto.recover=function(){
- SetRenderTargetCMD._pool.push(this);
- this._renderTexture=null;
- }
- SetRenderTargetCMD.create=function(renderTexture){
- var cmd;
- cmd=SetRenderTargetCMD._pool.length > 0 ? SetRenderTargetCMD._pool.pop():new SetRenderTargetCMD();
- cmd._renderTexture=renderTexture;
- return cmd;
- }
- SetRenderTargetCMD._pool=[];
- return SetRenderTargetCMD;
- })(Command)
- /**
- *@private
- *<code>MeshSprite3DStaticBatchManager</code> 类用于网格精灵静态批处理管理。
- */
- //class laya.d3.graphics.MeshRenderStaticBatchManager extends laya.d3.graphics.StaticBatchManager
- var MeshRenderStaticBatchManager=(function(_super){
- function MeshRenderStaticBatchManager(){
- /**@private [只读]*/
- //this._updateCountMark=0;
- this._opaqueBatchMarks=[];
- MeshRenderStaticBatchManager.__super.call(this);
- this._updateCountMark=0;
- }
- __class(MeshRenderStaticBatchManager,'laya.d3.graphics.MeshRenderStaticBatchManager',_super);
- var __proto=MeshRenderStaticBatchManager.prototype;
- /**
- *@inheritDoc
- */
- __proto._compare=function(left,right){
- var lRender=left._render,rRender=right._render;
- var leftGeo=(left).meshFilter.sharedMesh,rightGeo=(right).meshFilter.sharedMesh;
- var lightOffset=lRender.lightmapIndex-rRender.lightmapIndex;
- if (lightOffset===0){
- var receiveShadowOffset=(lRender.receiveShadow ? 1 :0)-(rRender.receiveShadow ? 1 :0);
- if (receiveShadowOffset===0){
- var materialOffset=lRender.sharedMaterial.id-rRender.sharedMaterial.id;
- if (materialOffset===0){
- var verDec=leftGeo._vertexBuffers[0].vertexDeclaration.id-rightGeo._vertexBuffers[0].vertexDeclaration.id;
- if (verDec===0){
- return rightGeo._indexBuffer.indexCount-leftGeo._indexBuffer.indexCount;
- }else {
- return verDec;
- }
- }else {
- return materialOffset;
- }
- }else {
- return receiveShadowOffset;
- }
- }else {
- return lightOffset;
- }
- }
- /**
- *@inheritDoc
- */
- __proto._getBatchRenderElementFromPool=function(){
- var renderElement=this._batchRenderElementPool[this._batchRenderElementPoolIndex++];
- if (!renderElement){
- renderElement=new SubMeshRenderElement();
- this._batchRenderElementPool[this._batchRenderElementPoolIndex-1]=renderElement;
- renderElement.staticBatchElementList=[];
- }
- return renderElement;
- }
- /**
- *@private
- */
- __proto._getStaticBatch=function(rootOwner,number){
- var key=rootOwner ? rootOwner.id :0;
- var batchOwner=this._staticBatches[key];
- (batchOwner)|| (batchOwner=this._staticBatches[key]=[]);
- return (batchOwner[number])|| (batchOwner[number]=new SubMeshStaticBatch(rootOwner,number,MeshRenderStaticBatchManager._verDec));
- }
- /**
- *@inheritDoc
- */
- __proto._initStaticBatchs=function(rootOwner){
- this._quickSort(this._initBatchSprites,0,this._initBatchSprites.length-1);
- var lastCanMerage=false;
- var curStaticBatch;
- var batchNumber=0;
- for (var i=0,n=this._initBatchSprites.length;i < n;i++){
- var sprite=this._initBatchSprites[i];
- if (lastCanMerage){
- if (curStaticBatch.addTest(sprite)){
- curStaticBatch.add(sprite);
- }else {
- lastCanMerage=false;
- batchNumber++;
- }
- }else {
- var lastIndex=n-1;
- if (i!==lastIndex){
- curStaticBatch=this._getStaticBatch(rootOwner,batchNumber);
- curStaticBatch.add(sprite);
- lastCanMerage=true;
- }
- }
- }
- for (var key in this._staticBatches){
- var batches=this._staticBatches[key];
- for (i=0,n=batches.length;i < n;i++)
- batches[i].finishInit();
- }
- this._initBatchSprites.length=0;
- }
- /**
- *@private
- */
- __proto._destroyRenderSprite=function(sprite){
- var staticBatch=sprite._render._staticBatch;
- staticBatch.remove(sprite);
- if (staticBatch._batchElements.length===0){
- var owner=staticBatch.batchOwner;
- var ownerID=owner ? owner.id :0;
- var batches=this._staticBatches[ownerID];
- batches[staticBatch.number]=null;
- staticBatch.dispose();
- var empty=true;
- for (var i=0;i < batches.length;i++){
- if (batches[i])
- empty=false;
- }
- if (empty){
- delete this._staticBatches[ownerID];
- }
- }
- }
- /**
- *@inheritDoc
- */
- __proto._clear=function(){
- _super.prototype._clear.call(this);
- this._updateCountMark++;
- }
- /**
- *@inheritDoc
- */
- __proto._garbageCollection=function(){
- for (var key in this._staticBatches){
- var batches=this._staticBatches[key];
- for (var i=0,n=batches.length;i < n;i++){
- var staticBatch=batches[i];
- if (staticBatch._batchElements.length===0){
- staticBatch.dispose();
- batches.splice(i,1);
- i--,n--;
- if (n===0)
- delete this._staticBatches[key];
- }
- }
- }
- }
- /**
- *@private
- */
- __proto.getBatchOpaquaMark=function(lightMapIndex,receiveShadow,materialID,staticBatchID){
- var staLightMapMarks=(this._opaqueBatchMarks[lightMapIndex])|| (this._opaqueBatchMarks[lightMapIndex]=[]);
- var staReceiveShadowMarks=(staLightMapMarks[receiveShadow])|| (staLightMapMarks[receiveShadow]=[]);
- var staMaterialMarks=(staReceiveShadowMarks[materialID])|| (staReceiveShadowMarks[materialID]=[]);
- return (staMaterialMarks[staticBatchID])|| (staMaterialMarks[staticBatchID]=new BatchMark);
- }
- __static(MeshRenderStaticBatchManager,
- ['_verDec',function(){return this._verDec=VertexMesh.getVertexDeclaration("POSITION,NORMAL,COLOR,UV,UV1,TANGENT");},'instance',function(){return this.instance=new MeshRenderStaticBatchManager();}
- ]);
- return MeshRenderStaticBatchManager;
- })(StaticBatchManager)
- /**
- *@private
- *<code>SubMeshDynamicBatch</code> 类用于网格动态合并。
- */
- //class laya.d3.graphics.SubMeshDynamicBatch extends laya.d3.core.GeometryElement
- var SubMeshDynamicBatch=(function(_super){
- function SubMeshDynamicBatch(){
- /**@private */
- this._vertices=null;
- /**@private */
- this._indices=null;
- /**@private */
- this._positionOffset=0;
- /**@private */
- this._normalOffset=0;
- /**@private */
- this._colorOffset=0;
- /**@private */
- this._uv0Offset=0;
- /**@private */
- this._uv1Offset=0;
- /**@private */
- this._sTangentOffset=0;
- /**@private */
- this._vertexBuffer=null;
- /**@private */
- this._indexBuffer=null;
- SubMeshDynamicBatch.__super.call(this);
- this._bufferState=new BufferState();
- var maxVerDec=VertexMesh.getVertexDeclaration("POSITION,NORMAL,COLOR,UV,UV1,TANGENT");
- var maxByteCount=maxVerDec.vertexStride *32000;
- this._vertices=new Float32Array(maxByteCount / 4);
- this._vertexBuffer=new VertexBuffer3D(maxByteCount,/*laya.webgl.WebGLContext.DYNAMIC_DRAW*/0x88E8);
- this._indices=new Int16Array(/*CLASS CONST:laya.d3.graphics.SubMeshDynamicBatch.maxIndicesCount*/32000);
- this._indexBuffer=new IndexBuffer3D(/*laya.d3.graphics.IndexBuffer3D.INDEXTYPE_USHORT*/"ushort",this._indices.length,/*laya.webgl.WebGLContext.DYNAMIC_DRAW*/0x88E8);
- var memorySize=this._vertexBuffer._byteLength+this._indexBuffer._byteLength;
- Resource._addMemory(memorySize,memorySize);
- }
- __class(SubMeshDynamicBatch,'laya.d3.graphics.SubMeshDynamicBatch',_super);
- var __proto=SubMeshDynamicBatch.prototype;
- /**
- *@private
- */
- __proto._getBatchVertices=function(vertexDeclaration,batchVertices,batchOffset,transform,element,subMesh){
- var vertexFloatCount=vertexDeclaration.vertexStride / 4;
- var oriVertexes=subMesh._vertexBuffer.getData();
- var lightmapScaleOffset=element.render.lightmapScaleOffset;
- var multiSubMesh=element._dynamicMultiSubMesh;
- var vertexCount=element._dynamicVertexCount;
- element._computeWorldPositionsAndNormals(this._positionOffset,this._normalOffset,multiSubMesh,vertexCount);
- var worldPositions=element._dynamicWorldPositions;
- var worldNormals=element._dynamicWorldNormals;
- var indices=subMesh._indices;
- for (var i=0;i < vertexCount;i++){
- var index=multiSubMesh ? indices[i] :i;
- var oriOffset=index *vertexFloatCount;
- var bakeOffset=(i+batchOffset)*vertexFloatCount;
- var oriOff=i *3;
- var bakOff=bakeOffset+this._positionOffset;
- batchVertices[bakOff]=worldPositions[oriOff];
- batchVertices[bakOff+1]=worldPositions[oriOff+1];
- batchVertices[bakOff+2]=worldPositions[oriOff+2];
- if (this._normalOffset!==-1){
- bakOff=bakeOffset+this._normalOffset;
- batchVertices[bakOff]=worldNormals[oriOff];
- batchVertices[bakOff+1]=worldNormals[oriOff+1];
- batchVertices[bakOff+2]=worldNormals[oriOff+2];
- }
- if (this._colorOffset!==-1){
- bakOff=bakeOffset+this._colorOffset;
- oriOff=oriOffset+this._colorOffset;
- batchVertices[bakOff]=oriVertexes[oriOff];
- batchVertices[bakOff+1]=oriVertexes[oriOff+1];
- batchVertices[bakOff+2]=oriVertexes[oriOff+2];
- batchVertices[bakOff+3]=oriVertexes[oriOff+3];
- }
- if (this._uv0Offset!==-1){
- bakOff=bakeOffset+this._uv0Offset;
- oriOff=oriOffset+this._uv0Offset;
- batchVertices[bakOff]=oriVertexes[oriOff];
- batchVertices[bakOff+1]=oriVertexes[oriOff+1];
- }
- if (this._sTangentOffset!==-1){
- bakOff=bakeOffset+this._sTangentOffset;
- oriOff=oriOffset+this._sTangentOffset;
- batchVertices[bakOff]=oriVertexes[oriOff];
- batchVertices[bakOff+1]=oriVertexes[oriOff+1];
- batchVertices[bakOff+2]=oriVertexes[oriOff+2];
- batchVertices[bakOff+3]=oriVertexes[oriOff+3];
- bakOff=bakeOffset+this._sTangentOffset;
- oriOff=oriOffset+this._sTangentOffset;
- batchVertices[bakOff]=oriVertexes[oriOff];
- batchVertices[bakOff+1]=oriVertexes[oriOff+1];
- batchVertices[bakOff+2]=oriVertexes[oriOff+2];
- batchVertices[bakOff+3]=oriVertexes[oriOff+3];
- }
- }
- }
- /**
- *@private
- */
- __proto._getBatchIndices=function(batchIndices,batchIndexCount,batchVertexCount,transform,subMesh,multiSubMesh){
- var subIndices=subMesh._indices;
- var k=0,m=0,batchOffset=0;
- var isInvert=transform._isFrontFaceInvert;
- if (multiSubMesh){
- if (isInvert){
- for (k=0,m=subIndices.length;k < m;k+=3){
- batchOffset=batchIndexCount+k;
- var index=batchVertexCount+k;
- batchIndices[batchOffset]=index;
- batchIndices[batchOffset+1]=index+2;
- batchIndices[batchOffset+2]=index+1;
- }
- }else {
- for (k=m,m=subIndices.length;k < m;k+=3){
- batchOffset=batchIndexCount+k;
- index=batchVertexCount+k;
- batchIndices[batchOffset]=index;
- batchIndices[batchOffset+1]=index+1;
- batchIndices[batchOffset+2]=index+2;
- }
- }
- }else {
- if (isInvert){
- for (k=0,m=subIndices.length;k < m;k+=3){
- batchOffset=batchIndexCount+k;
- batchIndices[batchOffset]=batchVertexCount+subIndices[k];
- batchIndices[batchOffset+1]=batchVertexCount+subIndices[k+2];
- batchIndices[batchOffset+2]=batchVertexCount+subIndices[k+1];
- }
- }else {
- for (k=m,m=subIndices.length;k < m;k+=3){
- batchOffset=batchIndexCount+k;
- batchIndices[batchOffset]=batchVertexCount+subIndices[k];
- batchIndices[batchOffset+1]=batchVertexCount+subIndices[k+1];
- batchIndices[batchOffset+2]=batchVertexCount+subIndices[k+2];
- }
- }
- }
- }
- /**
- *@private
- */
- __proto._flush=function(vertexCount,indexCount){
- this._vertexBuffer.setData(this._vertices,0,0,vertexCount *(this._vertexBuffer.vertexDeclaration.vertexStride / 4));
- this._indexBuffer.setData(this._indices,0,0,indexCount);
- LayaGL.instance.drawElements(/*laya.webgl.WebGLContext.TRIANGLES*/0x0004,indexCount,/*laya.webgl.WebGLContext.UNSIGNED_SHORT*/0x1403,0);
- }
- /**
- *@inheritDoc
- */
- __proto._prepareRender=function(state){
- var element=state.renderElement;
- var vertexDeclaration=element.vertexBatchVertexDeclaration;
- this._bufferState=MeshRenderDynamicBatchManager.instance._getBufferState(vertexDeclaration);
- this._positionOffset=vertexDeclaration.getVertexElementByUsage(/*laya.d3.graphics.Vertex.VertexMesh.MESH_POSITION0*/0).offset / 4;
- var normalElement=vertexDeclaration.getVertexElementByUsage(/*laya.d3.graphics.Vertex.VertexMesh.MESH_NORMAL0*/3);
- this._normalOffset=normalElement ? normalElement.offset / 4 :-1;
- var colorElement=vertexDeclaration.getVertexElementByUsage(/*laya.d3.graphics.Vertex.VertexMesh.MESH_COLOR0*/1);
- this._colorOffset=colorElement ? colorElement.offset / 4 :-1;
- var uv0Element=vertexDeclaration.getVertexElementByUsage(/*laya.d3.graphics.Vertex.VertexMesh.MESH_TEXTURECOORDINATE0*/2);
- this._uv0Offset=uv0Element ? uv0Element.offset / 4 :-1;
- var uv1Element=vertexDeclaration.getVertexElementByUsage(/*laya.d3.graphics.Vertex.VertexMesh.MESH_TEXTURECOORDINATE1*/7);
- this._uv1Offset=uv1Element ? uv1Element.offset / 4 :-1;
- var tangentElement=vertexDeclaration.getVertexElementByUsage(/*laya.d3.graphics.Vertex.VertexMesh.MESH_TANGENT0*/4);
- this._sTangentOffset=tangentElement ? tangentElement.offset / 4 :-1;
- return true;
- }
- /**
- *@inheritDoc
- */
- __proto._render=function(context){
- this._bufferState.bind();
- var element=context.renderElement;
- var vertexDeclaration=element.vertexBatchVertexDeclaration;
- var batchElements=element.vertexBatchElementList;
- var batchVertexCount=0;
- var batchIndexCount=0;
- var floatStride=vertexDeclaration.vertexStride / 4;
- var renderBatchCount=0;
- var elementCount=batchElements.length;
- for (var i=0;i < elementCount;i++){
- var subElement=batchElements [i];
- var subMesh=subElement._geometry;
- var indexCount=subMesh._indexCount;
- if (batchIndexCount+indexCount > /*CLASS CONST:laya.d3.graphics.SubMeshDynamicBatch.maxIndicesCount*/32000){
- this._flush(batchVertexCount,batchIndexCount);
- renderBatchCount++;
- Stat.trianglesFaces+=batchIndexCount / 3;
- batchVertexCount=batchIndexCount=0;
- };
- var transform=subElement._transform;
- this._getBatchVertices(vertexDeclaration,this._vertices,batchVertexCount,transform,subElement,subMesh);
- this._getBatchIndices(this._indices,batchIndexCount,batchVertexCount,transform,subMesh,subElement._dynamicMultiSubMesh);
- batchVertexCount+=subElement._dynamicVertexCount;
- batchIndexCount+=indexCount;
- }
- this._flush(batchVertexCount,batchIndexCount);
- renderBatchCount++;
- Stat.renderBatches+=renderBatchCount;
- Stat.savedRenderBatches+=elementCount-renderBatchCount;
- Stat.trianglesFaces+=batchIndexCount / 3;
- }
- SubMeshDynamicBatch.maxAllowVertexCount=10;
- SubMeshDynamicBatch.maxAllowAttribueCount=900;
- SubMeshDynamicBatch.maxIndicesCount=32000;
- SubMeshDynamicBatch.instance=null;
- return SubMeshDynamicBatch;
- })(GeometryElement)
- /**
- *<code>SkyBox</code> 类用于创建天空盒。
- */
- //class laya.d3.resource.models.SkyBox extends laya.d3.resource.models.SkyMesh
- var SkyBox=(function(_super){
- /**
- *创建一个 <code>SkyBox</code> 实例。
- */
- function SkyBox(){
- SkyBox.__super.call(this);
- var halfHeight=0.5;
- var halfWidth=0.5;
- var halfDepth=0.5;
- var vertices=new Float32Array([-halfDepth,halfHeight,-halfWidth,halfDepth,halfHeight,-halfWidth,halfDepth,halfHeight,halfWidth,-halfDepth,halfHeight,halfWidth,
- -halfDepth,-halfHeight,-halfWidth,halfDepth,-halfHeight,-halfWidth,halfDepth,-halfHeight,halfWidth,-halfDepth,-halfHeight,halfWidth]);
- var indices=new Uint8Array([0,1,2,2,3,0,
- 4,7,6,6,5,4,
- 0,3,7,7,4,0,
- 1,5,6,6,2,1,
- 3,2,6,6,7,3,
- 0,4,5,5,1,0]);
- var verDec=VertexMesh.getVertexDeclaration("POSITION");
- this._vertexBuffer=new VertexBuffer3D(verDec.vertexStride *8,/*laya.webgl.WebGLContext.STATIC_DRAW*/0x88E4,false);
- this._vertexBuffer.vertexDeclaration=verDec;
- this._indexBuffer=new IndexBuffer3D(/*laya.d3.graphics.IndexBuffer3D.INDEXTYPE_UBYTE*/"ubyte",36,/*laya.webgl.WebGLContext.STATIC_DRAW*/0x88E4,false);
- this._vertexBuffer.setData(vertices);
- this._indexBuffer.setData(indices);
- var bufferState=new BufferState();
- bufferState.bind();
- bufferState.applyVertexBuffer(this._vertexBuffer);
- bufferState.applyIndexBuffer(this._indexBuffer);
- bufferState.unBind();
- this._bufferState=bufferState;
- }
- __class(SkyBox,'laya.d3.resource.models.SkyBox',_super);
- var __proto=SkyBox.prototype;
- /**
- *@inheritDoc
- */
- __proto._render=function(state){
- LayaGL.instance.drawElements(/*laya.webgl.WebGLContext.TRIANGLES*/0x0004,36,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,0);
- Stat.trianglesFaces+=12;
- Stat.renderBatches++;
- }
- SkyBox.__init__=function(){
- SkyBox.instance=new SkyBox();
- }
- SkyBox.instance=null;
- return SkyBox;
- })(SkyMesh)
- /**
- *<code>MeshColliderShape</code> 类用于创建网格碰撞器。
- */
- //class laya.d3.physics.shape.MeshColliderShape extends laya.d3.physics.shape.ColliderShape
- var MeshColliderShape=(function(_super){
- function MeshColliderShape(){
- /**@private */
- this._mesh=null;
- /**@private */
- this._convex=false;
- MeshColliderShape.__super.call(this);
- }
- __class(MeshColliderShape,'laya.d3.physics.shape.MeshColliderShape',_super);
- var __proto=MeshColliderShape.prototype;
- /**
- *@inheritDoc
- */
- __proto._setScale=function(value){
- if (this._compoundParent){
- this.updateLocalTransformations();
- }else {
- ColliderShape._nativeScale.setValue(value.x,value.y,value.z);
- this._nativeShape.setLocalScaling(ColliderShape._nativeScale);
- this._nativeShape.updateBound();
- }
- }
- /**
- *@inheritDoc
- */
- __proto.cloneTo=function(destObject){
- var destMeshCollider=destObject;
- destMeshCollider.convex=this._convex;
- destMeshCollider.mesh=this._mesh;
- _super.prototype.cloneTo.call(this,destObject);
- }
- /**
- *@inheritDoc
- */
- __proto.clone=function(){
- var dest=new MeshColliderShape();
- this.cloneTo(dest);
- return dest;
- }
- /**
- *@inheritDoc
- */
- __proto.destroy=function(){
- if (this._nativeShape){
- var physics3D=Laya3D._physics3D;
- physics3D.destroy(this._nativeShape);
- this._nativeShape=null;
- }
- }
- /**
- *设置网格。
- *@param 网格。
- */
- /**
- *获取网格。
- *@return 网格。
- */
- __getset(0,__proto,'mesh',function(){
- return this._mesh;
- },function(value){
- if (this._mesh!==value){
- var physics3D=Laya3D._physics3D;
- if (this._mesh){
- physics3D.destroy(this._nativeShape);
- }
- if (value){
- this._nativeShape=new physics3D.btGImpactMeshShape(value._getPhysicMesh());
- this._nativeShape.updateBound();
- }
- this._mesh=value;
- }
- });
- /**
- *设置是否使用凸多边形。
- *@param value 是否使用凸多边形。
- */
- /**
- *获取是否使用凸多边形。
- *@return 是否使用凸多边形。
- */
- __getset(0,__proto,'convex',function(){
- return this._convex;
- },function(value){
- this._convex=value;
- });
- return MeshColliderShape;
- })(ColliderShape)
- /**
- *<code>HemisphereShape</code> 类用于创建半球形粒子形状。
- */
- //class laya.d3.core.particleShuriKen.module.shape.HemisphereShape extends laya.d3.core.particleShuriKen.module.shape.BaseShape
- var HemisphereShape=(function(_super){
- function HemisphereShape(){
- /**发射器半径。*/
- this.radius=NaN;
- /**从外壳发射。*/
- this.emitFromShell=false;
- HemisphereShape.__super.call(this);
- this.radius=1.0;
- this.emitFromShell=false;
- this.randomDirection=false;
- }
- __class(HemisphereShape,'laya.d3.core.particleShuriKen.module.shape.HemisphereShape',_super);
- var __proto=HemisphereShape.prototype;
- /**
- *@inheritDoc
- */
- __proto._getShapeBoundBox=function(boundBox){
- var min=boundBox.min;
- min.x=min.y=min.z=-this.radius;
- var max=boundBox.max;
- max.x=max.y=this.radius;
- max.z=0;
- }
- /**
- *@inheritDoc
- */
- __proto._getSpeedBoundBox=function(boundBox){
- var min=boundBox.min;
- min.x=min.y=-1;
- min.z=0;
- var max=boundBox.max;
- max.x=max.y=max.z=1;
- }
- /**
- *用于生成粒子初始位置和方向。
- *@param position 粒子位置。
- *@param direction 粒子方向。
- */
- __proto.generatePositionAndDirection=function(position,direction,rand,randomSeeds){
- if (rand){
- rand.seed=randomSeeds[16];
- if (this.emitFromShell)
- ShapeUtils._randomPointUnitSphere(position,rand);
- else
- ShapeUtils._randomPointInsideUnitSphere(position,rand);
- randomSeeds[16]=rand.seed;
- }else {
- if (this.emitFromShell)
- ShapeUtils._randomPointUnitSphere(position);
- else
- ShapeUtils._randomPointInsideUnitSphere(position);
- }
- Vector3.scale(position,this.radius,position);
- var z=position.z;
- (z < 0.0)&& (position.z=z *-1.0);
- if (this.randomDirection){
- if (rand){
- rand.seed=randomSeeds[17];
- ShapeUtils._randomPointUnitSphere(direction,rand);
- randomSeeds[17]=rand.seed;
- }else {
- ShapeUtils._randomPointUnitSphere(direction);
- }
- }else {
- position.cloneTo(direction);
- }
- }
- __proto.cloneTo=function(destObject){
- _super.prototype.cloneTo.call(this,destObject);
- var destShape=destObject;
- destShape.radius=this.radius;
- destShape.emitFromShell=this.emitFromShell;
- destShape.randomDirection=this.randomDirection;
- }
- return HemisphereShape;
- })(BaseShape)
- /**
- *<code>TerrainFilter</code> 类用于创建TerrainFilter过滤器。
- */
- //class laya.d3.terrain.TerrainFilter extends laya.d3.core.GeometryElement
- var TerrainFilter=(function(_super){
- function TerrainFilter(owner,chunkOffsetX,chunkOffsetZ,gridSize,terrainHeightData,heightDataWidth,heightDataHeight,cameraCoordinateInverse){
- this._owner=null;
- this._gridSize=NaN;
- this.memorySize=0;
- this._numberVertices=0;
- this._maxNumberIndices=0;
- this._currentNumberIndices=0;
- this._numberTriangle=0;
- this._vertexBuffer=null;
- this._indexBuffer=null;
- this._indexArrayBuffer=null;
- this._boundingBoxCorners=null;
- this._leafs=null;
- this._leafNum=0;
- this._terrainHeightData=null;
- this._terrainHeightDataWidth=0;
- this._terrainHeightDataHeight=0;
- this._chunkOffsetX=0;
- this._chunkOffsetZ=0;
- this._cameraCoordinateInverse=false;
- this._cameraPos=null;
- this._currentLOD=0;
- //LOD级别 4个叶子节点 第1个叶子的level<<24+第2个叶子的level<<16+第3个叶子的level<<8+第4个叶子的level
- this._perspectiveFactor=NaN;
- this._LODTolerance=0;
- /**@private */
- this._boundingSphere=null;
- /**@private */
- this._boundingBox=null;
- TerrainFilter.__super.call(this);
- this._bufferState=new BufferState();
- this._owner=owner;
- this._cameraPos=new Vector3();
- this._chunkOffsetX=chunkOffsetX;
- this._chunkOffsetZ=chunkOffsetZ;
- this._gridSize=gridSize;
- this._terrainHeightData=terrainHeightData;
- this._terrainHeightDataWidth=heightDataWidth;
- this._terrainHeightDataHeight=heightDataHeight;
- this._leafNum=(TerrainLeaf.CHUNK_GRID_NUM / TerrainLeaf.LEAF_GRID_NUM)*(TerrainLeaf.CHUNK_GRID_NUM / TerrainLeaf.LEAF_GRID_NUM);
- this._leafs=__newvec(this._leafNum);
- this._cameraCoordinateInverse=cameraCoordinateInverse;
- for (var i=0;i < this._leafNum;i++){
- this._leafs[i]=new TerrainLeaf();
- }
- this.recreateResource();
- }
- __class(TerrainFilter,'laya.d3.terrain.TerrainFilter',_super);
- var __proto=TerrainFilter.prototype;
- __proto.recreateResource=function(){
- this._currentNumberIndices=0;
- this._numberTriangle=0;
- var nLeafVertexCount=TerrainLeaf.LEAF_VERTEXT_COUNT;
- var nLeafIndexCount=TerrainLeaf.LEAF_MAX_INDEX_COUNT;
- this._numberVertices=nLeafVertexCount *this._leafNum;
- this._maxNumberIndices=nLeafIndexCount *this._leafNum;
- this._indexArrayBuffer=new Uint16Array(this._maxNumberIndices);
- var vertexDeclaration=VertexPositionTerrain.vertexDeclaration;
- var vertexFloatStride=vertexDeclaration.vertexStride / 4;
- var vertices=new Float32Array(this._numberVertices *vertexFloatStride);
- var nNum=TerrainLeaf.CHUNK_GRID_NUM / TerrainLeaf.LEAF_GRID_NUM;
- var i=0,x=0,z=0;
- for (i=0;i < this._leafNum;i++){
- x=i % nNum;
- z=Math.floor(i / nNum);
- this._leafs[i].calcVertextBuffer(this._chunkOffsetX,this._chunkOffsetZ,x *TerrainLeaf.LEAF_GRID_NUM,z *TerrainLeaf.LEAF_GRID_NUM,this._gridSize,vertices,i *TerrainLeaf.LEAF_PLANE_VERTEXT_COUNT,vertexFloatStride,this._terrainHeightData,this._terrainHeightDataWidth,this._terrainHeightDataHeight,this._cameraCoordinateInverse);
- }
- for (i=0;i < this._leafNum;i++){
- x=i % nNum;
- z=Math.floor(i / nNum);
- this._leafs[i].calcSkirtVertextBuffer(this._chunkOffsetX,this._chunkOffsetZ,x *TerrainLeaf.LEAF_GRID_NUM,z *TerrainLeaf.LEAF_GRID_NUM,this._gridSize,vertices,this._leafNum *TerrainLeaf.LEAF_PLANE_VERTEXT_COUNT+i *TerrainLeaf.LEAF_SKIRT_VERTEXT_COUNT,vertexFloatStride,this._terrainHeightData,this._terrainHeightDataWidth,this._terrainHeightDataHeight);
- }
- this.assembleIndexInit();
- this._vertexBuffer=new VertexBuffer3D(vertexDeclaration.vertexStride *this._numberVertices,/*laya.webgl.WebGLContext.STATIC_DRAW*/0x88E4,false);
- this._vertexBuffer.vertexDeclaration=vertexDeclaration;
- this._indexBuffer=new IndexBuffer3D(/*laya.d3.graphics.IndexBuffer3D.INDEXTYPE_USHORT*/"ushort",this._maxNumberIndices,/*laya.webgl.WebGLContext.STATIC_DRAW*/0x88E4,false);
- this._vertexBuffer.setData(vertices);
- this._indexBuffer.setData(this._indexArrayBuffer);
- this.memorySize=(this._vertexBuffer._byteLength+this._indexBuffer._byteLength)*2;
- this.calcOriginalBoudingBoxAndSphere();
- this._bufferState.bind();
- this._bufferState.applyVertexBuffer(this._vertexBuffer);
- this._bufferState.applyIndexBuffer(this._indexBuffer);
- this._bufferState.unBind();
- }
- __proto.setLODLevel=function(leafsLODLevel){
- if (leafsLODLevel.length !=4)return true;
- var nLOD=((leafsLODLevel[0]+1)<< 24)+((leafsLODLevel[1]+1)<< 16)+((leafsLODLevel[2]+1)<< 8)+(leafsLODLevel[3]+1);
- if (this._currentLOD==nLOD){
- return false;
- }
- this._currentLOD=nLOD;
- return true;
- }
- __proto.assembleIndexInit=function(){
- this._currentNumberIndices=0;
- this._numberTriangle=0;
- var nOffsetIndex=0;
- for (var i=0;i < this._leafNum;i++){
- var planeLODIndex=TerrainLeaf.getPlaneLODIndex(i,0);
- this._indexArrayBuffer.set(planeLODIndex,nOffsetIndex);
- nOffsetIndex+=planeLODIndex.length;
- var skirtLODIndex=TerrainLeaf.getSkirtLODIndex(i,0);
- this._indexArrayBuffer.set(skirtLODIndex,nOffsetIndex);
- nOffsetIndex+=skirtLODIndex.length;
- this._currentNumberIndices+=(planeLODIndex.length+skirtLODIndex.length);
- }
- this._numberTriangle=this._currentNumberIndices / 3;
- }
- __proto.isNeedAssemble=function(camera,cameraPostion){
- var perspectiveFactor=Math.min(camera.viewport.width,camera.viewport.height)/ (2 *Math.tan(Math.PI *camera.fieldOfView / 180.0));
- if (this._perspectiveFactor !=perspectiveFactor){
- this._perspectiveFactor=perspectiveFactor;
- return 1;
- }
- if (this._LODTolerance !=Terrain.LOD_TOLERANCE_VALUE){
- this._LODTolerance=Terrain.LOD_TOLERANCE_VALUE;
- return 1;
- }
- if (Vector3.equals(cameraPostion,this._cameraPos)==false){
- this._cameraPos.x=cameraPostion.x;
- this._cameraPos.y=cameraPostion.y;
- this._cameraPos.z=cameraPostion.z;
- return 2;
- }
- return 0;
- }
- __proto.assembleIndex=function(camera,cameraPostion){
- var nNeedType=this.isNeedAssemble(camera,cameraPostion);
- if (nNeedType > 0){
- for (var i=0;i < this._leafNum;i++){
- TerrainFilter._TEMP_ARRAY_BUFFER[i]=this._leafs[i].determineLod(cameraPostion,this._perspectiveFactor,Terrain.LOD_TOLERANCE_VALUE,nNeedType==1);
- }
- if (this.setLODLevel(TerrainFilter._TEMP_ARRAY_BUFFER)){
- this._currentNumberIndices=0;
- this._numberTriangle=0;
- var nOffsetIndex=0;
- for (i=0;i < this._leafNum;i++){
- var nLODLevel=TerrainFilter._TEMP_ARRAY_BUFFER[i];
- var planeLODIndex=TerrainLeaf.getPlaneLODIndex(i,nLODLevel);
- this._indexArrayBuffer.set(planeLODIndex,nOffsetIndex);
- nOffsetIndex+=planeLODIndex.length;
- var skirtLODIndex=TerrainLeaf.getSkirtLODIndex(i,nLODLevel);
- this._indexArrayBuffer.set(skirtLODIndex,nOffsetIndex);
- nOffsetIndex+=skirtLODIndex.length;
- this._currentNumberIndices+=(planeLODIndex.length+skirtLODIndex.length);
- }
- this._numberTriangle=this._currentNumberIndices / 3;
- return true;
- }
- }
- return false;
- }
- __proto.calcOriginalBoudingBoxAndSphere=function(){
- var sizeOfY=new Vector2(2147483647,-2147483647);
- for (var i=0;i < this._leafNum;i++){
- sizeOfY.x=this._leafs[i]._sizeOfY.x < sizeOfY.x ? this._leafs[i]._sizeOfY.x :sizeOfY.x;
- sizeOfY.y=this._leafs[i]._sizeOfY.y > sizeOfY.y ? this._leafs[i]._sizeOfY.y :sizeOfY.y;
- };
- var min=new Vector3(this._chunkOffsetX *TerrainLeaf.CHUNK_GRID_NUM *this._gridSize,sizeOfY.x,this._chunkOffsetZ *TerrainLeaf.CHUNK_GRID_NUM *this._gridSize);
- var max=new Vector3((this._chunkOffsetX+1)*TerrainLeaf.CHUNK_GRID_NUM *this._gridSize,sizeOfY.y,(this._chunkOffsetZ+1)*TerrainLeaf.CHUNK_GRID_NUM *this._gridSize);
- if (TerrainLeaf.__ADAPT_MATRIX__){
- Vector3.transformV3ToV3(min,TerrainLeaf.__ADAPT_MATRIX__,min);
- Vector3.transformV3ToV3(max,TerrainLeaf.__ADAPT_MATRIX__,max);
- }
- this._boundingBox=new BoundBox(min,max);
- var size=new Vector3();
- Vector3.subtract(max,min,size);
- Vector3.scale(size,0.5,size);
- var center=new Vector3();
- Vector3.add(min,size,center);
- this._boundingSphere=new BoundSphere(center,Vector3.scalarLength(size));
- this._boundingBoxCorners=__newvec(8,null);
- this._boundingBox.getCorners(this._boundingBoxCorners);
- }
- __proto.calcLeafBoudingBox=function(worldMatrix){
- for (var i=0;i < this._leafNum;i++){
- this._leafs[i].calcLeafBoudingBox(worldMatrix);
- }
- }
- __proto.calcLeafBoudingSphere=function(worldMatrix,maxScale){
- for (var i=0;i < this._leafNum;i++){
- this._leafs[i].calcLeafBoudingSphere(worldMatrix,maxScale);
- }
- }
- __proto._getVertexBuffer=function(index){
- (index===void 0)&& (index=0);
- if (index==0){
- return this._vertexBuffer;
- }
- return null;
- }
- __proto._getIndexBuffer=function(){
- return this._indexBuffer;
- }
- /**
- *@inheritDoc
- */
- __proto._getType=function(){
- return TerrainFilter._type;
- }
- /**
- *@inheritDoc
- */
- __proto._prepareRender=function(state){
- return true;
- }
- /**
- *@inheritDoc
- */
- __proto._render=function(state){
- this._bufferState.bind();
- LayaGL.instance.drawElements(Terrain.RENDER_LINE_MODEL ? /*laya.webgl.WebGLContext.LINES*/0x0001 :/*laya.webgl.WebGLContext.TRIANGLES*/0x0004,this._currentNumberIndices,/*laya.webgl.WebGLContext.UNSIGNED_SHORT*/0x1403,0);
- Stat.trianglesFaces+=this._numberTriangle;
- Stat.renderBatches++;
- }
- /**
- *@inheritDoc
- */
- __proto.destroy=function(){
- this._owner=null;
- this._bufferState.destroy();
- if (this._vertexBuffer)this._vertexBuffer.destroy();
- if (this._indexBuffer)this._indexBuffer.destroy();
- }
- __static(TerrainFilter,
- ['_TEMP_ARRAY_BUFFER',function(){return this._TEMP_ARRAY_BUFFER=new Uint32Array(TerrainLeaf.CHUNK_GRID_NUM / TerrainLeaf.LEAF_GRID_NUM *TerrainLeaf.CHUNK_GRID_NUM / TerrainLeaf.LEAF_GRID_NUM);},'_type',function(){return this._type=GeometryElement._typeCounter++;}
- ]);
- return TerrainFilter;
- })(GeometryElement)
- /**
- *<code>BloomEffect</code> 类用于创建泛光效果。
- */
- //class laya.d3.core.render.BloomEffect extends laya.d3.core.render.PostProcessEffect
- var BloomEffect=(function(_super){
- function BloomEffect(){
- /**@private */
- this._shader=null;
- /**@private */
- this._pyramid=null;
- /**@private */
- this._intensity=0.0;
- /**@private */
- this._threshold=1.0;
- /**@private */
- this._softKnee=0.5;
- /**@private */
- this._diffusion=7.0;
- /**@private */
- this._anamorphicRatio=0.0;
- /**@private */
- this._dirtIntensity=0.0;
- /**限制泛光像素的数量,该值在伽马空间。*/
- this.clamp=65472.0;
- /**是否开启快速模式。该模式通过降低质量来提升性能。*/
- this.fastMode=false;
- /**镜头污渍纹路,用于为泛光特效增加污渍灰尘效果*/
- this.dirtTexture=null;
- BloomEffect.__super.call(this);
- this._shaderData=new ShaderData();
- this._linearColor=new Color();
- this._shaderThreshold=new Vector4();
- this._shaderParams=new Vector4();
- this._shaderSetting=new Vector4();
- this._dirtTileOffset=new Vector4();
- this.color=new Color(1.0,1.0,1.0,1.0);
- this._shader=Shader3D.find("PostProcessBloom");
- this._pyramid=new Array(16 *2);
- }
- __class(BloomEffect,'laya.d3.core.render.BloomEffect',_super);
- var __proto=BloomEffect.prototype;
- /**
- *@inheritDoc
- */
- __proto.render=function(context){
- var cmd=context.command;
- var viewport=context.camera.viewport;
- this._shaderData.setTexture(BloomEffect.SHADERVALUE_AUTOEXPOSURETEX,Texture2D.whiteTexture);
- var ratio=this._anamorphicRatio;
- var rw=ratio < 0 ?-ratio :0;
- var rh=ratio > 0 ? ratio :0;
- var tw=Math.floor(viewport.width / (2-rw));
- var th=Math.floor(viewport.height / (2-rh));
- var s=Math.max(tw,th);
- var logs=NaN;
- /*__JS__ */logs=Math.log2(s)+this._diffusion-10;
- var logsInt=Math.floor(logs);
- var iterations=Math.min(Math.max(logsInt,1),16);
- var sampleScale=0.5+logs-logsInt;
- this._shaderData.setNumber(BloomEffect.SHADERVALUE_SAMPLESCALE,sampleScale);
- var lthresh=Utils3D.gammaToLinearSpace(this.threshold);
- var knee=lthresh *this._softKnee+1e-5;
- this._shaderThreshold.setValue(lthresh,lthresh-knee,knee *2,0.25 / knee);
- this._shaderData.setVector(BloomEffect.SHADERVALUE_THRESHOLD,this._shaderThreshold);
- var lclamp=Utils3D.gammaToLinearSpace(this.clamp);
- this._shaderParams.setValue(lclamp,0,0,0);
- this._shaderData.setVector(BloomEffect.SHADERVALUE_PARAMS,this._shaderParams);
- var qualityOffset=this.fastMode ? 1 :0;
- var lastDownTexture=context.source;
- for (var i=0;i < iterations;i++){
- var downIndex=i *2;
- var upIndex=downIndex+1;
- var subShader=i==0 ? 0+qualityOffset :2+qualityOffset;
- var mipDownTexture=RenderTexture.getTemporary(tw,th,/*laya.resource.BaseTexture.FORMAT_R8G8B8*/0,/*laya.resource.BaseTexture.FORMAT_DEPTHSTENCIL_NONE*/3,/*laya.resource.BaseTexture.FILTERMODE_BILINEAR*/1);
- var mipUpTexture=RenderTexture.getTemporary(tw,th,/*laya.resource.BaseTexture.FORMAT_R8G8B8*/0,/*laya.resource.BaseTexture.FORMAT_DEPTHSTENCIL_NONE*/3,/*laya.resource.BaseTexture.FILTERMODE_BILINEAR*/1);
- this._pyramid[downIndex]=mipDownTexture;
- this._pyramid[upIndex]=mipUpTexture;
- cmd.blit(lastDownTexture,mipDownTexture,this._shader,this._shaderData,subShader);
- lastDownTexture=mipDownTexture;
- tw=Math.max(tw / 2,1);
- th=Math.max(th / 2,1);
- };
- var lastUpTexture=this._pyramid[2 *iterations-3];
- for (i=iterations-2;i >=0;i--){
- downIndex=i *2;
- upIndex=downIndex+1;
- mipDownTexture=this._pyramid[downIndex];
- mipUpTexture=this._pyramid[upIndex];
- cmd.setShaderDataTexture(this._shaderData,BloomEffect.SHADERVALUE_BLOOMTEX,mipDownTexture);
- cmd.blit(lastUpTexture,mipUpTexture,this._shader,this._shaderData,4+qualityOffset);
- lastUpTexture=mipUpTexture;
- };
- var linearColor=this._linearColor;
- this.color.toLinear(linearColor);
- var intensity=Math.pow(2,this._intensity / 10.0)-1.0;
- var shaderSettings=this._shaderSetting;
- this._shaderSetting.setValue(sampleScale,intensity,this._dirtIntensity,iterations);
- var dirtTexture=dirtTexture ? dirtTexture :Texture2D.blackTexture;
- var dirtRatio=dirtTexture.width / dirtTexture.height;
- var screenRatio=viewport.width / viewport.height;
- var dirtTileOffset=this._dirtTileOffset;
- dirtTileOffset.setValue(1.0,1.0,0.0,0.0);
- if (dirtRatio > screenRatio)
- dirtTileOffset.setValue(screenRatio / dirtRatio,1.0,(1.0-dirtTileOffset.x)*0.5,0.0);
- else if (dirtRatio < screenRatio)
- dirtTileOffset.setValue(1.0,dirtRatio / screenRatio,0.0,(1.0-dirtTileOffset.y)*0.5);
- var compositeShaderData=context.compositeShaderData;
- var compositeDefineData=context.compositeDefineData;
- if (this.fastMode)
- compositeDefineData.add(PostProcess.SHADERDEFINE_BLOOM_LOW);
- else
- compositeDefineData.add(PostProcess.SHADERDEFINE_BLOOM);
- compositeShaderData.setVector(PostProcess.SHADERVALUE_BLOOM_DIRTTILEOFFSET,dirtTileOffset);
- compositeShaderData.setVector(PostProcess.SHADERVALUE_BLOOM_SETTINGS,shaderSettings);
- compositeShaderData.setVector(PostProcess.SHADERVALUE_BLOOM_COLOR,new Vector4(linearColor.r,linearColor.g,linearColor.b,linearColor.a));
- compositeShaderData.setTexture(PostProcess.SHADERVALUE_BLOOM_DIRTTEX,dirtTexture);
- compositeShaderData.setTexture(PostProcess.SHADERVALUE_BLOOMTEX,lastUpTexture);
- for (i=0;i < iterations;i++){
- downIndex=i *2;
- upIndex=downIndex+1;
- if (this._pyramid[downIndex] !=lastUpTexture)
- RenderTexture.setReleaseTemporary(this._pyramid[downIndex]);
- if (this._pyramid[upIndex] !=lastUpTexture)
- RenderTexture.setReleaseTemporary(this._pyramid[upIndex]);
- }
- context.tempRenderTextures.push(lastUpTexture);
- }
- /**
- *设置软膝盖过渡强度,在阈值以下进行渐变过渡(0为完全硬过度,1为完全软过度)。
- *@param value 软膝盖值。
- */
- /**
- *获取软膝盖过渡强度,在阈值以下进行渐变过渡(0为完全硬过度,1为完全软过度)。
- *@return 软膝盖值。
- */
- __getset(0,__proto,'softKnee',function(){
- return this._softKnee;
- },function(value){
- this._softKnee=Math.min(Math.max(value,0.0),1.0);
- });
- /**
- *设置泛光过滤器强度,最小值为0。
- *@param value 强度。
- */
- /**
- *获取泛光过滤器强度,最小值为0。
- *@return 强度。
- */
- __getset(0,__proto,'intensity',function(){
- return this._intensity;
- },function(value){
- this._intensity=Math.max(value,0.0);
- });
- /**
- *获取泛光阈值,在该阈值亮度以下的像素会被过滤掉,该值在伽马空间。
- *@param value 阈值。
- */
- /**
- *设置泛光阈值,在该阈值亮度以下的像素会被过滤掉,该值在伽马空间。
- *@return 阈值。
- */
- __getset(0,__proto,'threshold',function(){
- return this._threshold;
- },function(value){
- this._threshold=Math.max(value,0.0);
- });
- /**
- *设置形变比,通过扭曲泛光产生视觉上形变,负值为垂直扭曲,正值为水平扭曲。
- *@param value 形变比。
- */
- /**
- *获取形变比,通过扭曲泛光产生视觉上形变,负值为垂直扭曲,正值为水平扭曲。
- *@return 形变比。
- */
- __getset(0,__proto,'anamorphicRatio',function(){
- return this._anamorphicRatio;
- },function(value){
- this._anamorphicRatio=Math.min(Math.max(value,-1.0),1.0);
- });
- /**
- *设置扩散值,改变泛光的扩散范围,最好使用整数值保证效果,该值会改变内部的迭代次数,范围是1到10。
- *@param value 光晕的扩散范围。
- */
- /**
- *获取扩散值,改变泛光的扩散范围,最好使用整数值保证效果,该值会改变内部的迭代次数,范围是1到10。
- *@return 光晕的扩散范围。
- */
- __getset(0,__proto,'diffusion',function(){
- return this._diffusion;
- },function(value){
- this._diffusion=Math.min(Math.max(value,1),10);
- });
- /**
- *设置污渍强度。
- *@param value 污渍强度。
- */
- /**
- *获取污渍强度。
- *@return 污渍强度。
- */
- __getset(0,__proto,'dirtIntensity',function(){
- return this._dirtIntensity;
- },function(value){
- this._dirtIntensity=Math.max(value,0.0);
- });
- BloomEffect.SUBSHADER_PREFILTER13=0;
- BloomEffect.SUBSHADER_PREFILTER4=1;
- BloomEffect.SUBSHADER_DOWNSAMPLE13=2;
- BloomEffect.SUBSHADER_DOWNSAMPLE4=3;
- BloomEffect.SUBSHADER_UPSAMPLETENT=4;
- BloomEffect.SUBSHADER_UPSAMPLEBOX=5;
- BloomEffect.MAXPYRAMIDSIZE=16;
- __static(BloomEffect,
- ['SHADERVALUE_MAINTEX',function(){return this.SHADERVALUE_MAINTEX=Shader3D.propertyNameToID("u_MainTex");},'SHADERVALUE_AUTOEXPOSURETEX',function(){return this.SHADERVALUE_AUTOEXPOSURETEX=Shader3D.propertyNameToID("u_AutoExposureTex");},'SHADERVALUE_SAMPLESCALE',function(){return this.SHADERVALUE_SAMPLESCALE=Shader3D.propertyNameToID("u_SampleScale");},'SHADERVALUE_THRESHOLD',function(){return this.SHADERVALUE_THRESHOLD=Shader3D.propertyNameToID("u_Threshold");},'SHADERVALUE_PARAMS',function(){return this.SHADERVALUE_PARAMS=Shader3D.propertyNameToID("u_Params");},'SHADERVALUE_BLOOMTEX',function(){return this.SHADERVALUE_BLOOMTEX=Shader3D.propertyNameToID("u_BloomTex");}
- ]);
- return BloomEffect;
- })(PostProcessEffect)
- /**
- *@private
- *<code>SetShaderDataTextureCMD</code> 类用于创建设置渲染目标指令。
- */
- //class laya.d3.core.render.command.SetShaderDataTextureCMD extends laya.d3.core.render.command.Command
- var SetShaderDataTextureCMD=(function(_super){
- function SetShaderDataTextureCMD(){
- /**@private */
- this._shaderData=null;
- /**@private */
- this._nameID=0;
- /**@private */
- this._texture=null;
- SetShaderDataTextureCMD.__super.call(this);
- }
- __class(SetShaderDataTextureCMD,'laya.d3.core.render.command.SetShaderDataTextureCMD',_super);
- var __proto=SetShaderDataTextureCMD.prototype;
- /**
- *@inheritDoc
- */
- __proto.run=function(){
- this._shaderData.setTexture(this._nameID,this._texture);
- }
- /**
- *@inheritDoc
- */
- __proto.recover=function(){
- SetShaderDataTextureCMD._pool.push(this);
- this._shaderData=null;
- this._nameID=0;
- this._texture=null;
- }
- SetShaderDataTextureCMD.create=function(shaderData,nameID,texture){
- var cmd;
- cmd=SetShaderDataTextureCMD._pool.length > 0 ? SetShaderDataTextureCMD._pool.pop():new SetShaderDataTextureCMD();
- cmd._shaderData=shaderData;
- cmd._nameID=nameID;
- cmd._texture=texture;
- return cmd;
- }
- SetShaderDataTextureCMD._pool=[];
- return SetShaderDataTextureCMD;
- })(Command)
- /**
- *<code>SphereShape</code> 类用于创建球形粒子形状。
- */
- //class laya.d3.core.particleShuriKen.module.shape.SphereShape extends laya.d3.core.particleShuriKen.module.shape.BaseShape
- var SphereShape=(function(_super){
- function SphereShape(){
- /**发射器半径。*/
- this.radius=NaN;
- /**从外壳发射。*/
- this.emitFromShell=false;
- SphereShape.__super.call(this);
- this.radius=1.0;
- this.emitFromShell=false;
- this.randomDirection=false;
- }
- __class(SphereShape,'laya.d3.core.particleShuriKen.module.shape.SphereShape',_super);
- var __proto=SphereShape.prototype;
- /**
- *@inheritDoc
- */
- __proto._getShapeBoundBox=function(boundBox){
- var min=boundBox.min;
- min.x=min.y=min.z=-this.radius;
- var max=boundBox.max;
- max.x=max.y=max.z=this.radius;
- }
- /**
- *@inheritDoc
- */
- __proto._getSpeedBoundBox=function(boundBox){
- var min=boundBox.min;
- min.x=min.y=min.z=-1;
- var max=boundBox.max;
- max.x=max.y=max.z=1;
- }
- /**
- *用于生成粒子初始位置和方向。
- *@param position 粒子位置。
- *@param direction 粒子方向。
- */
- __proto.generatePositionAndDirection=function(position,direction,rand,randomSeeds){
- if (rand){
- rand.seed=randomSeeds[16];
- if (this.emitFromShell)
- ShapeUtils._randomPointUnitSphere(position,rand);
- else
- ShapeUtils._randomPointInsideUnitSphere(position,rand);
- randomSeeds[16]=rand.seed;
- }else {
- if (this.emitFromShell)
- ShapeUtils._randomPointUnitSphere(position);
- else
- ShapeUtils._randomPointInsideUnitSphere(position);
- }
- Vector3.scale(position,this.radius,position);
- if (this.randomDirection){
- if (rand){
- rand.seed=randomSeeds[17];
- ShapeUtils._randomPointUnitSphere(direction,rand);
- randomSeeds[17]=rand.seed;
- }else {
- ShapeUtils._randomPointUnitSphere(direction);
- }
- }else {
- position.cloneTo(direction);
- }
- }
- __proto.cloneTo=function(destObject){
- _super.prototype.cloneTo.call(this,destObject);
- var destShape=destObject;
- destShape.radius=this.radius;
- destShape.emitFromShell=this.emitFromShell;
- destShape.randomDirection=this.randomDirection;
- }
- return SphereShape;
- })(BaseShape)
- /**
- *<code>Vector3Keyframe</code> 类用于创建三维向量关键帧实例。
- */
- //class laya.d3.core.Vector3Keyframe extends laya.d3.core.Keyframe
- var Vector3Keyframe=(function(_super){
- function Vector3Keyframe(){
- Vector3Keyframe.__super.call(this);
- this.inTangent=new Vector3();
- this.outTangent=new Vector3();
- this.value=new Vector3();
- }
- __class(Vector3Keyframe,'laya.d3.core.Vector3Keyframe',_super);
- var __proto=Vector3Keyframe.prototype;
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(dest){
- _super.prototype.cloneTo.call(this,dest);
- var destKeyFarme=dest;
- this.inTangent.cloneTo(destKeyFarme.inTangent);
- this.outTangent.cloneTo(destKeyFarme.outTangent);
- this.value.cloneTo(destKeyFarme.value);
- }
- return Vector3Keyframe;
- })(Keyframe)
- /**
- *<code>SkyDome</code> 类用于创建天空盒。
- */
- //class laya.d3.resource.models.SkyDome extends laya.d3.resource.models.SkyMesh
- var SkyDome=(function(_super){
- function SkyDome(stacks,slices){
- /**@private */
- this._stacks=0;
- /**@private */
- this._slices=0;
- SkyDome.__super.call(this);
- (stacks===void 0)&& (stacks=48);
- (slices===void 0)&& (slices=48);
- this._stacks=stacks;
- this._slices=slices;
- var vertexDeclaration=VertexPositionTexture0.vertexDeclaration;
- var vertexFloatCount=vertexDeclaration.vertexStride / 4;
- var numberVertices=(this._stacks+1)*(this._slices+1);
- var numberIndices=(3 *this._stacks *(this._slices+1))*2;
- var vertices=new Float32Array(numberVertices *vertexFloatCount);
- var indices=new Uint16Array(numberIndices);
- var stackAngle=Math.PI / this._stacks;
- var sliceAngle=(Math.PI *2.0)/ this._slices;
- var vertexIndex=0;
- var vertexCount=0;
- var indexCount=0;
- for (var stack=0;stack < (this._stacks+1);stack++){
- var r=Math.sin(stack *stackAngle);
- var y=Math.cos(stack *stackAngle);
- for (var slice=0;slice < (this._slices+1);slice++){
- var x=r *Math.sin(slice *sliceAngle);
- var z=r *Math.cos(slice *sliceAngle);
- vertices[vertexCount+0]=x *SkyDome._radius;
- vertices[vertexCount+1]=y *SkyDome._radius;
- vertices[vertexCount+2]=z *SkyDome._radius;
- vertices[vertexCount+3]=-(slice / this._slices)+0.75;
- vertices[vertexCount+4]=stack / this._stacks;
- vertexCount+=vertexFloatCount;
- if (stack !=(this._stacks-1)){
- indices[indexCount++]=vertexIndex+1;
- indices[indexCount++]=vertexIndex;
- indices[indexCount++]=vertexIndex+(this._slices+1);
- indices[indexCount++]=vertexIndex+(this._slices+1);
- indices[indexCount++]=vertexIndex;
- indices[indexCount++]=vertexIndex+(this._slices);
- vertexIndex++;
- }
- }
- }
- this._vertexBuffer=new VertexBuffer3D(vertices.length *4,/*laya.webgl.WebGLContext.STATIC_DRAW*/0x88E4,false);
- this._vertexBuffer.vertexDeclaration=vertexDeclaration;
- this._indexBuffer=new IndexBuffer3D(/*laya.d3.graphics.IndexBuffer3D.INDEXTYPE_USHORT*/"ushort",indices.length,/*laya.webgl.WebGLContext.STATIC_DRAW*/0x88E4,false);
- this._vertexBuffer.setData(vertices);
- this._indexBuffer.setData(indices);
- var bufferState=new BufferState();
- bufferState.bind();
- bufferState.applyVertexBuffer(this._vertexBuffer);
- bufferState.applyIndexBuffer(this._indexBuffer);
- bufferState.unBind();
- this._bufferState=bufferState;
- }
- __class(SkyDome,'laya.d3.resource.models.SkyDome',_super);
- var __proto=SkyDome.prototype;
- __proto._render=function(state){
- var indexCount=this._indexBuffer.indexCount;
- LayaGL.instance.drawElements(/*laya.webgl.WebGLContext.TRIANGLES*/0x0004,indexCount,/*laya.webgl.WebGLContext.UNSIGNED_SHORT*/0x1403,0);
- Stat.trianglesFaces+=indexCount / 3;
- Stat.renderBatches++;
- }
- /**
- *获取堆数。
- */
- __getset(0,__proto,'stacks',function(){
- return this._stacks;
- });
- /**
- *获取层数。
- */
- __getset(0,__proto,'slices',function(){
- return this._slices;
- });
- SkyDome.__init__=function(){
- SkyDome.instance=new SkyDome();
- }
- SkyDome._radius=1;
- SkyDome.instance=null;
- return SkyDome;
- })(SkyMesh)
- /**
- *<code>ConeColliderShape</code> 类用于创建圆柱碰撞器。
- */
- //class laya.d3.physics.shape.ConeColliderShape extends laya.d3.physics.shape.ColliderShape
- var ConeColliderShape=(function(_super){
- function ConeColliderShape(radius,height,orientation){
- /**@private */
- //this._orientation=0;
- /**@private */
- this._radius=1;
- /**@private */
- this._height=0.5;
- ConeColliderShape.__super.call(this);
- (radius===void 0)&& (radius=0.5);
- (height===void 0)&& (height=1.0);
- (orientation===void 0)&& (orientation=/*laya.d3.physics.shape.ColliderShape.SHAPEORIENTATION_UPY*/1);
- this._radius=radius;
- this._height=height;
- this._orientation=orientation;
- this._type=/*laya.d3.physics.shape.ColliderShape.SHAPETYPES_CYLINDER*/2;
- switch (orientation){
- case /*laya.d3.physics.shape.ColliderShape.SHAPEORIENTATION_UPX*/0:
- this._nativeShape=new Laya3D._physics3D.btConeShapeX(radius,height);
- break ;
- case /*laya.d3.physics.shape.ColliderShape.SHAPEORIENTATION_UPY*/1:
- this._nativeShape=new Laya3D._physics3D.btConeShape(radius,height);
- break ;
- case /*laya.d3.physics.shape.ColliderShape.SHAPEORIENTATION_UPZ*/2:
- this._nativeShape=new Laya3D._physics3D.btConeShapeZ(radius,height);
- break ;
- default :
- throw "ConeColliderShape:unknown orientation.";
- }
- }
- __class(ConeColliderShape,'laya.d3.physics.shape.ConeColliderShape',_super);
- var __proto=ConeColliderShape.prototype;
- /**
- *@inheritDoc
- */
- __proto.clone=function(){
- var dest=new ConeColliderShape(this._radius,this._height,this._orientation);
- this.cloneTo(dest);
- return dest;
- }
- /**
- *获取半径。
- */
- __getset(0,__proto,'radius',function(){
- return this._radius;
- });
- /**
- *获取高度。
- */
- __getset(0,__proto,'height',function(){
- return this._height;
- });
- /**
- *获取方向。
- */
- __getset(0,__proto,'orientation',function(){
- return this._orientation;
- });
- return ConeColliderShape;
- })(ColliderShape)
- /**
- *<code>BoxShape</code> 类用于创建球形粒子形状。
- */
- //class laya.d3.core.particleShuriKen.module.shape.BoxShape extends laya.d3.core.particleShuriKen.module.shape.BaseShape
- var BoxShape=(function(_super){
- function BoxShape(){
- /**发射器X轴长度。*/
- this.x=NaN;
- /**发射器Y轴长度。*/
- this.y=NaN;
- /**发射器Z轴长度。*/
- this.z=NaN;
- BoxShape.__super.call(this);
- this.x=1.0;
- this.y=1.0;
- this.z=1.0;
- this.randomDirection=false;
- }
- __class(BoxShape,'laya.d3.core.particleShuriKen.module.shape.BoxShape',_super);
- var __proto=BoxShape.prototype;
- /**
- *@inheritDoc
- */
- __proto._getShapeBoundBox=function(boundBox){
- var min=boundBox.min;
- min.x=-this.x *0.5;
- min.y=-this.y *0.5;
- min.z=-this.z *0.5;
- var max=boundBox.max;
- max.x=this.x *0.5;
- max.y=this.y *0.5;
- max.z=this.z *0.5;
- }
- /**
- *@inheritDoc
- */
- __proto._getSpeedBoundBox=function(boundBox){
- var min=boundBox.min;
- min.x=0.0;
- min.y=0.0;
- min.z=0.0;
- var max=boundBox.max;
- max.x=0.0;
- max.y=1.0;
- max.z=0.0;
- }
- /**
- *用于生成粒子初始位置和方向。
- *@param position 粒子位置。
- *@param direction 粒子方向。
- */
- __proto.generatePositionAndDirection=function(position,direction,rand,randomSeeds){
- if (rand){
- rand.seed=randomSeeds[16];
- ShapeUtils._randomPointInsideHalfUnitBox(position,rand);
- randomSeeds[16]=rand.seed;
- }else {
- ShapeUtils._randomPointInsideHalfUnitBox(position);
- }
- position.x=this.x *position.x;
- position.y=this.y *position.y;
- position.z=this.z *position.z;
- if (this.randomDirection){
- if (rand){
- rand.seed=randomSeeds[17];
- ShapeUtils._randomPointUnitSphere(direction,rand);
- randomSeeds[17]=rand.seed;
- }else {
- ShapeUtils._randomPointUnitSphere(direction);
- }
- }else {
- direction.x=0.0;
- direction.y=0.0;
- direction.z=1.0;
- }
- }
- __proto.cloneTo=function(destObject){
- _super.prototype.cloneTo.call(this,destObject);
- var destShape=destObject;
- destShape.x=this.x;
- destShape.y=this.y;
- destShape.z=this.z;
- destShape.randomDirection=this.randomDirection;
- }
- return BoxShape;
- })(BaseShape)
- /**
- *<code>QuaternionKeyframe</code> 类用于创建四元数关键帧实例。
- */
- //class laya.d3.core.QuaternionKeyframe extends laya.d3.core.Keyframe
- var QuaternionKeyframe=(function(_super){
- function QuaternionKeyframe(){
- QuaternionKeyframe.__super.call(this);
- this.inTangent=new Vector4();
- this.outTangent=new Vector4();
- this.value=new Quaternion();
- }
- __class(QuaternionKeyframe,'laya.d3.core.QuaternionKeyframe',_super);
- var __proto=QuaternionKeyframe.prototype;
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(dest){
- _super.prototype.cloneTo.call(this,dest);
- var destKeyFarme=dest;
- this.inTangent.cloneTo(destKeyFarme.inTangent);
- this.outTangent.cloneTo(destKeyFarme.outTangent);
- this.value.cloneTo(destKeyFarme.value);
- }
- return QuaternionKeyframe;
- })(Keyframe)
- /**
- *<code>VertexShurikenParticle</code> 类用于创建粒子顶点结构。
- */
- //class laya.d3.graphics.Vertex.VertexShurikenParticleBillboard extends laya.d3.graphics.Vertex.VertexShuriKenParticle
- var VertexShurikenParticleBillboard=(function(_super){
- function VertexShurikenParticleBillboard(cornerTextureCoordinate,positionStartLifeTime,velocity,startColor,startSize,startRotation0,startRotation1,startRotation2,ageAddScale,time,startSpeed,randoms0,randoms1,simulationWorldPostion){
- /**@private */
- this._cornerTextureCoordinate=null;
- /**@private */
- this._positionStartLifeTime=null;
- /**@private */
- this._velocity=null;
- /**@private */
- this._startColor=null;
- /**@private */
- this._startSize=null;
- /**@private */
- this._startRotation0=null;
- /**@private */
- this._startRotation1=null;
- /**@private */
- this._startRotation2=null;
- /**@private */
- this._startLifeTime=NaN;
- /**@private */
- this._time=NaN;
- /**@private */
- this._startSpeed=NaN;
- /**@private */
- this._randoms0=null;
- /**@private */
- this._randoms1=null;
- /**@private */
- this._simulationWorldPostion=null;
- VertexShurikenParticleBillboard.__super.call(this);
- this._cornerTextureCoordinate=cornerTextureCoordinate;
- this._positionStartLifeTime=positionStartLifeTime;
- this._velocity=velocity;
- this._startColor=startColor;
- this._startSize=startSize;
- this._startRotation0=startRotation0;
- this._startRotation1=startRotation1;
- this._startRotation2=startRotation2;
- this._startLifeTime=ageAddScale;
- this._time=time;
- this._startSpeed=startSpeed;
- this._randoms0=this.random0;
- this._randoms1=this.random1;
- this._simulationWorldPostion=simulationWorldPostion;
- }
- __class(VertexShurikenParticleBillboard,'laya.d3.graphics.Vertex.VertexShurikenParticleBillboard',_super);
- var __proto=VertexShurikenParticleBillboard.prototype;
- __getset(0,__proto,'cornerTextureCoordinate',function(){
- return this._cornerTextureCoordinate;
- });
- __getset(0,__proto,'random1',function(){
- return this._randoms1;
- });
- __getset(0,__proto,'startRotation2',function(){
- return this._startRotation2;
- });
- __getset(0,__proto,'positionStartLifeTime',function(){
- return this._positionStartLifeTime;
- });
- __getset(0,__proto,'velocity',function(){
- return this._velocity;
- });
- __getset(0,__proto,'random0',function(){
- return this._randoms0;
- });
- __getset(0,__proto,'startSize',function(){
- return this._startSize;
- });
- __getset(0,__proto,'startColor',function(){
- return this._startColor;
- });
- __getset(0,__proto,'startRotation0',function(){
- return this._startRotation0;
- });
- __getset(0,__proto,'startRotation1',function(){
- return this._startRotation1;
- });
- __getset(0,__proto,'startLifeTime',function(){
- return this._startLifeTime;
- });
- __getset(0,__proto,'time',function(){
- return this._time;
- });
- __getset(0,__proto,'startSpeed',function(){
- return this._startSpeed;
- });
- __getset(0,__proto,'simulationWorldPostion',function(){
- return this._simulationWorldPostion;
- });
- __getset(1,VertexShurikenParticleBillboard,'vertexDeclaration',function(){
- return VertexShurikenParticleBillboard._vertexDeclaration;
- },laya.d3.graphics.Vertex.VertexShuriKenParticle._$SET_vertexDeclaration);
- __static(VertexShurikenParticleBillboard,
- ['_vertexDeclaration',function(){return this._vertexDeclaration=new VertexDeclaration(152,[
- new VertexElement(0,/*laya.d3.graphics.VertexElementFormat.Vector4*/"vector4",/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_CORNERTEXTURECOORDINATE0*/0),
- new VertexElement(16,/*laya.d3.graphics.VertexElementFormat.Vector4*/"vector4",/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_SHAPEPOSITIONSTARTLIFETIME*/4),
- new VertexElement(32,/*laya.d3.graphics.VertexElementFormat.Vector4*/"vector4",/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_DIRECTIONTIME*/5),
- new VertexElement(48,/*laya.d3.graphics.VertexElementFormat.Vector4*/"vector4",/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_STARTCOLOR0*/6),
- new VertexElement(64,/*laya.d3.graphics.VertexElementFormat.Vector3*/"vector3",/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_STARTSIZE*/8),
- new VertexElement(76,/*laya.d3.graphics.VertexElementFormat.Vector3*/"vector3",/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_STARTROTATION*/9),
- new VertexElement(88,/*laya.d3.graphics.VertexElementFormat.Single*/"single",/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_STARTSPEED*/10),
- new VertexElement(92,/*laya.d3.graphics.VertexElementFormat.Vector4*/"vector4",/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_RANDOM0*/11),
- new VertexElement(108,/*laya.d3.graphics.VertexElementFormat.Vector4*/"vector4",/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_RANDOM1*/12),
- new VertexElement(124,/*laya.d3.graphics.VertexElementFormat.Vector3*/"vector3",/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_SIMULATIONWORLDPOSTION*/13),
- new VertexElement(136,/*laya.d3.graphics.VertexElementFormat.Vector4*/"vector4",/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_SIMULATIONWORLDROTATION*/14)]);}
- ]);
- return VertexShurikenParticleBillboard;
- })(VertexShuriKenParticle)
- /**
- *@private
- */
- //class laya.d3.core.render.SubMeshRenderElement extends laya.d3.core.render.RenderElement
- var SubMeshRenderElement=(function(_super){
- function SubMeshRenderElement(){
- /**@private */
- //this._dynamicWorldPositionNormalNeedUpdate=false;
- /**@private */
- //this._dynamicVertexBatch=false;
- /**@private */
- //this._dynamicMultiSubMesh=false;
- /**@private */
- //this._dynamicVertexCount=0;
- /**@private */
- //this._dynamicWorldPositions=null;
- /**@private */
- //this._dynamicWorldNormals=null;
- /**@private */
- //this.staticBatchIndexStart=0;
- /**@private */
- //this.staticBatchIndexEnd=0;
- /**@private */
- //this.staticBatchElementList=null;
- /**@private */
- //this.instanceSubMesh=null;
- /**@private */
- //this.instanceBatchElementList=null;
- /**@private */
- //this.vertexBatchElementList=null;
- /**@private */
- //this.vertexBatchVertexDeclaration=null;
- SubMeshRenderElement.__super.call(this);
- this._dynamicWorldPositionNormalNeedUpdate=true;
- }
- __class(SubMeshRenderElement,'laya.d3.core.render.SubMeshRenderElement',_super);
- var __proto=SubMeshRenderElement.prototype;
- /**
- *@private
- */
- __proto._onWorldMatrixChanged=function(){
- this._dynamicWorldPositionNormalNeedUpdate=true;
- }
- /**
- *@inheritDoc
- */
- __proto._computeWorldPositionsAndNormals=function(positionOffset,normalOffset,multiSubMesh,vertexCount){
- if (this._dynamicWorldPositionNormalNeedUpdate){
- var subMesh=this._geometry;
- var vertexBuffer=subMesh._vertexBuffer;
- var vertexFloatCount=vertexBuffer.vertexDeclaration.vertexStride / 4;
- var oriVertexes=vertexBuffer.getData();
- var worldMat=this._transform.worldMatrix;
- var rotation=this._transform.rotation;
- var indices=subMesh._indices;
- for (var i=0;i < vertexCount;i++){
- var index=multiSubMesh ? indices[i] :i;
- var oriOffset=index *vertexFloatCount;
- var bakeOffset=i *3;
- Utils3D.transformVector3ArrayToVector3ArrayCoordinate(oriVertexes,oriOffset+positionOffset,worldMat,this._dynamicWorldPositions,bakeOffset);
- (normalOffset!==-1)&& (Utils3D.transformVector3ArrayByQuat(oriVertexes,oriOffset+normalOffset,rotation,this._dynamicWorldNormals,bakeOffset));
- }
- this._dynamicWorldPositionNormalNeedUpdate=false;
- }
- }
- /**
- *@inheritDoc
- */
- __proto.setTransform=function(transform){
- if (this._transform!==transform){
- (this._transform)&& (this._transform.off(/*laya.events.Event.TRANSFORM_CHANGED*/"transformchanged",this,this._onWorldMatrixChanged));
- (transform)&& (transform.on(/*laya.events.Event.TRANSFORM_CHANGED*/"transformchanged",this,this._onWorldMatrixChanged));
- this._dynamicWorldPositionNormalNeedUpdate=true;
- this._transform=transform;
- }
- }
- /**
- *@inheritDoc
- */
- __proto.setGeometry=function(geometry){
- if (this._geometry!==geometry){
- var subMesh=geometry;
- var mesh=subMesh._mesh;
- if (mesh){
- var multiSubMesh=mesh._subMeshCount > 1;
- var dynBatVerCount=multiSubMesh ? subMesh._indexCount :mesh._vertexCount;
- if (dynBatVerCount <=/*laya.d3.graphics.SubMeshDynamicBatch.maxAllowVertexCount*/10){
- var length=dynBatVerCount *3;
- this._dynamicVertexBatch=true;
- this._dynamicWorldPositions=new Float32Array(length);
- this._dynamicWorldNormals=new Float32Array(length);
- this._dynamicVertexCount=dynBatVerCount;
- this._dynamicMultiSubMesh=multiSubMesh;
- }else {
- this._dynamicVertexBatch=false;
- }
- }
- this._geometry=geometry;
- }
- }
- /**
- *@inheritDoc
- */
- __proto.addToOpaqueRenderQueue=function(context,queue){
- var subMeshStaticBatch=this.staticBatch;
- var elements=queue.elements;
- if (subMeshStaticBatch){
- var staManager=MeshRenderStaticBatchManager.instance;
- var staBatchMarks=staManager.getBatchOpaquaMark(this.render.lightmapIndex+1,this.render.receiveShadow,this.material.id,subMeshStaticBatch._batchID);
- if (staManager._updateCountMark===staBatchMarks.updateMark){
- var staBatchIndex=staBatchMarks.indexInList;
- if (staBatchMarks.batched){
- elements[staBatchIndex].staticBatchElementList.push(this);
- }else {
- var staOriElement=elements[staBatchIndex];
- var staOriRender=staOriElement.render;
- var staBatchElement=staManager._getBatchRenderElementFromPool();
- staBatchElement.renderType=/*laya.d3.core.render.RenderElement.RENDERTYPE_STATICBATCH*/1;
- staBatchElement.setGeometry(subMeshStaticBatch);
- staBatchElement.material=staOriElement.material;
- var staRootOwner=subMeshStaticBatch.batchOwner;
- var staBatchTransform=staRootOwner ? staRootOwner._transform :null;
- staBatchElement.setTransform(staBatchTransform);
- staBatchElement.render=staOriRender;
- var staBatchList=staBatchElement.staticBatchElementList;
- staBatchList.length=0;
- staBatchList.push(staOriElement);
- staBatchList.push(this);
- elements[staBatchIndex]=staBatchElement;
- staBatchMarks.batched=true;
- }
- }else {
- staBatchMarks.updateMark=staManager._updateCountMark;
- staBatchMarks.indexInList=elements.length;
- staBatchMarks.batched=false;
- elements.push(this);
- }
- }else if (this.material._shader._enableInstancing && WebGLContext._angleInstancedArrays){
- var subMesh=this._geometry;
- var insManager=MeshRenderDynamicBatchManager.instance;
- var insBatchMarks=insManager.getInstanceBatchOpaquaMark(this.render.lightmapIndex+1,this.render.receiveShadow,this.material.id,subMesh._id);
- if (insManager._updateCountMark===insBatchMarks.updateMark){
- var insBatchIndex=insBatchMarks.indexInList;
- if (insBatchMarks.batched){
- var instanceBatchElementList=elements[insBatchIndex].instanceBatchElementList;
- if (instanceBatchElementList.length===SubMeshInstanceBatch.instance.maxInstanceCount){
- insBatchMarks.updateMark=insManager._updateCountMark;
- insBatchMarks.indexInList=elements.length;
- insBatchMarks.batched=false;
- elements.push(this);
- }else {
- instanceBatchElementList.push(this);
- }
- }else {
- var insOriElement=elements[insBatchIndex];
- var insOriRender=insOriElement.render;
- var insBatchElement=insManager._getBatchRenderElementFromPool();
- insBatchElement.renderType=/*laya.d3.core.render.RenderElement.RENDERTYPE_INSTANCEBATCH*/2;
- insBatchElement.setGeometry(SubMeshInstanceBatch.instance);
- insBatchElement.material=insOriElement.material;
- insBatchElement.setTransform(null);
- insBatchElement.render=insOriRender;
- insBatchElement.instanceSubMesh=subMesh;
- var insBatchList=insBatchElement.instanceBatchElementList;
- insBatchList.length=0;
- insBatchList.push(insOriElement);
- insBatchList.push(this);
- elements[insBatchIndex]=insBatchElement;
- insBatchMarks.batched=true;
- }
- }else {
- insBatchMarks.updateMark=insManager._updateCountMark;
- insBatchMarks.indexInList=elements.length;
- insBatchMarks.batched=false;
- elements.push(this);
- }
- }else if (this._dynamicVertexBatch){
- var verDec=(this._geometry)._vertexBuffer.vertexDeclaration;
- var dynManager=MeshRenderDynamicBatchManager.instance;
- var dynBatchMarks=dynManager.getVertexBatchOpaquaMark(this.render.lightmapIndex+1,this.render.receiveShadow,this.material.id,verDec.id);
- if (dynManager._updateCountMark===dynBatchMarks.updateMark){
- var dynBatchIndex=dynBatchMarks.indexInList;
- if (dynBatchMarks.batched){
- elements[dynBatchIndex].vertexBatchElementList.push(this);
- }else {
- var dynOriElement=elements[dynBatchIndex];
- var dynOriRender=dynOriElement.render;
- var dynBatchElement=dynManager._getBatchRenderElementFromPool();
- dynBatchElement.renderType=/*laya.d3.core.render.RenderElement.RENDERTYPE_VERTEXBATCH*/3;
- dynBatchElement.setGeometry(SubMeshDynamicBatch.instance);
- dynBatchElement.material=dynOriElement.material;
- dynBatchElement.setTransform(null);
- dynBatchElement.render=dynOriRender;
- dynBatchElement.vertexBatchVertexDeclaration=verDec;
- var dynBatchList=dynBatchElement.vertexBatchElementList;
- dynBatchList.length=0;
- dynBatchList.push(dynOriElement);
- dynBatchList.push(this);
- elements[dynBatchIndex]=dynBatchElement;
- dynBatchMarks.batched=true;
- }
- }else {
- dynBatchMarks.updateMark=dynManager._updateCountMark;
- dynBatchMarks.indexInList=elements.length;
- dynBatchMarks.batched=false;
- elements.push(this);
- }
- }else {
- elements.push(this);
- }
- }
- /**
- *@inheritDoc
- */
- __proto.addToTransparentRenderQueue=function(context,queue){
- var subMeshStaticBatch=this.staticBatch;
- var elements=queue.elements;
- if (subMeshStaticBatch){
- var staManager=MeshRenderStaticBatchManager.instance;
- var staLastElement=queue.lastTransparentRenderElement;
- if (staLastElement){
- var staLastRender=staLastElement.render;
- if (staLastElement._geometry._getType()!==this._geometry._getType()|| staLastElement.staticBatch!==subMeshStaticBatch || staLastElement.material!==this.material || staLastRender.receiveShadow!==this.render.receiveShadow || staLastRender.lightmapIndex!==this.render.lightmapIndex){
- elements.push(this);
- queue.lastTransparentBatched=false;
- }else {
- if (queue.lastTransparentBatched){
- (elements [elements.length-1]).staticBatchElementList.push((this));
- }else {
- var staBatchElement=staManager._getBatchRenderElementFromPool();
- staBatchElement.renderType=/*laya.d3.core.render.RenderElement.RENDERTYPE_STATICBATCH*/1;
- staBatchElement.setGeometry(subMeshStaticBatch);
- staBatchElement.material=staLastElement.material;
- var staRootOwner=subMeshStaticBatch.batchOwner;
- var staBatchTransform=staRootOwner ? staRootOwner._transform :null;
- staBatchElement.setTransform(staBatchTransform);
- staBatchElement.render=this.render;
- var staBatchList=staBatchElement.staticBatchElementList;
- staBatchList.length=0;
- staBatchList.push(staLastElement);
- staBatchList.push(this);
- elements[elements.length-1]=staBatchElement;
- }
- queue.lastTransparentBatched=true;
- }
- }else {
- elements.push(this);
- queue.lastTransparentBatched=false;
- }
- }else if (this.material._shader._enableInstancing && WebGLContext._angleInstancedArrays){
- var subMesh=this._geometry;
- var insManager=MeshRenderDynamicBatchManager.instance;
- var insLastElement=queue.lastTransparentRenderElement;
- if (insLastElement){
- var insLastRender=insLastElement.render;
- if (insLastElement._geometry._getType()!==this._geometry._getType()|| (insLastElement._geometry)!==subMesh || insLastElement.material!==this.material || insLastRender.receiveShadow!==this.render.receiveShadow || insLastRender.lightmapIndex!==this.render.lightmapIndex){
- elements.push(this);
- queue.lastTransparentBatched=false;
- }else {
- if (queue.lastTransparentBatched){
- (elements [elements.length-1]).instanceBatchElementList.push((this));
- }else {
- var insBatchElement=insManager._getBatchRenderElementFromPool();
- insBatchElement.renderType=/*laya.d3.core.render.RenderElement.RENDERTYPE_INSTANCEBATCH*/2;
- insBatchElement.setGeometry(SubMeshInstanceBatch.instance);
- insBatchElement.material=insLastElement.material;
- insBatchElement.setTransform(null);
- insBatchElement.render=this.render;
- insBatchElement.instanceSubMesh=subMesh;
- var insBatchList=insBatchElement.instanceBatchElementList;
- insBatchList.length=0;
- insBatchList.push(insLastElement);
- insBatchList.push(this);
- elements[elements.length-1]=insBatchElement;
- }
- queue.lastTransparentBatched=true;
- }
- }else {
- elements.push(this);
- queue.lastTransparentBatched=false;
- }
- }else if (this._dynamicVertexBatch){
- var verDec=(this._geometry)._vertexBuffer.vertexDeclaration;
- var dynManager=MeshRenderDynamicBatchManager.instance;
- var dynLastElement=queue.lastTransparentRenderElement;
- if (dynLastElement){
- var dynLastRender=dynLastElement.render;
- 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){
- elements.push(this);
- queue.lastTransparentBatched=false;
- }else {
- if (queue.lastTransparentBatched){
- (elements [elements.length-1]).vertexBatchElementList.push((this));
- }else {
- var dynBatchElement=dynManager._getBatchRenderElementFromPool();
- dynBatchElement.renderType=/*laya.d3.core.render.RenderElement.RENDERTYPE_VERTEXBATCH*/3;
- dynBatchElement.setGeometry(SubMeshDynamicBatch.instance);
- dynBatchElement.material=dynLastElement.material;
- dynBatchElement.setTransform(null);
- dynBatchElement.render=this.render;
- dynBatchElement.vertexBatchVertexDeclaration=verDec;
- var dynBatchList=dynBatchElement.vertexBatchElementList;
- dynBatchList.length=0;
- dynBatchList.push(dynLastElement);
- dynBatchList.push(this);
- elements[elements.length-1]=dynBatchElement;
- }
- queue.lastTransparentBatched=true;
- }
- }else {
- elements.push(this);
- queue.lastTransparentBatched=false;
- }
- }else {
- elements.push(this);
- }
- queue.lastTransparentRenderElement=this;
- }
- /**
- *@inheritDoc
- */
- __proto.destroy=function(){
- _super.prototype.destroy.call(this);
- this._dynamicWorldPositions=null;
- this._dynamicWorldNormals=null;
- this.staticBatch=null;
- this.staticBatchElementList=null;
- this.vertexBatchElementList=null;
- this.vertexBatchVertexDeclaration=null;
- }
- SubMeshRenderElement._maxInstanceCount=1024;
- __static(SubMeshRenderElement,
- ['_instanceMatrixData',function(){return this._instanceMatrixData=new Float32Array(SubMeshRenderElement._maxInstanceCount *16);},'_instanceMatrixBuffer',function(){return this._instanceMatrixBuffer=new VertexBuffer3D(SubMeshRenderElement._instanceMatrixData.length *4,/*laya.webgl.WebGLContext.DYNAMIC_DRAW*/0x88E8);}
- ]);
- return SubMeshRenderElement;
- })(RenderElement)
- /**
- *<code>VertexShurikenParticle</code> 类用于创建粒子顶点结构。
- */
- //class laya.d3.graphics.Vertex.VertexShurikenParticleMesh extends laya.d3.graphics.Vertex.VertexShuriKenParticle
- var VertexShurikenParticleMesh=(function(_super){
- function VertexShurikenParticleMesh(cornerTextureCoordinate,positionStartLifeTime,velocity,startColor,startSize,startRotation0,startRotation1,startRotation2,ageAddScale,time,startSpeed,randoms0,randoms1,simulationWorldPostion){
- /**@private */
- this._cornerTextureCoordinate=null;
- /**@private */
- this._positionStartLifeTime=null;
- /**@private */
- this._velocity=null;
- /**@private */
- this._startColor=null;
- /**@private */
- this._startSize=null;
- /**@private */
- this._startRotation0=null;
- /**@private */
- this._startRotation1=null;
- /**@private */
- this._startRotation2=null;
- /**@private */
- this._startLifeTime=NaN;
- /**@private */
- this._time=NaN;
- /**@private */
- this._startSpeed=NaN;
- /**@private */
- this._randoms0=null;
- /**@private */
- this._randoms1=null;
- /**@private */
- this._simulationWorldPostion=null;
- VertexShurikenParticleMesh.__super.call(this);
- this._cornerTextureCoordinate=cornerTextureCoordinate;
- this._positionStartLifeTime=positionStartLifeTime;
- this._velocity=velocity;
- this._startColor=startColor;
- this._startSize=startSize;
- this._startRotation0=startRotation0;
- this._startRotation1=startRotation1;
- this._startRotation2=startRotation2;
- this._startLifeTime=ageAddScale;
- this._time=time;
- this._startSpeed=startSpeed;
- this._randoms0=this.random0;
- this._randoms1=this.random1;
- this._simulationWorldPostion=simulationWorldPostion;
- }
- __class(VertexShurikenParticleMesh,'laya.d3.graphics.Vertex.VertexShurikenParticleMesh',_super);
- var __proto=VertexShurikenParticleMesh.prototype;
- __getset(0,__proto,'cornerTextureCoordinate',function(){
- return this._cornerTextureCoordinate;
- });
- __getset(0,__proto,'velocity',function(){
- return this._velocity;
- });
- __getset(0,__proto,'position',function(){
- return this._positionStartLifeTime;
- });
- __getset(0,__proto,'random0',function(){
- return this._randoms0;
- });
- __getset(0,__proto,'startSize',function(){
- return this._startSize;
- });
- __getset(0,__proto,'startColor',function(){
- return this._startColor;
- });
- __getset(0,__proto,'startRotation0',function(){
- return this._startRotation0;
- });
- __getset(0,__proto,'startRotation1',function(){
- return this._startRotation1;
- });
- __getset(0,__proto,'random1',function(){
- return this._randoms1;
- });
- __getset(0,__proto,'startRotation2',function(){
- return this._startRotation2;
- });
- __getset(0,__proto,'startLifeTime',function(){
- return this._startLifeTime;
- });
- __getset(0,__proto,'time',function(){
- return this._time;
- });
- __getset(0,__proto,'startSpeed',function(){
- return this._startSpeed;
- });
- __getset(0,__proto,'simulationWorldPostion',function(){
- return this._simulationWorldPostion;
- });
- __getset(1,VertexShurikenParticleMesh,'vertexDeclaration',function(){
- return VertexShurikenParticleMesh._vertexDeclaration;
- },laya.d3.graphics.Vertex.VertexShuriKenParticle._$SET_vertexDeclaration);
- __static(VertexShurikenParticleMesh,
- ['_vertexDeclaration',function(){return this._vertexDeclaration=new VertexDeclaration(172,[
- new VertexElement(0,/*laya.d3.graphics.VertexElementFormat.Vector3*/"vector3",/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_POSITION0*/1),
- new VertexElement(12,/*laya.d3.graphics.VertexElementFormat.Vector4*/"vector4",/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_COLOR0*/2),
- new VertexElement(28,/*laya.d3.graphics.VertexElementFormat.Vector2*/"vector2",/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_TEXTURECOORDINATE0*/3),
- new VertexElement(36,/*laya.d3.graphics.VertexElementFormat.Vector4*/"vector4",/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_SHAPEPOSITIONSTARTLIFETIME*/4),
- new VertexElement(52,/*laya.d3.graphics.VertexElementFormat.Vector4*/"vector4",/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_DIRECTIONTIME*/5),
- new VertexElement(68,/*laya.d3.graphics.VertexElementFormat.Vector4*/"vector4",/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_STARTCOLOR0*/6),
- new VertexElement(84,/*laya.d3.graphics.VertexElementFormat.Vector3*/"vector3",/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_STARTSIZE*/8),
- new VertexElement(96,/*laya.d3.graphics.VertexElementFormat.Vector3*/"vector3",/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_STARTROTATION*/9),
- new VertexElement(108,/*laya.d3.graphics.VertexElementFormat.Single*/"single",/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_STARTSPEED*/10),
- new VertexElement(112,/*laya.d3.graphics.VertexElementFormat.Vector4*/"vector4",/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_RANDOM0*/11),
- new VertexElement(128,/*laya.d3.graphics.VertexElementFormat.Vector4*/"vector4",/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_RANDOM1*/12),
- new VertexElement(144,/*laya.d3.graphics.VertexElementFormat.Vector3*/"vector3",/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_SIMULATIONWORLDPOSTION*/13),
- new VertexElement(156,/*laya.d3.graphics.VertexElementFormat.Vector4*/"vector4",/*laya.d3.graphics.Vertex.VertexShuriKenParticle.PARTICLE_SIMULATIONWORLDROTATION*/14)]);}
- ]);
- return VertexShurikenParticleMesh;
- })(VertexShuriKenParticle)
- /**
- *<code>Sprite3D</code> 类用于实现3D精灵。
- */
- //class laya.d3.core.Sprite3D extends laya.display.Node
- var Sprite3D=(function(_super){
- function Sprite3D(name,isStatic){
- /**@private */
- //this._id=0;
- /**@private */
- //this._url=null;
- /**@private */
- //this._isStatic=false;
- /**@private */
- //this._layer=0;
- /**@private */
- //this._scripts=null;
- /**@private */
- //this._transform=null;
- /**@private */
- //this._hierarchyAnimator=null;
- /**@private */
- this._needProcessCollisions=false;
- /**@private */
- this._needProcessTriggers=false;
- Sprite3D.__super.call(this);
- (isStatic===void 0)&& (isStatic=false);
- this._id=++Sprite3D._uniqueIDCounter;
- this._transform=new Transform3D(this);
- this._isStatic=isStatic;
- this.layer=0;
- this.name=name ? name :"New Sprite3D";
- }
- __class(Sprite3D,'laya.d3.core.Sprite3D',_super);
- var __proto=Sprite3D.prototype;
- Laya.imps(__proto,{"laya.resource.ICreateResource":true})
- /**
- *@private
- */
- __proto._setCreateURL=function(url){
- this._url=URL.formatURL(url);
- }
- /**
- *@private
- */
- __proto._changeAnimatorsToLinkSprite3D=function(sprite3D,isLink,path){
- var animator=this.getComponent(Animator);
- if (animator){
- if (!animator.avatar)
- sprite3D._changeAnimatorToLinkSprite3DNoAvatar(animator,isLink,path);
- }
- if (this._parent && (this._parent instanceof laya.d3.core.Sprite3D )){
- path.unshift(this._parent.name);
- var p=this._parent;
- (p._hierarchyAnimator)&& (p._changeAnimatorsToLinkSprite3D(sprite3D,isLink,path));
- }
- }
- /**
- *@private
- */
- __proto._setHierarchyAnimator=function(animator,parentAnimator){
- this._changeHierarchyAnimator(animator);
- this._changeAnimatorAvatar(animator.avatar);
- for (var i=0,n=this._children.length;i < n;i++){
- var child=this._children[i];
- (child._hierarchyAnimator==parentAnimator)&& (child._setHierarchyAnimator(animator,parentAnimator));
- }
- }
- /**
- *@private
- */
- __proto._clearHierarchyAnimator=function(animator,parentAnimator){
- this._changeHierarchyAnimator(parentAnimator);
- this._changeAnimatorAvatar(parentAnimator ? parentAnimator.avatar :null);
- for (var i=0,n=this._children.length;i < n;i++){
- var child=this._children[i];
- (child._hierarchyAnimator==animator)&& (child._clearHierarchyAnimator(animator,parentAnimator));
- }
- }
- /**
- *@private
- */
- __proto._changeHierarchyAnimatorAvatar=function(animator,avatar){
- this._changeAnimatorAvatar(avatar);
- for (var i=0,n=this._children.length;i < n;i++){
- var child=this._children[i];
- (child._hierarchyAnimator==animator)&& (child._changeHierarchyAnimatorAvatar(animator,avatar));
- }
- }
- /**
- *@private
- */
- __proto._changeAnimatorToLinkSprite3DNoAvatar=function(animator,isLink,path){
- animator._handleSpriteOwnersBySprite(isLink,path,this);
- for (var i=0,n=this._children.length;i < n;i++){
- var child=this._children[i];
- var index=path.length;
- path.push(child.name);
- child._changeAnimatorToLinkSprite3DNoAvatar(animator,isLink,path);
- path.splice(index,1);
- }
- }
- /**
- *@private
- */
- __proto._changeHierarchyAnimator=function(animator){
- this._hierarchyAnimator=animator;
- }
- /**
- *@private
- */
- __proto._changeAnimatorAvatar=function(avatar){}
- /**
- *@inheritDoc
- */
- __proto._onAdded=function(){
- if ((this._parent instanceof laya.d3.core.Sprite3D )){
- var parent3D=this._parent;
- this.transform._setParent(parent3D.transform);
- if (parent3D._hierarchyAnimator){
- (!this._hierarchyAnimator)&& (this._setHierarchyAnimator(parent3D._hierarchyAnimator,null));
- parent3D._changeAnimatorsToLinkSprite3D(this,true,/*new vector.<>*/[this.name]);
- }
- }
- _super.prototype._onAdded.call(this);
- }
- /**
- *@inheritDoc
- */
- __proto._onRemoved=function(){
- _super.prototype._onRemoved.call(this);
- if ((this._parent instanceof laya.d3.core.Sprite3D )){
- var parent3D=this._parent;
- this.transform._setParent(null);
- if (parent3D._hierarchyAnimator){
- (this._hierarchyAnimator==parent3D._hierarchyAnimator)&& (this._clearHierarchyAnimator(parent3D._hierarchyAnimator,null));
- parent3D._changeAnimatorsToLinkSprite3D(this,false,/*new vector.<>*/[this.name]);
- }
- }
- }
- /**
- *@inheritDoc
- */
- __proto._parse=function(data,spriteMap){
- (data.isStatic!==undefined)&& (this._isStatic=data.isStatic);
- (data.active!==undefined)&& (this.active=data.active);
- (data.name !=undefined)&& (this.name=data.name);
- if (data.position!==undefined){
- var loccalPosition=this.transform.localPosition;
- loccalPosition.fromArray(data.position);
- this.transform.localPosition=loccalPosition;
- }
- if (data.rotationEuler!==undefined){
- var localRotationEuler=this.transform.localRotationEuler;
- localRotationEuler.fromArray(data.rotationEuler);
- this.transform.localRotationEuler=localRotationEuler;
- }
- if (data.rotation!==undefined){
- var localRotation=this.transform.localRotation;
- localRotation.fromArray(data.rotation);
- this.transform.localRotation=localRotation;
- }
- if (data.scale!==undefined){
- var localScale=this.transform.localScale;
- localScale.fromArray(data.scale);
- this.transform.localScale=localScale;
- }
- (data.layer !=undefined)&& (this.layer=data.layer);
- }
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto._cloneTo=function(destObject,srcRoot,dstRoot){
- if (this.destroyed)
- throw new Error("Sprite3D: Can't be cloned if the Sprite3D has destroyed.");
- var destSprite3D=destObject;
- destSprite3D.name=this.name;
- destSprite3D.destroyed=this.destroyed;
- destSprite3D.active=this.active;
- var destLocalPosition=destSprite3D.transform.localPosition;
- this.transform.localPosition.cloneTo(destLocalPosition);
- destSprite3D.transform.localPosition=destLocalPosition;
- var destLocalRotation=destSprite3D.transform.localRotation;
- this.transform.localRotation.cloneTo(destLocalRotation);
- destSprite3D.transform.localRotation=destLocalRotation;
- var destLocalScale=destSprite3D.transform.localScale;
- this.transform.localScale.cloneTo(destLocalScale);
- destSprite3D.transform.localScale=destLocalScale;
- destSprite3D._isStatic=this._isStatic;
- destSprite3D.layer=this.layer;
- _super.prototype._cloneTo.call(this,destSprite3D,srcRoot,dstRoot);
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var dstSprite3D=Sprite3D._createSprite3DInstance(this);
- Sprite3D._parseSprite3DInstance(this,dstSprite3D,this,dstSprite3D);
- return dstSprite3D;
- }
- /**
- *@inheritDoc
- */
- __proto.destroy=function(destroyChild){
- (destroyChild===void 0)&& (destroyChild=true);
- if (this.destroyed)
- return;
- _super.prototype.destroy.call(this,destroyChild);
- this._transform=null;
- this._scripts=null;
- this._url && Loader.clearRes(this._url);
- }
- /**
- *获取唯一标识ID。
- *@return 唯一标识ID。
- */
- __getset(0,__proto,'id',function(){
- return this._id;
- });
- /**
- *获取资源的URL地址。
- *@return URL地址。
- */
- __getset(0,__proto,'url',function(){
- return this._url;
- });
- /**
- *设置蒙版。
- *@param value 蒙版。
- */
- /**
- *获取蒙版。
- *@return 蒙版。
- */
- __getset(0,__proto,'layer',function(){
- return this._layer;
- },function(value){
- if (this._layer!==value){
- if (value >=0 && value <=30){
- this._layer=value;
- }else {
- throw new Error("Layer value must be 0-30.");
- }
- }
- });
- /**
- *获取精灵变换。
- *@return 精灵变换。
- */
- __getset(0,__proto,'transform',function(){
- return this._transform;
- });
- /**
- *获取是否为静态。
- *@return 是否为静态。
- */
- __getset(0,__proto,'isStatic',function(){
- return this._isStatic;
- });
- Sprite3D._parse=function(data,propertyParams,constructParams){
- var json=data.data;
- var outBatchSprits=[];
- var sprite;
- switch (data.version){
- case "LAYAHIERARCHY:02":
- sprite=Utils3D._createNodeByJson02(json,outBatchSprits);
- break ;
- default :
- sprite=Utils3D._createNodeByJson(json,outBatchSprits);
- }
- StaticBatchManager.combine(sprite,outBatchSprits);
- return sprite;
- }
- Sprite3D.__init__=function(){}
- Sprite3D.instantiate=function(original,parent,worldPositionStays,position,rotation){
- (worldPositionStays===void 0)&& (worldPositionStays=true);
- var destSprite3D=original.clone();
- (parent)&& (parent.addChild(destSprite3D));
- var transform=destSprite3D.transform;
- if (worldPositionStays){
- var worldMatrix=transform.worldMatrix;
- original.transform.worldMatrix.cloneTo(worldMatrix);
- transform.worldMatrix=worldMatrix;
- }else {
- (position)&& (transform.position=position);
- (rotation)&& (transform.rotation=rotation);
- }
- return destSprite3D;
- }
- Sprite3D.load=function(url,complete){
- Laya.loader.create(url,complete,null,/*Laya3D.HIERARCHY*/"HIERARCHY");
- }
- Sprite3D._createSprite3DInstance=function(scrSprite){
- var node=/*__JS__ */new scrSprite.constructor();
- var children=scrSprite._children;
- for (var i=0,n=children.length;i < n;i++){
- var child=Sprite3D._createSprite3DInstance(children[i])
- node.addChild(child);
- }
- return node;
- }
- Sprite3D._parseSprite3DInstance=function(srcRoot,dstRoot,scrSprite,dstSprite){
- var srcChildren=scrSprite._children;
- var dstChildren=dstSprite._children;
- for (var i=0,n=srcChildren.length;i < n;i++)
- Sprite3D._parseSprite3DInstance(srcRoot,dstRoot,srcChildren[i],dstChildren[i])
- scrSprite._cloneTo(dstSprite,srcRoot,dstRoot);
- }
- Sprite3D._uniqueIDCounter=0;
- __static(Sprite3D,
- ['WORLDMATRIX',function(){return this.WORLDMATRIX=Shader3D.propertyNameToID("u_WorldMat");},'MVPMATRIX',function(){return this.MVPMATRIX=Shader3D.propertyNameToID("u_MvpMatrix");}
- ]);
- return Sprite3D;
- })(Node)
- /**
- *<code>BaseMaterial</code> 类用于创建材质,抽象类,不允许实例。
- */
- //class laya.d3.core.material.BaseMaterial extends laya.resource.Resource
- var BaseMaterial=(function(_super){
- function BaseMaterial(){
- /**@private */
- //this._alphaTest=false;
- /**@private */
- //this._defineDatas=null;
- /**@private */
- //this._disablePublicDefineDatas=null;
- /**@private */
- //this._shader=null;
- /**@private */
- this._shaderValues=null;
- /**所属渲染队列. */
- //this.renderQueue=0;
- BaseMaterial.__super.call(this);
- this._defineDatas=new DefineDatas();
- this._disablePublicDefineDatas=new DefineDatas();
- this._shaderValues=new ShaderData(this);
- this.renderQueue=/*CLASS CONST:laya.d3.core.material.BaseMaterial.RENDERQUEUE_OPAQUE*/2000;
- this._alphaTest=false;
- }
- __class(BaseMaterial,'laya.d3.core.material.BaseMaterial',_super);
- var __proto=BaseMaterial.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *@private
- */
- __proto._removeTetxureReference=function(){
- var data=this._shaderValues.getData();
- for (var k in data){
- var value=data[k];
- if (value && (value instanceof laya.resource.BaseTexture ))
- (value)._removeReference();
- }
- }
- /**
- *@inheritDoc
- */
- __proto._addReference=function(count){
- (count===void 0)&& (count=1);
- _super.prototype._addReference.call(this,count);
- var data=this._shaderValues.getData();
- for (var k in data){
- var value=data[k];
- if (value && (value instanceof laya.resource.BaseTexture ))
- (value)._addReference();
- }
- }
- /**
- *@inheritDoc
- */
- __proto._removeReference=function(count){
- (count===void 0)&& (count=1);
- _super.prototype._removeReference.call(this,count);
- this._removeTetxureReference();
- }
- /**
- *@inheritDoc
- */
- __proto._disposeResource=function(){
- if (this._referenceCount > 0)
- this._removeTetxureReference();
- this._shaderValues=null;
- }
- /**
- *设置使用Shader名字。
- *@param name 名称。
- */
- __proto.setShaderName=function(name){
- this._shader=Shader3D.find(name);
- if (!this._shader)
- throw new Error("BaseMaterial: unknown shader name.");
- }
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var destBaseMaterial=destObject;
- destBaseMaterial.name=this.name;
- destBaseMaterial.renderQueue=this.renderQueue;
- this._disablePublicDefineDatas.cloneTo(destBaseMaterial._disablePublicDefineDatas);
- this._defineDatas.cloneTo(destBaseMaterial._defineDatas);
- this._shaderValues.cloneTo(destBaseMaterial._shaderValues);
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var dest=/*__JS__ */new this.constructor();
- this.cloneTo(dest);
- return dest;
- }
- /**
- *设置透明测试模式裁剪值。
- *@param value 透明测试模式裁剪值。
- */
- /**
- *获取透明测试模式裁剪值。
- *@return 透明测试模式裁剪值。
- */
- __getset(0,__proto,'alphaTestValue',function(){
- return this._shaderValues.getNumber(BaseMaterial.ALPHATESTVALUE);
- },function(value){
- this._shaderValues.setNumber(BaseMaterial.ALPHATESTVALUE,value);
- });
- /**
- *设置是否透明裁剪。
- *@param value 是否透明裁剪。
- */
- /**
- *获取是否透明裁剪。
- *@return 是否透明裁剪。
- */
- __getset(0,__proto,'alphaTest',function(){
- return this._alphaTest;
- },function(value){
- this._alphaTest=value;
- if (value)
- this._defineDatas.add(laya.d3.core.material.BaseMaterial.SHADERDEFINE_ALPHATEST);
- else
- this._defineDatas.remove(laya.d3.core.material.BaseMaterial.SHADERDEFINE_ALPHATEST);
- });
- BaseMaterial.load=function(url,complete){
- Laya.loader.create(url,complete,null,/*Laya3D.MATERIAL*/"MATERIAL");
- }
- BaseMaterial.__init__=function(){
- BaseMaterial.SHADERDEFINE_ALPHATEST=BaseMaterial.shaderDefines.registerDefine("ALPHATEST");
- }
- BaseMaterial._parse=function(data,propertyParams,constructParams){
- var jsonData=data;
- var props=jsonData.props;
- var material;
- var classType=props.type;
- var clasPaths=classType.split('.');
- var clas=Browser.window;
- clasPaths.forEach(function(cls){
- clas=clas[cls];
- });
- if (typeof(clas)=='function')
- material=new clas();
- else
- throw('_getSprite3DHierarchyInnerUrls 错误: '+data.type+' 不是类');
- switch (jsonData.version){
- case "LAYAMATERIAL:01":
- case "LAYAMATERIAL:02":;
- var i=0,n=0;
- for (var key in props){
- switch (key){
- case "vectors":;
- var vectors=props[key];
- for (i=0,n=vectors.length;i < n;i++){
- var vector=vectors[i];
- var vectorValue=vector.value;
- switch (vectorValue.length){
- case 2:
- material[vector.name]=new Vector2(vectorValue[0],vectorValue[1]);
- break ;
- case 3:
- material[vector.name]=new Vector3(vectorValue[0],vectorValue[1],vectorValue[2]);
- break ;
- case 4:
- material[vector.name]=new Vector4(vectorValue[0],vectorValue[1],vectorValue[2],vectorValue[3]);
- break ;
- default :
- throw new Error("BaseMaterial:unkonwn color length.");
- }
- }
- break ;
- case "textures":;
- var textures=props[key];
- for (i=0,n=textures.length;i < n;i++){
- var texture=textures[i];
- var path=texture.path;
- (path)&& (material[texture.name]=Loader.getRes(path));
- }
- break ;
- case "defines":;
- var defineNames=props[key];
- for (i=0,n=defineNames.length;i < n;i++){
- var define=material._shader.getSubShaderAt(0).getMaterialDefineByName(defineNames[i]);
- material._defineDatas.add(define);
- }
- break ;
- case "renderStates":;
- var renderStatesData=props[key];
- var renderStateData=renderStatesData[0];
- var mat=material;
- mat.blend=renderStateData.blend;
- mat.cull=renderStateData.cull;
- mat.depthTest=renderStateData.depthTest;
- mat.depthWrite=renderStateData.depthWrite;
- mat.blendSrc=renderStateData.srcBlend;
- mat.blendDst=renderStateData.dstBlend;
- break ;
- case "cull":
- (material).cull=props[key];
- break ;
- case "blend":
- (material).blend=props[key];
- break ;
- case "depthWrite":
- (material).depthWrite=props[key];
- break ;
- case "srcBlend":
- (material).blendSrc=props[key];
- break ;
- case "dstBlend":
- (material).blendDst=props[key];
- break ;
- default :
- material[key]=props[key];
- }
- }
- break ;
- default :
- throw new Error("BaseMaterial:unkonwn version.");
- }
- return material;
- }
- BaseMaterial.RENDERQUEUE_OPAQUE=2000;
- BaseMaterial.RENDERQUEUE_ALPHATEST=2450;
- BaseMaterial.RENDERQUEUE_TRANSPARENT=3000;
- BaseMaterial.SHADERDEFINE_ALPHATEST=0;
- __static(BaseMaterial,
- ['ALPHATESTVALUE',function(){return this.ALPHATESTVALUE=Shader3D.propertyNameToID("u_AlphaTestValue");},'shaderDefines',function(){return this.shaderDefines=new ShaderDefines();}
- ]);
- return BaseMaterial;
- })(Resource)
- /**
- *<code>ScreenQuad</code> 类用于创建全屏四边形。
- */
- //class laya.d3.core.render.ScreenQuad extends laya.resource.Resource
- var ScreenQuad=(function(_super){
- function ScreenQuad(){
- /**@private */
- this._vertexBuffer=null;
- ScreenQuad.__super.call(this);
- this._bufferState=new BufferState();
- this._vertexBuffer=new VertexBuffer3D(16 *4,/*laya.webgl.WebGLContext.STATIC_DRAW*/0x88E4,false);
- this._vertexBuffer.vertexDeclaration=laya.d3.core.render.ScreenQuad._vertexDeclaration;
- this._vertexBuffer.setData(ScreenQuad._vertices);
- this._bufferState.bind();
- this._bufferState.applyVertexBuffer(this._vertexBuffer);
- this._bufferState.unBind();
- this._setGPUMemory(this._vertexBuffer._byteLength);
- }
- __class(ScreenQuad,'laya.d3.core.render.ScreenQuad',_super);
- var __proto=ScreenQuad.prototype;
- /**
- *@private
- */
- __proto.render=function(){
- this._bufferState.bind();
- LayaGL.instance.drawArrays(/*laya.webgl.WebGLContext.TRIANGLE_STRIP*/0x0005,0,4);
- Stat.renderBatches++;
- }
- /**
- *@inheritDoc
- */
- __proto.destroy=function(){
- _super.prototype.destroy.call(this);
- this._bufferState.destroy();
- this._vertexBuffer.destroy();
- this._setGPUMemory(0);
- }
- ScreenQuad.__init__=function(){
- ScreenQuad.instance=new ScreenQuad();
- ScreenQuad.instance.lock=true;
- }
- ScreenQuad.SCREENQUAD_POSITION_UV=0;
- ScreenQuad.instance=null;
- __static(ScreenQuad,
- ['_vertexDeclaration',function(){return this._vertexDeclaration=new VertexDeclaration(16,[new VertexElement(0,/*laya.d3.graphics.VertexElementFormat.Vector4*/"vector4",/*CLASS CONST:laya.d3.core.render.ScreenQuad.SCREENQUAD_POSITION_UV*/0)]);},'_vertices',function(){return this._vertices=new Float32Array([1,1,1,0,1,-1,1,1,-1,1,0,0,-1,-1,0,1]);}
- ]);
- return ScreenQuad;
- })(Resource)
- /**
- *<code>Avatar</code> 类用于创建Avatar。
- */
- //class laya.d3.core.Avatar extends laya.resource.Resource
- var Avatar=(function(_super){
- function Avatar(){
- /**@private */
- this._rootNode=null;
- /**@private [NATIVE]*/
- this._nativeNodeCount=0;
- /**@private [NATIVE]*/
- this._nativeCurCloneCount=0;
- Avatar.__super.call(this);
- }
- __class(Avatar,'laya.d3.core.Avatar',_super);
- var __proto=Avatar.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *@private
- */
- __proto._initCloneToAnimator=function(destNode,destAnimator){
- destAnimator._avatarNodeMap[destNode.name]=destNode;
- for (var i=0,n=destNode.getChildCount();i < n;i++)
- this._initCloneToAnimator(destNode.getChildByIndex(i),destAnimator);
- }
- /**
- *@private
- */
- __proto._parseNode=function(nodaData,node){
- var name=nodaData.props.name;
- node.name=name;
- var props=nodaData.props;
- var transform=node.transform;
- var pos=transform.localPosition;
- var rot=transform.localRotation;
- var sca=transform.localScale;
- pos.fromArray(props.translate);
- rot.fromArray(props.rotation);
- sca.fromArray(props.scale);
- transform.localPosition=pos;
- transform.localRotation=rot;
- transform.localScale=sca;
- var childrenData=nodaData.child;
- for (var j=0,n=childrenData.length;j < n;j++){
- var childData=childrenData[j];
- var childBone=new AnimationNode(new Float32Array(3),new Float32Array(4),new Float32Array(3),new Float32Array(16));
- node.addChild(childBone);
- if (Render.supportWebGLPlusAnimation)
- this._nativeNodeCount++;
- this._parseNode(childData,childBone);
- }
- }
- /**
- *克隆数据到Avatr。
- *@param destObject 克隆源。
- */
- __proto._cloneDatasToAnimator=function(destAnimator){
- var destRoot;
- destRoot=this._rootNode.clone();
- var transform=this._rootNode.transform;
- var destTransform=destRoot.transform;
- var destPosition=destTransform.localPosition;
- var destRotation=destTransform.localRotation;
- var destScale=destTransform.localScale;
- transform.localPosition.cloneTo(destPosition);
- transform.localRotation.cloneTo(destRotation);
- transform.localScale.cloneTo(destScale);
- destTransform.localPosition=destPosition;
- destTransform.localRotation=destRotation;
- destTransform.localScale=destScale;
- destAnimator._avatarNodeMap={};
- this._initCloneToAnimator(destRoot,destAnimator);
- }
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var destAvatar=destObject;
- var destRoot=this._rootNode.clone();
- destAvatar._rootNode=destRoot;
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var dest=/*__JS__ */new this.constructor();
- this.cloneTo(dest);
- return dest;
- }
- /**
- *@private [NATIVE]
- */
- __proto._cloneDatasToAnimatorNative=function(destAnimator){
- var animationNodeLocalPositions=new Float32Array(this._nativeNodeCount *3);
- var animationNodeLocalRotations=new Float32Array(this._nativeNodeCount *4);
- var animationNodeLocalScales=new Float32Array(this._nativeNodeCount *3);
- var animationNodeWorldMatrixs=new Float32Array(this._nativeNodeCount *16);
- var animationNodeParentIndices=new Int16Array(this._nativeNodeCount);
- destAnimator._animationNodeLocalPositions=animationNodeLocalPositions;
- destAnimator._animationNodeLocalRotations=animationNodeLocalRotations;
- destAnimator._animationNodeLocalScales=animationNodeLocalScales;
- destAnimator._animationNodeWorldMatrixs=animationNodeWorldMatrixs;
- destAnimator._animationNodeParentIndices=animationNodeParentIndices;
- this._nativeCurCloneCount=0;
- var destRoot=this._rootNode._cloneNative(animationNodeLocalPositions,animationNodeLocalRotations,animationNodeLocalScales,animationNodeWorldMatrixs,animationNodeParentIndices,-1,this);
- var transform=this._rootNode.transform;
- var destTransform=destRoot.transform;
- var destPosition=destTransform.localPosition;
- var destRotation=destTransform.localRotation;
- var destScale=destTransform.localScale;
- transform.localPosition.cloneTo(destPosition);
- transform.localRotation.cloneTo(destRotation);
- transform.localScale.cloneTo(destScale);
- destTransform.localPosition=destPosition;
- destTransform.localRotation=destRotation;
- destTransform.localScale=destScale;
- destAnimator._avatarNodeMap={};
- this._initCloneToAnimator(destRoot,destAnimator);
- }
- Avatar._parse=function(data,propertyParams,constructParams){
- var avatar=new Avatar();
- avatar._rootNode=new AnimationNode(new Float32Array(3),new Float32Array(4),new Float32Array(3),new Float32Array(16));
- if (Render.supportWebGLPlusAnimation)
- avatar._nativeNodeCount++;
- if (data.version){
- var rootNode=data.rootNode;
- (rootNode)&& (avatar._parseNode(rootNode,avatar._rootNode));
- }
- return avatar;
- }
- Avatar.load=function(url,complete){
- Laya.loader.create(url,complete,null,/*Laya3D.AVATAR*/"AVATAR");
- }
- return Avatar;
- })(Resource)
- /**
- *<code>Mesh</code> 类用于创建文件网格数据模板。
- */
- //class laya.d3.resource.models.Mesh extends laya.resource.Resource
- var Mesh=(function(_super){
- function Mesh(){
- /**@private */
- this._nativeTriangleMesh=null;
- /**@private */
- this._bounds=null;
- /**@private */
- this._subMeshCount=0;
- /**@private */
- this._subMeshes=null;
- /**@private */
- this._vertexBuffers=null;
- /**@private */
- this._indexBuffer=null;
- /**@private */
- this._boneNames=null;
- /**@private */
- this._inverseBindPoses=null;
- /**@private */
- this._inverseBindPosesBuffer=null;
- /**@private */
- this._bindPoseIndices=null;
- /**@private */
- this._skinDataPathMarks=null;
- /**@private */
- this._vertexCount=0;
- this._tempVector30=new Vector3()
- this._tempVector31=new Vector3();
- this._tempVector32=new Vector3();
- this._bufferState=new BufferState();
- this._instanceBufferState=new BufferState();
- Mesh.__super.call(this);
- this._subMeshes=[];
- this._vertexBuffers=[];
- this._skinDataPathMarks=[];
- }
- __class(Mesh,'laya.d3.resource.models.Mesh',_super);
- var __proto=Mesh.prototype;
- Laya.imps(__proto,{"laya.d3.core.IClone":true})
- /**
- *@private
- */
- __proto._getPositionElement=function(vertexBuffer){
- var vertexElements=vertexBuffer.vertexDeclaration.vertexElements;
- for (var i=0,n=vertexElements.length;i < n;i++){
- var vertexElement=vertexElements[i];
- if (vertexElement.elementFormat===/*laya.d3.graphics.VertexElementFormat.Vector3*/"vector3" && vertexElement.elementUsage===/*laya.d3.graphics.Vertex.VertexMesh.MESH_POSITION0*/0)
- return vertexElement;
- }
- return null;
- }
- /**
- *@private
- */
- __proto._generateBoundingObject=function(){
- var min=this._tempVector30;
- var max=this._tempVector31;
- min.x=min.y=min.z=Number.MAX_VALUE;
- max.x=max.y=max.z=-Number.MAX_VALUE;
- var vertexBufferCount=this._vertexBuffers.length;
- for (var i=0;i < vertexBufferCount;i++){
- var vertexBuffer=this._vertexBuffers[i];
- var positionElement=this._getPositionElement(vertexBuffer);
- var verticesData=vertexBuffer.getData();
- var floatCount=vertexBuffer.vertexDeclaration.vertexStride / 4;
- var posOffset=positionElement.offset / 4;
- for (var j=0,m=verticesData.length;j < m;j+=floatCount){
- var ofset=j+posOffset;
- var pX=verticesData[ofset];
- var pY=verticesData[ofset+1];
- var pZ=verticesData[ofset+2];
- min.x=Math.min(min.x,pX);
- min.y=Math.min(min.y,pY);
- min.z=Math.min(min.z,pZ);
- max.x=Math.max(max.x,pX);
- max.y=Math.max(max.y,pY);
- max.z=Math.max(max.z,pZ);
- }
- }
- this._bounds=new Bounds(min,max);
- }
- /**
- *@private
- */
- __proto._setSubMeshes=function(subMeshes){
- this._subMeshes=subMeshes
- this._subMeshCount=subMeshes.length;
- for (var i=0;i < this._subMeshCount;i++)
- subMeshes[i]._indexInMesh=i;
- this._generateBoundingObject();
- }
- /**
- *@inheritDoc
- */
- __proto._getSubMesh=function(index){
- return this._subMeshes[index];
- }
- /**
- *@private
- */
- __proto._setBuffer=function(vertexBuffers,indexBuffer){
- var bufferState=this._bufferState;
- bufferState.bind();
- bufferState.applyVertexBuffers(vertexBuffers);
- bufferState.applyIndexBuffer(indexBuffer);
- bufferState.unBind();
- var instanceBufferState=this._instanceBufferState;
- instanceBufferState.bind();
- instanceBufferState.applyVertexBuffers(vertexBuffers);
- instanceBufferState.applyInstanceVertexBuffer(SubMeshInstanceBatch.instance.instanceWorldMatrixBuffer);
- instanceBufferState.applyInstanceVertexBuffer(SubMeshInstanceBatch.instance.instanceMVPMatrixBuffer);
- instanceBufferState.applyIndexBuffer(indexBuffer);
- instanceBufferState.unBind();
- }
- /**
- *@inheritDoc
- */
- __proto._disposeResource=function(){
- for (var i=0,n=this._subMeshes.length;i < n;i++)
- this._subMeshes[i].destroy();
- this._nativeTriangleMesh && Laya3D._physics3D.destroy(this._nativeTriangleMesh);
- for (i=0,n=this._vertexBuffers.length;i < n;i++)
- this._vertexBuffers[i].destroy();
- this._indexBuffer.destroy();
- this._setCPUMemory(0);
- this._setGPUMemory(0);
- this._bufferState.destroy();
- this._instanceBufferState.destroy();
- this._bufferState=null;
- this._instanceBufferState=null;
- this._vertexBuffers=null;
- this._indexBuffer=null;
- this._subMeshes=null;
- this._nativeTriangleMesh=null;
- this._vertexBuffers=null;
- this._indexBuffer=null;
- this._boneNames=null;
- this._inverseBindPoses=null;
- }
- /**
- *@private
- */
- __proto._getPhysicMesh=function(){
- if (!this._nativeTriangleMesh){
- var physics3D=Laya3D._physics3D;
- var triangleMesh=new physics3D.btTriangleMesh();
- var nativePositio0=Mesh._nativeTempVector30;
- var nativePositio1=Mesh._nativeTempVector31;
- var nativePositio2=Mesh._nativeTempVector32;
- var position0=this._tempVector30;
- var position1=this._tempVector31;
- var position2=this._tempVector32;
- var vertexBuffer=this._vertexBuffers[0];
- var positionElement=this._getPositionElement(vertexBuffer);
- var verticesData=vertexBuffer.getData();
- var floatCount=vertexBuffer.vertexDeclaration.vertexStride / 4;
- var posOffset=positionElement.offset / 4;
- var indices=this._indexBuffer.getData();
- for (var i=0,n=indices.length;i < n;i+=3){
- var p0Index=indices[i] *floatCount+posOffset;
- var p1Index=indices[i+1] *floatCount+posOffset;
- var p2Index=indices[i+2] *floatCount+posOffset;
- position0.setValue(verticesData[p0Index],verticesData[p0Index+1],verticesData[p0Index+2]);
- position1.setValue(verticesData[p1Index],verticesData[p1Index+1],verticesData[p1Index+2]);
- position2.setValue(verticesData[p2Index],verticesData[p2Index+1],verticesData[p2Index+2]);
- Utils3D._convertToBulletVec3(position0,nativePositio0,true);
- Utils3D._convertToBulletVec3(position1,nativePositio1,true);
- Utils3D._convertToBulletVec3(position2,nativePositio2,true);
- triangleMesh.addTriangle(nativePositio0,nativePositio1,nativePositio2,true);
- }
- this._nativeTriangleMesh=triangleMesh;
- }
- return this._nativeTriangleMesh;
- }
- /**
- *克隆。
- *@param destObject 克隆源。
- */
- __proto.cloneTo=function(destObject){
- var destMesh=destObject;
- for (var i=0;i < this._vertexBuffers.length;i++){
- var vb=this._vertexBuffers[i];
- var destVB=new VertexBuffer3D(vb._byteLength,vb.bufferUsage,vb.canRead);
- destVB.vertexDeclaration=vb.vertexDeclaration;
- destVB.setData(vb.getData().slice());
- destMesh._vertexBuffers.push(destVB);
- destMesh._vertexCount+=destVB.vertexCount;
- };
- var ib=this._indexBuffer;
- var destIB=new IndexBuffer3D(/*laya.d3.graphics.IndexBuffer3D.INDEXTYPE_USHORT*/"ushort",ib.indexCount,ib.bufferUsage,ib.canRead);
- destIB.setData(ib.getData().slice());
- destMesh._indexBuffer=destIB;
- destMesh._setBuffer(destMesh._vertexBuffers,destIB);
- destMesh._setCPUMemory(this.cpuMemory);
- destMesh._setGPUMemory(this.gpuMemory);
- var boneNames=this._boneNames;
- var destBoneNames=destMesh._boneNames=__newvec(boneNames.length);
- for (i=0;i < boneNames.length;i++)
- destBoneNames[i]=boneNames[i];
- var inverseBindPoses=this._inverseBindPoses;
- var destInverseBindPoses=destMesh._inverseBindPoses=__newvec(inverseBindPoses.length);
- for (i=0;i < inverseBindPoses.length;i++)
- destInverseBindPoses[i]=inverseBindPoses[i];
- destMesh._bindPoseIndices=new Uint16Array(this._bindPoseIndices);
- for (i=0;i < this._skinDataPathMarks.length;i++)
- destMesh._skinDataPathMarks[i]=this._skinDataPathMarks[i].slice();
- for (i=0;i < this.subMeshCount;i++){
- var subMesh=this._subMeshes[i];
- var subIndexBufferStart=subMesh._subIndexBufferStart;
- var subIndexBufferCount=subMesh._subIndexBufferCount;
- var boneIndicesList=subMesh._boneIndicesList;
- var destSubmesh=new SubMesh(destMesh);
- destSubmesh._subIndexBufferStart.length=subIndexBufferStart.length;
- destSubmesh._subIndexBufferCount.length=subIndexBufferCount.length;
- destSubmesh._boneIndicesList.length=boneIndicesList.length;
- for (var j=0;j < subIndexBufferStart.length;j++)
- destSubmesh._subIndexBufferStart[j]=subIndexBufferStart[j];
- for (j=0;j < subIndexBufferCount.length;j++)
- destSubmesh._subIndexBufferCount[j]=subIndexBufferCount[j];
- for (j=0;j < boneIndicesList.length;j++)
- destSubmesh._boneIndicesList[j]=new Uint16Array(boneIndicesList[j]);
- destSubmesh._indexBuffer=destIB;
- destSubmesh._indexStart=subMesh._indexStart;
- destSubmesh._indexCount=subMesh._indexCount;
- destSubmesh._indices=new Uint16Array(destIB.getData().buffer,subMesh._indexStart *2,subMesh._indexCount);
- var vertexBuffer=destMesh._vertexBuffers[0];
- destSubmesh._vertexBuffer=vertexBuffer;
- destMesh._subMeshes.push(destSubmesh);
- }
- destMesh._setSubMeshes(destMesh._subMeshes);
- }
- /**
- *克隆。
- *@return 克隆副本。
- */
- __proto.clone=function(){
- var dest=/*__JS__ */new this.constructor();
- this.cloneTo(dest);
- return dest;
- }
- /**
- *获取网格的全局默认绑定动作逆矩阵。
- *@return 网格的全局默认绑定动作逆矩阵。
- */
- __getset(0,__proto,'inverseAbsoluteBindPoses',function(){
- return this._inverseBindPoses;
- });
- /**
- *获取顶点个数
- */
- __getset(0,__proto,'vertexCount',function(){
- return this._vertexCount;
- });
- /**
- *获取SubMesh的个数。
- *@return SubMesh的个数。
- */
- __getset(0,__proto,'subMeshCount',function(){
- return this._subMeshCount;
- });
- /**
- *获取边界
- *@return 边界。
- */
- __getset(0,__proto,'bounds',function(){
- return this._bounds;
- });
- Mesh._parse=function(data,propertyParams,constructParams){
- var mesh=new Mesh();
- MeshReader.read(data,mesh,mesh._subMeshes);
- return mesh;
- }
- Mesh.load=function(url,complete){
- Laya.loader.create(url,complete,null,/*Laya3D.MESH*/"MESH");
- }
- __static(Mesh,
- ['_nativeTempVector30',function(){return this._nativeTempVector30=new Laya3D._physics3D.btVector3(0,0,0);},'_nativeTempVector31',function(){return this._nativeTempVector31=new Laya3D._physics3D.btVector3(0,0,0);},'_nativeTempVector32',function(){return this._nativeTempVector32=new Laya3D._physics3D.btVector3(0,0,0);}
- ]);
- return Mesh;
- })(Resource)
- /**
- *<code>TerrainHeightData</code> 类用于描述地形高度信息。
- */
- //class laya.d3.terrain.TerrainHeightData extends laya.resource.Resource
- var TerrainHeightData=(function(_super){
- function TerrainHeightData(width,height,bitType,value){
- this._terrainHeightData=null;
- this._width=0;
- this._height=0;
- this._bitType=0;
- this._value=NaN;
- TerrainHeightData.__super.call(this);
- this._width=width;
- this._height=height;
- this._bitType=bitType;
- this._value=value;
- }
- __class(TerrainHeightData,'laya.d3.terrain.TerrainHeightData',_super);
- TerrainHeightData._pharse=function(data,propertyParams,constructParams){
- var terrainHeightData=new TerrainHeightData(constructParams[0],constructParams[1],constructParams[2],constructParams[3]);
- var buffer;
- var ratio=NaN;
- if (terrainHeightData._bitType==8){
- buffer=new Uint8Array(data);
- ratio=1.0 / 255.0;
- }else if (terrainHeightData._bitType==16){
- buffer=new Int16Array(data);
- ratio=1.0 / 32766.0;
- }
- terrainHeightData._terrainHeightData=new Float32Array(terrainHeightData._height *terrainHeightData._width);
- for (var i=0,n=terrainHeightData._height *terrainHeightData._width;i < n;i++){
- terrainHeightData._terrainHeightData[i]=(buffer[i] *ratio *terrainHeightData._value)/ 2;
- }
- }
- TerrainHeightData.load=function(url,complete,widht,height,bitType,value){
- Laya.loader.create(url,complete,null,/*Laya3D.TERRAINHEIGHTDATA*/"TERRAINHEIGHTDATA",[widht,height,bitType,value],null,1,false);
- }
- return TerrainHeightData;
- })(Resource)
- /**
- *<code>AnimationClip</code> 类用于动画片段资源。
- */
- //class laya.d3.animation.AnimationClip extends laya.resource.Resource
- var AnimationClip=(function(_super){
- function AnimationClip(){
- /**@private */
- //this._duration=NaN;
- /**@private */
- //this._frameRate=0;
- /**@private */
- //this._nodesDic=null;
- /**@private */
- //this._nodesMap=null;
- /**@private */
- //this._events=null;
- /**是否循环。*/
- //this.islooping=false;
- AnimationClip.__super.call(this);
- this._nodes=new KeyframeNodeList();
- this._events=[];
- }
- __class(AnimationClip,'laya.d3.animation.AnimationClip',_super);
- var __proto=AnimationClip.prototype;
- /**
- *获取动画片段时长。
- */
- __proto.duration=function(){
- return this._duration;
- }
- /**
- *@private
- */
- __proto._hermiteInterpolate=function(frame,nextFrame,t,dur){
- var t0=frame.outTangent,t1=nextFrame.inTangent;
- if (/*__JS__ */Number.isFinite(t0)&& Number.isFinite(t1)){
- var t2=t *t;
- var t3=t2 *t;
- var a=2.0 *t3-3.0 *t2+1.0;
- var b=t3-2.0 *t2+t;
- var c=t3-t2;
- var d=-2.0 *t3+3.0 *t2;
- return a *frame.value+b *t0 *dur+c *t1 *dur+d *nextFrame.value;
- }else
- return frame.value;
- }
- /**
- *@private
- */
- __proto._hermiteInterpolateVector3=function(frame,nextFrame,t,dur,out){
- var p0=frame.value;
- var tan0=frame.outTangent;
- var p1=nextFrame.value;
- var tan1=nextFrame.inTangent;
- var t2=t *t;
- var t3=t2 *t;
- var a=2.0 *t3-3.0 *t2+1.0;
- var b=t3-2.0 *t2+t;
- var c=t3-t2;
- var d=-2.0 *t3+3.0 *t2;
- var t0=tan0.x,t1=tan1.x;
- if (/*__JS__ */Number.isFinite(t0)&& Number.isFinite(t1))
- out.x=a *p0.x+b *t0 *dur+c *t1 *dur+d *p1.x;
- else
- out.x=p0.x;
- t0=tan0.y,t1=tan1.y;
- if (/*__JS__ */Number.isFinite(t0)&& Number.isFinite(t1))
- out.y=a *p0.y+b *t0 *dur+c *t1 *dur+d *p1.y;
- else
- out.y=p0.y;
- t0=tan0.z,t1=tan1.z;
- if (/*__JS__ */Number.isFinite(t0)&& Number.isFinite(t1))
- out.z=a *p0.z+b *t0 *dur+c *t1 *dur+d *p1.z;
- else
- out.z=p0.z;
- }
- /**
- *@private
- */
- __proto._hermiteInterpolateQuaternion=function(frame,nextFrame,t,dur,out){
- var p0=frame.value;
- var tan0=frame.outTangent;
- var p1=nextFrame.value;
- var tan1=nextFrame.inTangent;
- var t2=t *t;
- var t3=t2 *t;
- var a=2.0 *t3-3.0 *t2+1.0;
- var b=t3-2.0 *t2+t;
- var c=t3-t2;
- var d=-2.0 *t3+3.0 *t2;
- var t0=tan0.x,t1=tan1.x;
- if (/*__JS__ */Number.isFinite(t0)&& Number.isFinite(t1))
- out.x=a *p0.x+b *t0 *dur+c *t1 *dur+d *p1.x;
- else
- out.x=p0.x;
- t0=tan0.y,t1=tan1.y;
- if (/*__JS__ */Number.isFinite(t0)&& Number.isFinite(t1))
- out.y=a *p0.y+b *t0 *dur+c *t1 *dur+d *p1.y;
- else
- out.y=p0.y;
- t0=tan0.z,t1=tan1.z;
- if (/*__JS__ */Number.isFinite(t0)&& Number.isFinite(t1))
- out.z=a *p0.z+b *t0 *dur+c *t1 *dur+d *p1.z;
- else
- out.z=p0.z;
- t0=tan0.w,t1=tan1.w;
- if (/*__JS__ */Number.isFinite(t0)&& Number.isFinite(t1))
- out.w=a *p0.w+b *t0 *dur+c *t1 *dur+d *p1.w;
- else
- out.w=p0.w;
- }
- /**
- *@private
- */
- __proto._evaluateClipDatasRealTime=function(nodes,playCurTime,realTimeCurrentFrameIndexes,addtive,frontPlay){
- for (var i=0,n=nodes.count;i < n;i++){
- var node=nodes.getNodeByIndex(i);
- var type=node.type;
- var nextFrameIndex=0;
- var keyFrames=node._keyFrames;
- var keyFramesCount=keyFrames.length;
- var frameIndex=realTimeCurrentFrameIndexes[i];
- if (frontPlay){
- if ((frameIndex!==-1)&& (playCurTime < keyFrames[frameIndex].time)){
- frameIndex=-1;
- realTimeCurrentFrameIndexes[i]=frameIndex;
- }
- nextFrameIndex=frameIndex+1;
- while (nextFrameIndex < keyFramesCount){
- if (keyFrames[nextFrameIndex].time > playCurTime)
- break ;
- frameIndex++;
- nextFrameIndex++;
- realTimeCurrentFrameIndexes[i]=frameIndex;
- }
- }else {
- nextFrameIndex=frameIndex+1;
- if ((nextFrameIndex!==keyFramesCount)&& (playCurTime > keyFrames[nextFrameIndex].time)){
- frameIndex=keyFramesCount-1;
- realTimeCurrentFrameIndexes[i]=frameIndex;
- }
- nextFrameIndex=frameIndex+1;
- while (frameIndex >-1){
- if (keyFrames[frameIndex].time < playCurTime)
- break ;
- frameIndex--;
- nextFrameIndex--;
- realTimeCurrentFrameIndexes[i]=frameIndex;
- }
- };
- var isEnd=nextFrameIndex===keyFramesCount;
- switch (type){
- case 0:
- if (frameIndex!==-1){
- var frame=keyFrames [frameIndex];
- if (isEnd){
- node.data=frame.value;
- }else {
- var nextFarme=keyFrames [nextFrameIndex];
- var d=nextFarme.time-frame.time;
- var t=NaN;
- if (d!==0)
- t=(playCurTime-frame.time)/ d;
- else
- t=0;
- node.data=this._hermiteInterpolate(frame,nextFarme,t,d);
- }
- }else {
- node.data=(keyFrames [0]).value;
- }
- if (addtive)
- node.data-=(keyFrames [0]).value;
- break ;
- case 1:
- case 4:;
- var clipData=node.data;
- this._evaluateFrameNodeVector3DatasRealTime(keyFrames,frameIndex,isEnd,playCurTime,clipData);
- if (addtive){
- var firstFrameValue=(keyFrames [0]).value;
- clipData.x-=firstFrameValue.x;
- clipData.y-=firstFrameValue.y;
- clipData.z-=firstFrameValue.z;
- }
- break ;
- case 2:;
- var clipQuat=node.data;
- this._evaluateFrameNodeQuaternionDatasRealTime(keyFrames,frameIndex,isEnd,playCurTime,clipQuat);
- if (addtive){
- var tempQuat=AnimationClip._tempQuaternion0;
- var firstFrameValueQua=(keyFrames [0]).value;
- Utils3D.quaternionConjugate(firstFrameValueQua,tempQuat);
- Quaternion.multiply(tempQuat,clipQuat,clipQuat);
- }
- break ;
- case 3:
- clipData=node.data;
- this._evaluateFrameNodeVector3DatasRealTime(keyFrames,frameIndex,isEnd,playCurTime,clipData);
- if (addtive){
- firstFrameValue=(keyFrames [0]).value;
- clipData.x /=firstFrameValue.x;
- clipData.y /=firstFrameValue.y;
- clipData.z /=firstFrameValue.z;
- }
- break ;
- default :
- throw "AnimationClip:unknown node type.";
- }
- }
- }
- __proto._evaluateClipDatasRealTimeForNative=function(nodes,playCurTime,realTimeCurrentFrameIndexes,addtive){
- LayaGL.instance.evaluateClipDatasRealTime(nodes._nativeObj,playCurTime,realTimeCurrentFrameIndexes,addtive);
- }
- /**
- *@private
- */
- __proto._evaluateFrameNodeVector3DatasRealTime=function(keyFrames,frameIndex,isEnd,playCurTime,outDatas){
- if (frameIndex!==-1){
- var frame=keyFrames[frameIndex];
- if (isEnd){
- var frameData=frame.value;
- outDatas.x=frameData.x;
- outDatas.y=frameData.y;
- outDatas.z=frameData.z;
- }else {
- var nextKeyFrame=keyFrames[frameIndex+1];
- var t=NaN;
- var startTime=frame.time;
- var d=nextKeyFrame.time-startTime;
- if (d!==0)
- t=(playCurTime-startTime)/ d;
- else
- t=0;
- this._hermiteInterpolateVector3(frame,nextKeyFrame,t,d,outDatas);
- }
- }else {
- var firstFrameDatas=keyFrames[0].value;
- outDatas.x=firstFrameDatas.x;
- outDatas.y=firstFrameDatas.y;
- outDatas.z=firstFrameDatas.z;
- }
- }
- /**
- *@private
- */
- __proto._evaluateFrameNodeQuaternionDatasRealTime=function(keyFrames,frameIndex,isEnd,playCurTime,outDatas){
- if (frameIndex!==-1){
- var frame=keyFrames[frameIndex];
- if (isEnd){
- var frameData=frame.value;
- outDatas.x=frameData.x;
- outDatas.y=frameData.y;
- outDatas.z=frameData.z;
- outDatas.w=frameData.w;
- }else {
- var nextKeyFrame=keyFrames[frameIndex+1];
- var t=NaN;
- var startTime=frame.time;
- var d=nextKeyFrame.time-startTime;
- if (d!==0)
- t=(playCurTime-startTime)/ d;
- else
- t=0;
- this._hermiteInterpolateQuaternion(frame,nextKeyFrame,t,d,outDatas);
- }
- }else {
- var firstFrameDatas=keyFrames[0].value;
- outDatas.x=firstFrameDatas.x;
- outDatas.y=firstFrameDatas.y;
- outDatas.z=firstFrameDatas.z;
- outDatas.w=firstFrameDatas.w;
- }
- }
- /**
- *@private
- */
- __proto._binarySearchEventIndex=function(time){
- var start=0;
- var end=this._events.length-1;
- var mid=0;
- while (start <=end){
- mid=Math.floor((start+end)/ 2);
- var midValue=this._events[mid].time;
- if (midValue==time)
- return mid;
- else if (midValue > time)
- end=mid-1;
- else
- start=mid+1;
- }
- return start;
- }
- /**
- *添加动画事件。
- */
- __proto.addEvent=function(event){
- var index=this._binarySearchEventIndex(event.time);
- this._events.splice(index,0,event);
- }
- /**
- *@inheritDoc
- */
- __proto._disposeResource=function(){
- this._nodes=null;
- this._nodesMap=null;
- }
- AnimationClip._parse=function(data,propertyParams,constructParams){
- var clip=new AnimationClip();
- var reader=new Byte(data);
- var version=reader.readUTFString();
- switch (version){
- case "LAYAANIMATION:03":
- AnimationClipParser03.parse(clip,reader);
- break ;
- case "LAYAANIMATION:04":
- case "LAYAANIMATION:COMPRESSION_04":
- AnimationClipParser04.parse(clip,reader,version);
- break ;
- default :
- throw "unknown animationClip version.";
- }
- return clip;
- }
- AnimationClip.load=function(url,complete){
- Laya.loader.create(url,complete,null,/*Laya3D.ANIMATIONCLIP*/"ANIMATIONCLIP");
- }
- __static(AnimationClip,
- ['_tempQuaternion0',function(){return this._tempQuaternion0=new Quaternion();}
- ]);
- return AnimationClip;
- })(Resource)
- /**
- *@private
- *<code>ShaderInstance</code> 类用于实现ShaderInstance。
- */
- //class laya.d3.shader.ShaderInstance extends laya.resource.Resource
- var ShaderInstance=(function(_super){
- function ShaderInstance(vs,ps,attributeMap,uniformMap,shaderPass){
- /**@private */
- //this._attributeMap=null;
- /**@private */
- //this._uniformMap=null;
- /**@private */
- //this._shaderPass=null;
- /**@private */
- //this._vs=null;
- /**@private */
- //this._ps=null;
- /**@private */
- //this._curActTexIndex=0;
- /**@private */
- //this._vshader=null;
- /**@private */
- //this._pshader=null;
- /**@private */
- //this._program=null;
- /**@private */
- //this._sceneUniformParamsMap=null;
- /**@private */
- //this._cameraUniformParamsMap=null;
- /**@private */
- //this._spriteUniformParamsMap=null;
- /**@private */
- //this._materialUniformParamsMap=null;
- /**@private */
- //this._customUniformParamsMap=null;
- /**@private */
- this._stateParamsMap=[];
- /**@private */
- this._uploadMark=-1;
- /**@private */
- //this._uploadMaterial=null;
- /**@private */
- //this._uploadRender=null;
- /**@private */
- this._uploadRenderType=-1;
- /**@private */
- //this._uploadCamera=null;
- /**@private */
- //this._uploadScene=null;
- ShaderInstance.__super.call(this);
- this._vs=vs;
- this._ps=ps;
- this._attributeMap=attributeMap;
- this._uniformMap=uniformMap;
- this._shaderPass=shaderPass;
- this._create();
- this.lock=true;
- }
- __class(ShaderInstance,'laya.d3.shader.ShaderInstance',_super);
- var __proto=ShaderInstance.prototype;
- /**
- *@private
- */
- __proto._create=function(){
- var gl=LayaGL.instance;
- this._program=gl.createProgram();
- this._vshader=this._createShader(gl,this._vs,/*laya.webgl.WebGLContext.VERTEX_SHADER*/0x8B31);
- this._pshader=this._createShader(gl,this._ps,/*laya.webgl.WebGLContext.FRAGMENT_SHADER*/0x8B30);
- gl.attachShader(this._program,this._vshader);
- gl.attachShader(this._program,this._pshader);
- for (var k in this._attributeMap)
- gl.bindAttribLocation(this._program,this._attributeMap[k],k);
- gl.linkProgram(this._program);
- if (!Render.isConchApp && Shader3D.debugMode && !gl.getProgramParameter(this._program,/*laya.webgl.WebGLContext.LINK_STATUS*/0x8B82))
- throw gl.getProgramInfoLog(this._program);
- var sceneParms=[];
- var cameraParms=[];
- var spriteParms=[];
- var materialParms=[];
- var customParms=[];
- this._customUniformParamsMap=[];
- var nUniformNum=gl.getProgramParameter(this._program,/*laya.webgl.WebGLContext.ACTIVE_UNIFORMS*/0x8B86);
- WebGLContext.useProgram(gl,this._program);
- this._curActTexIndex=0;
- var one,i=0,n=0;
- for (i=0;i < nUniformNum;i++){
- var uniformData=gl.getActiveUniform(this._program,i);
- var uniName=uniformData.name;
- one=new ShaderVariable();
- one.location=gl.getUniformLocation(this._program,uniName);
- if (uniName.indexOf('[0]')> 0){
- one.name=uniName=uniName.substr(0,uniName.length-3);
- one.isArray=true;
- }else {
- one.name=uniName;
- one.isArray=false;
- }
- one.type=uniformData.type;
- this._addShaderUnifiormFun(one);
- var uniformPeriod=this._uniformMap[uniName];
- if (uniformPeriod !=null){
- one.dataOffset=Shader3D.propertyNameToID(uniName);
- switch (uniformPeriod){
- case /*laya.d3.shader.Shader3D.PERIOD_CUSTOM*/0:
- customParms.push(one);
- break ;
- case /*laya.d3.shader.Shader3D.PERIOD_MATERIAL*/1:
- materialParms.push(one);
- break ;
- case /*laya.d3.shader.Shader3D.PERIOD_SPRITE*/2:
- spriteParms.push(one);
- break ;
- case /*laya.d3.shader.Shader3D.PERIOD_CAMERA*/3:
- cameraParms.push(one);
- break ;
- case /*laya.d3.shader.Shader3D.PERIOD_SCENE*/4:
- sceneParms.push(one);
- break ;
- default :
- throw new Error("Shader3D: period is unkonw.");
- }
- }
- }
- this._sceneUniformParamsMap=LayaGL.instance.createCommandEncoder(sceneParms.length *4 *5+4,64,true);
- for (i=0,n=sceneParms.length;i < n;i++)
- this._sceneUniformParamsMap.addShaderUniform(sceneParms[i]);
- this._cameraUniformParamsMap=LayaGL.instance.createCommandEncoder(cameraParms.length *4 *5+4,64,true);
- for (i=0,n=cameraParms.length;i < n;i++)
- this._cameraUniformParamsMap.addShaderUniform(cameraParms[i]);
- this._spriteUniformParamsMap=LayaGL.instance.createCommandEncoder(spriteParms.length *4 *5+4,64,true);
- for (i=0,n=spriteParms.length;i < n;i++)
- this._spriteUniformParamsMap.addShaderUniform(spriteParms[i]);
- this._materialUniformParamsMap=LayaGL.instance.createCommandEncoder(materialParms.length *4 *5+4,64,true);
- for (i=0,n=materialParms.length;i < n;i++)
- this._materialUniformParamsMap.addShaderUniform(materialParms[i]);
- this._customUniformParamsMap.length=customParms.length;
- for (i=0,n=customParms.length;i < n;i++){
- var custom=customParms[i];
- this._customUniformParamsMap[custom.dataOffset]=custom;
- };
- var stateMap=this._shaderPass._stateMap;
- for (var s in stateMap)
- this._stateParamsMap[stateMap[s]]=Shader3D.propertyNameToID(s);
- }
- /**
- *@private
- */
- __proto._getRenderState=function(shaderDatas,stateIndex){
- var stateID=this._stateParamsMap[stateIndex];
- if (stateID==null)
- return null;
- else
- return shaderDatas[stateID];
- }
- /**
- *@inheritDoc
- */
- __proto._disposeResource=function(){
- LayaGL.instance.deleteShader(this._vshader);
- LayaGL.instance.deleteShader(this._pshader);
- LayaGL.instance.deleteProgram(this._program);
- this._vshader=this._pshader=this._program=null;
- this._setGPUMemory(0);
- this._curActTexIndex=0;
- }
- /**
- *@private
- */
- __proto._addShaderUnifiormFun=function(one){
- var gl=LayaGL.instance;
- one.caller=this;
- var isArray=one.isArray;
- switch (one.type){
- case /*laya.webgl.WebGLContext.BOOL*/0x8B56:
- one.fun=this._uniform1i;
- one.uploadedValue=new Array(1);
- break ;
- case /*laya.webgl.WebGLContext.INT*/0x1404:
- one.fun=isArray ? this._uniform1iv :this._uniform1i;
- one.uploadedValue=new Array(1);
- break ;
- case /*laya.webgl.WebGLContext.FLOAT*/0x1406:
- one.fun=isArray ? this._uniform1fv :this._uniform1f;
- one.uploadedValue=new Array(1);
- break ;
- case /*laya.webgl.WebGLContext.FLOAT_VEC2*/0x8B50:
- one.fun=isArray ? this._uniform_vec2v :this._uniform_vec2;
- one.uploadedValue=new Array(2);
- break ;
- case /*laya.webgl.WebGLContext.FLOAT_VEC3*/0x8B51:
- one.fun=isArray ? this._uniform_vec3v :this._uniform_vec3;
- one.uploadedValue=new Array(3);
- break ;
- case /*laya.webgl.WebGLContext.FLOAT_VEC4*/0x8B52:
- one.fun=isArray ? this._uniform_vec4v :this._uniform_vec4;
- one.uploadedValue=new Array(4);
- break ;
- case /*laya.webgl.WebGLContext.FLOAT_MAT2*/0x8B5A:
- one.fun=this._uniformMatrix2fv;
- break ;
- case /*laya.webgl.WebGLContext.FLOAT_MAT3*/0x8B5B:
- one.fun=this._uniformMatrix3fv;
- break ;
- case /*laya.webgl.WebGLContext.FLOAT_MAT4*/0x8B5C:
- one.fun=isArray ? this._uniformMatrix4fv :this._uniformMatrix4f;
- break ;
- case /*laya.webgl.WebGLContext.SAMPLER_2D*/0x8B5E:
- gl.uniform1i(one.location,this._curActTexIndex);
- one.textureID=WebGLContext._glTextureIDs[this._curActTexIndex++];
- one.fun=this._uniform_sampler2D;
- break ;
- case 0x8b5f:
- gl.uniform1i(one.location,this._curActTexIndex);
- one.textureID=WebGLContext._glTextureIDs[this._curActTexIndex++];
- one.fun=this._uniform_sampler3D;
- break ;
- case /*laya.webgl.WebGLContext.SAMPLER_CUBE*/0x8B60:
- gl.uniform1i(one.location,this._curActTexIndex);
- one.textureID=WebGLContext._glTextureIDs[this._curActTexIndex++];
- one.fun=this._uniform_samplerCube;
- break ;
- default :
- throw new Error("compile shader err!");
- break ;
- }
- }
- /**
- *@private
- */
- __proto._createShader=function(gl,str,type){
- var shader=gl.createShader(type);
- gl.shaderSource(shader,str);
- gl.compileShader(shader);
- if (Shader3D.debugMode && !gl.getShaderParameter(shader,/*laya.webgl.WebGLContext.COMPILE_STATUS*/0x8B81))
- throw gl.getShaderInfoLog(shader);
- return shader;
- }
- /**
- *@private
- */
- __proto._uniform1f=function(one,value){
- var uploadedValue=one.uploadedValue;
- if (uploadedValue[0]!==value){
- LayaGL.instance.uniform1f(one.location,uploadedValue[0]=value);
- return 1;
- }
- return 0;
- }
- /**
- *@private
- */
- __proto._uniform1fv=function(one,value){
- if (value.length < 4){
- var uploadedValue=one.uploadedValue;
- if (uploadedValue[0]!==value[0] || uploadedValue[1]!==value[1] || uploadedValue[2]!==value[2] || uploadedValue[3]!==value[3]){
- LayaGL.instance.uniform1fv(one.location,value);
- uploadedValue[0]=value[0];
- uploadedValue[1]=value[1];
- uploadedValue[2]=value[2];
- uploadedValue[3]=value[3];
- return 1;
- }
- return 0;
- }else {
- LayaGL.instance.uniform1fv(one.location,value);
- return 1;
- }
- }
- /**
- *@private
- */
- __proto._uniform_vec2=function(one,v){
- var uploadedValue=one.uploadedValue;
- if (uploadedValue[0]!==v.x || uploadedValue[1]!==v.y){
- LayaGL.instance.uniform2f(one.location,uploadedValue[0]=v.x,uploadedValue[1]=v.y);
- return 1;
- }
- return 0;
- }
- /**
- *@private
- */
- __proto._uniform_vec2v=function(one,value){
- if (value.length < 2){
- var uploadedValue=one.uploadedValue;
- if (uploadedValue[0]!==value[0] || uploadedValue[1]!==value[1] || uploadedValue[2]!==value[2] || uploadedValue[3]!==value[3]){
- LayaGL.instance.uniform2fv(one.location,value);
- uploadedValue[0]=value[0];
- uploadedValue[1]=value[1];
- uploadedValue[2]=value[2];
- uploadedValue[3]=value[3];
- return 1;
- }
- return 0;
- }else {
- LayaGL.instance.uniform2fv(one.location,value);
- return 1;
- }
- }
- /**
- *@private
- */
- __proto._uniform_vec3=function(one,v){
- var uploadedValue=one.uploadedValue;
- if (uploadedValue[0]!==v.x || uploadedValue[1]!==v.y || uploadedValue[2]!==v.z){
- LayaGL.instance.uniform3f(one.location,uploadedValue[0]=v.x,uploadedValue[1]=v.y,uploadedValue[2]=v.z);
- return 1;
- }
- return 0;
- }
- /**
- *@private
- */
- __proto._uniform_vec3v=function(one,v){
- LayaGL.instance.uniform3fv(one.location,v);
- return 1;
- }
- /**
- *@private
- */
- __proto._uniform_vec4=function(one,v){
- var uploadedValue=one.uploadedValue;
- if (uploadedValue[0]!==v.x || uploadedValue[1]!==v.y || uploadedValue[2]!==v.z || uploadedValue[3]!==v.w){
- LayaGL.instance.uniform4f(one.location,uploadedValue[0]=v.x,uploadedValue[1]=v.y,uploadedValue[2]=v.z,uploadedValue[3]=v.w);
- return 1;
- }
- return 0;
- }
- /**
- *@private
- */
- __proto._uniform_vec4v=function(one,v){
- LayaGL.instance.uniform4fv(one.location,v);
- return 1;
- }
- /**
- *@private
- */
- __proto._uniformMatrix2fv=function(one,value){
- LayaGL.instance.uniformMatrix2fv(one.location,false,value);
- return 1;
- }
- /**
- *@private
- */
- __proto._uniformMatrix3fv=function(one,value){
- LayaGL.instance.uniformMatrix3fv(one.location,false,value);
- return 1;
- }
- /**
- *@private
- */
- __proto._uniformMatrix4f=function(one,m){
- var value=m.elements;
- LayaGL.instance.uniformMatrix4fv(one.location,false,value);
- return 1;
- }
- /**
- *@private
- */
- __proto._uniformMatrix4fv=function(one,m){
- LayaGL.instance.uniformMatrix4fv(one.location,false,m);
- return 1;
- }
- /**
- *@private
- */
- __proto._uniform1i=function(one,value){
- var uploadedValue=one.uploadedValue;
- if (uploadedValue[0]!==value){
- LayaGL.instance.uniform1i(one.location,uploadedValue[0]=value);
- return 1;
- }
- return 0;
- }
- /**
- *@private
- */
- __proto._uniform1iv=function(one,value){
- LayaGL.instance.uniform1iv(one.location,value);
- return 1;
- }
- /**
- *@private
- */
- __proto._uniform_ivec2=function(one,value){
- var uploadedValue=one.uploadedValue;
- if (uploadedValue[0]!==value[0] || uploadedValue[1]!==value[1]){
- LayaGL.instance.uniform2i(one.location,uploadedValue[0]=value[0],uploadedValue[1]=value[1]);
- return 1;
- }
- return 0;
- }
- /**
- *@private
- */
- __proto._uniform_ivec2v=function(one,value){
- LayaGL.instance.uniform2iv(one.location,value);
- return 1;
- }
- /**
- *@private
- */
- __proto._uniform_vec3i=function(one,value){
- var uploadedValue=one.uploadedValue;
- if (uploadedValue[0]!==value[0] || uploadedValue[1]!==value[1] || uploadedValue[2]!==value[2]){
- LayaGL.instance.uniform3i(one.location,uploadedValue[0]=value[0],uploadedValue[1]=value[1],uploadedValue[2]=value[2]);
- return 1;
- }
- return 0;
- }
- /**
- *@private
- */
- __proto._uniform_vec3vi=function(one,value){
- LayaGL.instance.uniform3iv(one.location,value);
- return 1;
- }
- /**
- *@private
- */
- __proto._uniform_vec4i=function(one,value){
- var uploadedValue=one.uploadedValue;
- if (uploadedValue[0]!==value[0] || uploadedValue[1]!==value[1] || uploadedValue[2]!==value[2] || uploadedValue[3]!==value[3]){
- LayaGL.instance.uniform4i(one.location,uploadedValue[0]=value[0],uploadedValue[1]=value[1],uploadedValue[2]=value[2],uploadedValue[3]=value[3]);
- return 1;
- }
- return 0;
- }
- /**
- *@private
- */
- __proto._uniform_vec4vi=function(one,value){
- LayaGL.instance.uniform4iv(one.location,value);
- return 1;
- }
- /**
- *@private
- */
- __proto._uniform_sampler2D=function(one,texture){
- var value=texture._getSource()|| texture.defaulteTexture._getSource();
- var gl=LayaGL.instance;
- WebGLContext.activeTexture(gl,one.textureID);
- WebGLContext.bindTexture(gl,/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1,value);
- return 0;
- }
- __proto._uniform_sampler3D=function(one,texture){
- var value=texture._getSource()|| texture.defaulteTexture._getSource();
- var gl=LayaGL.instance;
- WebGLContext.activeTexture(gl,one.textureID);
- WebGLContext.bindTexture(gl,/*laya.webgl.WebGLContext.TEXTURE_3D*/0x806f,value);
- return 0;
- }
- /**
- *@private
- */
- __proto._uniform_samplerCube=function(one,texture){
- var value=texture._getSource()|| texture.defaulteTexture._getSource();
- var gl=LayaGL.instance;
- WebGLContext.activeTexture(gl,one.textureID);
- WebGLContext.bindTexture(gl,/*laya.webgl.WebGLContext.TEXTURE_CUBE_MAP*/0x8513,value);
- return 0;
- }
- /**
- *@private
- */
- __proto.bind=function(){
- return WebGLContext.useProgram(LayaGL.instance,this._program);
- }
- /**
- *@private
- */
- __proto.uploadUniforms=function(shaderUniform,shaderDatas,uploadUnTexture){
- Stat.shaderCall+=LayaGLRunner.uploadShaderUniforms(LayaGL.instance,shaderUniform,shaderDatas,uploadUnTexture);
- }
- /**
- *@private
- */
- __proto.uploadRenderStateBlendDepth=function(shaderDatas){
- var gl=LayaGL.instance;
- var renderState=this._shaderPass.renderState;
- var datas=shaderDatas.getData();
- var depthWrite=this._getRenderState(datas,/*laya.d3.shader.Shader3D.RENDER_STATE_DEPTH_WRITE*/13);
- var depthTest=this._getRenderState(datas,/*laya.d3.shader.Shader3D.RENDER_STATE_DEPTH_TEST*/12);
- var blend=this._getRenderState(datas,/*laya.d3.shader.Shader3D.RENDER_STATE_BLEND*/1);
- depthWrite==null && (depthWrite=renderState.depthWrite);
- depthTest==null && (depthTest=renderState.depthTest);
- blend==null && (blend=renderState.blend);
- WebGLContext.setDepthMask(gl,depthWrite);
- if (depthTest===/*laya.d3.core.material.RenderState.DEPTHTEST_OFF*/0)
- WebGLContext.setDepthTest(gl,false);
- else {
- WebGLContext.setDepthTest(gl,true);
- WebGLContext.setDepthFunc(gl,depthTest);
- }
- switch (blend){
- case /*laya.d3.core.material.RenderState.BLEND_DISABLE*/0:
- WebGLContext.setBlend(gl,false);
- break ;
- case /*laya.d3.core.material.RenderState.BLEND_ENABLE_ALL*/1:
- WebGLContext.setBlend(gl,true);
- var srcBlend=this._getRenderState(datas,/*laya.d3.shader.Shader3D.RENDER_STATE_BLEND_SRC*/2);
- srcBlend==null && (srcBlend=renderState.srcBlend);
- var dstBlend=this._getRenderState(datas,/*laya.d3.shader.Shader3D.RENDER_STATE_BLEND_DST*/3);
- dstBlend==null && (dstBlend=renderState.dstBlend);
- WebGLContext.setBlendFunc(gl,srcBlend,dstBlend);
- break ;
- case /*laya.d3.core.material.RenderState.BLEND_ENABLE_SEPERATE*/2:
- WebGLContext.setBlend(gl,true);
- var srcRGB=this._getRenderState(datas,/*laya.d3.shader.Shader3D.RENDER_STATE_BLEND_SRC_RGB*/4);
- srcRGB==null && (srcRGB=renderState.srcBlendRGB);
- var dstRGB=this._getRenderState(datas,/*laya.d3.shader.Shader3D.RENDER_STATE_BLEND_DST_RGB*/5);
- dstRGB==null && (dstRGB=renderState.dstBlendRGB);
- var srcAlpha=this._getRenderState(datas,/*laya.d3.shader.Shader3D.RENDER_STATE_BLEND_SRC_ALPHA*/6);
- srcAlpha==null && (srcAlpha=renderState.srcBlendAlpha);
- var dstAlpha=this._getRenderState(datas,/*laya.d3.shader.Shader3D.RENDER_STATE_BLEND_DST_ALPHA*/7);
- dstAlpha==null && (dstAlpha=renderState.dstBlendAlpha);
- WebGLContext.setBlendFuncSeperate(gl,srcRGB,dstRGB,srcAlpha,dstAlpha);
- break ;
- }
- }
- /**
- *@private
- */
- __proto.uploadRenderStateFrontFace=function(shaderDatas,isTarget,transform){
- var gl=LayaGL.instance;
- var renderState=this._shaderPass.renderState;
- var datas=shaderDatas.getData();
- var cull=this._getRenderState(datas,/*laya.d3.shader.Shader3D.RENDER_STATE_CULL*/0);
- cull==null && (cull=renderState.cull);
- var forntFace=0;
- switch (cull){
- case /*laya.d3.core.material.RenderState.CULL_NONE*/0:
- WebGLContext.setCullFace(gl,false);
- break ;
- case /*laya.d3.core.material.RenderState.CULL_FRONT*/1:
- WebGLContext.setCullFace(gl,true);
- if (isTarget){
- if (transform && transform._isFrontFaceInvert)
- forntFace=/*laya.webgl.WebGLContext.CCW*/0x0901;
- else
- forntFace=/*laya.webgl.WebGLContext.CW*/0x0900;
- }else {
- if (transform && transform._isFrontFaceInvert)
- forntFace=/*laya.webgl.WebGLContext.CW*/0x0900;
- else
- forntFace=/*laya.webgl.WebGLContext.CCW*/0x0901;
- }
- WebGLContext.setFrontFace(gl,forntFace);
- break ;
- case /*laya.d3.core.material.RenderState.CULL_BACK*/2:
- WebGLContext.setCullFace(gl,true);
- if (isTarget){
- if (transform && transform._isFrontFaceInvert)
- forntFace=/*laya.webgl.WebGLContext.CW*/0x0900;
- else
- forntFace=/*laya.webgl.WebGLContext.CCW*/0x0901;
- }else {
- if (transform && transform._isFrontFaceInvert)
- forntFace=/*laya.webgl.WebGLContext.CCW*/0x0901;
- else
- forntFace=/*laya.webgl.WebGLContext.CW*/0x0900;
- }
- WebGLContext.setFrontFace(gl,forntFace);
- break ;
- }
- }
- /**
- *@private
- */
- __proto.uploadCustomUniform=function(index,data){
- Stat.shaderCall+=LayaGLRunner.uploadCustomUniform(LayaGL.instance,this._customUniformParamsMap,index,data);
- }
- /**
- *@private
- *[NATIVE]
- */
- __proto._uniformMatrix2fvForNative=function(one,value){
- LayaGL.instance.uniformMatrix2fvEx(one.location,false,value);
- return 1;
- }
- /**
- *@private
- *[NATIVE]
- */
- __proto._uniformMatrix3fvForNative=function(one,value){
- LayaGL.instance.uniformMatrix3fvEx(one.location,false,value);
- return 1;
- }
- /**
- *@private
- *[NATIVE]
- */
- __proto._uniformMatrix4fvForNative=function(one,m){
- LayaGL.instance.uniformMatrix4fvEx(one.location,false,m);
- return 1;
- }
- return ShaderInstance;
- })(Resource)
- /**
- *<code>TerrainRes</code> 类用于描述地形信息。
- */
- //class laya.d3.terrain.TerrainRes extends laya.resource.Resource
- var TerrainRes=(function(_super){
- function TerrainRes(){
- this._version=NaN;
- this._cameraCoordinateInverse=false;
- this._gridSize=NaN;
- this._chunkNumX=0;
- this._chunkNumZ=0;
- this._heightDataX=0;
- this._heightDataZ=0;
- this._heightDataBitType=0;
- this._heightDataValue=NaN;
- this._heightDataUrl=null;
- this._detailTextureInfos=null;
- this._chunkInfos=null;
- this._heightData=null;
- this._materialInfo=null;
- this._alphaMaps=null;
- this._normalMaps=null;
- TerrainRes.__super.call(this);
- }
- __class(TerrainRes,'laya.d3.terrain.TerrainRes',_super);
- var __proto=TerrainRes.prototype;
- __proto.parseData=function(data){
- var json=data[0];
- var resouMap=data[1];
- this._version=json.version;
- if (this._version==1.0){
- this._cameraCoordinateInverse=json.cameraCoordinateInverse;
- this._gridSize=json.gridSize;
- this._chunkNumX=json.chunkNumX;
- this._chunkNumZ=json.chunkNumZ;
- var heightData=json.heightData;
- this._heightDataX=heightData.numX;
- this._heightDataZ=heightData.numZ;
- this._heightDataBitType=heightData.bitType;
- this._heightDataValue=heightData.value;
- this._heightDataUrl=resouMap[heightData.url];
- this._materialInfo=new MaterialInfo();
- if (json.material){
- var ambient=json.material.ambient;
- var diffuse=json.material.diffuse;
- var specular=json.material.specular;
- this._materialInfo.ambientColor=new Vector3(ambient[0],ambient[1],ambient[2]);
- this._materialInfo.diffuseColor=new Vector3(diffuse[0],diffuse[1],diffuse[2]);
- this._materialInfo.specularColor=new Vector4(specular[0],specular[1],specular[2],specular[3]);
- };
- var detailTextures=json.detailTexture;
- this._detailTextureInfos=__newvec(detailTextures.length);
- for (var i=0;i < detailTextures.length;i++){
- var detail=detailTextures[i];
- var info=new DetailTextureInfo();
- info.diffuseTexture=resouMap[detail.diffuse];
- info.normalTexture=detail.normal ? resouMap[detail.normal] :null;
- if (detail.scale){
- info.scale=new Vector2(detail.scale[0],detail.scale[1]);
- }else {
- info.scale=new Vector2(1,1);
- }
- if (detail.offset){
- info.offset=new Vector2(detail.offset[0],detail.offset[1]);
- }else {
- info.offset=new Vector2(0,0);
- }
- this._detailTextureInfos[i]=info;
- };
- var alphaMaps=json.alphaMap;
- this._alphaMaps=__newvec(alphaMaps.length);
- for (i=0;i < this._alphaMaps.length;i++){
- this._alphaMaps[i]=json.alphaMap[i];
- };
- var normalMaps=json.normalMap;
- this._normalMaps=__newvec(normalMaps.length);
- for (i=0;i < this._normalMaps.length;i++){
- this._normalMaps[i]=json.normalMap[i];
- };
- var jchunks=json.chunkInfo;
- if (this._chunkNumX *this._chunkNumZ !=jchunks.length){
- alert("terrain data error");
- return false;
- }
- this._chunkInfos=__newvec(jchunks.length);
- for (i=0;i < jchunks.length;i++){
- var jchunk=jchunks[i];
- var chunkinfo=new ChunkInfo();
- var nAlphaMapNum=jchunk.alphaMap.length;
- var nDetailIDNum=jchunk.detailID.length;
- if (nAlphaMapNum !=nDetailIDNum){
- alert("terrain chunk data error");
- return false;
- }
- chunkinfo.alphaMap=__newvec(nAlphaMapNum);
- chunkinfo.detailID=__newvec(nDetailIDNum);
- chunkinfo.normalMap=resouMap[this._normalMaps[jchunk.normalMap]];
- for (var j=0;j < nAlphaMapNum;j++){
- chunkinfo.alphaMap[j]=resouMap[this._alphaMaps[jchunk.alphaMap[j]]];
- var jid=jchunk.detailID[j];
- var nIDNum=jid.length;
- chunkinfo.detailID[j]=new Uint8Array(nIDNum);
- for (var k=0;k < nIDNum;k++){
- chunkinfo.detailID[j][k]=jid[k];
- }
- }
- this._chunkInfos[i]=chunkinfo;
- }
- this._heightData=Loader.getRes(this._heightDataUrl);
- this.onLoadTerrainComplete(this._heightData);
- }
- return true;
- }
- __proto.onLoadTerrainComplete=function(heightData){}
- TerrainRes._parse=function(data,propertyParams,constructParams){
- var terrainRes=new TerrainRes();
- terrainRes.parseData(data);
- return terrainRes;
- }
- TerrainRes.load=function(url,complete){
- Laya.loader.create(url,complete,null,/*Laya3D.TERRAINRES*/"TERRAIN",null,null,1,false);
- }
- return TerrainRes;
- })(Resource)
- /**
- *<code>ShurikenParticleRender</code> 类用于创建3D粒子渲染器。
- */
- //class laya.d3.core.particleShuriKen.ShurikenParticleRenderer extends laya.d3.core.render.BaseRender
- var ShurikenParticleRenderer=(function(_super){
- function ShurikenParticleRenderer(owner){
- /**@private */
- //this._defaultBoundBox=null;
- /**@private */
- //this._renderMode=0;
- /**@private */
- //this._mesh=null;
- /**拉伸广告牌模式摄像机速度缩放,暂不支持。*/
- //this.stretchedBillboardCameraSpeedScale=NaN;
- /**拉伸广告牌模式速度缩放。*/
- //this.stretchedBillboardSpeedScale=NaN;
- /**拉伸广告牌模式长度缩放。*/
- //this.stretchedBillboardLengthScale=NaN;
- this._finalGravity=new Vector3();
- this._tempRotationMatrix=new Matrix4x4();
- ShurikenParticleRenderer.__super.call(this,owner);
- this._defaultBoundBox=new BoundBox(new Vector3(),new Vector3());
- this._renderMode=-1;
- this.stretchedBillboardCameraSpeedScale=0.0;
- this.stretchedBillboardSpeedScale=0.0;
- this.stretchedBillboardLengthScale=1.0;
- }
- __class(ShurikenParticleRenderer,'laya.d3.core.particleShuriKen.ShurikenParticleRenderer',_super);
- var __proto=ShurikenParticleRenderer.prototype;
- /**
- *@inheritDoc
- */
- __proto._calculateBoundingBox=function(){
- var min=this._bounds.getMin();
- min.x=-Number.MAX_VALUE;
- min.y=-Number.MAX_VALUE;
- min.z=-Number.MAX_VALUE;
- this._bounds.setMin(min);
- var max=this._bounds.getMax();
- max.x=Number.MAX_VALUE;
- max.y=Number.MAX_VALUE;
- max.z=Number.MAX_VALUE;
- this._bounds.setMax(max);
- if (Render.supportWebGLPlusCulling){
- min=this._bounds.getMin();
- max=this._bounds.getMax();
- var buffer=FrustumCulling._cullingBuffer;
- buffer[this._cullingBufferIndex+1]=min.x;
- buffer[this._cullingBufferIndex+2]=min.y;
- buffer[this._cullingBufferIndex+3]=min.z;
- buffer[this._cullingBufferIndex+4]=max.x;
- buffer[this._cullingBufferIndex+5]=max.y;
- buffer[this._cullingBufferIndex+6]=max.z;
- }
- }
- /**
- *@inheritDoc
- */
- __proto._needRender=function(boundFrustum){
- if (boundFrustum){
- if (boundFrustum.containsBoundBox(this._bounds._getBoundBox())!==/*laya.d3.math.ContainmentType.Disjoint*/0){
- if ((this._owner).particleSystem.isAlive)
- return true;
- else
- return false;
- }else {
- return false;
- }
- }else {
- return true;
- }
- }
- /**
- *@inheritDoc
- */
- __proto._renderUpdate=function(context,transfrom){
- var particleSystem=(this._owner).particleSystem;
- var sv=this._shaderValues;
- var transform=this._owner.transform;
- switch (particleSystem.simulationSpace){
- case 0:
- break ;
- case 1:
- sv.setVector3(ShuriKenParticle3D.WORLDPOSITION,transform.position);
- sv.setQuaternion(ShuriKenParticle3D.WORLDROTATION,transform.rotation);
- break ;
- default :
- throw new Error("ShurikenParticleMaterial: SimulationSpace value is invalid.");
- }
- switch (particleSystem.scaleMode){
- case 0:;
- var scale=transform.scale;
- sv.setVector3(ShuriKenParticle3D.POSITIONSCALE,scale);
- sv.setVector3(ShuriKenParticle3D.SIZESCALE,scale);
- break ;
- case 1:;
- var localScale=transform.localScale;
- sv.setVector3(ShuriKenParticle3D.POSITIONSCALE,localScale);
- sv.setVector3(ShuriKenParticle3D.SIZESCALE,localScale);
- break ;
- case 2:
- sv.setVector3(ShuriKenParticle3D.POSITIONSCALE,transform.scale);
- sv.setVector3(ShuriKenParticle3D.SIZESCALE,Vector3._ONE);
- break ;
- }
- Vector3.scale(Physics3DUtils.gravity,particleSystem.gravityModifier,this._finalGravity);
- sv.setVector3(ShuriKenParticle3D.GRAVITY,this._finalGravity);
- sv.setInt(ShuriKenParticle3D.SIMULATIONSPACE,particleSystem.simulationSpace);
- sv.setBool(ShuriKenParticle3D.THREEDSTARTROTATION,particleSystem.threeDStartRotation);
- sv.setInt(ShuriKenParticle3D.SCALINGMODE,particleSystem.scaleMode);
- sv.setNumber(ShuriKenParticle3D.STRETCHEDBILLBOARDLENGTHSCALE,this.stretchedBillboardLengthScale);
- sv.setNumber(ShuriKenParticle3D.STRETCHEDBILLBOARDSPEEDSCALE,this.stretchedBillboardSpeedScale);
- sv.setNumber(ShuriKenParticle3D.CURRENTTIME,particleSystem._currentTime);
- }
- /**
- *@inheritDoc
- */
- __proto._destroy=function(){
- _super.prototype._destroy.call(this);
- (this._mesh)&& (this._mesh._removeReference(),this._mesh=null);
- }
- /**
- *设置渲染模式,0为BILLBOARD、1为STRETCHEDBILLBOARD、2为HORIZONTALBILLBOARD、3为VERTICALBILLBOARD、4为MESH。
- *@param value 渲染模式。
- */
- /**
- *获取渲染模式。
- *@return 渲染模式。
- */
- __getset(0,__proto,'renderMode',function(){
- return this._renderMode;
- },function(value){
- if (this._renderMode!==value){
- var defineDatas=this._defineDatas;
- switch (this._renderMode){
- case 0:
- defineDatas.remove(ShuriKenParticle3D.SHADERDEFINE_RENDERMODE_BILLBOARD);
- break ;
- case 1:
- defineDatas.remove(ShuriKenParticle3D.SHADERDEFINE_RENDERMODE_STRETCHEDBILLBOARD);
- break ;
- case 2:
- defineDatas.remove(ShuriKenParticle3D.SHADERDEFINE_RENDERMODE_HORIZONTALBILLBOARD);
- break ;
- case 3:
- defineDatas.remove(ShuriKenParticle3D.SHADERDEFINE_RENDERMODE_VERTICALBILLBOARD);
- break ;
- case 4:
- defineDatas.remove(ShuriKenParticle3D.SHADERDEFINE_RENDERMODE_MESH);
- break ;
- }
- this._renderMode=value;
- switch (value){
- case 0:
- defineDatas.add(ShuriKenParticle3D.SHADERDEFINE_RENDERMODE_BILLBOARD);
- break ;
- case 1:
- defineDatas.add(ShuriKenParticle3D.SHADERDEFINE_RENDERMODE_STRETCHEDBILLBOARD);
- break ;
- case 2:
- defineDatas.add(ShuriKenParticle3D.SHADERDEFINE_RENDERMODE_HORIZONTALBILLBOARD);
- break ;
- case 3:
- defineDatas.add(ShuriKenParticle3D.SHADERDEFINE_RENDERMODE_VERTICALBILLBOARD);
- break ;
- case 4:
- defineDatas.add(ShuriKenParticle3D.SHADERDEFINE_RENDERMODE_MESH);
- break ;
- default :
- throw new Error("ShurikenParticleRender: unknown renderMode Value.");
- }
- (this._owner).particleSystem._initBufferDatas();
- }
- });
- /**
- *设置网格渲染模式所使用的Mesh,rendderMode为4时生效。
- *@param value 网格模式所使用Mesh。
- */
- /**
- *获取网格渲染模式所使用的Mesh,rendderMode为4时生效。
- *@return 网格模式所使用Mesh。
- */
- __getset(0,__proto,'mesh',function(){
- return this._mesh
- },function(value){
- if (this._mesh!==value){
- (this._mesh)&& (this._mesh._removeReference());
- this._mesh=value;
- (value)&& (value._addReference());
- (this._owner).particleSystem._initBufferDatas();
- }
- });
- /**
- *@inheritDoc
- */
- __getset(0,__proto,'bounds',function(){
- if (this._boundsChange){
- this._calculateBoundingBox();
- this._boundsChange=false;
- }
- return this._bounds;
- });
- return ShurikenParticleRenderer;
- })(BaseRender)
- /**
- *<code>PhysicsTriggerComponent</code> 类用于创建物理触发器组件。
- */
- //class laya.d3.physics.PhysicsTriggerComponent extends laya.d3.physics.PhysicsComponent
- var PhysicsTriggerComponent=(function(_super){
- function PhysicsTriggerComponent(collisionGroup,canCollideWith){
- /**@private */
- this._isTrigger=false;
- PhysicsTriggerComponent.__super.call(this,collisionGroup,canCollideWith);
- }
- __class(PhysicsTriggerComponent,'laya.d3.physics.PhysicsTriggerComponent',_super);
- var __proto=PhysicsTriggerComponent.prototype;
- /**
- *@inheritDoc
- */
- __proto._onAdded=function(){
- _super.prototype._onAdded.call(this);
- this.isTrigger=this._isTrigger;
- }
- /**
- *@inheritDoc
- */
- __proto._cloneTo=function(dest){
- _super.prototype._cloneTo.call(this,dest);
- (dest).isTrigger=this._isTrigger;
- }
- /**
- *设置是否为触发器。
- *@param value 是否为触发器。
- */
- /**
- *获取是否为触发器。
- *@return 是否为触发器。
- */
- __getset(0,__proto,'isTrigger',function(){
- return this._isTrigger;
- },function(value){
- this._isTrigger=value;
- if (this._nativeColliderObject){
- var flags=this._nativeColliderObject.getCollisionFlags();
- if (value){
- if ((flags & 4)===0)
- this._nativeColliderObject.setCollisionFlags(flags | 4);
- }else {
- if ((flags & 4)!==0)
- this._nativeColliderObject.setCollisionFlags(flags ^ 4);
- }
- }
- });
- return PhysicsTriggerComponent;
- })(PhysicsComponent)
- /**
- *<code>CharacterController</code> 类用于创建角色控制器。
- */
- //class laya.d3.physics.CharacterController extends laya.d3.physics.PhysicsComponent
- var CharacterController=(function(_super){
- function CharacterController(stepheight,upAxis,collisionGroup,canCollideWith){
- /**@private */
- //this._stepHeight=NaN;
- /**@private */
- this._maxSlope=45.0;
- /**@private */
- this._jumpSpeed=10.0;
- /**@private */
- this._fallSpeed=55.0;
- /**@private */
- //this._nativeKinematicCharacter=null;
- this._upAxis=new Vector3(0,1,0);
- this._gravity=new Vector3(0,-9.8 *3,0);
- (stepheight===void 0)&& (stepheight=0.1);
- (collisionGroup===void 0)&& (collisionGroup=/*laya.d3.utils.Physics3DUtils.COLLISIONFILTERGROUP_DEFAULTFILTER*/0x1);
- (canCollideWith===void 0)&& (canCollideWith=Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER);
- this._stepHeight=stepheight;
- (upAxis)&& (this._upAxis=upAxis);
- CharacterController.__super.call(this,collisionGroup,canCollideWith);
- }
- __class(CharacterController,'laya.d3.physics.CharacterController',_super);
- var __proto=CharacterController.prototype;
- /**
- *@private
- */
- __proto._constructCharacter=function(){
- var physics3D=Laya3D._physics3D;
- if (this._nativeKinematicCharacter)
- physics3D.destroy(this._nativeKinematicCharacter);
- var nativeUpAxis=CharacterController._nativeTempVector30;
- nativeUpAxis.setValue(this._upAxis.x,this._upAxis.y,this._upAxis.z);
- this._nativeKinematicCharacter=new physics3D.btKinematicCharacterController(this._nativeColliderObject,this._colliderShape._nativeShape,this._stepHeight,nativeUpAxis);
- this.fallSpeed=this._fallSpeed;
- this.maxSlope=this._maxSlope;
- this.jumpSpeed=this._jumpSpeed;
- this.gravity=this._gravity;
- }
- /**
- *@inheritDoc
- */
- __proto._onShapeChange=function(colShape){
- _super.prototype._onShapeChange.call(this,colShape);
- this._constructCharacter();
- }
- /**
- *@inheritDoc
- */
- __proto._onAdded=function(){
- var physics3D=Laya3D._physics3D;
- var ghostObject=new physics3D.btPairCachingGhostObject();
- ghostObject.setUserIndex(this.id);
- ghostObject.setCollisionFlags(16);
- this._nativeColliderObject=ghostObject;
- if (this._colliderShape)
- this._constructCharacter();
- _super.prototype._onAdded.call(this);
- }
- /**
- *@inheritDoc
- */
- __proto._addToSimulation=function(){
- this._simulation._characters.push(this);
- this._simulation._addCharacter(this,this._collisionGroup,this._canCollideWith);
- }
- /**
- *@inheritDoc
- */
- __proto._removeFromSimulation=function(){
- this._simulation._removeCharacter(this);
- var characters=this._simulation._characters;
- characters.splice(characters.indexOf(this),1);
- }
- /**
- *@inheritDoc
- */
- __proto._cloneTo=function(dest){
- _super.prototype._cloneTo.call(this,dest);
- var destCharacterController=dest;
- destCharacterController.stepHeight=this._stepHeight;
- destCharacterController.upAxis=this._upAxis;
- destCharacterController.maxSlope=this._maxSlope;
- destCharacterController.jumpSpeed=this._jumpSpeed;
- destCharacterController.fallSpeed=this._fallSpeed;
- destCharacterController.gravity=this._gravity;
- }
- /**
- *@inheritDoc
- */
- __proto._onDestroy=function(){
- Laya3D._physics3D.destroy(this._nativeKinematicCharacter);
- _super.prototype._onDestroy.call(this);
- this._nativeKinematicCharacter=null;
- }
- /**
- *通过指定移动向量移动角色。
- *@param movement 移动向量。
- */
- __proto.move=function(movement){
- var nativeMovement=PhysicsComponent._nativeVector30;
- nativeMovement.setValue(-movement.x,movement.y,movement.z);
- this._nativeKinematicCharacter.setWalkDirection(nativeMovement);
- }
- /**
- *跳跃。
- *@param velocity 跳跃速度。
- */
- __proto.jump=function(velocity){
- if (velocity){
- var nativeVelocity=PhysicsComponent._nativeVector30;
- Utils3D._convertToBulletVec3(velocity,nativeVelocity,true);
- this._nativeKinematicCharacter.jump(nativeVelocity);
- }else {
- this._nativeKinematicCharacter.jump();
- }
- }
- /**
- *设置角色降落速度。
- *@param value 角色降落速度。
- */
- /**
- *获取角色降落速度。
- *@return 角色降落速度。
- */
- __getset(0,__proto,'fallSpeed',function(){
- return this._fallSpeed;
- },function(value){
- this._fallSpeed=value;
- this._nativeKinematicCharacter.setFallSpeed(value);
- });
- /**
- *设置角色行走的脚步高度,表示可跨越的最大高度。
- *@param value 脚步高度。
- */
- /**
- *获取角色行走的脚步高度,表示可跨越的最大高度。
- *@return 脚步高度。
- */
- __getset(0,__proto,'stepHeight',function(){
- return this._stepHeight;
- },function(value){
- this._stepHeight=value;
- this._constructCharacter();
- });
- /**
- *设置角色跳跃速度。
- *@param value 角色跳跃速度。
- */
- /**
- *获取角色跳跃速度。
- *@return 角色跳跃速度。
- */
- __getset(0,__proto,'jumpSpeed',function(){
- return this._jumpSpeed;
- },function(value){
- this._jumpSpeed=value;
- this._nativeKinematicCharacter.setJumpSpeed(value);
- });
- /**
- *设置重力。
- *@param value 重力。
- */
- /**
- *获取重力。
- *@return 重力。
- */
- __getset(0,__proto,'gravity',function(){
- return this._gravity;
- },function(value){
- this._gravity=value;
- var nativeGravity=CharacterController._nativeTempVector30;
- nativeGravity.setValue(-value.x,value.y,value.z);
- this._nativeKinematicCharacter.setGravity(nativeGravity);
- });
- /**
- *设置最大坡度。
- *@param value 最大坡度。
- */
- /**
- *获取最大坡度。
- *@return 最大坡度。
- */
- __getset(0,__proto,'maxSlope',function(){
- return this._maxSlope;
- },function(value){
- this._maxSlope=value;
- this._nativeKinematicCharacter.setMaxSlope((value / 180)*Math.PI);
- });
- /**
- *获取角色是否在地表。
- */
- __getset(0,__proto,'isGrounded',function(){
- return this._nativeKinematicCharacter.onGround();
- });
- /**
- *设置角色的Up轴。
- *@return 角色的Up轴。
- */
- /**
- *获取角色的Up轴。
- *@return 角色的Up轴。
- */
- __getset(0,__proto,'upAxis',function(){
- return this._upAxis;
- },function(value){
- this._upAxis=value;
- this._constructCharacter();
- });
- CharacterController.UPAXIS_X=0;
- CharacterController.UPAXIS_Y=1;
- CharacterController.UPAXIS_Z=2;
- __static(CharacterController,
- ['_nativeTempVector30',function(){return this._nativeTempVector30=new Laya3D._physics3D.btVector3(0,0,0);}
- ]);
- return CharacterController;
- })(PhysicsComponent)
- /**
- *<code>MeshRender</code> 类用于网格渲染器。
- */
- //class laya.d3.terrain.TerrainRender extends laya.d3.core.render.BaseRender
- var TerrainRender=(function(_super){
- function TerrainRender(owner){
- /**@private */
- this._terrainSprite3DOwner=null;
- /**@private */
- this._projectionViewWorldMatrix=null;
- TerrainRender.__super.call(this,owner);
- this._terrainSprite3DOwner=owner;
- this._projectionViewWorldMatrix=new Matrix4x4();
- }
- __class(TerrainRender,'laya.d3.terrain.TerrainRender',_super);
- var __proto=TerrainRender.prototype;
- /**
- *@inheritDoc
- */
- __proto._needRender=function(boundFrustum){
- if (boundFrustum)
- return boundFrustum.containsBoundBox(this._bounds._getBoundBox())!==/*laya.d3.math.ContainmentType.Disjoint*/0;
- else
- return true;
- }
- /**
- *@inheritDoc
- */
- __proto._calculateBoundingBox=function(){}
- /**
- *@inheritDoc
- */
- __proto._renderUpdate=function(context,transform){
- this._shaderValues.setMatrix4x4(Sprite3D.WORLDMATRIX,transform.worldMatrix);
- }
- /**
- *@inheritDoc
- */
- __proto._renderUpdateWithCamera=function(context,transform){
- var projectionView=context.projectionViewMatrix;
- Matrix4x4.multiply(projectionView,transform.worldMatrix,this._projectionViewWorldMatrix);
- this._shaderValues.setMatrix4x4(Sprite3D.MVPMATRIX,this._projectionViewWorldMatrix);
- }
- /**
- *@private
- */
- __proto._destroy=function(){
- _super.prototype._destroy.call(this);
- this._terrainSprite3DOwner=null;
- }
- return TerrainRender;
- })(BaseRender)
- /**
- *<code>MeshRenderer</code> 类用于网格渲染器。
- */
- //class laya.d3.core.MeshRenderer extends laya.d3.core.render.BaseRender
- var MeshRenderer=(function(_super){
- function MeshRenderer(owner){
- /**@private */
- //this._oriDefineValue=0;
- /**@private */
- //this._projectionViewWorldMatrix=null;
- MeshRenderer.__super.call(this,owner);
- this._projectionViewWorldMatrix=new Matrix4x4();
- }
- __class(MeshRenderer,'laya.d3.core.MeshRenderer',_super);
- var __proto=MeshRenderer.prototype;
- /**
- *@private
- */
- __proto._onMeshChange=function(mesh){
- this._boundsChange=true;
- }
- /**
- *@inheritDoc
- */
- __proto._calculateBoundingBox=function(){
- var sharedMesh=(this._owner).meshFilter.sharedMesh;
- if (sharedMesh){
- var worldMat=(this._owner).transform.worldMatrix;
- sharedMesh.bounds._tranform(worldMat,this._bounds);
- }
- if (Render.supportWebGLPlusCulling){
- var min=this._bounds.getMin();
- var max=this._bounds.getMax();
- var buffer=FrustumCulling._cullingBuffer;
- buffer[this._cullingBufferIndex+1]=min.x;
- buffer[this._cullingBufferIndex+2]=min.y;
- buffer[this._cullingBufferIndex+3]=min.z;
- buffer[this._cullingBufferIndex+4]=max.x;
- buffer[this._cullingBufferIndex+5]=max.y;
- buffer[this._cullingBufferIndex+6]=max.z;
- }
- }
- /**
- *@private
- */
- __proto._changeRenderObjectsByMesh=function(mesh){
- var count=mesh.subMeshCount;
- this._renderElements.length=count;
- for (var i=0;i < count;i++){
- var renderElement=this._renderElements[i];
- if (!renderElement){
- var material=this.sharedMaterials[i];
- renderElement=this._renderElements[i]=new SubMeshRenderElement();
- renderElement.setTransform(this._owner._transform);
- renderElement.render=this;
- renderElement.material=material ? material :BlinnPhongMaterial.defaultMaterial;
- }
- renderElement.setGeometry(mesh._getSubMesh(i));
- }
- }
- /**
- *@inheritDoc
- */
- __proto._needRender=function(boundFrustum){
- if (boundFrustum)
- return boundFrustum.containsBoundBox(this.bounds._getBoundBox())!==/*laya.d3.math.ContainmentType.Disjoint*/0;
- else
- return true;
- }
- /**
- *@inheritDoc
- */
- __proto._renderUpdate=function(context,transform){
- var element=context.renderElement;
- switch (element.renderType){
- case /*laya.d3.core.render.RenderElement.RENDERTYPE_NORMAL*/0:
- this._shaderValues.setMatrix4x4(Sprite3D.WORLDMATRIX,transform.worldMatrix);
- break ;
- case /*laya.d3.core.render.RenderElement.RENDERTYPE_STATICBATCH*/1:
- this._oriDefineValue=this._defineDatas.value;
- if (transform)
- this._shaderValues.setMatrix4x4(Sprite3D.WORLDMATRIX,transform.worldMatrix);
- else
- this._shaderValues.setMatrix4x4(Sprite3D.WORLDMATRIX,Matrix4x4.DEFAULT);
- this._defineDatas.add(MeshSprite3D.SHADERDEFINE_UV1);
- this._defineDatas.remove(RenderableSprite3D.SHADERDEFINE_SCALEOFFSETLIGHTINGMAPUV);
- break ;
- case /*laya.d3.core.render.RenderElement.RENDERTYPE_VERTEXBATCH*/3:
- this._shaderValues.setMatrix4x4(Sprite3D.WORLDMATRIX,Matrix4x4.DEFAULT);
- break ;
- case /*laya.d3.core.render.RenderElement.RENDERTYPE_INSTANCEBATCH*/2:;
- var worldMatrixData=SubMeshInstanceBatch.instance.instanceWorldMatrixData;
- var insBatches=element.instanceBatchElementList;
- var count=insBatches.length;
- for (var i=0;i < count;i++)
- worldMatrixData.set(insBatches[i]._transform.worldMatrix.elements,i *16);
- SubMeshInstanceBatch.instance.instanceWorldMatrixBuffer.setData(worldMatrixData,0,0,count *16);
- this._defineDatas.add(MeshSprite3D.SHADERDEFINE_GPU_INSTANCE);
- break ;
- }
- }
- /**
- *@inheritDoc
- */
- __proto._renderUpdateWithCamera=function(context,transform){
- var projectionView=context.projectionViewMatrix;
- var element=context.renderElement;
- switch (element.renderType){
- case /*laya.d3.core.render.RenderElement.RENDERTYPE_NORMAL*/0:
- case /*laya.d3.core.render.RenderElement.RENDERTYPE_STATICBATCH*/1:
- case /*laya.d3.core.render.RenderElement.RENDERTYPE_VERTEXBATCH*/3:
- if (transform){
- Matrix4x4.multiply(projectionView,transform.worldMatrix,this._projectionViewWorldMatrix);
- this._shaderValues.setMatrix4x4(Sprite3D.MVPMATRIX,this._projectionViewWorldMatrix);
- }else {
- this._shaderValues.setMatrix4x4(Sprite3D.MVPMATRIX,projectionView);
- }
- break ;
- case /*laya.d3.core.render.RenderElement.RENDERTYPE_INSTANCEBATCH*/2:;
- var mvpMatrixData=SubMeshInstanceBatch.instance.instanceMVPMatrixData;
- var insBatches=element.instanceBatchElementList;
- var count=insBatches.length;
- for (var i=0;i < count;i++){
- var worldMat=insBatches[i]._transform.worldMatrix;
- Utils3D.mulMatrixByArray(projectionView.elements,0,worldMat.elements,0,mvpMatrixData,i *16);
- }
- SubMeshInstanceBatch.instance.instanceMVPMatrixBuffer.setData(mvpMatrixData,0,0,count *16);
- break ;
- }
- }
- /**
- *@inheritDoc
- */
- __proto._renderUpdateWithCameraForNative=function(context,transform){
- var projectionView=context.projectionViewMatrix;
- var element=context.renderElement;
- switch (element.renderType){
- case /*laya.d3.core.render.RenderElement.RENDERTYPE_NORMAL*/0:
- if (transform){
- Matrix4x4.multiply(projectionView,transform.worldMatrix,this._projectionViewWorldMatrix);
- this._shaderValues.setMatrix4x4(Sprite3D.MVPMATRIX,this._projectionViewWorldMatrix);
- }else {
- this._shaderValues.setMatrix4x4(Sprite3D.MVPMATRIX,projectionView);
- }
- break ;
- case /*laya.d3.core.render.RenderElement.RENDERTYPE_STATICBATCH*/1:
- case /*laya.d3.core.render.RenderElement.RENDERTYPE_VERTEXBATCH*/3:;
- var noteValue=ShaderData._SET_RUNTIME_VALUE_MODE_REFERENCE_;
- ShaderData.setRuntimeValueMode(false);
- if (transform){
- Matrix4x4.multiply(projectionView,transform.worldMatrix,this._projectionViewWorldMatrix);
- this._shaderValues.setMatrix4x4(Sprite3D.MVPMATRIX,this._projectionViewWorldMatrix);
- }else {
- this._shaderValues.setMatrix4x4(Sprite3D.MVPMATRIX,projectionView);
- }
- ShaderData.setRuntimeValueMode(noteValue);
- break ;
- case /*laya.d3.core.render.RenderElement.RENDERTYPE_INSTANCEBATCH*/2:;
- var mvpMatrixData=SubMeshInstanceBatch.instance.instanceMVPMatrixData;
- var insBatches=element.instanceBatchElementList;
- var count=insBatches.length;
- for (var i=0;i < count;i++){
- var worldMat=insBatches[i]._transform.worldMatrix;
- Utils3D.mulMatrixByArray(projectionView.elements,0,worldMat.elements,0,mvpMatrixData,i *16);
- }
- SubMeshInstanceBatch.instance.instanceMVPMatrixBuffer.setData(mvpMatrixData,0,0,count *16);
- break ;
- }
- }
- /**
- *@private
- */
- __proto._revertBatchRenderUpdate=function(context){
- var element=context.renderElement;
- switch (element.renderType){
- case /*laya.d3.core.render.RenderElement.RENDERTYPE_STATICBATCH*/1:
- this._defineDatas.value=this._oriDefineValue;
- break ;
- case /*laya.d3.core.render.RenderElement.RENDERTYPE_INSTANCEBATCH*/2:
- this._defineDatas.remove(MeshSprite3D.SHADERDEFINE_GPU_INSTANCE);
- break ;
- }
- }
- /**
- *@inheritDoc
- */
- __proto._destroy=function(){
- (this._isPartOfStaticBatch)&& (MeshRenderStaticBatchManager.instance._destroyRenderSprite(this._owner));
- _super.prototype._destroy.call(this);
- }
- __static(MeshRenderer,
- ['_tempVector30',function(){return this._tempVector30=new Vector3();},'_tempVector31',function(){return this._tempVector31=new Vector3();}
- ]);
- return MeshRenderer;
- })(BaseRender)
- /**
- *<code>TrailRenderer</code> 类用于创建拖尾渲染器。
- */
- //class laya.d3.core.trail.TrailRenderer extends laya.d3.core.render.BaseRender
- var TrailRenderer=(function(_super){
- function TrailRenderer(owner){
- this._projectionViewWorldMatrix=new Matrix4x4();
- TrailRenderer.__super.call(this,owner);
- }
- __class(TrailRenderer,'laya.d3.core.trail.TrailRenderer',_super);
- var __proto=TrailRenderer.prototype;
- /**
- *@inheritDoc
- */
- __proto._calculateBoundingBox=function(){
- var min=this._bounds.getMin();
- min.x=-Number.MAX_VALUE;
- min.y=-Number.MAX_VALUE;
- min.z=-Number.MAX_VALUE;
- this._bounds.setMin(min);
- var max=this._bounds.getMax();
- max.x=Number.MAX_VALUE;
- max.y=Number.MAX_VALUE;
- max.z=Number.MAX_VALUE;
- this._bounds.setMax(max);
- if (Render.supportWebGLPlusCulling){
- min=this._bounds.getMin();
- max=this._bounds.getMax();
- var buffer=FrustumCulling._cullingBuffer;
- buffer[this._cullingBufferIndex+1]=min.x;
- buffer[this._cullingBufferIndex+2]=min.y;
- buffer[this._cullingBufferIndex+3]=min.z;
- buffer[this._cullingBufferIndex+4]=max.x;
- buffer[this._cullingBufferIndex+5]=max.y;
- buffer[this._cullingBufferIndex+6]=max.z;
- }
- }
- /**
- *@inheritDoc
- */
- __proto._needRender=function(boundFrustum){
- return true;
- }
- /**
- *@inheritDoc
- */
- __proto._renderUpdate=function(state,transform){
- _super.prototype._renderUpdate.call(this,state,transform);
- (this._owner).trailFilter._update(state);
- }
- /**
- *@inheritDoc
- */
- __proto._renderUpdateWithCamera=function(context,transform){
- var projectionView=context.projectionViewMatrix;
- if (transform){
- Matrix4x4.multiply(projectionView,transform.worldMatrix,this._projectionViewWorldMatrix);
- this._shaderValues.setMatrix4x4(Sprite3D.MVPMATRIX,this._projectionViewWorldMatrix);
- }else {
- this._shaderValues.setMatrix4x4(Sprite3D.MVPMATRIX,projectionView);
- }
- }
- return TrailRenderer;
- })(BaseRender)
- /**
- *<code>PixelLineRenderer</code> 类用于线渲染器。
- */
- //class laya.d3.core.pixelLine.PixelLineRenderer extends laya.d3.core.render.BaseRender
- var PixelLineRenderer=(function(_super){
- function PixelLineRenderer(owner){
- /**@private */
- this._projectionViewWorldMatrix=null;
- PixelLineRenderer.__super.call(this,owner);
- this._projectionViewWorldMatrix=new Matrix4x4();
- }
- __class(PixelLineRenderer,'laya.d3.core.pixelLine.PixelLineRenderer',_super);
- var __proto=PixelLineRenderer.prototype;
- /**
- *@inheritDoc
- */
- __proto._calculateBoundingBox=function(){
- var min=this._bounds.getMin();
- min.x=-Number.MAX_VALUE;
- min.y=-Number.MAX_VALUE;
- min.z=-Number.MAX_VALUE;
- this._bounds.setMin(min);
- var max=this._bounds.getMax();
- max.x=Number.MAX_VALUE;
- max.y=Number.MAX_VALUE;
- max.z=Number.MAX_VALUE;
- this._bounds.setMax(max);
- if (Render.supportWebGLPlusCulling){
- min=this._bounds.getMin();
- max=this._bounds.getMax();
- var buffer=FrustumCulling._cullingBuffer;
- buffer[this._cullingBufferIndex+1]=min.x;
- buffer[this._cullingBufferIndex+2]=min.y;
- buffer[this._cullingBufferIndex+3]=min.z;
- buffer[this._cullingBufferIndex+4]=max.x;
- buffer[this._cullingBufferIndex+5]=max.y;
- buffer[this._cullingBufferIndex+6]=max.z;
- }
- }
- /**
- *@inheritDoc
- */
- __proto._renderUpdateWithCamera=function(context,transform){
- var projectionView=context.projectionViewMatrix;
- var sv=this._shaderValues;
- if (transform){
- var worldMat=transform.worldMatrix;
- sv.setMatrix4x4(Sprite3D.WORLDMATRIX,worldMat);
- Matrix4x4.multiply(projectionView,worldMat,this._projectionViewWorldMatrix);
- sv.setMatrix4x4(Sprite3D.MVPMATRIX,this._projectionViewWorldMatrix);
- }else {
- sv.setMatrix4x4(Sprite3D.WORLDMATRIX,Matrix4x4.DEFAULT);
- sv.setMatrix4x4(Sprite3D.MVPMATRIX,projectionView);
- }
- }
- return PixelLineRenderer;
- })(BaseRender)
- /**
- *<code>Scene3D</code> 类用于实现场景。
- */
- //class laya.d3.core.scene.Scene3D extends laya.display.Sprite
- var Scene3D=(function(_super){
- function Scene3D(){
- /**@private */
- //this._url=null;
- /**@private */
- //this._group=null;
- /**@private */
- this._reflectionMode=1;
- /**@private */
- this._enableLightCount=3;
- /**@private */
- //this._renderTargetTexture=null;
- /**@private */
- //this._enableFog=false;
- /**@private */
- //this._physicsSimulation=null;
- /**@private */
- //this._octree=null;
- /**@private */
- //this._shaderValues=null;
- /**@private */
- //this._defineDatas=null;
- /**是否启用灯光。*/
- this.enableLight=true;
- //阴影相关变量
- //this.parallelSplitShadowMaps=null;
- /**@private */
- //this._debugTool=null;
- this._time=0;
- /**@private [NATIVE]*/
- //this._cullingBufferIndices=null;
- /**@private [NATIVE]*/
- //this._cullingBufferResult=null;
- Scene3D.__super.call(this);
- this._lights=[];
- this._lightmaps=[];
- this._skyRenderer=new SkyRenderer();
- this._input=new Input3D();
- this._timer=Laya.timer;
- this._collsionTestList=[];
- this._renders=new SimpleSingletonList();
- this._opaqueQueue=new RenderQueue(false);
- this._transparentQueue=new RenderQueue(true);
- this._cameraPool=[];
- this._animatorPool=new SimpleSingletonList();
- this._scriptPool=new SimpleSingletonList();
- this._castShadowRenders=new CastShadowList();
- this.currentCreationLayer=Math.pow(2,0);
- this._key=new SubmitKey();
- this._pickIdToSprite=new Object();
- if (Laya3D._enbalePhysics)
- this._physicsSimulation=new PhysicsSimulation(Laya3D.physicsSettings);
- this._defineDatas=new DefineDatas();
- this._shaderValues=new ShaderData(null);
- this.parallelSplitShadowMaps=[];
- this.enableFog=false;
- this.fogStart=300;
- this.fogRange=1000;
- this.fogColor=new Vector3(0.7,0.7,0.7);
- this.ambientColor=new Vector3(0.212,0.227,0.259);
- this.reflectionIntensity=1.0;
- (WebGL.shaderHighPrecision)&& (this._defineDatas.add(Shader3D.SHADERDEFINE_HIGHPRECISION));
- if (Render.supportWebGLPlusCulling){
- this._cullingBufferIndices=new Int32Array(1024);
- this._cullingBufferResult=new Int32Array(1024);
- }
- this._shaderValues.setTexture(laya.d3.core.scene.Scene3D.RANGEATTENUATIONTEXTURE,ShaderInit3D._rangeAttenTex);
- this._scene=this;
- if (Laya3D._enbalePhysics && !PhysicsSimulation.disableSimulation)
- this._input.__init__(Render.canvas,this);
- var config=Laya3D._config;
- if (config.octreeCulling){
- this._octree=new BoundsOctree(config.octreeInitialSize,config.octreeInitialCenter,config.octreeMinNodeSize,config.octreeLooseness);
- }
- if (Laya3D._config.debugFrustumCulling){
- this._debugTool=new PixelLineSprite3D();
- var lineMaterial=new PixelLineMaterial();
- lineMaterial.renderQueue=/*laya.d3.core.material.BaseMaterial.RENDERQUEUE_TRANSPARENT*/3000;
- lineMaterial.alphaTest=false;
- lineMaterial.depthWrite=false;
- lineMaterial.cull=/*laya.d3.core.material.RenderState.CULL_BACK*/2;
- lineMaterial.blend=/*laya.d3.core.material.RenderState.BLEND_ENABLE_ALL*/1;
- lineMaterial.blendSrc=/*laya.d3.core.material.RenderState.BLENDPARAM_SRC_ALPHA*/0x0302;
- lineMaterial.blendDst=/*laya.d3.core.material.RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA*/0x0303;
- lineMaterial.depthTest=/*laya.d3.core.material.RenderState.DEPTHTEST_LESS*/0x0201;
- this._debugTool.pixelLineRenderer.sharedMaterial=lineMaterial;
- }
- }
- __class(Scene3D,'laya.d3.core.scene.Scene3D',_super);
- var __proto=Scene3D.prototype;
- Laya.imps(__proto,{"laya.webgl.submit.ISubmit":true,"laya.resource.ICreateResource":true})
- /**
- *@private
- *[Editer]
- */
- __proto._allotPickColorByID=function(id,pickColor){
- var pickColorR=Math.floor(id / (255 *255));
- id-=pickColorR *255 *255;
- var pickColorG=Math.floor(id / 255);
- id-=pickColorG *255;
- var pickColorB=id;
- pickColor.x=pickColorR / 255;
- pickColor.y=pickColorG / 255;
- pickColor.z=pickColorB / 255;
- pickColor.w=1.0;
- }
- /**
- *@private
- *[Editer]
- */
- __proto._searchIDByPickColor=function(pickColor){
- var id=pickColor.x *255 *255+pickColor.y *255+pickColor.z;
- return id;
- }
- /**
- *@private
- */
- __proto._setLightmapToChildNode=function(sprite){
- if ((sprite instanceof laya.d3.core.RenderableSprite3D ))
- (sprite)._render._applyLightMapParams();
- var children=sprite._children;
- for (var i=0,n=children.length;i < n;i++)
- this._setLightmapToChildNode(children[i]);
- }
- /**
- *@private
- */
- __proto._update=function(){
- var delta=this.timer._delta / 1000;
- this._time+=delta;
- this._shaderValues.setNumber(laya.d3.core.scene.Scene3D.TIME,this._time);
- var simulation=this._physicsSimulation;
- if (Laya3D._enbalePhysics && !PhysicsSimulation.disableSimulation){
- simulation._updatePhysicsTransformFromRender();
- PhysicsComponent._addUpdateList=false;
- simulation._simulate(delta);
- simulation._updateCharacters();
- PhysicsComponent._addUpdateList=true;
- simulation._updateCollisions();
- simulation._eventScripts();
- this._input._update();
- }
- this._updateScript();
- Animator._update(this);
- this._lateUpdateScript();
- }
- /**
- *@private
- */
- __proto._binarySearchIndexInCameraPool=function(camera){
- var start=0;
- var end=this._cameraPool.length-1;
- var mid=0;
- while (start <=end){
- mid=Math.floor((start+end)/ 2);
- var midValue=this._cameraPool[mid]._renderingOrder;
- if (midValue==camera._renderingOrder)
- return mid;
- else if (midValue > camera._renderingOrder)
- end=mid-1;
- else
- start=mid+1;
- }
- return start;
- }
- /**
- *@private
- */
- __proto._setCreateURL=function(url){
- this._url=URL.formatURL(url);
- }
- /**
- *@private
- */
- __proto._getGroup=function(){
- return this._group;
- }
- /**
- *@private
- */
- __proto._setGroup=function(value){
- this._group=value;
- }
- /**
- *@private
- */
- __proto._updateScript=function(){
- var pool=this._scriptPool;
- var elements=pool.elements;
- for (var i=0,n=pool.length;i < n;i++){
- var script=elements [i];
- (script && script.enabled)&& (script.onUpdate());
- }
- }
- /**
- *@private
- */
- __proto._lateUpdateScript=function(){
- var pool=this._scriptPool;
- var elements=pool.elements;
- for (var i=0,n=pool.length;i < n;i++){
- var script=elements [i];
- (script && script.enabled)&& (script.onLateUpdate());
- }
- }
- /**
- *@private
- */
- __proto._preRenderScript=function(){
- var pool=this._scriptPool;
- var elements=pool.elements;
- for (var i=0,n=pool.length;i < n;i++){
- var script=elements [i];
- (script && script.enabled)&& (script.onPreRender());
- }
- }
- /**
- *@private
- */
- __proto._postRenderScript=function(){
- var pool=this._scriptPool;
- var elements=pool.elements;
- for (var i=0,n=pool.length;i < n;i++){
- var script=elements [i];
- (script && script.enabled)&& (script.onPostRender());
- }
- }
- /**
- *@private
- */
- __proto._prepareSceneToRender=function(){
- var lightCount=this._lights.length;
- if (lightCount > 0){
- var renderLightCount=0;
- for (var i=0;i < lightCount;i++){
- if (!this._lights[i]._prepareToScene())
- continue ;
- renderLightCount++;
- if (renderLightCount >=this._enableLightCount)
- break ;
- }
- }
- }
- /**
- *@private
- */
- __proto._addCamera=function(camera){
- var index=this._binarySearchIndexInCameraPool(camera);
- var order=camera._renderingOrder;
- var count=this._cameraPool.length;
- while (index < count && this._cameraPool[index]._renderingOrder <=order)
- index++;
- this._cameraPool.splice(index,0,camera);
- }
- /**
- *@private
- */
- __proto._removeCamera=function(camera){
- this._cameraPool.splice(this._cameraPool.indexOf(camera),1);
- }
- /**
- *@private
- */
- __proto._preCulling=function(context,camera){
- FrustumCulling.renderObjectCulling(camera,this,context,this._renders);
- }
- /**
- *@private
- */
- __proto._clear=function(gl,state){
- var viewport=state.viewport;
- var camera=state.camera;
- var renderTarget=camera.getRenderTexture();
- var vpW=viewport.width;
- var vpH=viewport.height;
- var vpX=viewport.x;
- var vpY=camera._getCanvasHeight()-viewport.y-vpH;
- gl.viewport(vpX,vpY,vpW,vpH);
- var flag=0;
- var clearFlag=camera.clearFlag;
- if (clearFlag===/*laya.d3.core.BaseCamera.CLEARFLAG_SKY*/1 && !(camera.skyRenderer._isAvailable()|| this._skyRenderer._isAvailable()))
- clearFlag=/*laya.d3.core.BaseCamera.CLEARFLAG_SOLIDCOLOR*/0;
- switch (clearFlag){
- case /*laya.d3.core.BaseCamera.CLEARFLAG_SOLIDCOLOR*/0:;
- var clearColor=camera.clearColor;
- gl.enable(/*laya.webgl.WebGLContext.SCISSOR_TEST*/0x0C11);
- gl.scissor(vpX,vpY,vpW,vpH);
- if (clearColor)
- gl.clearColor(clearColor.x,clearColor.y,clearColor.z,clearColor.w);
- else
- gl.clearColor(0,0,0,0);
- if (renderTarget){
- flag=/*laya.webgl.WebGLContext.COLOR_BUFFER_BIT*/0x00004000;
- switch (renderTarget.depthStencilFormat){
- case /*laya.resource.BaseTexture.FORMAT_DEPTH_16*/0:
- flag |=/*laya.webgl.WebGLContext.DEPTH_BUFFER_BIT*/0x00000100;
- break ;
- case /*laya.resource.BaseTexture.FORMAT_STENCIL_8*/1:
- flag |=/*laya.webgl.WebGLContext.STENCIL_BUFFER_BIT*/0x00000400;
- break ;
- case /*laya.resource.BaseTexture.FORMAT_DEPTHSTENCIL_16_8*/2:
- flag |=/*laya.webgl.WebGLContext.DEPTH_BUFFER_BIT*/0x00000100;
- flag |=/*laya.webgl.WebGLContext.STENCIL_BUFFER_BIT*/0x00000400;
- break ;
- }
- }else {
- flag=/*laya.webgl.WebGLContext.COLOR_BUFFER_BIT*/0x00004000 | /*laya.webgl.WebGLContext.DEPTH_BUFFER_BIT*/0x00000100;
- }
- WebGLContext.setDepthMask(gl,true);
- gl.clear(flag);
- gl.disable(/*laya.webgl.WebGLContext.SCISSOR_TEST*/0x0C11);
- break ;
- case /*laya.d3.core.BaseCamera.CLEARFLAG_SKY*/1:
- case /*laya.d3.core.BaseCamera.CLEARFLAG_DEPTHONLY*/2:
- gl.enable(/*laya.webgl.WebGLContext.SCISSOR_TEST*/0x0C11);
- gl.scissor(vpX,vpY,vpW,vpH);
- if (renderTarget){
- switch (renderTarget.depthStencilFormat){
- case /*laya.resource.BaseTexture.FORMAT_DEPTH_16*/0:
- flag=/*laya.webgl.WebGLContext.DEPTH_BUFFER_BIT*/0x00000100;
- break ;
- case /*laya.resource.BaseTexture.FORMAT_STENCIL_8*/1:
- flag=/*laya.webgl.WebGLContext.STENCIL_BUFFER_BIT*/0x00000400;
- break ;
- case /*laya.resource.BaseTexture.FORMAT_DEPTHSTENCIL_16_8*/2:
- flag=/*laya.webgl.WebGLContext.DEPTH_BUFFER_BIT*/0x00000100 | /*laya.webgl.WebGLContext.STENCIL_BUFFER_BIT*/0x00000400;
- break ;
- }
- }else {
- flag=/*laya.webgl.WebGLContext.DEPTH_BUFFER_BIT*/0x00000100;
- }
- WebGLContext.setDepthMask(gl,true);
- gl.clear(flag);
- gl.disable(/*laya.webgl.WebGLContext.SCISSOR_TEST*/0x0C11);
- break ;
- case /*laya.d3.core.BaseCamera.CLEARFLAG_NONE*/3:
- break ;
- default :
- throw new Error("BaseScene:camera clearFlag invalid.");
- }
- }
- /**
- *@private
- */
- __proto._renderScene=function(gl,state,customShader,replacementTag){
- var camera=state.camera;
- var position=camera.transform.position;
- camera.getRenderTexture()? this._opaqueQueue._render(state,true,customShader,replacementTag):this._opaqueQueue._render(state,false,customShader,replacementTag);
- if (camera.clearFlag===/*laya.d3.core.BaseCamera.CLEARFLAG_SKY*/1){
- if (camera.skyRenderer._isAvailable())
- camera.skyRenderer._render(state);
- else if (this._skyRenderer._isAvailable())
- this._skyRenderer._render(state);
- }
- camera.getRenderTexture()? this._transparentQueue._render(state,true,customShader,replacementTag):this._transparentQueue._render(state,false,customShader,replacementTag);
- camera._applyPostProcessCommandBuffers();
- if (Laya3D._config.debugFrustumCulling){
- var renderElements=this._debugTool._render._renderElements;
- for (var i=0,n=renderElements.length;i < n;i++){
- renderElements[i]._render(state,false,customShader,replacementTag);
- }
- }
- }
- /**
- *@inheritDoc
- */
- __proto._parse=function(data,spriteMap){
- var lightMapsData=data.lightmaps;
- if (lightMapsData){
- var lightMapCount=lightMapsData.length;
- var lightmaps=__newvec(lightMapCount);
- for (var i=0;i < lightMapCount;i++)
- lightmaps[i]=Loader.getRes(lightMapsData[i].path);
- this.setlightmaps(lightmaps);
- };
- var ambientColorData=data.ambientColor;
- if (ambientColorData){
- var ambCol=this.ambientColor;
- ambCol.fromArray(ambientColorData);
- this.ambientColor=ambCol;
- };
- var skyData=data.sky;
- if (skyData){
- this._skyRenderer.material=Loader.getRes(skyData.material.path);
- switch (skyData.mesh){
- case "SkyBox":
- this._skyRenderer.mesh=SkyBox.instance;
- break ;
- case "SkyDome":
- this._skyRenderer.mesh=SkyDome.instance;
- break ;
- default :
- this.skyRenderer.mesh=SkyBox.instance;
- }
- };
- var reflectionTextureData=data.reflectionTexture;
- reflectionTextureData && (this.customReflection=Loader.getRes(reflectionTextureData));
- this.enableFog=data.enableFog;
- this.fogStart=data.fogStart;
- this.fogRange=data.fogRange;
- var fogColorData=data.fogColor;
- if (fogColorData){
- var fogCol=this.fogColor;
- fogCol.fromArray(fogColorData);
- this.fogColor=fogCol;
- }
- }
- /**
- *@inheritDoc
- */
- __proto._onActive=function(){
- laya.display.Node.prototype._onActive.call(this);
- Laya.stage._scene3Ds.push(this);
- }
- /**
- *@inheritDoc
- */
- __proto._onInActive=function(){
- laya.display.Node.prototype._onInActive.call(this);
- var scenes=Laya.stage._scene3Ds;
- scenes.splice(scenes.indexOf(this),1);
- }
- /**
- *@private
- */
- __proto._addLight=function(light){
- if (this._lights.indexOf(light)< 0)this._lights.push(light);
- }
- /**
- *@private
- */
- __proto._removeLight=function(light){
- var index=this._lights.indexOf(light);
- index >=0 && (this._lights.splice(index,1));
- }
- /**
- *@private
- */
- __proto._addRenderObject=function(render){
- if (this._octree){
- this._octree.add(render);
- }else {
- this._renders.add(render);
- if (Render.supportWebGLPlusCulling){
- var indexInList=render._getIndexInList();
- var length=this._cullingBufferIndices.length;
- if (indexInList >=length){
- var tempIndices=this._cullingBufferIndices;
- var tempResult=this._cullingBufferResult;
- this._cullingBufferIndices=new Int32Array(length+1024);
- this._cullingBufferResult=new Int32Array(length+1024);
- this._cullingBufferIndices.set(tempIndices,0);
- this._cullingBufferResult.set(tempResult,0);
- }
- this._cullingBufferIndices[indexInList]=render._cullingBufferIndex;
- }
- }
- }
- /**
- *@private
- */
- __proto._removeRenderObject=function(render){
- if (this._octree){
- this._octree.remove(render);
- }else {
- var endRender;
- if (Render.supportWebGLPlusCulling){
- endRender=this._renders.elements [this._renders.length-1];
- }
- this._renders.remove(render);
- if (Render.supportWebGLPlusCulling){
- this._cullingBufferIndices[endRender._getIndexInList()]=endRender._cullingBufferIndex;
- }
- }
- }
- /**
- *@private
- */
- __proto._addShadowCastRenderObject=function(render){
- if (this._octree){
- }else {
- this._castShadowRenders.add(render);
- }
- }
- /**
- *@private
- */
- __proto._removeShadowCastRenderObject=function(render){
- if (this._octree){
- }else {
- this._castShadowRenders.remove(render);
- }
- }
- /**
- *@private
- */
- __proto._getRenderQueue=function(index){
- if (index <=2500)
- return this._opaqueQueue;
- else
- return this._transparentQueue;
- }
- /**
- *设置光照贴图。
- *@param value 光照贴图。
- */
- __proto.setlightmaps=function(value){
- var maps=this._lightmaps;
- for (var i=0,n=maps.length;i < n;i++)
- maps[i]._removeReference();
- if (value){
- var count=value.length;
- maps.length=count;
- for (i=0;i < count;i++){
- var lightMap=value[i];
- lightMap._addReference();
- maps[i]=lightMap;
- }
- }else {
- throw new Error("Scene3D: value value can't be null.");
- }
- for (i=0,n=this._children.length;i < n;i++)
- this._setLightmapToChildNode(this._children[i]);
- }
- /**
- *获取光照贴图浅拷贝列表。
- *@return 获取光照贴图浅拷贝列表。
- */
- __proto.getlightmaps=function(){
- return this._lightmaps.slice();
- }
- /**
- *@inheritDoc
- */
- __proto.destroy=function(destroyChild){
- (destroyChild===void 0)&& (destroyChild=true);
- if (this.destroyed)
- return;
- _super.prototype.destroy.call(this,destroyChild);
- this._skyRenderer.destroy();
- this._skyRenderer=null;
- this._lights=null;
- this._lightmaps=null;
- this._renderTargetTexture=null;
- this._shaderValues=null;
- this._renders=null;
- this._castShadowRenders=null;
- this._cameraPool=null;
- this._octree=null;
- this.parallelSplitShadowMaps=null;
- this._physicsSimulation && this._physicsSimulation._destroy();
- Loader.clearRes(this.url);
- }
- /**
- *@inheritDoc
- */
- __proto.render=function(ctx,x,y){
- ctx._curSubmit=Submit.RENDERBASE;
- this._children.length > 0 && ctx.addRenderObject(this);
- }
- /**
- *@private
- */
- __proto.renderSubmit=function(){
- var gl=LayaGL.instance;
- this._prepareSceneToRender();
- var i=0,n=0,n1=0;
- for (i=0,n=this._cameraPool.length,n1=n-1;i < n;i++){
- if (Render.supportWebGLPlusRendering)
- ShaderData.setRuntimeValueMode((i==n1)? true :false);
- var camera=this._cameraPool [i];
- camera.enableRender && camera.render();
- }
- Context.set2DRenderConfig();
- return 1;
- }
- /**
- *@private
- */
- __proto.getRenderType=function(){
- return 0;
- }
- /**
- *@private
- */
- __proto.releaseRender=function(){}
- /**
- *@private
- */
- __proto.reUse=function(context,pos){
- return 0;
- }
- /**
- *设置雾化颜色。
- *@param value 雾化颜色。
- */
- /**
- *获取雾化颜色。
- *@return 雾化颜色。
- */
- __getset(0,__proto,'fogColor',function(){
- return this._shaderValues.getVector(laya.d3.core.scene.Scene3D.FOGCOLOR);
- },function(value){
- this._shaderValues.setVector3(laya.d3.core.scene.Scene3D.FOGCOLOR,value);
- });
- /**
- *设置是否允许雾化。
- *@param value 是否允许雾化。
- */
- /**
- *获取是否允许雾化。
- *@return 是否允许雾化。
- */
- __getset(0,__proto,'enableFog',function(){
- return this._enableFog;
- },function(value){
- if (this._enableFog!==value){
- this._enableFog=value;
- if (value){
- this._defineDatas.add(laya.d3.core.scene.Scene3D.SHADERDEFINE_FOG);
- }else
- this._defineDatas.remove(laya.d3.core.scene.Scene3D.SHADERDEFINE_FOG);
- }
- });
- /**
- *获取资源的URL地址。
- *@return URL地址。
- */
- __getset(0,__proto,'url',function(){
- return this._url;
- });
- /**
- *设置雾化起始位置。
- *@param value 雾化起始位置。
- */
- /**
- *获取雾化起始位置。
- *@return 雾化起始位置。
- */
- __getset(0,__proto,'fogStart',function(){
- return this._shaderValues.getNumber(laya.d3.core.scene.Scene3D.FOGSTART);
- },function(value){
- this._shaderValues.setNumber(laya.d3.core.scene.Scene3D.FOGSTART,value);
- });
- /**
- *设置反射强度。
- *@param 反射强度。
- */
- /**
- *获取反射强度。
- *@return 反射强度。
- */
- __getset(0,__proto,'reflectionIntensity',function(){
- return this._shaderValues.getNumber(laya.d3.core.scene.Scene3D.REFLETIONINTENSITY);
- },function(value){
- value=Math.max(Math.min(value,1.0),0.0);
- this._shaderValues.setNumber(laya.d3.core.scene.Scene3D.REFLETIONINTENSITY,value);
- });
- /**
- *获取天空渲染器。
- *@return 天空渲染器。
- */
- __getset(0,__proto,'skyRenderer',function(){
- return this._skyRenderer;
- });
- /**
- *设置雾化范围。
- *@param value 雾化范围。
- */
- /**
- *获取雾化范围。
- *@return 雾化范围。
- */
- __getset(0,__proto,'fogRange',function(){
- return this._shaderValues.getNumber(laya.d3.core.scene.Scene3D.FOGRANGE);
- },function(value){
- this._shaderValues.setNumber(laya.d3.core.scene.Scene3D.FOGRANGE,value);
- });
- /**
- *设置环境光颜色。
- *@param value 环境光颜色。
- */
- /**
- *获取环境光颜色。
- *@return 环境光颜色。
- */
- __getset(0,__proto,'ambientColor',function(){
- return this._shaderValues.getVector(laya.d3.core.scene.Scene3D.AMBIENTCOLOR);
- },function(value){
- this._shaderValues.setVector3(laya.d3.core.scene.Scene3D.AMBIENTCOLOR,value);
- });
- /**
- *设置反射贴图。
- *@param 反射贴图。
- */
- /**
- *获取反射贴图。
- *@return 反射贴图。
- */
- __getset(0,__proto,'customReflection',function(){
- return this._shaderValues.getTexture(laya.d3.core.scene.Scene3D.REFLECTIONTEXTURE);
- },function(value){
- this._shaderValues.setTexture(laya.d3.core.scene.Scene3D.REFLECTIONTEXTURE,value);
- if (value)
- this._defineDatas.add(laya.d3.core.scene.Scene3D.SHADERDEFINE_REFLECTMAP);
- else
- this._defineDatas.remove(laya.d3.core.scene.Scene3D.SHADERDEFINE_REFLECTMAP);
- });
- /**
- *获取物理模拟器。
- *@return 物理模拟器。
- */
- __getset(0,__proto,'physicsSimulation',function(){
- return this._physicsSimulation;
- });
- /**
- *设置反射模式。
- *@param value 反射模式。
- */
- /**
- *获取反射模式。
- *@return 反射模式。
- */
- __getset(0,__proto,'reflectionMode',function(){
- return this._reflectionMode;
- },function(value){
- this._reflectionMode=value;
- });
- /**
- *设置场景时钟。
- */
- /**
- *获取场景时钟。
- */
- __getset(0,__proto,'timer',function(){
- return this._timer;
- },function(value){
- this._timer=value;
- });
- /**
- *获取输入。
- *@return 输入。
- */
- __getset(0,__proto,'input',function(){
- return this._input;
- });
- Scene3D._parse=function(data,propertyParams,constructParams){
- var json=data.data;
- var outBatchSprits=[];
- var scene;
- switch (data.version){
- case "LAYAHIERARCHY:02":
- scene=Utils3D._createNodeByJson02(json,outBatchSprits);
- break ;
- default :
- scene=Utils3D._createNodeByJson(json,outBatchSprits);
- }
- StaticBatchManager.combine(null,outBatchSprits);
- return scene;
- }
- Scene3D.load=function(url,complete){
- Laya.loader.create(url,complete,null,/*Laya3D.HIERARCHY*/"HIERARCHY");
- }
- Scene3D.REFLECTIONMODE_SKYBOX=0;
- Scene3D.REFLECTIONMODE_CUSTOM=1;
- Scene3D.SHADERDEFINE_FOG=0;
- Scene3D.SHADERDEFINE_DIRECTIONLIGHT=0;
- Scene3D.SHADERDEFINE_POINTLIGHT=0;
- Scene3D.SHADERDEFINE_SPOTLIGHT=0;
- Scene3D.SHADERDEFINE_CAST_SHADOW=0;
- Scene3D.SHADERDEFINE_SHADOW_PSSM1=0;
- Scene3D.SHADERDEFINE_SHADOW_PSSM2=0;
- Scene3D.SHADERDEFINE_SHADOW_PSSM3=0;
- Scene3D.SHADERDEFINE_SHADOW_PCF_NO=0;
- Scene3D.SHADERDEFINE_SHADOW_PCF1=0;
- Scene3D.SHADERDEFINE_SHADOW_PCF2=0;
- Scene3D.SHADERDEFINE_SHADOW_PCF3=0;
- Scene3D.SHADERDEFINE_REFLECTMAP=0;
- __static(Scene3D,
- ['FOGCOLOR',function(){return this.FOGCOLOR=Shader3D.propertyNameToID("u_FogColor");},'FOGSTART',function(){return this.FOGSTART=Shader3D.propertyNameToID("u_FogStart");},'FOGRANGE',function(){return this.FOGRANGE=Shader3D.propertyNameToID("u_FogRange");},'LIGHTDIRECTION',function(){return this.LIGHTDIRECTION=Shader3D.propertyNameToID("u_DirectionLight.Direction");},'LIGHTDIRCOLOR',function(){return this.LIGHTDIRCOLOR=Shader3D.propertyNameToID("u_DirectionLight.Color");},'POINTLIGHTPOS',function(){return this.POINTLIGHTPOS=Shader3D.propertyNameToID("u_PointLight.Position");},'POINTLIGHTRANGE',function(){return this.POINTLIGHTRANGE=Shader3D.propertyNameToID("u_PointLight.Range");},'POINTLIGHTATTENUATION',function(){return this.POINTLIGHTATTENUATION=Shader3D.propertyNameToID("u_PointLight.Attenuation");},'POINTLIGHTCOLOR',function(){return this.POINTLIGHTCOLOR=Shader3D.propertyNameToID("u_PointLight.Color");},'SPOTLIGHTPOS',function(){return this.SPOTLIGHTPOS=Shader3D.propertyNameToID("u_SpotLight.Position");},'SPOTLIGHTDIRECTION',function(){return this.SPOTLIGHTDIRECTION=Shader3D.propertyNameToID("u_SpotLight.Direction");},'SPOTLIGHTSPOTANGLE',function(){return this.SPOTLIGHTSPOTANGLE=Shader3D.propertyNameToID("u_SpotLight.Spot");},'SPOTLIGHTRANGE',function(){return this.SPOTLIGHTRANGE=Shader3D.propertyNameToID("u_SpotLight.Range");},'SPOTLIGHTCOLOR',function(){return this.SPOTLIGHTCOLOR=Shader3D.propertyNameToID("u_SpotLight.Color");},'SHADOWDISTANCE',function(){return this.SHADOWDISTANCE=Shader3D.propertyNameToID("u_shadowPSSMDistance");},'SHADOWLIGHTVIEWPROJECT',function(){return this.SHADOWLIGHTVIEWPROJECT=Shader3D.propertyNameToID("u_lightShadowVP");},'SHADOWMAPPCFOFFSET',function(){return this.SHADOWMAPPCFOFFSET=Shader3D.propertyNameToID("u_shadowPCFoffset");},'SHADOWMAPTEXTURE1',function(){return this.SHADOWMAPTEXTURE1=Shader3D.propertyNameToID("u_shadowMap1");},'SHADOWMAPTEXTURE2',function(){return this.SHADOWMAPTEXTURE2=Shader3D.propertyNameToID("u_shadowMap2");},'SHADOWMAPTEXTURE3',function(){return this.SHADOWMAPTEXTURE3=Shader3D.propertyNameToID("u_shadowMap3");},'AMBIENTCOLOR',function(){return this.AMBIENTCOLOR=Shader3D.propertyNameToID("u_AmbientColor");},'REFLECTIONTEXTURE',function(){return this.REFLECTIONTEXTURE=Shader3D.propertyNameToID("u_ReflectTexture");},'REFLETIONINTENSITY',function(){return this.REFLETIONINTENSITY=Shader3D.propertyNameToID("u_ReflectIntensity");},'TIME',function(){return this.TIME=Shader3D.propertyNameToID("u_Time");},'ANGLEATTENUATIONTEXTURE',function(){return this.ANGLEATTENUATIONTEXTURE=Shader3D.propertyNameToID("u_AngleTexture");},'RANGEATTENUATIONTEXTURE',function(){return this.RANGEATTENUATIONTEXTURE=Shader3D.propertyNameToID("u_RangeTexture");},'POINTLIGHTMATRIX',function(){return this.POINTLIGHTMATRIX=Shader3D.propertyNameToID("u_PointLightMatrix");},'SPOTLIGHTMATRIX',function(){return this.SPOTLIGHTMATRIX=Shader3D.propertyNameToID("u_SpotLightMatrix");}
- ]);
- return Scene3D;
- })(Sprite)
- /**
- *<code>RenderableSprite3D</code> 类用于可渲染3D精灵的父类,抽象类不允许实例。
- */
- //class laya.d3.core.RenderableSprite3D extends laya.d3.core.Sprite3D
- var RenderableSprite3D=(function(_super){
- function RenderableSprite3D(name){
- this.pickColor=null;
- /**@private */
- this._render=null;
- RenderableSprite3D.__super.call(this,name);
- }
- __class(RenderableSprite3D,'laya.d3.core.RenderableSprite3D',_super);
- var __proto=RenderableSprite3D.prototype;
- /**
- *@inheritDoc
- */
- __proto._onInActive=function(){
- laya.display.Node.prototype._onInActive.call(this);
- var scene3D=this._scene;
- scene3D._removeRenderObject(this._render);
- (this._render.castShadow)&& (scene3D._removeShadowCastRenderObject(this._render));
- }
- /**
- *@inheritDoc
- */
- __proto._onActive=function(){
- laya.display.Node.prototype._onActive.call(this);
- var scene3D=this._scene;
- scene3D._addRenderObject(this._render);
- (this._render.castShadow)&& (scene3D._addShadowCastRenderObject(this._render));
- }
- /**
- *@inheritDoc
- */
- __proto._onActiveInScene=function(){
- laya.display.Node.prototype._onActiveInScene.call(this);
- if (Laya3D._editerEnvironment){
- var scene=this._scene;
- var pickColor=new Vector4();
- scene._allotPickColorByID(this.id,pickColor);
- scene._pickIdToSprite[this.id]=this;
- this._render._shaderValues.setVector(laya.d3.core.RenderableSprite3D.PICKCOLOR,pickColor);
- }
- }
- /**
- *@private
- */
- __proto._addToInitStaticBatchManager=function(){}
- /**
- *@inheritDoc
- */
- __proto._setBelongScene=function(scene){
- laya.display.Node.prototype._setBelongScene.call(this,scene);
- this._render._setBelongScene(scene);
- }
- /**
- *@inheritDoc
- */
- __proto._setUnBelongScene=function(){
- this._render._defineDatas.remove(laya.d3.core.RenderableSprite3D.SAHDERDEFINE_LIGHTMAP);
- laya.display.Node.prototype._setUnBelongScene.call(this);
- }
- /**
- *@inheritDoc
- */
- __proto._changeHierarchyAnimator=function(animator){
- if (this._hierarchyAnimator){
- var renderableSprites=this._hierarchyAnimator._renderableSprites;
- renderableSprites.splice(renderableSprites.indexOf(this),1);
- }
- if (animator)
- animator._renderableSprites.push(this);
- _super.prototype._changeHierarchyAnimator.call(this,animator);
- }
- /**
- *@inheritDoc
- */
- __proto.destroy=function(destroyChild){
- (destroyChild===void 0)&& (destroyChild=true);
- _super.prototype.destroy.call(this,destroyChild);
- this._render._destroy();
- this._render=null;
- }
- RenderableSprite3D.__init__=function(){
- RenderableSprite3D.SHADERDEFINE_RECEIVE_SHADOW=RenderableSprite3D.shaderDefines.registerDefine("RECEIVESHADOW");
- RenderableSprite3D.SHADERDEFINE_SCALEOFFSETLIGHTINGMAPUV=RenderableSprite3D.shaderDefines.registerDefine("SCALEOFFSETLIGHTINGMAPUV");
- RenderableSprite3D.SAHDERDEFINE_LIGHTMAP=RenderableSprite3D.shaderDefines.registerDefine("LIGHTMAP");
- }
- RenderableSprite3D.SHADERDEFINE_RECEIVE_SHADOW=0;
- RenderableSprite3D.SHADERDEFINE_SCALEOFFSETLIGHTINGMAPUV=0;
- RenderableSprite3D.SAHDERDEFINE_LIGHTMAP=0;
- __static(RenderableSprite3D,
- ['LIGHTMAPSCALEOFFSET',function(){return this.LIGHTMAPSCALEOFFSET=Shader3D.propertyNameToID("u_LightmapScaleOffset");},'LIGHTMAP',function(){return this.LIGHTMAP=Shader3D.propertyNameToID("u_LightMap");},'PICKCOLOR',function(){return this.PICKCOLOR=Shader3D.propertyNameToID("u_PickColor");},'shaderDefines',function(){return this.shaderDefines=new ShaderDefines();}
- ]);
- return RenderableSprite3D;
- })(Sprite3D)
- /**
- *<code>UnlitMaterial</code> 类用于实现不受光照影响的材质。
- */
- //class laya.d3.core.material.UnlitMaterial extends laya.d3.core.material.BaseMaterial
- var UnlitMaterial=(function(_super){
- function UnlitMaterial(){
- /**@private */
- this._albedoIntensity=1.0;
- /**@private */
- this._enableVertexColor=false;
- this._albedoColor=new Vector4(1.0,1.0,1.0,1.0);
- UnlitMaterial.__super.call(this);
- this.setShaderName("Unlit");
- this._shaderValues.setVector(UnlitMaterial.ALBEDOCOLOR,new Vector4(1.0,1.0,1.0,1.0));
- this.renderMode=0;
- }
- __class(UnlitMaterial,'laya.d3.core.material.UnlitMaterial',_super);
- var __proto=UnlitMaterial.prototype;
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_ColorB',function(){
- return this._albedoColor.z;
- },function(value){
- this._albedoColor.z=value;
- this.albedoColor=this._albedoColor;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_ColorR',function(){
- return this._albedoColor.x;
- },function(value){
- this._albedoColor.x=value;
- this.albedoColor=this._albedoColor;
- });
- /**
- *设置反照率颜色alpha分量。
- *@param value 反照率颜色alpha分量。
- */
- /**
- *获取反照率颜色Z分量。
- *@return 反照率颜色Z分量。
- */
- __getset(0,__proto,'albedoColorA',function(){
- return this._ColorA;
- },function(value){
- this._ColorA=value;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_MainTex_STX',function(){
- return this._shaderValues.getVector(UnlitMaterial.TILINGOFFSET).x;
- },function(x){
- var tilOff=this._shaderValues.getVector(UnlitMaterial.TILINGOFFSET);
- tilOff.x=x;
- this.tilingOffset=tilOff;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_ColorG',function(){
- return this._albedoColor.y;
- },function(value){
- this._albedoColor.y=value;
- this.albedoColor=this._albedoColor;
- });
- /**
- *@private
- */
- /**@private */
- __getset(0,__proto,'_ColorA',function(){
- return this._albedoColor.w;
- },function(value){
- this._albedoColor.w=value;
- this.albedoColor=this._albedoColor;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_AlbedoIntensity',function(){
- return this._albedoIntensity;
- },function(value){
- if (this._albedoIntensity!==value){
- var finalAlbedo=this._shaderValues.getVector(UnlitMaterial.ALBEDOCOLOR);
- Vector4.scale(this._albedoColor,value,finalAlbedo);
- this._albedoIntensity=value;
- this._shaderValues.setVector(UnlitMaterial.ALBEDOCOLOR,finalAlbedo);
- }
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_MainTex_STZ',function(){
- return this._shaderValues.getVector(UnlitMaterial.TILINGOFFSET).z;
- },function(z){
- var tilOff=this._shaderValues.getVector(UnlitMaterial.TILINGOFFSET);
- tilOff.z=z;
- this.tilingOffset=tilOff;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_MainTex_STY',function(){
- return this._shaderValues.getVector(UnlitMaterial.TILINGOFFSET).y;
- },function(y){
- var tilOff=this._shaderValues.getVector(UnlitMaterial.TILINGOFFSET);
- tilOff.y=y;
- this.tilingOffset=tilOff;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_Cutoff',function(){
- return this.alphaTestValue;
- },function(value){
- this.alphaTestValue=value;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_MainTex_STW',function(){
- return this._shaderValues.getVector(UnlitMaterial.TILINGOFFSET).w;
- },function(w){
- var tilOff=this._shaderValues.getVector(UnlitMaterial.TILINGOFFSET);
- tilOff.w=w;
- this.tilingOffset=tilOff;
- });
- /**
- *设置反照率颜色R分量。
- *@param value 反照率颜色R分量。
- */
- /**
- *获取反照率颜色R分量。
- *@return 反照率颜色R分量。
- */
- __getset(0,__proto,'albedoColorR',function(){
- return this._ColorR;
- },function(value){
- this._ColorR=value;
- });
- /**
- *设置反照率颜色G分量。
- *@param value 反照率颜色G分量。
- */
- /**
- *获取反照率颜色G分量。
- *@return 反照率颜色G分量。
- */
- __getset(0,__proto,'albedoColorG',function(){
- return this._ColorG;
- },function(value){
- this._ColorG=value;
- });
- /**
- *设置反照率颜色B分量。
- *@param value 反照率颜色B分量。
- */
- /**
- *获取反照率颜色B分量。
- *@return 反照率颜色B分量。
- */
- __getset(0,__proto,'albedoColorB',function(){
- return this._ColorB;
- },function(value){
- this._ColorB=value;
- });
- /**
- *获取纹理平铺和偏移X分量。
- *@param x 纹理平铺和偏移X分量。
- */
- /**
- *获取纹理平铺和偏移X分量。
- *@return 纹理平铺和偏移X分量。
- */
- __getset(0,__proto,'tilingOffsetX',function(){
- return this._MainTex_STX;
- },function(x){
- this._MainTex_STX=x;
- });
- /**
- *设置反照率颜色。
- *@param value 反照率颜色。
- */
- /**
- *获取反照率颜色。
- *@return 反照率颜色。
- */
- __getset(0,__proto,'albedoColor',function(){
- return this._albedoColor;
- },function(value){
- var finalAlbedo=this._shaderValues.getVector(UnlitMaterial.ALBEDOCOLOR);
- Vector4.scale(value,this._albedoIntensity,finalAlbedo);
- this._albedoColor=value;
- this._shaderValues.setVector(UnlitMaterial.ALBEDOCOLOR,finalAlbedo);
- });
- /**
- *设置反照率强度。
- *@param value 反照率强度。
- */
- /**
- *获取反照率强度。
- *@return 反照率强度。
- */
- __getset(0,__proto,'albedoIntensity',function(){
- return this._albedoIntensity;
- },function(value){
- this._AlbedoIntensity=value;
- });
- /**
- *设置是否支持顶点色。
- *@param value 是否支持顶点色。
- */
- /**
- *获取是否支持顶点色。
- *@return 是否支持顶点色。
- */
- __getset(0,__proto,'enableVertexColor',function(){
- return this._enableVertexColor;
- },function(value){
- this._enableVertexColor=value;
- if (value)
- this._defineDatas.add(laya.d3.core.material.UnlitMaterial.SHADERDEFINE_ENABLEVERTEXCOLOR);
- else
- this._defineDatas.remove(laya.d3.core.material.UnlitMaterial.SHADERDEFINE_ENABLEVERTEXCOLOR);
- });
- /**
- *设置反照率贴图。
- *@param value 反照率贴图。
- */
- /**
- *获取反照率贴图。
- *@return 反照率贴图。
- */
- __getset(0,__proto,'albedoTexture',function(){
- return this._shaderValues.getTexture(UnlitMaterial.ALBEDOTEXTURE);
- },function(value){
- if (value)
- this._defineDatas.add(laya.d3.core.material.UnlitMaterial.SHADERDEFINE_ALBEDOTEXTURE);
- else
- this._defineDatas.remove(laya.d3.core.material.UnlitMaterial.SHADERDEFINE_ALBEDOTEXTURE);
- this._shaderValues.setTexture(UnlitMaterial.ALBEDOTEXTURE,value);
- });
- /**
- *获取纹理平铺和偏移Y分量。
- *@param y 纹理平铺和偏移Y分量。
- */
- /**
- *获取纹理平铺和偏移Y分量。
- *@return 纹理平铺和偏移Y分量。
- */
- __getset(0,__proto,'tilingOffsetY',function(){
- return this._MainTex_STY;
- },function(y){
- this._MainTex_STY=y;
- });
- /**
- *获取纹理平铺和偏移Z分量。
- *@param z 纹理平铺和偏移Z分量。
- */
- /**
- *获取纹理平铺和偏移Z分量。
- *@return 纹理平铺和偏移Z分量。
- */
- __getset(0,__proto,'tilingOffsetZ',function(){
- return this._MainTex_STZ;
- },function(z){
- this._MainTex_STZ=z;
- });
- /**
- *设置混合源。
- *@param value 混合源
- */
- /**
- *获取混合源。
- *@return 混合源。
- */
- __getset(0,__proto,'blendSrc',function(){
- return this._shaderValues.getInt(UnlitMaterial.BLEND_SRC);
- },function(value){
- this._shaderValues.setInt(UnlitMaterial.BLEND_SRC,value);
- });
- /**
- *获取纹理平铺和偏移W分量。
- *@param w 纹理平铺和偏移W分量。
- */
- /**
- *获取纹理平铺和偏移W分量。
- *@return 纹理平铺和偏移W分量。
- */
- __getset(0,__proto,'tilingOffsetW',function(){
- return this._MainTex_STW;
- },function(w){
- this._MainTex_STW=w;
- });
- /**
- *获取纹理平铺和偏移。
- *@param value 纹理平铺和偏移。
- */
- /**
- *获取纹理平铺和偏移。
- *@return 纹理平铺和偏移。
- */
- __getset(0,__proto,'tilingOffset',function(){
- return this._shaderValues.getVector(UnlitMaterial.TILINGOFFSET);
- },function(value){
- if (value){
- if (value.x !=1 || value.y !=1 || value.z !=0 || value.w !=0)
- this._defineDatas.add(laya.d3.core.material.UnlitMaterial.SHADERDEFINE_TILINGOFFSET);
- else
- this._defineDatas.remove(laya.d3.core.material.UnlitMaterial.SHADERDEFINE_TILINGOFFSET);
- }else {
- this._defineDatas.remove(laya.d3.core.material.UnlitMaterial.SHADERDEFINE_TILINGOFFSET);
- }
- this._shaderValues.setVector(UnlitMaterial.TILINGOFFSET,value);
- });
- /**
- *设置渲染模式。
- *@return 渲染模式。
- */
- __getset(0,__proto,'renderMode',null,function(value){
- switch (value){
- case 0:
- this.alphaTest=false;
- this.renderQueue=/*laya.d3.core.material.BaseMaterial.RENDERQUEUE_OPAQUE*/2000;
- this.depthWrite=true;
- this.cull=/*laya.d3.core.material.RenderState.CULL_BACK*/2;
- this.blend=/*laya.d3.core.material.RenderState.BLEND_DISABLE*/0;
- this.depthTest=/*laya.d3.core.material.RenderState.DEPTHTEST_LESS*/0x0201;
- break ;
- case 1:
- this.renderQueue=/*laya.d3.core.material.BaseMaterial.RENDERQUEUE_ALPHATEST*/2450;
- this.alphaTest=true;
- this.depthWrite=true;
- this.cull=/*laya.d3.core.material.RenderState.CULL_BACK*/2;
- this.blend=/*laya.d3.core.material.RenderState.BLEND_DISABLE*/0;
- this.depthTest=/*laya.d3.core.material.RenderState.DEPTHTEST_LESS*/0x0201;
- break ;
- case 2:
- this.renderQueue=/*laya.d3.core.material.BaseMaterial.RENDERQUEUE_TRANSPARENT*/3000;
- this.alphaTest=false;
- this.depthWrite=false;
- this.cull=/*laya.d3.core.material.RenderState.CULL_BACK*/2;
- this.blend=/*laya.d3.core.material.RenderState.BLEND_ENABLE_ALL*/1;
- this.blendSrc=/*laya.d3.core.material.RenderState.BLENDPARAM_SRC_ALPHA*/0x0302;
- this.blendDst=/*laya.d3.core.material.RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA*/0x0303;
- this.depthTest=/*laya.d3.core.material.RenderState.DEPTHTEST_LESS*/0x0201;
- break ;
- default :
- throw new Error("UnlitMaterial : renderMode value error.");
- }
- });
- /**
- *设置是否写入深度。
- *@param value 是否写入深度。
- */
- /**
- *获取是否写入深度。
- *@return 是否写入深度。
- */
- __getset(0,__proto,'depthWrite',function(){
- return this._shaderValues.getBool(UnlitMaterial.DEPTH_WRITE);
- },function(value){
- this._shaderValues.setBool(UnlitMaterial.DEPTH_WRITE,value);
- });
- /**
- *设置剔除方式。
- *@param value 剔除方式。
- */
- /**
- *获取剔除方式。
- *@return 剔除方式。
- */
- __getset(0,__proto,'cull',function(){
- return this._shaderValues.getInt(UnlitMaterial.CULL);
- },function(value){
- this._shaderValues.setInt(UnlitMaterial.CULL,value);
- });
- /**
- *设置混合方式。
- *@param value 混合方式。
- */
- /**
- *获取混合方式。
- *@return 混合方式。
- */
- __getset(0,__proto,'blend',function(){
- return this._shaderValues.getInt(UnlitMaterial.BLEND);
- },function(value){
- this._shaderValues.setInt(UnlitMaterial.BLEND,value);
- });
- /**
- *设置混合目标。
- *@param value 混合目标
- */
- /**
- *获取混合目标。
- *@return 混合目标。
- */
- __getset(0,__proto,'blendDst',function(){
- return this._shaderValues.getInt(UnlitMaterial.BLEND_DST);
- },function(value){
- this._shaderValues.setInt(UnlitMaterial.BLEND_DST,value);
- });
- /**
- *设置深度测试方式。
- *@param value 深度测试方式
- */
- /**
- *获取深度测试方式。
- *@return 深度测试方式。
- */
- __getset(0,__proto,'depthTest',function(){
- return this._shaderValues.getInt(UnlitMaterial.DEPTH_TEST);
- },function(value){
- this._shaderValues.setInt(UnlitMaterial.DEPTH_TEST,value);
- });
- UnlitMaterial.__init__=function(){
- UnlitMaterial.SHADERDEFINE_ALBEDOTEXTURE=UnlitMaterial.shaderDefines.registerDefine("ALBEDOTEXTURE");
- UnlitMaterial.SHADERDEFINE_TILINGOFFSET=UnlitMaterial.shaderDefines.registerDefine("TILINGOFFSET");
- UnlitMaterial.SHADERDEFINE_ENABLEVERTEXCOLOR=UnlitMaterial.shaderDefines.registerDefine("ENABLEVERTEXCOLOR");
- }
- UnlitMaterial.RENDERMODE_OPAQUE=0;
- UnlitMaterial.RENDERMODE_CUTOUT=1;
- UnlitMaterial.RENDERMODE_TRANSPARENT=2;
- UnlitMaterial.RENDERMODE_ADDTIVE=3;
- UnlitMaterial.SHADERDEFINE_ALBEDOTEXTURE=0;
- UnlitMaterial.SHADERDEFINE_TILINGOFFSET=0;
- UnlitMaterial.SHADERDEFINE_ENABLEVERTEXCOLOR=0;
- __static(UnlitMaterial,
- ['ALBEDOTEXTURE',function(){return this.ALBEDOTEXTURE=Shader3D.propertyNameToID("u_AlbedoTexture");},'ALBEDOCOLOR',function(){return this.ALBEDOCOLOR=Shader3D.propertyNameToID("u_AlbedoColor");},'TILINGOFFSET',function(){return this.TILINGOFFSET=Shader3D.propertyNameToID("u_TilingOffset");},'CULL',function(){return this.CULL=Shader3D.propertyNameToID("s_Cull");},'BLEND',function(){return this.BLEND=Shader3D.propertyNameToID("s_Blend");},'BLEND_SRC',function(){return this.BLEND_SRC=Shader3D.propertyNameToID("s_BlendSrc");},'BLEND_DST',function(){return this.BLEND_DST=Shader3D.propertyNameToID("s_BlendDst");},'DEPTH_TEST',function(){return this.DEPTH_TEST=Shader3D.propertyNameToID("s_DepthTest");},'DEPTH_WRITE',function(){return this.DEPTH_WRITE=Shader3D.propertyNameToID("s_DepthWrite");},'defaultMaterial',function(){return this.defaultMaterial=new UnlitMaterial();},'shaderDefines',function(){return this.shaderDefines=new ShaderDefines(BaseMaterial.shaderDefines);}
- ]);
- return UnlitMaterial;
- })(BaseMaterial)
- /**
- *<code>LightSprite</code> 类用于创建灯光的父类。
- */
- //class laya.d3.core.light.LightSprite extends laya.d3.core.Sprite3D
- var LightSprite=(function(_super){
- function LightSprite(){
- /**@private */
- this._intensityColor=null;
- /**@private */
- this._intensity=NaN;
- /**@private */
- this._shadow=false;
- /**@private */
- this._shadowFarPlane=0;
- /**@private */
- this._shadowMapSize=0;
- /**@private */
- this._shadowMapCount=0;
- /**@private */
- this._shadowMapPCFType=0;
- /**@private */
- this._parallelSplitShadowMap=null;
- /**@private */
- this._lightmapBakedType=0;
- /**灯光颜色。 */
- this.color=null;
- LightSprite.__super.call(this);
- this._intensity=1.0;
- this._intensityColor=new Vector3();
- this.color=new Vector3(1.0,1.0,1.0);
- this._shadow=false;
- this._shadowFarPlane=8;
- this._shadowMapSize=512;
- this._shadowMapCount=1;
- this._shadowMapPCFType=0;
- this._lightmapBakedType=LightSprite.LIGHTMAPBAKEDTYPE_REALTIME;
- }
- __class(LightSprite,'laya.d3.core.light.LightSprite',_super);
- var __proto=LightSprite.prototype;
- /**
- *@inheritDoc
- */
- __proto._parse=function(data,spriteMap){
- _super.prototype._parse.call(this,data,spriteMap);
- var colorData=data.color;
- this.color.fromArray(colorData);
- this.intensity=data.intensity;
- this.lightmapBakedType=data.lightmapBakedType;
- }
- /**
- *@inheritDoc
- */
- __proto._onActive=function(){
- laya.display.Node.prototype._onActive.call(this);
- (this.lightmapBakedType!==LightSprite.LIGHTMAPBAKEDTYPE_BAKED)&& ((this._scene)._addLight(this));
- }
- /**
- *@inheritDoc
- */
- __proto._onInActive=function(){
- laya.display.Node.prototype._onInActive.call(this);
- (this.lightmapBakedType!==LightSprite.LIGHTMAPBAKEDTYPE_BAKED)&& ((this._scene)._removeLight(this));
- }
- /**
- *更新灯光相关渲染状态参数。
- *@param state 渲染状态参数。
- */
- __proto._prepareToScene=function(){
- return false;
- }
- /**
- *设置灯光烘培类型。
- */
- /**
- *获取灯光烘培类型。
- */
- __getset(0,__proto,'lightmapBakedType',function(){
- return this._lightmapBakedType;
- },function(value){
- if (this._lightmapBakedType!==value){
- this._lightmapBakedType=value;
- if (this.activeInHierarchy){
- if (value!==LightSprite.LIGHTMAPBAKEDTYPE_BAKED)
- (this._scene)._addLight(this);
- else
- (this._scene)._removeLight(this);
- }
- }
- });
- /**
- *设置阴影PCF类型。
- *@param value PCF类型。
- */
- /**
- *获取阴影PCF类型。
- *@return PCF类型。
- */
- __getset(0,__proto,'shadowPCFType',function(){
- return this._shadowMapPCFType;
- },function(value){
- this._shadowMapPCFType=value;
- (this._parallelSplitShadowMap)&& (this._parallelSplitShadowMap.setPCFType(value));
- });
- /**
- *设置灯光强度。
- *@param value 灯光强度
- */
- /**
- *获取灯光强度。
- *@return 灯光强度
- */
- __getset(0,__proto,'intensity',function(){
- return this._intensity;
- },function(value){
- this._intensity=value;
- });
- /**
- *设置是否产生阴影。
- *@param value 是否产生阴影。
- */
- /**
- *获取是否产生阴影。
- *@return 是否产生阴影。
- */
- __getset(0,__proto,'shadow',function(){
- return this._shadow;
- },function(value){
- throw new Error("LightSprite: must override it.");
- });
- /**
- *设置阴影最远范围。
- *@param value 阴影最远范围。
- */
- /**
- *获取阴影最远范围。
- *@return 阴影最远范围。
- */
- __getset(0,__proto,'shadowDistance',function(){
- return this._shadowFarPlane;
- },function(value){
- this._shadowFarPlane=value;
- (this._parallelSplitShadowMap)&& (this._parallelSplitShadowMap.setFarDistance(value));
- });
- /**
- *设置阴影分段数。
- *@param value 阴影分段数。
- */
- /**
- *获取阴影分段数。
- *@return 阴影分段数。
- */
- __getset(0,__proto,'shadowPSSMCount',function(){
- return this._shadowMapCount;
- },function(value){
- this._shadowMapCount=value;
- (this._parallelSplitShadowMap)&& (this._parallelSplitShadowMap.shadowMapCount=value);
- });
- /**
- *设置阴影贴图尺寸。
- *@param value 阴影贴图尺寸。
- */
- /**
- *获取阴影贴图尺寸。
- *@return 阴影贴图尺寸。
- */
- __getset(0,__proto,'shadowResolution',function(){
- return this._shadowMapSize;
- },function(value){
- this._shadowMapSize=value;
- (this._parallelSplitShadowMap)&& (this._parallelSplitShadowMap.setShadowMapTextureSize(value));
- });
- /**
- *设置灯光的漫反射颜色。
- *@param value 灯光的漫反射颜色。
- */
- /**
- *获取灯光的漫反射颜色。
- *@return 灯光的漫反射颜色。
- */
- __getset(0,__proto,'diffuseColor',function(){
- console.log("LightSprite: discard property,please use color property instead.");
- return this.color;
- },function(value){
- console.log("LightSprite: discard property,please use color property instead.");
- this.color=value;
- });
- LightSprite.LIGHTMAPBAKEDTYPE_REALTIME=0;
- LightSprite.LIGHTMAPBAKEDTYPE_MIXED=1;
- LightSprite.LIGHTMAPBAKEDTYPE_BAKED=2;
- return LightSprite;
- })(Sprite3D)
- /**
- *<code>Terrain</code> 类用于创建地块。
- */
- //class laya.d3.terrain.Terrain extends laya.d3.core.Sprite3D
- var Terrain=(function(_super){
- function Terrain(terrainRes){
- //地形资源
- this._terrainRes=null;
- this._lightmapScaleOffset=null;
- Terrain.__super.call(this);
- this._lightmapScaleOffset=new Vector4(1,1,0,0);
- if (terrainRes){
- this._terrainRes=terrainRes;
- this.buildTerrain(terrainRes);
- }
- }
- __class(Terrain,'laya.d3.terrain.Terrain',_super);
- var __proto=Terrain.prototype;
- /**
- *@inheritDoc
- */
- __proto._parse=function(data,spriteMap){
- _super.prototype._parse.call(this,data,spriteMap);
- this.terrainRes=Loader.getRes(data.dataPath);
- var lightmapIndex=data.lightmapIndex;
- if (lightmapIndex !=null)
- this.setLightmapIndex(lightmapIndex);
- var lightmapScaleOffsetArray=data.lightmapScaleOffset;
- if (lightmapScaleOffsetArray)
- this.setLightmapScaleOffset(new Vector4(lightmapScaleOffsetArray[0],lightmapScaleOffsetArray[1],lightmapScaleOffsetArray[2],lightmapScaleOffsetArray[3]));
- }
- __proto.setLightmapIndex=function(value){
- for (var i=0;i < this._children.length;i++){
- var terrainChunk=this._children[i];
- terrainChunk.terrainRender.lightmapIndex=value;
- }
- }
- __proto.setLightmapScaleOffset=function(value){
- if (!value)return;
- value.cloneTo(this._lightmapScaleOffset);
- for (var i=0;i < this._children.length;i++){
- var terrainChunk=this._children[i];
- terrainChunk.terrainRender.lightmapScaleOffset=this._lightmapScaleOffset;
- }
- }
- __proto.disableLight=function(){
- for (var i=0,n=this._children.length;i < n;i++){
- var terrainChunk=this._children[i];
- for (var j=0,m=terrainChunk._render.sharedMaterials.length;j < m;j++){
- var terrainMaterial=terrainChunk._render.sharedMaterials [j];
- terrainMaterial.disableLight();
- }
- }
- }
- //建筑地形
- __proto.buildTerrain=function(terrainRes){
- var chunkNumX=terrainRes._chunkNumX;
- var chunkNumZ=terrainRes._chunkNumZ;
- var heightData=terrainRes._heightData;
- var n=0;
- for (var i=0;i < chunkNumZ;i++){
- for (var j=0;j < chunkNumX;j++){
- var terrainChunk=new TerrainChunk(j,i,terrainRes._gridSize,heightData._terrainHeightData,heightData._width,heightData._height,terrainRes._cameraCoordinateInverse);
- var chunkInfo=terrainRes._chunkInfos[n++];
- for (var k=0;k < chunkInfo.alphaMap.length;k++){
- var nNum=chunkInfo.detailID[k].length;
- var sDetialTextureUrl1=(nNum > 0)? terrainRes._detailTextureInfos[chunkInfo.detailID[k][0]].diffuseTexture :null;
- var sDetialTextureUrl2=(nNum > 1)? terrainRes._detailTextureInfos[chunkInfo.detailID[k][1]].diffuseTexture :null;
- var sDetialTextureUrl3=(nNum > 2)? terrainRes._detailTextureInfos[chunkInfo.detailID[k][2]].diffuseTexture :null;
- var sDetialTextureUrl4=(nNum > 3)? terrainRes._detailTextureInfos[chunkInfo.detailID[k][3]].diffuseTexture :null;
- var detialScale1=(nNum > 0)? terrainRes._detailTextureInfos[chunkInfo.detailID[k][0]].scale :null;
- var detialScale2=(nNum > 1)? terrainRes._detailTextureInfos[chunkInfo.detailID[k][1]].scale :null;
- var detialScale3=(nNum > 2)? terrainRes._detailTextureInfos[chunkInfo.detailID[k][2]].scale :null;
- var detialScale4=(nNum > 3)? terrainRes._detailTextureInfos[chunkInfo.detailID[k][3]].scale :null;
- terrainChunk.buildRenderElementAndMaterial(nNum,chunkInfo.normalMap,chunkInfo.alphaMap[k],sDetialTextureUrl1,sDetialTextureUrl2,sDetialTextureUrl3,sDetialTextureUrl4,terrainRes._materialInfo.ambientColor,terrainRes._materialInfo.diffuseColor,terrainRes._materialInfo.specularColor,detialScale1 ? detialScale1.x :1,detialScale1 ? detialScale1.y :1,detialScale2 ? detialScale2.x :1,detialScale2 ? detialScale2.y :1,detialScale3 ? detialScale3.x :1,detialScale3 ? detialScale3.y :1,detialScale4 ? detialScale4.x :1,detialScale4 ? detialScale4.y :1);
- }
- terrainChunk.terrainRender.receiveShadow=true;
- terrainChunk.terrainRender.lightmapScaleOffset=this._lightmapScaleOffset;
- this.addChild(terrainChunk);
- }
- }
- }
- /**
- *获取地形X轴长度。
- *@return 地形X轴长度。
- */
- __proto.width=function(){
- return this._terrainRes._chunkNumX *TerrainLeaf.CHUNK_GRID_NUM *this._terrainRes._gridSize;
- }
- /**
- *获取地形Z轴长度。
- *@return 地形Z轴长度。
- */
- __proto.depth=function(){
- return this._terrainRes._chunkNumZ *TerrainLeaf.CHUNK_GRID_NUM *this._terrainRes._gridSize;
- }
- /**
- *获取地形高度。
- *@param x X轴坐标。
- *@param z Z轴坐标。
- */
- __proto.getHeightXZ=function(x,z){
- if (!this._terrainRes)
- return NaN;
- x-=this.transform.position.x;
- z-=this.transform.position.z;
- if (!Terrain.__VECTOR3__){
- Terrain.__VECTOR3__=new Vector3();
- }
- Terrain.__VECTOR3__.x=x;
- Terrain.__VECTOR3__.y=0;
- Terrain.__VECTOR3__.z=z;
- Vector3.transformV3ToV3(Terrain.__VECTOR3__,TerrainLeaf.__ADAPT_MATRIX_INV__,Terrain.__VECTOR3__);
- x=Terrain.__VECTOR3__.x;
- z=Terrain.__VECTOR3__.z;
- if (x < 0 || x > this.width()|| z < 0 || z > this.depth())
- return NaN;
- var gridSize=this._terrainRes._gridSize;
- var nIndexX=parseInt(""+x / gridSize);
- var nIndexZ=parseInt(""+z / gridSize);
- var offsetX=x-nIndexX *gridSize;
- var offsetZ=z-nIndexZ *gridSize;
- var h1=NaN;
- var h2=NaN;
- var h3=NaN;
- var u=NaN;
- var v=NaN;
- var heightData=this._terrainRes._heightData;
- if (offsetX+offsetZ > gridSize){
- h1=heightData._terrainHeightData[(nIndexZ+1-1)*heightData._width+nIndexX+1];
- h2=heightData._terrainHeightData[(nIndexZ+1-1)*heightData._width+nIndexX];
- h3=heightData._terrainHeightData[(nIndexZ-1)*heightData._width+nIndexX+1];
- u=(gridSize-offsetX)/ gridSize;
- v=(gridSize-offsetZ)/ gridSize;
- return h1+(h2-h1)*u+(h3-h1)*v;
- }else {
- h1=heightData._terrainHeightData[Math.max(0.0,nIndexZ-1)*heightData._width+nIndexX];
- h2=heightData._terrainHeightData[Math.min(heightData._width *heightData._height-1,(nIndexZ+1-1)*heightData._width+nIndexX)];
- h3=heightData._terrainHeightData[Math.min(heightData._width *heightData._height-1,Math.max(0.0,nIndexZ-1)*heightData._width+nIndexX+1)];
- u=offsetX / gridSize;
- v=offsetZ / gridSize;
- return h1+(h2-h1)*v+(h3-h1)*u;
- }
- }
- __getset(0,__proto,'terrainRes',null,function(value){
- if (value){
- this._terrainRes=value;
- this.buildTerrain(value);
- }
- });
- Terrain.load=function(url){
- Laya.loader.create(url,null,null,/*Laya3D.TERRAINRES*/"TERRAIN",null,null,1,false);
- }
- Terrain.RENDER_LINE_MODEL=false;
- Terrain.LOD_TOLERANCE_VALUE=4;
- Terrain.LOD_DISTANCE_FACTOR=2.0;
- Terrain.__VECTOR3__=null;
- return Terrain;
- })(Sprite3D)
- /**
- *<code>TrailMaterial</code> 类用于实现拖尾材质。
- */
- //class laya.d3.core.trail.TrailMaterial extends laya.d3.core.material.BaseMaterial
- var TrailMaterial=(function(_super){
- function TrailMaterial(){
- /**@private */
- this._color=null;
- TrailMaterial.__super.call(this);
- this.setShaderName("Trail");
- this._color=new Vector4(1.0,1.0,1.0,1.0);
- this._shaderValues.setVector(TrailMaterial.TINTCOLOR,new Vector4(1.0,1.0,1.0,1.0));
- this.renderMode=0;
- }
- __class(TrailMaterial,'laya.d3.core.trail.TrailMaterial',_super);
- var __proto=TrailMaterial.prototype;
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_TintColorB',function(){
- return this._color.z;
- },function(value){
- this._color.z=value;
- this.color=this._color;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_MainTex_STZ',function(){
- return this._shaderValues.getVector(TrailMaterial.TILINGOFFSET).z;
- },function(z){
- var tilOff=this._shaderValues.getVector(TrailMaterial.TILINGOFFSET);
- tilOff.z=z;
- this.tilingOffset=tilOff;
- });
- /**
- *设置贴图。
- *@param value 贴图。
- */
- /**
- *获取贴图。
- *@return 贴图。
- */
- __getset(0,__proto,'texture',function(){
- return this._shaderValues.getTexture(TrailMaterial.MAINTEXTURE);
- },function(value){
- if (value)
- this._defineDatas.add(laya.d3.core.trail.TrailMaterial.SHADERDEFINE_MAINTEXTURE);
- else
- this._defineDatas.remove(laya.d3.core.trail.TrailMaterial.SHADERDEFINE_MAINTEXTURE);
- this._shaderValues.setTexture(TrailMaterial.MAINTEXTURE,value);
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_TintColorR',function(){
- return this._color.x;
- },function(value){
- this._color.x=value;
- this.color=this._color;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_MainTex_STW',function(){
- return this._shaderValues.getVector(TrailMaterial.TILINGOFFSET).w;
- },function(w){
- var tilOff=this._shaderValues.getVector(TrailMaterial.TILINGOFFSET);
- tilOff.w=w;
- this.tilingOffset=tilOff;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_TintColorG',function(){
- return this._color.y;
- },function(value){
- this._color.y=value;
- this.color=this._color;
- });
- /**
- *@private
- */
- /**@private */
- __getset(0,__proto,'_TintColorA',function(){
- return this._color.w;
- },function(value){
- this._color.w=value;
- this.color=this._color;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_MainTex_STY',function(){
- return this._shaderValues.getVector(TrailMaterial.TILINGOFFSET).y;
- },function(y){
- var tilOff=this._shaderValues.getVector(TrailMaterial.TILINGOFFSET);
- tilOff.y=y;
- this.tilingOffset=tilOff;
- });
- /**
- *设置渲染模式。
- *@return 渲染模式。
- */
- __getset(0,__proto,'renderMode',null,function(value){
- switch (value){
- case 1:
- this.renderQueue=/*laya.d3.core.material.BaseMaterial.RENDERQUEUE_TRANSPARENT*/3000;
- this.alphaTest=false;
- this.depthWrite=false;
- this.cull=/*laya.d3.core.material.RenderState.CULL_NONE*/0;
- this.blend=/*laya.d3.core.material.RenderState.BLEND_ENABLE_ALL*/1;
- this.blendSrc=/*laya.d3.core.material.RenderState.BLENDPARAM_SRC_ALPHA*/0x0302;
- this.blendDst=/*laya.d3.core.material.RenderState.BLENDPARAM_ONE*/1;
- this.depthTest=/*laya.d3.core.material.RenderState.DEPTHTEST_LESS*/0x0201;
- this._defineDatas.add(TrailMaterial.SHADERDEFINE_ADDTIVEFOG);
- break ;
- case 0:
- this.renderQueue=/*laya.d3.core.material.BaseMaterial.RENDERQUEUE_TRANSPARENT*/3000;
- this.alphaTest=false;
- this.depthWrite=false;
- this.cull=/*laya.d3.core.material.RenderState.CULL_NONE*/0;
- this.blend=/*laya.d3.core.material.RenderState.BLEND_ENABLE_ALL*/1;
- this.blendSrc=/*laya.d3.core.material.RenderState.BLENDPARAM_SRC_ALPHA*/0x0302;
- this.blendDst=/*laya.d3.core.material.RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA*/0x0303;
- this.depthTest=/*laya.d3.core.material.RenderState.DEPTHTEST_LESS*/0x0201;
- this._defineDatas.remove(TrailMaterial.SHADERDEFINE_ADDTIVEFOG);
- break ;
- default :
- throw new Error("TrailMaterial : renderMode value error.");
- }
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_MainTex_STX',function(){
- return this._shaderValues.getVector(TrailMaterial.TILINGOFFSET).x;
- },function(x){
- var tilOff=this._shaderValues.getVector(TrailMaterial.TILINGOFFSET);
- tilOff.x=x;
- this.tilingOffset=tilOff;
- });
- /**
- *设置颜色R分量。
- *@param value 颜色R分量。
- */
- /**
- *获取颜色R分量。
- *@return 颜色R分量。
- */
- __getset(0,__proto,'colorR',function(){
- return this._TintColorR;
- },function(value){
- this._TintColorR=value;
- });
- /**
- *设置颜色G分量。
- *@param value 颜色G分量。
- */
- /**
- *获取颜色G分量。
- *@return 颜色G分量。
- */
- __getset(0,__proto,'colorG',function(){
- return this._TintColorG;
- },function(value){
- this._TintColorG=value;
- });
- /**
- *设置颜色B分量。
- *@param value 颜色B分量。
- */
- /**
- *获取颜色B分量。
- *@return 颜色B分量。
- */
- __getset(0,__proto,'colorB',function(){
- return this._TintColorB;
- },function(value){
- this._TintColorB=value;
- });
- /**
- *设置颜色alpha分量。
- *@param value 颜色alpha分量。
- */
- /**
- *获取颜色Z分量。
- *@return 颜色Z分量。
- */
- __getset(0,__proto,'colorA',function(){
- return this._TintColorA;
- },function(value){
- this._TintColorA=value;
- });
- /**
- *设置混合方式。
- *@param value 混合方式。
- */
- /**
- *获取混合方式。
- *@return 混合方式。
- */
- __getset(0,__proto,'blend',function(){
- return this._shaderValues.getInt(TrailMaterial.BLEND);
- },function(value){
- this._shaderValues.setInt(TrailMaterial.BLEND,value);
- });
- /**
- *设置颜色。
- *@param value 颜色。
- */
- /**
- *获取颜色。
- *@return 颜色。
- */
- __getset(0,__proto,'color',function(){
- return this._shaderValues.getVector(TrailMaterial.TINTCOLOR);
- },function(value){
- this._shaderValues.setVector(TrailMaterial.TINTCOLOR,value);
- });
- /**
- *获取纹理平铺和偏移X分量。
- *@param x 纹理平铺和偏移X分量。
- */
- /**
- *获取纹理平铺和偏移X分量。
- *@return 纹理平铺和偏移X分量。
- */
- __getset(0,__proto,'tilingOffsetX',function(){
- return this._MainTex_STX;
- },function(x){
- this._MainTex_STX=x;
- });
- /**
- *获取纹理平铺和偏移Y分量。
- *@param y 纹理平铺和偏移Y分量。
- */
- /**
- *获取纹理平铺和偏移Y分量。
- *@return 纹理平铺和偏移Y分量。
- */
- __getset(0,__proto,'tilingOffsetY',function(){
- return this._MainTex_STY;
- },function(y){
- this._MainTex_STY=y;
- });
- /**
- *获取纹理平铺和偏移Z分量。
- *@param z 纹理平铺和偏移Z分量。
- */
- /**
- *获取纹理平铺和偏移Z分量。
- *@return 纹理平铺和偏移Z分量。
- */
- __getset(0,__proto,'tilingOffsetZ',function(){
- return this._MainTex_STZ;
- },function(z){
- this._MainTex_STZ=z;
- });
- /**
- *设置混合源。
- *@param value 混合源
- */
- /**
- *获取混合源。
- *@return 混合源。
- */
- __getset(0,__proto,'blendSrc',function(){
- return this._shaderValues.getInt(TrailMaterial.BLEND_SRC);
- },function(value){
- this._shaderValues.setInt(TrailMaterial.BLEND_SRC,value);
- });
- /**
- *获取纹理平铺和偏移W分量。
- *@param w 纹理平铺和偏移W分量。
- */
- /**
- *获取纹理平铺和偏移W分量。
- *@return 纹理平铺和偏移W分量。
- */
- __getset(0,__proto,'tilingOffsetW',function(){
- return this._MainTex_STW;
- },function(w){
- this._MainTex_STW=w;
- });
- /**
- *设置纹理平铺和偏移。
- *@param value 纹理平铺和偏移。
- */
- /**
- *获取纹理平铺和偏移。
- *@return 纹理平铺和偏移。
- */
- __getset(0,__proto,'tilingOffset',function(){
- return this._shaderValues.getVector(TrailMaterial.TILINGOFFSET);
- },function(value){
- if (value){
- if (value.x !=1 || value.y !=1 || value.z !=0 || value.w !=0)
- this._defineDatas.add(laya.d3.core.trail.TrailMaterial.SHADERDEFINE_TILINGOFFSET);
- else
- this._defineDatas.remove(laya.d3.core.trail.TrailMaterial.SHADERDEFINE_TILINGOFFSET);
- }else {
- this._defineDatas.remove(laya.d3.core.trail.TrailMaterial.SHADERDEFINE_TILINGOFFSET);
- }
- this._shaderValues.setVector(TrailMaterial.TILINGOFFSET,value);
- });
- /**
- *设置是否写入深度。
- *@param value 是否写入深度。
- */
- /**
- *获取是否写入深度。
- *@return 是否写入深度。
- */
- __getset(0,__proto,'depthWrite',function(){
- return this._shaderValues.getBool(TrailMaterial.DEPTH_WRITE);
- },function(value){
- this._shaderValues.setBool(TrailMaterial.DEPTH_WRITE,value);
- });
- /**
- *设置剔除方式。
- *@param value 剔除方式。
- */
- /**
- *获取剔除方式。
- *@return 剔除方式。
- */
- __getset(0,__proto,'cull',function(){
- return this._shaderValues.getInt(TrailMaterial.CULL);
- },function(value){
- this._shaderValues.setInt(TrailMaterial.CULL,value);
- });
- /**
- *设置混合目标。
- *@param value 混合目标
- */
- /**
- *获取混合目标。
- *@return 混合目标。
- */
- __getset(0,__proto,'blendDst',function(){
- return this._shaderValues.getInt(TrailMaterial.BLEND_DST);
- },function(value){
- this._shaderValues.setInt(TrailMaterial.BLEND_DST,value);
- });
- /**
- *设置深度测试方式。
- *@param value 深度测试方式
- */
- /**
- *获取深度测试方式。
- *@return 深度测试方式。
- */
- __getset(0,__proto,'depthTest',function(){
- return this._shaderValues.getInt(TrailMaterial.DEPTH_TEST);
- },function(value){
- this._shaderValues.setInt(TrailMaterial.DEPTH_TEST,value);
- });
- TrailMaterial.__init__=function(){
- TrailMaterial.SHADERDEFINE_MAINTEXTURE=TrailMaterial.shaderDefines.registerDefine("MAINTEXTURE");
- TrailMaterial.SHADERDEFINE_TILINGOFFSET=TrailMaterial.shaderDefines.registerDefine("TILINGOFFSET");
- TrailMaterial.SHADERDEFINE_ADDTIVEFOG=TrailMaterial.shaderDefines.registerDefine("ADDTIVEFOG");
- }
- TrailMaterial.RENDERMODE_ALPHABLENDED=0;
- TrailMaterial.RENDERMODE_ADDTIVE=1;
- TrailMaterial.SHADERDEFINE_MAINTEXTURE=0;
- TrailMaterial.SHADERDEFINE_TILINGOFFSET=0;
- TrailMaterial.SHADERDEFINE_ADDTIVEFOG=0;
- __static(TrailMaterial,
- ['defaultMaterial',function(){return this.defaultMaterial=new TrailMaterial();},'MAINTEXTURE',function(){return this.MAINTEXTURE=Shader3D.propertyNameToID("u_MainTexture");},'TINTCOLOR',function(){return this.TINTCOLOR=Shader3D.propertyNameToID("u_MainColor");},'TILINGOFFSET',function(){return this.TILINGOFFSET=Shader3D.propertyNameToID("u_TilingOffset");},'CULL',function(){return this.CULL=Shader3D.propertyNameToID("s_Cull");},'BLEND',function(){return this.BLEND=Shader3D.propertyNameToID("s_Blend");},'BLEND_SRC',function(){return this.BLEND_SRC=Shader3D.propertyNameToID("s_BlendSrc");},'BLEND_DST',function(){return this.BLEND_DST=Shader3D.propertyNameToID("s_BlendDst");},'DEPTH_TEST',function(){return this.DEPTH_TEST=Shader3D.propertyNameToID("s_DepthTest");},'DEPTH_WRITE',function(){return this.DEPTH_WRITE=Shader3D.propertyNameToID("s_DepthWrite");},'shaderDefines',function(){return this.shaderDefines=new ShaderDefines(BaseMaterial.shaderDefines);}
- ]);
- return TrailMaterial;
- })(BaseMaterial)
- /**
- *<code>SkyProceduralMaterial</code> 类用于实现SkyProceduralMaterial材质。
- */
- //class laya.d3.core.material.SkyProceduralMaterial extends laya.d3.core.material.BaseMaterial
- var SkyProceduralMaterial=(function(_super){
- function SkyProceduralMaterial(){
- /**@private */
- this._sunDisk=0;
- SkyProceduralMaterial.__super.call(this);
- this.setShaderName("SkyBoxProcedural");
- this.sunDisk=1;
- this.sunSize=0.04;
- this.sunSizeConvergence=5;
- this.atmosphereThickness=1.0;
- this.skyTint=new Vector4(0.5,0.5,0.5,1.0);
- this.groundTint=new Vector4(0.369,0.349,0.341,1.0);
- this.exposure=1.3;
- }
- __class(SkyProceduralMaterial,'laya.d3.core.material.SkyProceduralMaterial',_super);
- var __proto=SkyProceduralMaterial.prototype;
- /**
- *设置曝光强度,范围是0到8。
- *@param value 曝光强度。
- */
- /**
- *获取曝光强度,范围是0到8。
- *@return 曝光强度。
- */
- __getset(0,__proto,'exposure',function(){
- return this._shaderValues.getNumber(SkyProceduralMaterial.EXPOSURE);
- },function(value){
- value=Math.min(Math.max(0.0,value),8.0);
- this._shaderValues.setNumber(SkyProceduralMaterial.EXPOSURE,value);
- });
- /**
- *设置太阳尺寸,范围是0到1。
- *@param value 太阳尺寸。
- */
- /**
- *获取太阳尺寸,范围是0到1。
- *@return 太阳尺寸。
- */
- __getset(0,__proto,'sunSize',function(){
- return this._shaderValues.getNumber(SkyProceduralMaterial.SUNSIZE);
- },function(value){
- value=Math.min(Math.max(0.0,value),1.0);
- this._shaderValues.setNumber(SkyProceduralMaterial.SUNSIZE,value);
- });
- /**
- *设置太阳状态。
- *@param value 太阳状态。
- */
- /**
- *获取太阳状态。
- *@return 太阳状态。
- */
- __getset(0,__proto,'sunDisk',function(){
- return this._sunDisk;
- },function(value){
- switch (value){
- case 1:
- this._defineDatas.remove(SkyProceduralMaterial.SHADERDEFINE_SUN_SIMPLE);
- this._defineDatas.add(SkyProceduralMaterial.SHADERDEFINE_SUN_HIGH_QUALITY);
- break ;
- case 2:
- this._defineDatas.remove(SkyProceduralMaterial.SHADERDEFINE_SUN_HIGH_QUALITY);
- this._defineDatas.add(SkyProceduralMaterial.SHADERDEFINE_SUN_SIMPLE);
- break ;
- case 0:
- this._defineDatas.remove(SkyProceduralMaterial.SHADERDEFINE_SUN_HIGH_QUALITY);
- this._defineDatas.remove(SkyProceduralMaterial.SHADERDEFINE_SUN_SIMPLE);
- break ;
- default :
- throw "SkyBoxProceduralMaterial: unknown sun value.";
- }
- this._sunDisk=value;
- });
- /**
- *设置太阳尺寸收缩,范围是0到20。
- *@param value 太阳尺寸收缩。
- */
- /**
- *获取太阳尺寸收缩,范围是0到20。
- *@return 太阳尺寸收缩。
- */
- __getset(0,__proto,'sunSizeConvergence',function(){
- return this._shaderValues.getNumber(SkyProceduralMaterial.SUNSIZECONVERGENCE);
- },function(value){
- value=Math.min(Math.max(0.0,value),20.0);
- this._shaderValues.setNumber(SkyProceduralMaterial.SUNSIZECONVERGENCE,value);
- });
- /**
- *设置大气厚度,范围是0到5。
- *@param value 大气厚度。
- */
- /**
- *获取大气厚度,范围是0到5。
- *@return 大气厚度。
- */
- __getset(0,__proto,'atmosphereThickness',function(){
- return this._shaderValues.getNumber(SkyProceduralMaterial.ATMOSPHERETHICKNESS);
- },function(value){
- value=Math.min(Math.max(0.0,value),5.0);
- this._shaderValues.setNumber(SkyProceduralMaterial.ATMOSPHERETHICKNESS,value);
- });
- /**
- *设置地面颜色。
- *@param value 地面颜色。
- */
- /**
- *获取地面颜色。
- *@return 地面颜色。
- */
- __getset(0,__proto,'groundTint',function(){
- return this._shaderValues.getVector(SkyProceduralMaterial.GROUNDTINT);
- },function(value){
- this._shaderValues.setVector(SkyProceduralMaterial.GROUNDTINT,value);
- });
- /**
- *设置天空颜色。
- *@param value 天空颜色。
- */
- /**
- *获取天空颜色。
- *@return 天空颜色。
- */
- __getset(0,__proto,'skyTint',function(){
- return this._shaderValues.getVector(SkyProceduralMaterial.SKYTINT);
- },function(value){
- this._shaderValues.setVector(SkyProceduralMaterial.SKYTINT,value);
- });
- SkyProceduralMaterial.__init__=function(){
- SkyProceduralMaterial.SHADERDEFINE_SUN_HIGH_QUALITY=SkyProceduralMaterial.shaderDefines.registerDefine("SUN_HIGH_QUALITY");
- SkyProceduralMaterial.SHADERDEFINE_SUN_SIMPLE=SkyProceduralMaterial.shaderDefines.registerDefine("SUN_SIMPLE");
- }
- SkyProceduralMaterial.SUN_NODE=0;
- SkyProceduralMaterial.SUN_HIGH_QUALITY=1;
- SkyProceduralMaterial.SUN_SIMPLE=2;
- SkyProceduralMaterial.SHADERDEFINE_SUN_HIGH_QUALITY=0;
- SkyProceduralMaterial.SHADERDEFINE_SUN_SIMPLE=0;
- __static(SkyProceduralMaterial,
- ['SUNSIZE',function(){return this.SUNSIZE=Shader3D.propertyNameToID("u_SunSize");},'SUNSIZECONVERGENCE',function(){return this.SUNSIZECONVERGENCE=Shader3D.propertyNameToID("u_SunSizeConvergence");},'ATMOSPHERETHICKNESS',function(){return this.ATMOSPHERETHICKNESS=Shader3D.propertyNameToID("u_AtmosphereThickness");},'SKYTINT',function(){return this.SKYTINT=Shader3D.propertyNameToID("u_SkyTint");},'GROUNDTINT',function(){return this.GROUNDTINT=Shader3D.propertyNameToID("u_GroundTint");},'EXPOSURE',function(){return this.EXPOSURE=Shader3D.propertyNameToID("u_Exposure");},'defaultMaterial',function(){return this.defaultMaterial=new SkyProceduralMaterial();},'shaderDefines',function(){return this.shaderDefines=new ShaderDefines(BaseMaterial.shaderDefines);}
- ]);
- return SkyProceduralMaterial;
- })(BaseMaterial)
- /**
- *...
- *@author
- */
- //class laya.d3.core.pixelLine.PixelLineMaterial extends laya.d3.core.material.BaseMaterial
- var PixelLineMaterial=(function(_super){
- function PixelLineMaterial(){
- PixelLineMaterial.__super.call(this);
- this.setShaderName("LineShader");
- this._shaderValues.setVector(PixelLineMaterial.COLOR,new Vector4(1.0,1.0,1.0,1.0));
- }
- __class(PixelLineMaterial,'laya.d3.core.pixelLine.PixelLineMaterial',_super);
- var __proto=PixelLineMaterial.prototype;
- /**
- *设置混合方式。
- *@param value 混合方式。
- */
- /**
- *获取混合方式。
- *@return 混合方式。
- */
- __getset(0,__proto,'blend',function(){
- return this._shaderValues.getInt(PixelLineMaterial.BLEND);
- },function(value){
- this._shaderValues.setInt(PixelLineMaterial.BLEND,value);
- });
- /**
- *设置颜色。
- *@param value 颜色。
- */
- /**
- *获取颜色。
- *@return 颜色。
- */
- __getset(0,__proto,'color',function(){
- return this._shaderValues.getVector(PixelLineMaterial.COLOR);
- },function(value){
- this._shaderValues.setVector(PixelLineMaterial.COLOR,value);
- });
- /**
- *设置剔除方式。
- *@param value 剔除方式。
- */
- /**
- *获取剔除方式。
- *@return 剔除方式。
- */
- __getset(0,__proto,'cull',function(){
- return this._shaderValues.getInt(PixelLineMaterial.CULL);
- },function(value){
- this._shaderValues.setInt(PixelLineMaterial.CULL,value);
- });
- /**
- *设置是否写入深度。
- *@param value 是否写入深度。
- */
- /**
- *获取是否写入深度。
- *@return 是否写入深度。
- */
- __getset(0,__proto,'depthWrite',function(){
- return this._shaderValues.getBool(PixelLineMaterial.DEPTH_WRITE);
- },function(value){
- this._shaderValues.setBool(PixelLineMaterial.DEPTH_WRITE,value);
- });
- /**
- *设置混合源。
- *@param value 混合源
- */
- /**
- *获取混合源。
- *@return 混合源。
- */
- __getset(0,__proto,'blendSrc',function(){
- return this._shaderValues.getInt(PixelLineMaterial.BLEND_SRC);
- },function(value){
- this._shaderValues.setInt(PixelLineMaterial.BLEND_SRC,value);
- });
- /**
- *设置混合目标。
- *@param value 混合目标
- */
- /**
- *获取混合目标。
- *@return 混合目标。
- */
- __getset(0,__proto,'blendDst',function(){
- return this._shaderValues.getInt(PixelLineMaterial.BLEND_DST);
- },function(value){
- this._shaderValues.setInt(PixelLineMaterial.BLEND_DST,value);
- });
- /**
- *设置深度测试方式。
- *@param value 深度测试方式
- */
- /**
- *获取深度测试方式。
- *@return 深度测试方式。
- */
- __getset(0,__proto,'depthTest',function(){
- return this._shaderValues.getInt(PixelLineMaterial.DEPTH_TEST);
- },function(value){
- this._shaderValues.setInt(PixelLineMaterial.DEPTH_TEST,value);
- });
- __static(PixelLineMaterial,
- ['COLOR',function(){return this.COLOR=Shader3D.propertyNameToID("u_Color");},'defaultMaterial',function(){return this.defaultMaterial=new PixelLineMaterial();},'shaderDefines',function(){return this.shaderDefines=new ShaderDefines(BaseMaterial.shaderDefines);},'CULL',function(){return this.CULL=Shader3D.propertyNameToID("s_Cull");},'BLEND',function(){return this.BLEND=Shader3D.propertyNameToID("s_Blend");},'BLEND_SRC',function(){return this.BLEND_SRC=Shader3D.propertyNameToID("s_BlendSrc");},'BLEND_DST',function(){return this.BLEND_DST=Shader3D.propertyNameToID("s_BlendDst");},'DEPTH_TEST',function(){return this.DEPTH_TEST=Shader3D.propertyNameToID("s_DepthTest");},'DEPTH_WRITE',function(){return this.DEPTH_WRITE=Shader3D.propertyNameToID("s_DepthWrite");}
- ]);
- return PixelLineMaterial;
- })(BaseMaterial)
- /**
- *<code>BaseCamera</code> 类用于创建摄像机的父类。
- */
- //class laya.d3.core.BaseCamera extends laya.d3.core.Sprite3D
- var BaseCamera=(function(_super){
- function BaseCamera(nearPlane,farPlane){
- /**@private 渲染顺序。*/
- //this._renderingOrder=0;
- /**@private 近裁剪面。*/
- //this._nearPlane=NaN;
- /**@private 远裁剪面。*/
- //this._farPlane=NaN;
- /**@private 视野。*/
- //this._fieldOfView=NaN;
- /**@private 正交投影的垂直尺寸。*/
- //this._orthographicVerticalSize=NaN;
- /**@private */
- //this._orthographic=false;
- /**@private 是否使用用户自定义投影矩阵,如果使用了用户投影矩阵,摄像机投影矩阵相关的参数改变则不改变投影矩阵的值,需调用ResetProjectionMatrix方法。*/
- //this._useUserProjectionMatrix=false;
- /**@private */
- //this._shaderValues=null;
- /**清楚标记。*/
- //this.clearFlag=0;
- /**可视层位标记遮罩值,支持混合 例:cullingMask=Math.pow(2,0)|Math.pow(2,1)为第0层和第1层可见。*/
- //this.cullingMask=0;
- /**渲染时是否用遮挡剔除。 */
- //this.useOcclusionCulling=false;
- BaseCamera.__super.call(this);
- this._skyRenderer=new SkyRenderer();
- this._forward=new Vector3();
- this._up=new Vector3();
- this.clearColor=new Vector4(100 / 255,149 / 255,237 / 255,255 / 255);
- (nearPlane===void 0)&& (nearPlane=0.3);
- (farPlane===void 0)&& (farPlane=1000);
- this._shaderValues=new ShaderData(null);
- this._fieldOfView=60;
- this._useUserProjectionMatrix=false;
- this._orthographic=false;
- this._orthographicVerticalSize=10;
- this.renderingOrder=0;
- this._nearPlane=nearPlane;
- this._farPlane=farPlane;
- this.cullingMask=2147483647;
- this.clearFlag=/*CLASS CONST:laya.d3.core.BaseCamera.CLEARFLAG_SOLIDCOLOR*/0;
- this.useOcclusionCulling=true;
- this._calculateProjectionMatrix();
- Laya.stage.on(/*laya.events.Event.RESIZE*/"resize",this,this._onScreenSizeChanged);
- }
- __class(BaseCamera,'laya.d3.core.BaseCamera',_super);
- var __proto=BaseCamera.prototype;
- /**
- *通过RenderingOrder属性对摄像机机型排序。
- */
- __proto._sortCamerasByRenderingOrder=function(){
- if (this.displayedInStage){
- var cameraPool=this.scene._cameraPool;
- var n=cameraPool.length-1;
- for (var i=0;i < n;i++){
- if (cameraPool[i].renderingOrder > cameraPool[n].renderingOrder){
- var tempCamera=cameraPool[i];
- cameraPool[i]=cameraPool[n];
- cameraPool[n]=tempCamera;
- }
- }
- }
- }
- /**
- *@private
- */
- __proto._calculateProjectionMatrix=function(){}
- /**
- *@private
- */
- __proto._onScreenSizeChanged=function(){
- this._calculateProjectionMatrix();
- }
- /**
- *@private
- */
- __proto._prepareCameraToRender=function(){
- this.transform.getForward(this._forward);
- this.transform.getUp(this._up);
- var cameraSV=this._shaderValues;
- cameraSV.setVector3(laya.d3.core.BaseCamera.CAMERAPOS,this.transform.position);
- cameraSV.setVector3(laya.d3.core.BaseCamera.CAMERADIRECTION,this._forward);
- cameraSV.setVector3(laya.d3.core.BaseCamera.CAMERAUP,this._up);
- }
- /**
- *@private
- */
- __proto._prepareCameraViewProject=function(vieMat,proMat,viewProject,vieProNoTraSca){
- var shaderData=this._shaderValues;
- shaderData.setMatrix4x4(laya.d3.core.BaseCamera.VIEWMATRIX,vieMat);
- shaderData.setMatrix4x4(laya.d3.core.BaseCamera.PROJECTMATRIX,proMat);
- shaderData.setMatrix4x4(laya.d3.core.BaseCamera.VIEWPROJECTMATRIX,viewProject);
- this.transform.worldMatrix.cloneTo(BaseCamera._tempMatrix4x40);
- BaseCamera._tempMatrix4x40.transpose();
- Matrix4x4.multiply(proMat,BaseCamera._tempMatrix4x40,vieProNoTraSca);
- shaderData.setMatrix4x4(laya.d3.core.BaseCamera.VPMATRIX_NO_TRANSLATE,vieProNoTraSca);
- }
- /**
- *相机渲染。
- *@param shader 着色器。
- *@param replacementTag 着色器替换标记。
- */
- __proto.render=function(shader,replacementTag){}
- /**
- *增加可视图层,layer值为0到31层。
- *@param layer 图层。
- */
- __proto.addLayer=function(layer){
- this.cullingMask |=Math.pow(2,layer);
- }
- /**
- *移除可视图层,layer值为0到31层。
- *@param layer 图层。
- */
- __proto.removeLayer=function(layer){
- this.cullingMask &=~Math.pow(2,layer);
- }
- /**
- *增加所有图层。
- */
- __proto.addAllLayers=function(){
- this.cullingMask=2147483647;
- }
- /**
- *移除所有图层。
- */
- __proto.removeAllLayers=function(){
- this.cullingMask=0;
- }
- __proto.resetProjectionMatrix=function(){
- this._useUserProjectionMatrix=false;
- this._calculateProjectionMatrix();
- }
- /**
- *@inheritDoc
- */
- __proto._onActive=function(){
- (this._scene)._addCamera(this);
- laya.display.Node.prototype._onActive.call(this);
- }
- /**
- *@inheritDoc
- */
- __proto._onInActive=function(){
- (this._scene)._removeCamera(this);
- laya.display.Node.prototype._onInActive.call(this);
- }
- /**
- *@inheritDoc
- */
- __proto._parse=function(data,spriteMap){
- _super.prototype._parse.call(this,data,spriteMap);
- var clearFlagData=data.clearFlag;
- (clearFlagData!==undefined)&& (this.clearFlag=clearFlagData);
- this.orthographic=data.orthographic;
- this.fieldOfView=data.fieldOfView;
- this.nearPlane=data.nearPlane;
- this.farPlane=data.farPlane;
- var color=data.clearColor;
- this.clearColor=new Vector4(color[0],color[1],color[2],color[3]);
- var skyboxMaterial=data.skyboxMaterial;
- if (skyboxMaterial){
- this._skyRenderer.material=Loader.getRes(skyboxMaterial.path);
- }
- }
- /**
- *@inheritDoc
- */
- __proto.destroy=function(destroyChild){
- (destroyChild===void 0)&& (destroyChild=true);
- this._skyRenderer.destroy();
- this._skyRenderer=null;
- Laya.stage.off(/*laya.events.Event.RESIZE*/"resize",this,this._onScreenSizeChanged);
- _super.prototype.destroy.call(this,destroyChild);
- }
- __getset(0,__proto,'renderingOrder',function(){
- return this._renderingOrder;
- },function(value){
- this._renderingOrder=value;
- this._sortCamerasByRenderingOrder();
- });
- /**
- *获取天空渲染器。
- *@return 天空渲染器。
- */
- __getset(0,__proto,'skyRenderer',function(){
- return this._skyRenderer;
- });
- /**
- *设置是否正交投影矩阵。
- *@param 是否正交投影矩阵。
- */
- /**
- *获取是否正交投影矩阵。
- *@return 是否正交投影矩阵。
- */
- __getset(0,__proto,'orthographic',function(){
- return this._orthographic;
- },function(vaule){
- this._orthographic=vaule;
- this._calculateProjectionMatrix();
- });
- /**
- *设置视野。
- *@param value 视野。
- */
- /**
- *获取视野。
- *@return 视野。
- */
- __getset(0,__proto,'fieldOfView',function(){
- return this._fieldOfView;
- },function(value){
- this._fieldOfView=value;
- this._calculateProjectionMatrix();
- });
- /**
- *设置近裁面。
- *@param value 近裁面。
- */
- /**
- *获取近裁面。
- *@return 近裁面。
- */
- __getset(0,__proto,'nearPlane',function(){
- return this._nearPlane;
- },function(value){
- this._nearPlane=value;
- this._calculateProjectionMatrix();
- });
- /**
- *设置远裁面。
- *@param value 远裁面。
- */
- /**
- *获取远裁面。
- *@return 远裁面。
- */
- __getset(0,__proto,'farPlane',function(){
- return this._farPlane;
- },function(vaule){
- this._farPlane=vaule;
- this._calculateProjectionMatrix();
- });
- /**
- *设置正交投影垂直矩阵尺寸。
- *@param 正交投影垂直矩阵尺寸。
- */
- /**
- *获取正交投影垂直矩阵尺寸。
- *@return 正交投影垂直矩阵尺寸。
- */
- __getset(0,__proto,'orthographicVerticalSize',function(){
- return this._orthographicVerticalSize;
- },function(vaule){
- this._orthographicVerticalSize=vaule;
- this._calculateProjectionMatrix();
- });
- BaseCamera.RENDERINGTYPE_DEFERREDLIGHTING="DEFERREDLIGHTING";
- BaseCamera.RENDERINGTYPE_FORWARDRENDERING="FORWARDRENDERING";
- BaseCamera.CLEARFLAG_SOLIDCOLOR=0;
- BaseCamera.CLEARFLAG_SKY=1;
- BaseCamera.CLEARFLAG_DEPTHONLY=2;
- BaseCamera.CLEARFLAG_NONE=3;
- __static(BaseCamera,
- ['_tempMatrix4x40',function(){return this._tempMatrix4x40=new Matrix4x4();},'CAMERAPOS',function(){return this.CAMERAPOS=Shader3D.propertyNameToID("u_CameraPos");},'VIEWMATRIX',function(){return this.VIEWMATRIX=Shader3D.propertyNameToID("u_View");},'PROJECTMATRIX',function(){return this.PROJECTMATRIX=Shader3D.propertyNameToID("u_Projection");},'VIEWPROJECTMATRIX',function(){return this.VIEWPROJECTMATRIX=Shader3D.propertyNameToID("u_ViewProjection");},'VPMATRIX_NO_TRANSLATE',function(){return this.VPMATRIX_NO_TRANSLATE=Shader3D.propertyNameToID("u_MvpMatrix");},'CAMERADIRECTION',function(){return this.CAMERADIRECTION=Shader3D.propertyNameToID("u_CameraDirection");},'CAMERAUP',function(){return this.CAMERAUP=Shader3D.propertyNameToID("u_CameraUp");},'_invertYScaleMatrix',function(){return this._invertYScaleMatrix=new Matrix4x4(1,0,0,0,0,-1,0,0,0,0,1,0,0,0,0,1);},'_invertYProjectionMatrix',function(){return this._invertYProjectionMatrix=new Matrix4x4();},'_invertYProjectionViewMatrix',function(){return this._invertYProjectionViewMatrix=new Matrix4x4();}
- ]);
- return BaseCamera;
- })(Sprite3D)
- /**
- *<code>PBRStandardMaterial</code> 类用于实现PBR(Standard)材质。
- */
- //class laya.d3.core.material.PBRStandardMaterial extends laya.d3.core.material.BaseMaterial
- var PBRStandardMaterial=(function(_super){
- function PBRStandardMaterial(){
- /**@private */
- this._albedoColor=null;
- /**@private */
- this._emissionColor=null;
- PBRStandardMaterial.__super.call(this);
- this.setShaderName("PBRStandard");
- this._albedoColor=new Vector4(1.0,1.0,1.0,1.0);
- this._shaderValues.setVector(PBRStandardMaterial.ALBEDOCOLOR,new Vector4(1.0,1.0,1.0,1.0));
- this._emissionColor=new Vector4(0.0,0.0,0.0,0.0);
- this._shaderValues.setVector(PBRStandardMaterial.EMISSIONCOLOR,new Vector4(0.0,0.0,0.0,0.0));
- this._shaderValues.setNumber(PBRStandardMaterial.METALLIC,0.0);
- this._shaderValues.setNumber(PBRStandardMaterial.SMOOTHNESS,0.5);
- this._shaderValues.setNumber(PBRStandardMaterial.SMOOTHNESSSCALE,1.0);
- this._shaderValues.setNumber(PBRStandardMaterial.SMOOTHNESSSOURCE,0);
- this._shaderValues.setNumber(PBRStandardMaterial.OCCLUSIONSTRENGTH,1.0);
- this._shaderValues.setNumber(PBRStandardMaterial.NORMALSCALE,1.0);
- this._shaderValues.setNumber(PBRStandardMaterial.PARALLAXSCALE,0.001);
- this._shaderValues.setBool(PBRStandardMaterial.ENABLEEMISSION,false);
- this._shaderValues.setBool(PBRStandardMaterial.ENABLEREFLECT,true);
- this._shaderValues.setNumber(BaseMaterial.ALPHATESTVALUE,0.5);
- this._disablePublicDefineDatas.remove(Scene3D.SHADERDEFINE_REFLECTMAP);
- this.renderMode=0;
- }
- __class(PBRStandardMaterial,'laya.d3.core.material.PBRStandardMaterial',_super);
- var __proto=PBRStandardMaterial.prototype;
- /**
- *@inheritDoc
- */
- __proto.cloneTo=function(destObject){
- _super.prototype.cloneTo.call(this,destObject);
- var destMaterial=destObject;
- this._albedoColor.cloneTo(destMaterial._albedoColor);
- this._emissionColor.cloneTo(destMaterial._emissionColor);
- }
- /**
- *@private
- */
- /**@private */
- __getset(0,__proto,'_Parallax',function(){
- return this._shaderValues.getNumber(PBRStandardMaterial.PARALLAXSCALE);
- },function(value){
- this._shaderValues.setNumber(PBRStandardMaterial.PARALLAXSCALE,value);
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_ColorB',function(){
- return this._albedoColor.z;
- },function(value){
- this._albedoColor.z=value;
- this.albedoColor=this._albedoColor;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_ColorR',function(){
- return this._albedoColor.x;
- },function(value){
- this._albedoColor.x=value;
- this.albedoColor=this._albedoColor;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_ColorG',function(){
- return this._albedoColor.y;
- },function(value){
- this._albedoColor.y=value;
- this.albedoColor=this._albedoColor;
- });
- /**
- *设置金属度。
- *@param value 金属度,范围为0到1。
- */
- /**
- *获取金属度。
- *@return 金属度,范围为0到1。
- */
- __getset(0,__proto,'metallic',function(){
- return this._Metallic;
- },function(value){
- this._Metallic=Math.max(0.0,Math.min(1.0,value));
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_GlossMapScale',function(){
- return this._shaderValues.getNumber(PBRStandardMaterial.SMOOTHNESSSCALE);
- },function(value){
- this._shaderValues.setNumber(PBRStandardMaterial.SMOOTHNESSSCALE,value);
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_Glossiness',function(){
- return this._shaderValues.getNumber(PBRStandardMaterial.SMOOTHNESS);
- },function(value){
- this._shaderValues.setNumber(PBRStandardMaterial.SMOOTHNESS,value);
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_ColorA',function(){
- return this._albedoColor.w;
- },function(value){
- this._albedoColor.w=value;
- this.albedoColor=this._albedoColor;
- });
- /**
- *设置是否开启反射。
- *@param value 是否开启反射。
- */
- /**
- *获取是否开启反射。
- *@return 是否开启反射。
- */
- __getset(0,__proto,'enableReflection',function(){
- return this._shaderValues.getBool(PBRStandardMaterial.ENABLEREFLECT);
- },function(value){
- this._shaderValues.setBool(PBRStandardMaterial.ENABLEREFLECT,true);
- if (value){
- this._disablePublicDefineDatas.remove(Scene3D.SHADERDEFINE_REFLECTMAP);
- }else {
- this._disablePublicDefineDatas.add(Scene3D.SHADERDEFINE_REFLECTMAP);
- }
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_Metallic',function(){
- return this._shaderValues.getNumber(PBRStandardMaterial.METALLIC);
- },function(value){
- this._shaderValues.setNumber(PBRStandardMaterial.METALLIC,value);
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_BumpScale',function(){
- return this._shaderValues.getNumber(PBRStandardMaterial.NORMALSCALE);
- },function(value){
- this._shaderValues.setNumber(PBRStandardMaterial.NORMALSCALE,value);
- });
- /**
- *@private
- */
- /**@private */
- __getset(0,__proto,'_OcclusionStrength',function(){
- return this._shaderValues.getNumber(PBRStandardMaterial.OCCLUSIONSTRENGTH);
- },function(value){
- this._shaderValues.setNumber(PBRStandardMaterial.OCCLUSIONSTRENGTH,value);
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_EmissionColorR',function(){
- return this._emissionColor.x;
- },function(value){
- this._emissionColor.x=value;
- this.emissionColor=this._emissionColor;
- });
- /**
- *获取纹理平铺和偏移。
- *@param value 纹理平铺和偏移。
- */
- /**
- *获取纹理平铺和偏移。
- *@return 纹理平铺和偏移。
- */
- __getset(0,__proto,'tilingOffset',function(){
- return this._shaderValues.getVector(PBRStandardMaterial.TILINGOFFSET);
- },function(value){
- if (value){
- if (value.x !=1 || value.y !=1 || value.z !=0 || value.w !=0){
- this._defineDatas.add(laya.d3.core.material.PBRStandardMaterial.SHADERDEFINE_TILINGOFFSET);
- }else {
- this._defineDatas.remove(laya.d3.core.material.PBRStandardMaterial.SHADERDEFINE_TILINGOFFSET);
- }
- }else {
- this._defineDatas.remove(laya.d3.core.material.PBRStandardMaterial.SHADERDEFINE_TILINGOFFSET);
- }
- this._shaderValues.setVector(PBRStandardMaterial.TILINGOFFSET,value);
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_EmissionColorG',function(){
- return this._emissionColor.y;
- },function(value){
- this._emissionColor.y=value;
- this.emissionColor=this._emissionColor;
- });
- /**
- *设置混合源。
- *@param value 混合源
- */
- /**
- *获取混合源。
- *@return 混合源。
- */
- __getset(0,__proto,'blendSrc',function(){
- return this._shaderValues.getInt(PBRStandardMaterial.BLEND_SRC);
- },function(value){
- this._shaderValues.setInt(PBRStandardMaterial.BLEND_SRC,value);
- });
- /**
- *获取纹理平铺和偏移W分量。
- *@param w 纹理平铺和偏移W分量。
- */
- /**
- *获取纹理平铺和偏移W分量。
- *@return 纹理平铺和偏移W分量。
- */
- __getset(0,__proto,'tilingOffsetW',function(){
- return this._MainTex_STW;
- },function(w){
- this._MainTex_STW=w;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_EmissionColorB',function(){
- return this._emissionColor.z;
- },function(value){
- this._emissionColor.z=value;
- this.emissionColor=this._emissionColor;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_EmissionColorA',function(){
- return this._emissionColor.w;
- },function(value){
- this._emissionColor.w=value;
- this.emissionColor=this._emissionColor;
- });
- /**
- *设置反射率颜色alpha分量。
- *@param value 反射率颜色alpha分量。
- */
- /**
- *获取反射率颜色Z分量。
- *@return 反射率颜色Z分量。
- */
- __getset(0,__proto,'albedoColorA',function(){
- return this._ColorA;
- },function(value){
- this._ColorA=value;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_MainTex_STX',function(){
- return this._shaderValues.getVector(PBRStandardMaterial.TILINGOFFSET).x;
- },function(x){
- var tilOff=this._shaderValues.getVector(PBRStandardMaterial.TILINGOFFSET);
- tilOff.x=x;
- this.tilingOffset=tilOff;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_MainTex_STY',function(){
- return this._shaderValues.getVector(PBRStandardMaterial.TILINGOFFSET).y;
- },function(y){
- var tilOff=this._shaderValues.getVector(PBRStandardMaterial.TILINGOFFSET);
- tilOff.y=y;
- this.tilingOffset=tilOff;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_MainTex_STZ',function(){
- return this._shaderValues.getVector(PBRStandardMaterial.TILINGOFFSET).z;
- },function(z){
- var tilOff=this._shaderValues.getVector(PBRStandardMaterial.TILINGOFFSET);
- tilOff.z=z;
- this.tilingOffset=tilOff;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_Cutoff',function(){
- return this.alphaTestValue;
- },function(value){
- this.alphaTestValue=value;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_MainTex_STW',function(){
- return this._shaderValues.getVector(PBRStandardMaterial.TILINGOFFSET).w;
- },function(w){
- var tilOff=this._shaderValues.getVector(PBRStandardMaterial.TILINGOFFSET);
- tilOff.w=w;
- this.tilingOffset=tilOff;
- });
- /**
- *设置反射率颜色R分量。
- *@param value 反射率颜色R分量。
- */
- /**
- *获取反射率颜色R分量。
- *@return 反射率颜色R分量。
- */
- __getset(0,__proto,'albedoColorR',function(){
- return this._ColorR;
- },function(value){
- this._ColorR=value;
- });
- /**
- *设置反射率颜色G分量。
- *@param value 反射率颜色G分量。
- */
- /**
- *获取反射率颜色G分量。
- *@return 反射率颜色G分量。
- */
- __getset(0,__proto,'albedoColorG',function(){
- return this._ColorG;
- },function(value){
- this._ColorG=value;
- });
- /**
- *设置反射率颜色B分量。
- *@param value 反射率颜色B分量。
- */
- /**
- *获取反射率颜色B分量。
- *@return 反射率颜色B分量。
- */
- __getset(0,__proto,'albedoColorB',function(){
- return this._ColorB;
- },function(value){
- this._ColorB=value;
- });
- /**
- *获取纹理平铺和偏移X分量。
- *@param x 纹理平铺和偏移X分量。
- */
- /**
- *获取纹理平铺和偏移X分量。
- *@return 纹理平铺和偏移X分量。
- */
- __getset(0,__proto,'tilingOffsetX',function(){
- return this._MainTex_STX;
- },function(x){
- this._MainTex_STX=x;
- });
- /**
- *设置漫反射颜色。
- *@param value 漫反射颜色。
- */
- /**
- *获取漫反射颜色。
- *@return 漫反射颜色。
- */
- __getset(0,__proto,'albedoColor',function(){
- return this._albedoColor;
- },function(value){
- this._albedoColor=value;
- this._shaderValues.setVector(PBRStandardMaterial.ALBEDOCOLOR,value);
- });
- /**
- *设置漫反射贴图。
- *@param value 漫反射贴图。
- */
- /**
- *获取漫反射贴图。
- *@return 漫反射贴图。
- */
- __getset(0,__proto,'albedoTexture',function(){
- return this._shaderValues.getTexture(PBRStandardMaterial.ALBEDOTEXTURE);
- },function(value){
- if (value){
- this._defineDatas.add(laya.d3.core.material.PBRStandardMaterial.SHADERDEFINE_ALBEDOTEXTURE);
- }else {
- this._defineDatas.remove(laya.d3.core.material.PBRStandardMaterial.SHADERDEFINE_ALBEDOTEXTURE);
- }
- this._shaderValues.setTexture(PBRStandardMaterial.ALBEDOTEXTURE,value);
- });
- /**
- *设置剔除方式。
- *@param value 剔除方式。
- */
- /**
- *获取剔除方式。
- *@return 剔除方式。
- */
- __getset(0,__proto,'cull',function(){
- return this._shaderValues.getInt(PBRStandardMaterial.CULL);
- },function(value){
- this._shaderValues.setInt(PBRStandardMaterial.CULL,value);
- });
- /**
- *设置视差贴图。
- *@param value 视察贴图。
- */
- /**
- *获取视差贴图。
- *@return 视察贴图。
- */
- __getset(0,__proto,'parallaxTexture',function(){
- return this._shaderValues.getTexture(PBRStandardMaterial.PARALLAXTEXTURE);
- },function(value){
- if (value){
- this._defineDatas.add(laya.d3.core.material.PBRStandardMaterial.SHADERDEFINE_PARALLAXTEXTURE);
- }else {
- this._defineDatas.remove(laya.d3.core.material.PBRStandardMaterial.SHADERDEFINE_PARALLAXTEXTURE);
- }
- this._shaderValues.setTexture(PBRStandardMaterial.PARALLAXTEXTURE,value);
- });
- /**
- *设置法线贴图。
- *@param value 法线贴图。
- */
- /**
- *获取法线贴图。
- *@return 法线贴图。
- */
- __getset(0,__proto,'normalTexture',function(){
- return this._shaderValues.getTexture(PBRStandardMaterial.NORMALTEXTURE);
- },function(value){
- if (value){
- this._defineDatas.add(laya.d3.core.material.PBRStandardMaterial.SHADERDEFINE_NORMALTEXTURE);
- }else {
- this._defineDatas.remove(laya.d3.core.material.PBRStandardMaterial.SHADERDEFINE_NORMALTEXTURE);
- }
- this._shaderValues.setTexture(PBRStandardMaterial.NORMALTEXTURE,value);
- });
- /**
- *设置放射颜色。
- *@param value 放射颜色。
- */
- /**
- *获取放射颜色。
- *@return 放射颜色。
- */
- __getset(0,__proto,'emissionColor',function(){
- return this._shaderValues.getVector(PBRStandardMaterial.EMISSIONCOLOR);
- },function(value){
- this._shaderValues.setVector(PBRStandardMaterial.EMISSIONCOLOR,value);
- });
- /**
- *设置视差贴图缩放系数。
- *@param value 视差缩放系数。
- */
- /**
- *获取视差贴图缩放系数。
- *@return 视差缩放系数。
- */
- __getset(0,__proto,'parallaxTextureScale',function(){
- return this._Parallax;
- },function(value){
- this._Parallax=Math.max(0.005,Math.min(0.08,value));
- });
- /**
- *设置法线贴图缩放系数。
- *@param value 法线贴图缩放系数。
- */
- /**
- *获取法线贴图缩放系数。
- *@return 法线贴图缩放系数。
- */
- __getset(0,__proto,'normalTextureScale',function(){
- return this._BumpScale;
- },function(value){
- this._BumpScale=value;
- });
- /**
- *获取纹理平铺和偏移Z分量。
- *@param z 纹理平铺和偏移Z分量。
- */
- /**
- *获取纹理平铺和偏移Z分量。
- *@return 纹理平铺和偏移Z分量。
- */
- __getset(0,__proto,'tilingOffsetZ',function(){
- return this._MainTex_STZ;
- },function(z){
- this._MainTex_STZ=z;
- });
- /**
- *设置遮挡贴图。
- *@param value 遮挡贴图。
- */
- /**
- *获取遮挡贴图。
- *@return 遮挡贴图。
- */
- __getset(0,__proto,'occlusionTexture',function(){
- return this._shaderValues.getTexture(PBRStandardMaterial.OCCLUSIONTEXTURE);
- },function(value){
- if (value){
- this._defineDatas.add(laya.d3.core.material.PBRStandardMaterial.SHADERDEFINE_OCCLUSIONTEXTURE);
- }else {
- this._defineDatas.remove(laya.d3.core.material.PBRStandardMaterial.SHADERDEFINE_OCCLUSIONTEXTURE);
- }
- this._shaderValues.setTexture(PBRStandardMaterial.OCCLUSIONTEXTURE,value);
- });
- /**
- *设置遮挡贴图强度。
- *@param value 遮挡贴图强度,范围为0到1。
- */
- /**
- *获取遮挡贴图强度。
- *@return 遮挡贴图强度,范围为0到1。
- */
- __getset(0,__proto,'occlusionTextureStrength',function(){
- return this._OcclusionStrength;
- },function(value){
- this._OcclusionStrength=Math.max(0.0,Math.min(1.0,value));
- });
- /**
- *设置是否激活放射属性。
- *@param value 是否激活放射属性
- */
- /**
- *获取是否激活放射属性。
- *@return 是否激活放射属性。
- */
- __getset(0,__proto,'enableEmission',function(){
- return this._shaderValues.getBool(PBRStandardMaterial.ENABLEEMISSION);
- },function(value){
- if (value){
- this._defineDatas.add(laya.d3.core.material.PBRStandardMaterial.SHADERDEFINE_EMISSION);
- }else {
- this._defineDatas.remove(laya.d3.core.material.PBRStandardMaterial.SHADERDEFINE_EMISSION);
- }
- this._shaderValues.setBool(PBRStandardMaterial.ENABLEEMISSION,value);
- });
- /**
- *设置金属光滑度贴图。
- *@param value 金属光滑度贴图。
- */
- /**
- *获取金属光滑度贴图。
- *@return 金属光滑度贴图。
- */
- __getset(0,__proto,'metallicGlossTexture',function(){
- return this._shaderValues.getTexture(PBRStandardMaterial.METALLICGLOSSTEXTURE);
- },function(value){
- if (value){
- this._defineDatas.add(laya.d3.core.material.PBRStandardMaterial.SHADERDEFINE_METALLICGLOSSTEXTURE);
- }else {
- this._defineDatas.remove(laya.d3.core.material.PBRStandardMaterial.SHADERDEFINE_METALLICGLOSSTEXTURE);
- }
- this._shaderValues.setTexture(PBRStandardMaterial.METALLICGLOSSTEXTURE,value);
- });
- /**
- *设置放射颜色A分量。
- *@param value 放射颜色A分量。
- */
- /**
- *获取放射颜色A分量。
- *@return 放射颜色A分量。
- */
- __getset(0,__proto,'emissionColorA',function(){
- return this._EmissionColorA;
- },function(value){
- this._EmissionColorA=value;
- });
- /**
- *设置光滑度。
- *@param value 光滑度,范围为0到1。
- */
- /**
- *获取光滑度。
- *@return 光滑度,范围为0到1。
- */
- __getset(0,__proto,'smoothness',function(){
- return this._Glossiness;
- },function(value){
- this._Glossiness=Math.max(0.0,Math.min(1.0,value));
- });
- /**
- *设置混合目标。
- *@param value 混合目标
- */
- /**
- *获取混合目标。
- *@return 混合目标。
- */
- __getset(0,__proto,'blendDst',function(){
- return this._shaderValues.getInt(PBRStandardMaterial.BLEND_DST);
- },function(value){
- this._shaderValues.setInt(PBRStandardMaterial.BLEND_DST,value);
- });
- /**
- *设置光滑度缩放系数。
- *@param value 光滑度缩放系数,范围为0到1。
- */
- /**
- *获取光滑度缩放系数。
- *@return 光滑度缩放系数,范围为0到1。
- */
- __getset(0,__proto,'smoothnessTextureScale',function(){
- return this._GlossMapScale;
- },function(value){
- this._GlossMapScale=Math.max(0.0,Math.min(1.0,value));
- });
- /**
- *设置是否写入深度。
- *@param value 是否写入深度。
- */
- /**
- *获取是否写入深度。
- *@return 是否写入深度。
- */
- __getset(0,__proto,'depthWrite',function(){
- return this._shaderValues.getBool(PBRStandardMaterial.DEPTH_WRITE);
- },function(value){
- this._shaderValues.setBool(PBRStandardMaterial.DEPTH_WRITE,value);
- });
- /**
- *设置光滑度数据源。
- *@param value 光滑滑度数据源,0或1。
- */
- /**
- *获取光滑度数据源
- *@return 光滑滑度数据源,0或1。
- */
- __getset(0,__proto,'smoothnessSource',function(){
- return this._shaderValues.getInt(PBRStandardMaterial.SMOOTHNESSSOURCE);
- },function(value){
- if (value){
- this._defineDatas.add(laya.d3.core.material.PBRStandardMaterial.SHADERDEFINE_SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA);
- this._shaderValues.setInt(PBRStandardMaterial.SMOOTHNESSSOURCE,1);
- }else {
- this._defineDatas.remove(laya.d3.core.material.PBRStandardMaterial.SHADERDEFINE_SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA);
- this._shaderValues.setInt(PBRStandardMaterial.SMOOTHNESSSOURCE,0);
- }
- });
- /**
- *设置放射颜色R分量。
- *@param value 放射颜色R分量。
- */
- /**
- *获取放射颜色R分量。
- *@return 放射颜色R分量。
- */
- __getset(0,__proto,'emissionColorR',function(){
- return this._EmissionColorR;
- },function(value){
- this._EmissionColorR=value;
- });
- /**
- *设置放射颜色G分量。
- *@param value 放射颜色G分量。
- */
- /**
- *获取放射颜色G分量。
- *@return 放射颜色G分量。
- */
- __getset(0,__proto,'emissionColorG',function(){
- return this._EmissionColorG;
- },function(value){
- this._EmissionColorG=value;
- });
- /**
- *设置放射颜色B分量。
- *@param value 放射颜色B分量。
- */
- /**
- *获取放射颜色B分量。
- *@return 放射颜色B分量。
- */
- __getset(0,__proto,'emissionColorB',function(){
- return this._EmissionColorB;
- },function(value){
- this._EmissionColorB=value;
- });
- /**
- *设置放射贴图。
- *@param value 放射贴图。
- */
- /**
- *获取放射贴图。
- *@return 放射贴图。
- */
- __getset(0,__proto,'emissionTexture',function(){
- return this._shaderValues.getTexture(PBRStandardMaterial.EMISSIONTEXTURE);
- },function(value){
- if (value){
- this._defineDatas.add(laya.d3.core.material.PBRStandardMaterial.SHADERDEFINE_EMISSIONTEXTURE);
- }else {
- this._defineDatas.remove(laya.d3.core.material.PBRStandardMaterial.SHADERDEFINE_EMISSIONTEXTURE);
- }
- this._shaderValues.setTexture(PBRStandardMaterial.EMISSIONTEXTURE,value);
- });
- /**
- *获取纹理平铺和偏移Y分量。
- *@param y 纹理平铺和偏移Y分量。
- */
- /**
- *获取纹理平铺和偏移Y分量。
- *@return 纹理平铺和偏移Y分量。
- */
- __getset(0,__proto,'tilingOffsetY',function(){
- return this._MainTex_STY;
- },function(y){
- this._MainTex_STY=y;
- });
- /**
- *设置渲染模式。
- *@return 渲染模式。
- */
- __getset(0,__proto,'renderMode',null,function(value){
- switch (value){
- case 0:
- this.alphaTest=false;
- this.renderQueue=/*laya.d3.core.material.BaseMaterial.RENDERQUEUE_OPAQUE*/2000;
- this.depthWrite=true;
- this.cull=/*laya.d3.core.material.RenderState.CULL_BACK*/2;
- this.blend=/*laya.d3.core.material.RenderState.BLEND_DISABLE*/0;
- this.depthTest=/*laya.d3.core.material.RenderState.DEPTHTEST_LESS*/0x0201;
- this._defineDatas.remove(PBRStandardMaterial.SHADERDEFINE_ALPHAPREMULTIPLY);
- break ;
- case 1:
- this.renderQueue=/*laya.d3.core.material.BaseMaterial.RENDERQUEUE_ALPHATEST*/2450;
- this.alphaTest=true;
- this.depthWrite=true;
- this.cull=/*laya.d3.core.material.RenderState.CULL_BACK*/2;
- this.blend=/*laya.d3.core.material.RenderState.BLEND_DISABLE*/0;
- this.depthTest=/*laya.d3.core.material.RenderState.DEPTHTEST_LESS*/0x0201;
- this._defineDatas.remove(PBRStandardMaterial.SHADERDEFINE_ALPHAPREMULTIPLY);
- break ;
- case 2:
- this.renderQueue=/*laya.d3.core.material.BaseMaterial.RENDERQUEUE_TRANSPARENT*/3000;
- this.alphaTest=false;
- this.depthWrite=false;
- this.cull=/*laya.d3.core.material.RenderState.CULL_BACK*/2;
- this.blend=/*laya.d3.core.material.RenderState.BLEND_ENABLE_ALL*/1;
- this.blendSrc=/*laya.d3.core.material.RenderState.BLENDPARAM_SRC_ALPHA*/0x0302;
- this.blendDst=/*laya.d3.core.material.RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA*/0x0303;
- this.depthTest=/*laya.d3.core.material.RenderState.DEPTHTEST_LESS*/0x0201;
- this._defineDatas.remove(PBRStandardMaterial.SHADERDEFINE_ALPHAPREMULTIPLY);
- break ;
- break ;
- case 3:
- this.renderQueue=/*laya.d3.core.material.BaseMaterial.RENDERQUEUE_TRANSPARENT*/3000;
- this.alphaTest=false;
- this.depthWrite=false;
- this.cull=/*laya.d3.core.material.RenderState.CULL_BACK*/2;
- this.blend=/*laya.d3.core.material.RenderState.BLEND_ENABLE_ALL*/1;
- this.blendSrc=/*laya.d3.core.material.RenderState.BLENDPARAM_ONE*/1;
- this.blendDst=/*laya.d3.core.material.RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA*/0x0303;
- this.depthTest=/*laya.d3.core.material.RenderState.DEPTHTEST_LESS*/0x0201;
- this._defineDatas.add(PBRStandardMaterial.SHADERDEFINE_ALPHAPREMULTIPLY);
- break ;
- default :
- throw new Error("PBRSpecularMaterial : renderMode value error.");
- }
- });
- /**
- *设置混合方式。
- *@param value 混合方式。
- */
- /**
- *获取混合方式。
- *@return 混合方式。
- */
- __getset(0,__proto,'blend',function(){
- return this._shaderValues.getInt(PBRStandardMaterial.BLEND);
- },function(value){
- this._shaderValues.setInt(PBRStandardMaterial.BLEND,value);
- });
- /**
- *设置深度测试方式。
- *@param value 深度测试方式
- */
- /**
- *获取深度测试方式。
- *@return 深度测试方式。
- */
- __getset(0,__proto,'depthTest',function(){
- return this._shaderValues.getInt(PBRStandardMaterial.DEPTH_TEST);
- },function(value){
- this._shaderValues.setInt(PBRStandardMaterial.DEPTH_TEST,value);
- });
- PBRStandardMaterial.__init__=function(){
- PBRStandardMaterial.SHADERDEFINE_ALBEDOTEXTURE=PBRStandardMaterial.shaderDefines.registerDefine("ALBEDOTEXTURE");
- PBRStandardMaterial.SHADERDEFINE_METALLICGLOSSTEXTURE=PBRStandardMaterial.shaderDefines.registerDefine("METALLICGLOSSTEXTURE");
- PBRStandardMaterial.SHADERDEFINE_SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA=PBRStandardMaterial.shaderDefines.registerDefine("SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA");
- PBRStandardMaterial.SHADERDEFINE_NORMALTEXTURE=PBRStandardMaterial.shaderDefines.registerDefine("NORMALTEXTURE");
- PBRStandardMaterial.SHADERDEFINE_PARALLAXTEXTURE=PBRStandardMaterial.shaderDefines.registerDefine("PARALLAXTEXTURE");
- PBRStandardMaterial.SHADERDEFINE_OCCLUSIONTEXTURE=PBRStandardMaterial.shaderDefines.registerDefine("OCCLUSIONTEXTURE");
- PBRStandardMaterial.SHADERDEFINE_EMISSION=PBRStandardMaterial.shaderDefines.registerDefine("EMISSION");
- PBRStandardMaterial.SHADERDEFINE_EMISSIONTEXTURE=PBRStandardMaterial.shaderDefines.registerDefine("EMISSIONTEXTURE");
- PBRStandardMaterial.SHADERDEFINE_REFLECTMAP=PBRStandardMaterial.shaderDefines.registerDefine("REFLECTMAP");
- PBRStandardMaterial.SHADERDEFINE_TILINGOFFSET=PBRStandardMaterial.shaderDefines.registerDefine("TILINGOFFSET");
- PBRStandardMaterial.SHADERDEFINE_ALPHAPREMULTIPLY=PBRStandardMaterial.shaderDefines.registerDefine("ALPHAPREMULTIPLY");
- }
- PBRStandardMaterial.SmoothnessSource_MetallicGlossTexture_Alpha=0;
- PBRStandardMaterial.SmoothnessSource_AlbedoTexture_Alpha=1;
- PBRStandardMaterial.RENDERMODE_OPAQUE=0;
- PBRStandardMaterial.RENDERMODE_CUTOUT=1;
- PBRStandardMaterial.RENDERMODE_FADE=2;
- PBRStandardMaterial.RENDERMODE_TRANSPARENT=3;
- PBRStandardMaterial.SHADERDEFINE_ALBEDOTEXTURE=0;
- PBRStandardMaterial.SHADERDEFINE_NORMALTEXTURE=0;
- PBRStandardMaterial.SHADERDEFINE_SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA=0;
- PBRStandardMaterial.SHADERDEFINE_METALLICGLOSSTEXTURE=0;
- PBRStandardMaterial.SHADERDEFINE_OCCLUSIONTEXTURE=0;
- PBRStandardMaterial.SHADERDEFINE_PARALLAXTEXTURE=0;
- PBRStandardMaterial.SHADERDEFINE_EMISSION=0;
- PBRStandardMaterial.SHADERDEFINE_EMISSIONTEXTURE=0;
- PBRStandardMaterial.SHADERDEFINE_REFLECTMAP=0;
- PBRStandardMaterial.SHADERDEFINE_TILINGOFFSET=0;
- PBRStandardMaterial.SHADERDEFINE_ALPHAPREMULTIPLY=0;
- PBRStandardMaterial.SMOOTHNESSSOURCE=-1;
- PBRStandardMaterial.ENABLEEMISSION=-1;
- PBRStandardMaterial.ENABLEREFLECT=-1;
- __static(PBRStandardMaterial,
- ['ALBEDOTEXTURE',function(){return this.ALBEDOTEXTURE=Shader3D.propertyNameToID("u_AlbedoTexture");},'METALLICGLOSSTEXTURE',function(){return this.METALLICGLOSSTEXTURE=Shader3D.propertyNameToID("u_MetallicGlossTexture");},'NORMALTEXTURE',function(){return this.NORMALTEXTURE=Shader3D.propertyNameToID("u_NormalTexture");},'PARALLAXTEXTURE',function(){return this.PARALLAXTEXTURE=Shader3D.propertyNameToID("u_ParallaxTexture");},'OCCLUSIONTEXTURE',function(){return this.OCCLUSIONTEXTURE=Shader3D.propertyNameToID("u_OcclusionTexture");},'EMISSIONTEXTURE',function(){return this.EMISSIONTEXTURE=Shader3D.propertyNameToID("u_EmissionTexture");},'ALBEDOCOLOR',function(){return this.ALBEDOCOLOR=Shader3D.propertyNameToID("u_AlbedoColor");},'EMISSIONCOLOR',function(){return this.EMISSIONCOLOR=Shader3D.propertyNameToID("u_EmissionColor");},'METALLIC',function(){return this.METALLIC=Shader3D.propertyNameToID("u_metallic");},'SMOOTHNESS',function(){return this.SMOOTHNESS=Shader3D.propertyNameToID("u_smoothness");},'SMOOTHNESSSCALE',function(){return this.SMOOTHNESSSCALE=Shader3D.propertyNameToID("u_smoothnessScale");},'OCCLUSIONSTRENGTH',function(){return this.OCCLUSIONSTRENGTH=Shader3D.propertyNameToID("u_occlusionStrength");},'NORMALSCALE',function(){return this.NORMALSCALE=Shader3D.propertyNameToID("u_normalScale");},'PARALLAXSCALE',function(){return this.PARALLAXSCALE=Shader3D.propertyNameToID("u_parallaxScale");},'TILINGOFFSET',function(){return this.TILINGOFFSET=Shader3D.propertyNameToID("u_TilingOffset");},'CULL',function(){return this.CULL=Shader3D.propertyNameToID("s_Cull");},'BLEND',function(){return this.BLEND=Shader3D.propertyNameToID("s_Blend");},'BLEND_SRC',function(){return this.BLEND_SRC=Shader3D.propertyNameToID("s_BlendSrc");},'BLEND_DST',function(){return this.BLEND_DST=Shader3D.propertyNameToID("s_BlendDst");},'DEPTH_TEST',function(){return this.DEPTH_TEST=Shader3D.propertyNameToID("s_DepthTest");},'DEPTH_WRITE',function(){return this.DEPTH_WRITE=Shader3D.propertyNameToID("s_DepthWrite");},'defaultMaterial',function(){return this.defaultMaterial=new PBRStandardMaterial();},'shaderDefines',function(){return this.shaderDefines=new ShaderDefines(BaseMaterial.shaderDefines);}
- ]);
- return PBRStandardMaterial;
- })(BaseMaterial)
- /**
- *<code>ShurikenParticleMaterial</code> 类用于实现粒子材质。
- */
- //class laya.d3.core.particleShuriKen.ShurikenParticleMaterial extends laya.d3.core.material.BaseMaterial
- var ShurikenParticleMaterial=(function(_super){
- function ShurikenParticleMaterial(){
- /**@private */
- //this._color=null;
- ShurikenParticleMaterial.__super.call(this);
- this.setShaderName("PARTICLESHURIKEN");
- this._color=new Vector4(1.0,1.0,1.0,1.0);
- this.renderMode=0;
- }
- __class(ShurikenParticleMaterial,'laya.d3.core.particleShuriKen.ShurikenParticleMaterial',_super);
- var __proto=ShurikenParticleMaterial.prototype;
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_TintColorB',function(){
- return this._color.z;
- },function(value){
- this._color.z=value;
- this.color=this._color;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_MainTex_STZ',function(){
- return this._shaderValues.getVector(ShurikenParticleMaterial.TILINGOFFSET).z;
- },function(z){
- var tilOff=this._shaderValues.getVector(ShurikenParticleMaterial.TILINGOFFSET);
- tilOff.z=z;
- this.tilingOffset=tilOff;
- });
- /**
- *设置漫反射贴图。
- *@param value 漫反射贴图。
- */
- /**
- *获取漫反射贴图。
- *@return 漫反射贴图。
- */
- __getset(0,__proto,'texture',function(){
- return this._shaderValues.getTexture(ShurikenParticleMaterial.DIFFUSETEXTURE);
- },function(value){
- if (value)
- this._defineDatas.add(laya.d3.core.particleShuriKen.ShurikenParticleMaterial.SHADERDEFINE_DIFFUSEMAP);
- else
- this._defineDatas.remove(laya.d3.core.particleShuriKen.ShurikenParticleMaterial.SHADERDEFINE_DIFFUSEMAP);
- this._shaderValues.setTexture(ShurikenParticleMaterial.DIFFUSETEXTURE,value);
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_TintColorR',function(){
- return this._color.x;
- },function(value){
- this._color.x=value;
- this.color=this._color;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_MainTex_STW',function(){
- return this._shaderValues.getVector(ShurikenParticleMaterial.TILINGOFFSET).w;
- },function(w){
- var tilOff=this._shaderValues.getVector(ShurikenParticleMaterial.TILINGOFFSET);
- tilOff.w=w;
- this.tilingOffset=tilOff;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_TintColorG',function(){
- return this._color.y;
- },function(value){
- this._color.y=value;
- this.color=this._color;
- });
- /**
- *@private
- */
- /**@private */
- __getset(0,__proto,'_TintColorA',function(){
- return this._color.w;
- },function(value){
- this._color.w=value;
- this.color=this._color;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_MainTex_STY',function(){
- return this._shaderValues.getVector(ShurikenParticleMaterial.TILINGOFFSET).y;
- },function(y){
- var tilOff=this._shaderValues.getVector(ShurikenParticleMaterial.TILINGOFFSET);
- tilOff.y=y;
- this.tilingOffset=tilOff;
- });
- /**
- *设置渲染模式。
- *@return 渲染模式。
- */
- __getset(0,__proto,'renderMode',null,function(value){
- switch (value){
- case 1:
- this.renderQueue=/*laya.d3.core.material.BaseMaterial.RENDERQUEUE_TRANSPARENT*/3000;
- this.depthWrite=false;
- this.cull=/*laya.d3.core.material.RenderState.CULL_NONE*/0;
- this.blend=/*laya.d3.core.material.RenderState.BLEND_ENABLE_ALL*/1;
- this.blendSrc=/*laya.d3.core.material.RenderState.BLENDPARAM_SRC_ALPHA*/0x0302;
- this.blendDst=/*laya.d3.core.material.RenderState.BLENDPARAM_ONE*/1;
- this.alphaTest=false;
- this._defineDatas.add(ShurikenParticleMaterial.SHADERDEFINE_ADDTIVEFOG);
- break ;
- case 0:
- this.renderQueue=/*laya.d3.core.material.BaseMaterial.RENDERQUEUE_TRANSPARENT*/3000;
- this.depthWrite=false;
- this.cull=/*laya.d3.core.material.RenderState.CULL_NONE*/0;
- this.blend=/*laya.d3.core.material.RenderState.BLEND_ENABLE_ALL*/1;
- this.blendSrc=/*laya.d3.core.material.RenderState.BLENDPARAM_SRC_ALPHA*/0x0302;
- this.blendDst=/*laya.d3.core.material.RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA*/0x0303;
- this.alphaTest=false;
- this._defineDatas.remove(ShurikenParticleMaterial.SHADERDEFINE_ADDTIVEFOG);
- break ;
- default :
- throw new Error("ShurikenParticleMaterial : renderMode value error.");
- }
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_MainTex_STX',function(){
- return this._shaderValues.getVector(ShurikenParticleMaterial.TILINGOFFSET).x;
- },function(x){
- var tilOff=this._shaderValues.getVector(ShurikenParticleMaterial.TILINGOFFSET);
- tilOff.x=x;
- this.tilingOffset=tilOff;
- });
- /**
- *设置颜色R分量。
- *@param value 颜色R分量。
- */
- /**
- *获取颜色R分量。
- *@return 颜色R分量。
- */
- __getset(0,__proto,'colorR',function(){
- return this._TintColorR;
- },function(value){
- this._TintColorR=value;
- });
- /**
- *设置颜色G分量。
- *@param value 颜色G分量。
- */
- /**
- *获取颜色G分量。
- *@return 颜色G分量。
- */
- __getset(0,__proto,'colorG',function(){
- return this._TintColorG;
- },function(value){
- this._TintColorG=value;
- });
- /**
- *设置颜色B分量。
- *@param value 颜色B分量。
- */
- /**
- *获取颜色B分量。
- *@return 颜色B分量。
- */
- __getset(0,__proto,'colorB',function(){
- return this._TintColorB;
- },function(value){
- this._TintColorB=value;
- });
- /**
- *设置颜色alpha分量。
- *@param value 颜色alpha分量。
- */
- /**
- *获取颜色Z分量。
- *@return 颜色Z分量。
- */
- __getset(0,__proto,'colorA',function(){
- return this._TintColorA;
- },function(value){
- this._TintColorA=value;
- });
- /**
- *设置混合方式。
- *@param value 混合方式。
- */
- /**
- *获取混合方式。
- *@return 混合方式。
- */
- __getset(0,__proto,'blend',function(){
- return this._shaderValues.getInt(ShurikenParticleMaterial.BLEND);
- },function(value){
- this._shaderValues.setInt(ShurikenParticleMaterial.BLEND,value);
- });
- /**
- *设置颜色。
- *@param value 颜色。
- */
- /**
- *获取颜色。
- *@return 颜色。
- */
- __getset(0,__proto,'color',function(){
- return this._shaderValues.getVector(ShurikenParticleMaterial.TINTCOLOR);
- },function(value){
- if (value)
- this._defineDatas.add(laya.d3.core.particleShuriKen.ShurikenParticleMaterial.SHADERDEFINE_TINTCOLOR);
- else
- this._defineDatas.remove(laya.d3.core.particleShuriKen.ShurikenParticleMaterial.SHADERDEFINE_TINTCOLOR);
- this._shaderValues.setVector(ShurikenParticleMaterial.TINTCOLOR,value);
- });
- /**
- *获取纹理平铺和偏移X分量。
- *@param x 纹理平铺和偏移X分量。
- */
- /**
- *获取纹理平铺和偏移X分量。
- *@return 纹理平铺和偏移X分量。
- */
- __getset(0,__proto,'tilingOffsetX',function(){
- return this._MainTex_STX;
- },function(x){
- this._MainTex_STX=x;
- });
- /**
- *获取纹理平铺和偏移Y分量。
- *@param y 纹理平铺和偏移Y分量。
- */
- /**
- *获取纹理平铺和偏移Y分量。
- *@return 纹理平铺和偏移Y分量。
- */
- __getset(0,__proto,'tilingOffsetY',function(){
- return this._MainTex_STY;
- },function(y){
- this._MainTex_STY=y;
- });
- /**
- *获取纹理平铺和偏移Z分量。
- *@param z 纹理平铺和偏移Z分量。
- */
- /**
- *获取纹理平铺和偏移Z分量。
- *@return 纹理平铺和偏移Z分量。
- */
- __getset(0,__proto,'tilingOffsetZ',function(){
- return this._MainTex_STZ;
- },function(z){
- this._MainTex_STZ=z;
- });
- /**
- *设置混合源。
- *@param value 混合源
- */
- /**
- *获取混合源。
- *@return 混合源。
- */
- __getset(0,__proto,'blendSrc',function(){
- return this._shaderValues.getInt(ShurikenParticleMaterial.BLEND_SRC);
- },function(value){
- this._shaderValues.setInt(ShurikenParticleMaterial.BLEND_SRC,value);
- });
- /**
- *获取纹理平铺和偏移W分量。
- *@param w 纹理平铺和偏移W分量。
- */
- /**
- *获取纹理平铺和偏移W分量。
- *@return 纹理平铺和偏移W分量。
- */
- __getset(0,__proto,'tilingOffsetW',function(){
- return this._MainTex_STW;
- },function(w){
- this._MainTex_STW=w;
- });
- /**
- *获取纹理平铺和偏移。
- *@param value 纹理平铺和偏移。
- */
- /**
- *获取纹理平铺和偏移。
- *@return 纹理平铺和偏移。
- */
- __getset(0,__proto,'tilingOffset',function(){
- return this._shaderValues.getVector(ShurikenParticleMaterial.TILINGOFFSET);
- },function(value){
- if (value){
- if (value.x !=1 || value.y !=1 || value.z !=0 || value.w !=0)
- this._defineDatas.add(laya.d3.core.particleShuriKen.ShurikenParticleMaterial.SHADERDEFINE_TILINGOFFSET);
- else
- this._defineDatas.remove(laya.d3.core.particleShuriKen.ShurikenParticleMaterial.SHADERDEFINE_TILINGOFFSET);
- }else {
- this._defineDatas.remove(laya.d3.core.particleShuriKen.ShurikenParticleMaterial.SHADERDEFINE_TILINGOFFSET);
- }
- this._shaderValues.setVector(ShurikenParticleMaterial.TILINGOFFSET,value);
- });
- /**
- *设置是否写入深度。
- *@param value 是否写入深度。
- */
- /**
- *获取是否写入深度。
- *@return 是否写入深度。
- */
- __getset(0,__proto,'depthWrite',function(){
- return this._shaderValues.getBool(ShurikenParticleMaterial.DEPTH_WRITE);
- },function(value){
- this._shaderValues.setBool(ShurikenParticleMaterial.DEPTH_WRITE,value);
- });
- /**
- *设置剔除方式。
- *@param value 剔除方式。
- */
- /**
- *获取剔除方式。
- *@return 剔除方式。
- */
- __getset(0,__proto,'cull',function(){
- return this._shaderValues.getInt(ShurikenParticleMaterial.CULL);
- },function(value){
- this._shaderValues.setInt(ShurikenParticleMaterial.CULL,value);
- });
- /**
- *设置混合目标。
- *@param value 混合目标
- */
- /**
- *获取混合目标。
- *@return 混合目标。
- */
- __getset(0,__proto,'blendDst',function(){
- return this._shaderValues.getInt(ShurikenParticleMaterial.BLEND_DST);
- },function(value){
- this._shaderValues.setInt(ShurikenParticleMaterial.BLEND_DST,value);
- });
- /**
- *设置深度测试方式。
- *@param value 深度测试方式
- */
- /**
- *获取深度测试方式。
- *@return 深度测试方式。
- */
- __getset(0,__proto,'depthTest',function(){
- return this._shaderValues.getInt(ShurikenParticleMaterial.DEPTH_TEST);
- },function(value){
- this._shaderValues.setInt(ShurikenParticleMaterial.DEPTH_TEST,value);
- });
- ShurikenParticleMaterial.__init__=function(){
- ShurikenParticleMaterial.SHADERDEFINE_DIFFUSEMAP=ShurikenParticleMaterial.shaderDefines.registerDefine("DIFFUSEMAP");
- ShurikenParticleMaterial.SHADERDEFINE_TINTCOLOR=ShurikenParticleMaterial.shaderDefines.registerDefine("TINTCOLOR");
- ShurikenParticleMaterial.SHADERDEFINE_ADDTIVEFOG=ShurikenParticleMaterial.shaderDefines.registerDefine("ADDTIVEFOG");
- ShurikenParticleMaterial.SHADERDEFINE_TILINGOFFSET=ShurikenParticleMaterial.shaderDefines.registerDefine("TILINGOFFSET");
- }
- ShurikenParticleMaterial.RENDERMODE_ALPHABLENDED=0;
- ShurikenParticleMaterial.RENDERMODE_ADDTIVE=1;
- ShurikenParticleMaterial.SHADERDEFINE_DIFFUSEMAP=0;
- ShurikenParticleMaterial.SHADERDEFINE_TINTCOLOR=0;
- ShurikenParticleMaterial.SHADERDEFINE_TILINGOFFSET=0;
- ShurikenParticleMaterial.SHADERDEFINE_ADDTIVEFOG=0;
- __static(ShurikenParticleMaterial,
- ['DIFFUSETEXTURE',function(){return this.DIFFUSETEXTURE=Shader3D.propertyNameToID("u_texture");},'TINTCOLOR',function(){return this.TINTCOLOR=Shader3D.propertyNameToID("u_Tintcolor");},'TILINGOFFSET',function(){return this.TILINGOFFSET=Shader3D.propertyNameToID("u_TilingOffset");},'CULL',function(){return this.CULL=Shader3D.propertyNameToID("s_Cull");},'BLEND',function(){return this.BLEND=Shader3D.propertyNameToID("s_Blend");},'BLEND_SRC',function(){return this.BLEND_SRC=Shader3D.propertyNameToID("s_BlendSrc");},'BLEND_DST',function(){return this.BLEND_DST=Shader3D.propertyNameToID("s_BlendDst");},'DEPTH_TEST',function(){return this.DEPTH_TEST=Shader3D.propertyNameToID("s_DepthTest");},'DEPTH_WRITE',function(){return this.DEPTH_WRITE=Shader3D.propertyNameToID("s_DepthWrite");},'defaultMaterial',function(){return this.defaultMaterial=new ShurikenParticleMaterial();},'shaderDefines',function(){return this.shaderDefines=new ShaderDefines(BaseMaterial.shaderDefines);}
- ]);
- return ShurikenParticleMaterial;
- })(BaseMaterial)
- /**
- *<code>EffectMaterial</code> 类用于实现Mesh特效材质。
- */
- //class laya.d3.core.material.EffectMaterial extends laya.d3.core.material.BaseMaterial
- var EffectMaterial=(function(_super){
- function EffectMaterial(){
- /**@private */
- this._color=null;
- EffectMaterial.__super.call(this);
- this.setShaderName("Effect");
- this._color=new Vector4(1.0,1.0,1.0,1.0);
- this._shaderValues.setVector(EffectMaterial.TINTCOLOR,new Vector4(1.0,1.0,1.0,1.0));
- this.renderMode=0;
- }
- __class(EffectMaterial,'laya.d3.core.material.EffectMaterial',_super);
- var __proto=EffectMaterial.prototype;
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_TintColorB',function(){
- return this._color.z;
- },function(value){
- this._color.z=value;
- this.color=this._color;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_MainTex_STZ',function(){
- return this._shaderValues.getVector(EffectMaterial.TILINGOFFSET).z;
- },function(z){
- var tilOff=this._shaderValues.getVector(EffectMaterial.TILINGOFFSET);
- tilOff.z=z;
- this.tilingOffset=tilOff;
- });
- /**
- *设置贴图。
- *@param value 贴图。
- */
- /**
- *获取贴图。
- *@return 贴图。
- */
- __getset(0,__proto,'texture',function(){
- return this._shaderValues.getTexture(EffectMaterial.MAINTEXTURE);
- },function(value){
- if (value)
- this._defineDatas.add(laya.d3.core.material.EffectMaterial.SHADERDEFINE_MAINTEXTURE);
- else
- this._defineDatas.remove(laya.d3.core.material.EffectMaterial.SHADERDEFINE_MAINTEXTURE);
- this._shaderValues.setTexture(EffectMaterial.MAINTEXTURE,value);
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_TintColorR',function(){
- return this._color.x;
- },function(value){
- this._color.x=value;
- this.color=this._color;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_MainTex_STW',function(){
- return this._shaderValues.getVector(EffectMaterial.TILINGOFFSET).w;
- },function(w){
- var tilOff=this._shaderValues.getVector(EffectMaterial.TILINGOFFSET);
- tilOff.w=w;
- this.tilingOffset=tilOff;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_TintColorG',function(){
- return this._color.y;
- },function(value){
- this._color.y=value;
- this.color=this._color;
- });
- /**
- *@private
- */
- /**@private */
- __getset(0,__proto,'_TintColorA',function(){
- return this._color.w;
- },function(value){
- this._color.w=value;
- this.color=this._color;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_MainTex_STY',function(){
- return this._shaderValues.getVector(EffectMaterial.TILINGOFFSET).y;
- },function(y){
- var tilOff=this._shaderValues.getVector(EffectMaterial.TILINGOFFSET);
- tilOff.y=y;
- this.tilingOffset=tilOff;
- });
- /**
- *设置渲染模式。
- *@return 渲染模式。
- */
- __getset(0,__proto,'renderMode',null,function(value){
- switch (value){
- case 0:
- this.renderQueue=/*laya.d3.core.material.BaseMaterial.RENDERQUEUE_TRANSPARENT*/3000;
- this.alphaTest=false;
- this.depthWrite=false;
- this.cull=/*laya.d3.core.material.RenderState.CULL_NONE*/0;
- this.blend=/*laya.d3.core.material.RenderState.BLEND_ENABLE_ALL*/1;
- this.blendSrc=/*laya.d3.core.material.RenderState.BLENDPARAM_SRC_ALPHA*/0x0302;
- this.blendDst=/*laya.d3.core.material.RenderState.BLENDPARAM_ONE*/1;
- this.depthTest=/*laya.d3.core.material.RenderState.DEPTHTEST_LESS*/0x0201;
- this._defineDatas.add(EffectMaterial.SHADERDEFINE_ADDTIVEFOG);
- break ;
- case 1:
- this.renderQueue=/*laya.d3.core.material.BaseMaterial.RENDERQUEUE_TRANSPARENT*/3000;
- this.alphaTest=false;
- this.depthWrite=false;
- this.cull=/*laya.d3.core.material.RenderState.CULL_NONE*/0;
- this.blend=/*laya.d3.core.material.RenderState.BLEND_ENABLE_ALL*/1;
- this.blendSrc=/*laya.d3.core.material.RenderState.BLENDPARAM_SRC_ALPHA*/0x0302;
- this.blendDst=/*laya.d3.core.material.RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA*/0x0303;
- this.depthTest=/*laya.d3.core.material.RenderState.DEPTHTEST_LESS*/0x0201;
- this._defineDatas.remove(EffectMaterial.SHADERDEFINE_ADDTIVEFOG);
- break ;
- default :
- throw new Error("MeshEffectMaterial : renderMode value error.");
- }
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_MainTex_STX',function(){
- return this._shaderValues.getVector(EffectMaterial.TILINGOFFSET).x;
- },function(x){
- var tilOff=this._shaderValues.getVector(EffectMaterial.TILINGOFFSET);
- tilOff.x=x;
- this.tilingOffset=tilOff;
- });
- /**
- *设置颜色R分量。
- *@param value 颜色R分量。
- */
- /**
- *获取颜色R分量。
- *@return 颜色R分量。
- */
- __getset(0,__proto,'colorR',function(){
- return this._TintColorR;
- },function(value){
- this._TintColorR=value;
- });
- /**
- *设置颜色G分量。
- *@param value 颜色G分量。
- */
- /**
- *获取颜色G分量。
- *@return 颜色G分量。
- */
- __getset(0,__proto,'colorG',function(){
- return this._TintColorG;
- },function(value){
- this._TintColorG=value;
- });
- /**
- *设置颜色B分量。
- *@param value 颜色B分量。
- */
- /**
- *获取颜色B分量。
- *@return 颜色B分量。
- */
- __getset(0,__proto,'colorB',function(){
- return this._TintColorB;
- },function(value){
- this._TintColorB=value;
- });
- /**
- *设置颜色alpha分量。
- *@param value 颜色alpha分量。
- */
- /**
- *获取颜色Z分量。
- *@return 颜色Z分量。
- */
- __getset(0,__proto,'colorA',function(){
- return this._TintColorA;
- },function(value){
- this._TintColorA=value;
- });
- /**
- *设置混合方式。
- *@param value 混合方式。
- */
- /**
- *获取混合方式。
- *@return 混合方式。
- */
- __getset(0,__proto,'blend',function(){
- return this._shaderValues.getInt(EffectMaterial.BLEND);
- },function(value){
- this._shaderValues.setInt(EffectMaterial.BLEND,value);
- });
- /**
- *设置颜色。
- *@param value 颜色。
- */
- /**
- *获取颜色。
- *@return 颜色。
- */
- __getset(0,__proto,'color',function(){
- return this._shaderValues.getVector(EffectMaterial.TINTCOLOR);
- },function(value){
- this._shaderValues.setVector(EffectMaterial.TINTCOLOR,value);
- });
- /**
- *获取纹理平铺和偏移X分量。
- *@param x 纹理平铺和偏移X分量。
- */
- /**
- *获取纹理平铺和偏移X分量。
- *@return 纹理平铺和偏移X分量。
- */
- __getset(0,__proto,'tilingOffsetX',function(){
- return this._MainTex_STX;
- },function(x){
- this._MainTex_STX=x;
- });
- /**
- *获取纹理平铺和偏移Y分量。
- *@param y 纹理平铺和偏移Y分量。
- */
- /**
- *获取纹理平铺和偏移Y分量。
- *@return 纹理平铺和偏移Y分量。
- */
- __getset(0,__proto,'tilingOffsetY',function(){
- return this._MainTex_STY;
- },function(y){
- this._MainTex_STY=y;
- });
- /**
- *获取纹理平铺和偏移Z分量。
- *@param z 纹理平铺和偏移Z分量。
- */
- /**
- *获取纹理平铺和偏移Z分量。
- *@return 纹理平铺和偏移Z分量。
- */
- __getset(0,__proto,'tilingOffsetZ',function(){
- return this._MainTex_STZ;
- },function(z){
- this._MainTex_STZ=z;
- });
- /**
- *设置混合源。
- *@param value 混合源
- */
- /**
- *获取混合源。
- *@return 混合源。
- */
- __getset(0,__proto,'blendSrc',function(){
- return this._shaderValues.getInt(EffectMaterial.BLEND_SRC);
- },function(value){
- this._shaderValues.setInt(EffectMaterial.BLEND_SRC,value);
- });
- /**
- *获取纹理平铺和偏移W分量。
- *@param w 纹理平铺和偏移W分量。
- */
- /**
- *获取纹理平铺和偏移W分量。
- *@return 纹理平铺和偏移W分量。
- */
- __getset(0,__proto,'tilingOffsetW',function(){
- return this._MainTex_STW;
- },function(w){
- this._MainTex_STW=w;
- });
- /**
- *设置纹理平铺和偏移。
- *@param value 纹理平铺和偏移。
- */
- /**
- *获取纹理平铺和偏移。
- *@return 纹理平铺和偏移。
- */
- __getset(0,__proto,'tilingOffset',function(){
- return this._shaderValues.getVector(EffectMaterial.TILINGOFFSET);
- },function(value){
- if (value){
- if (value.x !=1 || value.y !=1 || value.z !=0 || value.w !=0)
- this._defineDatas.add(laya.d3.core.material.EffectMaterial.SHADERDEFINE_TILINGOFFSET);
- else
- this._defineDatas.remove(laya.d3.core.material.EffectMaterial.SHADERDEFINE_TILINGOFFSET);
- }else {
- this._defineDatas.remove(laya.d3.core.material.EffectMaterial.SHADERDEFINE_TILINGOFFSET);
- }
- this._shaderValues.setVector(EffectMaterial.TILINGOFFSET,value);
- });
- /**
- *设置是否写入深度。
- *@param value 是否写入深度。
- */
- /**
- *获取是否写入深度。
- *@return 是否写入深度。
- */
- __getset(0,__proto,'depthWrite',function(){
- return this._shaderValues.getBool(EffectMaterial.DEPTH_WRITE);
- },function(value){
- this._shaderValues.setBool(EffectMaterial.DEPTH_WRITE,value);
- });
- /**
- *设置剔除方式。
- *@param value 剔除方式。
- */
- /**
- *获取剔除方式。
- *@return 剔除方式。
- */
- __getset(0,__proto,'cull',function(){
- return this._shaderValues.getInt(EffectMaterial.CULL);
- },function(value){
- this._shaderValues.setInt(EffectMaterial.CULL,value);
- });
- /**
- *设置混合目标。
- *@param value 混合目标
- */
- /**
- *获取混合目标。
- *@return 混合目标。
- */
- __getset(0,__proto,'blendDst',function(){
- return this._shaderValues.getInt(EffectMaterial.BLEND_DST);
- },function(value){
- this._shaderValues.setInt(EffectMaterial.BLEND_DST,value);
- });
- /**
- *设置深度测试方式。
- *@param value 深度测试方式
- */
- /**
- *获取深度测试方式。
- *@return 深度测试方式。
- */
- __getset(0,__proto,'depthTest',function(){
- return this._shaderValues.getInt(EffectMaterial.DEPTH_TEST);
- },function(value){
- this._shaderValues.setInt(EffectMaterial.DEPTH_TEST,value);
- });
- EffectMaterial.__init__=function(){
- EffectMaterial.SHADERDEFINE_MAINTEXTURE=EffectMaterial.shaderDefines.registerDefine("MAINTEXTURE");
- EffectMaterial.SHADERDEFINE_TILINGOFFSET=EffectMaterial.shaderDefines.registerDefine("TILINGOFFSET");
- EffectMaterial.SHADERDEFINE_ADDTIVEFOG=EffectMaterial.shaderDefines.registerDefine("ADDTIVEFOG");
- }
- EffectMaterial.RENDERMODE_ADDTIVE=0;
- EffectMaterial.RENDERMODE_ALPHABLENDED=1;
- EffectMaterial.SHADERDEFINE_MAINTEXTURE=0;
- EffectMaterial.SHADERDEFINE_TILINGOFFSET=0;
- EffectMaterial.SHADERDEFINE_ADDTIVEFOG=0;
- __static(EffectMaterial,
- ['defaultMaterial',function(){return this.defaultMaterial=new EffectMaterial();},'MAINTEXTURE',function(){return this.MAINTEXTURE=Shader3D.propertyNameToID("u_AlbedoTexture");},'TINTCOLOR',function(){return this.TINTCOLOR=Shader3D.propertyNameToID("u_AlbedoColor");},'TILINGOFFSET',function(){return this.TILINGOFFSET=Shader3D.propertyNameToID("u_TilingOffset");},'CULL',function(){return this.CULL=Shader3D.propertyNameToID("s_Cull");},'BLEND',function(){return this.BLEND=Shader3D.propertyNameToID("s_Blend");},'BLEND_SRC',function(){return this.BLEND_SRC=Shader3D.propertyNameToID("s_BlendSrc");},'BLEND_DST',function(){return this.BLEND_DST=Shader3D.propertyNameToID("s_BlendDst");},'DEPTH_TEST',function(){return this.DEPTH_TEST=Shader3D.propertyNameToID("s_DepthTest");},'DEPTH_WRITE',function(){return this.DEPTH_WRITE=Shader3D.propertyNameToID("s_DepthWrite");},'shaderDefines',function(){return this.shaderDefines=new ShaderDefines(BaseMaterial.shaderDefines);}
- ]);
- return EffectMaterial;
- })(BaseMaterial)
- /**
- *...
- *@author
- */
- //class laya.d3.core.material.WaterPrimaryMaterial extends laya.d3.core.material.BaseMaterial
- var WaterPrimaryMaterial=(function(_super){
- function WaterPrimaryMaterial(){
- WaterPrimaryMaterial.__super.call(this);
- this.setShaderName("WaterPrimary");
- this._shaderValues.setVector(WaterPrimaryMaterial.HORIZONCOLOR,new Vector4(0.172 ,0.463 ,0.435 ,0));
- this._shaderValues.setNumber(WaterPrimaryMaterial.WAVESCALE,0.15);
- this._shaderValues.setVector(WaterPrimaryMaterial.WAVESPEED,new Vector4(19,9,-16,-7));
- }
- __class(WaterPrimaryMaterial,'laya.d3.core.material.WaterPrimaryMaterial',_super);
- var __proto=WaterPrimaryMaterial.prototype;
- /**
- *设置波动速率。
- *@param value 波动速率。
- */
- /**
- *获取波动速率。
- *@return 波动速率。
- */
- __getset(0,__proto,'waveSpeed',function(){
- return this._shaderValues.getVector(WaterPrimaryMaterial.WAVESPEED);
- },function(value){
- this._shaderValues.setVector(WaterPrimaryMaterial.WAVESPEED,value);
- });
- /**
- *设置地平线颜色。
- *@param value 地平线颜色。
- */
- /**
- *获取地平线颜色。
- *@return 地平线颜色。
- */
- __getset(0,__proto,'horizonColor',function(){
- return this._shaderValues.getVector(WaterPrimaryMaterial.HORIZONCOLOR);
- },function(value){
- this._shaderValues.setVector(WaterPrimaryMaterial.HORIZONCOLOR,value);
- });
- /**
- *设置主贴图。
- *@param value 主贴图。
- */
- /**
- *获取主贴图。
- *@return 主贴图。
- */
- __getset(0,__proto,'mainTexture',function(){
- return this._shaderValues.getTexture(WaterPrimaryMaterial.MAINTEXTURE);
- },function(value){
- if (value)
- this._defineDatas.add(laya.d3.core.material.WaterPrimaryMaterial.SHADERDEFINE_MAINTEXTURE);
- else
- this._defineDatas.remove(laya.d3.core.material.WaterPrimaryMaterial.SHADERDEFINE_MAINTEXTURE);
- this._shaderValues.setTexture(WaterPrimaryMaterial.MAINTEXTURE,value);
- });
- /**
- *设置法线贴图。
- *@param value 法线贴图。
- */
- /**
- *获取法线贴图。
- *@return 法线贴图。
- */
- __getset(0,__proto,'normalTexture',function(){
- return this._shaderValues.getTexture(WaterPrimaryMaterial.NORMALTEXTURE);
- },function(value){
- if (value)
- this._defineDatas.add(laya.d3.core.material.WaterPrimaryMaterial.SHADERDEFINE_NORMALTEXTURE);
- else
- this._defineDatas.remove(laya.d3.core.material.WaterPrimaryMaterial.SHADERDEFINE_NORMALTEXTURE);
- this._shaderValues.setTexture(WaterPrimaryMaterial.NORMALTEXTURE,value);
- });
- /**
- *设置波动缩放系数。
- *@param value 波动缩放系数。
- */
- /**
- *获取波动缩放系数。
- *@return 波动缩放系数。
- */
- __getset(0,__proto,'waveScale',function(){
- return this._shaderValues.getNumber(WaterPrimaryMaterial.WAVESCALE);
- },function(value){
- this._shaderValues.setNumber(WaterPrimaryMaterial.WAVESCALE,value);
- });
- WaterPrimaryMaterial.__init__=function(){
- WaterPrimaryMaterial.SHADERDEFINE_MAINTEXTURE=WaterPrimaryMaterial.shaderDefines.registerDefine("MAINTEXTURE");
- WaterPrimaryMaterial.SHADERDEFINE_NORMALTEXTURE=WaterPrimaryMaterial.shaderDefines.registerDefine("NORMALTEXTURE");
- }
- WaterPrimaryMaterial.SHADERDEFINE_MAINTEXTURE=0;
- WaterPrimaryMaterial.SHADERDEFINE_NORMALTEXTURE=0;
- __static(WaterPrimaryMaterial,
- ['HORIZONCOLOR',function(){return this.HORIZONCOLOR=Shader3D.propertyNameToID("u_HorizonColor");},'MAINTEXTURE',function(){return this.MAINTEXTURE=Shader3D.propertyNameToID("u_MainTexture");},'NORMALTEXTURE',function(){return this.NORMALTEXTURE=Shader3D.propertyNameToID("u_NormalTexture");},'WAVESCALE',function(){return this.WAVESCALE=Shader3D.propertyNameToID("u_WaveScale");},'WAVESPEED',function(){return this.WAVESPEED=Shader3D.propertyNameToID("u_WaveSpeed");},'defaultMaterial',function(){return this.defaultMaterial=new WaterPrimaryMaterial();},'shaderDefines',function(){return this.shaderDefines=new ShaderDefines(BaseMaterial.shaderDefines);}
- ]);
- return WaterPrimaryMaterial;
- })(BaseMaterial)
- /**
- *...
- *@author ...
- */
- //class laya.d3.core.material.ExtendTerrainMaterial extends laya.d3.core.material.BaseMaterial
- var ExtendTerrainMaterial=(function(_super){
- function ExtendTerrainMaterial(){
- /**@private */
- this._enableLighting=true;
- ExtendTerrainMaterial.__super.call(this);
- this.setShaderName("ExtendTerrain");
- this.renderMode=1;
- }
- __class(ExtendTerrainMaterial,'laya.d3.core.material.ExtendTerrainMaterial',_super);
- var __proto=ExtendTerrainMaterial.prototype;
- __proto._setDetailNum=function(value){
- switch (value){
- case 1:
- this._defineDatas.add(laya.d3.core.material.ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM1);
- this._defineDatas.remove(laya.d3.core.material.ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM2);
- this._defineDatas.remove(laya.d3.core.material.ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM3);
- this._defineDatas.remove(laya.d3.core.material.ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM4);
- this._defineDatas.remove(laya.d3.core.material.ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM5);
- break ;
- case 2:
- this._defineDatas.add(laya.d3.core.material.ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM2);
- this._defineDatas.remove(laya.d3.core.material.ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM1);
- this._defineDatas.remove(laya.d3.core.material.ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM3);
- this._defineDatas.remove(laya.d3.core.material.ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM4);
- this._defineDatas.remove(laya.d3.core.material.ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM5);
- break ;
- case 3:
- this._defineDatas.add(laya.d3.core.material.ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM3);
- this._defineDatas.remove(laya.d3.core.material.ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM1);
- this._defineDatas.remove(laya.d3.core.material.ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM2);
- this._defineDatas.remove(laya.d3.core.material.ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM4);
- this._defineDatas.remove(laya.d3.core.material.ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM5);
- break ;
- case 4:
- this._defineDatas.add(laya.d3.core.material.ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM4);
- this._defineDatas.remove(laya.d3.core.material.ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM1);
- this._defineDatas.remove(laya.d3.core.material.ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM2);
- this._defineDatas.remove(laya.d3.core.material.ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM3);
- this._defineDatas.remove(laya.d3.core.material.ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM5);
- break ;
- case 5:
- this._defineDatas.add(laya.d3.core.material.ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM5);
- this._defineDatas.remove(laya.d3.core.material.ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM1);
- this._defineDatas.remove(laya.d3.core.material.ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM2);
- this._defineDatas.remove(laya.d3.core.material.ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM3);
- this._defineDatas.remove(laya.d3.core.material.ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM4);
- break ;
- }
- }
- __getset(0,__proto,'diffuseScaleOffset2',null,function(scaleOffset2){
- this._shaderValues.setVector(ExtendTerrainMaterial.DIFFUSESCALEOFFSET2,scaleOffset2);
- });
- /**
- *设置splatAlpha贴图。
- *@param value splatAlpha贴图。
- */
- /**
- *获取splatAlpha贴图。
- *@return splatAlpha贴图。
- */
- __getset(0,__proto,'splatAlphaTexture',function(){
- return this._shaderValues.getTexture(ExtendTerrainMaterial.SPLATALPHATEXTURE);
- },function(value){
- this._shaderValues.setTexture(ExtendTerrainMaterial.SPLATALPHATEXTURE,value);
- });
- __getset(0,__proto,'diffuseScaleOffset3',null,function(scaleOffset3){
- this._shaderValues.setVector(ExtendTerrainMaterial.DIFFUSESCALEOFFSET3,scaleOffset3);
- });
- /**
- *设置第一层贴图。
- *@param value 第一层贴图。
- */
- __getset(0,__proto,'diffuseTexture1',null,function(value){
- this._shaderValues.setTexture(ExtendTerrainMaterial.DIFFUSETEXTURE1,value);
- this._setDetailNum(1);
- });
- /**
- *设置渲染模式。
- *@return 渲染模式。
- */
- __getset(0,__proto,'renderMode',null,function(value){
- switch (value){
- case 1:
- this.renderQueue=/*laya.d3.core.material.BaseMaterial.RENDERQUEUE_OPAQUE*/2000;
- this.depthWrite=true;
- this.cull=/*laya.d3.core.material.RenderState.CULL_BACK*/2;
- this.blend=/*laya.d3.core.material.RenderState.BLEND_DISABLE*/0;
- this.depthTest=/*laya.d3.core.material.RenderState.DEPTHTEST_LESS*/0x0201;
- break ;
- case 2:
- this.renderQueue=/*laya.d3.core.material.BaseMaterial.RENDERQUEUE_OPAQUE*/2000;
- this.depthWrite=false;
- this.cull=/*laya.d3.core.material.RenderState.CULL_BACK*/2;
- this.blend=/*laya.d3.core.material.RenderState.BLEND_ENABLE_ALL*/1;
- this.blendSrc=/*laya.d3.core.material.RenderState.BLENDPARAM_SRC_ALPHA*/0x0302;
- this.blendDst=/*laya.d3.core.material.RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA*/0x0303;
- this.depthTest=/*laya.d3.core.material.RenderState.DEPTHTEST_LEQUAL*/0x0203;
- break ;
- default :
- throw new Error("ExtendTerrainMaterial:renderMode value error.");
- }
- });
- /**
- *设置第二层贴图。
- *@param value 第二层贴图。
- */
- /**
- *获取第二层贴图。
- *@return 第二层贴图。
- */
- __getset(0,__proto,'diffuseTexture2',function(){
- return this._shaderValues.getTexture(ExtendTerrainMaterial.DIFFUSETEXTURE2);
- },function(value){
- this._shaderValues.setTexture(ExtendTerrainMaterial.DIFFUSETEXTURE2,value);
- this._setDetailNum(2);
- });
- __getset(0,__proto,'diffuseScaleOffset1',null,function(scaleOffset1){
- this._shaderValues.setVector(ExtendTerrainMaterial.DIFFUSESCALEOFFSET1,scaleOffset1);
- });
- /**
- *设置第三层贴图。
- *@param value 第三层贴图。
- */
- /**
- *获取第三层贴图。
- *@return 第三层贴图。
- */
- __getset(0,__proto,'diffuseTexture3',function(){
- return this._shaderValues.getTexture(ExtendTerrainMaterial.DIFFUSETEXTURE3);
- },function(value){
- this._shaderValues.setTexture(ExtendTerrainMaterial.DIFFUSETEXTURE3,value);
- this._setDetailNum(3);
- });
- /**
- *设置第四层贴图。
- *@param value 第四层贴图。
- */
- /**
- *获取第四层贴图。
- *@return 第四层贴图。
- */
- __getset(0,__proto,'diffuseTexture4',function(){
- return this._shaderValues.getTexture(ExtendTerrainMaterial.DIFFUSETEXTURE4);
- },function(value){
- this._shaderValues.setTexture(ExtendTerrainMaterial.DIFFUSETEXTURE4,value);
- this._setDetailNum(4);
- });
- /**
- *设置第五层贴图。
- *@param value 第五层贴图。
- */
- /**
- *获取第五层贴图。
- *@return 第五层贴图。
- */
- __getset(0,__proto,'diffuseTexture5',function(){
- return this._shaderValues.getTexture(ExtendTerrainMaterial.DIFFUSETEXTURE5);
- },function(value){
- this._shaderValues.setTexture(ExtendTerrainMaterial.DIFFUSETEXTURE5,value);
- this._setDetailNum(5);
- });
- __getset(0,__proto,'diffuseScaleOffset4',null,function(scaleOffset4){
- this._shaderValues.setVector(ExtendTerrainMaterial.DIFFUSESCALEOFFSET4,scaleOffset4);
- });
- __getset(0,__proto,'diffuseScaleOffset5',null,function(scaleOffset5){
- this._shaderValues.setVector(ExtendTerrainMaterial.DIFFUSESCALEOFFSET5,scaleOffset5);
- });
- /**
- *设置混合源。
- *@param value 混合源
- */
- /**
- *获取混合源。
- *@return 混合源。
- */
- __getset(0,__proto,'blendSrc',function(){
- return this._shaderValues.getInt(ExtendTerrainMaterial.BLEND_SRC);
- },function(value){
- this._shaderValues.setInt(ExtendTerrainMaterial.BLEND_SRC,value);
- });
- /**
- *设置是否启用光照。
- *@param value 是否启用光照。
- */
- /**
- *获取是否启用光照。
- *@return 是否启用光照。
- */
- __getset(0,__proto,'enableLighting',function(){
- return this._enableLighting;
- },function(value){
- if (this._enableLighting!==value){
- if (value)
- this._disablePublicDefineDatas.remove(Scene3D.SHADERDEFINE_POINTLIGHT | Scene3D.SHADERDEFINE_SPOTLIGHT | Scene3D.SHADERDEFINE_DIRECTIONLIGHT);
- else
- this._disablePublicDefineDatas.add(Scene3D.SHADERDEFINE_POINTLIGHT | Scene3D.SHADERDEFINE_SPOTLIGHT | Scene3D.SHADERDEFINE_DIRECTIONLIGHT);
- this._enableLighting=value;
- }
- });
- /**
- *设置是否写入深度。
- *@param value 是否写入深度。
- */
- /**
- *获取是否写入深度。
- *@return 是否写入深度。
- */
- __getset(0,__proto,'depthWrite',function(){
- return this._shaderValues.getBool(ExtendTerrainMaterial.DEPTH_WRITE);
- },function(value){
- this._shaderValues.setBool(ExtendTerrainMaterial.DEPTH_WRITE,value);
- });
- /**
- *设置剔除方式。
- *@param value 剔除方式。
- */
- /**
- *获取剔除方式。
- *@return 剔除方式。
- */
- __getset(0,__proto,'cull',function(){
- return this._shaderValues.getInt(ExtendTerrainMaterial.CULL);
- },function(value){
- this._shaderValues.setInt(ExtendTerrainMaterial.CULL,value);
- });
- /**
- *设置混合方式。
- *@param value 混合方式。
- */
- /**
- *获取混合方式。
- *@return 混合方式。
- */
- __getset(0,__proto,'blend',function(){
- return this._shaderValues.getInt(ExtendTerrainMaterial.BLEND);
- },function(value){
- this._shaderValues.setInt(ExtendTerrainMaterial.BLEND,value);
- });
- /**
- *设置混合目标。
- *@param value 混合目标
- */
- /**
- *获取混合目标。
- *@return 混合目标。
- */
- __getset(0,__proto,'blendDst',function(){
- return this._shaderValues.getInt(ExtendTerrainMaterial.BLEND_DST);
- },function(value){
- this._shaderValues.setInt(ExtendTerrainMaterial.BLEND_DST,value);
- });
- /**
- *设置深度测试方式。
- *@param value 深度测试方式
- */
- /**
- *获取深度测试方式。
- *@return 深度测试方式。
- */
- __getset(0,__proto,'depthTest',function(){
- return this._shaderValues.getInt(ExtendTerrainMaterial.DEPTH_TEST);
- },function(value){
- this._shaderValues.setInt(ExtendTerrainMaterial.DEPTH_TEST,value);
- });
- ExtendTerrainMaterial.__init__=function(){
- ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM1=ExtendTerrainMaterial.shaderDefines.registerDefine("ExtendTerrain_DETAIL_NUM1");
- ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM2=ExtendTerrainMaterial.shaderDefines.registerDefine("ExtendTerrain_DETAIL_NUM2");
- ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM3=ExtendTerrainMaterial.shaderDefines.registerDefine("ExtendTerrain_DETAIL_NUM3");
- ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM4=ExtendTerrainMaterial.shaderDefines.registerDefine("ExtendTerrain_DETAIL_NUM4");
- ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM5=ExtendTerrainMaterial.shaderDefines.registerDefine("ExtendTerrain_DETAIL_NUM5");
- }
- ExtendTerrainMaterial.RENDERMODE_OPAQUE=1;
- ExtendTerrainMaterial.RENDERMODE_TRANSPARENT=2;
- ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM1=0;
- ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM2=0;
- ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM3=0;
- ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM4=0;
- ExtendTerrainMaterial.SHADERDEFINE_DETAIL_NUM5=0;
- __static(ExtendTerrainMaterial,
- ['SPLATALPHATEXTURE',function(){return this.SPLATALPHATEXTURE=Shader3D.propertyNameToID("u_SplatAlphaTexture");},'DIFFUSETEXTURE1',function(){return this.DIFFUSETEXTURE1=Shader3D.propertyNameToID("u_DiffuseTexture1");},'DIFFUSETEXTURE2',function(){return this.DIFFUSETEXTURE2=Shader3D.propertyNameToID("u_DiffuseTexture2");},'DIFFUSETEXTURE3',function(){return this.DIFFUSETEXTURE3=Shader3D.propertyNameToID("u_DiffuseTexture3");},'DIFFUSETEXTURE4',function(){return this.DIFFUSETEXTURE4=Shader3D.propertyNameToID("u_DiffuseTexture4");},'DIFFUSETEXTURE5',function(){return this.DIFFUSETEXTURE5=Shader3D.propertyNameToID("u_DiffuseTexture5");},'DIFFUSESCALEOFFSET1',function(){return this.DIFFUSESCALEOFFSET1=Shader3D.propertyNameToID("u_DiffuseScaleOffset1");},'DIFFUSESCALEOFFSET2',function(){return this.DIFFUSESCALEOFFSET2=Shader3D.propertyNameToID("u_DiffuseScaleOffset2");},'DIFFUSESCALEOFFSET3',function(){return this.DIFFUSESCALEOFFSET3=Shader3D.propertyNameToID("u_DiffuseScaleOffset3");},'DIFFUSESCALEOFFSET4',function(){return this.DIFFUSESCALEOFFSET4=Shader3D.propertyNameToID("u_DiffuseScaleOffset4");},'DIFFUSESCALEOFFSET5',function(){return this.DIFFUSESCALEOFFSET5=Shader3D.propertyNameToID("u_DiffuseScaleOffset5");},'CULL',function(){return this.CULL=Shader3D.propertyNameToID("s_Cull");},'BLEND',function(){return this.BLEND=Shader3D.propertyNameToID("s_Blend");},'BLEND_SRC',function(){return this.BLEND_SRC=Shader3D.propertyNameToID("s_BlendSrc");},'BLEND_DST',function(){return this.BLEND_DST=Shader3D.propertyNameToID("s_BlendDst");},'DEPTH_TEST',function(){return this.DEPTH_TEST=Shader3D.propertyNameToID("s_DepthTest");},'DEPTH_WRITE',function(){return this.DEPTH_WRITE=Shader3D.propertyNameToID("s_DepthWrite");},'shaderDefines',function(){return this.shaderDefines=new ShaderDefines(BaseMaterial.shaderDefines);}
- ]);
- return ExtendTerrainMaterial;
- })(BaseMaterial)
- /**
- *<code>BlinnPhongMaterial</code> 类用于实现Blinn-Phong材质。
- */
- //class laya.d3.core.material.BlinnPhongMaterial extends laya.d3.core.material.BaseMaterial
- var BlinnPhongMaterial=(function(_super){
- function BlinnPhongMaterial(){
- /**@private */
- //this._albedoColor=null;
- /**@private */
- //this._albedoIntensity=NaN;
- /**@private */
- //this._enableLighting=false;
- /**@private */
- this._enableVertexColor=false;
- BlinnPhongMaterial.__super.call(this);
- this.setShaderName("BLINNPHONG");
- this._albedoIntensity=1.0;
- this._albedoColor=new Vector4(1.0,1.0,1.0,1.0);
- var sv=this._shaderValues;
- sv.setVector(BlinnPhongMaterial.ALBEDOCOLOR,new Vector4(1.0,1.0,1.0,1.0));
- sv.setVector(BlinnPhongMaterial.MATERIALSPECULAR,new Vector4(1.0,1.0,1.0,1.0));
- sv.setNumber(BlinnPhongMaterial.SHININESS,0.078125);
- sv.setNumber(BaseMaterial.ALPHATESTVALUE,0.5);
- sv.setVector(BlinnPhongMaterial.TILINGOFFSET,new Vector4(1.0,1.0,0.0,0.0));
- this._enableLighting=true;
- this.renderMode=0;
- }
- __class(BlinnPhongMaterial,'laya.d3.core.material.BlinnPhongMaterial',_super);
- var __proto=BlinnPhongMaterial.prototype;
- /**
- *禁用雾化。
- */
- __proto.disableFog=function(){
- this._disablePublicDefineDatas.add(Scene3D.SHADERDEFINE_FOG);
- }
- /**
- *@inheritDoc
- */
- __proto.cloneTo=function(destObject){
- _super.prototype.cloneTo.call(this,destObject);
- var destMaterial=destObject;
- destMaterial._enableLighting=this._enableLighting;
- destMaterial._albedoIntensity=this._albedoIntensity;
- destMaterial._enableVertexColor=this._enableVertexColor;
- this._albedoColor.cloneTo(destMaterial._albedoColor);
- }
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_SpecColorG',function(){
- return this._shaderValues.getVector(BlinnPhongMaterial.MATERIALSPECULAR).y;
- },function(value){
- this._shaderValues.getVector(BlinnPhongMaterial.MATERIALSPECULAR).y=value;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_ColorB',function(){
- return this._albedoColor.z;
- },function(value){
- this._albedoColor.z=value;
- this.albedoColor=this._albedoColor;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_ColorR',function(){
- return this._albedoColor.x;
- },function(value){
- this._albedoColor.x=value;
- this.albedoColor=this._albedoColor;
- });
- /**
- *设置反照率颜色alpha分量。
- *@param value 反照率颜色alpha分量。
- */
- /**
- *获取反照率颜色Z分量。
- *@return 反照率颜色Z分量。
- */
- __getset(0,__proto,'albedoColorA',function(){
- return this._ColorA;
- },function(value){
- this._ColorA=value;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_MainTex_STX',function(){
- return this._shaderValues.getVector(BlinnPhongMaterial.TILINGOFFSET).x;
- },function(x){
- var tilOff=this._shaderValues.getVector(BlinnPhongMaterial.TILINGOFFSET);
- tilOff.x=x;
- this.tilingOffset=tilOff;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_SpecColorB',function(){
- return this._shaderValues.getVector(BlinnPhongMaterial.MATERIALSPECULAR).z;
- },function(value){
- this._shaderValues.getVector(BlinnPhongMaterial.MATERIALSPECULAR).z=value;
- });
- /**
- *设置渲染模式。
- *@return 渲染模式。
- */
- __getset(0,__proto,'renderMode',null,function(value){
- switch (value){
- case 0:
- this.alphaTest=false;
- this.renderQueue=/*laya.d3.core.material.BaseMaterial.RENDERQUEUE_OPAQUE*/2000;
- this.depthWrite=true;
- this.cull=/*laya.d3.core.material.RenderState.CULL_BACK*/2;
- this.blend=/*laya.d3.core.material.RenderState.BLEND_DISABLE*/0;
- this.depthTest=/*laya.d3.core.material.RenderState.DEPTHTEST_LESS*/0x0201;
- break ;
- case 1:
- this.renderQueue=/*laya.d3.core.material.BaseMaterial.RENDERQUEUE_ALPHATEST*/2450;
- this.alphaTest=true;
- this.depthWrite=true;
- this.cull=/*laya.d3.core.material.RenderState.CULL_BACK*/2;
- this.blend=/*laya.d3.core.material.RenderState.BLEND_DISABLE*/0;
- this.depthTest=/*laya.d3.core.material.RenderState.DEPTHTEST_LESS*/0x0201;
- break ;
- case 2:
- this.renderQueue=/*laya.d3.core.material.BaseMaterial.RENDERQUEUE_TRANSPARENT*/3000;
- this.alphaTest=false;
- this.depthWrite=false;
- this.cull=/*laya.d3.core.material.RenderState.CULL_BACK*/2;
- this.blend=/*laya.d3.core.material.RenderState.BLEND_ENABLE_ALL*/1;
- this.blendSrc=/*laya.d3.core.material.RenderState.BLENDPARAM_SRC_ALPHA*/0x0302;
- this.blendDst=/*laya.d3.core.material.RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA*/0x0303;
- this.depthTest=/*laya.d3.core.material.RenderState.DEPTHTEST_LESS*/0x0201;
- break ;
- default :
- throw new Error("Material:renderMode value error.");
- }
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_SpecColorR',function(){
- return this._shaderValues.getVector(BlinnPhongMaterial.MATERIALSPECULAR).x;
- },function(value){
- this._shaderValues.getVector(BlinnPhongMaterial.MATERIALSPECULAR).x=value;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_ColorG',function(){
- return this._albedoColor.y;
- },function(value){
- this._albedoColor.y=value;
- this.albedoColor=this._albedoColor;
- });
- /**
- *@private
- */
- /**@private */
- __getset(0,__proto,'_ColorA',function(){
- return this._albedoColor.w;
- },function(value){
- this._albedoColor.w=value;
- this.albedoColor=this._albedoColor;
- });
- /**
- *设置高光颜色。
- *@param value 高光颜色。
- */
- /**
- *获取高光颜色。
- *@return 高光颜色。
- */
- __getset(0,__proto,'specularColor',function(){
- return this._shaderValues.getVector(BlinnPhongMaterial.MATERIALSPECULAR);
- },function(value){
- this._shaderValues.setVector(BlinnPhongMaterial.MATERIALSPECULAR,value);
- });
- /**
- *设置反照率颜色B分量。
- *@param value 反照率颜色B分量。
- */
- /**
- *获取反照率颜色B分量。
- *@return 反照率颜色B分量。
- */
- __getset(0,__proto,'albedoColorB',function(){
- return this._ColorB;
- },function(value){
- this._ColorB=value;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_SpecColorA',function(){
- return this._shaderValues.getVector(BlinnPhongMaterial.MATERIALSPECULAR).w;
- },function(value){
- this._shaderValues.getVector(BlinnPhongMaterial.MATERIALSPECULAR).w=value;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_MainTex_STZ',function(){
- return this._shaderValues.getVector(BlinnPhongMaterial.TILINGOFFSET).z;
- },function(z){
- var tilOff=this._shaderValues.getVector(BlinnPhongMaterial.TILINGOFFSET);
- tilOff.z=z;
- this.tilingOffset=tilOff;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_AlbedoIntensity',function(){
- return this._albedoIntensity;
- },function(value){
- if (this._albedoIntensity!==value){
- var finalAlbedo=this._shaderValues.getVector(BlinnPhongMaterial.ALBEDOCOLOR);
- Vector4.scale(this._albedoColor,value,finalAlbedo);
- this._albedoIntensity=value;
- this._shaderValues.setVector(BlinnPhongMaterial.ALBEDOCOLOR,finalAlbedo);
- }
- });
- /**
- *设置高光颜色A分量。
- *@param value 高光颜色A分量。
- */
- /**
- *获取高光颜色A分量。
- *@return 高光颜色A分量。
- */
- __getset(0,__proto,'specularColorA',function(){
- return this._SpecColorA;
- },function(value){
- this._SpecColorA=value;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_Shininess',function(){
- return this._shaderValues.getNumber(BlinnPhongMaterial.SHININESS);
- },function(value){
- value=Math.max(0.0,Math.min(1.0,value));
- this._shaderValues.setNumber(BlinnPhongMaterial.SHININESS,value);
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_MainTex_STY',function(){
- return this._shaderValues.getVector(BlinnPhongMaterial.TILINGOFFSET).y;
- },function(y){
- var tilOff=this._shaderValues.getVector(BlinnPhongMaterial.TILINGOFFSET);
- tilOff.y=y;
- this.tilingOffset=tilOff;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_Cutoff',function(){
- return this.alphaTestValue;
- },function(value){
- this.alphaTestValue=value;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_MainTex_STW',function(){
- return this._shaderValues.getVector(BlinnPhongMaterial.TILINGOFFSET).w;
- },function(w){
- var tilOff=this._shaderValues.getVector(BlinnPhongMaterial.TILINGOFFSET);
- tilOff.w=w;
- this.tilingOffset=tilOff;
- });
- /**
- *设置反照率贴图。
- *@param value 反照率贴图。
- */
- /**
- *获取反照率贴图。
- *@return 反照率贴图。
- */
- __getset(0,__proto,'albedoTexture',function(){
- return this._shaderValues.getTexture(BlinnPhongMaterial.ALBEDOTEXTURE);
- },function(value){
- if (value)
- this._defineDatas.add(laya.d3.core.material.BlinnPhongMaterial.SHADERDEFINE_DIFFUSEMAP);
- else
- this._defineDatas.remove(laya.d3.core.material.BlinnPhongMaterial.SHADERDEFINE_DIFFUSEMAP);
- this._shaderValues.setTexture(BlinnPhongMaterial.ALBEDOTEXTURE,value);
- });
- /**
- *设置是否支持顶点色。
- *@param value 是否支持顶点色。
- */
- /**
- *获取是否支持顶点色。
- *@return 是否支持顶点色。
- */
- __getset(0,__proto,'enableVertexColor',function(){
- return this._enableVertexColor;
- },function(value){
- this._enableVertexColor=value;
- if (value)
- this._defineDatas.add(laya.d3.core.material.BlinnPhongMaterial.SHADERDEFINE_ENABLEVERTEXCOLOR);
- else
- this._defineDatas.remove(laya.d3.core.material.BlinnPhongMaterial.SHADERDEFINE_ENABLEVERTEXCOLOR);
- });
- /**
- *设置反照率颜色。
- *@param value 反照率颜色。
- */
- /**
- *获取反照率颜色。
- *@return 反照率颜色。
- */
- __getset(0,__proto,'albedoColor',function(){
- return this._albedoColor;
- },function(value){
- var finalAlbedo=this._shaderValues.getVector(BlinnPhongMaterial.ALBEDOCOLOR);
- Vector4.scale(value,this._albedoIntensity,finalAlbedo);
- this._albedoColor=value;
- this._shaderValues.setVector(BlinnPhongMaterial.ALBEDOCOLOR,finalAlbedo);
- });
- /**
- *获取纹理平铺和偏移X分量。
- *@param x 纹理平铺和偏移X分量。
- */
- /**
- *获取纹理平铺和偏移X分量。
- *@return 纹理平铺和偏移X分量。
- */
- __getset(0,__proto,'tilingOffsetX',function(){
- return this._MainTex_STX;
- },function(x){
- this._MainTex_STX=x;
- });
- /**
- *获取纹理平铺和偏移Y分量。
- *@param y 纹理平铺和偏移Y分量。
- */
- /**
- *获取纹理平铺和偏移Y分量。
- *@return 纹理平铺和偏移Y分量。
- */
- __getset(0,__proto,'tilingOffsetY',function(){
- return this._MainTex_STY;
- },function(y){
- this._MainTex_STY=y;
- });
- /**
- *获取纹理平铺和偏移Z分量。
- *@param z 纹理平铺和偏移Z分量。
- */
- /**
- *获取纹理平铺和偏移Z分量。
- *@return 纹理平铺和偏移Z分量。
- */
- __getset(0,__proto,'tilingOffsetZ',function(){
- return this._MainTex_STZ;
- },function(z){
- this._MainTex_STZ=z;
- });
- /**
- *设置混合源。
- *@param value 混合源
- */
- /**
- *获取混合源。
- *@return 混合源。
- */
- __getset(0,__proto,'blendSrc',function(){
- return this._shaderValues.getInt(BlinnPhongMaterial.BLEND_SRC);
- },function(value){
- this._shaderValues.setInt(BlinnPhongMaterial.BLEND_SRC,value);
- });
- /**
- *设置是否启用光照。
- *@param value 是否启用光照。
- */
- /**
- *获取是否启用光照。
- *@return 是否启用光照。
- */
- __getset(0,__proto,'enableLighting',function(){
- return this._enableLighting;
- },function(value){
- if (this._enableLighting!==value){
- if (value)
- this._disablePublicDefineDatas.remove(Scene3D.SHADERDEFINE_POINTLIGHT | Scene3D.SHADERDEFINE_SPOTLIGHT | Scene3D.SHADERDEFINE_DIRECTIONLIGHT);
- else
- this._disablePublicDefineDatas.add(Scene3D.SHADERDEFINE_POINTLIGHT | Scene3D.SHADERDEFINE_SPOTLIGHT | Scene3D.SHADERDEFINE_DIRECTIONLIGHT);
- this._enableLighting=value;
- }
- });
- /**
- *获取纹理平铺和偏移W分量。
- *@param w 纹理平铺和偏移W分量。
- */
- /**
- *获取纹理平铺和偏移W分量。
- *@return 纹理平铺和偏移W分量。
- */
- __getset(0,__proto,'tilingOffsetW',function(){
- return this._MainTex_STW;
- },function(w){
- this._MainTex_STW=w;
- });
- /**
- *获取纹理平铺和偏移。
- *@param value 纹理平铺和偏移。
- */
- /**
- *获取纹理平铺和偏移。
- *@return 纹理平铺和偏移。
- */
- __getset(0,__proto,'tilingOffset',function(){
- return this._shaderValues.getVector(BlinnPhongMaterial.TILINGOFFSET);
- },function(value){
- if (value){
- if (value.x !=1 || value.y !=1 || value.z !=0 || value.w !=0)
- this._defineDatas.add(laya.d3.core.material.BlinnPhongMaterial.SHADERDEFINE_TILINGOFFSET);
- else
- this._defineDatas.remove(laya.d3.core.material.BlinnPhongMaterial.SHADERDEFINE_TILINGOFFSET);
- }else {
- this._defineDatas.remove(laya.d3.core.material.BlinnPhongMaterial.SHADERDEFINE_TILINGOFFSET);
- }
- this._shaderValues.setVector(BlinnPhongMaterial.TILINGOFFSET,value);
- });
- /**
- *设置反照率颜色R分量。
- *@param value 反照率颜色R分量。
- */
- /**
- *获取反照率颜色R分量。
- *@return 反照率颜色R分量。
- */
- __getset(0,__proto,'albedoColorR',function(){
- return this._ColorR;
- },function(value){
- this._ColorR=value;
- });
- /**
- *设置反照率颜色G分量。
- *@param value 反照率颜色G分量。
- */
- /**
- *获取反照率颜色G分量。
- *@return 反照率颜色G分量。
- */
- __getset(0,__proto,'albedoColorG',function(){
- return this._ColorG;
- },function(value){
- this._ColorG=value;
- });
- /**
- *设置反照率强度。
- *@param value 反照率强度。
- */
- /**
- *获取反照率强度。
- *@return 反照率强度。
- */
- __getset(0,__proto,'albedoIntensity',function(){
- return this._albedoIntensity;
- },function(value){
- this._AlbedoIntensity=value;
- });
- /**
- *设置高光颜色R分量。
- *@param value 高光颜色R分量。
- */
- /**
- *获取高光颜色R轴分量。
- *@return 高光颜色R轴分量。
- */
- __getset(0,__proto,'specularColorR',function(){
- return this._SpecColorR;
- },function(value){
- this._SpecColorR=value;
- });
- /**
- *设置高光颜色G分量。
- *@param value 高光颜色G分量。
- */
- /**
- *获取高光颜色G分量。
- *@return 高光颜色G分量。
- */
- __getset(0,__proto,'specularColorG',function(){
- return this._SpecColorG;
- },function(value){
- this._SpecColorG=value;
- });
- /**
- *设置高光颜色B分量。
- *@param value 高光颜色B分量。
- */
- /**
- *获取高光颜色B分量。
- *@return 高光颜色B分量。
- */
- __getset(0,__proto,'specularColorB',function(){
- return this._SpecColorB;
- },function(value){
- this._SpecColorB=value;
- });
- /**
- *设置混合目标。
- *@param value 混合目标
- */
- /**
- *获取混合目标。
- *@return 混合目标。
- */
- __getset(0,__proto,'blendDst',function(){
- return this._shaderValues.getInt(BlinnPhongMaterial.BLEND_DST);
- },function(value){
- this._shaderValues.setInt(BlinnPhongMaterial.BLEND_DST,value);
- });
- /**
- *设置高光强度,范围为0到1。
- *@param value 高光强度。
- */
- /**
- *获取高光强度,范围为0到1。
- *@return 高光强度。
- */
- __getset(0,__proto,'shininess',function(){
- return this._Shininess;
- },function(value){
- this._Shininess=value;
- });
- /**
- *设置剔除方式。
- *@param value 剔除方式。
- */
- /**
- *获取剔除方式。
- *@return 剔除方式。
- */
- __getset(0,__proto,'cull',function(){
- return this._shaderValues.getInt(BlinnPhongMaterial.CULL);
- },function(value){
- this._shaderValues.setInt(BlinnPhongMaterial.CULL,value);
- });
- /**
- *设置法线贴图。
- *@param value 法线贴图。
- */
- /**
- *获取法线贴图。
- *@return 法线贴图。
- */
- __getset(0,__proto,'normalTexture',function(){
- return this._shaderValues.getTexture(BlinnPhongMaterial.NORMALTEXTURE);
- },function(value){
- if (value)
- this._defineDatas.add(laya.d3.core.material.BlinnPhongMaterial.SHADERDEFINE_NORMALMAP);
- else
- this._defineDatas.remove(laya.d3.core.material.BlinnPhongMaterial.SHADERDEFINE_NORMALMAP);
- this._shaderValues.setTexture(BlinnPhongMaterial.NORMALTEXTURE,value);
- });
- /**
- *设置高光贴图,高光强度则从该贴图RGB值中获取,如果该值为空则从漫反射贴图的Alpha通道获取。
- *@param value 高光贴图。
- */
- /**
- *获取高光贴图。
- *@return 高光贴图。
- */
- __getset(0,__proto,'specularTexture',function(){
- return this._shaderValues.getTexture(BlinnPhongMaterial.SPECULARTEXTURE);
- },function(value){
- if (value)
- this._defineDatas.add(laya.d3.core.material.BlinnPhongMaterial.SHADERDEFINE_SPECULARMAP);
- else
- this._defineDatas.remove(laya.d3.core.material.BlinnPhongMaterial.SHADERDEFINE_SPECULARMAP);
- this._shaderValues.setTexture(BlinnPhongMaterial.SPECULARTEXTURE,value);
- });
- /**
- *设置是否写入深度。
- *@param value 是否写入深度。
- */
- /**
- *获取是否写入深度。
- *@return 是否写入深度。
- */
- __getset(0,__proto,'depthWrite',function(){
- return this._shaderValues.getBool(BlinnPhongMaterial.DEPTH_WRITE);
- },function(value){
- this._shaderValues.setBool(BlinnPhongMaterial.DEPTH_WRITE,value);
- });
- /**
- *设置混合方式。
- *@param value 混合方式。
- */
- /**
- *获取混合方式。
- *@return 混合方式。
- */
- __getset(0,__proto,'blend',function(){
- return this._shaderValues.getInt(BlinnPhongMaterial.BLEND);
- },function(value){
- this._shaderValues.setInt(BlinnPhongMaterial.BLEND,value);
- });
- /**
- *设置深度测试方式。
- *@param value 深度测试方式
- */
- /**
- *获取深度测试方式。
- *@return 深度测试方式。
- */
- __getset(0,__proto,'depthTest',function(){
- return this._shaderValues.getInt(BlinnPhongMaterial.DEPTH_TEST);
- },function(value){
- this._shaderValues.setInt(BlinnPhongMaterial.DEPTH_TEST,value);
- });
- BlinnPhongMaterial.__init__=function(){
- BlinnPhongMaterial.SHADERDEFINE_DIFFUSEMAP=BlinnPhongMaterial.shaderDefines.registerDefine("DIFFUSEMAP");
- BlinnPhongMaterial.SHADERDEFINE_NORMALMAP=BlinnPhongMaterial.shaderDefines.registerDefine("NORMALMAP");
- BlinnPhongMaterial.SHADERDEFINE_SPECULARMAP=BlinnPhongMaterial.shaderDefines.registerDefine("SPECULARMAP");
- BlinnPhongMaterial.SHADERDEFINE_TILINGOFFSET=BlinnPhongMaterial.shaderDefines.registerDefine("TILINGOFFSET");
- BlinnPhongMaterial.SHADERDEFINE_ENABLEVERTEXCOLOR=BlinnPhongMaterial.shaderDefines.registerDefine("ENABLEVERTEXCOLOR");
- }
- BlinnPhongMaterial.SPECULARSOURCE_DIFFUSEMAPALPHA=0;
- BlinnPhongMaterial.SPECULARSOURCE_SPECULARMAP=0;
- BlinnPhongMaterial.RENDERMODE_OPAQUE=0;
- BlinnPhongMaterial.RENDERMODE_CUTOUT=1;
- BlinnPhongMaterial.RENDERMODE_TRANSPARENT=2;
- BlinnPhongMaterial.SHADERDEFINE_DIFFUSEMAP=0;
- BlinnPhongMaterial.SHADERDEFINE_NORMALMAP=0;
- BlinnPhongMaterial.SHADERDEFINE_SPECULARMAP=0;
- BlinnPhongMaterial.SHADERDEFINE_TILINGOFFSET=0;
- BlinnPhongMaterial.SHADERDEFINE_ENABLEVERTEXCOLOR=0;
- __static(BlinnPhongMaterial,
- ['ALBEDOTEXTURE',function(){return this.ALBEDOTEXTURE=Shader3D.propertyNameToID("u_DiffuseTexture");},'NORMALTEXTURE',function(){return this.NORMALTEXTURE=Shader3D.propertyNameToID("u_NormalTexture");},'SPECULARTEXTURE',function(){return this.SPECULARTEXTURE=Shader3D.propertyNameToID("u_SpecularTexture");},'ALBEDOCOLOR',function(){return this.ALBEDOCOLOR=Shader3D.propertyNameToID("u_DiffuseColor");},'MATERIALSPECULAR',function(){return this.MATERIALSPECULAR=Shader3D.propertyNameToID("u_MaterialSpecular");},'SHININESS',function(){return this.SHININESS=Shader3D.propertyNameToID("u_Shininess");},'TILINGOFFSET',function(){return this.TILINGOFFSET=Shader3D.propertyNameToID("u_TilingOffset");},'CULL',function(){return this.CULL=Shader3D.propertyNameToID("s_Cull");},'BLEND',function(){return this.BLEND=Shader3D.propertyNameToID("s_Blend");},'BLEND_SRC',function(){return this.BLEND_SRC=Shader3D.propertyNameToID("s_BlendSrc");},'BLEND_DST',function(){return this.BLEND_DST=Shader3D.propertyNameToID("s_BlendDst");},'DEPTH_TEST',function(){return this.DEPTH_TEST=Shader3D.propertyNameToID("s_DepthTest");},'DEPTH_WRITE',function(){return this.DEPTH_WRITE=Shader3D.propertyNameToID("s_DepthWrite");},'defaultMaterial',function(){return this.defaultMaterial=new BlinnPhongMaterial();},'shaderDefines',function(){return this.shaderDefines=new ShaderDefines(BaseMaterial.shaderDefines);}
- ]);
- return BlinnPhongMaterial;
- })(BaseMaterial)
- /**
- *...
- *@author ...
- */
- //class laya.d3.core.material.TerrainMaterial extends laya.d3.core.material.BaseMaterial
- var TerrainMaterial=(function(_super){
- function TerrainMaterial(){
- this._diffuseScale1=null;
- this._diffuseScale2=null;
- this._diffuseScale3=null;
- this._diffuseScale4=null;
- TerrainMaterial.__super.call(this);
- this.setShaderName("Terrain");
- this.renderMode=1;
- this._diffuseScale1=new Vector2();
- this._diffuseScale2=new Vector2();
- this._diffuseScale3=new Vector2();
- this._diffuseScale4=new Vector2();
- this.ambientColor=new Vector3(0.6,0.6,0.6);
- this.diffuseColor=new Vector3(1.0,1.0,1.0);
- this.specularColor=new Vector4(0.2,0.2,0.2,32.0);
- }
- __class(TerrainMaterial,'laya.d3.core.material.TerrainMaterial',_super);
- var __proto=TerrainMaterial.prototype;
- __proto.setDiffuseScale1=function(x,y){
- this._diffuseScale1.x=x;
- this._diffuseScale1.y=y;
- this._shaderValues.setVector2(6,this._diffuseScale1);
- }
- __proto.setDiffuseScale2=function(x,y){
- this._diffuseScale2.x=x;
- this._diffuseScale2.y=y;
- this._shaderValues.setVector2(7,this._diffuseScale2);
- }
- __proto.setDiffuseScale3=function(x,y){
- this._diffuseScale3.x=x;
- this._diffuseScale3.y=y;
- this._shaderValues.setVector2(8,this._diffuseScale3);
- }
- __proto.setDiffuseScale4=function(x,y){
- this._diffuseScale4.x=x;
- this._diffuseScale4.y=y;
- this._shaderValues.setVector2(9,this._diffuseScale4);
- }
- __proto.setDetailNum=function(value){
- switch (value){
- case 1:
- this._defineDatas.add(laya.d3.core.material.TerrainMaterial.SHADERDEFINE_DETAIL_NUM1);
- this._defineDatas.remove(laya.d3.core.material.TerrainMaterial.SHADERDEFINE_DETAIL_NUM2);
- this._defineDatas.remove(laya.d3.core.material.TerrainMaterial.SHADERDEFINE_DETAIL_NUM3);
- this._defineDatas.remove(laya.d3.core.material.TerrainMaterial.SHADERDEFINE_DETAIL_NUM4);
- break ;
- case 2:
- this._defineDatas.add(laya.d3.core.material.TerrainMaterial.SHADERDEFINE_DETAIL_NUM2);
- this._defineDatas.remove(laya.d3.core.material.TerrainMaterial.SHADERDEFINE_DETAIL_NUM1);
- this._defineDatas.remove(laya.d3.core.material.TerrainMaterial.SHADERDEFINE_DETAIL_NUM3);
- this._defineDatas.remove(laya.d3.core.material.TerrainMaterial.SHADERDEFINE_DETAIL_NUM4);
- break ;
- case 3:
- this._defineDatas.add(laya.d3.core.material.TerrainMaterial.SHADERDEFINE_DETAIL_NUM3);
- this._defineDatas.remove(laya.d3.core.material.TerrainMaterial.SHADERDEFINE_DETAIL_NUM1);
- this._defineDatas.remove(laya.d3.core.material.TerrainMaterial.SHADERDEFINE_DETAIL_NUM2);
- this._defineDatas.remove(laya.d3.core.material.TerrainMaterial.SHADERDEFINE_DETAIL_NUM4);
- break ;
- case 4:
- this._defineDatas.add(laya.d3.core.material.TerrainMaterial.SHADERDEFINE_DETAIL_NUM4);
- this._defineDatas.remove(laya.d3.core.material.TerrainMaterial.SHADERDEFINE_DETAIL_NUM1);
- this._defineDatas.remove(laya.d3.core.material.TerrainMaterial.SHADERDEFINE_DETAIL_NUM2);
- this._defineDatas.remove(laya.d3.core.material.TerrainMaterial.SHADERDEFINE_DETAIL_NUM3);
- break ;
- }
- }
- __proto.disableLight=function(){
- this._disablePublicDefineDatas.add(Scene3D.SHADERDEFINE_POINTLIGHT | Scene3D.SHADERDEFINE_SPOTLIGHT | Scene3D.SHADERDEFINE_DIRECTIONLIGHT);
- }
- /**
- *@inheritDoc
- */
- __proto.setShaderName=function(name){
- _super.prototype.setShaderName.call(this,name);
- }
- /**
- *设置渲染模式。
- *@return 渲染模式。
- */
- __getset(0,__proto,'renderMode',null,function(value){
- switch (value){
- case 1:
- this.renderQueue=/*laya.d3.core.material.BaseMaterial.RENDERQUEUE_OPAQUE*/2000;
- this.depthWrite=true;
- this.cull=/*laya.d3.core.material.RenderState.CULL_BACK*/2;
- this.blend=/*laya.d3.core.material.RenderState.BLEND_DISABLE*/0;
- this.depthTest=/*laya.d3.core.material.RenderState.DEPTHTEST_LESS*/0x0201;
- break ;
- case 2:
- this.renderQueue=/*laya.d3.core.material.BaseMaterial.RENDERQUEUE_OPAQUE*/2000;
- this.depthWrite=false;
- this.cull=/*laya.d3.core.material.RenderState.CULL_BACK*/2;
- this.blend=/*laya.d3.core.material.RenderState.BLEND_ENABLE_ALL*/1;
- this.blendSrc=/*laya.d3.core.material.RenderState.BLENDPARAM_SRC_ALPHA*/0x0302;
- this.blendDst=/*laya.d3.core.material.RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA*/0x0303;
- this.depthTest=/*laya.d3.core.material.RenderState.DEPTHTEST_LEQUAL*/0x0203;
- break ;
- default :
- throw new Error("TerrainMaterial:renderMode value error.");
- }
- });
- /**
- *设置第二层贴图。
- *@param value 第二层贴图。
- */
- /**
- *获取第二层贴图。
- *@return 第二层贴图。
- */
- __getset(0,__proto,'diffuseTexture2',function(){
- return this._shaderValues.getTexture(3);
- },function(value){
- this._shaderValues.setTexture(3,value);
- });
- __getset(0,__proto,'ambientColor',function(){
- return this._shaderValues.getVector(10);
- },function(value){
- this._shaderValues.setVector3(10,value);
- });
- /**
- *设置第四层贴图。
- *@param value 第四层贴图。
- */
- /**
- *获取第四层贴图。
- *@return 第四层贴图。
- */
- __getset(0,__proto,'diffuseTexture4',function(){
- return this._shaderValues.getTexture(5);
- },function(value){
- this._shaderValues.setTexture(5,value);
- });
- __getset(0,__proto,'diffuseColor',function(){
- return this._shaderValues.getVector(11);
- },function(value){
- this._shaderValues.setVector3(11,value);
- });
- /**
- *设置第一层贴图。
- *@param value 第一层贴图。
- */
- /**
- *获取第一层贴图。
- *@return 第一层贴图。
- */
- __getset(0,__proto,'diffuseTexture1',function(){
- return this._shaderValues.getTexture(2);
- },function(value){
- this._shaderValues.setTexture(2,value);
- });
- __getset(0,__proto,'specularColor',function(){
- return this._shaderValues.getVector(12);
- },function(value){
- this._shaderValues.setVector(12,value);
- });
- /**
- *设置第三层贴图。
- *@param value 第三层贴图。
- */
- /**
- *获取第三层贴图。
- *@return 第三层贴图。
- */
- __getset(0,__proto,'diffuseTexture3',function(){
- return this._shaderValues.getTexture(4);
- },function(value){
- this._shaderValues.setTexture(4,value);
- });
- /**
- *设置splatAlpha贴图。
- *@param value splatAlpha贴图。
- */
- /**
- *获取splatAlpha贴图。
- *@return splatAlpha贴图。
- */
- __getset(0,__proto,'splatAlphaTexture',function(){
- return this._shaderValues.getTexture(0);
- },function(value){
- this._shaderValues.setTexture(0,value);
- });
- /**
- *设置剔除方式。
- *@param value 剔除方式。
- */
- /**
- *获取剔除方式。
- *@return 剔除方式。
- */
- __getset(0,__proto,'cull',function(){
- return this._shaderValues.getInt(TerrainMaterial.CULL);
- },function(value){
- this._shaderValues.setInt(TerrainMaterial.CULL,value);
- });
- __getset(0,__proto,'normalTexture',function(){
- return this._shaderValues.getTexture(1);
- },function(value){
- this._shaderValues.setTexture(1,value);
- });
- /**
- *设置是否写入深度。
- *@param value 是否写入深度。
- */
- /**
- *获取是否写入深度。
- *@return 是否写入深度。
- */
- __getset(0,__proto,'depthWrite',function(){
- return this._shaderValues.getBool(TerrainMaterial.DEPTH_WRITE);
- },function(value){
- this._shaderValues.setBool(TerrainMaterial.DEPTH_WRITE,value);
- });
- /**
- *设置混合方式。
- *@param value 混合方式。
- */
- /**
- *获取混合方式。
- *@return 混合方式。
- */
- __getset(0,__proto,'blend',function(){
- return this._shaderValues.getInt(TerrainMaterial.BLEND);
- },function(value){
- this._shaderValues.setInt(TerrainMaterial.BLEND,value);
- });
- /**
- *设置混合源。
- *@param value 混合源
- */
- /**
- *获取混合源。
- *@return 混合源。
- */
- __getset(0,__proto,'blendSrc',function(){
- return this._shaderValues.getInt(TerrainMaterial.BLEND_SRC);
- },function(value){
- this._shaderValues.setInt(TerrainMaterial.BLEND_SRC,value);
- });
- /**
- *设置混合目标。
- *@param value 混合目标
- */
- /**
- *获取混合目标。
- *@return 混合目标。
- */
- __getset(0,__proto,'blendDst',function(){
- return this._shaderValues.getInt(TerrainMaterial.BLEND_DST);
- },function(value){
- this._shaderValues.setInt(TerrainMaterial.BLEND_DST,value);
- });
- /**
- *设置深度测试方式。
- *@param value 深度测试方式
- */
- /**
- *获取深度测试方式。
- *@return 深度测试方式。
- */
- __getset(0,__proto,'depthTest',function(){
- return this._shaderValues.getInt(TerrainMaterial.DEPTH_TEST);
- },function(value){
- this._shaderValues.setInt(TerrainMaterial.DEPTH_TEST,value);
- });
- TerrainMaterial.__init__=function(){
- TerrainMaterial.SHADERDEFINE_DETAIL_NUM1=TerrainMaterial.shaderDefines.registerDefine("DETAIL_NUM1");
- TerrainMaterial.SHADERDEFINE_DETAIL_NUM2=TerrainMaterial.shaderDefines.registerDefine("DETAIL_NUM2");
- TerrainMaterial.SHADERDEFINE_DETAIL_NUM4=TerrainMaterial.shaderDefines.registerDefine("DETAIL_NUM4");
- TerrainMaterial.SHADERDEFINE_DETAIL_NUM3=TerrainMaterial.shaderDefines.registerDefine("DETAIL_NUM3");
- }
- TerrainMaterial.RENDERMODE_OPAQUE=1;
- TerrainMaterial.RENDERMODE_TRANSPARENT=2;
- TerrainMaterial.SPLATALPHATEXTURE=0;
- TerrainMaterial.NORMALTEXTURE=1;
- TerrainMaterial.DIFFUSETEXTURE1=2;
- TerrainMaterial.DIFFUSETEXTURE2=3;
- TerrainMaterial.DIFFUSETEXTURE3=4;
- TerrainMaterial.DIFFUSETEXTURE4=5;
- TerrainMaterial.DIFFUSESCALE1=6;
- TerrainMaterial.DIFFUSESCALE2=7;
- TerrainMaterial.DIFFUSESCALE3=8;
- TerrainMaterial.DIFFUSESCALE4=9;
- TerrainMaterial.MATERIALAMBIENT=10;
- TerrainMaterial.MATERIALDIFFUSE=11;
- TerrainMaterial.MATERIALSPECULAR=12;
- TerrainMaterial.SHADERDEFINE_DETAIL_NUM1=0;
- TerrainMaterial.SHADERDEFINE_DETAIL_NUM2=0;
- TerrainMaterial.SHADERDEFINE_DETAIL_NUM3=0;
- TerrainMaterial.SHADERDEFINE_DETAIL_NUM4=0;
- __static(TerrainMaterial,
- ['CULL',function(){return this.CULL=Shader3D.propertyNameToID("s_Cull");},'BLEND',function(){return this.BLEND=Shader3D.propertyNameToID("s_Blend");},'BLEND_SRC',function(){return this.BLEND_SRC=Shader3D.propertyNameToID("s_BlendSrc");},'BLEND_DST',function(){return this.BLEND_DST=Shader3D.propertyNameToID("s_BlendDst");},'DEPTH_TEST',function(){return this.DEPTH_TEST=Shader3D.propertyNameToID("s_DepthTest");},'DEPTH_WRITE',function(){return this.DEPTH_WRITE=Shader3D.propertyNameToID("s_DepthWrite");},'defaultMaterial',function(){return this.defaultMaterial=new TerrainMaterial();},'shaderDefines',function(){return this.shaderDefines=new ShaderDefines(BaseMaterial.shaderDefines);}
- ]);
- return TerrainMaterial;
- })(BaseMaterial)
- /**
- *<code>SkyBoxMaterial</code> 类用于实现SkyBoxMaterial材质。
- */
- //class laya.d3.core.material.SkyBoxMaterial extends laya.d3.core.material.BaseMaterial
- var SkyBoxMaterial=(function(_super){
- /**
- *创建一个 <code>SkyBoxMaterial</code> 实例。
- */
- function SkyBoxMaterial(){
- SkyBoxMaterial.__super.call(this);
- this.setShaderName("SkyBox");
- }
- __class(SkyBoxMaterial,'laya.d3.core.material.SkyBoxMaterial',_super);
- var __proto=SkyBoxMaterial.prototype;
- /**
- *设置颜色。
- *@param value 颜色。
- */
- /**
- *获取颜色。
- *@return 颜色。
- */
- __getset(0,__proto,'tintColor',function(){
- return this._shaderValues.getVector(SkyBoxMaterial.TINTCOLOR);
- },function(value){
- this._shaderValues.setVector(SkyBoxMaterial.TINTCOLOR,value);
- });
- /**
- *设置曝光强度。
- *@param value 曝光强度。
- */
- /**
- *获取曝光强度。
- *@return 曝光强度。
- */
- __getset(0,__proto,'exposure',function(){
- return this._shaderValues.getNumber(SkyBoxMaterial.EXPOSURE);
- },function(value){
- this._shaderValues.setNumber(SkyBoxMaterial.EXPOSURE,value);
- });
- /**
- *设置曝光强度。
- *@param value 曝光强度。
- */
- /**
- *获取曝光强度。
- *@return 曝光强度。
- */
- __getset(0,__proto,'rotation',function(){
- return this._shaderValues.getNumber(SkyBoxMaterial.ROTATION);
- },function(value){
- this._shaderValues.setNumber(SkyBoxMaterial.ROTATION,value);
- });
- /**
- *设置天空盒纹理。
- */
- /**
- *获取天空盒纹理。
- */
- __getset(0,__proto,'textureCube',function(){
- return this._shaderValues.getTexture(SkyBoxMaterial.TEXTURECUBE);
- },function(value){
- this._shaderValues.setTexture(SkyBoxMaterial.TEXTURECUBE,value);
- });
- __static(SkyBoxMaterial,
- ['TINTCOLOR',function(){return this.TINTCOLOR=Shader3D.propertyNameToID("u_TintColor");},'EXPOSURE',function(){return this.EXPOSURE=Shader3D.propertyNameToID("u_Exposure");},'ROTATION',function(){return this.ROTATION=Shader3D.propertyNameToID("u_Rotation");},'TEXTURECUBE',function(){return this.TEXTURECUBE=Shader3D.propertyNameToID("u_CubeTexture");},'defaultMaterial',function(){return this.defaultMaterial=new SkyBoxMaterial();}
- ]);
- return SkyBoxMaterial;
- })(BaseMaterial)
- /**
- *<code>PBRSpecularMaterial</code> 类用于实现PBR(Specular)材质。
- */
- //class laya.d3.core.material.PBRSpecularMaterial extends laya.d3.core.material.BaseMaterial
- var PBRSpecularMaterial=(function(_super){
- function PBRSpecularMaterial(){
- /**@private */
- this._albedoColor=null;
- /**@private */
- this._specularColor=null;
- /**@private */
- this._emissionColor=null;
- PBRSpecularMaterial.__super.call(this);
- this.setShaderName("PBRSpecular");
- this._albedoColor=new Vector4(1.0,1.0,1.0,1.0);
- this._shaderValues.setVector(PBRSpecularMaterial.ALBEDOCOLOR,new Vector4(1.0,1.0,1.0,1.0));
- this._emissionColor=new Vector4(0.0,0.0,0.0,0.0);
- this._shaderValues.setVector(PBRSpecularMaterial.EMISSIONCOLOR,new Vector4(0.0,0.0,0.0,0.0));
- this._specularColor=new Vector4(0.2,0.2,0.2,0.2);
- this._shaderValues.setVector(PBRSpecularMaterial.SPECULARCOLOR,new Vector4(0.2,0.2,0.2,0.2));
- this._shaderValues.setNumber(PBRSpecularMaterial.SMOOTHNESS,0.5);
- this._shaderValues.setNumber(PBRSpecularMaterial.SMOOTHNESSSCALE,1.0);
- this._shaderValues.setNumber(PBRSpecularMaterial.SMOOTHNESSSOURCE,0);
- this._shaderValues.setNumber(PBRSpecularMaterial.OCCLUSIONSTRENGTH,1.0);
- this._shaderValues.setNumber(PBRSpecularMaterial.NORMALSCALE,1.0);
- this._shaderValues.setNumber(PBRSpecularMaterial.PARALLAXSCALE,0.001);
- this._shaderValues.setBool(PBRSpecularMaterial.ENABLEEMISSION,false);
- this._shaderValues.setNumber(BaseMaterial.ALPHATESTVALUE,0.5);
- this.renderMode=0;
- }
- __class(PBRSpecularMaterial,'laya.d3.core.material.PBRSpecularMaterial',_super);
- var __proto=PBRSpecularMaterial.prototype;
- /**
- *@inheritDoc
- */
- __proto.cloneTo=function(destObject){
- _super.prototype.cloneTo.call(this,destObject);
- var destMaterial=destObject;
- this._albedoColor.cloneTo(destMaterial._albedoColor);
- this._specularColor.cloneTo(destMaterial._specularColor);
- this._emissionColor.cloneTo(destMaterial._emissionColor);
- }
- /**
- *设置放射贴图。
- *@param value 放射贴图。
- */
- /**
- *获取放射贴图。
- *@return 放射贴图。
- */
- __getset(0,__proto,'emissionTexture',function(){
- return this._shaderValues.getTexture(PBRSpecularMaterial.EMISSIONTEXTURE);
- },function(value){
- if (value)
- this._defineDatas.add(laya.d3.core.material.PBRSpecularMaterial.SHADERDEFINE_EMISSIONTEXTURE);
- else
- this._defineDatas.remove(laya.d3.core.material.PBRSpecularMaterial.SHADERDEFINE_EMISSIONTEXTURE);
- this._shaderValues.setTexture(PBRSpecularMaterial.EMISSIONTEXTURE,value);
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_SpecColorG',function(){
- return this._specularColor.y;
- },function(value){
- this._specularColor.y=value;
- this.specularColor=this._specularColor;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_ColorB',function(){
- return this._albedoColor.z;
- },function(value){
- this._albedoColor.z=value;
- this.albedoColor=this._albedoColor;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_ColorR',function(){
- return this._albedoColor.x;
- },function(value){
- this._albedoColor.x=value;
- this.albedoColor=this._albedoColor;
- });
- /**
- *设置反射率颜色A分量。
- *@param value 反射率颜色A分量。
- */
- /**
- *获取反射率颜色A分量。
- *@return 反射率颜色A分量。
- */
- __getset(0,__proto,'albedoColorA',function(){
- return this._ColorA;
- },function(value){
- this._ColorA=value;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_MainTex_STX',function(){
- return this._shaderValues.getVector(PBRSpecularMaterial.TILINGOFFSET).x;
- },function(x){
- var tilOff=this._shaderValues.getVector(PBRSpecularMaterial.TILINGOFFSET);
- tilOff.x=x;
- this.tilingOffset=tilOff;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_SpecColorB',function(){
- return this._specularColor.z;
- },function(value){
- this._specularColor.z=value;
- this.specularColor=this._specularColor;
- });
- /**
- *设置渲染模式。
- *@return 渲染模式。
- */
- __getset(0,__proto,'renderMode',null,function(value){
- switch (value){
- case 0:
- this.alphaTest=false;
- this.renderQueue=/*laya.d3.core.material.BaseMaterial.RENDERQUEUE_OPAQUE*/2000;
- this.depthWrite=true;
- this.cull=/*laya.d3.core.material.RenderState.CULL_BACK*/2;
- this.blend=/*laya.d3.core.material.RenderState.BLEND_DISABLE*/0;
- this.depthTest=/*laya.d3.core.material.RenderState.DEPTHTEST_LESS*/0x0201;
- this._defineDatas.remove(PBRSpecularMaterial.SHADERDEFINE_ALPHAPREMULTIPLY);
- break ;
- case 1:
- this.renderQueue=/*laya.d3.core.material.BaseMaterial.RENDERQUEUE_ALPHATEST*/2450;
- this.alphaTest=true;
- this.depthWrite=true;
- this.cull=/*laya.d3.core.material.RenderState.CULL_BACK*/2;
- this.blend=/*laya.d3.core.material.RenderState.BLEND_DISABLE*/0;
- this.depthTest=/*laya.d3.core.material.RenderState.DEPTHTEST_LESS*/0x0201;
- this._defineDatas.remove(PBRSpecularMaterial.SHADERDEFINE_ALPHAPREMULTIPLY);
- break ;
- case 2:
- this.renderQueue=/*laya.d3.core.material.BaseMaterial.RENDERQUEUE_TRANSPARENT*/3000;
- this.alphaTest=false;
- this.depthWrite=false;
- this.cull=/*laya.d3.core.material.RenderState.CULL_BACK*/2;
- this.blend=/*laya.d3.core.material.RenderState.BLEND_ENABLE_ALL*/1;
- this.blendSrc=/*laya.d3.core.material.RenderState.BLENDPARAM_SRC_ALPHA*/0x0302;
- this.blendDst=/*laya.d3.core.material.RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA*/0x0303;
- this.depthTest=/*laya.d3.core.material.RenderState.DEPTHTEST_LESS*/0x0201;
- this._defineDatas.remove(PBRSpecularMaterial.SHADERDEFINE_ALPHAPREMULTIPLY);
- break ;
- break ;
- case 3:
- this.renderQueue=/*laya.d3.core.material.BaseMaterial.RENDERQUEUE_TRANSPARENT*/3000;
- this.alphaTest=false;
- this.depthWrite=false;
- this.cull=/*laya.d3.core.material.RenderState.CULL_BACK*/2;
- this.blend=/*laya.d3.core.material.RenderState.BLEND_ENABLE_ALL*/1;
- this.blendSrc=/*laya.d3.core.material.RenderState.BLENDPARAM_ONE*/1;
- this.blendDst=/*laya.d3.core.material.RenderState.BLENDPARAM_ONE_MINUS_SRC_ALPHA*/0x0303;
- this.depthTest=/*laya.d3.core.material.RenderState.DEPTHTEST_LESS*/0x0201;
- this._defineDatas.add(PBRSpecularMaterial.SHADERDEFINE_ALPHAPREMULTIPLY);
- break ;
- default :
- throw new Error("PBRSpecularMaterial : renderMode value error.");
- }
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_SpecColorR',function(){
- return this._specularColor.x;
- },function(value){
- this._specularColor.x=value;
- this.specularColor=this._specularColor;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_ColorG',function(){
- return this._albedoColor.y;
- },function(value){
- this._albedoColor.y=value;
- this.albedoColor=this._albedoColor;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_Glossiness',function(){
- return this._shaderValues.getNumber(PBRSpecularMaterial.SMOOTHNESS);
- },function(value){
- this._shaderValues.setNumber(PBRSpecularMaterial.SMOOTHNESS,value);
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_ColorA',function(){
- return this._albedoColor.w;
- },function(value){
- this._albedoColor.w=value;
- this.albedoColor=this._albedoColor;
- });
- /**
- *设置高光颜色。
- *@param value 高光颜色。
- */
- /**
- *获取高光颜色。
- *@return 高光颜色。
- */
- __getset(0,__proto,'specularColor',function(){
- return this._shaderValues.getVector(PBRSpecularMaterial.SPECULARCOLOR);
- },function(value){
- this._shaderValues.setVector(PBRSpecularMaterial.SPECULARCOLOR,value);
- });
- /**
- *设置反射率颜色B分量。
- *@param value 反射率颜色B分量。
- */
- /**
- *获取反射率颜色B分量。
- *@return 反射率颜色B分量。
- */
- __getset(0,__proto,'albedoColorB',function(){
- return this._ColorB;
- },function(value){
- this._ColorB=value;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_SpecColorA',function(){
- return this._specularColor.w;
- },function(value){
- this._specularColor.w=value;
- this.specularColor=this._specularColor;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_GlossMapScale',function(){
- return this._shaderValues.getNumber(PBRSpecularMaterial.SMOOTHNESSSCALE);
- },function(value){
- this._shaderValues.setNumber(PBRSpecularMaterial.SMOOTHNESSSCALE,value);
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_BumpScale',function(){
- return this._shaderValues.getNumber(PBRSpecularMaterial.NORMALSCALE);
- },function(value){
- this._shaderValues.setNumber(PBRSpecularMaterial.NORMALSCALE,value);
- });
- /**
- *@private
- */
- /**@private */
- __getset(0,__proto,'_Parallax',function(){
- return this._shaderValues.getNumber(PBRSpecularMaterial.PARALLAXSCALE);
- },function(value){
- this._shaderValues.setNumber(PBRSpecularMaterial.PARALLAXSCALE,value);
- });
- /**
- *@private
- */
- /**@private */
- __getset(0,__proto,'_OcclusionStrength',function(){
- return this._shaderValues.getNumber(PBRSpecularMaterial.OCCLUSIONSTRENGTH);
- },function(value){
- this._shaderValues.setNumber(PBRSpecularMaterial.OCCLUSIONSTRENGTH,value);
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_EmissionColorR',function(){
- return this._emissionColor.x;
- },function(value){
- this._emissionColor.x=value;
- this.emissionColor=this._emissionColor;
- });
- /**
- *获取纹理平铺和偏移。
- *@param value 纹理平铺和偏移。
- */
- /**
- *获取纹理平铺和偏移。
- *@return 纹理平铺和偏移。
- */
- __getset(0,__proto,'tilingOffset',function(){
- return this._shaderValues.getVector(PBRSpecularMaterial.TILINGOFFSET);
- },function(value){
- if (value){
- if (value.x !=1 || value.y !=1 || value.z !=0 || value.w !=0)
- this._defineDatas.add(laya.d3.core.material.PBRSpecularMaterial.SHADERDEFINE_TILINGOFFSET);
- else
- this._defineDatas.remove(laya.d3.core.material.PBRSpecularMaterial.SHADERDEFINE_TILINGOFFSET);
- }else {
- this._defineDatas.remove(laya.d3.core.material.PBRSpecularMaterial.SHADERDEFINE_TILINGOFFSET);
- }
- this._shaderValues.setVector(PBRSpecularMaterial.TILINGOFFSET,value);
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_EmissionColorG',function(){
- return this._emissionColor.y;
- },function(value){
- this._emissionColor.y=value;
- this.emissionColor=this._emissionColor;
- });
- /**
- *设置混合源。
- *@param value 混合源
- */
- /**
- *获取混合源。
- *@return 混合源。
- */
- __getset(0,__proto,'blendSrc',function(){
- return this._shaderValues.getInt(PBRSpecularMaterial.BLEND_SRC);
- },function(value){
- this._shaderValues.setInt(PBRSpecularMaterial.BLEND_SRC,value);
- });
- /**
- *获取纹理平铺和偏移W分量。
- *@param w 纹理平铺和偏移W分量。
- */
- /**
- *获取纹理平铺和偏移W分量。
- *@return 纹理平铺和偏移W分量。
- */
- __getset(0,__proto,'tilingOffsetW',function(){
- return this._MainTex_STW;
- },function(w){
- this._MainTex_STW=w;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_EmissionColorB',function(){
- return this._emissionColor.z;
- },function(value){
- this._emissionColor.z=value;
- this.emissionColor=this._emissionColor;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_EmissionColorA',function(){
- return this._emissionColor.w;
- },function(value){
- this._emissionColor.w=value;
- this.emissionColor=this._emissionColor;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_MainTex_STY',function(){
- return this._shaderValues.getVector(PBRSpecularMaterial.TILINGOFFSET).y;
- },function(y){
- var tilOff=this._shaderValues.getVector(PBRSpecularMaterial.TILINGOFFSET);
- tilOff.y=y;
- this.tilingOffset=tilOff;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_MainTex_STZ',function(){
- return this._shaderValues.getVector(PBRSpecularMaterial.TILINGOFFSET).z;
- },function(z){
- var tilOff=this._shaderValues.getVector(PBRSpecularMaterial.TILINGOFFSET);
- tilOff.z=z;
- this.tilingOffset=tilOff;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_Cutoff',function(){
- return this.alphaTestValue;
- },function(value){
- this.alphaTestValue=value;
- });
- /**
- *@private
- */
- /**
- *@private
- */
- __getset(0,__proto,'_MainTex_STW',function(){
- return this._shaderValues.getVector(PBRSpecularMaterial.TILINGOFFSET).w;
- },function(w){
- var tilOff=this._shaderValues.getVector(PBRSpecularMaterial.TILINGOFFSET);
- tilOff.w=w;
- this.tilingOffset=tilOff;
- });
- /**
- *设置反射率颜色R分量。
- *@param value 反射率颜色R分量。
- */
- /**
- *获取反射率颜色R分量。
- *@return 反射率颜色R分量。
- */
- __getset(0,__proto,'albedoColorR',function(){
- return this._ColorR;
- },function(value){
- this._ColorR=value;
- });
- /**
- *设置反射率颜色G分量。
- *@param value 反射率颜色G分量。
- */
- /**
- *获取反射率颜色G分量。
- *@return 反射率颜色G分量。
- */
- __getset(0,__proto,'albedoColorG',function(){
- return this._ColorG;
- },function(value){
- this._ColorG=value;
- });
- /**
- *获取纹理平铺和偏移X分量。
- *@param x 纹理平铺和偏移X分量。
- */
- /**
- *获取纹理平铺和偏移X分量。
- *@return 纹理平铺和偏移X分量。
- */
- __getset(0,__proto,'tilingOffsetX',function(){
- return this._MainTex_STX;
- },function(x){
- this._MainTex_STX=x;
- });
- /**
- *设置反射率颜色。
- *@param value 反射率颜色。
- */
- /**
- *获取反射率颜色。
- *@return 反射率颜色。
- */
- __getset(0,__proto,'albedoColor',function(){
- return this._albedoColor;
- },function(value){
- this._albedoColor=value;
- this._shaderValues.setVector(PBRSpecularMaterial.ALBEDOCOLOR,value);
- });
- /**
- *设置漫反射贴图。
- *@param value 漫反射贴图。
- */
- /**
- *获取漫反射贴图。
- *@return 漫反射贴图。
- */
- __getset(0,__proto,'albedoTexture',function(){
- return this._shaderValues.getTexture(PBRSpecularMaterial.ALBEDOTEXTURE);
- },function(value){
- if (value){
- this._defineDatas.add(laya.d3.core.material.PBRSpecularMaterial.SHADERDEFINE_ALBEDOTEXTURE);
- }else {
- this._defineDatas.remove(laya.d3.core.material.PBRSpecularMaterial.SHADERDEFINE_ALBEDOTEXTURE);
- }
- this._shaderValues.setTexture(PBRSpecularMaterial.ALBEDOTEXTURE,value);
- });
- /**
- *设置剔除方式。
- *@param value 剔除方式。
- */
- /**
- *获取剔除方式。
- *@return 剔除方式。
- */
- __getset(0,__proto,'cull',function(){
- return this._shaderValues.getInt(PBRSpecularMaterial.CULL);
- },function(value){
- this._shaderValues.setInt(PBRSpecularMaterial.CULL,value);
- });
- /**
- *设置视差贴图。
- *@param value 视察贴图。
- */
- /**
- *获取视差贴图。
- *@return 视察贴图。
- */
- __getset(0,__proto,'parallaxTexture',function(){
- return this._shaderValues.getTexture(PBRSpecularMaterial.PARALLAXTEXTURE);
- },function(value){
- if (value){
- this._defineDatas.add(laya.d3.core.material.PBRSpecularMaterial.SHADERDEFINE_PARALLAXTEXTURE);
- }else {
- this._defineDatas.remove(laya.d3.core.material.PBRSpecularMaterial.SHADERDEFINE_PARALLAXTEXTURE);
- }
- this._shaderValues.setTexture(PBRSpecularMaterial.PARALLAXTEXTURE,value);
- });
- /**
- *设置法线贴图。
- *@param value 法线贴图。
- */
- /**
- *获取法线贴图。
- *@return 法线贴图。
- */
- __getset(0,__proto,'normalTexture',function(){
- return this._shaderValues.getTexture(PBRSpecularMaterial.NORMALTEXTURE);
- },function(value){
- if (value){
- this._defineDatas.add(laya.d3.core.material.PBRSpecularMaterial.SHADERDEFINE_NORMALTEXTURE);
- }else {
- this._defineDatas.remove(laya.d3.core.material.PBRSpecularMaterial.SHADERDEFINE_NORMALTEXTURE);
- }
- this._shaderValues.setTexture(PBRSpecularMaterial.NORMALTEXTURE,value);
- });
- /**
- *设置放射颜色。
- *@param value 放射颜色。
- */
- /**
- *获取放射颜色。
- *@return 放射颜色。
- */
- __getset(0,__proto,'emissionColor',function(){
- return this._shaderValues.getVector(PBRSpecularMaterial.EMISSIONCOLOR);
- },function(value){
- this._shaderValues.setVector(PBRSpecularMaterial.EMISSIONCOLOR,value);
- });
- /**
- *设置视差贴图缩放系数。
- *@param value 视差缩放系数。
- */
- /**
- *获取视差贴图缩放系数。
- *@return 视差缩放系数。
- */
- __getset(0,__proto,'parallaxTextureScale',function(){
- return this._Parallax;
- },function(value){
- this._Parallax=Math.max(0.005,Math.min(0.08,value));
- });
- /**
- *设置法线贴图缩放系数。
- *@param value 法线贴图缩放系数。
- */
- /**
- *获取法线贴图缩放系数。
- *@return 法线贴图缩放系数。
- */
- __getset(0,__proto,'normalTextureScale',function(){
- return this._BumpScale;
- },function(value){
- this._BumpScale=value;
- });
- /**
- *获取纹理平铺和偏移Z分量。
- *@param z 纹理平铺和偏移Z分量。
- */
- /**
- *获取纹理平铺和偏移Z分量。
- *@return 纹理平铺和偏移Z分量。
- */
- __getset(0,__proto,'tilingOffsetZ',function(){
- return this._MainTex_STZ;
- },function(z){
- this._MainTex_STZ=z;
- });
- /**
- *设置遮挡贴图。
- *@param value 遮挡贴图。
- */
- /**
- *获取遮挡贴图。
- *@return 遮挡贴图。
- */
- __getset(0,__proto,'occlusionTexture',function(){
- return this._shaderValues.getTexture(PBRSpecularMaterial.OCCLUSIONTEXTURE);
- },function(value){
- if (value){
- this._defineDatas.add(laya.d3.core.material.PBRSpecularMaterial.SHADERDEFINE_OCCLUSIONTEXTURE);
- }else {
- this._defineDatas.remove(laya.d3.core.material.PBRSpecularMaterial.SHADERDEFINE_OCCLUSIONTEXTURE);
- }
- this._shaderValues.setTexture(PBRSpecularMaterial.OCCLUSIONTEXTURE,value);
- });
- /**
- *设置遮挡贴图强度。
- *@param value 遮挡贴图强度,范围为0到1。
- */
- /**
- *获取遮挡贴图强度。
- *@return 遮挡贴图强度,范围为0到1。
- */
- __getset(0,__proto,'occlusionTextureStrength',function(){
- return this._OcclusionStrength;
- },function(value){
- this._OcclusionStrength=Math.max(0.0,Math.min(1.0,value));
- });
- /**
- *设置高光贴图。
- *@param value 高光贴图。
- */
- /**
- *获取高光贴图。
- *@return 高光贴图。
- */
- __getset(0,__proto,'specularTexture',function(){
- return this._shaderValues.getTexture(PBRSpecularMaterial.SPECULARTEXTURE);
- },function(value){
- if (value){
- this._defineDatas.add(laya.d3.core.material.PBRSpecularMaterial.SHADERDEFINE_SPECULARTEXTURE);
- }else {
- this._defineDatas.remove(laya.d3.core.material.PBRSpecularMaterial.SHADERDEFINE_SPECULARTEXTURE);
- }
- this._shaderValues.setTexture(PBRSpecularMaterial.SPECULARTEXTURE,value);
- });
- /**
- *设置高光颜色R分量。
- *@param value 高光颜色R分量。
- */
- /**
- *获取高光颜色R分量。
- *@return 高光颜色R分量。
- */
- __getset(0,__proto,'specularColorR',function(){
- return this._SpecColorR;
- },function(value){
- this._SpecColorR=value;
- });
- /**
- *设置光滑度。
- *@param value 光滑度,范围为0到1。
- */
- /**
- *获取光滑度。
- *@return 光滑度,范围为0到1。
- */
- __getset(0,__proto,'smoothness',function(){
- return this._Glossiness;
- },function(value){
- this._Glossiness=Math.max(0.0,Math.min(1.0,value));
- });
- /**
- *设置高光颜色G分量。
- *@param value 高光颜色G分量。
- */
- /**
- *获取高光颜色G分量。
- *@return 高光颜色G分量。
- */
- __getset(0,__proto,'specularColorG',function(){
- return this._SpecColorG;
- },function(value){
- this._SpecColorG=value;
- });
- /**
- *设置高光颜色B分量。
- *@param value 高光颜色B分量。
- */
- /**
- *获取高光颜色B分量。
- *@return 高光颜色B分量。
- */
- __getset(0,__proto,'specularColorB',function(){
- return this._SpecColorB;
- },function(value){
- this._SpecColorB=value;
- });
- /**
- *设置高光颜色A分量。
- *@param value 高光颜色A分量。
- */
- /**
- *获取高光颜色A分量。
- *@return 高光颜色A分量。
- */
- __getset(0,__proto,'specularColorA',function(){
- return this._SpecColorA;
- },function(value){
- this._SpecColorA=value;
- });
- /**
- *设置混合目标。
- *@param value 混合目标
- */
- /**
- *获取混合目标。
- *@return 混合目标。
- */
- __getset(0,__proto,'blendDst',function(){
- return this._shaderValues.getInt(PBRSpecularMaterial.BLEND_DST);
- },function(value){
- this._shaderValues.setInt(PBRSpecularMaterial.BLEND_DST,value);
- });
- /**
- *设置光滑度缩放系数。
- *@param value 光滑度缩放系数,范围为0到1。
- */
- /**
- *获取光滑度缩放系数。
- *@return 光滑度缩放系数,范围为0到1。
- */
- __getset(0,__proto,'smoothnessTextureScale',function(){
- return this._GlossMapScale;
- },function(value){
- this._GlossMapScale=Math.max(0.0,Math.min(1.0,value));
- });
- /**
- *设置是否写入深度。
- *@param value 是否写入深度。
- */
- /**
- *获取是否写入深度。
- *@return 是否写入深度。
- */
- __getset(0,__proto,'depthWrite',function(){
- return this._shaderValues.getBool(PBRSpecularMaterial.DEPTH_WRITE);
- },function(value){
- this._shaderValues.setBool(PBRSpecularMaterial.DEPTH_WRITE,value);
- });
- /**
- *设置光滑度数据源。
- *@param value 光滑滑度数据源,0或1。
- */
- /**
- *获取光滑度数据源
- *@return 光滑滑度数据源,0或1。
- */
- __getset(0,__proto,'smoothnessSource',function(){
- return this._shaderValues.getInt(PBRSpecularMaterial.SMOOTHNESSSOURCE);
- },function(value){
- if (value){
- this._defineDatas.add(laya.d3.core.material.PBRSpecularMaterial.SHADERDEFINE_SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA);
- this._shaderValues.setInt(PBRSpecularMaterial.SMOOTHNESSSOURCE,1);
- }else {
- this._defineDatas.remove(laya.d3.core.material.PBRSpecularMaterial.SHADERDEFINE_SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA);
- this._shaderValues.setInt(PBRSpecularMaterial.SMOOTHNESSSOURCE,0);
- }
- });
- /**
- *设置是否激活放射属性。
- *@param value 是否激活放射属性
- */
- /**
- *获取是否激活放射属性。
- *@return 是否激活放射属性。
- */
- __getset(0,__proto,'enableEmission',function(){
- return this._shaderValues.getBool(PBRSpecularMaterial.ENABLEEMISSION);
- },function(value){
- if (value)
- this._defineDatas.add(laya.d3.core.material.PBRSpecularMaterial.SHADERDEFINE_EMISSION);
- else {
- this._defineDatas.remove(laya.d3.core.material.PBRSpecularMaterial.SHADERDEFINE_EMISSION);
- }
- this._shaderValues.setBool(PBRSpecularMaterial.ENABLEEMISSION,value);
- });
- /**
- *设置是否开启反射。
- *@param value 是否开启反射。
- */
- /**
- *获取是否开启反射。
- *@return 是否开启反射。
- */
- __getset(0,__proto,'enableReflection',function(){
- return this._shaderValues.getBool(PBRSpecularMaterial.ENABLEREFLECT);
- },function(value){
- this._shaderValues.setBool(PBRSpecularMaterial.ENABLEREFLECT,true);
- if (value)
- this._disablePublicDefineDatas.remove(Scene3D.SHADERDEFINE_REFLECTMAP);
- else
- this._disablePublicDefineDatas.add(Scene3D.SHADERDEFINE_REFLECTMAP);
- });
- /**
- *获取纹理平铺和偏移Y分量。
- *@param y 纹理平铺和偏移Y分量。
- */
- /**
- *获取纹理平铺和偏移Y分量。
- *@return 纹理平铺和偏移Y分量。
- */
- __getset(0,__proto,'tilingOffsetY',function(){
- return this._MainTex_STY;
- },function(y){
- this._MainTex_STY=y;
- });
- /**
- *设置混合方式。
- *@param value 混合方式。
- */
- /**
- *获取混合方式。
- *@return 混合方式。
- */
- __getset(0,__proto,'blend',function(){
- return this._shaderValues.getInt(PBRSpecularMaterial.BLEND);
- },function(value){
- this._shaderValues.setInt(PBRSpecularMaterial.BLEND,value);
- });
- /**
- *设置深度测试方式。
- *@param value 深度测试方式
- */
- /**
- *获取深度测试方式。
- *@return 深度测试方式。
- */
- __getset(0,__proto,'depthTest',function(){
- return this._shaderValues.getInt(PBRSpecularMaterial.DEPTH_TEST);
- },function(value){
- this._shaderValues.setInt(PBRSpecularMaterial.DEPTH_TEST,value);
- });
- PBRSpecularMaterial.__init__=function(){
- PBRSpecularMaterial.SHADERDEFINE_ALBEDOTEXTURE=PBRSpecularMaterial.shaderDefines.registerDefine("ALBEDOTEXTURE");
- PBRSpecularMaterial.SHADERDEFINE_SPECULARTEXTURE=PBRSpecularMaterial.shaderDefines.registerDefine("SPECULARTEXTURE");
- PBRSpecularMaterial.SHADERDEFINE_SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA=PBRSpecularMaterial.shaderDefines.registerDefine("SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA");
- PBRSpecularMaterial.SHADERDEFINE_NORMALTEXTURE=PBRSpecularMaterial.shaderDefines.registerDefine("NORMALTEXTURE");
- PBRSpecularMaterial.SHADERDEFINE_PARALLAXTEXTURE=PBRSpecularMaterial.shaderDefines.registerDefine("PARALLAXTEXTURE");
- PBRSpecularMaterial.SHADERDEFINE_OCCLUSIONTEXTURE=PBRSpecularMaterial.shaderDefines.registerDefine("OCCLUSIONTEXTURE");
- PBRSpecularMaterial.SHADERDEFINE_EMISSION=PBRSpecularMaterial.shaderDefines.registerDefine("EMISSION");
- PBRSpecularMaterial.SHADERDEFINE_EMISSIONTEXTURE=PBRSpecularMaterial.shaderDefines.registerDefine("EMISSIONTEXTURE");
- PBRSpecularMaterial.SHADERDEFINE_TILINGOFFSET=PBRSpecularMaterial.shaderDefines.registerDefine("TILINGOFFSET");
- PBRSpecularMaterial.SHADERDEFINE_ALPHAPREMULTIPLY=PBRSpecularMaterial.shaderDefines.registerDefine("ALPHAPREMULTIPLY");
- }
- PBRSpecularMaterial.SmoothnessSource_SpecularTexture_Alpha=0;
- PBRSpecularMaterial.SmoothnessSource_AlbedoTexture_Alpha=1;
- PBRSpecularMaterial.RENDERMODE_OPAQUE=0;
- PBRSpecularMaterial.RENDERMODE_CUTOUT=1;
- PBRSpecularMaterial.RENDERMODE_FADE=2;
- PBRSpecularMaterial.RENDERMODE_TRANSPARENT=3;
- PBRSpecularMaterial.SHADERDEFINE_ALBEDOTEXTURE=0;
- PBRSpecularMaterial.SHADERDEFINE_NORMALTEXTURE=0;
- PBRSpecularMaterial.SHADERDEFINE_SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA=0;
- PBRSpecularMaterial.SHADERDEFINE_SPECULARTEXTURE=0;
- PBRSpecularMaterial.SHADERDEFINE_OCCLUSIONTEXTURE=0;
- PBRSpecularMaterial.SHADERDEFINE_PARALLAXTEXTURE=0;
- PBRSpecularMaterial.SHADERDEFINE_EMISSION=0;
- PBRSpecularMaterial.SHADERDEFINE_EMISSIONTEXTURE=0;
- PBRSpecularMaterial.SHADERDEFINE_TILINGOFFSET=0;
- PBRSpecularMaterial.SHADERDEFINE_ALPHAPREMULTIPLY=0;
- PBRSpecularMaterial.SMOOTHNESSSOURCE=-1;
- PBRSpecularMaterial.ENABLEEMISSION=-1;
- PBRSpecularMaterial.ENABLEREFLECT=-1;
- __static(PBRSpecularMaterial,
- ['ALBEDOTEXTURE',function(){return this.ALBEDOTEXTURE=Shader3D.propertyNameToID("u_AlbedoTexture");},'SPECULARTEXTURE',function(){return this.SPECULARTEXTURE=Shader3D.propertyNameToID("u_SpecularTexture");},'NORMALTEXTURE',function(){return this.NORMALTEXTURE=Shader3D.propertyNameToID("u_NormalTexture");},'PARALLAXTEXTURE',function(){return this.PARALLAXTEXTURE=Shader3D.propertyNameToID("u_ParallaxTexture");},'OCCLUSIONTEXTURE',function(){return this.OCCLUSIONTEXTURE=Shader3D.propertyNameToID("u_OcclusionTexture");},'EMISSIONTEXTURE',function(){return this.EMISSIONTEXTURE=Shader3D.propertyNameToID("u_EmissionTexture");},'ALBEDOCOLOR',function(){return this.ALBEDOCOLOR=Shader3D.propertyNameToID("u_AlbedoColor");},'SPECULARCOLOR',function(){return this.SPECULARCOLOR=Shader3D.propertyNameToID("u_SpecularColor");},'EMISSIONCOLOR',function(){return this.EMISSIONCOLOR=Shader3D.propertyNameToID("u_EmissionColor");},'SMOOTHNESS',function(){return this.SMOOTHNESS=Shader3D.propertyNameToID("u_smoothness");},'SMOOTHNESSSCALE',function(){return this.SMOOTHNESSSCALE=Shader3D.propertyNameToID("u_smoothnessScale");},'OCCLUSIONSTRENGTH',function(){return this.OCCLUSIONSTRENGTH=Shader3D.propertyNameToID("u_occlusionStrength");},'NORMALSCALE',function(){return this.NORMALSCALE=Shader3D.propertyNameToID("u_normalScale");},'PARALLAXSCALE',function(){return this.PARALLAXSCALE=Shader3D.propertyNameToID("u_parallaxScale");},'TILINGOFFSET',function(){return this.TILINGOFFSET=Shader3D.propertyNameToID("u_TilingOffset");},'CULL',function(){return this.CULL=Shader3D.propertyNameToID("s_Cull");},'BLEND',function(){return this.BLEND=Shader3D.propertyNameToID("s_Blend");},'BLEND_SRC',function(){return this.BLEND_SRC=Shader3D.propertyNameToID("s_BlendSrc");},'BLEND_DST',function(){return this.BLEND_DST=Shader3D.propertyNameToID("s_BlendDst");},'DEPTH_TEST',function(){return this.DEPTH_TEST=Shader3D.propertyNameToID("s_DepthTest");},'DEPTH_WRITE',function(){return this.DEPTH_WRITE=Shader3D.propertyNameToID("s_DepthWrite");},'defaultMaterial',function(){return this.defaultMaterial=new PBRSpecularMaterial();},'shaderDefines',function(){return this.shaderDefines=new ShaderDefines(BaseMaterial.shaderDefines);}
- ]);
- return PBRSpecularMaterial;
- })(BaseMaterial)
- /**
- *<code>Rigidbody3D</code> 类用于创建刚体碰撞器。
- */
- //class laya.d3.physics.Rigidbody3D extends laya.d3.physics.PhysicsTriggerComponent
- var Rigidbody3D=(function(_super){
- function Rigidbody3D(collisionGroup,canCollideWith){
- /**@private */
- //this._nativeMotionState=null;
- /**@private */
- this._isKinematic=false;
- /**@private */
- this._mass=1.0;
- /**@private */
- this._angularDamping=0.0;
- /**@private */
- this._linearDamping=0.0;
- /**@private */
- this._overrideGravity=false;
- /**@private */
- this._detectCollisions=true;
- this._gravity=new Vector3(0,-10,0);
- this._totalTorque=new Vector3(0,0,0);
- this._linearVelocity=new Vector3();
- this._angularVelocity=new Vector3();
- this._linearFactor=new Vector3(1,1,1);
- this._angularFactor=new Vector3(1,1,1);
- (collisionGroup===void 0)&& (collisionGroup=/*laya.d3.utils.Physics3DUtils.COLLISIONFILTERGROUP_DEFAULTFILTER*/0x1);
- (canCollideWith===void 0)&& (canCollideWith=Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER);
- Rigidbody3D.__super.call(this,collisionGroup,canCollideWith);
- }
- __class(Rigidbody3D,'laya.d3.physics.Rigidbody3D',_super);
- var __proto=Rigidbody3D.prototype;
- /**
- *@private
- */
- __proto._updateMass=function(mass){
- if (this._nativeColliderObject && this._colliderShape){
- this._colliderShape._nativeShape.calculateLocalInertia(mass,Rigidbody3D._nativeInertia);
- this._nativeColliderObject.setMassProps(mass,Rigidbody3D._nativeInertia);
- this._nativeColliderObject.updateInertiaTensor();
- }
- }
- /**
- *@private
- *Dynamic刚体,初始化时调用一次。
- *Kinematic刚体,每次物理tick时调用(如果未进入睡眠状态),让物理引擎知道刚体位置。
- */
- __proto._delegateMotionStateGetWorldTransform=function(worldTransPointer){}
- /**
- *@private
- *Dynamic刚体,物理引擎每帧调用一次,用于更新渲染矩阵。
- */
- __proto._delegateMotionStateSetWorldTransform=function(worldTransPointer){
- var rigidBody=/*__JS__ */this._rigidbody;
- rigidBody._simulation._updatedRigidbodies++;
- var physics3D=Laya3D._physics3D;
- var worldTrans=physics3D.wrapPointer(worldTransPointer,physics3D.btTransform);
- rigidBody._updateTransformComponent(worldTrans);
- }
- /**
- *@private
- *Dynamic刚体,初始化时调用一次。
- *Kinematic刚体,每次物理tick时调用(如果未进入睡眠状态),让物理引擎知道刚体位置。
- *该函数只有在runtime下调用
- */
- __proto._delegateMotionStateGetWorldTransformNative=function(ridgidBody3D,worldTransPointer){}
- /**
- *@private
- *Dynamic刚体,物理引擎每帧调用一次,用于更新渲染矩阵。
- *该函数只有在runtime下调用
- */
- __proto._delegateMotionStateSetWorldTransformNative=function(rigidBody3D,worldTransPointer){
- var rigidBody=rigidBody3D;
- rigidBody._simulation._updatedRigidbodies++;
- var physics3D=Laya3D._physics3D;
- var worldTrans=physics3D.wrapPointer(worldTransPointer,physics3D.btTransform);
- rigidBody._updateTransformComponent(worldTrans);
- }
- /**
- *@inheritDoc
- */
- __proto._onScaleChange=function(scale){
- laya.d3.physics.PhysicsComponent.prototype._onScaleChange.call(this,scale);
- this._updateMass(this._isKinematic ? 0 :this._mass);
- }
- /**
- *@private
- */
- __proto._delegateMotionStateClear=function(){
- /*__JS__ */this._rigidbody=null;
- }
- /**
- *@inheritDoc
- */
- __proto._onAdded=function(){
- var physics3D=Laya3D._physics3D;
- var motionState=new physics3D.LayaMotionState();
- var isConchApp=/*__JS__ */(window.conch !=null);
- if (isConchApp && physics3D.LayaMotionState.prototype.setRigidbody){
- motionState.setRigidbody(this);
- motionState.setNativeGetWorldTransform(this._delegateMotionStateGetWorldTransformNative);
- motionState.setNativeSetWorldTransform(this._delegateMotionStateSetWorldTransformNative);
- }else {
- motionState.getWorldTransform=this._delegateMotionStateGetWorldTransform;
- motionState.setWorldTransform=this._delegateMotionStateSetWorldTransform;
- }
- motionState.clear=this._delegateMotionStateClear;
- motionState._rigidbody=this;
- this._nativeMotionState=motionState;
- var constructInfo=new physics3D.btRigidBodyConstructionInfo(0.0,motionState,null,Rigidbody3D._nativeVector3Zero);
- var btRigid=new physics3D.btRigidBody(constructInfo);
- btRigid.setUserIndex(this.id);
- this._nativeColliderObject=btRigid;
- _super.prototype._onAdded.call(this);
- this.mass=this._mass;
- this.linearFactor=this._linearFactor;
- this.angularFactor=this._angularFactor;
- this.linearDamping=this._linearDamping;
- this.angularDamping=this._angularDamping;
- this.overrideGravity=this._overrideGravity;
- this.gravity=this._gravity;
- this.isKinematic=this._isKinematic;
- physics3D.destroy(constructInfo);
- }
- /**
- *@inheritDoc
- */
- __proto._onShapeChange=function(colShape){
- laya.d3.physics.PhysicsComponent.prototype._onShapeChange.call(this,colShape);
- if (this._isKinematic){
- this._updateMass(0);
- }else {
- this._nativeColliderObject.setCenterOfMassTransform(this._nativeColliderObject.getWorldTransform());
- this._updateMass(this._mass);
- }
- }
- /**
- *@inheritDoc
- */
- __proto._parse=function(data){
- (data.friction !=null)&& (this.friction=data.friction);
- (data.rollingFriction !=null)&& (this.rollingFriction=data.rollingFriction);
- (data.restitution !=null)&& (this.restitution=data.restitution);
- (data.isTrigger !=null)&& (this.isTrigger=data.isTrigger);
- (data.mass !=null)&& (this.mass=data.mass);
- (data.isKinematic !=null)&& (this.isKinematic=data.isKinematic);
- (data.linearDamping !=null)&& (this.linearDamping=data.linearDamping);
- (data.angularDamping !=null)&& (this.angularDamping=data.angularDamping);
- (data.overrideGravity !=null)&& (this.overrideGravity=data.overrideGravity);
- if (data.gravity){
- this.gravity.fromArray(data.gravity);
- this.gravity=this.gravity;
- }
- laya.d3.physics.PhysicsComponent.prototype._parse.call(this,data);
- this._parseShape(data.shapes);
- }
- /**
- *@inheritDoc
- */
- __proto._onDestroy=function(){
- var physics3D=Laya3D._physics3D;
- this._nativeMotionState.clear();
- physics3D.destroy(this._nativeMotionState);
- laya.d3.physics.PhysicsComponent.prototype._onDestroy.call(this);
- this._nativeMotionState=null;
- this._gravity=null;
- this._totalTorque=null;
- this._linearVelocity=null;
- this._angularVelocity=null;
- this._linearFactor=null;
- this._angularFactor=null;
- }
- /**
- *@inheritDoc
- */
- __proto._addToSimulation=function(){
- this._simulation._addRigidBody(this,this._collisionGroup,this._detectCollisions ? this._canCollideWith :0);
- }
- /**
- *@inheritDoc
- */
- __proto._removeFromSimulation=function(){
- this._simulation._removeRigidBody(this);
- }
- /**
- *@inheritDoc
- */
- __proto._cloneTo=function(dest){
- _super.prototype._cloneTo.call(this,dest);
- var destRigidbody3D=dest;
- destRigidbody3D.isKinematic=this._isKinematic;
- destRigidbody3D.mass=this._mass;
- destRigidbody3D.gravity=this._gravity;
- destRigidbody3D.angularDamping=this._angularDamping;
- destRigidbody3D.linearDamping=this._linearDamping;
- destRigidbody3D.overrideGravity=this._overrideGravity;
- destRigidbody3D.linearVelocity=this._linearVelocity;
- destRigidbody3D.angularVelocity=this._angularVelocity;
- destRigidbody3D.linearFactor=this._linearFactor;
- destRigidbody3D.angularFactor=this._angularFactor;
- destRigidbody3D.detectCollisions=this._detectCollisions;
- }
- /**
- *应用作用力。
- *@param force 作用力。
- *@param localOffset 偏移,如果为null则为中心点
- */
- __proto.applyForce=function(force,localOffset){
- if (this._nativeColliderObject==null)
- throw "Attempted to call a Physics function that is avaliable only when the Entity has been already added to the Scene.";
- var nativeForce=Rigidbody3D._nativeTempVector30;
- nativeForce.setValue(-force.x,force.y,force.z);
- if (localOffset){
- var nativeOffset=Rigidbody3D._nativeTempVector31;
- nativeOffset.setValue(-localOffset.x,localOffset.y,localOffset.z);
- this._nativeColliderObject.applyForce(nativeForce,nativeOffset);
- }else {
- this._nativeColliderObject.applyCentralForce(nativeForce);
- }
- }
- /**
- *应用扭转力。
- *@param torque 扭转力。
- */
- __proto.applyTorque=function(torque){
- if (this._nativeColliderObject==null)
- throw "Attempted to call a Physics function that is avaliable only when the Entity has been already added to the Scene.";
- var nativeTorque=Rigidbody3D._nativeTempVector30;
- nativeTorque.setValue(-torque.x,torque.y,torque.z);
- this._nativeColliderObject.applyTorque(nativeTorque);
- }
- /**
- *应用冲量。
- *@param impulse 冲量。
- *@param localOffset 偏移,如果为null则为中心点。
- */
- __proto.applyImpulse=function(impulse,localOffset){
- if (this._nativeColliderObject==null)
- throw "Attempted to call a Physics function that is avaliable only when the Entity has been already added to the Scene.";
- Rigidbody3D._nativeImpulse.setValue(-impulse.x,impulse.y,impulse.z);
- if (localOffset){
- Rigidbody3D._nativeImpulseOffset.setValue(-localOffset.x,localOffset.y,localOffset.z);
- this._nativeColliderObject.applyImpulse(Rigidbody3D._nativeImpulse,Rigidbody3D._nativeImpulseOffset);
- }else {
- this._nativeColliderObject.applyCentralImpulse(Rigidbody3D._nativeImpulse);
- }
- }
- /**
- *应用扭转冲量。
- *@param torqueImpulse
- */
- __proto.applyTorqueImpulse=function(torqueImpulse){
- if (this._nativeColliderObject==null)
- throw "Attempted to call a Physics function that is avaliable only when the Entity has been already added to the Scene.";
- var nativeTorqueImpulse=Rigidbody3D._nativeTempVector30;
- nativeTorqueImpulse.setValue(-torqueImpulse.x,torqueImpulse.y,torqueImpulse.z);
- this._nativeColliderObject.applyTorqueImpulse(nativeTorqueImpulse);
- }
- /**
- *唤醒刚体。
- */
- __proto.wakeUp=function(){
- this._nativeColliderObject && (this._nativeColliderObject.activate(false));
- }
- /**
- *清除应用到刚体上的所有力。
- */
- __proto.clearForces=function(){
- var rigidBody=this._nativeColliderObject;
- if (rigidBody==null)
- throw "Attempted to call a Physics function that is avaliable only when the Entity has been already added to the Scene.";
- rigidBody.clearForces();
- var nativeZero=Rigidbody3D._nativeVector3Zero;
- rigidBody.setInterpolationAngularVelocity(nativeZero);
- rigidBody.setLinearVelocity(nativeZero);
- rigidBody.setInterpolationAngularVelocity(nativeZero);
- rigidBody.setAngularVelocity(nativeZero);
- }
- /**
- *设置刚体的角阻力。
- *@param value 角阻力。
- */
- /**
- *获取刚体的角阻力。
- *@return 角阻力。
- */
- __getset(0,__proto,'angularDamping',function(){
- return this._angularDamping;
- },function(value){
- this._angularDamping=value;
- if (this._nativeColliderObject)
- this._nativeColliderObject.setDamping(this._linearDamping,value);
- });
- /**
- *设置质量。
- *@param value 质量。
- */
- /**
- *获取质量。
- *@return 质量。
- */
- __getset(0,__proto,'mass',function(){
- return this._mass;
- },function(value){
- value=Math.max(value,1e-07);
- this._mass=value;
- (this._isKinematic)|| (this._updateMass(value));
- });
- /**
- *设置刚体的线阻力。
- *@param value 线阻力。
- */
- /**
- *获取刚体的线阻力。
- *@return 线阻力。
- */
- __getset(0,__proto,'linearDamping',function(){
- return this._linearDamping;
- },function(value){
- this._linearDamping=value;
- if (this._nativeColliderObject)
- this._nativeColliderObject.setDamping(value,this._angularDamping);
- });
- /**
- *设置是否为运动物体,如果为true仅可通过transform属性移动物体,而非其他力相关属性。
- *@param value 是否为运动物体。
- */
- /**
- *获取是否为运动物体,如果为true仅可通过transform属性移动物体,而非其他力相关属性。
- *@return 是否为运动物体。
- */
- __getset(0,__proto,'isKinematic',function(){
- return this._isKinematic;
- },function(value){
- this._isKinematic=value;
- var canInSimulation=!!(this._simulation && this._enabled && this._colliderShape);
- canInSimulation && this._removeFromSimulation();
- var natColObj=this._nativeColliderObject;
- var flags=natColObj.getCollisionFlags();
- if (value){
- flags=flags | 2;
- natColObj.setCollisionFlags(flags);
- this._nativeColliderObject.forceActivationState(4);
- this._enableProcessCollisions=false;
- this._updateMass(0);
- }else {
- if ((flags & 2)> 0)
- flags=flags ^ 2;
- natColObj.setCollisionFlags(flags);
- this._nativeColliderObject.setActivationState(1);
- this._enableProcessCollisions=true;
- this._updateMass(this._mass);
- };
- var nativeZero=Rigidbody3D._nativeVector3Zero;
- natColObj.setInterpolationLinearVelocity(nativeZero);
- natColObj.setLinearVelocity(nativeZero);
- natColObj.setInterpolationAngularVelocity(nativeZero);
- natColObj.setAngularVelocity(nativeZero);
- canInSimulation && this._addToSimulation();
- });
- /**
- *设置重力。
- *@param value 重力。
- */
- /**
- *获取重力。
- *@return 重力。
- */
- __getset(0,__proto,'gravity',function(){
- return this._gravity;
- },function(value){
- this._gravity=value;
- Rigidbody3D._nativeGravity.setValue(-value.x,value.y,value.z);
- this._nativeColliderObject.setGravity(Rigidbody3D._nativeGravity);
- });
- /**
- *设置是否重载重力。
- *@param value 是否重载重力。
- */
- /**
- *获取是否重载重力。
- *@return 是否重载重力。
- */
- __getset(0,__proto,'overrideGravity',function(){
- return this._overrideGravity;
- },function(value){
- this._overrideGravity=value;
- if (this._nativeColliderObject){
- var flag=this._nativeColliderObject.getFlags();
- if (value){
- if ((flag & 1)===0)
- this._nativeColliderObject.setFlags(flag | 1);
- }else {
- if ((flag & 1)> 0)
- this._nativeColliderObject.setFlags(flag ^ 1);
- }
- }
- });
- /**
- *获取总力。
- */
- __getset(0,__proto,'totalForce',function(){
- if (this._nativeColliderObject)
- return this._nativeColliderObject.getTotalForce();
- return null;
- });
- /**
- *设置线速度。
- *@param 线速度。
- */
- /**
- *获取线速度
- *@return 线速度
- */
- __getset(0,__proto,'linearVelocity',function(){
- if (this._nativeColliderObject)
- Utils3D._convertToLayaVec3(this._nativeColliderObject.getLinearVelocity(),this._linearVelocity,true);
- return this._linearVelocity;
- },function(value){
- this._linearVelocity=value;
- if (this._nativeColliderObject){
- var nativeValue=Rigidbody3D._nativeTempVector30;
- Utils3D._convertToBulletVec3(value,nativeValue,true);
- (this.isSleeping)&& (this.wakeUp());
- this._nativeColliderObject.setLinearVelocity(nativeValue);
- }
- });
- /**
- *设置是否进行碰撞检测。
- *@param value 是否进行碰撞检测。
- */
- /**
- *获取是否进行碰撞检测。
- *@return 是否进行碰撞检测。
- */
- __getset(0,__proto,'detectCollisions',function(){
- return this._detectCollisions;
- },function(value){
- if (this._detectCollisions!==value){
- this._detectCollisions=value;
- if (this._colliderShape && this._enabled && this._simulation){
- this._simulation._removeRigidBody(this);
- this._simulation._addRigidBody(this,this._collisionGroup,value ? this._canCollideWith :0);
- }
- }
- });
- /**
- *设置性因子。
- */
- /**
- *获取性因子。
- */
- __getset(0,__proto,'linearFactor',function(){
- if (this._nativeColliderObject)
- return this._linearFactor;
- return null;
- },function(value){
- this._linearFactor=value;
- if (this._nativeColliderObject){
- var nativeValue=Rigidbody3D._nativeTempVector30;
- Utils3D._convertToBulletVec3(value,nativeValue,false);
- this._nativeColliderObject.setLinearFactor(nativeValue);
- }
- });
- /**
- *设置角因子。
- */
- /**
- *获取角因子。
- */
- __getset(0,__proto,'angularFactor',function(){
- if (this._nativeColliderObject)
- return this._angularFactor;
- return null;
- },function(value){
- this._angularFactor=value;
- if (this._nativeColliderObject){
- var nativeValue=Rigidbody3D._nativeTempVector30;
- Utils3D._convertToBulletVec3(value,nativeValue,false);
- this._nativeColliderObject.setAngularFactor(nativeValue);
- }
- });
- /**
- *设置角速度。
- *@param 角速度
- */
- /**
- *获取角速度。
- *@return 角速度。
- */
- __getset(0,__proto,'angularVelocity',function(){
- if (this._nativeColliderObject)
- Utils3D._convertToLayaVec3(this._nativeColliderObject.getAngularVelocity(),this._angularVelocity,true);
- return this._angularVelocity;
- },function(value){
- this._angularVelocity=value;
- if (this._nativeColliderObject){
- var nativeValue=Rigidbody3D._nativeTempVector30;
- Utils3D._convertToBulletVec3(value,nativeValue,true);
- (this.isSleeping)&& (this.wakeUp());
- this._nativeColliderObject.setAngularVelocity(nativeValue);
- }
- });
- /**
- *获取刚体所有扭力。
- */
- __getset(0,__proto,'totalTorque',function(){
- if (this._nativeColliderObject){
- var nativeTotalTorque=this._nativeColliderObject.getTotalTorque();
- var totalTorque=this._totalTorque;
- totalTorque.x=-nativeTotalTorque.x;
- totalTorque.y=nativeTotalTorque.y;
- totalTorque.z=nativeTotalTorque.z;
- }
- return null;
- });
- /**
- *获取是否处于睡眠状态。
- *@return 是否处于睡眠状态。
- */
- __getset(0,__proto,'isSleeping',function(){
- if (this._nativeColliderObject)
- return this._nativeColliderObject.getActivationState()===/*laya.d3.physics.PhysicsComponent.ACTIVATIONSTATE_ISLAND_SLEEPING*/2;
- return false;
- });
- /**
- *设置刚体睡眠的线速度阈值。
- *@param value 刚体睡眠的线速度阈值。
- */
- /**
- *获取刚体睡眠的线速度阈值。
- *@return 刚体睡眠的线速度阈值。
- */
- __getset(0,__proto,'sleepLinearVelocity',function(){
- return this._nativeColliderObject.getLinearSleepingThreshold();
- },function(value){
- this._nativeColliderObject.setSleepingThresholds(value,this._nativeColliderObject.getAngularSleepingThreshold());
- });
- /**
- *设置刚体睡眠的角速度阈值。
- *@param value 刚体睡眠的角速度阈值。
- */
- /**
- *获取刚体睡眠的角速度阈值。
- *@return 刚体睡眠的角速度阈值。
- */
- __getset(0,__proto,'sleepAngularVelocity',function(){
- return this._nativeColliderObject.getAngularSleepingThreshold();
- },function(value){
- this._nativeColliderObject.setSleepingThresholds(this._nativeColliderObject.getLinearSleepingThreshold(),value);
- });
- Rigidbody3D.TYPE_STATIC=0;
- Rigidbody3D.TYPE_DYNAMIC=1;
- Rigidbody3D.TYPE_KINEMATIC=2;
- Rigidbody3D._BT_DISABLE_WORLD_GRAVITY=1;
- Rigidbody3D._BT_ENABLE_GYROPSCOPIC_FORCE=2;
- __static(Rigidbody3D,
- ['_nativeTempVector30',function(){return this._nativeTempVector30=new Laya3D._physics3D.btVector3(0,0,0);},'_nativeTempVector31',function(){return this._nativeTempVector31=new Laya3D._physics3D.btVector3(0,0,0);},'_nativeVector3Zero',function(){return this._nativeVector3Zero=new Laya3D._physics3D.btVector3(0,0,0);},'_nativeInertia',function(){return this._nativeInertia=new Laya3D._physics3D.btVector3(0,0,0);},'_nativeImpulse',function(){return this._nativeImpulse=new Laya3D._physics3D.btVector3(0,0,0);},'_nativeImpulseOffset',function(){return this._nativeImpulseOffset=new Laya3D._physics3D.btVector3(0,0,0);},'_nativeGravity',function(){return this._nativeGravity=new Laya3D._physics3D.btVector3(0,0,0);}
- ]);
- return Rigidbody3D;
- })(PhysicsTriggerComponent)
- /**
- *<code>PhysicsCollider</code> 类用于创建物理碰撞器。
- */
- //class laya.d3.physics.PhysicsCollider extends laya.d3.physics.PhysicsTriggerComponent
- var PhysicsCollider=(function(_super){
- /**
- *创建一个 <code>PhysicsCollider</code> 实例。
- *@param collisionGroup 所属碰撞组。
- *@param canCollideWith 可产生碰撞的碰撞组。
- */
- function PhysicsCollider(collisionGroup,canCollideWith){
- (collisionGroup===void 0)&& (collisionGroup=/*laya.d3.utils.Physics3DUtils.COLLISIONFILTERGROUP_DEFAULTFILTER*/0x1);
- (canCollideWith===void 0)&& (canCollideWith=Physics3DUtils.COLLISIONFILTERGROUP_ALLFILTER);
- PhysicsCollider.__super.call(this,collisionGroup,canCollideWith);
- }
- __class(PhysicsCollider,'laya.d3.physics.PhysicsCollider',_super);
- var __proto=PhysicsCollider.prototype;
- /**
- *@inheritDoc
- */
- __proto._addToSimulation=function(){
- this._simulation._addPhysicsCollider(this,this._collisionGroup,this._canCollideWith);
- }
- /**
- *@inheritDoc
- */
- __proto._removeFromSimulation=function(){
- this._simulation._removePhysicsCollider(this);
- }
- /**
- *@inheritDoc
- */
- __proto._onTransformChanged=function(flag){
- flag &=/*laya.d3.core.Transform3D.TRANSFORM_WORLDPOSITION*/0x08 | /*laya.d3.core.Transform3D.TRANSFORM_WORLDQUATERNION*/0x10 | /*laya.d3.core.Transform3D.TRANSFORM_WORLDSCALE*/0x20;
- if (flag){
- this._transformFlag |=flag;
- if (this._isValid()&& this._inPhysicUpdateListIndex===-1)
- this._simulation._physicsUpdateList.add(this);
- }
- }
- /**
- *@inheritDoc
- */
- __proto._parse=function(data){
- (data.friction !=null)&& (this.friction=data.friction);
- (data.rollingFriction !=null)&& (this.rollingFriction=data.rollingFriction);
- (data.restitution !=null)&& (this.restitution=data.restitution);
- (data.isTrigger !=null)&& (this.isTrigger=data.isTrigger);
- laya.d3.physics.PhysicsComponent.prototype._parse.call(this,data);
- this._parseShape(data.shapes);
- }
- /**
- *@inheritDoc
- */
- __proto._onAdded=function(){
- var physics3D=Laya3D._physics3D;
- var btColObj=new physics3D.btCollisionObject();
- btColObj.setUserIndex(this.id);
- btColObj.forceActivationState(5);
- var flags=btColObj.getCollisionFlags();
- if ((this.owner).isStatic){
- if ((flags & 2)> 0)
- flags=flags ^ 2;
- flags=flags | 1;
- }else {
- if ((flags & 1)> 0)
- flags=flags ^ 1;
- flags=flags | 2;
- }
- btColObj.setCollisionFlags(flags);
- this._nativeColliderObject=btColObj;
- _super.prototype._onAdded.call(this);
- }
- return PhysicsCollider;
- })(PhysicsTriggerComponent)
- /**
- *<code>SkinMeshRenderer</code> 类用于蒙皮渲染器。
- */
- //class laya.d3.core.SkinnedMeshRenderer extends laya.d3.core.MeshRenderer
- var SkinnedMeshRenderer=(function(_super){
- function SkinnedMeshRenderer(owner){
- /**@private */
- //this._cacheMesh=null;
- /**@private */
- //this._skinnedData=null;
- /**@private */
- //this._cacheAnimator=null;
- /**@private */
- //this._cacheRootBone=null;
- /**@private */
- //this._rootBone=null;
- /**@private */
- //this._cacheAvatar=null;
- /**@private */
- //this._cacheRootAnimationNode=null;
- /**@private [NATIVE]*/
- //this._cacheAnimationNodeIndices=null;
- this._bones=[];
- this._skinnedDataLoopMarks=[];
- this._localBounds=new Bounds(Vector3._ZERO,Vector3._ZERO);
- this._cacheAnimationNode=[];
- SkinnedMeshRenderer.__super.call(this,owner);
- }
- __class(SkinnedMeshRenderer,'laya.d3.core.SkinnedMeshRenderer',_super);
- var __proto=SkinnedMeshRenderer.prototype;
- /**
- *@private
- */
- __proto._computeSkinnedData=function(){
- if (this._cacheMesh && this._cacheAvatar || this._cacheMesh && this._cacheRootBone){
- var bindPoses=this._cacheMesh._inverseBindPoses;
- var meshBindPoseIndices=this._cacheMesh._bindPoseIndices;
- var pathMarks=this._cacheMesh._skinDataPathMarks;
- for (var i=0,n=this._cacheMesh.subMeshCount;i < n;i++){
- var subMeshBoneIndices=(this._cacheMesh._getSubMesh(i))._boneIndicesList;
- var subData=this._skinnedData[i];
- for (var j=0,m=subMeshBoneIndices.length;j < m;j++){
- var boneIndices=subMeshBoneIndices[j];
- if (Render.supportWebGLPlusAnimation)
- this._computeSubSkinnedDataNative(this._cacheAnimator._animationNodeWorldMatrixs,this._cacheAnimationNodeIndices,this._cacheMesh._inverseBindPosesBuffer,boneIndices,meshBindPoseIndices,subData[j]);
- else
- this._computeSubSkinnedData(bindPoses,boneIndices,meshBindPoseIndices,subData[j],pathMarks);
- }
- }
- }
- }
- /**
- *@private
- */
- __proto._computeSubSkinnedData=function(bindPoses,boneIndices,meshBindPoseInices,data,pathMarks){
- for (var k=0,q=boneIndices.length;k < q;k++){
- var index=boneIndices[k];
- if (this._skinnedDataLoopMarks[index]===Stat.loopCount){
- var p=pathMarks[index];
- var preData=this._skinnedData[p[0]][p[1]];
- var srcIndex=p[2] *16;
- var dstIndex=k *16;
- for (var d=0;d < 16;d++)
- data[dstIndex+d]=preData[srcIndex+d];
- }else {
- if (this._cacheRootBone){
- var boneIndex=meshBindPoseInices[index];
- Utils3D._mulMatrixArray(this._bones[boneIndex].transform.worldMatrix.elements,bindPoses[boneIndex],data,k *16);
- }
- else{
- Utils3D._mulMatrixArray(this._cacheAnimationNode[index].transform.getWorldMatrix(),bindPoses[meshBindPoseInices[index]],data,k *16);
- }
- this._skinnedDataLoopMarks[index]=Stat.loopCount;
- }
- }
- }
- /**
- *@private
- */
- __proto._boundChange=function(){
- this._boundsChange=true;
- }
- /**
- *@private
- */
- __proto._onMeshChange=function(value){
- _super.prototype._onMeshChange.call(this,value);
- this._cacheMesh=value;
- var subMeshCount=value.subMeshCount;
- this._skinnedData=__newvec(subMeshCount);
- this._skinnedDataLoopMarks.length=(value)._bindPoseIndices.length;
- for (var i=0;i < subMeshCount;i++){
- var subBoneIndices=(value._getSubMesh(i))._boneIndicesList;
- var subCount=subBoneIndices.length;
- var subData=this._skinnedData[i]=__newvec(subCount);
- for (var j=0;j < subCount;j++)
- subData[j]=new Float32Array(subBoneIndices[j].length *16);
- }
- if (!this._bones)
- (this._cacheAvatar && value)&& (this._getCacheAnimationNodes());
- }
- /**
- *@private
- */
- __proto._setCacheAnimator=function(animator){
- this._cacheAnimator=animator;
- this._defineDatas.add(SkinnedMeshSprite3D.SHADERDEFINE_BONE);
- this._setRootNode();
- }
- /**
- *@inheritDoc
- */
- __proto._calculateBoundingBox=function(){
- if (this._cacheRootBone){
- this._localBounds._tranform(this._cacheRootBone.transform.worldMatrix,this._bounds);
- }else {
- if (this._cacheAnimator && this._rootBone){
- var worldMat=SkinnedMeshRenderer._tempMatrix4x4;
- Utils3D.matrix4x4MultiplyMFM((this._cacheAnimator.owner).transform.worldMatrix,this._cacheRootAnimationNode.transform.getWorldMatrix(),worldMat);
- this._localBounds._tranform(worldMat,this._bounds);
- }else {
- _super.prototype._calculateBoundingBox.call(this);
- }
- }
- if (Render.supportWebGLPlusCulling){
- var min=this._bounds.getMin();
- var max=this._bounds.getMax();
- var buffer=FrustumCulling._cullingBuffer;
- buffer[this._cullingBufferIndex+1]=min.x;
- buffer[this._cullingBufferIndex+2]=min.y;
- buffer[this._cullingBufferIndex+3]=min.z;
- buffer[this._cullingBufferIndex+4]=max.x;
- buffer[this._cullingBufferIndex+5]=max.y;
- buffer[this._cullingBufferIndex+6]=max.z;
- }
- }
- /**
- *@inheritDoc
- */
- __proto._changeRenderObjectsByMesh=function(mesh){
- var count=mesh.subMeshCount;
- this._renderElements.length=count;
- for (var i=0;i < count;i++){
- var renderElement=this._renderElements[i];
- if (!renderElement){
- var material=this.sharedMaterials[i];
- renderElement=this._renderElements[i]=new RenderElement();
- renderElement.setTransform(this._owner._transform);
- renderElement.render=this;
- renderElement.material=material ? material :BlinnPhongMaterial.defaultMaterial;
- }
- renderElement.setGeometry(mesh._getSubMesh(i));
- }
- }
- /**
- *@inheritDoc
- */
- __proto._renderUpdate=function(context,transform){
- if (this._cacheAnimator){
- this._computeSkinnedData();
- if (this._cacheRootBone){
- this._shaderValues.setMatrix4x4(Sprite3D.WORLDMATRIX,Matrix4x4.DEFAULT);
- }else {
- var aniOwnerTrans=(this._cacheAnimator.owner)._transform;
- this._shaderValues.setMatrix4x4(Sprite3D.WORLDMATRIX,aniOwnerTrans.worldMatrix);
- }
- }else {
- this._shaderValues.setMatrix4x4(Sprite3D.WORLDMATRIX,transform.worldMatrix);
- }
- }
- /**
- *@inheritDoc
- */
- __proto._renderUpdateWithCamera=function(context,transform){
- var projectionView=context.projectionViewMatrix;
- if (this._cacheRootBone){
- this._shaderValues.setMatrix4x4(Sprite3D.MVPMATRIX,projectionView);
- }else {
- if (this._cacheAnimator){
- var aniOwnerTrans=(this._cacheAnimator.owner)._transform;
- Matrix4x4.multiply(projectionView,aniOwnerTrans.worldMatrix,this._projectionViewWorldMatrix);
- }else {
- Matrix4x4.multiply(projectionView,transform.worldMatrix,this._projectionViewWorldMatrix);
- }
- this._shaderValues.setMatrix4x4(Sprite3D.MVPMATRIX,this._projectionViewWorldMatrix);
- }
- }
- /**
- *@inheritDoc
- */
- __proto._destroy=function(){
- _super.prototype._destroy.call(this);
- if (this._cacheRootBone){
- this._cacheRootBone.transform.off(/*laya.events.Event.TRANSFORM_CHANGED*/"transformchanged",this,this._boundChange);
- }else {
- if (this._cacheRootAnimationNode)
- this._cacheRootAnimationNode.transform.off(/*laya.events.Event.TRANSFORM_CHANGED*/"transformchanged",this,this._boundChange);
- }
- }
- /**
- *@private
- */
- __proto._setRootBone=function(name){
- this._rootBone=name;
- this._setRootNode();
- }
- /**
- *@private
- */
- __proto._setRootNode=function(){
- var rootNode;
- if (this._cacheAnimator && this._rootBone && this._cacheAvatar)
- rootNode=this._cacheAnimator._avatarNodeMap[this._rootBone];
- else
- rootNode=null;
- if (this._cacheRootAnimationNode !=rootNode){
- this._boundChange();
- if (this._cacheRootAnimationNode)
- this._cacheRootAnimationNode.transform.off(/*laya.events.Event.TRANSFORM_CHANGED*/"transformchanged",this,this._boundChange);
- (rootNode)&&(rootNode.transform.on(/*laya.events.Event.TRANSFORM_CHANGED*/"transformchanged",this,this._boundChange));
- this._cacheRootAnimationNode=rootNode;
- }
- }
- /**
- *@private
- */
- __proto._getCacheAnimationNodes=function(){
- var meshBoneNames=this._cacheMesh._boneNames;
- var bindPoseIndices=this._cacheMesh._bindPoseIndices;
- var innerBindPoseCount=bindPoseIndices.length;
- if (!Render.supportWebGLPlusAnimation){
- this._cacheAnimationNode.length=innerBindPoseCount;
- var nodeMap=this._cacheAnimator._avatarNodeMap;
- for (var i=0;i < innerBindPoseCount;i++){
- var node=nodeMap[meshBoneNames[bindPoseIndices[i]]];
- this._cacheAnimationNode[i]=node;
- }
- }else {
- this._cacheAnimationNodeIndices=new Uint16Array(innerBindPoseCount);
- var nodeMapC=this._cacheAnimator._avatarNodeMap;
- for (i=0;i < innerBindPoseCount;i++){
- var nodeC=nodeMapC[meshBoneNames[bindPoseIndices[i]]];
- this._cacheAnimationNodeIndices[i]=nodeC._worldMatrixIndex;
- }
- }
- }
- /**
- *@private
- */
- __proto._setCacheAvatar=function(value){
- if (this._cacheAvatar!==value){
- if (this._cacheMesh){
- this._cacheAvatar=value;
- if (value){
- this._defineDatas.add(SkinnedMeshSprite3D.SHADERDEFINE_BONE);
- this._getCacheAnimationNodes();
- }
- }else {
- this._cacheAvatar=value;
- }
- this._setRootNode();
- }
- }
- /**
- *@private [NATIVE]
- */
- __proto._computeSubSkinnedDataNative=function(worldMatrixs,cacheAnimationNodeIndices,inverseBindPosesBuffer,boneIndices,bindPoseInices,data){
- LayaGL.instance.computeSubSkinnedData(worldMatrixs,cacheAnimationNodeIndices,inverseBindPosesBuffer,boneIndices,bindPoseInices,data);
- }
- /**
- *设置局部边界。
- *@param value 边界
- */
- /**
- *获取局部边界。
- *@return 边界。
- */
- __getset(0,__proto,'localBounds',function(){
- return this._localBounds;
- },function(value){
- this._localBounds=value;
- });
- /**
- *设置根节点。
- *@param value 根节点。
- */
- /**
- *获取根节点。
- *@return 根节点。
- */
- __getset(0,__proto,'rootBone',function(){
- return this._cacheRootBone;
- },function(value){
- if (this._cacheRootBone !=value){
- if (this._cacheRootBone)
- this._cacheRootBone.transform.off(/*laya.events.Event.TRANSFORM_CHANGED*/"transformchanged",this,this._boundChange);
- value.transform.on(/*laya.events.Event.TRANSFORM_CHANGED*/"transformchanged",this,this._boundChange);
- this._cacheRootBone=value;
- this._boundChange();
- }
- });
- /**
- *用于蒙皮的骨骼。
- */
- __getset(0,__proto,'bones',function(){
- return this._bones;
- });
- __static(SkinnedMeshRenderer,
- ['_tempMatrix4x4',function(){return this._tempMatrix4x4=new Matrix4x4();}
- ]);
- return SkinnedMeshRenderer;
- })(MeshRenderer)
- /**
- //*<code>RenderTexture</code> 类用于创建渲染目标。
- */
- //class laya.d3.resource.RenderTexture extends laya.resource.BaseTexture
- var RenderTexture=(function(_super){
- function RenderTexture(width,height,format,depthStencilFormat){
- /**@private */
- //this._frameBuffer=null;
- /**@private */
- //this._depthStencilBuffer=null;
- /**@private */
- //this._depthStencilFormat=0;
- (format===void 0)&& (format=0);
- (depthStencilFormat===void 0)&& (depthStencilFormat=/*laya.resource.BaseTexture.FORMAT_DEPTH_16*/0);
- RenderTexture.__super.call(this,format,false);
- this._glTextureType=/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1;
- this._width=width;
- this._height=height;
- this._depthStencilFormat=depthStencilFormat;
- this._create(width,height);
- }
- __class(RenderTexture,'laya.d3.resource.RenderTexture',_super);
- var __proto=RenderTexture.prototype;
- /**
- *@private
- */
- __proto._create=function(width,height){
- var gl=LayaGL.instance;
- this._frameBuffer=gl.createFramebuffer();
- WebGLContext.bindTexture(gl,this._glTextureType,this._glTexture);
- var glFormat=this._getGLFormat();
- gl.texImage2D(this._glTextureType,0,glFormat,width,height,0,glFormat,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,null);
- this._setGPUMemory(width *height *4);
- gl.bindFramebuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,this._frameBuffer);
- gl.framebufferTexture2D(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,/*laya.webgl.WebGLContext.COLOR_ATTACHMENT0*/0x8CE0,/*laya.webgl.WebGLContext.TEXTURE_2D*/0x0DE1,this._glTexture,0);
- if (this._depthStencilFormat!==/*laya.resource.BaseTexture.FORMAT_DEPTHSTENCIL_NONE*/3){
- this._depthStencilBuffer=gl.createRenderbuffer();
- gl.bindRenderbuffer(/*laya.webgl.WebGLContext.RENDERBUFFER*/0x8D41,this._depthStencilBuffer);
- switch (this._depthStencilFormat){
- case /*laya.resource.BaseTexture.FORMAT_DEPTH_16*/0:
- gl.renderbufferStorage(/*laya.webgl.WebGLContext.RENDERBUFFER*/0x8D41,/*laya.webgl.WebGLContext.DEPTH_COMPONENT16*/0x81A5,width,height);
- gl.framebufferRenderbuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,/*laya.webgl.WebGLContext.DEPTH_ATTACHMENT*/0x8D00,/*laya.webgl.WebGLContext.RENDERBUFFER*/0x8D41,this._depthStencilBuffer);
- break ;
- case /*laya.resource.BaseTexture.FORMAT_STENCIL_8*/1:
- gl.renderbufferStorage(/*laya.webgl.WebGLContext.RENDERBUFFER*/0x8D41,/*laya.webgl.WebGLContext.STENCIL_INDEX8*/0x8D48,width,height);
- gl.framebufferRenderbuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,/*laya.webgl.WebGLContext.STENCIL_ATTACHMENT*/0x8D20,/*laya.webgl.WebGLContext.RENDERBUFFER*/0x8D41,this._depthStencilBuffer);
- break ;
- case /*laya.resource.BaseTexture.FORMAT_DEPTHSTENCIL_16_8*/2:
- gl.renderbufferStorage(/*laya.webgl.WebGLContext.RENDERBUFFER*/0x8D41,/*laya.webgl.WebGLContext.DEPTH_STENCIL*/0x84F9,width,height);
- gl.framebufferRenderbuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,/*laya.webgl.WebGLContext.DEPTH_STENCIL_ATTACHMENT*/0x821A,/*laya.webgl.WebGLContext.RENDERBUFFER*/0x8D41,this._depthStencilBuffer);
- break ;
- default :
- throw "RenderTexture: unkonw depth format.";
- }
- }
- gl.bindFramebuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,null);
- gl.bindRenderbuffer(/*laya.webgl.WebGLContext.RENDERBUFFER*/0x8D41,null);
- this._setWarpMode(/*laya.webgl.WebGLContext.TEXTURE_WRAP_S*/0x2802,this._wrapModeU);
- this._setWarpMode(/*laya.webgl.WebGLContext.TEXTURE_WRAP_T*/0x2803,this._wrapModeV);
- this._setFilterMode(this._filterMode);
- this._setAnisotropy(this._anisoLevel);
- this._readyed=true;
- this._activeResource();
- }
- /**
- *@private
- */
- __proto._start=function(){
- LayaGL.instance.bindFramebuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,this._frameBuffer);
- RenderTexture._currentActive=this;
- this._readyed=false;
- }
- /**
- *@private
- */
- __proto._end=function(){
- LayaGL.instance.bindFramebuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,null);
- RenderTexture._currentActive=null;
- this._readyed=true;
- }
- /**
- *获得像素数据。
- *@param x X像素坐标。
- *@param y Y像素坐标。
- *@param width 宽度。
- *@param height 高度。
- *@return 像素数据。
- */
- __proto.getData=function(x,y,width,height,out){
- if (Render.isConchApp && /*__JS__ */conchConfig.threadMode==2){
- throw "native 2 thread mode use getDataAsync";
- };
- var gl=LayaGL.instance;
- gl.bindFramebuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,this._frameBuffer);
- var canRead=(gl.checkFramebufferStatus(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40)===/*laya.webgl.WebGLContext.FRAMEBUFFER_COMPLETE*/0x8CD5);
- if (!canRead){
- gl.bindFramebuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,null);
- return null;
- }
- gl.readPixels(x,y,width,height,/*laya.webgl.WebGLContext.RGBA*/0x1908,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,out);
- gl.bindFramebuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,null);
- return out;
- }
- /**
- *native多线程
- */
- __proto.getDataAsync=function(x,y,width,height,callBack){
- var gl=LayaGL.instance;
- gl.bindFramebuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,this._frameBuffer);
- gl.readPixelsAsync(x,y,width,height,/*laya.webgl.WebGLContext.RGBA*/0x1908,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,function(data){
- /*__JS__ */callBack(new Uint8Array(data));
- });
- gl.bindFramebuffer(/*laya.webgl.WebGLContext.FRAMEBUFFER*/0x8D40,null);
- }
- /**
- *@inheritDoc
- */
- __proto._disposeResource=function(){
- if (this._frameBuffer){
- var gl=LayaGL.instance;
- gl.deleteTexture(this._glTexture);
- gl.deleteFramebuffer(this._frameBuffer);
- gl.deleteRenderbuffer(this._depthStencilBuffer);
- this._glTexture=null;
- this._frameBuffer=null;
- this._depthStencilBuffer=null;
- this._setGPUMemory(0);
- }
- }
- /**
- *获取深度格式。
- *@return 深度格式。
- */
- __getset(0,__proto,'depthStencilFormat',function(){
- return this._depthStencilFormat;
- });
- /**
- *@inheritDoc
- */
- __getset(0,__proto,'defaulteTexture',function(){
- return Texture2D.grayTexture;
- });
- /**
- *获取当前激活的Rendertexture。
- */
- __getset(1,RenderTexture,'currentActive',function(){
- return RenderTexture._currentActive;
- },laya.resource.BaseTexture._$SET_currentActive);
- RenderTexture.getTemporary=function(width,height,format,depthStencilFormat,filterMode){
- (format===void 0)&& (format=/*laya.resource.BaseTexture.FORMAT_R8G8B8*/0);
- (depthStencilFormat===void 0)&& (depthStencilFormat=/*laya.resource.BaseTexture.FORMAT_DEPTH_16*/0);
- (filterMode===void 0)&& (filterMode=/*laya.resource.BaseTexture.FILTERMODE_BILINEAR*/1);
- var key=filterMode *10000000+depthStencilFormat *1000000+format *100000+10000 *height+width;
- var textures=RenderTexture._temporaryMap[key];
- if (!textures || textures && textures.length===0){
- var renderTexture=new RenderTexture(width,height,format,depthStencilFormat);
- renderTexture.filterMode=filterMode;
- return renderTexture;
- }else {
- return textures.pop();
- }
- }
- RenderTexture.setReleaseTemporary=function(renderTexture){
- var key=renderTexture.filterMode *10000000+renderTexture.depthStencilFormat *1000000+renderTexture.format *100000+10000 *renderTexture.height+renderTexture.width;
- var textures=RenderTexture._temporaryMap[key];
- (textures)|| (RenderTexture._temporaryMap[key]=textures=[]);
- textures.push(renderTexture);
- }
- RenderTexture._temporaryMap={};
- RenderTexture._currentActive=null;
- return RenderTexture;
- })(BaseTexture)
- /**
- *<code>TextureCube</code> 类用于生成立方体纹理。
- */
- //class laya.d3.resource.TextureCube extends laya.resource.BaseTexture
- var TextureCube=(function(_super){
- function TextureCube(format,mipmap){
- /**@private */
- //this._premultiplyAlpha=0;
- (format===void 0)&& (format=0);
- (mipmap===void 0)&& (mipmap=false);
- TextureCube.__super.call(this,format,mipmap);
- this._glTextureType=/*laya.webgl.WebGLContext.TEXTURE_CUBE_MAP*/0x8513;
- }
- __class(TextureCube,'laya.d3.resource.TextureCube',_super);
- var __proto=TextureCube.prototype;
- /**
- *通过六张图片源填充纹理。
- *@param 图片源数组。
- */
- __proto.setSixSideImageSources=function(source,premultiplyAlpha){
- (premultiplyAlpha===void 0)&& (premultiplyAlpha=false);
- var width=0;
- var height=0;
- for (var i=0;i < 6;i++){
- var img=source[i];
- if (!img){
- console.log("TextureCube: image Source can't be null.");
- return;
- };
- var nextWidth=img.width;
- var nextHeight=img.height;
- if (i > 0){
- if (width!==nextWidth){
- console.log("TextureCube: each side image's width and height must same.");
- return;
- }
- }
- width=nextWidth;
- height=nextHeight;
- if (width!==height){
- console.log("TextureCube: each side image's width and height must same.");
- return;
- }
- }
- this._width=width;
- this._height=height;
- var gl=LayaGL.instance;
- WebGLContext.bindTexture(gl,this._glTextureType,this._glTexture);
- var glFormat=this._getGLFormat();
- if (!Render.isConchApp){
- (premultiplyAlpha)&& (gl.pixelStorei(/*laya.webgl.WebGLContext.UNPACK_PREMULTIPLY_ALPHA_WEBGL*/0x9241,true));
- gl.texImage2D(/*laya.webgl.WebGLContext.TEXTURE_CUBE_MAP_POSITIVE_Z*/0x8519,0,glFormat,glFormat,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,source[0]);
- gl.texImage2D(/*laya.webgl.WebGLContext.TEXTURE_CUBE_MAP_NEGATIVE_Z*/0x851A,0,glFormat,glFormat,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,source[1]);
- gl.texImage2D(/*laya.webgl.WebGLContext.TEXTURE_CUBE_MAP_POSITIVE_X*/0x8515,0,glFormat,glFormat,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,source[2]);
- gl.texImage2D(/*laya.webgl.WebGLContext.TEXTURE_CUBE_MAP_NEGATIVE_X*/0x8516,0,glFormat,glFormat,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,source[3]);
- gl.texImage2D(/*laya.webgl.WebGLContext.TEXTURE_CUBE_MAP_POSITIVE_Y*/0x8517,0,glFormat,glFormat,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,source[4]);
- gl.texImage2D(/*laya.webgl.WebGLContext.TEXTURE_CUBE_MAP_NEGATIVE_Y*/0x8518,0,glFormat,glFormat,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,source[5]);
- (premultiplyAlpha)&& (gl.pixelStorei(/*laya.webgl.WebGLContext.UNPACK_PREMULTIPLY_ALPHA_WEBGL*/0x9241,false));
- }else {
- if (premultiplyAlpha==true){
- for (var j=0;j < 6;j++)
- source[j].setPremultiplyAlpha(premultiplyAlpha);
- }
- gl.texImage2D(/*laya.webgl.WebGLContext.TEXTURE_CUBE_MAP_POSITIVE_Z*/0x8519,0,/*laya.webgl.WebGLContext.RGBA*/0x1908,/*laya.webgl.WebGLContext.RGBA*/0x1908,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,source[0]);
- gl.texImage2D(/*laya.webgl.WebGLContext.TEXTURE_CUBE_MAP_NEGATIVE_Z*/0x851A,0,/*laya.webgl.WebGLContext.RGBA*/0x1908,/*laya.webgl.WebGLContext.RGBA*/0x1908,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,source[1]);
- gl.texImage2D(/*laya.webgl.WebGLContext.TEXTURE_CUBE_MAP_POSITIVE_X*/0x8515,0,/*laya.webgl.WebGLContext.RGBA*/0x1908,/*laya.webgl.WebGLContext.RGBA*/0x1908,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,source[2]);
- gl.texImage2D(/*laya.webgl.WebGLContext.TEXTURE_CUBE_MAP_NEGATIVE_X*/0x8516,0,/*laya.webgl.WebGLContext.RGBA*/0x1908,/*laya.webgl.WebGLContext.RGBA*/0x1908,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,source[3]);
- gl.texImage2D(/*laya.webgl.WebGLContext.TEXTURE_CUBE_MAP_POSITIVE_Y*/0x8517,0,/*laya.webgl.WebGLContext.RGBA*/0x1908,/*laya.webgl.WebGLContext.RGBA*/0x1908,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,source[4]);
- gl.texImage2D(/*laya.webgl.WebGLContext.TEXTURE_CUBE_MAP_NEGATIVE_Y*/0x8518,0,/*laya.webgl.WebGLContext.RGBA*/0x1908,/*laya.webgl.WebGLContext.RGBA*/0x1908,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,source[5]);
- }
- if (this._mipmap && this._isPot(width)&& this._isPot(height)){
- gl.generateMipmap(this._glTextureType);
- this._setGPUMemory(width *height *4 *(1+1 / 3)*6);
- }else {
- this._setGPUMemory(width *height *4 *6);
- }
- this._setWarpMode(/*laya.webgl.WebGLContext.TEXTURE_WRAP_S*/0x2802,this._wrapModeU);
- this._setWarpMode(/*laya.webgl.WebGLContext.TEXTURE_WRAP_T*/0x2803,this._wrapModeV);
- this._setFilterMode(this._filterMode);
- this._readyed=true;
- this._activeResource();
- }
- /**
- *通过六张图片源填充纹理。
- *@param 图片源数组。
- */
- __proto.setSixSidePixels=function(width,height,pixels){
- if (width <=0 || height <=0)
- throw new Error("TextureCube:width or height must large than 0.");
- if (!pixels)
- throw new Error("TextureCube:pixels can't be null.");
- this._width=width;
- this._height=height;
- var gl=LayaGL.instance;
- WebGLContext.bindTexture(gl,this._glTextureType,this._glTexture);
- var glFormat=this._getGLFormat();
- gl.texImage2D(/*laya.webgl.WebGLContext.TEXTURE_CUBE_MAP_POSITIVE_Z*/0x8519,0,glFormat,width,height,0,glFormat,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,pixels[0]);
- gl.texImage2D(/*laya.webgl.WebGLContext.TEXTURE_CUBE_MAP_NEGATIVE_Z*/0x851A,0,glFormat,width,height,0,glFormat,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,pixels[1]);
- gl.texImage2D(/*laya.webgl.WebGLContext.TEXTURE_CUBE_MAP_POSITIVE_X*/0x8515,0,glFormat,width,height,0,glFormat,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,pixels[2]);
- gl.texImage2D(/*laya.webgl.WebGLContext.TEXTURE_CUBE_MAP_NEGATIVE_X*/0x8516,0,glFormat,width,height,0,glFormat,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,pixels[3]);
- gl.texImage2D(/*laya.webgl.WebGLContext.TEXTURE_CUBE_MAP_POSITIVE_Y*/0x8517,0,glFormat,width,height,0,glFormat,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,pixels[4]);
- gl.texImage2D(/*laya.webgl.WebGLContext.TEXTURE_CUBE_MAP_NEGATIVE_Y*/0x8518,0,glFormat,width,height,0,glFormat,/*laya.webgl.WebGLContext.UNSIGNED_BYTE*/0x1401,pixels[5]);
- if (this._mipmap && this._isPot(width)&& this._isPot(height)){
- gl.generateMipmap(this._glTextureType);
- this._setGPUMemory(width *height *4 *(1+1 / 3)*6);
- }else {
- this._setGPUMemory(width *height *4 *6);
- }
- this._setWarpMode(/*laya.webgl.WebGLContext.TEXTURE_WRAP_S*/0x2802,this._wrapModeU);
- this._setWarpMode(/*laya.webgl.WebGLContext.TEXTURE_WRAP_T*/0x2803,this._wrapModeV);
- this._setFilterMode(this._filterMode);
- this._readyed=true;
- this._activeResource();
- }
- /**
- *@inheritDoc
- */
- __proto._recoverResource=function(){}
- /**
- *@inheritDoc
- */
- __getset(0,__proto,'defaulteTexture',function(){
- return TextureCube.grayTexture;
- });
- TextureCube.__init__=function(){
- var pixels=new Uint8Array(3);
- pixels[0]=128;
- pixels[1]=128;
- pixels[2]=128;
- TextureCube.grayTexture=new TextureCube(0,false);
- TextureCube.grayTexture.setSixSidePixels(1,1,[pixels,pixels,pixels,pixels,pixels,pixels]);
- TextureCube.grayTexture.lock=true;
- }
- TextureCube._parse=function(data,propertyParams,constructParams){
- var texture=constructParams ? new TextureCube(constructParams[0],constructParams[1]):new TextureCube();
- texture.setSixSideImageSources(data);
- return texture;
- }
- TextureCube.load=function(url,complete){
- Laya.loader.create(url,complete,null,/*Laya3D.TEXTURECUBE*/"TEXTURECUBE");
- }
- TextureCube.grayTexture=null;
- return TextureCube;
- })(BaseTexture)
- /**
- *<code>MeshSprite3D</code> 类用于创建网格。
- */
- //class laya.d3.core.MeshSprite3D extends laya.d3.core.RenderableSprite3D
- var MeshSprite3D=(function(_super){
- function MeshSprite3D(mesh,name){
- /**@private */
- //this._meshFilter=null;
- MeshSprite3D.__super.call(this,name);
- this._meshFilter=new MeshFilter(this);
- this._render=new MeshRenderer(this);
- (mesh)&& (this._meshFilter.sharedMesh=mesh);
- }
- __class(MeshSprite3D,'laya.d3.core.MeshSprite3D',_super);
- var __proto=MeshSprite3D.prototype;
- /**
- *@inheritDoc
- */
- __proto._parse=function(data,spriteMap){
- laya.d3.core.Sprite3D.prototype._parse.call(this,data,spriteMap);
- var render=this.meshRenderer;
- var lightmapIndex=data.lightmapIndex;
- (lightmapIndex !=null)&& (render.lightmapIndex=lightmapIndex);
- var lightmapScaleOffsetArray=data.lightmapScaleOffset;
- (lightmapScaleOffsetArray)&& (render.lightmapScaleOffset=new Vector4(lightmapScaleOffsetArray[0],lightmapScaleOffsetArray[1],lightmapScaleOffsetArray[2],lightmapScaleOffsetArray[3]));
- (data.meshPath !=undefined)&& (this.meshFilter.sharedMesh=Loader.getRes(data.meshPath));
- (data.enableRender !=undefined)&& (this.meshRenderer.enable=data.enableRender);
- var materials=data.materials;
- if (materials){
- var sharedMaterials=render.sharedMaterials;
- var materialCount=materials.length;
- sharedMaterials.length=materialCount;
- for (var i=0;i < materialCount;i++){
- sharedMaterials[i]=Loader.getRes(materials[i].path);
- }
- render.sharedMaterials=sharedMaterials;
- }
- }
- /**
- *@inheritDoc
- */
- __proto._addToInitStaticBatchManager=function(){
- MeshRenderStaticBatchManager.instance._addBatchSprite(this);
- }
- /**
- *@inheritDoc
- */
- __proto._cloneTo=function(destObject,rootSprite,dstSprite){
- var meshSprite3D=destObject;
- meshSprite3D._meshFilter.sharedMesh=this._meshFilter.sharedMesh;
- var meshRender=this._render;
- var destMeshRender=meshSprite3D._render;
- destMeshRender.enable=meshRender.enable;
- destMeshRender.sharedMaterials=meshRender.sharedMaterials;
- destMeshRender.castShadow=meshRender.castShadow;
- var lightmapScaleOffset=meshRender.lightmapScaleOffset;
- lightmapScaleOffset && (destMeshRender.lightmapScaleOffset=lightmapScaleOffset.clone());
- destMeshRender.lightmapIndex=meshRender.lightmapIndex;
- destMeshRender.receiveShadow=meshRender.receiveShadow;
- destMeshRender.sortingFudge=meshRender.sortingFudge;
- laya.d3.core.Sprite3D.prototype._cloneTo.call(this,destObject,rootSprite,dstSprite);
- }
- /**
- *@inheritDoc
- */
- __proto.destroy=function(destroyChild){
- (destroyChild===void 0)&& (destroyChild=true);
- if (this.destroyed)
- return;
- _super.prototype.destroy.call(this,destroyChild);
- this._meshFilter.destroy();
- }
- /**
- *获取网格过滤器。
- *@return 网格过滤器。
- */
- __getset(0,__proto,'meshFilter',function(){
- return this._meshFilter;
- });
- /**
- *获取网格渲染器。
- *@return 网格渲染器。
- */
- __getset(0,__proto,'meshRenderer',function(){
- return this._render;
- });
- MeshSprite3D.__init__=function(){
- MeshSprite3D.SHADERDEFINE_UV0=MeshSprite3D.shaderDefines.registerDefine("UV");
- MeshSprite3D.SHADERDEFINE_COLOR=MeshSprite3D.shaderDefines.registerDefine("COLOR");
- MeshSprite3D.SHADERDEFINE_UV1=MeshSprite3D.shaderDefines.registerDefine("UV1");
- MeshSprite3D.SHADERDEFINE_GPU_INSTANCE=MeshSprite3D.shaderDefines.registerDefine("GPU_INSTANCE");
- StaticBatchManager._registerManager(MeshRenderStaticBatchManager.instance);
- DynamicBatchManager._registerManager(MeshRenderDynamicBatchManager.instance);
- }
- MeshSprite3D.SHADERDEFINE_UV0=0;
- MeshSprite3D.SHADERDEFINE_COLOR=0;
- MeshSprite3D.SHADERDEFINE_UV1=0;
- MeshSprite3D.SHADERDEFINE_GPU_INSTANCE=0;
- __static(MeshSprite3D,
- ['shaderDefines',function(){return this.shaderDefines=new ShaderDefines(RenderableSprite3D.shaderDefines);}
- ]);
- return MeshSprite3D;
- })(RenderableSprite3D)
- /**
- *<code>SpotLight</code> 类用于创建聚光。
- */
- //class laya.d3.core.light.SpotLight extends laya.d3.core.light.LightSprite
- var SpotLight=(function(_super){
- function SpotLight(){
- /**@private */
- this._direction=null;
- /**@private */
- this._spotAngle=NaN;
- /**@private */
- this._range=NaN;
- SpotLight.__super.call(this);
- this._spotAngle=30.0;
- this._range=10.0;
- this._direction=new Vector3();
- }
- __class(SpotLight,'laya.d3.core.light.SpotLight',_super);
- var __proto=SpotLight.prototype;
- /**
- *@inheritDoc
- */
- __proto._onActive=function(){
- _super.prototype._onActive.call(this);
- (this._lightmapBakedType!==LightSprite.LIGHTMAPBAKEDTYPE_BAKED)&&((this.scene)._defineDatas.add(Scene3D.SHADERDEFINE_SPOTLIGHT));
- }
- /**
- *@inheritDoc
- */
- __proto._onInActive=function(){
- _super.prototype._onInActive.call(this);
- (this._lightmapBakedType!==LightSprite.LIGHTMAPBAKEDTYPE_BAKED)&&((this.scene)._defineDatas.remove(Scene3D.SHADERDEFINE_SPOTLIGHT));
- }
- /**
- *更新聚光相关渲染状态参数。
- *@param state 渲染状态参数。
- */
- __proto._prepareToScene=function(){
- var scene=this._scene;
- if (scene.enableLight && this.activeInHierarchy){
- var defineDatas=scene._defineDatas;
- var shaderValue=scene._shaderValues;
- Vector3.scale(this.color,this._intensity,this._intensityColor);
- shaderValue.setVector3(Scene3D.SPOTLIGHTCOLOR,this._intensityColor);
- shaderValue.setVector3(Scene3D.SPOTLIGHTPOS,this.transform.position);
- this.transform.worldMatrix.getForward(this._direction);
- Vector3.normalize(this._direction,this._direction);
- shaderValue.setVector3(Scene3D.SPOTLIGHTDIRECTION,this._direction);
- shaderValue.setNumber(Scene3D.SPOTLIGHTRANGE,this.range);
- shaderValue.setNumber(Scene3D.SPOTLIGHTSPOTANGLE,this.spotAngle *Math.PI / 180);
- return true;
- }else {
- return false;
- }
- }
- /**
- *@inheritDoc
- */
- __proto._parse=function(data,spriteMap){
- _super.prototype._parse.call(this,data,spriteMap);
- this.range=data.range;
- this.spotAngle=data.spotAngle;
- }
- /**
- *设置聚光灯的锥形角度。
- *@param value 聚光灯的锥形角度。
- */
- /**
- *获取聚光灯的锥形角度。
- *@return 聚光灯的锥形角度。
- */
- __getset(0,__proto,'spotAngle',function(){
- return this._spotAngle;
- },function(value){
- this._spotAngle=Math.max(Math.min(value,180),0);
- });
- /**
- *设置聚光的范围。
- *@param value 聚光的范围值。
- */
- /**
- *获取聚光的范围。
- *@return 聚光的范围值。
- */
- __getset(0,__proto,'range',function(){
- return this._range;
- },function(value){
- this._range=value;
- });
- __static(SpotLight,
- ['_tempMatrix0',function(){return this._tempMatrix0=new Matrix4x4();},'_tempMatrix1',function(){return this._tempMatrix1=new Matrix4x4();}
- ]);
- return SpotLight;
- })(LightSprite)
- /**
- *<code>DirectionLight</code> 类用于创建平行光。
- */
- //class laya.d3.core.light.DirectionLight extends laya.d3.core.light.LightSprite
- var DirectionLight=(function(_super){
- function DirectionLight(){
- /**@private */
- this._direction=null;
- DirectionLight.__super.call(this);
- this._direction=new Vector3();
- }
- __class(DirectionLight,'laya.d3.core.light.DirectionLight',_super);
- var __proto=DirectionLight.prototype;
- /**
- *@private
- */
- __proto._initShadow=function(){
- if (this._shadow){
- this._parallelSplitShadowMap=new ParallelSplitShadowMap();
- this.scene.parallelSplitShadowMaps.push(this._parallelSplitShadowMap);
- this.transform.worldMatrix.getForward(this._direction);
- Vector3.normalize(this._direction,this._direction);
- this._parallelSplitShadowMap.setInfo(this.scene,this._shadowFarPlane,this._direction,this._shadowMapSize,this._shadowMapCount,this._shadowMapPCFType);
- }else {
- var defineDatas=(this._scene)._defineDatas;
- var parallelSplitShadowMaps=this.scene.parallelSplitShadowMaps;
- parallelSplitShadowMaps.splice(parallelSplitShadowMaps.indexOf(this._parallelSplitShadowMap),1);
- this._parallelSplitShadowMap.disposeAllRenderTarget();
- this._parallelSplitShadowMap=null;
- defineDatas.remove(Scene3D.SHADERDEFINE_SHADOW_PSSM1);
- defineDatas.remove(Scene3D.SHADERDEFINE_SHADOW_PSSM2);
- defineDatas.remove(Scene3D.SHADERDEFINE_SHADOW_PSSM3);
- }
- }
- /**
- *@inheritDoc
- */
- __proto._onActive=function(){
- _super.prototype._onActive.call(this);
- this._shadow && (this._initShadow());
- (this._lightmapBakedType!==LightSprite.LIGHTMAPBAKEDTYPE_BAKED)&&((this._scene)._defineDatas.add(Scene3D.SHADERDEFINE_DIRECTIONLIGHT));
- }
- /**
- *@inheritDoc
- */
- __proto._onInActive=function(){
- _super.prototype._onInActive.call(this);
- (this._lightmapBakedType!==LightSprite.LIGHTMAPBAKEDTYPE_BAKED)&&((this._scene)._defineDatas.remove(Scene3D.SHADERDEFINE_DIRECTIONLIGHT));
- }
- /**
- *更新平行光相关渲染状态参数。
- *@param state 渲染状态参数。
- */
- __proto._prepareToScene=function(){
- var scene=this._scene;
- if (scene.enableLight && this.activeInHierarchy){
- var defineDatas=scene._defineDatas;
- var shaderValue=scene._shaderValues;
- Vector3.scale(this.color,this._intensity,this._intensityColor);
- shaderValue.setVector3(Scene3D.LIGHTDIRCOLOR,this._intensityColor);
- this.transform.worldMatrix.getForward(this._direction);
- Vector3.normalize(this._direction,this._direction);
- shaderValue.setVector3(Scene3D.LIGHTDIRECTION,this._direction);
- return true;
- }else {
- return false;
- }
- }
- /**
- *@inheritDoc
- */
- __getset(0,__proto,'shadow',_super.prototype._$get_shadow,function(value){
- if (this._shadow!==value){
- this._shadow=value;
- (this.scene)&& (this._initShadow());
- }
- });
- return DirectionLight;
- })(LightSprite)
- /**
- *<code>TrailSprite3D</code> 类用于创建拖尾渲染精灵。
- */
- //class laya.d3.core.trail.TrailSprite3D extends laya.d3.core.RenderableSprite3D
- var TrailSprite3D=(function(_super){
- function TrailSprite3D(){
- /**@private */
- //this._geometryFilter=null;
- TrailSprite3D.__super.call(this,this.name);
- this._render=new TrailRenderer(this);
- this._geometryFilter=new TrailFilter(this);
- }
- __class(TrailSprite3D,'laya.d3.core.trail.TrailSprite3D',_super);
- var __proto=TrailSprite3D.prototype;
- /**
- *@inheritDoc
- */
- __proto._parse=function(data,spriteMap){
- laya.d3.core.Sprite3D.prototype._parse.call(this,data,spriteMap);
- var render=this._render;
- var filter=this._geometryFilter;
- var i=0,j=0;
- var materials=data.materials;
- if (materials){
- var sharedMaterials=render.sharedMaterials;
- var materialCount=materials.length;
- sharedMaterials.length=materialCount;
- for (i=0;i < materialCount;i++)
- sharedMaterials[i]=Loader.getRes(materials[i].path);
- render.sharedMaterials=sharedMaterials;
- }
- filter.time=data.time;
- filter.minVertexDistance=data.minVertexDistance;
- filter.widthMultiplier=data.widthMultiplier;
- filter.textureMode=data.textureMode;
- (data.alignment !=null)&& (filter.alignment=data.alignment);
- var widthCurve=[];
- var widthCurveData=data.widthCurve;
- for (i=0,j=widthCurveData.length;i < j;i++){
- var trailkeyframe=new FloatKeyframe();
- trailkeyframe.time=widthCurveData[i].time;
- trailkeyframe.inTangent=widthCurveData[i].inTangent;
- trailkeyframe.outTangent=widthCurveData[i].outTangent;
- trailkeyframe.value=widthCurveData[i].value;
- widthCurve.push(trailkeyframe);
- }
- filter.widthCurve=widthCurve;
- var colorGradientData=data.colorGradient;
- var colorKeys=colorGradientData.colorKeys;
- var alphaKeys=colorGradientData.alphaKeys;
- var colorGradient=new Gradient(colorKeys.length,alphaKeys.length);
- colorGradient.mode=colorGradientData.mode;
- for (i=0,j=colorKeys.length;i < j;i++){
- var colorKey=colorKeys[i];
- colorGradient.addColorRGB(colorKey.time,new Color(colorKey.value[0],colorKey.value[1],colorKey.value[2],1.0));
- }
- for (i=0,j=alphaKeys.length;i < j;i++){
- var alphaKey=alphaKeys[i];
- colorGradient.addColorAlpha(alphaKey.time,alphaKey.value);
- }
- filter.colorGradient=colorGradient;
- }
- /**
- *@inheritDoc
- */
- __proto._onActive=function(){
- _super.prototype._onActive.call(this);
- this._transform.position.cloneTo(this._geometryFilter._lastPosition);
- }
- /**
- *@inheritDoc
- */
- __proto._cloneTo=function(destObject,srcSprite,dstSprite){
- laya.d3.core.Sprite3D.prototype._cloneTo.call(this,destObject,srcSprite,dstSprite);
- var i=0,j=0;
- var destTrailSprite3D=destObject;
- var destTrailFilter=destTrailSprite3D.trailFilter;
- destTrailFilter.time=this.trailFilter.time;
- destTrailFilter.minVertexDistance=this.trailFilter.minVertexDistance;
- destTrailFilter.widthMultiplier=this.trailFilter.widthMultiplier;
- destTrailFilter.textureMode=this.trailFilter.textureMode;
- var widthCurveData=this.trailFilter.widthCurve;
- var widthCurve=[];
- for (i=0,j=widthCurveData.length;i < j;i++){
- var keyFrame=new FloatKeyframe();
- widthCurveData[i].cloneTo(keyFrame);
- widthCurve.push(keyFrame);
- }
- destTrailFilter.widthCurve=widthCurve;
- var destColorGradient=new Gradient(this.trailFilter.colorGradient.maxColorRGBKeysCount,this.trailFilter.colorGradient.maxColorAlphaKeysCount);
- this.trailFilter.colorGradient.cloneTo(destColorGradient);
- destTrailFilter.colorGradient=destColorGradient;
- var destTrailRender=destTrailSprite3D.trailRenderer;
- destTrailRender.sharedMaterial=this.trailRenderer.sharedMaterial;
- }
- /**
- *<p>销毁此对象。</p>
- *@param destroyChild 是否同时销毁子节点,若值为true,则销毁子节点,否则不销毁子节点。
- */
- __proto.destroy=function(destroyChild){
- (destroyChild===void 0)&& (destroyChild=true);
- if (this.destroyed)
- return;
- _super.prototype.destroy.call(this,destroyChild);
- (this._geometryFilter).destroy();
- this._geometryFilter=null;
- }
- /**
- *获取Trail过滤器。
- *@return Trail过滤器。
- */
- __getset(0,__proto,'trailFilter',function(){
- return this._geometryFilter;
- });
- /**
- *获取Trail渲染器。
- *@return Trail渲染器。
- */
- __getset(0,__proto,'trailRenderer',function(){
- return this._render;
- });
- TrailSprite3D.__init__=function(){
- TrailSprite3D.SHADERDEFINE_GRADIENTMODE_BLEND=TrailSprite3D.shaderDefines.registerDefine("GRADIENTMODE_BLEND");
- }
- TrailSprite3D.SHADERDEFINE_GRADIENTMODE_BLEND=0;
- __static(TrailSprite3D,
- ['CURTIME',function(){return this.CURTIME=Shader3D.propertyNameToID("u_CurTime");},'LIFETIME',function(){return this.LIFETIME=Shader3D.propertyNameToID("u_LifeTime");},'WIDTHCURVE',function(){return this.WIDTHCURVE=Shader3D.propertyNameToID("u_WidthCurve");},'WIDTHCURVEKEYLENGTH',function(){return this.WIDTHCURVEKEYLENGTH=Shader3D.propertyNameToID("u_WidthCurveKeyLength");},'GRADIENTCOLORKEY',function(){return this.GRADIENTCOLORKEY=Shader3D.propertyNameToID("u_GradientColorkey");},'GRADIENTALPHAKEY',function(){return this.GRADIENTALPHAKEY=Shader3D.propertyNameToID("u_GradientAlphakey");},'shaderDefines',function(){return this.shaderDefines=new ShaderDefines(RenderableSprite3D.shaderDefines);}
- ]);
- return TrailSprite3D;
- })(RenderableSprite3D)
- /**
- *<code>ShuriKenParticle3D</code> 3D粒子。
- */
- //class laya.d3.core.particleShuriKen.ShuriKenParticle3D extends laya.d3.core.RenderableSprite3D
- var ShuriKenParticle3D=(function(_super){
- function ShuriKenParticle3D(){
- /**@private */
- //this._particleSystem=null;
- ShuriKenParticle3D.__super.call(this,null);
- this._render=new ShurikenParticleRenderer(this);
- this._particleSystem=new ShurikenParticleSystem(this);
- var elements=this._render._renderElements;
- var element=elements[0]=new RenderElement();
- element.setTransform(this._transform);
- element.render=this._render;
- element.setGeometry(this._particleSystem);
- element.material=ShurikenParticleMaterial.defaultMaterial;
- }
- __class(ShuriKenParticle3D,'laya.d3.core.particleShuriKen.ShuriKenParticle3D',_super);
- var __proto=ShuriKenParticle3D.prototype;
- /**
- *@private
- */
- __proto._initParticleVelocity=function(gradientData){
- var gradient=new GradientDataNumber();
- var velocitysData=gradientData.velocitys;
- for (var i=0,n=velocitysData.length;i < n;i++){
- var valueData=velocitysData[i];
- gradient.add(valueData.key,valueData.value);
- }
- return gradient;
- }
- /**
- *@private
- */
- __proto._initParticleColor=function(gradientColorData){
- var gradientColor=new Gradient(4,4);
- var alphasData=gradientColorData.alphas;
- var i=0,n=0;
- for (i=0,n=alphasData.length;i < n;i++){
- var alphaData=alphasData[i];
- if ((i===3)&& ((alphaData.key!==1))){
- alphaData.key=1;
- console.log("GradientDataColor warning:the forth key is be force set to 1.");
- }
- gradientColor.addColorAlpha(alphaData.key,alphaData.value);
- };
- var rgbsData=gradientColorData.rgbs;
- for (i=0,n=rgbsData.length;i < n;i++){
- var rgbData=rgbsData[i];
- var rgbValue=rgbData.value;
- if ((i===3)&& ((rgbData.key!==1))){
- rgbData.key=1;
- console.log("GradientDataColor warning:the forth key is be force set to 1.");
- }
- gradientColor.addColorRGB(rgbData.key,new Color(rgbValue[0],rgbValue[1],rgbValue[2],1.0));
- }
- return gradientColor;
- }
- /**
- *@private
- */
- __proto._initParticleSize=function(gradientSizeData){
- var gradientSize=new GradientDataNumber();
- var sizesData=gradientSizeData.sizes;
- for (var i=0,n=sizesData.length;i < n;i++){
- var valueData=sizesData[i];
- gradientSize.add(valueData.key,valueData.value);
- }
- return gradientSize;
- }
- /**
- *@private
- */
- __proto._initParticleRotation=function(gradientData){
- var gradient=new GradientDataNumber();
- var angularVelocitysData=gradientData.angularVelocitys;
- for (var i=0,n=angularVelocitysData.length;i < n;i++){
- var valueData=angularVelocitysData[i];
- gradient.add(valueData.key,valueData.value / 180.0 *Math.PI);
- }
- return gradient;
- }
- /**
- *@private
- */
- __proto._initParticleFrame=function(overTimeFramesData){
- var overTimeFrame=new GradientDataInt();
- var framesData=overTimeFramesData.frames;
- for (var i=0,n=framesData.length;i < n;i++){
- var frameData=framesData[i];
- overTimeFrame.add(frameData.key,frameData.value);
- }
- return overTimeFrame;
- }
- /**
- *@inheritDoc
- */
- __proto._parse=function(data,spriteMap){
- laya.d3.core.Sprite3D.prototype._parse.call(this,data,spriteMap);
- var anglelToRad=Math.PI / 180.0;
- var i=0,n=0;
- var particleRender=this.particleRenderer;
- var material;
- var materialData=data.material;
- (materialData)&& (material=Loader.getRes(materialData.path));
- particleRender.sharedMaterial=material;
- var meshPath=data.meshPath;
- (meshPath)&& (particleRender.mesh=Loader.getRes(meshPath));
- particleRender.renderMode=data.renderMode;
- particleRender.stretchedBillboardCameraSpeedScale=data.stretchedBillboardCameraSpeedScale;
- particleRender.stretchedBillboardSpeedScale=data.stretchedBillboardSpeedScale;
- particleRender.stretchedBillboardLengthScale=data.stretchedBillboardLengthScale;
- particleRender.sortingFudge=data.sortingFudge ? data.sortingFudge :0.0;
- var particleSystem=this.particleSystem;
- particleSystem.isPerformanceMode=data.isPerformanceMode;
- particleSystem.duration=data.duration;
- particleSystem.looping=data.looping;
- particleSystem.prewarm=data.prewarm;
- particleSystem.startDelayType=data.startDelayType;
- particleSystem.startDelay=data.startDelay;
- particleSystem.startDelayMin=data.startDelayMin;
- particleSystem.startDelayMax=data.startDelayMax;
- particleSystem.startLifetimeType=data.startLifetimeType;
- particleSystem.startLifetimeConstant=data.startLifetimeConstant;
- particleSystem.startLifeTimeGradient=ShuriKenParticle3D._initStartLife(data.startLifetimeGradient);
- particleSystem.startLifetimeConstantMin=data.startLifetimeConstantMin;
- particleSystem.startLifetimeConstantMax=data.startLifetimeConstantMax;
- particleSystem.startLifeTimeGradientMin=ShuriKenParticle3D._initStartLife(data.startLifetimeGradientMin);
- particleSystem.startLifeTimeGradientMax=ShuriKenParticle3D._initStartLife(data.startLifetimeGradientMax);
- particleSystem.startSpeedType=data.startSpeedType;
- particleSystem.startSpeedConstant=data.startSpeedConstant;
- particleSystem.startSpeedConstantMin=data.startSpeedConstantMin;
- particleSystem.startSpeedConstantMax=data.startSpeedConstantMax;
- particleSystem.threeDStartSize=data.threeDStartSize;
- particleSystem.startSizeType=data.startSizeType;
- particleSystem.startSizeConstant=data.startSizeConstant;
- var startSizeConstantSeparateArray=data.startSizeConstantSeparate;
- var startSizeConstantSeparateElement=particleSystem.startSizeConstantSeparate;
- startSizeConstantSeparateElement.x=startSizeConstantSeparateArray[0];
- startSizeConstantSeparateElement.y=startSizeConstantSeparateArray[1];
- startSizeConstantSeparateElement.z=startSizeConstantSeparateArray[2];
- particleSystem.startSizeConstantMin=data.startSizeConstantMin;
- particleSystem.startSizeConstantMax=data.startSizeConstantMax;
- var startSizeConstantMinSeparateArray=data.startSizeConstantMinSeparate;
- var startSizeConstantMinSeparateElement=particleSystem.startSizeConstantMinSeparate;
- startSizeConstantMinSeparateElement.x=startSizeConstantMinSeparateArray[0];
- startSizeConstantMinSeparateElement.y=startSizeConstantMinSeparateArray[1];
- startSizeConstantMinSeparateElement.z=startSizeConstantMinSeparateArray[2];
- var startSizeConstantMaxSeparateArray=data.startSizeConstantMaxSeparate;
- var startSizeConstantMaxSeparateElement=particleSystem.startSizeConstantMaxSeparate;
- startSizeConstantMaxSeparateElement.x=startSizeConstantMaxSeparateArray[0];
- startSizeConstantMaxSeparateElement.y=startSizeConstantMaxSeparateArray[1];
- startSizeConstantMaxSeparateElement.z=startSizeConstantMaxSeparateArray[2];
- particleSystem.threeDStartRotation=data.threeDStartRotation;
- particleSystem.startRotationType=data.startRotationType;
- particleSystem.startRotationConstant=data.startRotationConstant *anglelToRad;
- var startRotationConstantSeparateArray=data.startRotationConstantSeparate;
- var startRotationConstantSeparateElement=particleSystem.startRotationConstantSeparate;
- startRotationConstantSeparateElement.x=startRotationConstantSeparateArray[0] *anglelToRad;
- startRotationConstantSeparateElement.y=startRotationConstantSeparateArray[1] *anglelToRad;
- startRotationConstantSeparateElement.z=startRotationConstantSeparateArray[2] *anglelToRad;
- particleSystem.startRotationConstantMin=data.startRotationConstantMin *anglelToRad;
- particleSystem.startRotationConstantMax=data.startRotationConstantMax *anglelToRad;
- var startRotationConstantMinSeparateArray=data.startRotationConstantMinSeparate;
- var startRotationConstantMinSeparateElement=particleSystem.startRotationConstantMinSeparate;
- startRotationConstantMinSeparateElement.x=startRotationConstantMinSeparateArray[0] *anglelToRad;
- startRotationConstantMinSeparateElement.y=startRotationConstantMinSeparateArray[1] *anglelToRad;
- startRotationConstantMinSeparateElement.z=startRotationConstantMinSeparateArray[2] *anglelToRad;
- var startRotationConstantMaxSeparateArray=data.startRotationConstantMaxSeparate;
- var startRotationConstantMaxSeparateElement=particleSystem.startRotationConstantMaxSeparate;
- startRotationConstantMaxSeparateElement.x=startRotationConstantMaxSeparateArray[0] *anglelToRad;
- startRotationConstantMaxSeparateElement.y=startRotationConstantMaxSeparateArray[1] *anglelToRad;
- startRotationConstantMaxSeparateElement.z=startRotationConstantMaxSeparateArray[2] *anglelToRad;
- particleSystem.randomizeRotationDirection=data.randomizeRotationDirection;
- particleSystem.startColorType=data.startColorType;
- var startColorConstantArray=data.startColorConstant;
- var startColorConstantElement=particleSystem.startColorConstant;
- startColorConstantElement.x=startColorConstantArray[0];
- startColorConstantElement.y=startColorConstantArray[1];
- startColorConstantElement.z=startColorConstantArray[2];
- startColorConstantElement.w=startColorConstantArray[3];
- var startColorConstantMinArray=data.startColorConstantMin;
- var startColorConstantMinElement=particleSystem.startColorConstantMin;
- startColorConstantMinElement.x=startColorConstantMinArray[0];
- startColorConstantMinElement.y=startColorConstantMinArray[1];
- startColorConstantMinElement.z=startColorConstantMinArray[2];
- startColorConstantMinElement.w=startColorConstantMinArray[3];
- var startColorConstantMaxArray=data.startColorConstantMax;
- var startColorConstantMaxElement=particleSystem.startColorConstantMax;
- startColorConstantMaxElement.x=startColorConstantMaxArray[0];
- startColorConstantMaxElement.y=startColorConstantMaxArray[1];
- startColorConstantMaxElement.z=startColorConstantMaxArray[2];
- startColorConstantMaxElement.w=startColorConstantMaxArray[3];
- particleSystem.gravityModifier=data.gravityModifier;
- particleSystem.simulationSpace=data.simulationSpace;
- particleSystem.scaleMode=data.scaleMode;
- particleSystem.playOnAwake=data.playOnAwake;
- particleSystem.maxParticles=data.maxParticles;
- var autoRandomSeed=data.autoRandomSeed;
- (autoRandomSeed !=null)&& (particleSystem.autoRandomSeed=autoRandomSeed);
- var randomSeed=data.randomSeed;
- (randomSeed !=null)&& (particleSystem.randomSeed[0]=randomSeed);
- var emissionData=data.emission;
- var emission=particleSystem.emission;
- if (emissionData){
- emission.emissionRate=emissionData.emissionRate;
- var burstsData=emissionData.bursts;
- if (burstsData)
- for (i=0,n=burstsData.length;i < n;i++){
- var brust=burstsData[i];
- emission.addBurst(new Burst(brust.time,brust.min,brust.max));
- }
- emission.enbale=emissionData.enable;
- }else {
- emission.enbale=false;
- };
- var shapeData=data.shape;
- if (shapeData){
- var shape;
- switch (shapeData.shapeType){
- case 0:;
- var sphereShape;
- shape=sphereShape=new SphereShape();
- sphereShape.radius=shapeData.sphereRadius;
- sphereShape.emitFromShell=shapeData.sphereEmitFromShell;
- sphereShape.randomDirection=shapeData.sphereRandomDirection;
- break ;
- case 1:;
- var hemiSphereShape;
- shape=hemiSphereShape=new HemisphereShape();
- hemiSphereShape.radius=shapeData.hemiSphereRadius;
- hemiSphereShape.emitFromShell=shapeData.hemiSphereEmitFromShell;
- hemiSphereShape.randomDirection=shapeData.hemiSphereRandomDirection;
- break ;
- case 2:;
- var coneShape;
- shape=coneShape=new ConeShape();
- coneShape.angle=shapeData.coneAngle *anglelToRad;
- coneShape.radius=shapeData.coneRadius;
- coneShape.length=shapeData.coneLength;
- coneShape.emitType=shapeData.coneEmitType;
- coneShape.randomDirection=shapeData.coneRandomDirection;
- break ;
- case 3:;
- var boxShape;
- shape=boxShape=new BoxShape();
- boxShape.x=shapeData.boxX;
- boxShape.y=shapeData.boxY;
- boxShape.z=shapeData.boxZ;
- boxShape.randomDirection=shapeData.boxRandomDirection;
- break ;
- case 7:;
- var circleShape;
- shape=circleShape=new CircleShape();
- circleShape.radius=shapeData.circleRadius;
- circleShape.arc=shapeData.circleArc *anglelToRad;
- circleShape.emitFromEdge=shapeData.circleEmitFromEdge;
- circleShape.randomDirection=shapeData.circleRandomDirection;
- break ;
- default :;
- var tempShape;
- shape=tempShape=new CircleShape();
- tempShape.radius=shapeData.circleRadius;
- tempShape.arc=shapeData.circleArc *anglelToRad;
- tempShape.emitFromEdge=shapeData.circleEmitFromEdge;
- tempShape.randomDirection=shapeData.circleRandomDirection;
- break ;
- }
- shape.enable=shapeData.enable;
- particleSystem.shape=shape;
- };
- var velocityOverLifetimeData=data.velocityOverLifetime;
- if (velocityOverLifetimeData){
- var velocityData=velocityOverLifetimeData.velocity;
- var velocity;
- switch (velocityData.type){
- case 0:;
- var constantData=velocityData.constant;
- velocity=GradientVelocity.createByConstant(new Vector3(constantData[0],constantData[1],constantData[2]));
- break ;
- case 1:
- velocity=GradientVelocity.createByGradient(this._initParticleVelocity(velocityData.gradientX),this._initParticleVelocity(velocityData.gradientY),this._initParticleVelocity(velocityData.gradientZ));
- break ;
- case 2:;
- var constantMinData=velocityData.constantMin;
- var constantMaxData=velocityData.constantMax;
- velocity=GradientVelocity.createByRandomTwoConstant(new Vector3(constantMinData[0],constantMinData[1],constantMinData[2]),new Vector3(constantMaxData[0],constantMaxData[1],constantMaxData[2]));
- break ;
- case 3:
- 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));
- break ;
- };
- var velocityOverLifetime=new VelocityOverLifetime(velocity);
- velocityOverLifetime.space=velocityOverLifetimeData.space;
- velocityOverLifetime.enbale=velocityOverLifetimeData.enable;
- particleSystem.velocityOverLifetime=velocityOverLifetime;
- };
- var colorOverLifetimeData=data.colorOverLifetime;
- if (colorOverLifetimeData){
- var colorData=colorOverLifetimeData.color;
- var color;
- switch (colorData.type){
- case 0:;
- var constColorData=colorData.constant;
- color=GradientColor.createByConstant(new Vector4(constColorData[0],constColorData[1],constColorData[2],constColorData[3]));
- break ;
- case 1:
- color=GradientColor.createByGradient(this._initParticleColor(colorData.gradient));
- break ;
- case 2:;
- var minConstColorData=colorData.constantMin;
- var maxConstColorData=colorData.constantMax;
- color=GradientColor.createByRandomTwoConstant(new Vector4(minConstColorData[0],minConstColorData[1],minConstColorData[2],minConstColorData[3]),new Vector4(maxConstColorData[0],maxConstColorData[1],maxConstColorData[2],maxConstColorData[3]));
- break ;
- case 3:
- color=GradientColor.createByRandomTwoGradient(this._initParticleColor(colorData.gradientMin),this._initParticleColor(colorData.gradientMax));
- break ;
- };
- var colorOverLifetime=new ColorOverLifetime(color);
- colorOverLifetime.enbale=colorOverLifetimeData.enable;
- particleSystem.colorOverLifetime=colorOverLifetime;
- };
- var sizeOverLifetimeData=data.sizeOverLifetime;
- if (sizeOverLifetimeData){
- var sizeData=sizeOverLifetimeData.size;
- var size;
- switch (sizeData.type){
- case 0:
- if (sizeData.separateAxes){
- size=GradientSize.createByGradientSeparate(this._initParticleSize(sizeData.gradientX),this._initParticleSize(sizeData.gradientY),this._initParticleSize(sizeData.gradientZ));
- }else {
- size=GradientSize.createByGradient(this._initParticleSize(sizeData.gradient));
- }
- break ;
- case 1:
- if (sizeData.separateAxes){
- var constantMinSeparateData=sizeData.constantMinSeparate;
- var constantMaxSeparateData=sizeData.constantMaxSeparate;
- size=GradientSize.createByRandomTwoConstantSeparate(new Vector3(constantMinSeparateData[0],constantMinSeparateData[1],constantMinSeparateData[2]),new Vector3(constantMaxSeparateData[0],constantMaxSeparateData[1],constantMaxSeparateData[2]));
- }else {
- size=GradientSize.createByRandomTwoConstant(sizeData.constantMin,sizeData.constantMax);
- }
- break ;
- case 2:
- if (sizeData.separateAxes){
- 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));
- }else {
- size=GradientSize.createByRandomTwoGradient(this._initParticleSize(sizeData.gradientMin),this._initParticleSize(sizeData.gradientMax));
- }
- break ;
- };
- var sizeOverLifetime=new SizeOverLifetime(size);
- sizeOverLifetime.enbale=sizeOverLifetimeData.enable;
- particleSystem.sizeOverLifetime=sizeOverLifetime;
- };
- var rotationOverLifetimeData=data.rotationOverLifetime;
- if (rotationOverLifetimeData){
- var angularVelocityData=rotationOverLifetimeData.angularVelocity;
- var angularVelocity;
- switch (angularVelocityData.type){
- case 0:
- if (angularVelocityData.separateAxes){
- var conSep=angularVelocityData.constantSeparate;
- angularVelocity=GradientAngularVelocity.createByConstantSeparate(new Vector3(conSep[0]*anglelToRad,conSep[1]*anglelToRad,conSep[2]*anglelToRad));
- }else {
- angularVelocity=GradientAngularVelocity.createByConstant(angularVelocityData.constant *anglelToRad);
- }
- break ;
- case 1:
- if (angularVelocityData.separateAxes){
- angularVelocity=GradientAngularVelocity.createByGradientSeparate(this._initParticleRotation(angularVelocityData.gradientX),this._initParticleRotation(angularVelocityData.gradientY),this._initParticleRotation(angularVelocityData.gradientZ));
- }else {
- angularVelocity=GradientAngularVelocity.createByGradient(this._initParticleRotation(angularVelocityData.gradient));
- }
- break ;
- case 2:
- if (angularVelocityData.separateAxes){
- var minSep=angularVelocityData.constantMinSeparate;
- var maxSep=angularVelocityData.constantMaxSeparate;
- 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));
- }else {
- angularVelocity=GradientAngularVelocity.createByRandomTwoConstant(angularVelocityData.constantMin *anglelToRad,angularVelocityData.constantMax *anglelToRad);
- }
- break ;
- case 3:
- if (angularVelocityData.separateAxes){
- }else {
- angularVelocity=GradientAngularVelocity.createByRandomTwoGradient(this._initParticleRotation(angularVelocityData.gradientMin),this._initParticleRotation(angularVelocityData.gradientMax));
- }
- break ;
- };
- var rotationOverLifetime=new RotationOverLifetime(angularVelocity);
- rotationOverLifetime.enbale=rotationOverLifetimeData.enable;
- particleSystem.rotationOverLifetime=rotationOverLifetime;
- };
- var textureSheetAnimationData=data.textureSheetAnimation;
- if (textureSheetAnimationData){
- var frameData=textureSheetAnimationData.frame;
- var frameOverTime;
- switch (frameData.type){
- case 0:
- frameOverTime=FrameOverTime.createByConstant(frameData.constant);
- break ;
- case 1:
- frameOverTime=FrameOverTime.createByOverTime(this._initParticleFrame(frameData.overTime));
- break ;
- case 2:
- frameOverTime=FrameOverTime.createByRandomTwoConstant(frameData.constantMin,frameData.constantMax);
- break ;
- case 3:
- frameOverTime=FrameOverTime.createByRandomTwoOverTime(this._initParticleFrame(frameData.overTimeMin),this._initParticleFrame(frameData.overTimeMax));
- break ;
- };
- var startFrameData=textureSheetAnimationData.startFrame;
- var startFrame;
- switch (startFrameData.type){
- case 0:
- startFrame=StartFrame.createByConstant(startFrameData.constant);
- break ;
- case 1:
- startFrame=StartFrame.createByRandomTwoConstant(startFrameData.constantMin,startFrameData.constantMax);
- break ;
- };
- var textureSheetAnimation=new TextureSheetAnimation(frameOverTime,startFrame);
- textureSheetAnimation.enable=textureSheetAnimationData.enable;
- var tilesData=textureSheetAnimationData.tiles;
- textureSheetAnimation.tiles=new Vector2(tilesData[0],tilesData[1]);
- textureSheetAnimation.type=textureSheetAnimationData.type;
- textureSheetAnimation.randomRow=textureSheetAnimationData.randomRow;
- var rowIndex=textureSheetAnimationData.rowIndex;
- (rowIndex!==undefined)&& (textureSheetAnimation.rowIndex=rowIndex);
- textureSheetAnimation.cycles=textureSheetAnimationData.cycles;
- particleSystem.textureSheetAnimation=textureSheetAnimation;
- }
- }
- /**
- *@inheritDoc
- */
- __proto._activeHierarchy=function(activeChangeComponents){
- laya.display.Node.prototype._activeHierarchy.call(this,activeChangeComponents);
- (this.particleSystem.playOnAwake)&& (this.particleSystem.play());
- }
- /**
- *@inheritDoc
- */
- __proto._inActiveHierarchy=function(activeChangeComponents){
- laya.display.Node.prototype._inActiveHierarchy.call(this,activeChangeComponents);
- (this.particleSystem.isAlive)&& (this.particleSystem.simulate(0,true));
- }
- /**
- *@private
- */
- __proto._cloneTo=function(destObject,srcSprite,dstSprite){
- var destShuriKenParticle3D=destObject;
- var destParticleSystem=destShuriKenParticle3D._particleSystem;
- this._particleSystem.cloneTo(destParticleSystem);
- var destParticleRender=destShuriKenParticle3D._render;
- var particleRender=this._render;
- destParticleRender.sharedMaterials=particleRender.sharedMaterials;
- destParticleRender.enable=particleRender.enable;
- destParticleRender.renderMode=particleRender.renderMode;
- destParticleRender.mesh=particleRender.mesh;
- destParticleRender.stretchedBillboardCameraSpeedScale=particleRender.stretchedBillboardCameraSpeedScale;
- destParticleRender.stretchedBillboardSpeedScale=particleRender.stretchedBillboardSpeedScale;
- destParticleRender.stretchedBillboardLengthScale=particleRender.stretchedBillboardLengthScale;
- destParticleRender.sortingFudge=particleRender.sortingFudge;
- laya.d3.core.Sprite3D.prototype._cloneTo.call(this,destObject,srcSprite,dstSprite);
- }
- /**
- *<p>销毁此对象。</p>
- *@param destroyChild 是否同时销毁子节点,若值为true,则销毁子节点,否则不销毁子节点。
- */
- __proto.destroy=function(destroyChild){
- (destroyChild===void 0)&& (destroyChild=true);
- if (this.destroyed)
- return;
- _super.prototype.destroy.call(this,destroyChild);
- this._particleSystem.destroy();
- this._particleSystem=null;
- }
- /**
- *获取粒子系统。
- *@return 粒子系统。
- */
- __getset(0,__proto,'particleSystem',function(){
- return this._particleSystem;
- });
- /**
- *获取粒子渲染器。
- *@return 粒子渲染器。
- */
- __getset(0,__proto,'particleRenderer',function(){
- return this._render;
- });
- ShuriKenParticle3D.__init__=function(){
- ShuriKenParticle3D.SHADERDEFINE_RENDERMODE_BILLBOARD=ShuriKenParticle3D.shaderDefines.registerDefine("SPHERHBILLBOARD");
- ShuriKenParticle3D.SHADERDEFINE_RENDERMODE_STRETCHEDBILLBOARD=ShuriKenParticle3D.shaderDefines.registerDefine("STRETCHEDBILLBOARD");
- ShuriKenParticle3D.SHADERDEFINE_RENDERMODE_HORIZONTALBILLBOARD=ShuriKenParticle3D.shaderDefines.registerDefine("HORIZONTALBILLBOARD");
- ShuriKenParticle3D.SHADERDEFINE_RENDERMODE_VERTICALBILLBOARD=ShuriKenParticle3D.shaderDefines.registerDefine("VERTICALBILLBOARD");
- ShuriKenParticle3D.SHADERDEFINE_COLOROVERLIFETIME=ShuriKenParticle3D.shaderDefines.registerDefine("COLOROVERLIFETIME");
- ShuriKenParticle3D.SHADERDEFINE_RANDOMCOLOROVERLIFETIME=ShuriKenParticle3D.shaderDefines.registerDefine("RANDOMCOLOROVERLIFETIME");
- ShuriKenParticle3D.SHADERDEFINE_VELOCITYOVERLIFETIMECONSTANT=ShuriKenParticle3D.shaderDefines.registerDefine("VELOCITYOVERLIFETIMECONSTANT");
- ShuriKenParticle3D.SHADERDEFINE_VELOCITYOVERLIFETIMECURVE=ShuriKenParticle3D.shaderDefines.registerDefine("VELOCITYOVERLIFETIMECURVE");
- ShuriKenParticle3D.SHADERDEFINE_VELOCITYOVERLIFETIMERANDOMCONSTANT=ShuriKenParticle3D.shaderDefines.registerDefine("VELOCITYOVERLIFETIMERANDOMCONSTANT");
- ShuriKenParticle3D.SHADERDEFINE_VELOCITYOVERLIFETIMERANDOMCURVE=ShuriKenParticle3D.shaderDefines.registerDefine("VELOCITYOVERLIFETIMERANDOMCURVE");
- ShuriKenParticle3D.SHADERDEFINE_TEXTURESHEETANIMATIONCURVE=ShuriKenParticle3D.shaderDefines.registerDefine("TEXTURESHEETANIMATIONCURVE");
- ShuriKenParticle3D.SHADERDEFINE_TEXTURESHEETANIMATIONRANDOMCURVE=ShuriKenParticle3D.shaderDefines.registerDefine("TEXTURESHEETANIMATIONRANDOMCURVE");
- ShuriKenParticle3D.SHADERDEFINE_ROTATIONOVERLIFETIME=ShuriKenParticle3D.shaderDefines.registerDefine("ROTATIONOVERLIFETIME");
- ShuriKenParticle3D.SHADERDEFINE_ROTATIONOVERLIFETIMESEPERATE=ShuriKenParticle3D.shaderDefines.registerDefine("ROTATIONOVERLIFETIMESEPERATE");
- ShuriKenParticle3D.SHADERDEFINE_ROTATIONOVERLIFETIMECONSTANT=ShuriKenParticle3D.shaderDefines.registerDefine("ROTATIONOVERLIFETIMECONSTANT");
- ShuriKenParticle3D.SHADERDEFINE_ROTATIONOVERLIFETIMECURVE=ShuriKenParticle3D.shaderDefines.registerDefine("ROTATIONOVERLIFETIMECURVE");
- ShuriKenParticle3D.SHADERDEFINE_ROTATIONOVERLIFETIMERANDOMCONSTANTS=ShuriKenParticle3D.shaderDefines.registerDefine("ROTATIONOVERLIFETIMERANDOMCONSTANTS");
- ShuriKenParticle3D.SHADERDEFINE_ROTATIONOVERLIFETIMERANDOMCURVES=ShuriKenParticle3D.shaderDefines.registerDefine("ROTATIONOVERLIFETIMERANDOMCURVES");
- ShuriKenParticle3D.SHADERDEFINE_SIZEOVERLIFETIMECURVE=ShuriKenParticle3D.shaderDefines.registerDefine("SIZEOVERLIFETIMECURVE");
- ShuriKenParticle3D.SHADERDEFINE_SIZEOVERLIFETIMECURVESEPERATE=ShuriKenParticle3D.shaderDefines.registerDefine("SIZEOVERLIFETIMECURVESEPERATE");
- ShuriKenParticle3D.SHADERDEFINE_SIZEOVERLIFETIMERANDOMCURVES=ShuriKenParticle3D.shaderDefines.registerDefine("SIZEOVERLIFETIMERANDOMCURVES");
- ShuriKenParticle3D.SHADERDEFINE_SIZEOVERLIFETIMERANDOMCURVESSEPERATE=ShuriKenParticle3D.shaderDefines.registerDefine("SIZEOVERLIFETIMERANDOMCURVESSEPERATE");
- ShuriKenParticle3D.SHADERDEFINE_RENDERMODE_MESH=ShuriKenParticle3D.shaderDefines.registerDefine("RENDERMODE_MESH");
- ShuriKenParticle3D.SHADERDEFINE_SHAPE=ShuriKenParticle3D.shaderDefines.registerDefine("SHAPE");
- }
- ShuriKenParticle3D._initStartLife=function(gradientData){
- var gradient=new GradientDataNumber();
- var startLifetimesData=gradientData.startLifetimes;
- for (var i=0,n=startLifetimesData.length;i < n;i++){
- var valueData=startLifetimesData[i];
- gradient.add(valueData.key,valueData.value);
- }
- return gradient
- }
- ShuriKenParticle3D.SHADERDEFINE_RENDERMODE_BILLBOARD=0;
- ShuriKenParticle3D.SHADERDEFINE_RENDERMODE_STRETCHEDBILLBOARD=0;
- ShuriKenParticle3D.SHADERDEFINE_RENDERMODE_HORIZONTALBILLBOARD=0;
- ShuriKenParticle3D.SHADERDEFINE_RENDERMODE_VERTICALBILLBOARD=0;
- ShuriKenParticle3D.SHADERDEFINE_COLOROVERLIFETIME=0;
- ShuriKenParticle3D.SHADERDEFINE_RANDOMCOLOROVERLIFETIME=0;
- ShuriKenParticle3D.SHADERDEFINE_VELOCITYOVERLIFETIMECONSTANT=0;
- ShuriKenParticle3D.SHADERDEFINE_VELOCITYOVERLIFETIMECURVE=0;
- ShuriKenParticle3D.SHADERDEFINE_VELOCITYOVERLIFETIMERANDOMCONSTANT=0;
- ShuriKenParticle3D.SHADERDEFINE_VELOCITYOVERLIFETIMERANDOMCURVE=0;
- ShuriKenParticle3D.SHADERDEFINE_TEXTURESHEETANIMATIONCURVE=0;
- ShuriKenParticle3D.SHADERDEFINE_TEXTURESHEETANIMATIONRANDOMCURVE=0;
- ShuriKenParticle3D.SHADERDEFINE_ROTATIONOVERLIFETIME=0;
- ShuriKenParticle3D.SHADERDEFINE_ROTATIONOVERLIFETIMESEPERATE=0;
- ShuriKenParticle3D.SHADERDEFINE_ROTATIONOVERLIFETIMECONSTANT=0;
- ShuriKenParticle3D.SHADERDEFINE_ROTATIONOVERLIFETIMECURVE=0;
- ShuriKenParticle3D.SHADERDEFINE_ROTATIONOVERLIFETIMERANDOMCONSTANTS=0;
- ShuriKenParticle3D.SHADERDEFINE_ROTATIONOVERLIFETIMERANDOMCURVES=0;
- ShuriKenParticle3D.SHADERDEFINE_SIZEOVERLIFETIMECURVE=0;
- ShuriKenParticle3D.SHADERDEFINE_SIZEOVERLIFETIMECURVESEPERATE=0;
- ShuriKenParticle3D.SHADERDEFINE_SIZEOVERLIFETIMERANDOMCURVES=0;
- ShuriKenParticle3D.SHADERDEFINE_SIZEOVERLIFETIMERANDOMCURVESSEPERATE=0;
- ShuriKenParticle3D.SHADERDEFINE_RENDERMODE_MESH=0;
- ShuriKenParticle3D.SHADERDEFINE_SHAPE=0;
- __static(ShuriKenParticle3D,
- ['WORLDPOSITION',function(){return this.WORLDPOSITION=Shader3D.propertyNameToID("u_WorldPosition");},'WORLDROTATION',function(){return this.WORLDROTATION=Shader3D.propertyNameToID("u_WorldRotation");},'POSITIONSCALE',function(){return this.POSITIONSCALE=Shader3D.propertyNameToID("u_PositionScale");},'SIZESCALE',function(){return this.SIZESCALE=Shader3D.propertyNameToID("u_SizeScale");},'SCALINGMODE',function(){return this.SCALINGMODE=Shader3D.propertyNameToID("u_ScalingMode");},'GRAVITY',function(){return this.GRAVITY=Shader3D.propertyNameToID("u_Gravity");},'THREEDSTARTROTATION',function(){return this.THREEDSTARTROTATION=Shader3D.propertyNameToID("u_ThreeDStartRotation");},'STRETCHEDBILLBOARDLENGTHSCALE',function(){return this.STRETCHEDBILLBOARDLENGTHSCALE=Shader3D.propertyNameToID("u_StretchedBillboardLengthScale");},'STRETCHEDBILLBOARDSPEEDSCALE',function(){return this.STRETCHEDBILLBOARDSPEEDSCALE=Shader3D.propertyNameToID("u_StretchedBillboardSpeedScale");},'SIMULATIONSPACE',function(){return this.SIMULATIONSPACE=Shader3D.propertyNameToID("u_SimulationSpace");},'CURRENTTIME',function(){return this.CURRENTTIME=Shader3D.propertyNameToID("u_CurrentTime");},'VOLVELOCITYCONST',function(){return this.VOLVELOCITYCONST=Shader3D.propertyNameToID("u_VOLVelocityConst");},'VOLVELOCITYGRADIENTX',function(){return this.VOLVELOCITYGRADIENTX=Shader3D.propertyNameToID("u_VOLVelocityGradientX");},'VOLVELOCITYGRADIENTY',function(){return this.VOLVELOCITYGRADIENTY=Shader3D.propertyNameToID("u_VOLVelocityGradientY");},'VOLVELOCITYGRADIENTZ',function(){return this.VOLVELOCITYGRADIENTZ=Shader3D.propertyNameToID("u_VOLVelocityGradientZ");},'VOLVELOCITYCONSTMAX',function(){return this.VOLVELOCITYCONSTMAX=Shader3D.propertyNameToID("u_VOLVelocityConstMax");},'VOLVELOCITYGRADIENTXMAX',function(){return this.VOLVELOCITYGRADIENTXMAX=Shader3D.propertyNameToID("u_VOLVelocityGradientMaxX");},'VOLVELOCITYGRADIENTYMAX',function(){return this.VOLVELOCITYGRADIENTYMAX=Shader3D.propertyNameToID("u_VOLVelocityGradientMaxY");},'VOLVELOCITYGRADIENTZMAX',function(){return this.VOLVELOCITYGRADIENTZMAX=Shader3D.propertyNameToID("u_VOLVelocityGradientMaxZ");},'VOLSPACETYPE',function(){return this.VOLSPACETYPE=Shader3D.propertyNameToID("u_VOLSpaceType");},'COLOROVERLIFEGRADIENTALPHAS',function(){return this.COLOROVERLIFEGRADIENTALPHAS=Shader3D.propertyNameToID("u_ColorOverLifeGradientAlphas");},'COLOROVERLIFEGRADIENTCOLORS',function(){return this.COLOROVERLIFEGRADIENTCOLORS=Shader3D.propertyNameToID("u_ColorOverLifeGradientColors");},'MAXCOLOROVERLIFEGRADIENTALPHAS',function(){return this.MAXCOLOROVERLIFEGRADIENTALPHAS=Shader3D.propertyNameToID("u_MaxColorOverLifeGradientAlphas");},'MAXCOLOROVERLIFEGRADIENTCOLORS',function(){return this.MAXCOLOROVERLIFEGRADIENTCOLORS=Shader3D.propertyNameToID("u_MaxColorOverLifeGradientColors");},'SOLSIZEGRADIENT',function(){return this.SOLSIZEGRADIENT=Shader3D.propertyNameToID("u_SOLSizeGradient");},'SOLSIZEGRADIENTX',function(){return this.SOLSIZEGRADIENTX=Shader3D.propertyNameToID("u_SOLSizeGradientX");},'SOLSIZEGRADIENTY',function(){return this.SOLSIZEGRADIENTY=Shader3D.propertyNameToID("u_SOLSizeGradientY");},'SOLSizeGradientZ',function(){return this.SOLSizeGradientZ=Shader3D.propertyNameToID("u_SOLSizeGradientZ");},'SOLSizeGradientMax',function(){return this.SOLSizeGradientMax=Shader3D.propertyNameToID("u_SOLSizeGradientMax");},'SOLSIZEGRADIENTXMAX',function(){return this.SOLSIZEGRADIENTXMAX=Shader3D.propertyNameToID("u_SOLSizeGradientMaxX");},'SOLSIZEGRADIENTYMAX',function(){return this.SOLSIZEGRADIENTYMAX=Shader3D.propertyNameToID("u_SOLSizeGradientMaxY");},'SOLSizeGradientZMAX',function(){return this.SOLSizeGradientZMAX=Shader3D.propertyNameToID("u_SOLSizeGradientMaxZ");},'ROLANGULARVELOCITYCONST',function(){return this.ROLANGULARVELOCITYCONST=Shader3D.propertyNameToID("u_ROLAngularVelocityConst");},'ROLANGULARVELOCITYCONSTSEPRARATE',function(){return this.ROLANGULARVELOCITYCONSTSEPRARATE=Shader3D.propertyNameToID("u_ROLAngularVelocityConstSeprarate");},'ROLANGULARVELOCITYGRADIENT',function(){return this.ROLANGULARVELOCITYGRADIENT=Shader3D.propertyNameToID("u_ROLAngularVelocityGradient");},'ROLANGULARVELOCITYGRADIENTX',function(){return this.ROLANGULARVELOCITYGRADIENTX=Shader3D.propertyNameToID("u_ROLAngularVelocityGradientX");},'ROLANGULARVELOCITYGRADIENTY',function(){return this.ROLANGULARVELOCITYGRADIENTY=Shader3D.propertyNameToID("u_ROLAngularVelocityGradientY");},'ROLANGULARVELOCITYGRADIENTZ',function(){return this.ROLANGULARVELOCITYGRADIENTZ=Shader3D.propertyNameToID("u_ROLAngularVelocityGradientZ");},'ROLANGULARVELOCITYCONSTMAX',function(){return this.ROLANGULARVELOCITYCONSTMAX=Shader3D.propertyNameToID("u_ROLAngularVelocityConstMax");},'ROLANGULARVELOCITYCONSTMAXSEPRARATE',function(){return this.ROLANGULARVELOCITYCONSTMAXSEPRARATE=Shader3D.propertyNameToID("u_ROLAngularVelocityConstMaxSeprarate");},'ROLANGULARVELOCITYGRADIENTMAX',function(){return this.ROLANGULARVELOCITYGRADIENTMAX=Shader3D.propertyNameToID("u_ROLAngularVelocityGradientMax");},'ROLANGULARVELOCITYGRADIENTXMAX',function(){return this.ROLANGULARVELOCITYGRADIENTXMAX=Shader3D.propertyNameToID("u_ROLAngularVelocityGradientMaxX");},'ROLANGULARVELOCITYGRADIENTYMAX',function(){return this.ROLANGULARVELOCITYGRADIENTYMAX=Shader3D.propertyNameToID("u_ROLAngularVelocityGradientMaxY");},'ROLANGULARVELOCITYGRADIENTZMAX',function(){return this.ROLANGULARVELOCITYGRADIENTZMAX=Shader3D.propertyNameToID("u_ROLAngularVelocityGradientMaxZ");},'ROLANGULARVELOCITYGRADIENTWMAX',function(){return this.ROLANGULARVELOCITYGRADIENTWMAX=Shader3D.propertyNameToID("u_ROLAngularVelocityGradientMaxW");},'TEXTURESHEETANIMATIONCYCLES',function(){return this.TEXTURESHEETANIMATIONCYCLES=Shader3D.propertyNameToID("u_TSACycles");},'TEXTURESHEETANIMATIONSUBUVLENGTH',function(){return this.TEXTURESHEETANIMATIONSUBUVLENGTH=Shader3D.propertyNameToID("u_TSASubUVLength");},'TEXTURESHEETANIMATIONGRADIENTUVS',function(){return this.TEXTURESHEETANIMATIONGRADIENTUVS=Shader3D.propertyNameToID("u_TSAGradientUVs");},'TEXTURESHEETANIMATIONGRADIENTMAXUVS',function(){return this.TEXTURESHEETANIMATIONGRADIENTMAXUVS=Shader3D.propertyNameToID("u_TSAMaxGradientUVs");},'shaderDefines',function(){return this.shaderDefines=new ShaderDefines(RenderableSprite3D.shaderDefines);}
- ]);
- return ShuriKenParticle3D;
- })(RenderableSprite3D)
- /**
- *<code>PixelLineSprite3D</code> 类用于像素线渲染精灵。
- */
- //class laya.d3.core.pixelLine.PixelLineSprite3D extends laya.d3.core.RenderableSprite3D
- var PixelLineSprite3D=(function(_super){
- function PixelLineSprite3D(maxCount,name){
- /**@private */
- this._geometryFilter=null;
- (maxCount===void 0)&& (maxCount=2);
- PixelLineSprite3D.__super.call(this,name);
- this._geometryFilter=new PixelLineFilter(this,maxCount);
- this._render=new PixelLineRenderer(this);
- this._changeRenderObjects(this._render,0,PixelLineMaterial.defaultMaterial);
- }
- __class(PixelLineSprite3D,'laya.d3.core.pixelLine.PixelLineSprite3D',_super);
- var __proto=PixelLineSprite3D.prototype;
- /**
- *@inheritDoc
- */
- __proto._changeRenderObjects=function(sender,index,material){
- var renderObjects=this._render._renderElements;
- (material)|| (material=PixelLineMaterial.defaultMaterial);
- var renderElement=renderObjects[index];
- (renderElement)|| (renderElement=renderObjects[index]=new RenderElement());
- renderElement.setTransform(this._transform);
- renderElement.setGeometry(this._geometryFilter);
- renderElement.render=this._render;
- renderElement.material=material;
- }
- /**
- *增加一条线。
- *@param startPosition 初始点位置
- *@param endPosition 结束点位置
- *@param startColor 初始点颜色
- *@param endColor 结束点颜色
- */
- __proto.addLine=function(startPosition,endPosition,startColor,endColor){
- if (this._geometryFilter._lineCount!==this._geometryFilter._maxLineCount)
- this._geometryFilter._updateLineData(this._geometryFilter._lineCount++,startPosition,endPosition,startColor,endColor);
- else
- throw "PixelLineSprite3D: lineCount has equal with maxLineCount.";
- }
- /**
- *添加多条线段。
- *@param lines 线段数据
- */
- __proto.addLines=function(lines){
- var lineCount=this._geometryFilter._lineCount;
- var addCount=lines.length;
- if (lineCount+addCount > this._geometryFilter._maxLineCount){
- throw "PixelLineSprite3D: lineCount plus lines count must less than maxLineCount.";
- }else {
- this._geometryFilter._updateLineDatas(lineCount,lines);
- this._geometryFilter._lineCount+=addCount;
- }
- }
- /**
- *移除一条线段。
- *@param index 索引。
- */
- __proto.removeLine=function(index){
- if (index < this._geometryFilter._lineCount)
- this._geometryFilter._removeLineData(index);
- else
- throw "PixelLineSprite3D: index must less than lineCount.";
- }
- /**
- *更新线
- *@param index 索引
- *@param startPosition 初始点位置
- *@param endPosition 结束点位置
- *@param startColor 初始点颜色
- *@param endColor 结束点颜色
- */
- __proto.setLine=function(index,startPosition,endPosition,startColor,endColor){
- if (index < this._geometryFilter._lineCount)
- this._geometryFilter._updateLineData(index,startPosition,endPosition,startColor,endColor);
- else
- throw "PixelLineSprite3D: index must less than lineCount.";
- }
- /**
- *获取线段数据
- *@param out 线段数据。
- */
- __proto.getLine=function(index,out){
- if (index < this.lineCount)
- this._geometryFilter._getLineData(index,out);
- else
- throw "PixelLineSprite3D: index must less than lineCount.";
- }
- /**
- *清除所有线段。
- */
- __proto.clear=function(){
- this._geometryFilter._lineCount=0;
- }
- /**
- *设置最大线数量
- *@param value 最大线数量。
- */
- /**
- *获取最大线数量
- *@return 最大线数量。
- */
- __getset(0,__proto,'maxLineCount',function(){
- return this._geometryFilter._maxLineCount;
- },function(value){
- this._geometryFilter._resizeLineData(value);
- this._geometryFilter._lineCount=Math.min(this._geometryFilter._lineCount,value);
- });
- /**
- *获取line渲染器。
- *@return line渲染器。
- */
- __getset(0,__proto,'pixelLineRenderer',function(){
- return this._render;
- });
- /**
- *设置获取线数量。
- *@param value 线段数量。
- */
- /**
- *获取线数量。
- *@return 线段数量。
- */
- __getset(0,__proto,'lineCount',function(){
- return this._geometryFilter._lineCount;
- },function(value){
- if (value > this.maxLineCount)
- throw "PixelLineSprite3D: lineCount can't large than maxLineCount";
- else
- this._geometryFilter._lineCount=value;
- });
- return PixelLineSprite3D;
- })(RenderableSprite3D)
- /**
- *<code>SkinnedMeshSprite3D</code> 类用于创建网格。
- */
- //class laya.d3.core.SkinnedMeshSprite3D extends laya.d3.core.RenderableSprite3D
- var SkinnedMeshSprite3D=(function(_super){
- function SkinnedMeshSprite3D(mesh,name){
- /**@private */
- //this._meshFilter=null;
- SkinnedMeshSprite3D.__super.call(this,name);
- this._meshFilter=new MeshFilter(this);
- this._render=new SkinnedMeshRenderer(this);
- (mesh)&& (this._meshFilter.sharedMesh=mesh);
- }
- __class(SkinnedMeshSprite3D,'laya.d3.core.SkinnedMeshSprite3D',_super);
- var __proto=SkinnedMeshSprite3D.prototype;
- /**
- *@inheritDoc
- */
- __proto._parse=function(data,spriteMap){
- laya.d3.core.Sprite3D.prototype._parse.call(this,data,spriteMap);
- var render=this.skinnedMeshRenderer;
- var lightmapIndex=data.lightmapIndex;
- (lightmapIndex !=null)&& (render.lightmapIndex=lightmapIndex);
- var lightmapScaleOffsetArray=data.lightmapScaleOffset;
- (lightmapScaleOffsetArray)&& (render.lightmapScaleOffset=new Vector4(lightmapScaleOffsetArray[0],lightmapScaleOffsetArray[1],lightmapScaleOffsetArray[2],lightmapScaleOffsetArray[3]));
- var meshPath;
- meshPath=data.meshPath;
- if (meshPath){
- var mesh=Loader.getRes(meshPath);
- (mesh)&& (this.meshFilter.sharedMesh=mesh);
- };
- var materials=data.materials;
- if (materials){
- var sharedMaterials=render.sharedMaterials;
- var materialCount=materials.length;
- sharedMaterials.length=materialCount;
- for (var i=0;i < materialCount;i++){
- sharedMaterials[i]=Loader.getRes(materials[i].path);
- }
- render.sharedMaterials=sharedMaterials;
- };
- var boundBox=data.boundBox;
- var min=boundBox.min;
- var max=boundBox.max;
- render.localBounds.setMin(new Vector3(min[0],min[1],min[2]));
- render.localBounds.setMax(new Vector3(max[0],max[1],max[2]));
- if (spriteMap){
- var rootBoneData=data.rootBone;
- render.rootBone=spriteMap[rootBoneData];
- var bonesData=data.bones;
- var n=0;
- for (i=0,n=bonesData.length;i < n;i++)
- render.bones.push(spriteMap[bonesData[i]]);
- }else {
- (data.rootBone)&& (render._setRootBone(data.rootBone));
- }
- }
- /**
- *@inheritDoc
- */
- __proto._changeHierarchyAnimator=function(animator){
- _super.prototype._changeHierarchyAnimator.call(this,animator);
- this.skinnedMeshRenderer._setCacheAnimator(animator);
- }
- /**
- *@inheritDoc
- */
- __proto._changeAnimatorAvatar=function(avatar){
- this.skinnedMeshRenderer._setCacheAvatar(avatar);
- }
- /**
- *@inheritDoc
- */
- __proto._cloneTo=function(destObject,srcRoot,dstRoot){
- var meshSprite3D=destObject;
- meshSprite3D.meshFilter.sharedMesh=this.meshFilter.sharedMesh;
- var meshRender=this._render;
- var destMeshRender=meshSprite3D._render;
- destMeshRender.enable=meshRender.enable;
- destMeshRender.sharedMaterials=meshRender.sharedMaterials;
- destMeshRender.castShadow=meshRender.castShadow;
- var lightmapScaleOffset=meshRender.lightmapScaleOffset;
- lightmapScaleOffset && (destMeshRender.lightmapScaleOffset=lightmapScaleOffset.clone());
- destMeshRender.receiveShadow=meshRender.receiveShadow;
- destMeshRender.sortingFudge=meshRender.sortingFudge;
- destMeshRender._rootBone=meshRender._rootBone;
- var bones=meshRender.bones;
- var destBones=destMeshRender.bones;
- var bonesCount=bones.length;
- destBones.length=bonesCount;
- var rootBone=meshRender.rootBone;
- if (rootBone){
- var pathes=Utils3D._getHierarchyPath(srcRoot,rootBone,SkinnedMeshSprite3D._tempArray0);
- if (pathes)
- destMeshRender.rootBone=Utils3D._getNodeByHierarchyPath(dstRoot,pathes);
- else
- destMeshRender.rootBone=rootBone;
- }
- for (var i=0;i < bones.length;i++){
- pathes=Utils3D._getHierarchyPath(srcRoot,bones[i],SkinnedMeshSprite3D._tempArray0);
- if (pathes)
- destBones[i]=Utils3D._getNodeByHierarchyPath(dstRoot,pathes);
- else
- destBones[i]=bones[i];
- };
- var lbb=meshRender.localBounds;
- (lbb)&& (lbb.cloneTo(destMeshRender.localBounds));
- laya.d3.core.Sprite3D.prototype._cloneTo.call(this,destObject,srcRoot,dstRoot);
- }
- /**
- *@inheritDoc
- */
- __proto.destroy=function(destroyChild){
- (destroyChild===void 0)&& (destroyChild=true);
- if (this.destroyed)
- return;
- _super.prototype.destroy.call(this,destroyChild);
- this._meshFilter.destroy();
- }
- /**
- *获取网格过滤器。
- *@return 网格过滤器。
- */
- __getset(0,__proto,'meshFilter',function(){
- return this._meshFilter;
- });
- /**
- *获取网格渲染器。
- *@return 网格渲染器。
- */
- __getset(0,__proto,'skinnedMeshRenderer',function(){
- return this._render;
- });
- SkinnedMeshSprite3D.__init__=function(){
- SkinnedMeshSprite3D.SHADERDEFINE_BONE=SkinnedMeshSprite3D.shaderDefines.registerDefine("BONE");
- }
- SkinnedMeshSprite3D._tempArray0=[];
- SkinnedMeshSprite3D.SHADERDEFINE_BONE=0;
- __static(SkinnedMeshSprite3D,
- ['BONES',function(){return this.BONES=Shader3D.propertyNameToID("u_Bones");},'shaderDefines',function(){return this.shaderDefines=new ShaderDefines(MeshSprite3D.shaderDefines);}
- ]);
- return SkinnedMeshSprite3D;
- })(RenderableSprite3D)
- /**
- *<code>PointLight</code> 类用于创建点光。
- */
- //class laya.d3.core.light.PointLight extends laya.d3.core.light.LightSprite
- var PointLight=(function(_super){
- function PointLight(){
- /**@private */
- this._range=NaN;
- this._lightMatrix=new Matrix4x4();
- PointLight.__super.call(this);
- this._range=6.0;
- }
- __class(PointLight,'laya.d3.core.light.PointLight',_super);
- var __proto=PointLight.prototype;
- /**
- *@inheritDoc
- */
- __proto._onActive=function(){
- _super.prototype._onActive.call(this);
- (this._lightmapBakedType!==LightSprite.LIGHTMAPBAKEDTYPE_BAKED)&&((this._scene)._defineDatas.add(Scene3D.SHADERDEFINE_POINTLIGHT));
- }
- /**
- *@inheritDoc
- */
- __proto._onInActive=function(){
- _super.prototype._onInActive.call(this);
- (this._lightmapBakedType!==LightSprite.LIGHTMAPBAKEDTYPE_BAKED)&&((this._scene)._defineDatas.remove(Scene3D.SHADERDEFINE_POINTLIGHT));
- }
- /**
- *更新点光相关渲染状态参数。
- *@param state 渲染状态参数。
- */
- __proto._prepareToScene=function(){
- var scene=this._scene;
- if (scene.enableLight && this.activeInHierarchy){
- var defineDatas=scene._defineDatas;
- var shaderValue=scene._shaderValues;
- Vector3.scale(this.color,this._intensity,this._intensityColor);
- shaderValue.setVector3(Scene3D.POINTLIGHTCOLOR,this._intensityColor);
- shaderValue.setVector3(Scene3D.POINTLIGHTPOS,this.transform.position);
- shaderValue.setNumber(Scene3D.POINTLIGHTRANGE,this.range);
- var lightMatrix=this._lightMatrix;
- var lightMatrixE=lightMatrix.elements;
- lightMatrix.identity();
- lightMatrixE[0]=lightMatrixE[5]=lightMatrixE[10]=1.0 / this._range;
- var toLightMatrix=PointLight._tempMatrix0;
- this.transform.worldMatrix.invert(toLightMatrix);
- Matrix4x4.multiply(lightMatrix,toLightMatrix,lightMatrix);
- shaderValue.setMatrix4x4(Scene3D.POINTLIGHTMATRIX,lightMatrix);
- return true;
- }else {
- return false;
- }
- }
- /**
- *@inheritDoc
- */
- __proto._parse=function(data,spriteMap){
- _super.prototype._parse.call(this,data,spriteMap);
- this.range=data.range;
- }
- /**
- *设置点光的范围。
- *@param value 点光的范围。
- */
- /**
- *获取点光的范围。
- *@return 点光的范围。
- */
- __getset(0,__proto,'range',function(){
- return this._range;
- },function(value){
- this._range=value;
- });
- __static(PointLight,
- ['_tempMatrix0',function(){return this._tempMatrix0=new Matrix4x4();}
- ]);
- return PointLight;
- })(LightSprite)
- /**
- *<code>TerrainChunk</code> 类用于创建地块。
- */
- //class laya.d3.terrain.TerrainChunk extends laya.d3.core.RenderableSprite3D
- var TerrainChunk=(function(_super){
- function TerrainChunk(chunkOffsetX,chunkOffsetZ,girdSize,terrainHeightData,heightDataWidth,heightDataHeight,cameraCoordinateInverse,name){
- /**@private */
- this._terrainFilter=null;
- TerrainChunk.__super.call(this,name);
- this._terrainFilter=new TerrainFilter(this,chunkOffsetX,chunkOffsetZ,girdSize,terrainHeightData,heightDataWidth,heightDataHeight,cameraCoordinateInverse);
- this._render=new TerrainRender(this);
- }
- __class(TerrainChunk,'laya.d3.terrain.TerrainChunk',_super);
- var __proto=TerrainChunk.prototype;
- __proto.buildRenderElementAndMaterial=function(detailNum,normalMap,alphaMapUrl,detailUrl1,detailUrl2,detailUrl3,detailUrl4,ambientColor,diffuseColor,specularColor,sx1,sy1,sx2,sy2,sx3,sy3,sx4,sy4){
- (sx1===void 0)&& (sx1=1);
- (sy1===void 0)&& (sy1=1);
- (sx2===void 0)&& (sx2=1);
- (sy2===void 0)&& (sy2=1);
- (sx3===void 0)&& (sx3=1);
- (sy3===void 0)&& (sy3=1);
- (sx4===void 0)&& (sx4=1);
- (sy4===void 0)&& (sy4=1);
- var terrainMaterial=new TerrainMaterial();
- if (diffuseColor)terrainMaterial.diffuseColor=diffuseColor;
- if (ambientColor)terrainMaterial.ambientColor=ambientColor;
- if (specularColor)terrainMaterial.specularColor=specularColor;
- terrainMaterial.splatAlphaTexture=Loader.getRes(alphaMapUrl);
- terrainMaterial.normalTexture=normalMap ? Loader.getRes(normalMap):null;
- terrainMaterial.diffuseTexture1=detailUrl1 ? Loader.getRes(detailUrl1):null;
- terrainMaterial.diffuseTexture2=detailUrl2 ? Loader.getRes(detailUrl2):null;
- terrainMaterial.diffuseTexture3=detailUrl3 ? Loader.getRes(detailUrl3):null;
- terrainMaterial.diffuseTexture4=detailUrl4 ? Loader.getRes(detailUrl4):null;
- terrainMaterial.setDiffuseScale1(sx1,sy1);
- terrainMaterial.setDiffuseScale2(sx2,sy2);
- terrainMaterial.setDiffuseScale3(sx3,sy3);
- terrainMaterial.setDiffuseScale4(sx4,sy4);
- terrainMaterial.setDetailNum(detailNum);
- if (this._render._renderElements.length !=0){
- terrainMaterial.renderMode=/*laya.d3.core.material.TerrainMaterial.RENDERMODE_TRANSPARENT*/2;
- };
- var renderElement=new RenderElement();
- renderElement.setTransform(this._transform);
- renderElement.render=this._render;
- renderElement.setGeometry(this._terrainFilter);
- this._render._renderElements.push(renderElement);
- this._render.sharedMaterial=terrainMaterial;
- }
- __proto._cloneTo=function(destObject,srcSprite,dstSprite){
- console.log("Terrain Chunk can't clone");
- }
- __proto.destroy=function(destroyChild){
- (destroyChild===void 0)&& (destroyChild=true);
- if (this.destroyed)
- return;
- _super.prototype.destroy.call(this,destroyChild);
- this._terrainFilter.destroy();
- this._terrainFilter=null;
- }
- /**
- *获取地形过滤器。
- *@return 地形过滤器。
- */
- __getset(0,__proto,'terrainFilter',function(){
- return this._terrainFilter;
- });
- /**
- *获取地形渲染器。
- *@return 地形渲染器。
- */
- __getset(0,__proto,'terrainRender',function(){
- return this._render;
- });
- return TerrainChunk;
- })(RenderableSprite3D)
- /**
- *<code>Camera</code> 类用于创建摄像机。
- */
- //class laya.d3.core.Camera extends laya.d3.core.BaseCamera
- var Camera=(function(_super){
- function Camera(aspectRatio,nearPlane,farPlane){
- /**@private */
- //this._aspectRatio=NaN;
- /**@private */
- //this._viewport=null;
- /**@private */
- //this._normalizedViewport=null;
- /**@private */
- //this._viewMatrix=null;
- /**@private */
- //this._projectionMatrix=null;
- /**@private */
- //this._projectionViewMatrix=null;
- /**@private */
- //this._projectionViewMatrixNoTranslateScale=null;
- /**@private */
- //this._boundFrustum=null;
- /**@private */
- this._updateViewMatrix=true;
- /**@private 渲染目标。*/
- this._offScreenRenderTexture=null;
- /**@private */
- this._alwaysUseRenderTexture=false;
- /**@private */
- this._renderTexture=null;
- /**@private */
- this._postProcess=null;
- /**是否允许渲染。*/
- this.enableRender=true;
- /**@private [NATIVE]*/
- //this._boundFrustumBuffer=null;
- this._screenShaderData=new ShaderData();
- this._postProcessCommandBuffers=[];
- (aspectRatio===void 0)&& (aspectRatio=0);
- (nearPlane===void 0)&& (nearPlane=0.3);
- (farPlane===void 0)&& (farPlane=1000);
- this._viewMatrix=new Matrix4x4();
- this._projectionMatrix=new Matrix4x4();
- this._projectionViewMatrix=new Matrix4x4();
- this._projectionViewMatrixNoTranslateScale=new Matrix4x4();
- this._viewport=new Viewport(0,0,0,0);
- this._normalizedViewport=new Viewport(0,0,1,1);
- this._aspectRatio=aspectRatio;
- this._boundFrustum=new BoundFrustum(Matrix4x4.DEFAULT);
- if (Render.supportWebGLPlusCulling)
- this._boundFrustumBuffer=new Float32Array(24);
- Camera.__super.call(this,nearPlane,farPlane);
- this.transform.on(/*laya.events.Event.TRANSFORM_CHANGED*/"transformchanged",this,this._onTransformChanged);
- }
- __class(Camera,'laya.d3.core.Camera',_super);
- var __proto=Camera.prototype;
- /**
- *通过蒙版值获取蒙版是否显示。
- *@param layer 层。
- *@return 是否显示。
- */
- __proto._isLayerVisible=function(layer){
- return (Math.pow(2,layer)& this.cullingMask)!=0;
- }
- /**
- *@private
- */
- __proto._onTransformChanged=function(flag){
- flag &=/*laya.d3.core.Transform3D.TRANSFORM_WORLDMATRIX*/0x40;
- (flag)&& (this._updateViewMatrix=true);
- }
- /**
- *@private
- */
- __proto._calculationViewport=function(normalizedViewport,width,height){
- var lx=normalizedViewport.x *width;
- var ly=normalizedViewport.y *height;
- var rx=lx+Math.max(normalizedViewport.width *width,0);
- var ry=ly+Math.max(normalizedViewport.height *height,0);
- var ceilLeftX=Math.ceil(lx);
- var ceilLeftY=Math.ceil(ly);
- var floorRightX=Math.floor(rx);
- var floorRightY=Math.floor(ry);
- var pixelLeftX=ceilLeftX-lx >=0.5 ? Math.floor(lx):ceilLeftX;
- var pixelLeftY=ceilLeftY-ly >=0.5 ? Math.floor(ly):ceilLeftY;
- var pixelRightX=rx-floorRightX >=0.5 ? Math.ceil(rx):floorRightX;
- var pixelRightY=ry-floorRightY >=0.5 ? Math.ceil(ry):floorRightY;
- this._viewport.x=pixelLeftX;
- this._viewport.y=pixelLeftY;
- this._viewport.width=pixelRightX-pixelLeftX;
- this._viewport.height=pixelRightY-pixelLeftY;
- }
- /**
- *@inheritDoc
- */
- __proto._parse=function(data,spriteMap){
- _super.prototype._parse.call(this,data,spriteMap);
- var viewport=data.viewport;
- this.normalizedViewport=new Viewport(viewport[0],viewport[1],viewport[2],viewport[3]);
- }
- /**
- *@inheritDoc
- */
- __proto._calculateProjectionMatrix=function(){
- if (!this._useUserProjectionMatrix){
- if (this._orthographic){
- var halfWidth=this.orthographicVerticalSize *this.aspectRatio *0.5;
- var halfHeight=this.orthographicVerticalSize *0.5;
- Matrix4x4.createOrthoOffCenter(-halfWidth,halfWidth,-halfHeight,halfHeight,this.nearPlane,this.farPlane,this._projectionMatrix);
- }else {
- Matrix4x4.createPerspective(3.1416 *this.fieldOfView / 180.0,this.aspectRatio,this.nearPlane,this.farPlane,this._projectionMatrix);
- }
- }
- }
- /**
- *@private
- */
- __proto._getCanvasHeight=function(){
- if (this._offScreenRenderTexture)
- return this._offScreenRenderTexture.height;
- else
- return RenderContext3D.clientHeight;
- }
- /**
- *@private
- */
- __proto._applyPostProcessCommandBuffers=function(){
- for (var i=0,n=this._postProcessCommandBuffers.length;i < n;i++)
- this._postProcessCommandBuffers[i]._apply();
- }
- /**
- *@private
- */
- __proto._needForceSetRenderTexture=function(){
- return this._alwaysUseRenderTexture && !this._offScreenRenderTexture;
- }
- /**
- *@inheritDoc
- */
- __proto.render=function(shader,replacementTag){
- if (!this._scene)
- return;
- var forceSetRenderTexture=this._needForceSetRenderTexture();
- if (forceSetRenderTexture)
- this._renderTexture=RenderTexture.getTemporary(RenderContext3D.clientWidth,RenderContext3D.clientHeight,/*laya.resource.BaseTexture.FORMAT_R8G8B8*/0,/*laya.resource.BaseTexture.FORMAT_DEPTH_16*/0,/*laya.resource.BaseTexture.FILTERMODE_BILINEAR*/1);
- var gl=LayaGL.instance;
- var context=RenderContext3D._instance;
- var scene=context.scene=this._scene;
- if (scene.parallelSplitShadowMaps[0]){
- ShaderData.setRuntimeValueMode(false);
- var parallelSplitShadowMap=scene.parallelSplitShadowMaps[0];
- parallelSplitShadowMap._calcAllLightCameraInfo(this);
- scene._defineDatas.add(Scene3D.SHADERDEFINE_CAST_SHADOW);
- for (var i=0,n=parallelSplitShadowMap.shadowMapCount;i < n;i++){
- var smCamera=parallelSplitShadowMap.cameras[i];
- context.camera=smCamera;
- context.projectionViewMatrix=smCamera.projectionViewMatrix;
- FrustumCulling.renderObjectCulling(smCamera,scene,context,scene._castShadowRenders);
- var shadowMap=parallelSplitShadowMap.cameras[i+1].renderTarget;
- shadowMap._start();
- context.camera=smCamera;
- context.viewport=smCamera.viewport;
- smCamera._prepareCameraToRender();
- smCamera._prepareCameraViewProject(smCamera.viewMatrix,smCamera.projectionMatrix,context.projectionViewMatrix,smCamera._projectionViewMatrixNoTranslateScale);
- scene._clear(gl,context);
- var queue=scene._opaqueQueue;
- queue._render(context,false);
- shadowMap._end();
- }
- scene._defineDatas.remove(Scene3D.SHADERDEFINE_CAST_SHADOW);
- ShaderData.setRuntimeValueMode(true);
- }
- context.camera=this;
- scene._preRenderScript();
- var viewMat,projectMat;
- viewMat=context.viewMatrix=this.viewMatrix;
- var renderTar=this._renderTexture;
- if (renderTar){
- renderTar._start();
- Matrix4x4.multiply(BaseCamera._invertYScaleMatrix,this._projectionMatrix,BaseCamera._invertYProjectionMatrix);
- Matrix4x4.multiply(BaseCamera._invertYScaleMatrix,this.projectionViewMatrix,BaseCamera._invertYProjectionViewMatrix);
- projectMat=context.projectionMatrix=BaseCamera._invertYProjectionMatrix;
- context.projectionViewMatrix=BaseCamera._invertYProjectionViewMatrix;
- }else {
- projectMat=context.projectionMatrix=this._projectionMatrix;
- context.projectionViewMatrix=this.projectionViewMatrix;
- }
- context.viewport=this.viewport;
- this._prepareCameraToRender();
- this._prepareCameraViewProject(viewMat,projectMat,context.projectionViewMatrix,this._projectionViewMatrixNoTranslateScale);
- scene._preCulling(context,this);
- scene._clear(gl,context);
- scene._renderScene(gl,context,shader,replacementTag);
- scene._postRenderScript();
- (renderTar)&& (renderTar._end());
- (this._postProcess)&& (this._postProcess._render());
- if (forceSetRenderTexture){
- var blit=BlitCMD.create(this._renderTexture,null,CommandBuffer.screenShader,this._screenShaderData);
- blit.run();
- blit.recover();
- RenderTexture.setReleaseTemporary(this._renderTexture);
- }
- }
- /**
- *计算从屏幕空间生成的射线。
- *@param point 屏幕空间的位置位置。
- *@return out 输出射线。
- */
- __proto.viewportPointToRay=function(point,out){
- Picker.calculateCursorRay(point,this.viewport,this._projectionMatrix,this.viewMatrix,null,out);
- }
- /**
- *计算从裁切空间生成的射线。
- *@param point 裁切空间的位置。。
- *@return out 输出射线。
- */
- __proto.normalizedViewportPointToRay=function(point,out){
- var finalPoint=Camera._tempVector20;
- var vp=this.viewport;
- finalPoint.x=point.x *vp.width;
- finalPoint.y=point.y *vp.height;
- Picker.calculateCursorRay(finalPoint,this.viewport,this._projectionMatrix,this.viewMatrix,null,out);
- }
- /**
- *计算从世界空间准换三维坐标到屏幕空间。
- *@param position 世界空间的位置。
- *@return out 输出位置。
- */
- __proto.worldToViewportPoint=function(position,out){
- Matrix4x4.multiply(this._projectionMatrix,this._viewMatrix,this._projectionViewMatrix);
- this.viewport.project(position,this._projectionViewMatrix,out);
- out.x=out.x / Laya.stage.clientScaleX;
- out.y=out.y / Laya.stage.clientScaleY;
- }
- /**
- *计算从世界空间准换三维坐标到裁切空间。
- *@param position 世界空间的位置。
- *@return out 输出位置。
- */
- __proto.worldToNormalizedViewportPoint=function(position,out){
- Matrix4x4.multiply(this._projectionMatrix,this._viewMatrix,this._projectionViewMatrix);
- this.normalizedViewport.project(position,this._projectionViewMatrix,out);
- out.x=out.x / Laya.stage.clientScaleX;
- out.y=out.y / Laya.stage.clientScaleY;
- }
- /**
- *转换2D屏幕坐标系统到3D正交投影下的坐标系统,注:只有正交模型下有效。
- *@param source 源坐标。
- *@param out 输出坐标。
- *@return 是否转换成功。
- */
- __proto.convertScreenCoordToOrthographicCoord=function(source,out){
- if (this._orthographic){
- var clientWidth=RenderContext3D.clientWidth;
- var clientHeight=RenderContext3D.clientHeight;
- var ratioX=this.orthographicVerticalSize *this.aspectRatio / clientWidth;
- var ratioY=this.orthographicVerticalSize / clientHeight;
- out.x=(-clientWidth / 2+source.x)*ratioX;
- out.y=(clientHeight / 2-source.y)*ratioY;
- out.z=(this.nearPlane-this.farPlane)*(source.z+1)/ 2-this.nearPlane;
- Vector3.transformCoordinate(out,this.transform.worldMatrix,out);
- return true;
- }else {
- return false;
- }
- }
- /**
- *@inheritDoc
- */
- __proto.destroy=function(destroyChild){
- (destroyChild===void 0)&& (destroyChild=true);
- this._offScreenRenderTexture=null;
- this.transform.off(/*laya.events.Event.TRANSFORM_CHANGED*/"transformchanged",this,this._onTransformChanged);
- _super.prototype.destroy.call(this,destroyChild);
- }
- /**
- *在特定渲染管线阶段添加指令缓存。
- */
- __proto.addCommandBuffer=function(event,commandBuffer){
- switch (event){
- case 0:
- this._postProcessCommandBuffers.push(commandBuffer);
- break ;
- default :
- throw "Camera:unknown event.";
- }
- }
- /**
- *在特定渲染管线阶段移除指令缓存。
- */
- __proto.removeCommandBuffer=function(event,commandBuffer){
- switch (event){
- case 0:;
- var index=this._postProcessCommandBuffers.indexOf(commandBuffer);
- if (index!==-1)
- this._postProcessCommandBuffers.splice(index,1);
- break ;
- default :
- throw "Camera:unknown event.";
- }
- }
- /**
- *在特定渲染管线阶段移除所有指令缓存。
- */
- __proto.removeCommandBuffers=function(event){
- switch (event){
- case 0:
- this._postProcessCommandBuffers.length=0;
- break ;
- default :
- throw "Camera:unknown event.";
- }
- }
- /**
- *获取渲染结果纹理。
- *@return 渲染结果纹理。
- */
- __proto.getRenderTexture=function(){
- return this._renderTexture;
- }
- /**
- *设置自定义渲染场景的渲染目标。
- *@param value 自定义渲染场景的渲染目标。
- */
- /**
- *获取自定义渲染场景的渲染目标。
- *@return 自定义渲染场景的渲染目标。
- */
- __getset(0,__proto,'renderTarget',function(){
- return this._offScreenRenderTexture;
- },function(value){
- if (this._offScreenRenderTexture!==value){
- this._offScreenRenderTexture=value;
- this._renderTexture=value;
- this._calculateProjectionMatrix();
- }
- });
- /**
- *获取视图投影矩阵。
- *@return 视图投影矩阵。
- */
- __getset(0,__proto,'projectionViewMatrix',function(){
- Matrix4x4.multiply(this.projectionMatrix,this.viewMatrix,this._projectionViewMatrix);
- return this._projectionViewMatrix;
- });
- /**
- *设置横纵比。
- *@param value 横纵比。
- */
- /**
- *获取横纵比。
- *@return 横纵比。
- */
- __getset(0,__proto,'aspectRatio',function(){
- if (this._aspectRatio===0){
- var vp=this.viewport;
- return vp.width / vp.height;
- }
- return this._aspectRatio;
- },function(value){
- if (value < 0)
- throw new Error("Camera: the aspect ratio has to be a positive real number.");
- this._aspectRatio=value;
- this._calculateProjectionMatrix();
- });
- /**
- *获取摄像机视锥。
- */
- __getset(0,__proto,'boundFrustum',function(){
- this._boundFrustum.matrix=this.projectionViewMatrix;
- if (Render.supportWebGLPlusCulling){
- var near=this._boundFrustum.near;
- var far=this._boundFrustum.far;
- var left=this._boundFrustum.left;
- var right=this._boundFrustum.right;
- var top=this._boundFrustum.top;
- var bottom=this._boundFrustum.bottom;
- var nearNE=near.normal;
- var farNE=far.normal;
- var leftNE=left.normal;
- var rightNE=right.normal;
- var topNE=top.normal;
- var bottomNE=bottom.normal;
- var buffer=this._boundFrustumBuffer;
- buffer[0]=nearNE.x,buffer[1]=nearNE.y,buffer[2]=nearNE.z,buffer[3]=near.distance;
- buffer[4]=farNE.x,buffer[5]=farNE.y,buffer[6]=farNE.z,buffer[7]=far.distance;
- buffer[8]=leftNE.x,buffer[9]=leftNE.y,buffer[10]=leftNE.z,buffer[11]=left.distance;
- buffer[12]=rightNE.x,buffer[13]=rightNE.y,buffer[14]=rightNE.z,buffer[15]=right.distance;
- buffer[16]=topNE.x,buffer[17]=topNE.y,buffer[18]=topNE.z,buffer[19]=top.distance;
- buffer[20]=bottomNE.x,buffer[21]=bottomNE.y,buffer[22]=bottomNE.z,buffer[23]=bottom.distance;
- }
- return this._boundFrustum;
- });
- /**
- *设置屏幕像素坐标的视口。
- *@param 屏幕像素坐标的视口。
- */
- /**
- *获取屏幕像素坐标的视口。
- *@return 屏幕像素坐标的视口。
- */
- __getset(0,__proto,'viewport',function(){
- if (this._offScreenRenderTexture)
- this._calculationViewport(this._normalizedViewport,this._offScreenRenderTexture.width,this._offScreenRenderTexture.height);
- else
- this._calculationViewport(this._normalizedViewport,RenderContext3D.clientWidth,RenderContext3D.clientHeight);
- return this._viewport;
- },function(value){
- var width=0;
- var height=0;
- if (this._offScreenRenderTexture){
- width=this._offScreenRenderTexture.width;
- height=this._offScreenRenderTexture.height;
- }else {
- width=RenderContext3D.clientWidth;
- height=RenderContext3D.clientHeight;
- }
- this._normalizedViewport.x=value.x / width;
- this._normalizedViewport.y=value.y / height;
- this._normalizedViewport.width=value.width / width;
- this._normalizedViewport.height=value.height / height;
- this._calculationViewport(this._normalizedViewport,width,height);
- this._calculateProjectionMatrix();
- });
- /**
- *设置是否始终使用渲染纹理,在某些渲染配置下会直接将渲染结果渲染到屏幕上,getRenderTexture()方法的返回值为空,如需使用getRenderTexture()可开启此属性。
- *@param value 渲染纹理。
- */
- /**
- *获取是否始终使用渲染纹理,在某些渲染配置下会直接将渲染结果渲染到屏幕上,getRenderTexture()方法的返回值为空,如需使用getRenderTexture()可开启此属性。
- *@return 渲染纹理。
- */
- __getset(0,__proto,'alwaysUseRenderTexture',function(){
- return this._alwaysUseRenderTexture;
- },function(value){
- this._alwaysUseRenderTexture=value;
- });
- /**
- *设置裁剪空间的视口。
- *@return 裁剪空间的视口。
- */
- /**
- *获取裁剪空间的视口。
- *@return 裁剪空间的视口。
- */
- __getset(0,__proto,'normalizedViewport',function(){
- return this._normalizedViewport;
- },function(value){
- var width=0;
- var height=0;
- if (this._offScreenRenderTexture){
- width=this._offScreenRenderTexture.width;
- height=this._offScreenRenderTexture.height;
- }else {
- width=RenderContext3D.clientWidth;
- height=RenderContext3D.clientHeight;
- }
- if (this._normalizedViewport!==value)
- value.cloneTo(this._normalizedViewport);
- this._calculationViewport(value,width,height);
- this._calculateProjectionMatrix();
- });
- /**设置投影矩阵。*/
- /**获取投影矩阵。*/
- __getset(0,__proto,'projectionMatrix',function(){
- return this._projectionMatrix;
- },function(value){
- this._projectionMatrix=value;
- this._useUserProjectionMatrix=true;
- });
- /**
- *获取视图矩阵。
- *@return 视图矩阵。
- */
- __getset(0,__proto,'viewMatrix',function(){
- if (this._updateViewMatrix){
- var scale=this.transform.scale;
- var scaleX=scale.x;
- var scaleY=scale.y;
- var scaleZ=scale.z;
- var viewMatE=this._viewMatrix.elements;
- this.transform.worldMatrix.cloneTo(this._viewMatrix)
- viewMatE[0] /=scaleX;
- viewMatE[1] /=scaleX;
- viewMatE[2] /=scaleX;
- viewMatE[4] /=scaleY;
- viewMatE[5] /=scaleY;
- viewMatE[6] /=scaleY;
- viewMatE[8] /=scaleZ;
- viewMatE[9] /=scaleZ;
- viewMatE[10] /=scaleZ;
- this._viewMatrix.invert(this._viewMatrix);
- this._updateViewMatrix=false;
- }
- return this._viewMatrix;
- });
- /**
- *设置后期处理。
- *@param value 后期处理。
- */
- /**
- *获取后期处理。
- *@return 后期处理。
- */
- __getset(0,__proto,'postProcess',function(){
- return this._postProcess;
- },function(value){
- this._postProcess=value;
- this.alwaysUseRenderTexture=true;
- var postProcessCommandBuffer=new CommandBuffer();
- this.addCommandBuffer(/*CLASS CONST:laya.d3.core.Camera.CAMERAEVENT_POSTPROCESS*/0,postProcessCommandBuffer);
- value._init(this,postProcessCommandBuffer);
- });
- Camera.CAMERAEVENT_POSTPROCESS=0;
- Camera._updateMark=0;
- __static(Camera,
- ['_tempVector20',function(){return this._tempVector20=new Vector2();}
- ]);
- return Camera;
- })(BaseCamera)
- /**
- *<code>TerrainMeshSprite3D</code> 类用于创建网格。
- */
- //class laya.d3.core.MeshTerrainSprite3D extends laya.d3.core.MeshSprite3D
- var MeshTerrainSprite3D=(function(_super){
- function MeshTerrainSprite3D(mesh,heightMap,name){
- /**@private */
- this._minX=NaN;
- /**@private */
- this._minZ=NaN;
- /**@private */
- this._cellSize=null;
- /**@private */
- this._heightMap=null;
- MeshTerrainSprite3D.__super.call(this,mesh,name);
- this._heightMap=heightMap;
- this._cellSize=new Vector2();
- }
- __class(MeshTerrainSprite3D,'laya.d3.core.MeshTerrainSprite3D',_super);
- var __proto=MeshTerrainSprite3D.prototype;
- /**
- *@private
- */
- __proto._disableRotation=function(){
- var rotation=this.transform.rotation;
- rotation.x=0;
- rotation.y=0;
- rotation.z=0;
- rotation.w=1;
- this.transform.rotation=rotation;
- }
- /**
- *@private
- */
- __proto._getScaleX=function(){
- var worldMat=this.transform.worldMatrix;
- var worldMatE=worldMat.elements;
- var m11=worldMatE[0];
- var m12=worldMatE[1];
- var m13=worldMatE[2];
- return Math.sqrt((m11 *m11)+(m12 *m12)+(m13 *m13));
- }
- /**
- *@private
- */
- __proto._getScaleZ=function(){
- var worldMat=this.transform.worldMatrix;
- var worldMatE=worldMat.elements;
- var m31=worldMatE[8];
- var m32=worldMatE[9];
- var m33=worldMatE[10];
- return Math.sqrt((m31 *m31)+(m32 *m32)+(m33 *m33));
- }
- /**
- *@private
- */
- __proto._initCreateFromMesh=function(heightMapWidth,heightMapHeight){
- this._heightMap=HeightMap.creatFromMesh(this.meshFilter.sharedMesh,heightMapWidth,heightMapHeight,this._cellSize);
- var boundingBox=this.meshFilter.sharedMesh.bounds;
- var min=boundingBox.getMin();
- var max=boundingBox.getMax();
- this._minX=min.x;
- this._minZ=min.z;
- }
- /**
- *@private
- */
- __proto._initCreateFromMeshHeightMap=function(texture,minHeight,maxHeight){
- var boundingBox=this.meshFilter.sharedMesh.bounds;
- this._heightMap=HeightMap.createFromImage(texture,minHeight,maxHeight);
- this._computeCellSize(boundingBox);
- var min=boundingBox.getMin();
- var max=boundingBox.getMax();
- this._minX=min.x;
- this._minZ=min.z;
- }
- /**
- *@private
- */
- __proto._computeCellSize=function(boundingBox){
- var min=boundingBox.getMin();
- var max=boundingBox.getMax();
- var minX=min.x;
- var minZ=min.z;
- var maxX=max.x;
- var maxZ=max.z;
- var widthSize=maxX-minX;
- var heightSize=maxZ-minZ;
- this._cellSize.x=widthSize / (this._heightMap.width-1);
- this._cellSize.y=heightSize / (this._heightMap.height-1);
- }
- /**
- *@private
- */
- __proto._update=function(state){
- this._disableRotation();
- }
- /**
- *获取地形高度。
- *@param x X轴坐标。
- *@param z Z轴坐标。
- */
- __proto.getHeight=function(x,z){
- MeshTerrainSprite3D._tempVector3.x=x;
- MeshTerrainSprite3D._tempVector3.y=0;
- MeshTerrainSprite3D._tempVector3.z=z;
- this._disableRotation();
- var worldMat=this.transform.worldMatrix;
- worldMat.invert(MeshTerrainSprite3D._tempMatrix4x4);
- Vector3.transformCoordinate(MeshTerrainSprite3D._tempVector3,MeshTerrainSprite3D._tempMatrix4x4,MeshTerrainSprite3D._tempVector3);
- x=MeshTerrainSprite3D._tempVector3.x;
- z=MeshTerrainSprite3D._tempVector3.z;
- var c=(x-this._minX)/ this._cellSize.x;
- var d=(z-this._minZ)/ this._cellSize.y;
- var row=Math.floor(d);
- var col=Math.floor(c);
- var s=c-col;
- var t=d-row;
- var uy=NaN;
- var vy=NaN;
- var worldMatE=worldMat.elements;
- var m21=worldMatE[4];
- var m22=worldMatE[5];
- var m23=worldMatE[6];
- var scaleY=Math.sqrt((m21 *m21)+(m22 *m22)+(m23 *m23));
- var translateY=worldMatE[13];
- var h01=this._heightMap.getHeight(row,col+1);
- var h10=this._heightMap.getHeight((row+1),col);
- if (isNaN(h01)|| isNaN(h10))
- return NaN;
- if (s+t <=1.0){
- var h00=this._heightMap.getHeight(row,col);
- if (isNaN(h00))
- return NaN;
- uy=h01-h00;
- vy=h10-h00;
- return (h00+s *uy+t *vy)*scaleY+translateY;
- }else {
- var h11=this._heightMap.getHeight((row+1),col+1);
- if (isNaN(h11))
- return NaN;
- uy=h10-h11;
- vy=h01-h11;
- return (h11+(1.0-s)*uy+(1.0-t)*vy)*scaleY+translateY;
- }
- }
- /**
- *获取地形X轴最小位置。
- *@return 地形X轴最小位置。
- */
- __getset(0,__proto,'minX',function(){
- var worldMat=this.transform.worldMatrix;
- var worldMatE=worldMat.elements;
- return this._minX *this._getScaleX()+worldMatE[12];
- });
- /**
- *获取地形X轴长度。
- *@return 地形X轴长度。
- */
- __getset(0,__proto,'width',function(){
- return (this._heightMap.width-1)*this._cellSize.x *this._getScaleX();
- });
- /**
- *获取地形Z轴最小位置。
- *@return 地形X轴最小位置。
- */
- __getset(0,__proto,'minZ',function(){
- var worldMat=this.transform.worldMatrix;
- var worldMatE=worldMat.elements;
- return this._minZ *this._getScaleZ()+worldMatE[14];
- });
- /**
- *获取地形Z轴长度。
- *@return 地形Z轴长度。
- */
- __getset(0,__proto,'depth',function(){
- return (this._heightMap.height-1)*this._cellSize.y *this._getScaleZ();
- });
- MeshTerrainSprite3D.createFromMesh=function(mesh,heightMapWidth,heightMapHeight,name){
- var meshTerrainSprite3D=new MeshTerrainSprite3D(mesh,null,name);
- meshTerrainSprite3D._initCreateFromMesh(heightMapWidth,heightMapHeight);
- return meshTerrainSprite3D;
- }
- MeshTerrainSprite3D.createFromMeshAndHeightMap=function(mesh,texture,minHeight,maxHeight,name){
- var meshTerrainSprite3D=new MeshTerrainSprite3D(mesh,null,name);
- meshTerrainSprite3D._initCreateFromMeshHeightMap(texture,minHeight,maxHeight);
- return meshTerrainSprite3D;
- }
- __static(MeshTerrainSprite3D,
- ['_tempVector3',function(){return this._tempVector3=new Vector3();},'_tempMatrix4x4',function(){return this._tempMatrix4x4=new Matrix4x4();}
- ]);
- return MeshTerrainSprite3D;
- })(MeshSprite3D)
- })(window,document,Laya);
|