1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708 |
- (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>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>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>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>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;
- })()
- /**
- *<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>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>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;
- })()
- /**
- *...
- *@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>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;
- })()
- /**
- *<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;
- })()
- /**
- *@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>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;
- })()
- /**
- *<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>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>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>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>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>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;
- })()
- /**
- *@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>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
- */
- //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>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>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>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>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>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>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;
- })()
- /**
- *<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>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;
- })()
- /**
- *<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>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>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;
- })()
- /**
- *...
- *@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>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;
- })()
- /**
- *...
- *@author ...
- */
- //class laya.d3.core.scene.SceneManager
- var SceneManager=(function(){
- function SceneManager(){}
- __class(SceneManager,'laya.d3.core.scene.SceneManager');
- return SceneManager;
- })()
- /**
- *@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>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;
- })()
- /**
- *...
- *@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;
- })()
- /**
- *@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;
- })()
- /**
- **<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;
- })()
- /**
- *...
- *@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>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>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}";
- 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 #else\n \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;
- })()
- /**
- *@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>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;
- })()
- /**
- *@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;
- })()
- /**
- *<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>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;
- })()
- /**
- *<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>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;
- })()
- /**
- *<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>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;
- })()
- /**
- *@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>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;
- })()
- /**
- *...
- *@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;
- })()
- /**
- *@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;
- })()
- /**
- *@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;
- })()
- /**
- *@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>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;
- })()
- /**
- *<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
- *<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;
- })()
- /**
- *<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>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;
- })()
- /**
- *...
- *@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;
- })()
- /**
- *<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>Config3D</code> 类用于创建3D初始化配置。
- */
- //class Config3D
- var Config3D=(function(){
- function Config3D(){
- /**@private */
- this._defaultPhysicsMemory=128;
- /**@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>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;
- })()
- /**
- *<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>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;
- })()
- /**
- *<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>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;
- })()
- /**
- *...
- *@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>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;
- })()
- /**
- *<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>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;
- })()
- /**
- *<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>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>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>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;
- })()
- /**
- *<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>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>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;
- })()
- /**
- *@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;
- })()
- /**
- *@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;
- })()
- /**
- *...
- *@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;
- })()
- /**
- *<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;
- })()
- /**
- *...
- *@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>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>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>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
- *<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>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>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>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;
- })()
- /**
- *...
- *@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;
- })()
- /**
- *...
- *@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.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;
- })()
- /**
- *<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;
- })()
- /**
- *<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>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;
- })()
- /**
- *@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>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;
- })()
- /**
- *@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;
- })()
- /**
- *<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>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;
- })()
- /**
- *<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>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;
- })()
- /**
- *<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>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>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;
- })()
- //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>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>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;
- })()
- /**
- *@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>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>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>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>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>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>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>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>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>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;
- })()
- /**
- *<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>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>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>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)
- /**
- *@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>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>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>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>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>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>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>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>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>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)
- /**
- *<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)
- /**
- *@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)
- /**
- *<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>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>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>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.";
- return;
- 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;
- if(end){
- end._setIndexInList(index);
- }
- }
- if(element){
- element._setIndexInList(-1);
- }
- }
- return SimpleSingletonList;
- })(SingletonList)
- /**
- *<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>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)
- /**
- *@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>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>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)
- /**
- *<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>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)
- /**
- *@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)
- /**
- *<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)
- /**
- *<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)
- /**
- *@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>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>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)
- /**
- *<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)
- /**
- *@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>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)
- /**
- *<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>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)
- /**
- *@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>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)
- /**
- *@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>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>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)
- /**
- *<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>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)
- /**
- *@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>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>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>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)
- /**
- *<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>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>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>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>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>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>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>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>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>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>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>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>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>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>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>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>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>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>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)
- /**
- *...
- *@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>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)
- /**
- *...
- *@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)
- /**
- *...
- *@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)
- /**
- *<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>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>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>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>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)
- /**
- *<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)
- /**
- *...
- *@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>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)
- /**
- *<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)
- /**
- *<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;
- });
- __getset(0,__proto,'bounds',function(){
- if (this._boundsChange || this._cacheAvatar){
- this._calculateBoundingBox();
- this._boundsChange=false;
- }
- return this._bounds;
- });
- __static(SkinnedMeshRenderer,
- ['_tempMatrix4x4',function(){return this._tempMatrix4x4=new Matrix4x4();}
- ]);
- return SkinnedMeshRenderer;
- })(MeshRenderer)
- /**
- *<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>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>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>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>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>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>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>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>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>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>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>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>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);
|