| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672 |
- (function t(e, i, o) {
- function n(s, a) {
- if (!i[s]) {
- if (!e[s]) {
- var l = "function" == typeof require && require;
- if (!a && l) return l(s, !0);
- if (r) return r(s, !0);
- var h = new Error("Cannot find module '" + s + "'");
- throw h.code = "MODULE_NOT_FOUND", h;
- }
- var c = i[s] = {
- exports: {}
- };
- e[s][0].call(c.exports, function(t) {
- return n(e[s][1][t] || t);
- }, c, c.exports, t, e, i, o);
- }
- return i[s].exports;
- }
- for (var r = "function" == typeof require && require, s = 0; s < o.length; s++) n(o[s]);
- return n;
- })({
- 1: [ function(t, e, i) {
- "use strict";
- i.__esModule = !0;
- i.CannonRigidBody = void 0;
- var o, n = (o = t("../../../../../external/cannon/cannon")) && o.__esModule ? o : {
- default: o
- };
- function r(t, e) {
- for (var i = 0; i < e.length; i++) {
- var o = e[i];
- o.enumerable = o.enumerable || !1;
- o.configurable = !0;
- "value" in o && (o.writable = !0);
- Object.defineProperty(t, o.key, o);
- }
- }
- function s(t, e, i) {
- e && r(t.prototype, e);
- i && r(t, i);
- return t;
- }
- var a = new n.default.Vec3(), l = new n.default.Vec3(), h = cc.Vec3, c = function() {
- function t() {
- this._rigidBody = void 0;
- this._sharedBody = void 0;
- this._isEnabled = !1;
- }
- var e = t.prototype;
- e.__preload = function(t) {
- this._rigidBody = t;
- this._sharedBody = cc.director.getPhysics3DManager().physicsWorld.getSharedBody(this._rigidBody.node);
- this._sharedBody.reference = !0;
- this._sharedBody.wrappedBody = this;
- };
- e.onLoad = function() {};
- e.onEnable = function() {
- this._isEnabled = !0;
- this.mass = this._rigidBody.mass;
- this.allowSleep = this._rigidBody.allowSleep;
- this.linearDamping = this._rigidBody.linearDamping;
- this.angularDamping = this._rigidBody.angularDamping;
- this.useGravity = this._rigidBody.useGravity;
- this.isKinematic = this._rigidBody.isKinematic;
- this.fixedRotation = this._rigidBody.fixedRotation;
- this.linearFactor = this._rigidBody.linearFactor;
- this.angularFactor = this._rigidBody.angularFactor;
- this._sharedBody.enabled = !0;
- };
- e.onDisable = function() {
- this._isEnabled = !1;
- this._sharedBody.enabled = !1;
- };
- e.onDestroy = function() {
- this._sharedBody.reference = !1;
- this._rigidBody = null;
- this._sharedBody = null;
- };
- e.wakeUp = function() {
- return this._sharedBody.body.wakeUp();
- };
- e.sleep = function() {
- return this._sharedBody.body.sleep();
- };
- e.getLinearVelocity = function(t) {
- h.copy(t, this._sharedBody.body.velocity);
- return t;
- };
- e.setLinearVelocity = function(t) {
- var e = this._sharedBody.body;
- e.isSleeping() && e.wakeUp();
- h.copy(e.velocity, t);
- };
- e.getAngularVelocity = function(t) {
- h.copy(t, this._sharedBody.body.angularVelocity);
- return t;
- };
- e.setAngularVelocity = function(t) {
- var e = this._sharedBody.body;
- e.isSleeping() && e.wakeUp();
- h.copy(e.angularVelocity, t);
- };
- e.applyForce = function(t, e) {
- null == e && (e = h.ZERO);
- var i = this._sharedBody.body;
- i.isSleeping() && i.wakeUp();
- i.applyForce(h.copy(a, t), h.copy(l, e));
- };
- e.applyImpulse = function(t, e) {
- null == e && (e = h.ZERO);
- var i = this._sharedBody.body;
- i.isSleeping() && i.wakeUp();
- i.applyImpulse(h.copy(a, t), h.copy(l, e));
- };
- e.applyLocalForce = function(t, e) {
- null == e && (e = h.ZERO);
- var i = this._sharedBody.body;
- i.isSleeping() && i.wakeUp();
- i.applyLocalForce(h.copy(a, t), h.copy(l, e));
- };
- e.applyLocalImpulse = function(t, e) {
- null == e && (e = h.ZERO);
- var i = this._sharedBody.body;
- i.isSleeping() && i.wakeUp();
- i.applyLocalImpulse(h.copy(a, t), h.copy(l, e));
- };
- e.applyTorque = function(t) {
- var e = this._sharedBody.body;
- e.isSleeping() && e.wakeUp();
- e.torque.x += t.x;
- e.torque.y += t.y;
- e.torque.z += t.z;
- };
- e.applyLocalTorque = function(t) {
- var e = this._sharedBody.body;
- e.isSleeping() && e.wakeUp();
- h.copy(a, t);
- e.vectorToWorldFrame(a, a);
- e.torque.x += a.x;
- e.torque.y += a.y;
- e.torque.z += a.z;
- };
- s(t, [ {
- key: "isAwake",
- get: function() {
- return this._sharedBody.body.isAwake();
- }
- }, {
- key: "isSleepy",
- get: function() {
- return this._sharedBody.body.isSleepy();
- }
- }, {
- key: "isSleeping",
- get: function() {
- return this._sharedBody.body.isSleeping();
- }
- }, {
- key: "allowSleep",
- set: function(t) {
- var e = this._sharedBody.body;
- e.isSleeping() && e.wakeUp();
- e.allowSleep = t;
- }
- }, {
- key: "mass",
- set: function(t) {
- var e = this._sharedBody.body;
- e.mass = t;
- 0 == e.mass ? e.type = n.default.Body.STATIC : e.type = this._rigidBody.isKinematic ? n.default.Body.KINEMATIC : n.default.Body.DYNAMIC;
- e.updateMassProperties();
- e.isSleeping() && e.wakeUp();
- }
- }, {
- key: "isKinematic",
- set: function(t) {
- var e = this._sharedBody.body;
- 0 == e.mass ? e.type = n.default.Body.STATIC : e.type = t ? n.default.Body.KINEMATIC : n.default.Body.DYNAMIC;
- }
- }, {
- key: "fixedRotation",
- set: function(t) {
- var e = this._sharedBody.body;
- e.isSleeping() && e.wakeUp();
- e.fixedRotation = t;
- e.updateMassProperties();
- }
- }, {
- key: "linearDamping",
- set: function(t) {
- this._sharedBody.body.linearDamping = t;
- }
- }, {
- key: "angularDamping",
- set: function(t) {
- this._sharedBody.body.angularDamping = t;
- }
- }, {
- key: "useGravity",
- set: function(t) {
- var e = this._sharedBody.body;
- e.isSleeping() && e.wakeUp();
- e.useGravity = t;
- }
- }, {
- key: "linearFactor",
- set: function(t) {
- var e = this._sharedBody.body;
- e.isSleeping() && e.wakeUp();
- h.copy(e.linearFactor, t);
- }
- }, {
- key: "angularFactor",
- set: function(t) {
- var e = this._sharedBody.body;
- e.isSleeping() && e.wakeUp();
- h.copy(e.angularFactor, t);
- }
- }, {
- key: "rigidBody",
- get: function() {
- return this._rigidBody;
- }
- }, {
- key: "sharedBody",
- get: function() {
- return this._sharedBody;
- }
- }, {
- key: "isEnabled",
- get: function() {
- return this._isEnabled;
- }
- } ]);
- return t;
- }();
- i.CannonRigidBody = c;
- }, {
- "../../../../../external/cannon/cannon": 24
- } ],
- 2: [ function(t, e, i) {
- "use strict";
- i.__esModule = !0;
- i.CannonSharedBody = void 0;
- var o, n = (o = t("../../../../../external/cannon/cannon")) && o.__esModule ? o : {
- default: o
- }, r = t("../framework/physics-enum"), s = t("../framework/util"), a = t("./cannon-util");
- function l(t, e) {
- for (var i = 0; i < e.length; i++) {
- var o = e[i];
- o.enumerable = o.enumerable || !1;
- o.configurable = !0;
- "value" in o && (o.writable = !0);
- Object.defineProperty(t, o.key, o);
- }
- }
- function h(t, e, i) {
- e && l(t.prototype, e);
- i && l(t, i);
- return t;
- }
- var c = cc.Node._LocalDirtyFlag.PHYSICS_SCALE, u = cc.Quat, p = cc.Vec3, d = cc.js.array.fastRemoveAt, y = new p(), f = new u(), v = [], m = {
- type: "collision-enter",
- selfCollider: null,
- otherCollider: null,
- contacts: []
- }, g = function() {
- t.getSharedBody = function(e, i) {
- var o = e._id;
- if (t.sharedBodiesMap.has(o)) return t.sharedBodiesMap.get(o);
- var n = new t(e, i);
- t.sharedBodiesMap.set(e._id, n);
- return n;
- };
- function t(t, e) {
- this.node = void 0;
- this.wrappedWorld = void 0;
- this.body = new n.default.Body();
- this.shapes = [];
- this.wrappedBody = null;
- this.index = -1;
- this.ref = 0;
- this.onCollidedListener = this.onCollided.bind(this);
- this.wrappedWorld = e;
- this.node = t;
- this.body.material = this.wrappedWorld.world.defaultMaterial;
- this.body.addEventListener("cc-collide", this.onCollidedListener);
- this._updateGroup();
- this.node.on(cc.Node.EventType.GROUP_CHANGED, this._updateGroup, this);
- }
- var e = t.prototype;
- e._updateGroup = function() {
- (0, a.groupIndexToBitMask)(this.node.groupIndex, this.body);
- };
- e.addShape = function(t) {
- if (this.shapes.indexOf(t) < 0) {
- var e = this.body.shapes.length;
- this.body.addShape(t.shape);
- this.shapes.push(t);
- t.setIndex(e);
- var i = this.body.shapeOffsets[e], o = this.body.shapeOrientations[e];
- t.setOffsetAndOrient(i, o);
- }
- };
- e.removeShape = function(t) {
- var e = this.shapes.indexOf(t);
- if (e >= 0) {
- d(this.shapes, e);
- this.body.removeShape(t.shape);
- t.setIndex(-1);
- }
- };
- e.syncSceneToPhysics = function(t) {
- void 0 === t && (t = !1);
- var e = this.node, i = (0, s.worldDirty)(e);
- if (t || i) {
- this.body.aabbNeedsUpdate = !0;
- e.getWorldPosition(y);
- e.getWorldRotation(f);
- p.copy(this.body.position, y);
- u.copy(this.body.quaternion, f);
- if (e._localMatDirty & c) {
- for (var o = e.__wscale, n = 0; n < this.shapes.length; n++) this.shapes[n].setScale(o);
- (0, a.commitShapeUpdates)(this.body);
- }
- this.body.isSleeping() && this.body.wakeUp();
- }
- };
- e.syncPhysicsToScene = function() {
- if (this.body.type != r.ERigidBodyType.STATIC && !this.body.isSleeping()) {
- p.copy(y, this.body.position);
- u.copy(f, this.body.quaternion);
- this.node.setWorldPosition(y);
- this.node.setWorldRotation(f);
- }
- };
- e.destroy = function() {
- this.body.removeEventListener("cc-collide", this.onCollidedListener);
- this.node.off(cc.Node.EventType.GROUP_CHANGED, this._updateGroup, this);
- t.sharedBodiesMap.delete(this.node._id);
- delete n.default.World.idToBodyMap[this.body.id];
- this.node = null;
- this.wrappedWorld = null;
- this.body = null;
- this.shapes = null;
- this.onCollidedListener = null;
- };
- e.onCollided = function(t) {
- m.type = t.event;
- var e = (0, s.getWrap)(t.selfShape), i = (0, s.getWrap)(t.otherShape);
- if (e) {
- m.selfCollider = e.collider;
- m.otherCollider = i ? i.collider : null;
- var o = 0;
- for (o = m.contacts.length; o--; ) v.push(m.contacts.pop());
- for (o = 0; o < t.contacts.length; o++) {
- var n = t.contacts[o];
- if (v.length > 0) {
- var r = v.pop();
- p.copy(r.contactA, n.ri);
- p.copy(r.contactB, n.rj);
- p.copy(r.normal, n.ni);
- m.contacts.push(r);
- } else {
- var l = {
- contactA: p.copy(new p(), n.ri),
- contactB: p.copy(new p(), n.rj),
- normal: p.copy(new p(), n.ni)
- };
- m.contacts.push(l);
- }
- }
- for (o = 0; o < this.shapes.length; o++) {
- var h = this.shapes[o];
- m.type = a.deprecatedEventMap[m.type];
- h.collider.emit(m.type, m);
- m.type = t.event;
- h.collider.emit(m.type, m);
- }
- }
- };
- h(t, [ {
- key: "enabled",
- set: function(t) {
- if (t) {
- if (this.index < 0) {
- this.index = this.wrappedWorld.bodies.length;
- this.wrappedWorld.addSharedBody(this);
- var e = this.node;
- this.body.aabbNeedsUpdate = !0;
- e.getWorldPosition(y);
- e.getWorldRotation(f);
- var i = this.body.position;
- i.x = parseFloat(y.x.toFixed(3));
- i.y = parseFloat(y.y.toFixed(3));
- i.z = parseFloat(y.z.toFixed(3));
- var o = this.body.quaternion;
- o.x = parseFloat(f.x.toFixed(12));
- o.y = parseFloat(f.y.toFixed(12));
- o.z = parseFloat(f.z.toFixed(12));
- o.w = parseFloat(f.w.toFixed(12));
- if (e._localMatDirty & c) {
- for (var n = e.__wscale, r = 0; r < this.shapes.length; r++) this.shapes[r].setScale(n);
- (0, a.commitShapeUpdates)(this.body);
- }
- this.body.isSleeping() && this.body.wakeUp();
- }
- } else if (this.index >= 0 && (0 == this.shapes.length && null == this.wrappedBody || 0 == this.shapes.length && null != this.wrappedBody && !this.wrappedBody.rigidBody.enabledInHierarchy || 0 == this.shapes.length && null != this.wrappedBody && !this.wrappedBody.isEnabled)) {
- this.body.sleep();
- this.index = -1;
- this.wrappedWorld.removeSharedBody(this);
- }
- }
- }, {
- key: "reference",
- set: function(t) {
- t ? this.ref++ : this.ref--;
- 0 == this.ref && this.destroy();
- }
- } ]);
- return t;
- }();
- i.CannonSharedBody = g;
- g.sharedBodiesMap = new Map();
- }, {
- "../../../../../external/cannon/cannon": 24,
- "../framework/physics-enum": 19,
- "../framework/util": 23,
- "./cannon-util": 3
- } ],
- 3: [ function(t, e, i) {
- "use strict";
- i.__esModule = !0;
- i.groupIndexToBitMask = r;
- i.toCannonRaycastOptions = function(t, e) {
- t.checkCollisionResponse = !e.queryTrigger;
- r(e.groupIndex, t);
- t.skipBackFaces = !1;
- };
- i.fillRaycastResult = function(t, e) {
- t._assign(n.copy(new n(), e.hitPointWorld), e.distance, (0, o.getWrap)(e.shape).collider);
- };
- i.commitShapeUpdates = function(t) {
- t.aabbNeedsUpdate = !0;
- t.updateMassProperties();
- t.updateBoundingRadius();
- };
- i.deprecatedEventMap = void 0;
- var o = t("../framework/util"), n = cc.Vec3;
- function r(t, e) {
- var i = 1 << t, o = 0, n = cc.game.collisionMatrix[t];
- if (n) {
- for (var r = 0; r < n.length; r++) n[r] && (o |= 1 << r);
- e.collisionFilterGroup = i;
- e.collisionFilterMask = o;
- } else cc.error("cannon-utils: group is not exist", t);
- }
- i.deprecatedEventMap = {
- onCollisionEnter: "collision-enter",
- onCollisionStay: "collision-stay",
- onCollisionExit: "collision-exit",
- onTriggerEnter: "trigger-enter",
- onTriggerStay: "trigger-stay",
- onTriggerExit: "trigger-exit"
- };
- }, {
- "../framework/util": 23
- } ],
- 4: [ function(t, e, i) {
- "use strict";
- i.__esModule = !0;
- i.CannonWorld = void 0;
- var o, n = (o = t("../../../../../external/cannon/cannon")) && o.__esModule ? o : {
- default: o
- }, r = t("./cannon-util"), s = t("./shapes/cannon-shape"), a = t("./cannon-shared-body"), l = t("../framework/util");
- function h(t, e) {
- for (var i = 0; i < e.length; i++) {
- var o = e[i];
- o.enumerable = o.enumerable || !1;
- o.configurable = !0;
- "value" in o && (o.writable = !0);
- Object.defineProperty(t, o.key, o);
- }
- }
- function c(t, e, i) {
- e && h(t.prototype, e);
- i && h(t, i);
- return t;
- }
- var u = cc.Vec3, p = cc.js.array.fastRemoveAt, d = function() {
- function t() {
- this.bodies = [];
- this._world = void 0;
- this._raycastResult = new n.default.RaycastResult();
- this._world = new n.default.World();
- this._world.broadphase = new n.default.NaiveBroadphase();
- this._world.addEventListener("postStep", this.onPostStep.bind(this));
- }
- var e = t.prototype;
- e.onPostStep = function() {
- var t = cc.director.getPhysics3DManager();
- if (t.useFixedDigit) for (var e = t.fixDigits.position, i = t.fixDigits.rotation, o = this._world.bodies, r = 0; r < o.length; r++) {
- var s = o[r];
- if (s.type != n.default.Body.STATIC && !s.isSleeping()) {
- var a = s.position;
- a.x = parseFloat(a.x.toFixed(e));
- a.y = parseFloat(a.y.toFixed(e));
- a.z = parseFloat(a.z.toFixed(e));
- var l = s.quaternion;
- l.x = parseFloat(l.x.toFixed(i));
- l.y = parseFloat(l.y.toFixed(i));
- l.z = parseFloat(l.z.toFixed(i));
- l.w = parseFloat(l.w.toFixed(i));
- var h = s.velocity;
- h.x = parseFloat(h.x.toFixed(e));
- h.y = parseFloat(h.y.toFixed(e));
- h.z = parseFloat(h.z.toFixed(e));
- var c = s.angularVelocity;
- c.x = parseFloat(c.x.toFixed(e));
- c.y = parseFloat(c.y.toFixed(e));
- c.z = parseFloat(c.z.toFixed(e));
- }
- }
- };
- e.step = function(t, e, i) {
- this.syncSceneToPhysics();
- this._world.step(t, e, i);
- this.syncPhysicsToScene();
- this.emitEvents();
- };
- e.syncSceneToPhysics = function() {
- (0, l.clearNodeTransformRecord)();
- for (var t = 0; t < this.bodies.length; t++) this.bodies[t].syncSceneToPhysics();
- (0, l.clearNodeTransformDirtyFlag)();
- };
- e.syncPhysicsToScene = function() {
- for (var t = 0; t < this.bodies.length; t++) this.bodies[t].syncPhysicsToScene();
- };
- e.emitEvents = function() {
- this._world.emitTriggeredEvents();
- this._world.emitCollisionEvents();
- };
- e.raycastClosest = function(t, e, i) {
- v(t, e.maxDistance);
- (0, r.toCannonRaycastOptions)(m, e);
- var o = this._world.raycastClosest(y, f, m, this._raycastResult);
- o && (0, r.fillRaycastResult)(i, this._raycastResult);
- return o;
- };
- e.raycast = function(t, e, i, o) {
- v(t, e.maxDistance);
- (0, r.toCannonRaycastOptions)(m, e);
- return this._world.raycastAll(y, f, m, function(t) {
- var e = i.add();
- (0, r.fillRaycastResult)(e, t);
- o.push(e);
- });
- };
- e.getSharedBody = function(t) {
- return a.CannonSharedBody.getSharedBody(t, this);
- };
- e.addSharedBody = function(t) {
- if (this.bodies.indexOf(t) < 0) {
- this.bodies.push(t);
- this._world.addBody(t.body);
- }
- };
- e.removeSharedBody = function(t) {
- var e = this.bodies.indexOf(t);
- if (e >= 0) {
- p(this.bodies, e);
- this._world.remove(t.body);
- }
- };
- c(t, [ {
- key: "world",
- get: function() {
- return this._world;
- }
- }, {
- key: "defaultMaterial",
- set: function(t) {
- this._world.defaultMaterial.friction = t.friction;
- this._world.defaultMaterial.restitution = t.restitution;
- null != s.CannonShape.idToMaterial[t._uuid] && (s.CannonShape.idToMaterial[t._uuid] = this._world.defaultMaterial);
- }
- }, {
- key: "allowSleep",
- set: function(t) {
- this._world.allowSleep = t;
- }
- }, {
- key: "gravity",
- set: function(t) {
- u.copy(this._world.gravity, t);
- }
- } ]);
- return t;
- }();
- i.CannonWorld = d;
- var y = new n.default.Vec3(), f = new n.default.Vec3();
- function v(t, e) {
- u.copy(y, t.o);
- t.computeHit(f, e);
- }
- var m = {
- checkCollisionResponse: !1,
- collisionFilterGroup: -1,
- collisionFilterMask: -1,
- skipBackFaces: !1
- };
- }, {
- "../../../../../external/cannon/cannon": 24,
- "../framework/util": 23,
- "./cannon-shared-body": 2,
- "./cannon-util": 3,
- "./shapes/cannon-shape": 7
- } ],
- 5: [ function(t) {
- "use strict";
- var e = t("../framework/physics-selector"), i = t("./cannon-rigid-body"), o = t("./cannon-world"), n = t("./shapes/cannon-box-shape"), r = t("./shapes/cannon-sphere-shape");
- (0, e.instantiate)(n.CannonBoxShape, r.CannonSphereShape, i.CannonRigidBody, o.CannonWorld);
- }, {
- "../framework/physics-selector": 22,
- "./cannon-rigid-body": 1,
- "./cannon-world": 4,
- "./shapes/cannon-box-shape": 6,
- "./shapes/cannon-sphere-shape": 8
- } ],
- 6: [ function(t, e, i) {
- "use strict";
- i.__esModule = !0;
- i.CannonBoxShape = void 0;
- var o, n = (o = t("../../../../../../external/cannon/cannon")) && o.__esModule ? o : {
- default: o
- }, r = t("../cannon-util"), s = t("./cannon-shape");
- function a(t, e) {
- for (var i = 0; i < e.length; i++) {
- var o = e[i];
- o.enumerable = o.enumerable || !1;
- o.configurable = !0;
- "value" in o && (o.writable = !0);
- Object.defineProperty(t, o.key, o);
- }
- }
- function l(t, e, i) {
- e && a(t.prototype, e);
- i && a(t, i);
- return t;
- }
- function h(t, e) {
- t.prototype = Object.create(e.prototype);
- t.prototype.constructor = t;
- c(t, e);
- }
- function c(t, e) {
- return (c = Object.setPrototypeOf || function(t, e) {
- t.__proto__ = e;
- return t;
- })(t, e);
- }
- var u = cc.Vec3, p = new u(), d = function(t) {
- h(e, t);
- function e(e) {
- var i;
- (i = t.call(this) || this).halfExtent = new n.default.Vec3();
- u.multiplyScalar(i.halfExtent, e, .5);
- i._shape = new n.default.Box(i.halfExtent.clone());
- return i;
- }
- var i = e.prototype;
- i.onLoad = function() {
- t.prototype.onLoad.call(this);
- this.size = this.boxCollider.size;
- };
- i.setScale = function(e) {
- t.prototype.setScale.call(this, e);
- this.size = this.boxCollider.size;
- };
- l(e, [ {
- key: "boxCollider",
- get: function() {
- return this.collider;
- }
- }, {
- key: "box",
- get: function() {
- return this._shape;
- }
- }, {
- key: "size",
- set: function(t) {
- this.collider.node.getWorldScale(p);
- p.x = Math.abs(p.x);
- p.y = Math.abs(p.y);
- p.z = Math.abs(p.z);
- u.multiplyScalar(this.halfExtent, t, .5);
- u.multiply(this.box.halfExtents, this.halfExtent, p);
- this.box.updateConvexPolyhedronRepresentation();
- -1 != this._index && (0, r.commitShapeUpdates)(this._body);
- }
- } ]);
- return e;
- }(s.CannonShape);
- i.CannonBoxShape = d;
- }, {
- "../../../../../../external/cannon/cannon": 24,
- "../cannon-util": 3,
- "./cannon-shape": 7
- } ],
- 7: [ function(t, e, i) {
- "use strict";
- i.__esModule = !0;
- i.CannonShape = void 0;
- var o, n = (o = t("../../../../../../external/cannon/cannon")) && o.__esModule ? o : {
- default: o
- }, r = t("../../framework/util"), s = t("../cannon-util");
- function a(t, e) {
- for (var i = 0; i < e.length; i++) {
- var o = e[i];
- o.enumerable = o.enumerable || !1;
- o.configurable = !0;
- "value" in o && (o.writable = !0);
- Object.defineProperty(t, o.key, o);
- }
- }
- function l(t, e, i) {
- e && a(t.prototype, e);
- i && a(t, i);
- return t;
- }
- var h = {
- type: "trigger-enter",
- selfCollider: null,
- otherCollider: null
- }, c = cc.Vec3, u = new c(), p = function() {
- function t() {
- this._collider = void 0;
- this._shape = void 0;
- this._offset = new n.default.Vec3();
- this._orient = new n.default.Quaternion();
- this._index = -1;
- this._sharedBody = void 0;
- this.onTriggerListener = this.onTrigger.bind(this);
- }
- var e = t.prototype;
- e.__preload = function(t) {
- this._collider = t;
- (0, r.setWrap)(this._shape, this);
- this._shape.addEventListener("cc-trigger", this.onTriggerListener);
- this._sharedBody = cc.director.getPhysics3DManager().physicsWorld.getSharedBody(this._collider.node);
- this._sharedBody.reference = !0;
- };
- e.onLoad = function() {
- this.center = this._collider.center;
- this.isTrigger = this._collider.isTrigger;
- };
- e.onEnable = function() {
- this._sharedBody.addShape(this);
- this._sharedBody.enabled = !0;
- };
- e.onDisable = function() {
- this._sharedBody.removeShape(this);
- this._sharedBody.enabled = !1;
- };
- e.onDestroy = function() {
- this._sharedBody.reference = !1;
- this._shape.removeEventListener("cc-trigger", this.onTriggerListener);
- delete n.default.World.idToShapeMap[this._shape.id];
- this._sharedBody = null;
- (0, r.setWrap)(this._shape, null);
- this._offset = null;
- this._orient = null;
- this._shape = null;
- this._collider = null;
- this.onTriggerListener = null;
- };
- e.setScale = function() {
- this._setCenter(this._collider.center);
- };
- e.setIndex = function(t) {
- this._index = t;
- };
- e.setOffsetAndOrient = function(t, e) {
- cc.Vec3.copy(t, this._offset);
- cc.Vec3.copy(e, this._orient);
- this._offset = t;
- this._orient = e;
- };
- e._setCenter = function(t) {
- var e = this._offset;
- c.copy(e, t);
- this._collider.node.getWorldScale(u);
- c.multiply(e, e, u);
- };
- e.onTrigger = function(t) {
- h.type = t.event;
- var e = (0, r.getWrap)(t.selfShape), i = (0, r.getWrap)(t.otherShape);
- if (e) {
- h.selfCollider = e.collider;
- h.otherCollider = i ? i.collider : null;
- h.type = s.deprecatedEventMap[h.type];
- this._collider.emit(h.type, h);
- h.type = t.event;
- this._collider.emit(h.type, h);
- }
- };
- l(t, [ {
- key: "shape",
- get: function() {
- return this._shape;
- }
- }, {
- key: "collider",
- get: function() {
- return this._collider;
- }
- }, {
- key: "attachedRigidBody",
- get: function() {
- return this._sharedBody.wrappedBody ? this._sharedBody.wrappedBody.rigidBody : null;
- }
- }, {
- key: "sharedBody",
- get: function() {
- return this._sharedBody;
- }
- }, {
- key: "material",
- set: function(e) {
- if (null == e) this._shape.material = null; else {
- null == t.idToMaterial[e._uuid] && (t.idToMaterial[e._uuid] = new n.default.Material(e._uuid));
- this._shape.material = t.idToMaterial[e._uuid];
- this._shape.material.friction = e.friction;
- this._shape.material.restitution = e.restitution;
- }
- }
- }, {
- key: "isTrigger",
- set: function(t) {
- this._shape.collisionResponse = !t;
- this._index >= 0 && this._body.updateHasTrigger();
- }
- }, {
- key: "center",
- set: function(t) {
- this._setCenter(t);
- this._index >= 0 && (0, s.commitShapeUpdates)(this._body);
- }
- }, {
- key: "_body",
- get: function() {
- return this._sharedBody.body;
- }
- } ]);
- return t;
- }();
- i.CannonShape = p;
- p.idToMaterial = {};
- }, {
- "../../../../../../external/cannon/cannon": 24,
- "../../framework/util": 23,
- "../cannon-util": 3
- } ],
- 8: [ function(t, e, i) {
- "use strict";
- i.__esModule = !0;
- i.CannonSphereShape = void 0;
- var o, n = (o = t("../../../../../../external/cannon/cannon")) && o.__esModule ? o : {
- default: o
- }, r = t("../cannon-util"), s = t("./cannon-shape");
- function a(t, e) {
- for (var i = 0; i < e.length; i++) {
- var o = e[i];
- o.enumerable = o.enumerable || !1;
- o.configurable = !0;
- "value" in o && (o.writable = !0);
- Object.defineProperty(t, o.key, o);
- }
- }
- function l(t, e, i) {
- e && a(t.prototype, e);
- i && a(t, i);
- return t;
- }
- function h(t, e) {
- t.prototype = Object.create(e.prototype);
- t.prototype.constructor = t;
- c(t, e);
- }
- function c(t, e) {
- return (c = Object.setPrototypeOf || function(t, e) {
- t.__proto__ = e;
- return t;
- })(t, e);
- }
- var u = new cc.Vec3(), p = function(t) {
- h(e, t);
- function e(e) {
- var i;
- (i = t.call(this) || this)._radius = void 0;
- i._radius = e;
- i._shape = new n.default.Sphere(i._radius);
- return i;
- }
- var i = e.prototype;
- i.onLoad = function() {
- t.prototype.onLoad.call(this);
- this.radius = this.sphereCollider.radius;
- };
- i.setScale = function(e) {
- t.prototype.setScale.call(this, e);
- this.radius = this.sphereCollider.radius;
- };
- l(e, [ {
- key: "sphereCollider",
- get: function() {
- return this.collider;
- }
- }, {
- key: "sphere",
- get: function() {
- return this._shape;
- }
- }, {
- key: "radius",
- get: function() {
- return this._radius;
- },
- set: function(t) {
- this.collider.node.getWorldScale(u);
- var e = u.maxAxis();
- this.sphere.radius = t * Math.abs(e);
- this.sphere.updateBoundingSphereRadius();
- -1 != this._index && (0, r.commitShapeUpdates)(this._body);
- }
- } ]);
- return e;
- }(s.CannonShape);
- i.CannonSphereShape = p;
- }, {
- "../../../../../../external/cannon/cannon": 24,
- "../cannon-util": 3,
- "./cannon-shape": 7
- } ],
- 9: [ function(t) {
- "use strict";
- t("../cannon/instantiate");
- var e, i = (e = t("../../../../../external/cannon/cannon")) && e.__esModule ? e : {
- default: e
- };
- window && (window.CANNON = i.default);
- }, {
- "../../../../../external/cannon/cannon": 24,
- "../cannon/instantiate": 5
- } ],
- 10: [ function(t, e, i) {
- "use strict";
- i.__esModule = !0;
- var o = t("../framework");
- Object.keys(o).forEach(function(t) {
- "default" !== t && "__esModule" !== t && (t in i && i[t] === o[t] || (i[t] = o[t]));
- });
- }, {
- "../framework": 17
- } ],
- 11: [ function(t, e, i) {
- "use strict";
- i.__esModule = !0;
- i.PhysicsMaterial = void 0;
- var o, n, r, s, a, l;
- function h(t, e, i, o) {
- i && Object.defineProperty(t, e, {
- enumerable: i.enumerable,
- configurable: i.configurable,
- writable: i.writable,
- value: i.initializer ? i.initializer.call(o) : void 0
- });
- }
- function c(t, e) {
- for (var i = 0; i < e.length; i++) {
- var o = e[i];
- o.enumerable = o.enumerable || !1;
- o.configurable = !0;
- "value" in o && (o.writable = !0);
- Object.defineProperty(t, o.key, o);
- }
- }
- function u(t, e, i) {
- e && c(t.prototype, e);
- i && c(t, i);
- return t;
- }
- function p(t) {
- if (void 0 === t) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
- return t;
- }
- function d(t, e) {
- t.prototype = Object.create(e.prototype);
- t.prototype.constructor = t;
- y(t, e);
- }
- function y(t, e) {
- return (y = Object.setPrototypeOf || function(t, e) {
- t.__proto__ = e;
- return t;
- })(t, e);
- }
- function f(t, e, i, o, n) {
- var r = {};
- Object.keys(o).forEach(function(t) {
- r[t] = o[t];
- });
- r.enumerable = !!r.enumerable;
- r.configurable = !!r.configurable;
- ("value" in r || r.initializer) && (r.writable = !0);
- r = i.slice().reverse().reduce(function(i, o) {
- return o(t, e, i) || i;
- }, r);
- if (n && void 0 !== r.initializer) {
- r.value = r.initializer ? r.initializer.call(n) : void 0;
- r.initializer = void 0;
- }
- if (void 0 === r.initializer) {
- Object.defineProperty(t, e, r);
- r = null;
- }
- return r;
- }
- var v = cc._decorator, m = v.ccclass, g = v.property, b = cc.js.array.fastRemove, w = cc.math.equals, x = m("cc.PhysicsMaterial")(o = (n = (l = a = function(t) {
- d(e, t);
- function e() {
- var i;
- h(i = t.call(this) || this, "_friction", r, p(i));
- h(i, "_restitution", s, p(i));
- cc.EventTarget.call(p(i));
- e.allMaterials.push(p(i));
- "" == i._uuid && (i._uuid = "pm_" + e._idCounter++);
- return i;
- }
- var i = e.prototype;
- i.clone = function() {
- var t = new e();
- t._friction = this._friction;
- t._restitution = this._restitution;
- return t;
- };
- i.destroy = function() {
- if (t.prototype.destroy.call(this)) {
- b(e.allMaterials, this);
- return !0;
- }
- return !1;
- };
- u(e, [ {
- key: "friction",
- get: function() {
- return this._friction;
- },
- set: function(t) {
- if (!w(this._friction, t)) {
- this._friction = t;
- this.emit("physics_material_update");
- }
- }
- }, {
- key: "restitution",
- get: function() {
- return this._restitution;
- },
- set: function(t) {
- if (!w(this._restitution, t)) {
- this._restitution = t;
- this.emit("physics_material_update");
- }
- }
- } ]);
- return e;
- }(cc.Asset), a.allMaterials = [], a._idCounter = 0, l), r = f(n.prototype, "_friction", [ g ], {
- configurable: !0,
- enumerable: !0,
- writable: !0,
- initializer: function() {
- return .1;
- }
- }), s = f(n.prototype, "_restitution", [ g ], {
- configurable: !0,
- enumerable: !0,
- writable: !0,
- initializer: function() {
- return .1;
- }
- }), f(n.prototype, "friction", [ g ], Object.getOwnPropertyDescriptor(n.prototype, "friction"), n.prototype),
- f(n.prototype, "restitution", [ g ], Object.getOwnPropertyDescriptor(n.prototype, "restitution"), n.prototype),
- n)) || o;
- i.PhysicsMaterial = x;
- cc.js.mixin(x.prototype, cc.EventTarget.prototype);
- cc.PhysicsMaterial = x;
- }, {} ],
- 12: [ function(t, e, i) {
- "use strict";
- i.__esModule = !0;
- i.BoxCollider3D = void 0;
- var o, n, r, s, a, l, h, c = t("../../instance"), u = t("./collider-component");
- function p(t, e, i, o) {
- i && Object.defineProperty(t, e, {
- enumerable: i.enumerable,
- configurable: i.configurable,
- writable: i.writable,
- value: i.initializer ? i.initializer.call(o) : void 0
- });
- }
- function d(t, e) {
- for (var i = 0; i < e.length; i++) {
- var o = e[i];
- o.enumerable = o.enumerable || !1;
- o.configurable = !0;
- "value" in o && (o.writable = !0);
- Object.defineProperty(t, o.key, o);
- }
- }
- function y(t, e, i) {
- e && d(t.prototype, e);
- i && d(t, i);
- return t;
- }
- function f(t) {
- if (void 0 === t) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
- return t;
- }
- function v(t, e) {
- t.prototype = Object.create(e.prototype);
- t.prototype.constructor = t;
- m(t, e);
- }
- function m(t, e) {
- return (m = Object.setPrototypeOf || function(t, e) {
- t.__proto__ = e;
- return t;
- })(t, e);
- }
- function g(t, e, i, o, n) {
- var r = {};
- Object.keys(o).forEach(function(t) {
- r[t] = o[t];
- });
- r.enumerable = !!r.enumerable;
- r.configurable = !!r.configurable;
- ("value" in r || r.initializer) && (r.writable = !0);
- r = i.slice().reverse().reduce(function(i, o) {
- return o(t, e, i) || i;
- }, r);
- if (n && void 0 !== r.initializer) {
- r.value = r.initializer ? r.initializer.call(n) : void 0;
- r.initializer = void 0;
- }
- if (void 0 === r.initializer) {
- Object.defineProperty(t, e, r);
- r = null;
- }
- return r;
- }
- var b = cc._decorator, w = b.ccclass, x = b.executeInEditMode, _ = b.executionOrder, B = b.menu, S = b.property, E = cc.Vec3, M = (o = w("cc.BoxCollider3D"),
- n = _(98), r = B("i18n:MAIN_MENU.component.physics/Collider/Box 3D"), s = S({
- type: cc.Vec3
- }), o(a = n(a = r(a = x(a = (g((l = function(t) {
- v(e, t);
- function e() {
- var e;
- p(e = t.call(this) || this, "_size", h, f(e));
- e._shape = (0, c.createBoxShape)(e._size);
- return e;
- }
- y(e, [ {
- key: "size",
- get: function() {
- return this._size;
- },
- set: function(t) {
- E.copy(this._size, t);
- this.boxShape.size = this._size;
- }
- }, {
- key: "boxShape",
- get: function() {
- return this._shape;
- }
- } ]);
- return e;
- }(u.Collider3D)).prototype, "size", [ s ], Object.getOwnPropertyDescriptor(l.prototype, "size"), l.prototype),
- h = g(l.prototype, "_size", [ S ], {
- configurable: !0,
- enumerable: !0,
- writable: !0,
- initializer: function() {
- return new E(1, 1, 1);
- }
- }), l)) || a) || a) || a) || a);
- i.BoxCollider3D = M;
- }, {
- "../../instance": 18,
- "./collider-component": 13
- } ],
- 13: [ function(t, e, i) {
- "use strict";
- i.__esModule = !0;
- i.Collider3D = void 0;
- var o, n, r, s, a, l, h, c, u, p, d = t("../../assets/physics-material");
- function y(t, e, i, o) {
- i && Object.defineProperty(t, e, {
- enumerable: i.enumerable,
- configurable: i.configurable,
- writable: i.writable,
- value: i.initializer ? i.initializer.call(o) : void 0
- });
- }
- function f(t, e) {
- for (var i = 0; i < e.length; i++) {
- var o = e[i];
- o.enumerable = o.enumerable || !1;
- o.configurable = !0;
- "value" in o && (o.writable = !0);
- Object.defineProperty(t, o.key, o);
- }
- }
- function v(t, e, i) {
- e && f(t.prototype, e);
- i && f(t, i);
- return t;
- }
- function m(t) {
- if (void 0 === t) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
- return t;
- }
- function g(t, e) {
- t.prototype = Object.create(e.prototype);
- t.prototype.constructor = t;
- b(t, e);
- }
- function b(t, e) {
- return (b = Object.setPrototypeOf || function(t, e) {
- t.__proto__ = e;
- return t;
- })(t, e);
- }
- function w(t, e, i, o, n) {
- var r = {};
- Object.keys(o).forEach(function(t) {
- r[t] = o[t];
- });
- r.enumerable = !!r.enumerable;
- r.configurable = !!r.configurable;
- ("value" in r || r.initializer) && (r.writable = !0);
- r = i.slice().reverse().reduce(function(i, o) {
- return o(t, e, i) || i;
- }, r);
- if (n && void 0 !== r.initializer) {
- r.value = r.initializer ? r.initializer.call(n) : void 0;
- r.initializer = void 0;
- }
- if (void 0 === r.initializer) {
- Object.defineProperty(t, e, r);
- r = null;
- }
- return r;
- }
- var x = cc._decorator, _ = x.ccclass, B = x.property, S = cc.Vec3, E = (o = _("cc.Collider3D"),
- n = B({
- type: d.PhysicsMaterial,
- displayName: "Material",
- displayOrder: -1
- }), r = B({
- displayOrder: 0
- }), s = B({
- type: cc.Vec3,
- displayOrder: 1
- }), a = B({
- type: d.PhysicsMaterial
- }), o(l = (w((h = function(t) {
- g(e, t);
- function e() {
- var e;
- (e = t.call(this) || this)._shape = void 0;
- e._isSharedMaterial = !0;
- y(e, "_material", c, m(e));
- y(e, "_isTrigger", u, m(e));
- y(e, "_center", p, m(e));
- cc.EventTarget.call(m(e));
- return e;
- }
- var i = e.prototype;
- i.on = function() {};
- i.off = function() {};
- i.once = function() {};
- i.emit = function() {};
- i.__preload = function() {
- this._shape.__preload(this);
- };
- i.onLoad = function() {
- this.sharedMaterial = null == this._material ? cc.director.getPhysics3DManager().defaultMaterial : this._material;
- this._shape.onLoad();
- };
- i.onEnable = function() {
- this._shape.onEnable();
- };
- i.onDisable = function() {
- this._shape.onDisable();
- };
- i.onDestroy = function() {
- this._material && this._material.off("physics_material_update", this._updateMaterial, this);
- this._shape.onDestroy();
- };
- i._updateMaterial = function() {
- this._shape.material = this._material;
- };
- v(e, [ {
- key: "sharedMaterial",
- get: function() {
- return this._material;
- },
- set: function(t) {
- this.material = t;
- }
- }, {
- key: "material",
- get: function() {
- if (this._isSharedMaterial && null != this._material) {
- this._material.off("physics_material_update", this._updateMaterial, this);
- this._material = this._material.clone();
- this._material.on("physics_material_update", this._updateMaterial, this);
- this._isSharedMaterial = !1;
- }
- return this._material;
- },
- set: function(t) {
- if (null != t && null != this._material) {
- if (this._material._uuid != t._uuid) {
- this._material.off("physics_material_update", this._updateMaterial, this);
- t.on("physics_material_update", this._updateMaterial, this);
- this._isSharedMaterial = !1;
- this._material = t;
- }
- } else if (null != t && null == this._material) {
- t.on("physics_material_update", this._updateMaterial, this);
- this._material = t;
- } else if (null == t && null != this._material) {
- this._material.off("physics_material_update", this._updateMaterial, this);
- this._material = t;
- }
- this._updateMaterial();
- }
- }, {
- key: "isTrigger",
- get: function() {
- return this._isTrigger;
- },
- set: function(t) {
- this._isTrigger = t;
- this._shape.isTrigger = this._isTrigger;
- }
- }, {
- key: "center",
- get: function() {
- return this._center;
- },
- set: function(t) {
- S.copy(this._center, t);
- this._shape.center = this._center;
- }
- }, {
- key: "attachedRigidbody",
- get: function() {
- return this.shape.attachedRigidBody;
- }
- }, {
- key: "shape",
- get: function() {
- return this._shape;
- }
- }, {
- key: "_assertOnload",
- get: function() {
- var t = 0 == this._isOnLoadCalled;
- t && cc.error("Physics Error: Please make sure that the node has been added to the scene");
- return !t;
- }
- } ]);
- return e;
- }(cc.Component)).prototype, "sharedMaterial", [ n ], Object.getOwnPropertyDescriptor(h.prototype, "sharedMaterial"), h.prototype),
- w(h.prototype, "isTrigger", [ r ], Object.getOwnPropertyDescriptor(h.prototype, "isTrigger"), h.prototype),
- w(h.prototype, "center", [ s ], Object.getOwnPropertyDescriptor(h.prototype, "center"), h.prototype),
- c = w(h.prototype, "_material", [ a ], {
- configurable: !0,
- enumerable: !0,
- writable: !0,
- initializer: function() {
- return null;
- }
- }), u = w(h.prototype, "_isTrigger", [ B ], {
- configurable: !0,
- enumerable: !0,
- writable: !0,
- initializer: function() {
- return !1;
- }
- }), p = w(h.prototype, "_center", [ B ], {
- configurable: !0,
- enumerable: !0,
- writable: !0,
- initializer: function() {
- return new S();
- }
- }), h)) || l);
- i.Collider3D = E;
- cc.js.mixin(E.prototype, cc.EventTarget.prototype);
- }, {
- "../../assets/physics-material": 11
- } ],
- 14: [ function(t, e, i) {
- "use strict";
- i.__esModule = !0;
- i.SphereCollider3D = void 0;
- var o, n, r, s = t("../../instance"), a = t("./collider-component");
- function l(t, e, i, o) {
- i && Object.defineProperty(t, e, {
- enumerable: i.enumerable,
- configurable: i.configurable,
- writable: i.writable,
- value: i.initializer ? i.initializer.call(o) : void 0
- });
- }
- function h(t, e) {
- for (var i = 0; i < e.length; i++) {
- var o = e[i];
- o.enumerable = o.enumerable || !1;
- o.configurable = !0;
- "value" in o && (o.writable = !0);
- Object.defineProperty(t, o.key, o);
- }
- }
- function c(t, e, i) {
- e && h(t.prototype, e);
- i && h(t, i);
- return t;
- }
- function u(t) {
- if (void 0 === t) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
- return t;
- }
- function p(t, e) {
- t.prototype = Object.create(e.prototype);
- t.prototype.constructor = t;
- d(t, e);
- }
- function d(t, e) {
- return (d = Object.setPrototypeOf || function(t, e) {
- t.__proto__ = e;
- return t;
- })(t, e);
- }
- function y(t, e, i, o, n) {
- var r = {};
- Object.keys(o).forEach(function(t) {
- r[t] = o[t];
- });
- r.enumerable = !!r.enumerable;
- r.configurable = !!r.configurable;
- ("value" in r || r.initializer) && (r.writable = !0);
- r = i.slice().reverse().reduce(function(i, o) {
- return o(t, e, i) || i;
- }, r);
- if (n && void 0 !== r.initializer) {
- r.value = r.initializer ? r.initializer.call(n) : void 0;
- r.initializer = void 0;
- }
- if (void 0 === r.initializer) {
- Object.defineProperty(t, e, r);
- r = null;
- }
- return r;
- }
- var f = cc._decorator, v = f.ccclass, m = f.executeInEditMode, g = f.executionOrder, b = f.menu, w = f.property, x = v("cc.SphereCollider3D")(o = g(98)(o = b("i18n:MAIN_MENU.component.physics/Collider/Sphere 3D")(o = m(o = (y((n = function(t) {
- p(e, t);
- function e() {
- var e;
- l(e = t.call(this) || this, "_radius", r, u(e));
- e._shape = (0, s.createSphereShape)(e._radius);
- return e;
- }
- c(e, [ {
- key: "radius",
- get: function() {
- return this._radius;
- },
- set: function(t) {
- this._radius = t;
- this.sphereShape.radius = this._radius;
- }
- }, {
- key: "sphereShape",
- get: function() {
- return this._shape;
- }
- } ]);
- return e;
- }(a.Collider3D)).prototype, "radius", [ w ], Object.getOwnPropertyDescriptor(n.prototype, "radius"), n.prototype),
- r = y(n.prototype, "_radius", [ w ], {
- configurable: !0,
- enumerable: !0,
- writable: !0,
- initializer: function() {
- return .5;
- }
- }), n)) || o) || o) || o) || o;
- i.SphereCollider3D = x;
- }, {
- "../../instance": 18,
- "./collider-component": 13
- } ],
- 15: [ function(t, e, i) {
- "use strict";
- i.__esModule = !0;
- i.ConstantForce = void 0;
- var o, n, r, s, a, l, h, c, u, p, d, y, f, v, m = t("./rigid-body-component");
- function g(t, e, i, o) {
- i && Object.defineProperty(t, e, {
- enumerable: i.enumerable,
- configurable: i.configurable,
- writable: i.writable,
- value: i.initializer ? i.initializer.call(o) : void 0
- });
- }
- function b(t, e) {
- for (var i = 0; i < e.length; i++) {
- var o = e[i];
- o.enumerable = o.enumerable || !1;
- o.configurable = !0;
- "value" in o && (o.writable = !0);
- Object.defineProperty(t, o.key, o);
- }
- }
- function w(t, e, i) {
- e && b(t.prototype, e);
- i && b(t, i);
- return t;
- }
- function x(t) {
- if (void 0 === t) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
- return t;
- }
- function _(t, e) {
- t.prototype = Object.create(e.prototype);
- t.prototype.constructor = t;
- B(t, e);
- }
- function B(t, e) {
- return (B = Object.setPrototypeOf || function(t, e) {
- t.__proto__ = e;
- return t;
- })(t, e);
- }
- function S(t, e, i, o, n) {
- var r = {};
- Object.keys(o).forEach(function(t) {
- r[t] = o[t];
- });
- r.enumerable = !!r.enumerable;
- r.configurable = !!r.configurable;
- ("value" in r || r.initializer) && (r.writable = !0);
- r = i.slice().reverse().reduce(function(i, o) {
- return o(t, e, i) || i;
- }, r);
- if (n && void 0 !== r.initializer) {
- r.value = r.initializer ? r.initializer.call(n) : void 0;
- r.initializer = void 0;
- }
- if (void 0 === r.initializer) {
- Object.defineProperty(t, e, r);
- r = null;
- }
- return r;
- }
- var E = cc._decorator, M = E.ccclass, C = E.executeInEditMode, A = E.executionOrder, z = E.menu, F = E.property, R = E.requireComponent, T = E.disallowMultiple, P = cc.Vec3, q = (o = M("cc.ConstantForce"),
- n = A(98), r = R(m.RigidBody3D), s = z("i18n:MAIN_MENU.component.physics/Constant Force 3D"),
- a = F({
- displayOrder: 0
- }), l = F({
- displayOrder: 1
- }), h = F({
- displayOrder: 2
- }), c = F({
- displayOrder: 3
- }), o(u = n(u = r(u = s(u = T(u = C(u = (p = function(t) {
- _(e, t);
- function e() {
- for (var e, i = arguments.length, o = new Array(i), n = 0; n < i; n++) o[n] = arguments[n];
- (e = t.call.apply(t, [ this ].concat(o)) || this)._rigidbody = null;
- g(e, "_force", d, x(e));
- g(e, "_localForce", y, x(e));
- g(e, "_torque", f, x(e));
- g(e, "_localTorque", v, x(e));
- e._mask = 0;
- return e;
- }
- var i = e.prototype;
- i.onLoad = function() {
- this._rigidbody = this.node.getComponent(m.RigidBody3D);
- this._maskUpdate(this._force, 1);
- this._maskUpdate(this._localForce, 2);
- this._maskUpdate(this._torque, 4);
- this._maskUpdate(this._localTorque, 8);
- };
- i.lateUpdate = function() {
- if (null != this._rigidbody && 0 != this._mask) {
- 1 & this._mask && this._rigidbody.applyForce(this._force);
- 2 & this._mask && this._rigidbody.applyLocalForce(this.localForce);
- 4 & this._mask && this._rigidbody.applyTorque(this._torque);
- 8 & this._mask && this._rigidbody.applyLocalTorque(this._localTorque);
- }
- };
- i._maskUpdate = function(t, e) {
- P.strictEquals(t, P.ZERO) ? this._mask &= ~e : this._mask |= e;
- };
- w(e, [ {
- key: "force",
- get: function() {
- return this._force;
- },
- set: function(t) {
- P.copy(this._force, t);
- this._maskUpdate(this._force, 1);
- }
- }, {
- key: "localForce",
- get: function() {
- return this._localForce;
- },
- set: function(t) {
- P.copy(this._localForce, t);
- this._maskUpdate(this.localForce, 2);
- }
- }, {
- key: "torque",
- get: function() {
- return this._torque;
- },
- set: function(t) {
- P.copy(this._torque, t);
- this._maskUpdate(this._torque, 4);
- }
- }, {
- key: "localTorque",
- get: function() {
- return this._localTorque;
- },
- set: function(t) {
- P.copy(this._localTorque, t);
- this._maskUpdate(this._localTorque, 8);
- }
- } ]);
- return e;
- }(cc.Component), d = S(p.prototype, "_force", [ F ], {
- configurable: !0,
- enumerable: !0,
- writable: !0,
- initializer: function() {
- return new P();
- }
- }), y = S(p.prototype, "_localForce", [ F ], {
- configurable: !0,
- enumerable: !0,
- writable: !0,
- initializer: function() {
- return new P();
- }
- }), f = S(p.prototype, "_torque", [ F ], {
- configurable: !0,
- enumerable: !0,
- writable: !0,
- initializer: function() {
- return new P();
- }
- }), v = S(p.prototype, "_localTorque", [ F ], {
- configurable: !0,
- enumerable: !0,
- writable: !0,
- initializer: function() {
- return new P();
- }
- }), S(p.prototype, "force", [ a ], Object.getOwnPropertyDescriptor(p.prototype, "force"), p.prototype),
- S(p.prototype, "localForce", [ l ], Object.getOwnPropertyDescriptor(p.prototype, "localForce"), p.prototype),
- S(p.prototype, "torque", [ h ], Object.getOwnPropertyDescriptor(p.prototype, "torque"), p.prototype),
- S(p.prototype, "localTorque", [ c ], Object.getOwnPropertyDescriptor(p.prototype, "localTorque"), p.prototype),
- p)) || u) || u) || u) || u) || u) || u);
- i.ConstantForce = q;
- }, {
- "./rigid-body-component": 16
- } ],
- 16: [ function(t, e, i) {
- "use strict";
- i.__esModule = !0;
- i.RigidBody3D = void 0;
- var o, n, r, s, a, l, h, c, u, p, d, y, f, v, m, g, b, w, x, _, B, S = t("../instance");
- function E(t, e, i, o) {
- i && Object.defineProperty(t, e, {
- enumerable: i.enumerable,
- configurable: i.configurable,
- writable: i.writable,
- value: i.initializer ? i.initializer.call(o) : void 0
- });
- }
- function M(t, e) {
- for (var i = 0; i < e.length; i++) {
- var o = e[i];
- o.enumerable = o.enumerable || !1;
- o.configurable = !0;
- "value" in o && (o.writable = !0);
- Object.defineProperty(t, o.key, o);
- }
- }
- function C(t, e, i) {
- e && M(t.prototype, e);
- i && M(t, i);
- return t;
- }
- function A(t) {
- if (void 0 === t) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
- return t;
- }
- function z(t, e) {
- t.prototype = Object.create(e.prototype);
- t.prototype.constructor = t;
- F(t, e);
- }
- function F(t, e) {
- return (F = Object.setPrototypeOf || function(t, e) {
- t.__proto__ = e;
- return t;
- })(t, e);
- }
- function R(t, e, i, o, n) {
- var r = {};
- Object.keys(o).forEach(function(t) {
- r[t] = o[t];
- });
- r.enumerable = !!r.enumerable;
- r.configurable = !!r.configurable;
- ("value" in r || r.initializer) && (r.writable = !0);
- r = i.slice().reverse().reduce(function(i, o) {
- return o(t, e, i) || i;
- }, r);
- if (n && void 0 !== r.initializer) {
- r.value = r.initializer ? r.initializer.call(n) : void 0;
- r.initializer = void 0;
- }
- if (void 0 === r.initializer) {
- Object.defineProperty(t, e, r);
- r = null;
- }
- return r;
- }
- var T = cc._decorator, P = T.ccclass, q = T.disallowMultiple, I = T.executeInEditMode, O = T.executionOrder, V = T.menu, j = T.property, k = cc.Vec3, N = (o = P("cc.RigidBody3D"),
- n = O(99), r = V("i18n:MAIN_MENU.component.physics/Rigid Body 3D"), s = j({
- displayOrder: 0
- }), a = j({
- displayOrder: 1
- }), l = j({
- displayOrder: 2
- }), h = j({
- displayOrder: 3
- }), c = j({
- displayOrder: 4
- }), u = j({
- displayOrder: 5
- }), p = j({
- displayOrder: 6
- }), d = j({
- displayOrder: 7
- }), o(y = n(y = r(y = I(y = q(y = (R((f = function(t) {
- z(e, t);
- function e() {
- var e;
- (e = t.call(this) || this)._body = void 0;
- e._allowSleep = !0;
- E(e, "_mass", v, A(e));
- E(e, "_linearDamping", m, A(e));
- E(e, "_angularDamping", g, A(e));
- E(e, "_fixedRotation", b, A(e));
- E(e, "_isKinematic", w, A(e));
- E(e, "_useGravity", x, A(e));
- E(e, "_linearFactor", _, A(e));
- E(e, "_angularFactor", B, A(e));
- e._body = (0, S.createRigidBody)();
- return e;
- }
- var i = e.prototype;
- i.__preload = function() {
- this._body.__preload(this);
- };
- i.onEnable = function() {
- this._body.onEnable();
- };
- i.onDisable = function() {
- this._body.onDisable();
- };
- i.onDestroy = function() {
- this._body.onDestroy();
- };
- i.applyForce = function(t, e) {
- this._assertOnload && this._body.applyForce(t, e);
- };
- i.applyLocalForce = function(t, e) {
- this._assertOnload && this._body.applyLocalForce(t, e);
- };
- i.applyImpulse = function(t, e) {
- this._assertOnload && this._body.applyImpulse(t, e);
- };
- i.applyLocalImpulse = function(t, e) {
- this._assertOnload && this._body.applyLocalImpulse(t, e);
- };
- i.applyTorque = function(t) {
- this._assertOnload && this._body.applyTorque(t);
- };
- i.applyLocalTorque = function(t) {
- this._assertOnload && this._body.applyLocalTorque(t);
- };
- i.wakeUp = function() {
- this._assertOnload && this._body.wakeUp();
- };
- i.sleep = function() {
- this._assertOnload && this._body.sleep();
- };
- i.getLinearVelocity = function(t) {
- this._assertOnload && this._body.getLinearVelocity(t);
- };
- i.setLinearVelocity = function(t) {
- this._assertOnload && this._body.setLinearVelocity(t);
- };
- i.getAngularVelocity = function(t) {
- this._assertOnload && this._body.getAngularVelocity(t);
- };
- i.setAngularVelocity = function(t) {
- this._assertOnload && this._body.setAngularVelocity(t);
- };
- C(e, [ {
- key: "allowSleep",
- get: function() {
- return this._allowSleep;
- },
- set: function(t) {
- this._allowSleep = t;
- this._body.allowSleep = t;
- }
- }, {
- key: "mass",
- get: function() {
- return this._mass;
- },
- set: function(t) {
- this._mass = t;
- this._body.mass = t;
- }
- }, {
- key: "linearDamping",
- get: function() {
- return this._linearDamping;
- },
- set: function(t) {
- this._linearDamping = t;
- this._body.linearDamping = t;
- }
- }, {
- key: "angularDamping",
- get: function() {
- return this._angularDamping;
- },
- set: function(t) {
- this._angularDamping = t;
- this._body.angularDamping = t;
- }
- }, {
- key: "isKinematic",
- get: function() {
- return this._isKinematic;
- },
- set: function(t) {
- this._isKinematic = t;
- this._body.isKinematic = t;
- }
- }, {
- key: "useGravity",
- get: function() {
- return this._useGravity;
- },
- set: function(t) {
- this._useGravity = t;
- this._body.useGravity = t;
- }
- }, {
- key: "fixedRotation",
- get: function() {
- return this._fixedRotation;
- },
- set: function(t) {
- this._fixedRotation = t;
- this._body.fixedRotation = t;
- }
- }, {
- key: "linearFactor",
- get: function() {
- return this._linearFactor;
- },
- set: function(t) {
- k.copy(this._linearFactor, t);
- this._body.linearFactor = this._linearFactor;
- }
- }, {
- key: "angularFactor",
- get: function() {
- return this._angularFactor;
- },
- set: function(t) {
- k.copy(this._angularFactor, t);
- this._body.angularFactor = this._angularFactor;
- }
- }, {
- key: "isAwake",
- get: function() {
- return !!this._assertOnload && this._body.isAwake;
- }
- }, {
- key: "isSleepy",
- get: function() {
- return !!this._assertOnload && this._body.isSleepy;
- }
- }, {
- key: "isSleeping",
- get: function() {
- return !!this._assertOnload && this._body.isSleeping;
- }
- }, {
- key: "rigidBody",
- get: function() {
- return this._body;
- }
- }, {
- key: "_assertOnload",
- get: function() {
- var t = 0 == this._isOnLoadCalled;
- t && cc.error("Physics Error: Please make sure that the node has been added to the scene");
- return !t;
- }
- } ]);
- return e;
- }(cc.Component)).prototype, "mass", [ s ], Object.getOwnPropertyDescriptor(f.prototype, "mass"), f.prototype),
- R(f.prototype, "linearDamping", [ a ], Object.getOwnPropertyDescriptor(f.prototype, "linearDamping"), f.prototype),
- R(f.prototype, "angularDamping", [ l ], Object.getOwnPropertyDescriptor(f.prototype, "angularDamping"), f.prototype),
- R(f.prototype, "isKinematic", [ h ], Object.getOwnPropertyDescriptor(f.prototype, "isKinematic"), f.prototype),
- R(f.prototype, "useGravity", [ c ], Object.getOwnPropertyDescriptor(f.prototype, "useGravity"), f.prototype),
- R(f.prototype, "fixedRotation", [ u ], Object.getOwnPropertyDescriptor(f.prototype, "fixedRotation"), f.prototype),
- R(f.prototype, "linearFactor", [ p ], Object.getOwnPropertyDescriptor(f.prototype, "linearFactor"), f.prototype),
- R(f.prototype, "angularFactor", [ d ], Object.getOwnPropertyDescriptor(f.prototype, "angularFactor"), f.prototype),
- v = R(f.prototype, "_mass", [ j ], {
- configurable: !0,
- enumerable: !0,
- writable: !0,
- initializer: function() {
- return 10;
- }
- }), m = R(f.prototype, "_linearDamping", [ j ], {
- configurable: !0,
- enumerable: !0,
- writable: !0,
- initializer: function() {
- return .1;
- }
- }), g = R(f.prototype, "_angularDamping", [ j ], {
- configurable: !0,
- enumerable: !0,
- writable: !0,
- initializer: function() {
- return .1;
- }
- }), b = R(f.prototype, "_fixedRotation", [ j ], {
- configurable: !0,
- enumerable: !0,
- writable: !0,
- initializer: function() {
- return !1;
- }
- }), w = R(f.prototype, "_isKinematic", [ j ], {
- configurable: !0,
- enumerable: !0,
- writable: !0,
- initializer: function() {
- return !1;
- }
- }), x = R(f.prototype, "_useGravity", [ j ], {
- configurable: !0,
- enumerable: !0,
- writable: !0,
- initializer: function() {
- return !0;
- }
- }), _ = R(f.prototype, "_linearFactor", [ j ], {
- configurable: !0,
- enumerable: !0,
- writable: !0,
- initializer: function() {
- return new k(1, 1, 1);
- }
- }), B = R(f.prototype, "_angularFactor", [ j ], {
- configurable: !0,
- enumerable: !0,
- writable: !0,
- initializer: function() {
- return new k(1, 1, 1);
- }
- }), f)) || y) || y) || y) || y) || y);
- i.RigidBody3D = N;
- }, {
- "../instance": 18
- } ],
- 17: [ function(t, e, i) {
- "use strict";
- i.__esModule = !0;
- var o = t("./physics-manager");
- i.Physics3DManager = o.Physics3DManager;
- var n = t("./physics-ray-result");
- i.PhysicsRayResult = n.PhysicsRayResult;
- var r = t("./components/collider/box-collider-component");
- i.BoxCollider3D = r.BoxCollider3D;
- var s = t("./components/collider/collider-component");
- i.Collider3D = s.Collider3D;
- var a = t("./components/collider/sphere-collider-component");
- i.SphereCollider3D = a.SphereCollider3D;
- var l = t("./components/rigid-body-component");
- i.RigidBody3D = l.RigidBody3D;
- var h = t("./components/constant-force"), c = t("./assets/physics-material");
- i.PhysicsMaterial = c.PhysicsMaterial;
- cc.Physics3DManager = o.Physics3DManager;
- cc.Collider3D = s.Collider3D;
- cc.BoxCollider3D = r.BoxCollider3D;
- cc.SphereCollider3D = a.SphereCollider3D;
- cc.RigidBody3D = l.RigidBody3D;
- cc.PhysicsRayResult = n.PhysicsRayResult;
- cc.ConstantForce = h.ConstantForce;
- }, {
- "./assets/physics-material": 11,
- "./components/collider/box-collider-component": 12,
- "./components/collider/collider-component": 13,
- "./components/collider/sphere-collider-component": 14,
- "./components/constant-force": 15,
- "./components/rigid-body-component": 16,
- "./physics-manager": 20,
- "./physics-ray-result": 21
- } ],
- 18: [ function(t, e, i) {
- "use strict";
- i.__esModule = !0;
- i.createPhysicsWorld = function() {
- return new o.PhysicsWorld();
- };
- i.createRigidBody = function() {
- return new o.RigidBody();
- };
- i.createBoxShape = function(t) {
- return new o.BoxShape(t);
- };
- i.createSphereShape = function(t) {
- return new o.SphereShape(t);
- };
- var o = t("./physics-selector");
- }, {
- "./physics-selector": 22
- } ],
- 19: [ function(t, e, i) {
- "use strict";
- i.__esModule = !0;
- i.ERigidBodyType = void 0;
- var o;
- i.ERigidBodyType = o;
- (function(t) {
- t[t.DYNAMIC = 1] = "DYNAMIC";
- t[t.STATIC = 2] = "STATIC";
- t[t.KINEMATIC = 4] = "KINEMATIC";
- })(o || (i.ERigidBodyType = o = {}));
- }, {} ],
- 20: [ function(t, e, i) {
- "use strict";
- i.__esModule = !0;
- i.Physics3DManager = void 0;
- var o, n, r, s, a, l, h, c, u = t("./instance"), p = t("./assets/physics-material"), d = t("./physics-ray-result");
- function y(t, e, i, o) {
- i && Object.defineProperty(t, e, {
- enumerable: i.enumerable,
- configurable: i.configurable,
- writable: i.writable,
- value: i.initializer ? i.initializer.call(o) : void 0
- });
- }
- function f(t, e) {
- for (var i = 0; i < e.length; i++) {
- var o = e[i];
- o.enumerable = o.enumerable || !1;
- o.configurable = !0;
- "value" in o && (o.writable = !0);
- Object.defineProperty(t, o.key, o);
- }
- }
- function v(t, e, i) {
- e && f(t.prototype, e);
- i && f(t, i);
- return t;
- }
- function m(t, e, i, o, n) {
- var r = {};
- Object.keys(o).forEach(function(t) {
- r[t] = o[t];
- });
- r.enumerable = !!r.enumerable;
- r.configurable = !!r.configurable;
- ("value" in r || r.initializer) && (r.writable = !0);
- r = i.slice().reverse().reduce(function(i, o) {
- return o(t, e, i) || i;
- }, r);
- if (n && void 0 !== r.initializer) {
- r.value = r.initializer ? r.initializer.call(n) : void 0;
- r.initializer = void 0;
- }
- if (void 0 === r.initializer) {
- Object.defineProperty(t, e, r);
- r = null;
- }
- return r;
- }
- var g = cc._decorator, b = g.property, w = (0, g.ccclass)("cc.Physics3DManager")(o = (r = m((n = function() {
- function t() {
- this.physicsWorld = void 0;
- this.raycastClosestResult = new d.PhysicsRayResult();
- this.raycastResults = [];
- y(this, "_enabled", r, this);
- y(this, "_allowSleep", s, this);
- y(this, "_gravity", a, this);
- y(this, "_maxSubStep", l, this);
- y(this, "_fixedTime", h, this);
- y(this, "_useFixedTime", c, this);
- this.useAccumulator = !1;
- this._accumulator = 0;
- this.useFixedDigit = !1;
- this.useInternalTime = !1;
- this.fixDigits = {
- position: 5,
- rotation: 12,
- timeNow: 3
- };
- this._deltaTime = 0;
- this._lastTime = 0;
- this._material = null;
- this.raycastOptions = {
- groupIndex: -1,
- queryTrigger: !0,
- maxDistance: Infinity
- };
- this.raycastResultPool = new cc.RecyclePool(function() {
- return new d.PhysicsRayResult();
- }, 1);
- cc.director._scheduler && cc.director._scheduler.enableForTarget(this);
- this.physicsWorld = (0, u.createPhysicsWorld)();
- this._lastTime = performance.now();
- this.gravity = this._gravity;
- this.allowSleep = this._allowSleep;
- this._material = new p.PhysicsMaterial();
- this._material.friction = .1;
- this._material.restitution = .1;
- this._material.on("physics_material_update", this._updateMaterial, this);
- this.physicsWorld.defaultMaterial = this._material;
- }
- var e = t.prototype;
- e.update = function(t) {
- if (this._enabled) {
- if (this.useInternalTime) {
- var e = parseFloat(performance.now().toFixed(this.fixDigits.timeNow));
- this._deltaTime = e > this._lastTime ? (e - this._lastTime) / 1e3 : 0;
- this._lastTime = e;
- } else this._deltaTime = t;
- cc.director.emit(cc.Director.EVENT_BEFORE_PHYSICS);
- if (this._useFixedTime) this.physicsWorld.step(this._fixedTime); else if (this.useAccumulator) {
- var i = 0;
- this._accumulator += this._deltaTime;
- for (;i < this._maxSubStep && this._accumulator > this._fixedTime; ) {
- this.physicsWorld.step(this._fixedTime);
- this._accumulator -= this._fixedTime;
- i++;
- }
- } else this.physicsWorld.step(this._fixedTime, this._deltaTime, this._maxSubStep);
- cc.director.emit(cc.Director.EVENT_AFTER_PHYSICS);
- }
- };
- e.raycast = function(t, e, i, o) {
- void 0 === e && (e = 0);
- void 0 === i && (i = Infinity);
- void 0 === o && (o = !0);
- this.raycastResultPool.reset();
- this.raycastResults.length = 0;
- if ("string" == typeof e) {
- var n = cc.game.groupList.indexOf(e);
- -1 == n && (n = 0);
- this.raycastOptions.groupIndex = n;
- } else this.raycastOptions.groupIndex = e;
- this.raycastOptions.maxDistance = i;
- this.raycastOptions.queryTrigger = o;
- return this.physicsWorld.raycast(t, this.raycastOptions, this.raycastResultPool, this.raycastResults) ? this.raycastResults : null;
- };
- e.raycastClosest = function(t, e, i, o) {
- void 0 === e && (e = 0);
- void 0 === i && (i = Infinity);
- void 0 === o && (o = !0);
- if ("string" == typeof e) {
- var n = cc.game.groupList.indexOf(e);
- -1 == n && (n = 0);
- this.raycastOptions.groupIndex = n;
- } else this.raycastOptions.groupIndex = e;
- this.raycastOptions.maxDistance = i;
- this.raycastOptions.queryTrigger = o;
- return this.physicsWorld.raycastClosest(t, this.raycastOptions, this.raycastClosestResult) ? this.raycastClosestResult : null;
- };
- e._updateMaterial = function() {
- this.physicsWorld.defaultMaterial = this._material;
- };
- v(t, [ {
- key: "enabled",
- get: function() {
- return this._enabled;
- },
- set: function(t) {
- this._enabled = t;
- }
- }, {
- key: "allowSleep",
- get: function() {
- return this._allowSleep;
- },
- set: function(t) {
- this._allowSleep = t;
- this.physicsWorld.allowSleep = this._allowSleep;
- }
- }, {
- key: "maxSubStep",
- get: function() {
- return this._maxSubStep;
- },
- set: function(t) {
- this._maxSubStep = t;
- }
- }, {
- key: "deltaTime",
- get: function() {
- return this._fixedTime;
- },
- set: function(t) {
- this._fixedTime = t;
- }
- }, {
- key: "useFixedTime",
- get: function() {
- return this._useFixedTime;
- },
- set: function(t) {
- this._useFixedTime = t;
- }
- }, {
- key: "gravity",
- get: function() {
- return this._gravity;
- },
- set: function(t) {
- this._gravity.set(t);
- this.physicsWorld.gravity = t;
- }
- }, {
- key: "defaultMaterial",
- get: function() {
- return this._material;
- }
- } ]);
- return t;
- }()).prototype, "_enabled", [ b ], {
- configurable: !0,
- enumerable: !0,
- writable: !0,
- initializer: function() {
- return !1;
- }
- }), s = m(n.prototype, "_allowSleep", [ b ], {
- configurable: !0,
- enumerable: !0,
- writable: !0,
- initializer: function() {
- return !0;
- }
- }), a = m(n.prototype, "_gravity", [ b ], {
- configurable: !0,
- enumerable: !0,
- writable: !0,
- initializer: function() {
- return new cc.Vec3(0, -10, 0);
- }
- }), l = m(n.prototype, "_maxSubStep", [ b ], {
- configurable: !0,
- enumerable: !0,
- writable: !0,
- initializer: function() {
- return 1;
- }
- }), h = m(n.prototype, "_fixedTime", [ b ], {
- configurable: !0,
- enumerable: !0,
- writable: !0,
- initializer: function() {
- return 1 / 60;
- }
- }), c = m(n.prototype, "_useFixedTime", [ b ], {
- configurable: !0,
- enumerable: !0,
- writable: !0,
- initializer: function() {
- return !0;
- }
- }), n)) || o;
- i.Physics3DManager = w;
- }, {
- "./assets/physics-material": 11,
- "./instance": 18,
- "./physics-ray-result": 21
- } ],
- 21: [ function(t, e, i) {
- "use strict";
- i.__esModule = !0;
- i.PhysicsRayResult = void 0;
- function o(t, e) {
- for (var i = 0; i < e.length; i++) {
- var o = e[i];
- o.enumerable = o.enumerable || !1;
- o.configurable = !0;
- "value" in o && (o.writable = !0);
- Object.defineProperty(t, o.key, o);
- }
- }
- function n(t, e, i) {
- e && o(t.prototype, e);
- i && o(t, i);
- return t;
- }
- var r = cc.Vec3, s = function() {
- function t() {
- this._hitPoint = new r();
- this._distance = 0;
- this._collidier = null;
- }
- var e = t.prototype;
- e._assign = function(t, e, i) {
- r.copy(this._hitPoint, t);
- this._distance = e;
- this._collidier = i;
- };
- e.clone = function() {
- var e = new t();
- r.copy(e._hitPoint, this._hitPoint);
- e._distance = this._distance;
- e._collidier = this._collidier;
- return e;
- };
- n(t, [ {
- key: "hitPoint",
- get: function() {
- return this._hitPoint;
- }
- }, {
- key: "distance",
- get: function() {
- return this._distance;
- }
- }, {
- key: "collider",
- get: function() {
- return this._collidier;
- }
- } ]);
- return t;
- }();
- i.PhysicsRayResult = s;
- }, {} ],
- 22: [ function(t, e, i) {
- "use strict";
- i.__esModule = !0;
- i.instantiate = function(t, e, a, l) {
- i.BoxShape = o = t;
- i.SphereShape = n = e;
- i.RigidBody = r = a;
- i.PhysicsWorld = s = l;
- };
- i.PhysicsWorld = i.RigidBody = i.SphereShape = i.BoxShape = void 0;
- var o, n, r, s;
- i.BoxShape = o;
- i.SphereShape = n;
- i.RigidBody = r;
- i.PhysicsWorld = s;
- }, {} ],
- 23: [ function(t, e, i) {
- "use strict";
- i.__esModule = !0;
- i.stringfyVec3 = function(t) {
- return "(x: " + t.x + ", y: " + t.y + ", z: " + t.z + ")";
- };
- i.stringfyQuat = function(t) {
- return "(x: " + t.x + ", y: " + t.y + ", z: " + t.z + ", w: " + t.w + ")";
- };
- i.setWrap = function(t, e) {
- t.__cc_wrapper__ = e;
- };
- i.getWrap = function(t) {
- return t.__cc_wrapper__;
- };
- i.clearNodeTransformDirtyFlag = function() {
- for (var t in b) {
- var e = b[t];
- e._localMatDirty &= ~r;
- e._localMatDirty & s || (e._worldMatDirty = !1);
- }
- b = {};
- p.length = 0;
- };
- i.clearNodeTransformRecord = function() {
- b = {};
- p.length = 0;
- };
- i.updateWorldTransform = w;
- i.updateWorldRT = function(t, e, i) {
- var o = t.parent;
- if (o) {
- w(o, !0);
- h.transformMat4(d, e, l.invert(g, o._worldMatrix));
- c.multiply(m, c.conjugate(m, o.__wrot), i);
- t.setPosition(d);
- t.setRotation(m);
- } else {
- t.setPosition(e);
- t.setRotation(i);
- }
- };
- i.worldDirty = function(t) {
- for (var e = t; e; ) {
- if (e._worldMatDirty) return !0;
- e = e._parent;
- }
- return !1;
- };
- var o = cc.Node._LocalDirtyFlag, n = o.PHYSICS_TRS, r = o.ALL_TRS, s = o.SKEW, a = (cc.RenderFlow.FLAG_TRANSFORM,
- cc.Mat3), l = cc.Mat4, h = cc.Vec3, c = cc.Quat, u = cc.Trs, p = [], d = cc.v3(), y = cc.quat(), f = new a(), v = f.m, m = cc.quat(), g = cc.mat4(), b = {};
- function w(t, e) {
- void 0 === e && (e = !1);
- for (var i, o, r, s, g, w, x, _, B = t, S = 0, E = !1, M = 0; B; ) {
- if (!e && b[B._id]) {
- M |= B._localMatDirty & n;
- E = E || !!M;
- break;
- }
- p[S++] = B;
- B._localMatDirty & n && (E = !0);
- B = B._parent;
- }
- if (!E) return !1;
- p.length = S;
- for (;S; ) {
- i = p[--S];
- !e && (b[i._id] = i);
- o = i._worldMatrix;
- g = i._matrix;
- s = i._trs;
- w = i.__wpos = i.__wpos || cc.v3();
- x = i.__wrot = i.__wrot || cc.quat();
- _ = i.__wscale = i.__wscale || cc.v3();
- i._localMatDirty & n && u.toMat4(g, s);
- i._localMatDirty |= M;
- if ((M |= i._localMatDirty & n) & n) {
- if (B) {
- r = B._worldMatrix;
- u.toPosition(d, s);
- h.transformMat4(w, d, r);
- l.multiply(o, r, g);
- u.toRotation(y, s);
- c.multiply(x, B.__wrot, y);
- a.fromQuat(f, c.conjugate(m, x));
- a.multiplyMat4(f, f, o);
- _.x = v[0];
- _.y = v[4];
- _.z = v[8];
- } else {
- u.toPosition(w, s);
- u.toRotation(x, s);
- u.toScale(_, s);
- l.copy(o, g);
- }
- B = i;
- } else B = i;
- }
- return !0;
- }
- }, {} ],
- 24: [ function(t, e, i) {
- (function(o) {
- "use strict";
- !function(t) {
- if ("object" == typeof i && "undefined" != typeof e) e.exports = t(); else if ("function" == typeof define && define.amd) define([], t); else {
- var n;
- "undefined" != typeof window ? n = window : "undefined" != typeof o ? n = o : "undefined" != typeof self && (n = self),
- n.CANNON = t();
- }
- }(function() {
- return function e(i, o, n) {
- function r(a, l) {
- if (!o[a]) {
- if (!i[a]) {
- var h = "function" == typeof t && t;
- if (!l && h) return h(a, !0);
- if (s) return s(a, !0);
- throw new Error("Cannot find module '" + a + "'");
- }
- var c = o[a] = {
- exports: {}
- };
- i[a][0].call(c.exports, function(t) {
- return r(i[a][1][t] || t);
- }, c, c.exports, e, i, o, n);
- }
- return o[a].exports;
- }
- for (var s = "function" == typeof t && t, a = 0; a < n.length; a++) r(n[a]);
- return r;
- }({
- 1: [ function(t, e) {
- e.exports = {
- name: "@cocos/cannon",
- version: "1.1.1-exp.3",
- description: "A lightweight 3D physics engine written in JavaScript.",
- homepage: "https://github.com/cocos-creator/cannon.js",
- author: "Stefan Hedman <schteppe@gmail.com> (http://steffe.se), JayceLai",
- keywords: [ "cannon.js", "cocos", "creator", "physics", "engine", "3d" ],
- scripts: {
- build: "grunt && npm run preprocess && grunt addLicense && grunt addDate",
- preprocess: "node node_modules/uglify-js/bin/uglifyjs build/cannon.js -o build/cannon.min.js -c -m"
- },
- main: "./build/cannon.min.js",
- engines: {
- node: "*"
- },
- repository: {
- type: "git",
- url: "https://github.com/cocos-creator/cannon.js.git"
- },
- bugs: {
- url: "https://github.com/cocos-creator/cannon.js/issues"
- },
- licenses: [ {
- type: "MIT"
- } ],
- devDependencies: {
- jshint: "latest",
- "uglify-js": "latest",
- nodeunit: "^0.9.0",
- grunt: "~0.4.0",
- "grunt-contrib-jshint": "~0.1.1",
- "grunt-contrib-nodeunit": "^0.4.1",
- "grunt-contrib-concat": "~0.1.3",
- "grunt-contrib-uglify": "^0.5.1",
- "grunt-browserify": "^2.1.4",
- "grunt-contrib-yuidoc": "^0.5.2",
- browserify: "*"
- },
- dependencies: {}
- };
- }, {} ],
- 2: [ function(t, e) {
- e.exports = {
- version: t("../package.json").version,
- AABB: t("./collision/AABB"),
- ArrayCollisionMatrix: t("./collision/ArrayCollisionMatrix"),
- Body: t("./objects/Body"),
- Box: t("./shapes/Box"),
- Broadphase: t("./collision/Broadphase"),
- Constraint: t("./constraints/Constraint"),
- ContactEquation: t("./equations/ContactEquation"),
- Narrowphase: t("./world/Narrowphase"),
- ConeTwistConstraint: t("./constraints/ConeTwistConstraint"),
- ContactMaterial: t("./material/ContactMaterial"),
- ConvexPolyhedron: t("./shapes/ConvexPolyhedron"),
- Cylinder: t("./shapes/Cylinder"),
- DistanceConstraint: t("./constraints/DistanceConstraint"),
- Equation: t("./equations/Equation"),
- EventTarget: t("./utils/EventTarget"),
- FrictionEquation: t("./equations/FrictionEquation"),
- GSSolver: t("./solver/GSSolver"),
- GridBroadphase: t("./collision/GridBroadphase"),
- Heightfield: t("./shapes/Heightfield"),
- HingeConstraint: t("./constraints/HingeConstraint"),
- LockConstraint: t("./constraints/LockConstraint"),
- Mat3: t("./math/Mat3"),
- Material: t("./material/Material"),
- NaiveBroadphase: t("./collision/NaiveBroadphase"),
- ObjectCollisionMatrix: t("./collision/ObjectCollisionMatrix"),
- Pool: t("./utils/Pool"),
- Particle: t("./shapes/Particle"),
- Plane: t("./shapes/Plane"),
- PointToPointConstraint: t("./constraints/PointToPointConstraint"),
- Quaternion: t("./math/Quaternion"),
- Ray: t("./collision/Ray"),
- RaycastVehicle: t("./objects/RaycastVehicle"),
- RaycastResult: t("./collision/RaycastResult"),
- RigidVehicle: t("./objects/RigidVehicle"),
- RotationalEquation: t("./equations/RotationalEquation"),
- RotationalMotorEquation: t("./equations/RotationalMotorEquation"),
- SAPBroadphase: t("./collision/SAPBroadphase"),
- SPHSystem: t("./objects/SPHSystem"),
- Shape: t("./shapes/Shape"),
- Solver: t("./solver/Solver"),
- Sphere: t("./shapes/Sphere"),
- SplitSolver: t("./solver/SplitSolver"),
- Spring: t("./objects/Spring"),
- Transform: t("./math/Transform"),
- Trimesh: t("./shapes/Trimesh"),
- Vec3: t("./math/Vec3"),
- Vec3Pool: t("./utils/Vec3Pool"),
- World: t("./world/World"),
- Octree: t("./utils/Octree"),
- CMath: t("./math/CMath")
- };
- }, {
- "../package.json": 1,
- "./collision/AABB": 3,
- "./collision/ArrayCollisionMatrix": 4,
- "./collision/Broadphase": 5,
- "./collision/GridBroadphase": 6,
- "./collision/NaiveBroadphase": 7,
- "./collision/ObjectCollisionMatrix": 8,
- "./collision/Ray": 10,
- "./collision/RaycastResult": 11,
- "./collision/SAPBroadphase": 12,
- "./constraints/ConeTwistConstraint": 13,
- "./constraints/Constraint": 14,
- "./constraints/DistanceConstraint": 15,
- "./constraints/HingeConstraint": 16,
- "./constraints/LockConstraint": 17,
- "./constraints/PointToPointConstraint": 18,
- "./equations/ContactEquation": 20,
- "./equations/Equation": 21,
- "./equations/FrictionEquation": 22,
- "./equations/RotationalEquation": 23,
- "./equations/RotationalMotorEquation": 24,
- "./material/ContactMaterial": 25,
- "./material/Material": 26,
- "./math/CMath": 27,
- "./math/Mat3": 29,
- "./math/Quaternion": 30,
- "./math/Transform": 31,
- "./math/Vec3": 32,
- "./objects/Body": 33,
- "./objects/RaycastVehicle": 34,
- "./objects/RigidVehicle": 35,
- "./objects/SPHSystem": 36,
- "./objects/Spring": 37,
- "./shapes/Box": 39,
- "./shapes/ConvexPolyhedron": 40,
- "./shapes/Cylinder": 41,
- "./shapes/Heightfield": 42,
- "./shapes/Particle": 43,
- "./shapes/Plane": 44,
- "./shapes/Shape": 45,
- "./shapes/Sphere": 46,
- "./shapes/Trimesh": 47,
- "./solver/GSSolver": 48,
- "./solver/Solver": 49,
- "./solver/SplitSolver": 50,
- "./utils/EventTarget": 51,
- "./utils/Octree": 52,
- "./utils/Pool": 53,
- "./utils/Vec3Pool": 56,
- "./world/Narrowphase": 57,
- "./world/World": 58
- } ],
- 3: [ function(t, e) {
- var i = t("../math/Vec3");
- t("../utils/Utils");
- e.exports = o;
- function o(t) {
- t = t || {};
- this.lowerBound = new i();
- t.lowerBound && this.lowerBound.copy(t.lowerBound);
- this.upperBound = new i();
- t.upperBound && this.upperBound.copy(t.upperBound);
- }
- var n = new i();
- o.prototype.setFromPoints = function(t, e, i, o) {
- var r = this.lowerBound, s = this.upperBound, a = i;
- r.copy(t[0]);
- a && a.vmult(r, r);
- s.copy(r);
- for (var l = 1; l < t.length; l++) {
- var h = t[l];
- if (a) {
- a.vmult(h, n);
- h = n;
- }
- h.x > s.x && (s.x = h.x);
- h.x < r.x && (r.x = h.x);
- h.y > s.y && (s.y = h.y);
- h.y < r.y && (r.y = h.y);
- h.z > s.z && (s.z = h.z);
- h.z < r.z && (r.z = h.z);
- }
- if (e) {
- e.vadd(r, r);
- e.vadd(s, s);
- }
- if (o) {
- r.x -= o;
- r.y -= o;
- r.z -= o;
- s.x += o;
- s.y += o;
- s.z += o;
- }
- return this;
- };
- o.prototype.copy = function(t) {
- this.lowerBound.copy(t.lowerBound);
- this.upperBound.copy(t.upperBound);
- return this;
- };
- o.prototype.clone = function() {
- return new o().copy(this);
- };
- o.prototype.extend = function(t) {
- this.lowerBound.x = Math.min(this.lowerBound.x, t.lowerBound.x);
- this.upperBound.x = Math.max(this.upperBound.x, t.upperBound.x);
- this.lowerBound.y = Math.min(this.lowerBound.y, t.lowerBound.y);
- this.upperBound.y = Math.max(this.upperBound.y, t.upperBound.y);
- this.lowerBound.z = Math.min(this.lowerBound.z, t.lowerBound.z);
- this.upperBound.z = Math.max(this.upperBound.z, t.upperBound.z);
- };
- o.prototype.overlaps = function(t) {
- var e = this.lowerBound, i = this.upperBound, o = t.lowerBound, n = t.upperBound, r = o.x <= i.x && i.x <= n.x || e.x <= n.x && n.x <= i.x, s = o.y <= i.y && i.y <= n.y || e.y <= n.y && n.y <= i.y, a = o.z <= i.z && i.z <= n.z || e.z <= n.z && n.z <= i.z;
- return r && s && a;
- };
- o.prototype.volume = function() {
- var t = this.lowerBound, e = this.upperBound;
- return (e.x - t.x) * (e.y - t.y) * (e.z - t.z);
- };
- o.prototype.contains = function(t) {
- var e = this.lowerBound, i = this.upperBound, o = t.lowerBound, n = t.upperBound;
- return e.x <= o.x && i.x >= n.x && e.y <= o.y && i.y >= n.y && e.z <= o.z && i.z >= n.z;
- };
- o.prototype.getCorners = function(t, e, i, o, n, r, s, a) {
- var l = this.lowerBound, h = this.upperBound;
- t.copy(l);
- e.set(h.x, l.y, l.z);
- i.set(h.x, h.y, l.z);
- o.set(l.x, h.y, h.z);
- n.set(h.x, l.y, h.z);
- r.set(l.x, h.y, l.z);
- s.set(l.x, l.y, h.z);
- a.copy(h);
- };
- var r = [ new i(), new i(), new i(), new i(), new i(), new i(), new i(), new i() ];
- o.prototype.toLocalFrame = function(t, e) {
- var i = r, o = i[0], n = i[1], s = i[2], a = i[3], l = i[4], h = i[5], c = i[6], u = i[7];
- this.getCorners(o, n, s, a, l, h, c, u);
- for (var p = 0; 8 !== p; p++) {
- var d = i[p];
- t.pointToLocal(d, d);
- }
- return e.setFromPoints(i);
- };
- o.prototype.toWorldFrame = function(t, e) {
- var i = r, o = i[0], n = i[1], s = i[2], a = i[3], l = i[4], h = i[5], c = i[6], u = i[7];
- this.getCorners(o, n, s, a, l, h, c, u);
- for (var p = 0; 8 !== p; p++) {
- var d = i[p];
- t.pointToWorld(d, d);
- }
- return e.setFromPoints(i);
- };
- o.prototype.overlapsRay = function(t) {
- var e = 1 / t._direction.x, i = 1 / t._direction.y, o = 1 / t._direction.z, n = (this.lowerBound.x - t.from.x) * e, r = (this.upperBound.x - t.from.x) * e, s = (this.lowerBound.y - t.from.y) * i, a = (this.upperBound.y - t.from.y) * i, l = (this.lowerBound.z - t.from.z) * o, h = (this.upperBound.z - t.from.z) * o, c = Math.max(Math.max(Math.min(n, r), Math.min(s, a)), Math.min(l, h)), u = Math.min(Math.min(Math.max(n, r), Math.max(s, a)), Math.max(l, h));
- return !(u < 0 || c > u);
- };
- }, {
- "../math/Vec3": 32,
- "../utils/Utils": 55
- } ],
- 4: [ function(t, e) {
- e.exports = i;
- function i() {
- this.matrix = [];
- }
- i.prototype.get = function(t, e) {
- t = t.index;
- if ((e = e.index) > t) {
- var i = e;
- e = t;
- t = i;
- }
- return this.matrix[(t * (t + 1) >> 1) + e - 1];
- };
- i.prototype.set = function(t, e, i) {
- t = t.index;
- if ((e = e.index) > t) {
- var o = e;
- e = t;
- t = o;
- }
- this.matrix[(t * (t + 1) >> 1) + e - 1] = i ? 1 : 0;
- };
- i.prototype.reset = function() {
- for (var t = 0, e = this.matrix.length; t !== e; t++) this.matrix[t] = 0;
- };
- i.prototype.setNumObjects = function(t) {
- this.matrix.length = t * (t - 1) >> 1;
- };
- }, {} ],
- 5: [ function(t, e) {
- var i = t("../objects/Body"), o = t("../math/Vec3"), n = t("../math/Quaternion");
- t("../shapes/Shape"), t("../shapes/Plane");
- e.exports = r;
- function r() {
- this.world = null;
- this.useBoundingBoxes = !1;
- this.dirty = !0;
- }
- r.prototype.collisionPairs = function() {
- throw new Error("collisionPairs not implemented for this BroadPhase class!");
- };
- r.prototype.needBroadphaseCollision = function(t, e) {
- return 0 != (t.collisionFilterGroup & e.collisionFilterMask) && 0 != (e.collisionFilterGroup & t.collisionFilterMask) && (!(!t.hasTrigger && !e.hasTrigger) || 0 == (t.type & i.STATIC) && t.sleepState !== i.SLEEPING || 0 == (e.type & i.STATIC) && e.sleepState !== i.SLEEPING);
- };
- r.prototype.intersectionTest = function(t, e, i, o) {
- this.useBoundingBoxes ? this.doBoundingBoxBroadphase(t, e, i, o) : this.doBoundingSphereBroadphase(t, e, i, o);
- };
- var s = new o();
- new o(), new n(), new o();
- r.prototype.doBoundingSphereBroadphase = function(t, e, i, o) {
- var n = s;
- e.position.vsub(t.position, n);
- var r = Math.pow(t.boundingRadius + e.boundingRadius, 2);
- if (n.norm2() < r) {
- i.push(t);
- o.push(e);
- }
- };
- r.prototype.doBoundingBoxBroadphase = function(t, e, i, o) {
- t.aabbNeedsUpdate && t.computeAABB();
- e.aabbNeedsUpdate && e.computeAABB();
- if (t.aabb.overlaps(e.aabb)) {
- i.push(t);
- o.push(e);
- }
- };
- var a = {
- keys: []
- }, l = [], h = [];
- r.prototype.makePairsUnique = function(t, e) {
- for (var i = a, o = l, n = h, r = t.length, s = 0; s !== r; s++) {
- o[s] = t[s];
- n[s] = e[s];
- }
- t.length = 0;
- e.length = 0;
- for (s = 0; s !== r; s++) {
- var c = o[s].id, u = n[s].id;
- i[p = c < u ? c + "," + u : u + "," + c] = s;
- i.keys.push(p);
- }
- for (s = 0; s !== i.keys.length; s++) {
- var p = i.keys.pop(), d = i[p];
- t.push(o[d]);
- e.push(n[d]);
- delete i[p];
- }
- };
- r.prototype.setWorld = function() {};
- var c = new o();
- r.boundingSphereCheck = function(t, e) {
- var i = c;
- t.position.vsub(e.position, i);
- return Math.pow(t.shape.boundingSphereRadius + e.shape.boundingSphereRadius, 2) > i.norm2();
- };
- r.prototype.aabbQuery = function() {
- console.warn(".aabbQuery is not implemented in this Broadphase subclass.");
- return [];
- };
- }, {
- "../math/Quaternion": 30,
- "../math/Vec3": 32,
- "../objects/Body": 33,
- "../shapes/Plane": 44,
- "../shapes/Shape": 45
- } ],
- 6: [ function(t, e) {
- e.exports = r;
- var i = t("./Broadphase"), o = t("../math/Vec3"), n = t("../shapes/Shape");
- function r(t, e, n, r, s) {
- i.apply(this);
- this.nx = n || 10;
- this.ny = r || 10;
- this.nz = s || 10;
- this.aabbMin = t || new o(100, 100, 100);
- this.aabbMax = e || new o(-100, -100, -100);
- var a = this.nx * this.ny * this.nz;
- if (a <= 0) throw "GridBroadphase: Each dimension's n must be >0";
- this.bins = [];
- this.binLengths = [];
- this.bins.length = a;
- this.binLengths.length = a;
- for (var l = 0; l < a; l++) {
- this.bins[l] = [];
- this.binLengths[l] = 0;
- }
- }
- r.prototype = new i();
- r.prototype.constructor = r;
- var s = new o();
- new o();
- r.prototype.collisionPairs = function(t, e, i) {
- for (var o = t.numObjects(), r = t.bodies, a = this.aabbMax, l = this.aabbMin, h = this.nx, c = this.ny, u = this.nz, p = c * u, d = u, y = 1, f = a.x, v = a.y, m = a.z, g = l.x, b = l.y, w = l.z, x = h / (f - g), _ = c / (v - b), B = u / (m - w), S = (f - g) / h, E = (v - b) / c, M = (m - w) / u, C = .5 * Math.sqrt(S * S + E * E + M * M), A = n.types, z = A.SPHERE, F = A.PLANE, R = (A.BOX,
- A.COMPOUND, A.CONVEXPOLYHEDRON, this.bins), T = this.binLengths, P = this.bins.length, q = 0; q !== P; q++) T[q] = 0;
- var I = Math.ceil;
- l = Math.min, a = Math.max;
- function O(t, e, i, o, n, r, s) {
- var a = (t - g) * x | 0, l = (e - b) * _ | 0, f = (i - w) * B | 0, v = I((o - g) * x), m = I((n - b) * _), S = I((r - w) * B);
- a < 0 ? a = 0 : a >= h && (a = h - 1);
- l < 0 ? l = 0 : l >= c && (l = c - 1);
- f < 0 ? f = 0 : f >= u && (f = u - 1);
- v < 0 ? v = 0 : v >= h && (v = h - 1);
- m < 0 ? m = 0 : m >= c && (m = c - 1);
- S < 0 ? S = 0 : S >= u && (S = u - 1);
- l *= d;
- f *= y;
- v *= p;
- m *= d;
- S *= y;
- for (var E = a *= p; E <= v; E += p) for (var M = l; M <= m; M += d) for (var C = f; C <= S; C += y) {
- var A = E + M + C;
- R[A][T[A]++] = s;
- }
- }
- for (q = 0; q !== o; q++) {
- var V = (it = r[q]).shape;
- switch (V.type) {
- case z:
- var j = it.position.x, k = it.position.y, N = it.position.z, L = V.radius;
- O(j - L, k - L, N - L, j + L, k + L, N + L, it);
- break;
- case F:
- V.worldNormalNeedsUpdate && V.computeWorldNormal(it.quaternion);
- var W = V.worldNormal, D = g + .5 * S - it.position.x, U = b + .5 * E - it.position.y, G = w + .5 * M - it.position.z, H = s;
- H.set(D, U, G);
- for (var K = 0, Q = 0; K !== h; K++, Q += p, H.y = U, H.x += S) for (var X = 0, Y = 0; X !== c; X++,
- Y += d, H.z = G, H.y += E) for (var Z = 0, J = 0; Z !== u; Z++, J += y, H.z += M) if (H.dot(W) < C) {
- var $ = Q + Y + J;
- R[$][T[$]++] = it;
- }
- break;
- default:
- it.aabbNeedsUpdate && it.computeAABB();
- O(it.aabb.lowerBound.x, it.aabb.lowerBound.y, it.aabb.lowerBound.z, it.aabb.upperBound.x, it.aabb.upperBound.y, it.aabb.upperBound.z, it);
- }
- }
- for (q = 0; q !== P; q++) {
- var tt = T[q];
- if (tt > 1) {
- var et = R[q];
- for (K = 0; K !== tt; K++) {
- var it = et[K];
- for (X = 0; X !== K; X++) {
- var ot = et[X];
- this.needBroadphaseCollision(it, ot) && this.intersectionTest(it, ot, e, i);
- }
- }
- }
- }
- this.makePairsUnique(e, i);
- };
- }, {
- "../math/Vec3": 32,
- "../shapes/Shape": 45,
- "./Broadphase": 5
- } ],
- 7: [ function(t, e) {
- e.exports = n;
- var i = t("./Broadphase"), o = t("./AABB");
- function n() {
- i.apply(this);
- }
- n.prototype = new i();
- n.prototype.constructor = n;
- n.prototype.collisionPairs = function(t, e, i) {
- var o, n, r, s, a = t.bodies, l = a.length;
- for (o = 0; o !== l; o++) for (n = 0; n !== o; n++) {
- r = a[o];
- s = a[n];
- this.needBroadphaseCollision(r, s) && this.intersectionTest(r, s, e, i);
- }
- };
- new o();
- n.prototype.aabbQuery = function(t, e, i) {
- i = i || [];
- for (var o = 0; o < t.bodies.length; o++) {
- var n = t.bodies[o];
- n.aabbNeedsUpdate && n.computeAABB();
- n.aabb.overlaps(e) && i.push(n);
- }
- return i;
- };
- }, {
- "./AABB": 3,
- "./Broadphase": 5
- } ],
- 8: [ function(t, e) {
- e.exports = i;
- function i() {
- this.matrix = {};
- }
- i.prototype.get = function(t, e) {
- t = t.id;
- if ((e = e.id) > t) {
- var i = e;
- e = t;
- t = i;
- }
- return t + "-" + e in this.matrix;
- };
- i.prototype.set = function(t, e, i) {
- t = t.id;
- if ((e = e.id) > t) {
- var o = e;
- e = t;
- t = o;
- }
- i ? this.matrix[t + "-" + e] = !0 : delete this.matrix[t + "-" + e];
- };
- i.prototype.reset = function() {
- this.matrix = {};
- };
- i.prototype.setNumObjects = function() {};
- }, {} ],
- 9: [ function(t, e) {
- e.exports = i;
- function i() {
- this.current = [];
- this.previous = [];
- }
- i.prototype.getKey = function(t, e) {
- if (e < t) {
- var i = e;
- e = t;
- t = i;
- }
- return t << 16 | e;
- };
- i.prototype.set = function(t, e) {
- for (var i = this.getKey(t, e), o = this.current, n = 0; i > o[n]; ) n++;
- if (i !== o[n]) {
- for (e = o.length - 1; e >= n; e--) o[e + 1] = o[e];
- o[n] = i;
- }
- };
- i.prototype.tick = function() {
- var t = this.current;
- this.current = this.previous;
- this.previous = t;
- this.current.length = 0;
- };
- function o(t, e) {
- t.push((4294901760 & e) >> 16, 65535 & e);
- }
- i.prototype.getDiff = function(t, e) {
- for (var i = this.current, n = this.previous, r = i.length, s = n.length, a = 0, l = 0; l < r; l++) {
- for (var h = i[l]; h > n[a]; ) a++;
- h === n[a] || o(t, h);
- }
- a = 0;
- for (l = 0; l < s; l++) {
- for (var c = n[l]; c > i[a]; ) a++;
- i[a] === c || o(e, c);
- }
- };
- }, {} ],
- 10: [ function(t, e) {
- e.exports = l;
- var i = t("../math/Vec3"), o = t("../math/Quaternion"), n = t("../math/Transform"), r = (t("../shapes/ConvexPolyhedron"),
- t("../shapes/Box"), t("../collision/RaycastResult")), s = t("../shapes/Shape"), a = t("../collision/AABB");
- function l(t, e) {
- this.from = t ? t.clone() : new i();
- this.to = e ? e.clone() : new i();
- this._direction = new i();
- this.precision = 1e-4;
- this.checkCollisionResponse = !0;
- this.skipBackfaces = !1;
- this.collisionFilterMask = -1;
- this.collisionFilterGroup = -1;
- this.mode = l.ANY;
- this.result = new r();
- this.hasHit = !1;
- this.callback = function() {};
- }
- l.prototype.constructor = l;
- l.CLOSEST = 1;
- l.ANY = 2;
- l.ALL = 4;
- var h = new a(), c = [];
- l.prototype.intersectWorld = function(t, e) {
- this.mode = e.mode || l.ANY;
- this.result = e.result || new r();
- this.skipBackfaces = !!e.skipBackfaces;
- this.checkCollisionResponse = !!e.checkCollisionResponse;
- this.collisionFilterMask = "undefined" != typeof e.collisionFilterMask ? e.collisionFilterMask : -1;
- this.collisionFilterGroup = "undefined" != typeof e.collisionFilterGroup ? e.collisionFilterGroup : -1;
- e.from && this.from.copy(e.from);
- e.to && this.to.copy(e.to);
- this.callback = e.callback || function() {};
- this.hasHit = !1;
- this.result.reset();
- this._updateDirection();
- this.getAABB(h);
- c.length = 0;
- t.broadphase.aabbQuery(t, h, c);
- this.intersectBodies(c);
- return this.hasHit;
- };
- var u = new i(), p = new i();
- l.pointInTriangle = d;
- function d(t, e, i, o) {
- o.vsub(e, O);
- i.vsub(e, u);
- t.vsub(e, p);
- var n, r, s = O.dot(O), a = O.dot(u), l = O.dot(p), h = u.dot(u), c = u.dot(p);
- return (n = h * l - a * c) >= 0 && (r = s * c - a * l) >= 0 && n + r < s * h - a * a;
- }
- var y = new i(), f = new o();
- l.prototype.intersectBody = function(t, e) {
- if (e) {
- this.result = e;
- this._updateDirection();
- }
- var i = this.checkCollisionResponse;
- if ((!i || t.collisionResponse) && 0 != (this.collisionFilterGroup & t.collisionFilterMask) && 0 != (t.collisionFilterGroup & this.collisionFilterMask)) for (var o = y, n = f, r = 0, s = t.shapes.length; r < s; r++) {
- var a = t.shapes[r];
- if (!i || a.collisionResponse) {
- t.quaternion.mult(t.shapeOrientations[r], n);
- t.quaternion.vmult(t.shapeOffsets[r], o);
- o.vadd(t.position, o);
- this.intersectShape(a, n, o, t);
- if (this.result._shouldStop) break;
- }
- }
- };
- l.prototype.intersectBodies = function(t, e) {
- if (e) {
- this.result = e;
- this._updateDirection();
- }
- for (var i = 0, o = t.length; !this.result._shouldStop && i < o; i++) this.intersectBody(t[i]);
- };
- l.prototype._updateDirection = function() {
- this.to.vsub(this.from, this._direction);
- this._direction.normalize();
- };
- l.prototype.intersectShape = function(t, e, i, o) {
- if (!(j(this.from, this._direction, i) > t.boundingSphereRadius)) {
- var n = this[t.type];
- n && n.call(this, t, e, i, o, t);
- }
- };
- new i(), new i();
- var v = new i(), m = new i(), g = new i(), b = new i();
- new i(), new r();
- l.prototype.intersectBox = function(t, e, i, o, n) {
- return this.intersectConvex(t.convexPolyhedronRepresentation, e, i, o, n);
- };
- l.prototype[s.types.BOX] = l.prototype.intersectBox;
- l.prototype.intersectPlane = function(t, e, o, n, r) {
- var s = this.from, a = this.to, l = this._direction, h = new i(0, 0, 1);
- e.vmult(h, h);
- var c = new i();
- s.vsub(o, c);
- var u = c.dot(h);
- a.vsub(o, c);
- if (!(u * c.dot(h) > 0 || s.distanceTo(a) < u)) {
- var p = h.dot(l);
- if (!(Math.abs(p) < this.precision)) {
- var d = new i(), y = new i(), f = new i();
- s.vsub(o, d);
- var v = -h.dot(d) / p;
- l.scale(v, y);
- s.vadd(y, f);
- this.reportIntersection(h, f, r, n, -1);
- }
- }
- };
- l.prototype[s.types.PLANE] = l.prototype.intersectPlane;
- l.prototype.getAABB = function(t) {
- var e = this.to, i = this.from;
- t.lowerBound.x = Math.min(e.x, i.x);
- t.lowerBound.y = Math.min(e.y, i.y);
- t.lowerBound.z = Math.min(e.z, i.z);
- t.upperBound.x = Math.max(e.x, i.x);
- t.upperBound.y = Math.max(e.y, i.y);
- t.upperBound.z = Math.max(e.z, i.z);
- };
- var w = {
- faceList: [ 0 ]
- }, x = new i(), _ = new l(), B = [];
- l.prototype.intersectHeightfield = function(t, e, i, o, r) {
- t.data, t.elementSize;
- var s = _;
- s.from.copy(this.from);
- s.to.copy(this.to);
- n.pointToLocalFrame(i, e, s.from, s.from);
- n.pointToLocalFrame(i, e, s.to, s.to);
- s._updateDirection();
- var l, h, c, u, p = B;
- l = h = 0;
- c = u = t.data.length - 1;
- var d = new a();
- s.getAABB(d);
- t.getIndexOfPosition(d.lowerBound.x, d.lowerBound.y, p, !0);
- l = Math.max(l, p[0]);
- h = Math.max(h, p[1]);
- t.getIndexOfPosition(d.upperBound.x, d.upperBound.y, p, !0);
- c = Math.min(c, p[0] + 1);
- u = Math.min(u, p[1] + 1);
- for (var y = l; y < c; y++) for (var f = h; f < u; f++) {
- if (this.result._shouldStop) return;
- t.getAabbAtIndex(y, f, d);
- if (d.overlapsRay(s)) {
- t.getConvexTrianglePillar(y, f, !1);
- n.pointToWorldFrame(i, e, t.pillarOffset, x);
- this.intersectConvex(t.pillarConvex, e, x, o, r, w);
- if (this.result._shouldStop) return;
- t.getConvexTrianglePillar(y, f, !0);
- n.pointToWorldFrame(i, e, t.pillarOffset, x);
- this.intersectConvex(t.pillarConvex, e, x, o, r, w);
- }
- }
- };
- l.prototype[s.types.HEIGHTFIELD] = l.prototype.intersectHeightfield;
- var S = new i(), E = new i();
- l.prototype.intersectSphere = function(t, e, i, o, n) {
- var r = this.from, s = this.to, a = t.radius, l = Math.pow(s.x - r.x, 2) + Math.pow(s.y - r.y, 2) + Math.pow(s.z - r.z, 2), h = 2 * ((s.x - r.x) * (r.x - i.x) + (s.y - r.y) * (r.y - i.y) + (s.z - r.z) * (r.z - i.z)), c = Math.pow(r.x - i.x, 2) + Math.pow(r.y - i.y, 2) + Math.pow(r.z - i.z, 2) - Math.pow(a, 2), u = Math.pow(h, 2) - 4 * l * c, p = S, d = E;
- if (!(u < 0)) if (0 === u) {
- r.lerp(s, u, p);
- p.vsub(i, d);
- d.normalize();
- this.reportIntersection(d, p, n, o, -1);
- } else {
- var y = (-h - Math.sqrt(u)) / (2 * l), f = (-h + Math.sqrt(u)) / (2 * l);
- if (y >= 0 && y <= 1) {
- r.lerp(s, y, p);
- p.vsub(i, d);
- d.normalize();
- this.reportIntersection(d, p, n, o, -1);
- }
- if (this.result._shouldStop) return;
- if (f >= 0 && f <= 1) {
- r.lerp(s, f, p);
- p.vsub(i, d);
- d.normalize();
- this.reportIntersection(d, p, n, o, -1);
- }
- }
- };
- l.prototype[s.types.SPHERE] = l.prototype.intersectSphere;
- var M = new i(), C = (new i(), new i(), new i());
- l.prototype.intersectConvex = function(t, e, i, o, n, r) {
- for (var s = M, a = C, l = r && r.faceList || null, h = t.faces, c = t.vertices, u = t.faceNormals, p = this._direction, y = this.from, f = this.to, w = y.distanceTo(f), x = l ? l.length : h.length, _ = this.result, B = 0; !_._shouldStop && B < x; B++) {
- var S = l ? l[B] : B, E = h[S], A = u[S], z = e, F = i;
- a.copy(c[E[0]]);
- z.vmult(a, a);
- a.vadd(F, a);
- a.vsub(y, a);
- z.vmult(A, s);
- var R = p.dot(s);
- if (!(Math.abs(R) < this.precision)) {
- var T = s.dot(a) / R;
- if (!(T < 0)) {
- p.mult(T, v);
- v.vadd(y, v);
- m.copy(c[E[0]]);
- z.vmult(m, m);
- F.vadd(m, m);
- for (var P = 1; !_._shouldStop && P < E.length - 1; P++) {
- g.copy(c[E[P]]);
- b.copy(c[E[P + 1]]);
- z.vmult(g, g);
- z.vmult(b, b);
- F.vadd(g, g);
- F.vadd(b, b);
- var q = v.distanceTo(y);
- !d(v, m, g, b) && !d(v, g, m, b) || q > w || this.reportIntersection(s, v, n, o, S);
- }
- }
- }
- }
- };
- l.prototype[s.types.CONVEXPOLYHEDRON] = l.prototype.intersectConvex;
- var A = new i(), z = new i(), F = new i(), R = new i(), T = new i(), P = new i(), q = (new a(),
- []), I = new n();
- l.prototype.intersectTrimesh = function(t, e, i, o, r, s) {
- var a = A, l = q, h = I, c = C, u = z, p = F, y = R, f = P, w = T, x = (s && s.faceList,
- t.indices), _ = (t.vertices, t.faceNormals, this.from), B = this.to, S = this._direction;
- h.position.copy(i);
- h.quaternion.copy(e);
- n.vectorToLocalFrame(i, e, S, u);
- n.pointToLocalFrame(i, e, _, p);
- n.pointToLocalFrame(i, e, B, y);
- y.x *= t.scale.x;
- y.y *= t.scale.y;
- y.z *= t.scale.z;
- p.x *= t.scale.x;
- p.y *= t.scale.y;
- p.z *= t.scale.z;
- y.vsub(p, u);
- u.normalize();
- var E = p.distanceSquared(y);
- t.tree.rayQuery(this, h, l);
- for (var M = 0, O = l.length; !this.result._shouldStop && M !== O; M++) {
- var V = l[M];
- t.getNormal(V, a);
- t.getVertex(x[3 * V], m);
- m.vsub(p, c);
- var j = u.dot(a), k = a.dot(c) / j;
- if (!(k < 0)) {
- u.scale(k, v);
- v.vadd(p, v);
- t.getVertex(x[3 * V + 1], g);
- t.getVertex(x[3 * V + 2], b);
- var N = v.distanceSquared(p);
- if (!(!d(v, g, m, b) && !d(v, m, g, b) || N > E)) {
- n.vectorToWorldFrame(e, a, w);
- n.pointToWorldFrame(i, e, v, f);
- this.reportIntersection(w, f, r, o, V);
- }
- }
- }
- l.length = 0;
- };
- l.prototype[s.types.TRIMESH] = l.prototype.intersectTrimesh;
- l.prototype.reportIntersection = function(t, e, i, o, n) {
- var r = this.from, s = this.to, a = r.distanceTo(e), h = this.result;
- if (!(this.skipBackfaces && t.dot(this._direction) > 0)) {
- h.hitFaceIndex = "undefined" != typeof n ? n : -1;
- switch (this.mode) {
- case l.ALL:
- this.hasHit = !0;
- h.set(r, s, t, e, i, o, a);
- h.hasHit = !0;
- this.callback(h);
- break;
- case l.CLOSEST:
- if (a < h.distance || !h.hasHit) {
- this.hasHit = !0;
- h.hasHit = !0;
- h.set(r, s, t, e, i, o, a);
- }
- break;
- case l.ANY:
- this.hasHit = !0;
- h.hasHit = !0;
- h.set(r, s, t, e, i, o, a);
- h._shouldStop = !0;
- }
- }
- };
- var O = new i(), V = new i();
- function j(t, e, i) {
- i.vsub(t, O);
- var o = O.dot(e);
- e.mult(o, V);
- V.vadd(t, V);
- return i.distanceTo(V);
- }
- }, {
- "../collision/AABB": 3,
- "../collision/RaycastResult": 11,
- "../math/Quaternion": 30,
- "../math/Transform": 31,
- "../math/Vec3": 32,
- "../shapes/Box": 39,
- "../shapes/ConvexPolyhedron": 40,
- "../shapes/Shape": 45
- } ],
- 11: [ function(t, e) {
- var i = t("../math/Vec3");
- e.exports = o;
- function o() {
- this.rayFromWorld = new i();
- this.rayToWorld = new i();
- this.hitNormalWorld = new i();
- this.hitPointWorld = new i();
- this.hasHit = !1;
- this.shape = null;
- this.body = null;
- this.hitFaceIndex = -1;
- this.distance = -1;
- this._shouldStop = !1;
- }
- o.prototype.reset = function() {
- this.rayFromWorld.setZero();
- this.rayToWorld.setZero();
- this.hitNormalWorld.setZero();
- this.hitPointWorld.setZero();
- this.hasHit = !1;
- this.shape = null;
- this.body = null;
- this.hitFaceIndex = -1;
- this.distance = -1;
- this._shouldStop = !1;
- };
- o.prototype.abort = function() {
- this._shouldStop = !0;
- };
- o.prototype.set = function(t, e, i, o, n, r, s) {
- this.rayFromWorld.copy(t);
- this.rayToWorld.copy(e);
- this.hitNormalWorld.copy(i);
- this.hitPointWorld.copy(o);
- this.shape = n;
- this.body = r;
- this.distance = s;
- };
- }, {
- "../math/Vec3": 32
- } ],
- 12: [ function(t, e) {
- t("../shapes/Shape");
- var i = t("../collision/Broadphase");
- e.exports = o;
- function o(t) {
- i.apply(this);
- this.axisList = [];
- this.world = null;
- this.axisIndex = 0;
- var e = this.axisList;
- this._addBodyHandler = function(t) {
- e.push(t.body);
- };
- this._removeBodyHandler = function(t) {
- var i = e.indexOf(t.body);
- -1 !== i && e.splice(i, 1);
- };
- t && this.setWorld(t);
- }
- o.prototype = new i();
- o.prototype.setWorld = function(t) {
- this.axisList.length = 0;
- for (var e = 0; e < t.bodies.length; e++) this.axisList.push(t.bodies[e]);
- t.removeEventListener("addBody", this._addBodyHandler);
- t.removeEventListener("removeBody", this._removeBodyHandler);
- t.addEventListener("addBody", this._addBodyHandler);
- t.addEventListener("removeBody", this._removeBodyHandler);
- this.world = t;
- this.dirty = !0;
- };
- o.insertionSortX = function(t) {
- for (var e = 1, i = t.length; e < i; e++) {
- for (var o = t[e], n = e - 1; n >= 0 && !(t[n].aabb.lowerBound.x <= o.aabb.lowerBound.x); n--) t[n + 1] = t[n];
- t[n + 1] = o;
- }
- return t;
- };
- o.insertionSortY = function(t) {
- for (var e = 1, i = t.length; e < i; e++) {
- for (var o = t[e], n = e - 1; n >= 0 && !(t[n].aabb.lowerBound.y <= o.aabb.lowerBound.y); n--) t[n + 1] = t[n];
- t[n + 1] = o;
- }
- return t;
- };
- o.insertionSortZ = function(t) {
- for (var e = 1, i = t.length; e < i; e++) {
- for (var o = t[e], n = e - 1; n >= 0 && !(t[n].aabb.lowerBound.z <= o.aabb.lowerBound.z); n--) t[n + 1] = t[n];
- t[n + 1] = o;
- }
- return t;
- };
- o.prototype.collisionPairs = function(t, e, i) {
- var n, r, s = this.axisList, a = s.length, l = this.axisIndex;
- if (this.dirty) {
- this.sortList();
- this.dirty = !1;
- }
- for (n = 0; n !== a; n++) {
- var h = s[n];
- for (r = n + 1; r < a; r++) {
- var c = s[r];
- if (this.needBroadphaseCollision(h, c)) {
- if (!o.checkBounds(h, c, l)) break;
- this.intersectionTest(h, c, e, i);
- }
- }
- }
- };
- o.prototype.sortList = function() {
- for (var t = this.axisList, e = this.axisIndex, i = t.length, n = 0; n !== i; n++) {
- var r = t[n];
- r.aabbNeedsUpdate && r.computeAABB();
- }
- 0 === e ? o.insertionSortX(t) : 1 === e ? o.insertionSortY(t) : 2 === e && o.insertionSortZ(t);
- };
- o.checkBounds = function(t, e, i) {
- var o, n;
- if (0 === i) {
- o = t.position.x;
- n = e.position.x;
- } else if (1 === i) {
- o = t.position.y;
- n = e.position.y;
- } else if (2 === i) {
- o = t.position.z;
- n = e.position.z;
- }
- var r = t.boundingRadius;
- return n - e.boundingRadius < o + r;
- };
- o.prototype.autoDetectAxis = function() {
- for (var t = 0, e = 0, i = 0, o = 0, n = 0, r = 0, s = this.axisList, a = s.length, l = 1 / a, h = 0; h !== a; h++) {
- var c = s[h], u = c.position.x;
- t += u;
- e += u * u;
- var p = c.position.y;
- i += p;
- o += p * p;
- var d = c.position.z;
- n += d;
- r += d * d;
- }
- var y = e - t * t * l, f = o - i * i * l, v = r - n * n * l;
- this.axisIndex = y > f ? y > v ? 0 : 2 : f > v ? 1 : 2;
- };
- o.prototype.aabbQuery = function(t, e, i) {
- i = i || [];
- if (this.dirty) {
- this.sortList();
- this.dirty = !1;
- }
- var o = this.axisIndex, n = "x";
- 1 === o && (n = "y");
- 2 === o && (n = "z");
- for (var r = this.axisList, s = (e.lowerBound[n], e.upperBound[n], 0); s < r.length; s++) {
- var a = r[s];
- a.aabbNeedsUpdate && a.computeAABB();
- a.aabb.overlaps(e) && i.push(a);
- }
- return i;
- };
- }, {
- "../collision/Broadphase": 5,
- "../shapes/Shape": 45
- } ],
- 13: [ function(t, e) {
- e.exports = s;
- t("./Constraint");
- var i = t("./PointToPointConstraint"), o = t("../equations/ConeEquation"), n = t("../equations/RotationalEquation"), r = (t("../equations/ContactEquation"),
- t("../math/Vec3"));
- function s(t, e, s) {
- var a = "undefined" != typeof (s = s || {}).maxForce ? s.maxForce : 1e6, l = s.pivotA ? s.pivotA.clone() : new r(), h = s.pivotB ? s.pivotB.clone() : new r();
- this.axisA = s.axisA ? s.axisA.clone() : new r();
- this.axisB = s.axisB ? s.axisB.clone() : new r();
- i.call(this, t, l, e, h, a);
- this.collideConnected = !!s.collideConnected;
- this.angle = "undefined" != typeof s.angle ? s.angle : 0;
- var c = this.coneEquation = new o(t, e, s), u = this.twistEquation = new n(t, e, s);
- this.twistAngle = "undefined" != typeof s.twistAngle ? s.twistAngle : 0;
- c.maxForce = 0;
- c.minForce = -a;
- u.maxForce = 0;
- u.minForce = -a;
- this.equations.push(c, u);
- }
- s.prototype = new i();
- s.constructor = s;
- new r(), new r();
- s.prototype.update = function() {
- var t = this.bodyA, e = this.bodyB, o = this.coneEquation, n = this.twistEquation;
- i.prototype.update.call(this);
- t.vectorToWorldFrame(this.axisA, o.axisA);
- e.vectorToWorldFrame(this.axisB, o.axisB);
- this.axisA.tangents(n.axisA, n.axisA);
- t.vectorToWorldFrame(n.axisA, n.axisA);
- this.axisB.tangents(n.axisB, n.axisB);
- e.vectorToWorldFrame(n.axisB, n.axisB);
- o.angle = this.angle;
- n.maxAngle = this.twistAngle;
- };
- }, {
- "../equations/ConeEquation": 19,
- "../equations/ContactEquation": 20,
- "../equations/RotationalEquation": 23,
- "../math/Vec3": 32,
- "./Constraint": 14,
- "./PointToPointConstraint": 18
- } ],
- 14: [ function(t, e) {
- e.exports = o;
- var i = t("../utils/Utils");
- function o(t, e, n) {
- n = i.defaults(n, {
- collideConnected: !0,
- wakeUpBodies: !0
- });
- this.equations = [];
- this.bodyA = t;
- this.bodyB = e;
- this.id = o.idCounter++;
- this.collideConnected = n.collideConnected;
- if (n.wakeUpBodies) {
- t && t.wakeUp();
- e && e.wakeUp();
- }
- }
- o.prototype.update = function() {
- throw new Error("method update() not implmemented in this Constraint subclass!");
- };
- o.prototype.enable = function() {
- for (var t = this.equations, e = 0; e < t.length; e++) t[e].enabled = !0;
- };
- o.prototype.disable = function() {
- for (var t = this.equations, e = 0; e < t.length; e++) t[e].enabled = !1;
- };
- o.idCounter = 0;
- }, {
- "../utils/Utils": 55
- } ],
- 15: [ function(t, e) {
- e.exports = n;
- var i = t("./Constraint"), o = t("../equations/ContactEquation");
- function n(t, e, n, r) {
- i.call(this, t, e);
- "undefined" == typeof n && (n = t.position.distanceTo(e.position));
- "undefined" == typeof r && (r = 1e6);
- this.distance = n;
- var s = this.distanceEquation = new o(t, e);
- this.equations.push(s);
- s.minForce = -r;
- s.maxForce = r;
- }
- n.prototype = new i();
- n.prototype.update = function() {
- var t = this.bodyA, e = this.bodyB, i = this.distanceEquation, o = .5 * this.distance, n = i.ni;
- e.position.vsub(t.position, n);
- n.normalize();
- n.mult(o, i.ri);
- n.mult(-o, i.rj);
- };
- }, {
- "../equations/ContactEquation": 20,
- "./Constraint": 14
- } ],
- 16: [ function(t, e) {
- e.exports = s;
- t("./Constraint");
- var i = t("./PointToPointConstraint"), o = t("../equations/RotationalEquation"), n = t("../equations/RotationalMotorEquation"), r = (t("../equations/ContactEquation"),
- t("../math/Vec3"));
- function s(t, e, s) {
- var a = "undefined" != typeof (s = s || {}).maxForce ? s.maxForce : 1e6, l = s.pivotA ? s.pivotA.clone() : new r(), h = s.pivotB ? s.pivotB.clone() : new r();
- i.call(this, t, l, e, h, a);
- (this.axisA = s.axisA ? s.axisA.clone() : new r(1, 0, 0)).normalize();
- (this.axisB = s.axisB ? s.axisB.clone() : new r(1, 0, 0)).normalize();
- var c = this.rotationalEquation1 = new o(t, e, s), u = this.rotationalEquation2 = new o(t, e, s), p = this.motorEquation = new n(t, e, a);
- p.enabled = !1;
- this.equations.push(c, u, p);
- }
- s.prototype = new i();
- s.constructor = s;
- s.prototype.enableMotor = function() {
- this.motorEquation.enabled = !0;
- };
- s.prototype.disableMotor = function() {
- this.motorEquation.enabled = !1;
- };
- s.prototype.setMotorSpeed = function(t) {
- this.motorEquation.targetVelocity = t;
- };
- s.prototype.setMotorMaxForce = function(t) {
- this.motorEquation.maxForce = t;
- this.motorEquation.minForce = -t;
- };
- var a = new r(), l = new r();
- s.prototype.update = function() {
- var t = this.bodyA, e = this.bodyB, o = this.motorEquation, n = this.rotationalEquation1, r = this.rotationalEquation2, s = a, h = l, c = this.axisA, u = this.axisB;
- i.prototype.update.call(this);
- t.quaternion.vmult(c, s);
- e.quaternion.vmult(u, h);
- s.tangents(n.axisA, r.axisA);
- n.axisB.copy(h);
- r.axisB.copy(h);
- if (this.motorEquation.enabled) {
- t.quaternion.vmult(this.axisA, o.axisA);
- e.quaternion.vmult(this.axisB, o.axisB);
- }
- };
- }, {
- "../equations/ContactEquation": 20,
- "../equations/RotationalEquation": 23,
- "../equations/RotationalMotorEquation": 24,
- "../math/Vec3": 32,
- "./Constraint": 14,
- "./PointToPointConstraint": 18
- } ],
- 17: [ function(t, e) {
- e.exports = r;
- t("./Constraint");
- var i = t("./PointToPointConstraint"), o = t("../equations/RotationalEquation"), n = (t("../equations/RotationalMotorEquation"),
- t("../equations/ContactEquation"), t("../math/Vec3"));
- function r(t, e, r) {
- var s = "undefined" != typeof (r = r || {}).maxForce ? r.maxForce : 1e6, a = new n(), l = new n(), h = new n();
- t.position.vadd(e.position, h);
- h.scale(.5, h);
- e.pointToLocalFrame(h, l);
- t.pointToLocalFrame(h, a);
- i.call(this, t, a, e, l, s);
- this.xA = t.vectorToLocalFrame(n.UNIT_X);
- this.xB = e.vectorToLocalFrame(n.UNIT_X);
- this.yA = t.vectorToLocalFrame(n.UNIT_Y);
- this.yB = e.vectorToLocalFrame(n.UNIT_Y);
- this.zA = t.vectorToLocalFrame(n.UNIT_Z);
- this.zB = e.vectorToLocalFrame(n.UNIT_Z);
- var c = this.rotationalEquation1 = new o(t, e, r), u = this.rotationalEquation2 = new o(t, e, r), p = this.rotationalEquation3 = new o(t, e, r);
- this.equations.push(c, u, p);
- }
- r.prototype = new i();
- r.constructor = r;
- new n(), new n();
- r.prototype.update = function() {
- var t = this.bodyA, e = this.bodyB, o = (this.motorEquation, this.rotationalEquation1), n = this.rotationalEquation2, r = this.rotationalEquation3;
- i.prototype.update.call(this);
- t.vectorToWorldFrame(this.xA, o.axisA);
- e.vectorToWorldFrame(this.yB, o.axisB);
- t.vectorToWorldFrame(this.yA, n.axisA);
- e.vectorToWorldFrame(this.zB, n.axisB);
- t.vectorToWorldFrame(this.zA, r.axisA);
- e.vectorToWorldFrame(this.xB, r.axisB);
- };
- }, {
- "../equations/ContactEquation": 20,
- "../equations/RotationalEquation": 23,
- "../equations/RotationalMotorEquation": 24,
- "../math/Vec3": 32,
- "./Constraint": 14,
- "./PointToPointConstraint": 18
- } ],
- 18: [ function(t, e) {
- e.exports = r;
- var i = t("./Constraint"), o = t("../equations/ContactEquation"), n = t("../math/Vec3");
- function r(t, e, r, s, a) {
- i.call(this, t, r);
- a = "undefined" != typeof a ? a : 1e6;
- this.pivotA = e ? e.clone() : new n();
- this.pivotB = s ? s.clone() : new n();
- var l = this.equationX = new o(t, r), h = this.equationY = new o(t, r), c = this.equationZ = new o(t, r);
- this.equations.push(l, h, c);
- l.minForce = h.minForce = c.minForce = -a;
- l.maxForce = h.maxForce = c.maxForce = a;
- l.ni.set(1, 0, 0);
- h.ni.set(0, 1, 0);
- c.ni.set(0, 0, 1);
- }
- r.prototype = new i();
- r.prototype.update = function() {
- var t = this.bodyA, e = this.bodyB, i = this.equationX, o = this.equationY, n = this.equationZ;
- t.quaternion.vmult(this.pivotA, i.ri);
- e.quaternion.vmult(this.pivotB, i.rj);
- o.ri.copy(i.ri);
- o.rj.copy(i.rj);
- n.ri.copy(i.ri);
- n.rj.copy(i.rj);
- };
- }, {
- "../equations/ContactEquation": 20,
- "../math/Vec3": 32,
- "./Constraint": 14
- } ],
- 19: [ function(t, e) {
- e.exports = r;
- var i = t("../math/Vec3"), o = (t("../math/Mat3"), t("./Equation")), n = t("../math/CMath");
- function r(t, e, n) {
- var r = "undefined" != typeof (n = n || {}).maxForce ? n.maxForce : 1e6;
- o.call(this, t, e, -r, r);
- this.axisA = n.axisA ? n.axisA.clone() : new i(1, 0, 0);
- this.axisB = n.axisB ? n.axisB.clone() : new i(0, 1, 0);
- this.angle = "undefined" != typeof n.angle ? n.angle : 0;
- }
- r.prototype = new o();
- r.prototype.constructor = r;
- var s = new i(), a = new i();
- r.prototype.computeB = function(t) {
- var e = this.a, i = this.b, o = this.axisA, r = this.axisB, l = s, h = a, c = this.jacobianElementA, u = this.jacobianElementB;
- o.cross(r, l);
- r.cross(o, h);
- c.rotational.copy(h);
- u.rotational.copy(l);
- return -(n.cos(this.angle) - o.dot(r)) * e - this.computeGW() * i - t * this.computeGiMf();
- };
- }, {
- "../math/CMath": 27,
- "../math/Mat3": 29,
- "../math/Vec3": 32,
- "./Equation": 21
- } ],
- 20: [ function(t, e) {
- e.exports = n;
- var i = t("./Equation"), o = t("../math/Vec3");
- t("../math/Mat3");
- function n(t, e, n) {
- n = "undefined" != typeof n ? n : 1e6;
- i.call(this, t, e, 0, n);
- this.si = null;
- this.sj = null;
- this.restitution = 0;
- this.ri = new o();
- this.rj = new o();
- this.ni = new o();
- }
- n.prototype = new i();
- n.prototype.constructor = n;
- var r = new o(), s = new o(), a = new o();
- n.prototype.computeB = function(t) {
- var e = this.a, i = this.b, o = this.bi, n = this.bj, l = this.ri, h = this.rj, c = r, u = s, p = o.velocity, d = o.angularVelocity, y = (o.force,
- o.torque, n.velocity), f = n.angularVelocity, v = (n.force, n.torque, a), m = this.jacobianElementA, g = this.jacobianElementB, b = this.ni;
- l.cross(b, c);
- h.cross(b, u);
- b.negate(m.spatial);
- c.negate(m.rotational);
- g.spatial.copy(b);
- g.rotational.copy(u);
- v.copy(n.position);
- v.vadd(h, v);
- v.vsub(o.position, v);
- v.vsub(l, v);
- var w = b.dot(v), x = this.restitution + 1;
- return -w * e - (x * y.dot(b) - x * p.dot(b) + f.dot(u) - d.dot(c)) * i - t * this.computeGiMf();
- };
- var l = new o(), h = new o(), c = new o(), u = new o(), p = new o();
- n.prototype.getImpactVelocityAlongNormal = function() {
- var t = l, e = h, i = c, o = u, n = p;
- this.bi.position.vadd(this.ri, i);
- this.bj.position.vadd(this.rj, o);
- this.bi.getVelocityAtWorldPoint(i, t);
- this.bj.getVelocityAtWorldPoint(o, e);
- t.vsub(e, n);
- return this.ni.dot(n);
- };
- }, {
- "../math/Mat3": 29,
- "../math/Vec3": 32,
- "./Equation": 21
- } ],
- 21: [ function(t, e) {
- e.exports = n;
- var i = t("../math/JacobianElement"), o = t("../math/Vec3");
- function n(t, e, o, r) {
- this.id = n.id++;
- this.minForce = "undefined" == typeof o ? -1e6 : o;
- this.maxForce = "undefined" == typeof r ? 1e6 : r;
- this.bi = t;
- this.bj = e;
- this.a = 0;
- this.b = 0;
- this.eps = 0;
- this.jacobianElementA = new i();
- this.jacobianElementB = new i();
- this.enabled = !0;
- this.multiplier = 0;
- this.setSpookParams(1e7, 4, 1 / 60);
- }
- n.prototype.constructor = n;
- n.id = 0;
- n.prototype.setSpookParams = function(t, e, i) {
- var o = e, n = t, r = i;
- this.a = 4 / (r * (1 + 4 * o));
- this.b = 4 * o / (1 + 4 * o);
- this.eps = 4 / (r * r * n * (1 + 4 * o));
- };
- n.prototype.computeB = function(t, e, i) {
- var o = this.computeGW();
- return -this.computeGq() * t - o * e - this.computeGiMf() * i;
- };
- n.prototype.computeGq = function() {
- var t = this.jacobianElementA, e = this.jacobianElementB, i = this.bi, o = this.bj, n = i.position, r = o.position;
- return t.spatial.dot(n) + e.spatial.dot(r);
- };
- new o();
- n.prototype.computeGW = function() {
- var t = this.jacobianElementA, e = this.jacobianElementB, i = this.bi, o = this.bj, n = i.velocity, r = o.velocity, s = i.angularVelocity, a = o.angularVelocity;
- return t.multiplyVectors(n, s) + e.multiplyVectors(r, a);
- };
- n.prototype.computeGWlambda = function() {
- var t = this.jacobianElementA, e = this.jacobianElementB, i = this.bi, o = this.bj, n = i.vlambda, r = o.vlambda, s = i.wlambda, a = o.wlambda;
- return t.multiplyVectors(n, s) + e.multiplyVectors(r, a);
- };
- var r = new o(), s = new o(), a = new o(), l = new o();
- n.prototype.computeGiMf = function() {
- var t = this.jacobianElementA, e = this.jacobianElementB, i = this.bi, o = this.bj, n = i.force, h = i.torque, c = o.force, u = o.torque, p = i.invMassSolve, d = o.invMassSolve;
- n.scale(p, r);
- c.scale(d, s);
- i.invInertiaWorldSolve.vmult(h, a);
- o.invInertiaWorldSolve.vmult(u, l);
- return t.multiplyVectors(r, a) + e.multiplyVectors(s, l);
- };
- var h = new o();
- n.prototype.computeGiMGt = function() {
- var t = this.jacobianElementA, e = this.jacobianElementB, i = this.bi, o = this.bj, n = i.invMassSolve, r = o.invMassSolve, s = i.invInertiaWorldSolve, a = o.invInertiaWorldSolve, l = n + r;
- s.vmult(t.rotational, h);
- l += h.dot(t.rotational);
- a.vmult(e.rotational, h);
- return l + h.dot(e.rotational);
- };
- var c = new o();
- new o(), new o(), new o(), new o(), new o();
- n.prototype.addToWlambda = function(t) {
- var e = this.jacobianElementA, i = this.jacobianElementB, o = this.bi, n = this.bj, r = c;
- o.vlambda.addScaledVector(o.invMassSolve * t, e.spatial, o.vlambda);
- n.vlambda.addScaledVector(n.invMassSolve * t, i.spatial, n.vlambda);
- o.invInertiaWorldSolve.vmult(e.rotational, r);
- o.wlambda.addScaledVector(t, r, o.wlambda);
- n.invInertiaWorldSolve.vmult(i.rotational, r);
- n.wlambda.addScaledVector(t, r, n.wlambda);
- };
- n.prototype.computeC = function() {
- return this.computeGiMGt() + this.eps;
- };
- }, {
- "../math/JacobianElement": 28,
- "../math/Vec3": 32
- } ],
- 22: [ function(t, e) {
- e.exports = n;
- var i = t("./Equation"), o = t("../math/Vec3");
- t("../math/Mat3");
- function n(t, e, n) {
- i.call(this, t, e, -n, n);
- this.ri = new o();
- this.rj = new o();
- this.t = new o();
- }
- n.prototype = new i();
- n.prototype.constructor = n;
- var r = new o(), s = new o();
- n.prototype.computeB = function(t) {
- this.a;
- var e = this.b, i = (this.bi, this.bj, this.ri), o = this.rj, n = r, a = s, l = this.t;
- i.cross(l, n);
- o.cross(l, a);
- var h = this.jacobianElementA, c = this.jacobianElementB;
- l.negate(h.spatial);
- n.negate(h.rotational);
- c.spatial.copy(l);
- c.rotational.copy(a);
- return -this.computeGW() * e - t * this.computeGiMf();
- };
- }, {
- "../math/Mat3": 29,
- "../math/Vec3": 32,
- "./Equation": 21
- } ],
- 23: [ function(t, e) {
- e.exports = r;
- var i = t("../math/Vec3"), o = (t("../math/Mat3"), t("./Equation")), n = t("../math/CMath");
- function r(t, e, n) {
- var r = "undefined" != typeof (n = n || {}).maxForce ? n.maxForce : 1e6;
- o.call(this, t, e, -r, r);
- this.axisA = n.axisA ? n.axisA.clone() : new i(1, 0, 0);
- this.axisB = n.axisB ? n.axisB.clone() : new i(0, 1, 0);
- this.maxAngle = Math.PI / 2;
- }
- r.prototype = new o();
- r.prototype.constructor = r;
- var s = new i(), a = new i();
- r.prototype.computeB = function(t) {
- var e = this.a, i = this.b, o = this.axisA, r = this.axisB, l = s, h = a, c = this.jacobianElementA, u = this.jacobianElementB;
- o.cross(r, l);
- r.cross(o, h);
- c.rotational.copy(h);
- u.rotational.copy(l);
- return -(n.cos(this.maxAngle) - o.dot(r)) * e - this.computeGW() * i - t * this.computeGiMf();
- };
- }, {
- "../math/CMath": 27,
- "../math/Mat3": 29,
- "../math/Vec3": 32,
- "./Equation": 21
- } ],
- 24: [ function(t, e) {
- e.exports = n;
- var i = t("../math/Vec3"), o = (t("../math/Mat3"), t("./Equation"));
- function n(t, e, n) {
- n = "undefined" != typeof n ? n : 1e6;
- o.call(this, t, e, -n, n);
- this.axisA = new i();
- this.axisB = new i();
- this.targetVelocity = 0;
- }
- n.prototype = new o();
- n.prototype.constructor = n;
- n.prototype.computeB = function(t) {
- this.a;
- var e = this.b, i = (this.bi, this.bj, this.axisA), o = this.axisB, n = this.jacobianElementA, r = this.jacobianElementB;
- n.rotational.copy(i);
- o.negate(r.rotational);
- return -(this.computeGW() - this.targetVelocity) * e - t * this.computeGiMf();
- };
- }, {
- "../math/Mat3": 29,
- "../math/Vec3": 32,
- "./Equation": 21
- } ],
- 25: [ function(t, e) {
- var i = t("../utils/Utils");
- e.exports = o;
- function o(t, e, n) {
- n = i.defaults(n, {
- friction: .3,
- restitution: .3,
- contactEquationStiffness: 1e7,
- contactEquationRelaxation: 3,
- frictionEquationStiffness: 1e7,
- frictionEquationRelaxation: 3
- });
- this.id = o.idCounter++;
- this.materials = [ t, e ];
- this.friction = n.friction;
- this.restitution = n.restitution;
- this.contactEquationStiffness = n.contactEquationStiffness;
- this.contactEquationRelaxation = n.contactEquationRelaxation;
- this.frictionEquationStiffness = n.frictionEquationStiffness;
- this.frictionEquationRelaxation = n.frictionEquationRelaxation;
- }
- o.idCounter = 0;
- }, {
- "../utils/Utils": 55
- } ],
- 26: [ function(t, e) {
- e.exports = i;
- function i(t) {
- var e = "";
- if ("string" == typeof (t = t || {})) {
- e = t;
- t = {};
- } else "object" == typeof t && (e = "");
- this.name = e;
- this.id = i.idCounter++;
- this.friction = "undefined" != typeof t.friction ? t.friction : -1;
- this.restitution = "undefined" != typeof t.restitution ? t.restitution : -1;
- }
- i.idCounter = 0;
- }, {} ],
- 27: [ function(t, e) {
- var i = 180 / Math.PI;
- function o(t) {
- return t * i;
- }
- var n = {};
- function r(t) {
- if (n.digit != t) {
- for (var e = 1 / Math.pow(10, t), o = 0; o <= 90; o += e) n[o.toFixed(t)] = Math.sin(o / i);
- n.digit = t;
- }
- }
- function s(t, e) {
- return t <= 90 ? n[t.toFixed(e)] : t <= 180 ? n[(t = 180 - t).toFixed(e)] : t <= 270 ? -n[(t -= 180).toFixed(e)] : -n[(t = 360 - t).toFixed(e)];
- }
- function a(t) {
- var e = o(t) % 360;
- e < 0 && (e += 360);
- return s(e, u._digit);
- }
- function l(t) {
- var e = (o(t) + 90) % 360;
- e < 0 && (e += 360);
- return s(e, u._digit);
- }
- function h(t) {
- return Math.sin(t).toFixed(u.digit);
- }
- function c(t) {
- return Math.cos(t).toFixed(u.digit);
- }
- var u = {
- sin: Math.sin,
- cos: Math.cos,
- atan2: Math.atan2
- };
- u._sin = a;
- u._cos = l;
- u._sinArr = n;
- u._sin360 = s;
- u._sinNative = h;
- u._cosNative = c;
- u._radian2angle = o;
- u._calculateSinByDigit = r;
- u._digit = 1;
- Object.defineProperty(u, "digit", {
- get: function() {
- return this._digit;
- },
- set: function(t) {
- this._digit = t;
- 1 == this._mode && r(t);
- }
- });
- u._mode = 0;
- Object.defineProperty(u, "mode", {
- get: function() {
- return this._mode;
- },
- set: function(t) {
- if (this._mode != t) {
- this._mode = t;
- if (0 == t) {
- u.sin = Math.sin;
- u.cos = Math.cos;
- } else if (1 == t) {
- u.digit = u._digit;
- u.sin = a;
- u.cos = l;
- } else if (2 == t) {
- u.sin = h;
- u.cos = c;
- }
- }
- }
- });
- e.exports = u;
- }, {} ],
- 28: [ function(t, e) {
- e.exports = o;
- var i = t("./Vec3");
- function o() {
- this.spatial = new i();
- this.rotational = new i();
- }
- o.prototype.multiplyElement = function(t) {
- return t.spatial.dot(this.spatial) + t.rotational.dot(this.rotational);
- };
- o.prototype.multiplyVectors = function(t, e) {
- return t.dot(this.spatial) + e.dot(this.rotational);
- };
- }, {
- "./Vec3": 32
- } ],
- 29: [ function(t, e) {
- e.exports = o;
- var i = t("./Vec3");
- function o(t) {
- this.elements = t || [ 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
- }
- o.prototype.identity = function() {
- var t = this.elements;
- t[0] = 1;
- t[1] = 0;
- t[2] = 0;
- t[3] = 0;
- t[4] = 1;
- t[5] = 0;
- t[6] = 0;
- t[7] = 0;
- t[8] = 1;
- };
- o.prototype.setZero = function() {
- var t = this.elements;
- t[0] = 0;
- t[1] = 0;
- t[2] = 0;
- t[3] = 0;
- t[4] = 0;
- t[5] = 0;
- t[6] = 0;
- t[7] = 0;
- t[8] = 0;
- };
- o.prototype.setTrace = function(t) {
- var e = this.elements;
- e[0] = t.x;
- e[4] = t.y;
- e[8] = t.z;
- };
- o.prototype.getTrace = function(t) {
- t = t || new i();
- var e = this.elements;
- t.x = e[0];
- t.y = e[4];
- t.z = e[8];
- };
- o.prototype.vmult = function(t, e) {
- e = e || new i();
- var o = this.elements, n = t.x, r = t.y, s = t.z;
- e.x = o[0] * n + o[1] * r + o[2] * s;
- e.y = o[3] * n + o[4] * r + o[5] * s;
- e.z = o[6] * n + o[7] * r + o[8] * s;
- return e;
- };
- o.prototype.smult = function(t) {
- for (var e = 0; e < this.elements.length; e++) this.elements[e] *= t;
- };
- o.prototype.mmult = function(t, e) {
- for (var i = e || new o(), n = 0; n < 3; n++) for (var r = 0; r < 3; r++) {
- for (var s = 0, a = 0; a < 3; a++) s += t.elements[n + 3 * a] * this.elements[a + 3 * r];
- i.elements[n + 3 * r] = s;
- }
- return i;
- };
- o.prototype.scale = function(t, e) {
- e = e || new o();
- for (var i = this.elements, n = e.elements, r = 0; 3 !== r; r++) {
- n[3 * r + 0] = t.x * i[3 * r + 0];
- n[3 * r + 1] = t.y * i[3 * r + 1];
- n[3 * r + 2] = t.z * i[3 * r + 2];
- }
- return e;
- };
- o.prototype.solve = function(t, e) {
- e = e || new i();
- for (var o, n = [], r = 0; r < 12; r++) n.push(0);
- for (r = 0; r < 3; r++) for (o = 0; o < 3; o++) n[r + 4 * o] = this.elements[r + 3 * o];
- n[3] = t.x;
- n[7] = t.y;
- n[11] = t.z;
- var s, a, l = 3, h = l;
- do {
- if (0 === n[(r = h - l) + 4 * r]) for (o = r + 1; o < h; o++) if (0 !== n[r + 4 * o]) {
- s = 4;
- do {
- n[(a = 4 - s) + 4 * r] += n[a + 4 * o];
- } while (--s);
- break;
- }
- if (0 !== n[r + 4 * r]) for (o = r + 1; o < h; o++) {
- var c = n[r + 4 * o] / n[r + 4 * r];
- s = 4;
- do {
- n[(a = 4 - s) + 4 * o] = a <= r ? 0 : n[a + 4 * o] - n[a + 4 * r] * c;
- } while (--s);
- }
- } while (--l);
- e.z = n[11] / n[10];
- e.y = (n[7] - n[6] * e.z) / n[5];
- e.x = (n[3] - n[2] * e.z - n[1] * e.y) / n[0];
- if (isNaN(e.x) || isNaN(e.y) || isNaN(e.z) || Infinity === e.x || Infinity === e.y || Infinity === e.z) throw "Could not solve equation! Got x=[" + e.toString() + "], b=[" + t.toString() + "], A=[" + this.toString() + "]";
- return e;
- };
- o.prototype.e = function(t, e, i) {
- if (void 0 === i) return this.elements[e + 3 * t];
- this.elements[e + 3 * t] = i;
- };
- o.prototype.copy = function(t) {
- for (var e = 0; e < t.elements.length; e++) this.elements[e] = t.elements[e];
- return this;
- };
- o.prototype.toString = function() {
- for (var t = "", e = 0; e < 9; e++) t += this.elements[e] + ",";
- return t;
- };
- o.prototype.reverse = function(t) {
- t = t || new o();
- for (var e, i = [], n = 0; n < 18; n++) i.push(0);
- for (n = 0; n < 3; n++) for (e = 0; e < 3; e++) i[n + 6 * e] = this.elements[n + 3 * e];
- i[3] = 1;
- i[9] = 0;
- i[15] = 0;
- i[4] = 0;
- i[10] = 1;
- i[16] = 0;
- i[5] = 0;
- i[11] = 0;
- i[17] = 1;
- var r, s, a = 3, l = a;
- do {
- if (0 === i[(n = l - a) + 6 * n]) for (e = n + 1; e < l; e++) if (0 !== i[n + 6 * e]) {
- r = 6;
- do {
- i[(s = 6 - r) + 6 * n] += i[s + 6 * e];
- } while (--r);
- break;
- }
- if (0 !== i[n + 6 * n]) for (e = n + 1; e < l; e++) {
- var h = i[n + 6 * e] / i[n + 6 * n];
- r = 6;
- do {
- i[(s = 6 - r) + 6 * e] = s <= n ? 0 : i[s + 6 * e] - i[s + 6 * n] * h;
- } while (--r);
- }
- } while (--a);
- n = 2;
- do {
- e = n - 1;
- do {
- h = i[n + 6 * e] / i[n + 6 * n];
- r = 6;
- do {
- i[(s = 6 - r) + 6 * e] = i[s + 6 * e] - i[s + 6 * n] * h;
- } while (--r);
- } while (e--);
- } while (--n);
- n = 2;
- do {
- h = 1 / i[n + 6 * n];
- r = 6;
- do {
- i[(s = 6 - r) + 6 * n] = i[s + 6 * n] * h;
- } while (--r);
- } while (n--);
- n = 2;
- do {
- e = 2;
- do {
- s = i[3 + e + 6 * n];
- if (isNaN(s) || Infinity === s) throw "Could not reverse! A=[" + this.toString() + "]";
- t.e(n, e, s);
- } while (e--);
- } while (n--);
- return t;
- };
- o.prototype.setRotationFromQuaternion = function(t) {
- var e = t.x, i = t.y, o = t.z, n = t.w, r = e + e, s = i + i, a = o + o, l = e * r, h = e * s, c = e * a, u = i * s, p = i * a, d = o * a, y = n * r, f = n * s, v = n * a, m = this.elements;
- m[0] = 1 - (u + d);
- m[1] = h - v;
- m[2] = c + f;
- m[3] = h + v;
- m[4] = 1 - (l + d);
- m[5] = p - y;
- m[6] = c - f;
- m[7] = p + y;
- m[8] = 1 - (l + u);
- return this;
- };
- o.prototype.transpose = function(t) {
- for (var e = (t = t || new o()).elements, i = this.elements, n = 0; 3 !== n; n++) for (var r = 0; 3 !== r; r++) e[3 * n + r] = i[3 * r + n];
- return t;
- };
- }, {
- "./Vec3": 32
- } ],
- 30: [ function(t, e) {
- e.exports = n;
- var i = t("./Vec3"), o = t("./CMath");
- function n(t, e, i, o) {
- this.x = void 0 !== t ? t : 0;
- this.y = void 0 !== e ? e : 0;
- this.z = void 0 !== i ? i : 0;
- this.w = void 0 !== o ? o : 1;
- }
- n.prototype.set = function(t, e, i, o) {
- this.x = t;
- this.y = e;
- this.z = i;
- this.w = o;
- return this;
- };
- n.prototype.toString = function() {
- return this.x + "," + this.y + "," + this.z + "," + this.w;
- };
- n.prototype.toArray = function() {
- return [ this.x, this.y, this.z, this.w ];
- };
- n.prototype.setFromAxisAngle = function(t, e) {
- var i = o.sin(.5 * e);
- this.x = t.x * i;
- this.y = t.y * i;
- this.z = t.z * i;
- this.w = o.cos(.5 * e);
- return this;
- };
- n.prototype.toAxisAngle = function(t) {
- t = t || new i();
- this.normalize();
- var e = 2 * Math.acos(this.w), o = Math.sqrt(1 - this.w * this.w);
- if (o < .001) {
- t.x = this.x;
- t.y = this.y;
- t.z = this.z;
- } else {
- t.x = this.x / o;
- t.y = this.y / o;
- t.z = this.z / o;
- }
- return [ t, e ];
- };
- var r = new i(), s = new i();
- n.prototype.setFromVectors = function(t, e) {
- if (t.isAntiparallelTo(e)) {
- var i = r, o = s;
- t.tangents(i, o);
- this.setFromAxisAngle(i, Math.PI);
- } else {
- var n = t.cross(e);
- this.x = n.x;
- this.y = n.y;
- this.z = n.z;
- this.w = Math.sqrt(Math.pow(t.norm(), 2) * Math.pow(e.norm(), 2)) + t.dot(e);
- this.normalize();
- }
- return this;
- };
- new i(), new i(), new i();
- n.prototype.mult = function(t, e) {
- e = e || new n();
- var i = this.x, o = this.y, r = this.z, s = this.w, a = t.x, l = t.y, h = t.z, c = t.w;
- e.x = i * c + s * a + o * h - r * l;
- e.y = o * c + s * l + r * a - i * h;
- e.z = r * c + s * h + i * l - o * a;
- e.w = s * c - i * a - o * l - r * h;
- return e;
- };
- n.prototype.inverse = function(t) {
- var e = this.x, i = this.y, o = this.z, r = this.w;
- t = t || new n();
- this.conjugate(t);
- var s = 1 / (e * e + i * i + o * o + r * r);
- t.x *= s;
- t.y *= s;
- t.z *= s;
- t.w *= s;
- return t;
- };
- n.prototype.conjugate = function(t) {
- (t = t || new n()).x = -this.x;
- t.y = -this.y;
- t.z = -this.z;
- t.w = this.w;
- return t;
- };
- n.prototype.normalize = function() {
- var t = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
- if (0 === t) {
- this.x = 0;
- this.y = 0;
- this.z = 0;
- this.w = 0;
- } else {
- t = 1 / t;
- this.x *= t;
- this.y *= t;
- this.z *= t;
- this.w *= t;
- }
- return this;
- };
- n.prototype.normalizeFast = function() {
- var t = (3 - (this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w)) / 2;
- if (0 === t) {
- this.x = 0;
- this.y = 0;
- this.z = 0;
- this.w = 0;
- } else {
- this.x *= t;
- this.y *= t;
- this.z *= t;
- this.w *= t;
- }
- return this;
- };
- n.prototype.vmult = function(t, e) {
- e = e || new i();
- var o = t.x, n = t.y, r = t.z, s = this.x, a = this.y, l = this.z, h = this.w, c = h * o + a * r - l * n, u = h * n + l * o - s * r, p = h * r + s * n - a * o, d = -s * o - a * n - l * r;
- e.x = c * h + d * -s + u * -l - p * -a;
- e.y = u * h + d * -a + p * -s - c * -l;
- e.z = p * h + d * -l + c * -a - u * -s;
- return e;
- };
- n.prototype.copy = function(t) {
- this.x = t.x;
- this.y = t.y;
- this.z = t.z;
- this.w = t.w;
- return this;
- };
- n.prototype.toEuler = function(t, e) {
- e = e || "YZX";
- var i, n, r, s = this.x, a = this.y, l = this.z, h = this.w;
- switch (e) {
- case "YZX":
- var c = s * a + l * h;
- if (c > .499) {
- i = 2 * o.atan2(s, h);
- n = Math.PI / 2;
- r = 0;
- }
- if (c < -.499) {
- i = -2 * o.atan2(s, h);
- n = -Math.PI / 2;
- r = 0;
- }
- if (isNaN(i)) {
- var u = s * s, p = a * a, d = l * l;
- i = o.atan2(2 * a * h - 2 * s * l, 1 - 2 * p - 2 * d);
- n = Math.asin(2 * c);
- r = o.atan2(2 * s * h - 2 * a * l, 1 - 2 * u - 2 * d);
- }
- break;
- default:
- throw new Error("Euler order " + e + " not supported yet.");
- }
- t.y = i;
- t.z = n;
- t.x = r;
- };
- n.prototype.setFromEuler = function(t, e, i, n) {
- n = n || "XYZ";
- var r = o.cos(t / 2), s = o.cos(e / 2), a = o.cos(i / 2), l = o.sin(t / 2), h = o.sin(e / 2), c = o.sin(i / 2);
- if ("XYZ" === n) {
- this.x = l * s * a + r * h * c;
- this.y = r * h * a - l * s * c;
- this.z = r * s * c + l * h * a;
- this.w = r * s * a - l * h * c;
- } else if ("YXZ" === n) {
- this.x = l * s * a + r * h * c;
- this.y = r * h * a - l * s * c;
- this.z = r * s * c - l * h * a;
- this.w = r * s * a + l * h * c;
- } else if ("ZXY" === n) {
- this.x = l * s * a - r * h * c;
- this.y = r * h * a + l * s * c;
- this.z = r * s * c + l * h * a;
- this.w = r * s * a - l * h * c;
- } else if ("ZYX" === n) {
- this.x = l * s * a - r * h * c;
- this.y = r * h * a + l * s * c;
- this.z = r * s * c - l * h * a;
- this.w = r * s * a + l * h * c;
- } else if ("YZX" === n) {
- this.x = l * s * a + r * h * c;
- this.y = r * h * a + l * s * c;
- this.z = r * s * c - l * h * a;
- this.w = r * s * a - l * h * c;
- } else if ("XZY" === n) {
- this.x = l * s * a - r * h * c;
- this.y = r * h * a - l * s * c;
- this.z = r * s * c + l * h * a;
- this.w = r * s * a + l * h * c;
- }
- return this;
- };
- n.prototype.clone = function() {
- return new n(this.x, this.y, this.z, this.w);
- };
- n.prototype.slerp = function(t, e, i) {
- i = i || new n();
- var r, s, a, l, h, c = this.x, u = this.y, p = this.z, d = this.w, y = t.x, f = t.y, v = t.z, m = t.w;
- if ((s = c * y + u * f + p * v + d * m) < 0) {
- s = -s;
- y = -y;
- f = -f;
- v = -v;
- m = -m;
- }
- if (1 - s > 1e-6) {
- r = Math.acos(s);
- a = o.sin(r);
- l = o.sin((1 - e) * r) / a;
- h = o.sin(e * r) / a;
- } else {
- l = 1 - e;
- h = e;
- }
- i.x = l * c + h * y;
- i.y = l * u + h * f;
- i.z = l * p + h * v;
- i.w = l * d + h * m;
- return i;
- };
- n.prototype.integrate = function(t, e, i, o) {
- o = o || new n();
- var r = t.x * i.x, s = t.y * i.y, a = t.z * i.z, l = this.x, h = this.y, c = this.z, u = this.w, p = .5 * e;
- o.x += p * (r * u + s * c - a * h);
- o.y += p * (s * u + a * l - r * c);
- o.z += p * (a * u + r * h - s * l);
- o.w += p * (-r * l - s * h - a * c);
- return o;
- };
- }, {
- "./CMath": 27,
- "./Vec3": 32
- } ],
- 31: [ function(t, e) {
- var i = t("./Vec3"), o = t("./Quaternion");
- e.exports = n;
- function n(t) {
- t = t || {};
- this.position = new i();
- t.position && this.position.copy(t.position);
- this.quaternion = new o();
- t.quaternion && this.quaternion.copy(t.quaternion);
- }
- var r = new o();
- n.pointToLocalFrame = function(t, e, o, n) {
- n = n || new i();
- o.vsub(t, n);
- e.conjugate(r);
- r.vmult(n, n);
- return n;
- };
- n.prototype.pointToLocal = function(t, e) {
- return n.pointToLocalFrame(this.position, this.quaternion, t, e);
- };
- n.pointToWorldFrame = function(t, e, o, n) {
- n = n || new i();
- e.vmult(o, n);
- n.vadd(t, n);
- return n;
- };
- n.prototype.pointToWorld = function(t, e) {
- return n.pointToWorldFrame(this.position, this.quaternion, t, e);
- };
- n.prototype.vectorToWorldFrame = function(t, e) {
- e = e || new i();
- this.quaternion.vmult(t, e);
- return e;
- };
- n.vectorToWorldFrame = function(t, e, i) {
- t.vmult(e, i);
- return i;
- };
- n.vectorToLocalFrame = function(t, e, o, n) {
- n = n || new i();
- e.w *= -1;
- e.vmult(o, n);
- e.w *= -1;
- return n;
- };
- }, {
- "./Quaternion": 30,
- "./Vec3": 32
- } ],
- 32: [ function(t, e) {
- e.exports = o;
- var i = t("./Mat3");
- function o(t, e, i) {
- this.x = t || 0;
- this.y = e || 0;
- this.z = i || 0;
- }
- o.ZERO = new o(0, 0, 0);
- o.UNIT_X = new o(1, 0, 0);
- o.UNIT_Y = new o(0, 1, 0);
- o.UNIT_Z = new o(0, 0, 1);
- o.prototype.cross = function(t, e) {
- var i = t.x, n = t.y, r = t.z, s = this.x, a = this.y, l = this.z;
- (e = e || new o()).x = a * r - l * n;
- e.y = l * i - s * r;
- e.z = s * n - a * i;
- return e;
- };
- o.prototype.set = function(t, e, i) {
- this.x = t;
- this.y = e;
- this.z = i;
- return this;
- };
- o.prototype.setZero = function() {
- this.x = this.y = this.z = 0;
- };
- o.prototype.vadd = function(t, e) {
- if (!e) return new o(this.x + t.x, this.y + t.y, this.z + t.z);
- e.x = t.x + this.x;
- e.y = t.y + this.y;
- e.z = t.z + this.z;
- };
- o.prototype.vsub = function(t, e) {
- if (!e) return new o(this.x - t.x, this.y - t.y, this.z - t.z);
- e.x = this.x - t.x;
- e.y = this.y - t.y;
- e.z = this.z - t.z;
- };
- o.prototype.crossmat = function() {
- return new i([ 0, -this.z, this.y, this.z, 0, -this.x, -this.y, this.x, 0 ]);
- };
- o.prototype.normalize = function() {
- var t = this.x, e = this.y, i = this.z, o = Math.sqrt(t * t + e * e + i * i);
- if (o > 0) {
- var n = 1 / o;
- this.x *= n;
- this.y *= n;
- this.z *= n;
- } else {
- this.x = 0;
- this.y = 0;
- this.z = 0;
- }
- return o;
- };
- o.prototype.unit = function(t) {
- t = t || new o();
- var e = this.x, i = this.y, n = this.z, r = Math.sqrt(e * e + i * i + n * n);
- if (r > 0) {
- r = 1 / r;
- t.x = e * r;
- t.y = i * r;
- t.z = n * r;
- } else {
- t.x = 1;
- t.y = 0;
- t.z = 0;
- }
- return t;
- };
- o.prototype.norm = function() {
- var t = this.x, e = this.y, i = this.z;
- return Math.sqrt(t * t + e * e + i * i);
- };
- o.prototype.length = o.prototype.norm;
- o.prototype.norm2 = function() {
- return this.dot(this);
- };
- o.prototype.lengthSquared = o.prototype.norm2;
- o.prototype.distanceTo = function(t) {
- var e = this.x, i = this.y, o = this.z, n = t.x, r = t.y, s = t.z;
- return Math.sqrt((n - e) * (n - e) + (r - i) * (r - i) + (s - o) * (s - o));
- };
- o.prototype.distanceSquared = function(t) {
- var e = this.x, i = this.y, o = this.z, n = t.x, r = t.y, s = t.z;
- return (n - e) * (n - e) + (r - i) * (r - i) + (s - o) * (s - o);
- };
- o.prototype.mult = function(t, e) {
- e = e || new o();
- var i = this.x, n = this.y, r = this.z;
- e.x = t * i;
- e.y = t * n;
- e.z = t * r;
- return e;
- };
- o.prototype.vmul = function(t, e) {
- (e = e || new o()).x = t.x * this.x;
- e.y = t.y * this.y;
- e.z = t.z * this.z;
- return e;
- };
- o.prototype.scale = o.prototype.mult;
- o.prototype.addScaledVector = function(t, e, i) {
- (i = i || new o()).x = this.x + t * e.x;
- i.y = this.y + t * e.y;
- i.z = this.z + t * e.z;
- return i;
- };
- o.prototype.dot = function(t) {
- return this.x * t.x + this.y * t.y + this.z * t.z;
- };
- o.prototype.isZero = function() {
- return 0 === this.x && 0 === this.y && 0 === this.z;
- };
- o.prototype.negate = function(t) {
- (t = t || new o()).x = -this.x;
- t.y = -this.y;
- t.z = -this.z;
- return t;
- };
- var n = new o(), r = new o();
- o.prototype.tangents = function(t, e) {
- var i = this.norm();
- if (i > 0) {
- var o = n, s = 1 / i;
- o.set(this.x * s, this.y * s, this.z * s);
- var a = r;
- if (Math.abs(o.x) < .9) {
- a.set(1, 0, 0);
- o.cross(a, t);
- } else {
- a.set(0, 1, 0);
- o.cross(a, t);
- }
- o.cross(t, e);
- } else {
- t.set(1, 0, 0);
- e.set(0, 1, 0);
- }
- };
- o.prototype.toString = function() {
- return this.x + "," + this.y + "," + this.z;
- };
- o.prototype.toArray = function() {
- return [ this.x, this.y, this.z ];
- };
- o.prototype.copy = function(t) {
- this.x = t.x;
- this.y = t.y;
- this.z = t.z;
- return this;
- };
- o.prototype.lerp = function(t, e, i) {
- var o = this.x, n = this.y, r = this.z;
- i.x = o + (t.x - o) * e;
- i.y = n + (t.y - n) * e;
- i.z = r + (t.z - r) * e;
- };
- o.prototype.almostEquals = function(t, e) {
- void 0 === e && (e = 1e-6);
- return !(Math.abs(this.x - t.x) > e || Math.abs(this.y - t.y) > e || Math.abs(this.z - t.z) > e);
- };
- o.prototype.almostZero = function(t) {
- void 0 === t && (t = 1e-6);
- return !(Math.abs(this.x) > t || Math.abs(this.y) > t || Math.abs(this.z) > t);
- };
- var s = new o();
- o.prototype.isAntiparallelTo = function(t, e) {
- this.negate(s);
- return s.almostEquals(t, e);
- };
- o.prototype.clone = function() {
- return new o(this.x, this.y, this.z);
- };
- }, {
- "./Mat3": 29
- } ],
- 33: [ function(t, e) {
- e.exports = h;
- var i = t("../utils/EventTarget"), o = (t("../shapes/Shape"), t("../math/Vec3")), n = t("../math/Mat3"), r = t("../math/Quaternion"), s = (t("../material/Material"),
- t("../collision/AABB")), a = t("../shapes/Box"), l = t("../world/World");
- function h(t) {
- t = t || {};
- i.apply(this);
- this.id = h.idCounter++;
- this.world = null;
- this.preStep = null;
- this.postStep = null;
- this.vlambda = new o();
- this.collisionFilterGroup = "number" == typeof t.collisionFilterGroup ? t.collisionFilterGroup : 1;
- this.collisionFilterMask = "number" == typeof t.collisionFilterMask ? t.collisionFilterMask : -1;
- this.collisionResponse = !0;
- this.position = new o();
- this.previousPosition = new o();
- this.interpolatedPosition = new o();
- this.initPosition = new o();
- if (t.position) {
- this.position.copy(t.position);
- this.previousPosition.copy(t.position);
- this.interpolatedPosition.copy(t.position);
- this.initPosition.copy(t.position);
- }
- this.velocity = new o();
- t.velocity && this.velocity.copy(t.velocity);
- this.initVelocity = new o();
- this.force = new o();
- var e = "number" == typeof t.mass ? t.mass : 0;
- this.mass = e;
- this.invMass = e > 0 ? 1 / e : 0;
- this.material = t.material || null;
- this.linearDamping = "number" == typeof t.linearDamping ? t.linearDamping : .01;
- this.type = e <= 0 ? h.STATIC : h.DYNAMIC;
- typeof t.type == typeof h.STATIC && (this.type = t.type);
- this.allowSleep = "undefined" == typeof t.allowSleep || t.allowSleep;
- this.sleepState = 0;
- this.sleepSpeedLimit = "undefined" != typeof t.sleepSpeedLimit ? t.sleepSpeedLimit : .1;
- this.sleepTimeLimit = "undefined" != typeof t.sleepTimeLimit ? t.sleepTimeLimit : 1;
- this.timeLastSleepy = 0;
- this._wakeUpAfterNarrowphase = !1;
- this.torque = new o();
- this.quaternion = new r();
- this.initQuaternion = new r();
- this.previousQuaternion = new r();
- this.interpolatedQuaternion = new r();
- if (t.quaternion) {
- this.quaternion.copy(t.quaternion);
- this.initQuaternion.copy(t.quaternion);
- this.previousQuaternion.copy(t.quaternion);
- this.interpolatedQuaternion.copy(t.quaternion);
- }
- this.angularVelocity = new o();
- t.angularVelocity && this.angularVelocity.copy(t.angularVelocity);
- this.initAngularVelocity = new o();
- this.shapes = [];
- this.shapeOffsets = [];
- this.shapeOrientations = [];
- this.inertia = new o();
- this.invInertia = new o();
- this.invInertiaWorld = new n();
- this.invMassSolve = 0;
- this.invInertiaSolve = new o();
- this.invInertiaWorldSolve = new n();
- this.fixedRotation = "undefined" != typeof t.fixedRotation && t.fixedRotation;
- this.useGravity = !0;
- this.angularDamping = "undefined" != typeof t.angularDamping ? t.angularDamping : .01;
- this.linearFactor = new o(1, 1, 1);
- t.linearFactor && this.linearFactor.copy(t.linearFactor);
- this.angularFactor = new o(1, 1, 1);
- t.angularFactor && this.angularFactor.copy(t.angularFactor);
- this.aabb = new s();
- this.aabbNeedsUpdate = !0;
- this.boundingRadius = 0;
- this.wlambda = new o();
- t.shape && this.addShape(t.shape);
- this.hasTrigger = !0;
- this.updateMassProperties();
- }
- h.prototype = new i();
- h.prototype.constructor = h;
- h.COLLIDE_EVENT_NAME = "collide";
- h.DYNAMIC = 1;
- h.STATIC = 2;
- h.KINEMATIC = 4;
- h.AWAKE = 0;
- h.SLEEPY = 1;
- h.SLEEPING = 2;
- h.idCounter = 0;
- h.wakeupEvent = {
- type: "wakeup"
- };
- h.prototype.wakeUp = function() {
- l.SLEEPING = !1;
- var t = this.sleepState;
- this.sleepState = 0;
- this._wakeUpAfterNarrowphase = !1;
- t === h.SLEEPING && this.dispatchEvent(h.wakeupEvent);
- };
- h.prototype.sleep = function() {
- this.sleepState = h.SLEEPING;
- this.velocity.set(0, 0, 0);
- this.angularVelocity.set(0, 0, 0);
- this._wakeUpAfterNarrowphase = !1;
- };
- h.sleepyEvent = {
- type: "sleepy"
- };
- h.sleepEvent = {
- type: "sleep"
- };
- h.prototype.sleepTick = function(t) {
- if (this.allowSleep) {
- var e = this.sleepState, i = this.velocity.norm2() + this.angularVelocity.norm2(), o = Math.pow(this.sleepSpeedLimit, 2);
- if (e === h.AWAKE && i < o) {
- this.sleepState = h.SLEEPY;
- this.timeLastSleepy = t;
- this.dispatchEvent(h.sleepyEvent);
- } else if (e === h.SLEEPY && i > o) this.wakeUp(); else if (e === h.SLEEPY && t - this.timeLastSleepy > this.sleepTimeLimit) {
- this.sleep();
- this.dispatchEvent(h.sleepEvent);
- }
- }
- };
- h.prototype.updateSolveMassProperties = function() {
- if (this.sleepState === h.SLEEPING || this.type === h.KINEMATIC) {
- this.invMassSolve = 0;
- this.invInertiaSolve.setZero();
- this.invInertiaWorldSolve.setZero();
- } else {
- this.invMassSolve = this.invMass;
- this.invInertiaSolve.copy(this.invInertia);
- this.invInertiaWorldSolve.copy(this.invInertiaWorld);
- }
- };
- h.prototype.pointToLocalFrame = function(t, e) {
- e = e || new o();
- t.vsub(this.position, e);
- this.quaternion.conjugate().vmult(e, e);
- return e;
- };
- h.prototype.vectorToLocalFrame = function(t, e) {
- e = e || new o();
- this.quaternion.conjugate().vmult(t, e);
- return e;
- };
- h.prototype.pointToWorldFrame = function(t, e) {
- e = e || new o();
- this.quaternion.vmult(t, e);
- e.vadd(this.position, e);
- return e;
- };
- h.prototype.vectorToWorldFrame = function(t, e) {
- e = e || new o();
- this.quaternion.vmult(t, e);
- return e;
- };
- var c = new o(), u = new r();
- h.prototype.addShape = function(t, e, i) {
- var n = new o(), s = new r();
- e && n.copy(e);
- i && s.copy(i);
- this.shapes.push(t);
- this.shapeOffsets.push(n);
- this.shapeOrientations.push(s);
- this.aabbNeedsUpdate = !0;
- this.updateMassProperties();
- this.updateBoundingRadius();
- this.updateHasTrigger();
- l.idToShapeMap[t.id] = t;
- t.body = this;
- return this;
- };
- h.prototype.removeShape = function(t) {
- var e = this.shapes.indexOf(t);
- if (-1 !== e) {
- this.shapes.splice(e, 1);
- this.shapeOffsets.splice(e, 1);
- this.shapeOrientations.splice(e, 1);
- this.aabbNeedsUpdate = !0;
- this.updateMassProperties();
- this.updateBoundingRadius();
- this.updateHasTrigger();
- }
- };
- h.prototype.updateBoundingRadius = function() {
- for (var t = this.shapes, e = this.shapeOffsets, i = t.length, o = 0, n = 0; n !== i; n++) {
- var r = t[n];
- r.updateBoundingSphereRadius();
- var s = e[n].norm(), a = r.boundingSphereRadius;
- s + a > o && (o = s + a);
- }
- this.boundingRadius = o;
- };
- var p = new s();
- h.prototype.computeAABB = function() {
- for (var t = this.shapes, e = this.shapeOffsets, i = this.shapeOrientations, o = t.length, n = c, r = u, s = this.quaternion, a = this.aabb, l = p, h = 0; h !== o; h++) {
- var d = t[h];
- s.vmult(e[h], n);
- n.vadd(this.position, n);
- i[h].mult(s, r);
- d.calculateWorldAABB(n, r, l.lowerBound, l.upperBound);
- 0 === h ? a.copy(l) : a.extend(l);
- }
- this.aabbNeedsUpdate = !1;
- };
- var d = new n(), y = new n();
- new n();
- h.prototype.updateInertiaWorld = function(t) {
- var e = this.invInertia;
- if (e.x !== e.y || e.y !== e.z || t) {
- var i = d, o = y;
- i.setRotationFromQuaternion(this.quaternion);
- i.transpose(o);
- i.scale(e, i);
- i.mmult(o, this.invInertiaWorld);
- }
- };
- new o();
- var f = new o();
- h.prototype.applyForce = function(t, e) {
- if (this.type === h.DYNAMIC) {
- var i = f;
- e.cross(t, i);
- this.force.vadd(t, this.force);
- this.torque.vadd(i, this.torque);
- }
- };
- var v = new o(), m = new o();
- h.prototype.applyLocalForce = function(t, e) {
- if (this.type === h.DYNAMIC) {
- var i = v, o = m;
- this.vectorToWorldFrame(t, i);
- this.vectorToWorldFrame(e, o);
- this.applyForce(i, o);
- }
- };
- new o();
- var g = new o(), b = new o();
- h.prototype.applyImpulse = function(t, e) {
- if (this.type === h.DYNAMIC) {
- var i = e, o = g;
- o.copy(t);
- o.mult(this.invMass, o);
- this.velocity.vadd(o, this.velocity);
- var n = b;
- i.cross(t, n);
- this.invInertiaWorld.vmult(n, n);
- this.angularVelocity.vadd(n, this.angularVelocity);
- }
- };
- var w = new o(), x = new o();
- h.prototype.applyLocalImpulse = function(t, e) {
- if (this.type === h.DYNAMIC) {
- var i = w, o = x;
- this.vectorToWorldFrame(t, i);
- this.vectorToWorldFrame(e, o);
- this.applyImpulse(i, o);
- }
- };
- var _ = new o();
- h.prototype.updateMassProperties = function() {
- var t = _;
- this.invMass = this.mass > 0 ? 1 / this.mass : 0;
- var e = this.inertia, i = this.fixedRotation;
- this.computeAABB();
- t.set((this.aabb.upperBound.x - this.aabb.lowerBound.x) / 2, (this.aabb.upperBound.y - this.aabb.lowerBound.y) / 2, (this.aabb.upperBound.z - this.aabb.lowerBound.z) / 2);
- a.calculateInertia(t, this.mass, e);
- this.invInertia.set(e.x > 0 && !i ? 1 / e.x : 0, e.y > 0 && !i ? 1 / e.y : 0, e.z > 0 && !i ? 1 / e.z : 0);
- this.updateInertiaWorld(!0);
- };
- h.prototype.getVelocityAtWorldPoint = function(t, e) {
- var i = new o();
- t.vsub(this.position, i);
- this.angularVelocity.cross(i, e);
- this.velocity.vadd(e, e);
- return e;
- };
- new o(), new o(), new r(), new r();
- h.prototype.integrate = function(t, e, i) {
- this.previousPosition.copy(this.position);
- this.previousQuaternion.copy(this.quaternion);
- if ((this.type === h.DYNAMIC || this.type === h.KINEMATIC) && this.sleepState !== h.SLEEPING) {
- var o = this.velocity, n = this.angularVelocity, r = this.position, s = this.force, a = this.torque, l = this.quaternion, c = this.invMass, u = this.invInertiaWorld, p = this.linearFactor, d = c * t;
- o.x += s.x * d * p.x;
- o.y += s.y * d * p.y;
- o.z += s.z * d * p.z;
- var y = u.elements, f = this.angularFactor, v = a.x * f.x, m = a.y * f.y, g = a.z * f.z;
- n.x += t * (y[0] * v + y[1] * m + y[2] * g);
- n.y += t * (y[3] * v + y[4] * m + y[5] * g);
- n.z += t * (y[6] * v + y[7] * m + y[8] * g);
- r.x += o.x * t;
- r.y += o.y * t;
- r.z += o.z * t;
- l.integrate(this.angularVelocity, t, this.angularFactor, l);
- e && (i ? l.normalizeFast() : l.normalize());
- this.aabbNeedsUpdate = !0;
- this.updateInertiaWorld();
- }
- };
- h.prototype.isSleeping = function() {
- return this.sleepState === h.SLEEPING;
- };
- h.prototype.isSleepy = function() {
- return this.sleepState === h.SLEEPY;
- };
- h.prototype.isAwake = function() {
- return this.sleepState === h.AWAKE;
- };
- h.prototype.updateHasTrigger = function() {
- for (var t = this.shapes.length; t--; ) {
- this.hasTrigger = !this.shapes[t].collisionResponse;
- if (this.hasTrigger) break;
- }
- };
- }, {
- "../collision/AABB": 3,
- "../material/Material": 26,
- "../math/Mat3": 29,
- "../math/Quaternion": 30,
- "../math/Vec3": 32,
- "../shapes/Box": 39,
- "../shapes/Shape": 45,
- "../utils/EventTarget": 51,
- "../world/World": 58
- } ],
- 34: [ function(t, e) {
- t("./Body");
- var i = t("../math/Vec3"), o = t("../math/Quaternion"), n = (t("../collision/RaycastResult"),
- t("../collision/Ray")), r = t("../objects/WheelInfo");
- e.exports = s;
- function s(t) {
- this.chassisBody = t.chassisBody;
- this.wheelInfos = [];
- this.sliding = !1;
- this.world = null;
- this.indexRightAxis = "undefined" != typeof t.indexRightAxis ? t.indexRightAxis : 1;
- this.indexForwardAxis = "undefined" != typeof t.indexForwardAxis ? t.indexForwardAxis : 0;
- this.indexUpAxis = "undefined" != typeof t.indexUpAxis ? t.indexUpAxis : 2;
- }
- new i(), new i(), new i();
- var a = new i(), l = new i(), h = new i();
- new n();
- s.prototype.addWheel = function(t) {
- var e = new r(t = t || {}), i = this.wheelInfos.length;
- this.wheelInfos.push(e);
- return i;
- };
- s.prototype.setSteeringValue = function(t, e) {
- this.wheelInfos[e].steering = t;
- };
- new i();
- s.prototype.applyEngineForce = function(t, e) {
- this.wheelInfos[e].engineForce = t;
- };
- s.prototype.setBrake = function(t, e) {
- this.wheelInfos[e].brake = t;
- };
- s.prototype.addToWorld = function(t) {
- this.constraints;
- t.addBody(this.chassisBody);
- var e = this;
- this.preStepCallback = function() {
- e.updateVehicle(t.dt);
- };
- t.addEventListener("preStep", this.preStepCallback);
- this.world = t;
- };
- s.prototype.getVehicleAxisWorld = function(t, e) {
- e.set(0 === t ? 1 : 0, 1 === t ? 1 : 0, 2 === t ? 1 : 0);
- this.chassisBody.vectorToWorldFrame(e, e);
- };
- s.prototype.updateVehicle = function(t) {
- for (var e = this.wheelInfos, o = e.length, n = this.chassisBody, r = 0; r < o; r++) this.updateWheelTransform(r);
- this.currentVehicleSpeedKmHour = 3.6 * n.velocity.norm();
- var s = new i();
- this.getVehicleAxisWorld(this.indexForwardAxis, s);
- s.dot(n.velocity) < 0 && (this.currentVehicleSpeedKmHour *= -1);
- for (r = 0; r < o; r++) this.castRay(e[r]);
- this.updateSuspension(t);
- var a = new i(), l = new i();
- for (r = 0; r < o; r++) {
- var h = (d = e[r]).suspensionForce;
- h > d.maxSuspensionForce && (h = d.maxSuspensionForce);
- d.raycastResult.hitNormalWorld.scale(h * t, a);
- d.raycastResult.hitPointWorld.vsub(n.position, l);
- n.applyImpulse(a, l);
- }
- this.updateFriction(t);
- var c = new i(), u = new i(), p = new i();
- for (r = 0; r < o; r++) {
- var d = e[r];
- n.getVelocityAtWorldPoint(d.chassisConnectionPointWorld, p);
- var y = 1;
- switch (this.indexUpAxis) {
- case 1:
- y = -1;
- }
- if (d.isInContact) {
- this.getVehicleAxisWorld(this.indexForwardAxis, u);
- var f = u.dot(d.raycastResult.hitNormalWorld);
- d.raycastResult.hitNormalWorld.scale(f, c);
- u.vsub(c, u);
- var v = u.dot(p);
- d.deltaRotation = y * v * t / d.radius;
- }
- !d.sliding && d.isInContact || 0 === d.engineForce || !d.useCustomSlidingRotationalSpeed || (d.deltaRotation = (d.engineForce > 0 ? 1 : -1) * d.customSlidingRotationalSpeed * t);
- Math.abs(d.brake) > Math.abs(d.engineForce) && (d.deltaRotation = 0);
- d.rotation += d.deltaRotation;
- d.deltaRotation *= .99;
- }
- };
- s.prototype.updateSuspension = function() {
- for (var t = this.chassisBody.mass, e = this.wheelInfos, i = e.length, o = 0; o < i; o++) {
- var n = e[o];
- if (n.isInContact) {
- var r, s = n.suspensionRestLength - n.suspensionLength;
- r = n.suspensionStiffness * s * n.clippedInvContactDotSuspension;
- var a = n.suspensionRelativeVelocity;
- r -= (a < 0 ? n.dampingCompression : n.dampingRelaxation) * a;
- n.suspensionForce = r * t;
- n.suspensionForce < 0 && (n.suspensionForce = 0);
- } else n.suspensionForce = 0;
- }
- };
- s.prototype.removeFromWorld = function(t) {
- this.constraints;
- t.remove(this.chassisBody);
- t.removeEventListener("preStep", this.preStepCallback);
- this.world = null;
- };
- var c = new i(), u = new i();
- s.prototype.castRay = function(t) {
- var e = c, o = u;
- this.updateWheelTransformWorld(t);
- var n = this.chassisBody, r = -1, s = t.suspensionRestLength + t.radius;
- t.directionWorld.scale(s, e);
- var a = t.chassisConnectionPointWorld;
- a.vadd(e, o);
- var l = t.raycastResult;
- l.reset();
- var h = n.collisionResponse;
- n.collisionResponse = !1;
- this.world.rayTest(a, o, l);
- n.collisionResponse = h;
- var p = l.body;
- t.raycastResult.groundObject = 0;
- if (p) {
- r = l.distance;
- t.raycastResult.hitNormalWorld = l.hitNormalWorld;
- t.isInContact = !0;
- var d = l.distance;
- t.suspensionLength = d - t.radius;
- var y = t.suspensionRestLength - t.maxSuspensionTravel, f = t.suspensionRestLength + t.maxSuspensionTravel;
- t.suspensionLength < y && (t.suspensionLength = y);
- if (t.suspensionLength > f) {
- t.suspensionLength = f;
- t.raycastResult.reset();
- }
- var v = t.raycastResult.hitNormalWorld.dot(t.directionWorld), m = new i();
- n.getVelocityAtWorldPoint(t.raycastResult.hitPointWorld, m);
- var g = t.raycastResult.hitNormalWorld.dot(m);
- if (v >= -.1) {
- t.suspensionRelativeVelocity = 0;
- t.clippedInvContactDotSuspension = 10;
- } else {
- var b = -1 / v;
- t.suspensionRelativeVelocity = g * b;
- t.clippedInvContactDotSuspension = b;
- }
- } else {
- t.suspensionLength = t.suspensionRestLength + 0 * t.maxSuspensionTravel;
- t.suspensionRelativeVelocity = 0;
- t.directionWorld.scale(-1, t.raycastResult.hitNormalWorld);
- t.clippedInvContactDotSuspension = 1;
- }
- return r;
- };
- s.prototype.updateWheelTransformWorld = function(t) {
- t.isInContact = !1;
- var e = this.chassisBody;
- e.pointToWorldFrame(t.chassisConnectionPointLocal, t.chassisConnectionPointWorld);
- e.vectorToWorldFrame(t.directionLocal, t.directionWorld);
- e.vectorToWorldFrame(t.axleLocal, t.axleWorld);
- };
- s.prototype.updateWheelTransform = function(t) {
- var e = a, i = l, n = h, r = this.wheelInfos[t];
- this.updateWheelTransformWorld(r);
- r.directionLocal.scale(-1, e);
- i.copy(r.axleLocal);
- e.cross(i, n);
- n.normalize();
- i.normalize();
- var s = r.steering, c = new o();
- c.setFromAxisAngle(e, s);
- var u = new o();
- u.setFromAxisAngle(i, r.rotation);
- var p = r.worldTransform.quaternion;
- this.chassisBody.quaternion.mult(c, p);
- p.mult(u, p);
- p.normalize();
- var d = r.worldTransform.position;
- d.copy(r.directionWorld);
- d.scale(r.suspensionLength, d);
- d.vadd(r.chassisConnectionPointWorld, d);
- };
- var p = [ new i(1, 0, 0), new i(0, 1, 0), new i(0, 0, 1) ];
- s.prototype.getWheelTransformWorld = function(t) {
- return this.wheelInfos[t].worldTransform;
- };
- var d = new i(), y = [], f = [];
- s.prototype.updateFriction = function(t) {
- for (var e = d, o = this.wheelInfos, n = o.length, r = this.chassisBody, s = f, a = y, l = 0; l < n; l++) {
- v = (M = o[l]).raycastResult.body;
- M.sideImpulse = 0;
- M.forwardImpulse = 0;
- s[l] || (s[l] = new i());
- a[l] || (a[l] = new i());
- }
- for (l = 0; l < n; l++) if (v = (M = o[l]).raycastResult.body) {
- var h = a[l];
- this.getWheelTransformWorld(l).vectorToWorldFrame(p[this.indexRightAxis], h);
- var c = M.raycastResult.hitNormalWorld, u = h.dot(c);
- c.scale(u, e);
- h.vsub(e, h);
- h.normalize();
- c.cross(h, s[l]);
- s[l].normalize();
- M.sideImpulse = A(r, M.raycastResult.hitPointWorld, v, M.raycastResult.hitPointWorld, h);
- M.sideImpulse *= 1;
- }
- this.sliding = !1;
- for (l = 0; l < n; l++) {
- var v = (M = o[l]).raycastResult.body, m = 0;
- M.slipInfo = 1;
- if (v) {
- var g = M.brake ? M.brake : 0;
- m = b(r, v, M.raycastResult.hitPointWorld, s[l], g);
- var w = g / (m += M.engineForce * t);
- M.slipInfo *= w;
- }
- M.forwardImpulse = 0;
- M.skidInfo = 1;
- if (v) {
- M.skidInfo = 1;
- var x = M.suspensionForce * t * M.frictionSlip, _ = x * x;
- M.forwardImpulse = m;
- var B = .5 * M.forwardImpulse, S = 1 * M.sideImpulse, E = B * B + S * S;
- M.sliding = !1;
- if (E > _) {
- this.sliding = !0;
- M.sliding = !0;
- w = x / Math.sqrt(E);
- M.skidInfo *= w;
- }
- }
- }
- if (this.sliding) for (l = 0; l < n; l++) if (0 !== (M = o[l]).sideImpulse && M.skidInfo < 1) {
- M.forwardImpulse *= M.skidInfo;
- M.sideImpulse *= M.skidInfo;
- }
- for (l = 0; l < n; l++) {
- var M = o[l], C = new i();
- M.raycastResult.hitPointWorld.vsub(r.position, C);
- if (0 !== M.forwardImpulse) {
- var z = new i();
- s[l].scale(M.forwardImpulse, z);
- r.applyImpulse(z, C);
- }
- if (0 !== M.sideImpulse) {
- v = M.raycastResult.body;
- var F = new i();
- M.raycastResult.hitPointWorld.vsub(v.position, F);
- var R = new i();
- a[l].scale(M.sideImpulse, R);
- r.vectorToLocalFrame(C, C);
- C["xyz"[this.indexUpAxis]] *= M.rollInfluence;
- r.vectorToWorldFrame(C, C);
- r.applyImpulse(R, C);
- R.scale(-1, R);
- v.applyImpulse(R, F);
- }
- }
- };
- var v = new i(), m = new i(), g = new i();
- function b(t, e, i, o, n) {
- var r = 0, s = i, a = v, l = m, h = g;
- t.getVelocityAtWorldPoint(s, a);
- e.getVelocityAtWorldPoint(s, l);
- a.vsub(l, h);
- n < (r = -o.dot(h) * (1 / (S(t, i, o) + S(e, i, o)))) && (r = n);
- r < -n && (r = -n);
- return r;
- }
- var w = new i(), x = new i(), _ = new i(), B = new i();
- function S(t, e, i) {
- var o = w, n = x, r = _, s = B;
- e.vsub(t.position, o);
- o.cross(i, n);
- t.invInertiaWorld.vmult(n, s);
- s.cross(o, r);
- return t.invMass + i.dot(r);
- }
- var E = new i(), M = new i(), C = new i();
- function A(t, e, i, o, n) {
- if (n.norm2() > 1.1) return 0;
- var r = E, s = M, a = C;
- t.getVelocityAtWorldPoint(e, r);
- i.getVelocityAtWorldPoint(o, s);
- r.vsub(s, a);
- return -.2 * n.dot(a) * (1 / (t.invMass + i.invMass));
- }
- }, {
- "../collision/Ray": 10,
- "../collision/RaycastResult": 11,
- "../math/Quaternion": 30,
- "../math/Vec3": 32,
- "../objects/WheelInfo": 38,
- "./Body": 33
- } ],
- 35: [ function(t, e) {
- var i = t("./Body"), o = t("../shapes/Sphere"), n = t("../shapes/Box"), r = t("../math/Vec3"), s = t("../constraints/HingeConstraint"), a = t("../math/CMath");
- e.exports = l;
- function l(t) {
- this.wheelBodies = [];
- this.coordinateSystem = "undefined" == typeof t.coordinateSystem ? new r(1, 2, 3) : t.coordinateSystem.clone();
- this.chassisBody = t.chassisBody;
- if (!this.chassisBody) {
- var e = new n(new r(5, 2, .5));
- this.chassisBody = new i(1, e);
- }
- this.constraints = [];
- this.wheelAxes = [];
- this.wheelForces = [];
- }
- l.prototype.addWheel = function(t) {
- var e = (t = t || {}).body;
- e || (e = new i(1, new o(1.2)));
- this.wheelBodies.push(e);
- this.wheelForces.push(0);
- new r();
- var n = "undefined" != typeof t.position ? t.position.clone() : new r(), a = new r();
- this.chassisBody.pointToWorldFrame(n, a);
- e.position.set(a.x, a.y, a.z);
- var l = "undefined" != typeof t.axis ? t.axis.clone() : new r(0, 1, 0);
- this.wheelAxes.push(l);
- var h = new s(this.chassisBody, e, {
- pivotA: n,
- axisA: l,
- pivotB: r.ZERO,
- axisB: l,
- collideConnected: !1
- });
- this.constraints.push(h);
- return this.wheelBodies.length - 1;
- };
- l.prototype.setSteeringValue = function(t, e) {
- var i = this.wheelAxes[e], o = a.cos(t), n = a.sin(t), r = i.x, s = i.y;
- this.constraints[e].axisA.set(o * r - n * s, n * r + o * s, 0);
- };
- l.prototype.setMotorSpeed = function(t, e) {
- var i = this.constraints[e];
- i.enableMotor();
- i.motorTargetVelocity = t;
- };
- l.prototype.disableMotor = function(t) {
- this.constraints[t].disableMotor();
- };
- var h = new r();
- l.prototype.setWheelForce = function(t, e) {
- this.wheelForces[e] = t;
- };
- l.prototype.applyWheelForce = function(t, e) {
- var i = this.wheelAxes[e], o = this.wheelBodies[e], n = o.torque;
- i.scale(t, h);
- o.vectorToWorldFrame(h, h);
- n.vadd(h, n);
- };
- l.prototype.addToWorld = function(t) {
- for (var e = this.constraints, i = this.wheelBodies.concat([ this.chassisBody ]), o = 0; o < i.length; o++) t.addBody(i[o]);
- for (o = 0; o < e.length; o++) t.addConstraint(e[o]);
- t.addEventListener("preStep", this._update.bind(this));
- };
- l.prototype._update = function() {
- for (var t = this.wheelForces, e = 0; e < t.length; e++) this.applyWheelForce(t[e], e);
- };
- l.prototype.removeFromWorld = function(t) {
- for (var e = this.constraints, i = this.wheelBodies.concat([ this.chassisBody ]), o = 0; o < i.length; o++) t.remove(i[o]);
- for (o = 0; o < e.length; o++) t.removeConstraint(e[o]);
- };
- var c = new r();
- l.prototype.getWheelSpeed = function(t) {
- var e = this.wheelAxes[t], i = this.wheelBodies[t].angularVelocity;
- this.chassisBody.vectorToWorldFrame(e, c);
- return i.dot(c);
- };
- }, {
- "../constraints/HingeConstraint": 16,
- "../math/CMath": 27,
- "../math/Vec3": 32,
- "../shapes/Box": 39,
- "../shapes/Sphere": 46,
- "./Body": 33
- } ],
- 36: [ function(t, e) {
- e.exports = o;
- t("../shapes/Shape");
- var i = t("../math/Vec3");
- t("../math/Quaternion"), t("../shapes/Particle"), t("../objects/Body"), t("../material/Material");
- function o() {
- this.particles = [];
- this.density = 1;
- this.smoothingRadius = 1;
- this.speedOfSound = 1;
- this.viscosity = .01;
- this.eps = 1e-6;
- this.pressures = [];
- this.densities = [];
- this.neighbors = [];
- }
- o.prototype.add = function(t) {
- this.particles.push(t);
- this.neighbors.length < this.particles.length && this.neighbors.push([]);
- };
- o.prototype.remove = function(t) {
- var e = this.particles.indexOf(t);
- if (-1 !== e) {
- this.particles.splice(e, 1);
- this.neighbors.length > this.particles.length && this.neighbors.pop();
- }
- };
- var n = new i();
- o.prototype.getNeighbors = function(t, e) {
- for (var i = this.particles.length, o = t.id, r = this.smoothingRadius * this.smoothingRadius, s = n, a = 0; a !== i; a++) {
- var l = this.particles[a];
- l.position.vsub(t.position, s);
- o !== l.id && s.norm2() < r && e.push(l);
- }
- };
- var r = new i(), s = new i(), a = new i(), l = new i(), h = new i(), c = new i();
- o.prototype.update = function() {
- for (var t = this.particles.length, e = r, i = this.speedOfSound, o = this.eps, n = 0; n !== t; n++) {
- var u = this.particles[n];
- (S = this.neighbors[n]).length = 0;
- this.getNeighbors(u, S);
- S.push(this.particles[n]);
- for (var p = S.length, d = 0, y = 0; y !== p; y++) {
- u.position.vsub(S[y].position, e);
- var f = e.norm(), v = this.w(f);
- d += S[y].mass * v;
- }
- this.densities[n] = d;
- this.pressures[n] = i * i * (this.densities[n] - this.density);
- }
- var m = s, g = a, b = l, w = h, x = c;
- for (n = 0; n !== t; n++) {
- var _, B, S, E = this.particles[n];
- m.set(0, 0, 0);
- g.set(0, 0, 0);
- for (p = (S = this.neighbors[n]).length, y = 0; y !== p; y++) {
- var M = S[y];
- E.position.vsub(M.position, w);
- var C = w.norm();
- _ = -M.mass * (this.pressures[n] / (this.densities[n] * this.densities[n] + o) + this.pressures[y] / (this.densities[y] * this.densities[y] + o));
- this.gradw(w, b);
- b.mult(_, b);
- m.vadd(b, m);
- M.velocity.vsub(E.velocity, x);
- x.mult(1 / (1e-4 + this.densities[n] * this.densities[y]) * this.viscosity * M.mass, x);
- B = this.nablaw(C);
- x.mult(B, x);
- g.vadd(x, g);
- }
- g.mult(E.mass, g);
- m.mult(E.mass, m);
- E.force.vadd(g, E.force);
- E.force.vadd(m, E.force);
- }
- };
- o.prototype.w = function(t) {
- var e = this.smoothingRadius;
- return 315 / (64 * Math.PI * Math.pow(e, 9)) * Math.pow(e * e - t * t, 3);
- };
- o.prototype.gradw = function(t, e) {
- var i = t.norm(), o = this.smoothingRadius;
- t.mult(945 / (32 * Math.PI * Math.pow(o, 9)) * Math.pow(o * o - i * i, 2), e);
- };
- o.prototype.nablaw = function(t) {
- var e = this.smoothingRadius;
- return 945 / (32 * Math.PI * Math.pow(e, 9)) * (e * e - t * t) * (7 * t * t - 3 * e * e);
- };
- }, {
- "../material/Material": 26,
- "../math/Quaternion": 30,
- "../math/Vec3": 32,
- "../objects/Body": 33,
- "../shapes/Particle": 43,
- "../shapes/Shape": 45
- } ],
- 37: [ function(t, e) {
- var i = t("../math/Vec3");
- e.exports = o;
- function o(t, e, o) {
- o = o || {};
- this.restLength = "number" == typeof o.restLength ? o.restLength : 1;
- this.stiffness = o.stiffness || 100;
- this.damping = o.damping || 1;
- this.bodyA = t;
- this.bodyB = e;
- this.localAnchorA = new i();
- this.localAnchorB = new i();
- o.localAnchorA && this.localAnchorA.copy(o.localAnchorA);
- o.localAnchorB && this.localAnchorB.copy(o.localAnchorB);
- o.worldAnchorA && this.setWorldAnchorA(o.worldAnchorA);
- o.worldAnchorB && this.setWorldAnchorB(o.worldAnchorB);
- }
- o.prototype.setWorldAnchorA = function(t) {
- this.bodyA.pointToLocalFrame(t, this.localAnchorA);
- };
- o.prototype.setWorldAnchorB = function(t) {
- this.bodyB.pointToLocalFrame(t, this.localAnchorB);
- };
- o.prototype.getWorldAnchorA = function(t) {
- this.bodyA.pointToWorldFrame(this.localAnchorA, t);
- };
- o.prototype.getWorldAnchorB = function(t) {
- this.bodyB.pointToWorldFrame(this.localAnchorB, t);
- };
- var n = new i(), r = new i(), s = new i(), a = new i(), l = new i(), h = new i(), c = new i(), u = new i(), p = new i(), d = new i(), y = new i();
- o.prototype.applyForce = function() {
- var t = this.stiffness, e = this.damping, i = this.restLength, o = this.bodyA, f = this.bodyB, v = n, m = r, g = s, b = a, w = y, x = l, _ = h, B = c, S = u, E = p, M = d;
- this.getWorldAnchorA(x);
- this.getWorldAnchorB(_);
- x.vsub(o.position, B);
- _.vsub(f.position, S);
- _.vsub(x, v);
- var C = v.norm();
- m.copy(v);
- m.normalize();
- f.velocity.vsub(o.velocity, g);
- f.angularVelocity.cross(S, w);
- g.vadd(w, g);
- o.angularVelocity.cross(B, w);
- g.vsub(w, g);
- m.mult(-t * (C - i) - e * g.dot(m), b);
- o.force.vsub(b, o.force);
- f.force.vadd(b, f.force);
- B.cross(b, E);
- S.cross(b, M);
- o.torque.vsub(E, o.torque);
- f.torque.vadd(M, f.torque);
- };
- }, {
- "../math/Vec3": 32
- } ],
- 38: [ function(t, e) {
- var i = t("../math/Vec3"), o = t("../math/Transform"), n = t("../collision/RaycastResult"), r = t("../utils/Utils");
- e.exports = s;
- function s(t) {
- t = r.defaults(t, {
- chassisConnectionPointLocal: new i(),
- chassisConnectionPointWorld: new i(),
- directionLocal: new i(),
- directionWorld: new i(),
- axleLocal: new i(),
- axleWorld: new i(),
- suspensionRestLength: 1,
- suspensionMaxLength: 2,
- radius: 1,
- suspensionStiffness: 100,
- dampingCompression: 10,
- dampingRelaxation: 10,
- frictionSlip: 1e4,
- steering: 0,
- rotation: 0,
- deltaRotation: 0,
- rollInfluence: .01,
- maxSuspensionForce: Number.MAX_VALUE,
- isFrontWheel: !0,
- clippedInvContactDotSuspension: 1,
- suspensionRelativeVelocity: 0,
- suspensionForce: 0,
- skidInfo: 0,
- suspensionLength: 0,
- maxSuspensionTravel: 1,
- useCustomSlidingRotationalSpeed: !1,
- customSlidingRotationalSpeed: -.1
- });
- this.maxSuspensionTravel = t.maxSuspensionTravel;
- this.customSlidingRotationalSpeed = t.customSlidingRotationalSpeed;
- this.useCustomSlidingRotationalSpeed = t.useCustomSlidingRotationalSpeed;
- this.sliding = !1;
- this.chassisConnectionPointLocal = t.chassisConnectionPointLocal.clone();
- this.chassisConnectionPointWorld = t.chassisConnectionPointWorld.clone();
- this.directionLocal = t.directionLocal.clone();
- this.directionWorld = t.directionWorld.clone();
- this.axleLocal = t.axleLocal.clone();
- this.axleWorld = t.axleWorld.clone();
- this.suspensionRestLength = t.suspensionRestLength;
- this.suspensionMaxLength = t.suspensionMaxLength;
- this.radius = t.radius;
- this.suspensionStiffness = t.suspensionStiffness;
- this.dampingCompression = t.dampingCompression;
- this.dampingRelaxation = t.dampingRelaxation;
- this.frictionSlip = t.frictionSlip;
- this.steering = 0;
- this.rotation = 0;
- this.deltaRotation = 0;
- this.rollInfluence = t.rollInfluence;
- this.maxSuspensionForce = t.maxSuspensionForce;
- this.engineForce = 0;
- this.brake = 0;
- this.isFrontWheel = t.isFrontWheel;
- this.clippedInvContactDotSuspension = 1;
- this.suspensionRelativeVelocity = 0;
- this.suspensionForce = 0;
- this.skidInfo = 0;
- this.suspensionLength = 0;
- this.sideImpulse = 0;
- this.forwardImpulse = 0;
- this.raycastResult = new n();
- this.worldTransform = new o();
- this.isInContact = !1;
- }
- var a = new i(), l = new i();
- a = new i();
- s.prototype.updateWheel = function(t) {
- var e = this.raycastResult;
- if (this.isInContact) {
- var i = e.hitNormalWorld.dot(e.directionWorld);
- e.hitPointWorld.vsub(t.position, l);
- t.getVelocityAtWorldPoint(l, a);
- var o = e.hitNormalWorld.dot(a);
- if (i >= -.1) {
- this.suspensionRelativeVelocity = 0;
- this.clippedInvContactDotSuspension = 10;
- } else {
- var n = -1 / i;
- this.suspensionRelativeVelocity = o * n;
- this.clippedInvContactDotSuspension = n;
- }
- } else {
- e.suspensionLength = this.suspensionRestLength;
- this.suspensionRelativeVelocity = 0;
- e.directionWorld.scale(-1, e.hitNormalWorld);
- this.clippedInvContactDotSuspension = 1;
- }
- };
- }, {
- "../collision/RaycastResult": 11,
- "../math/Transform": 31,
- "../math/Vec3": 32,
- "../utils/Utils": 55
- } ],
- 39: [ function(t, e) {
- e.exports = r;
- var i = t("./Shape"), o = t("../math/Vec3"), n = t("./ConvexPolyhedron");
- function r(t) {
- i.call(this, {
- type: i.types.BOX
- });
- this.halfExtents = t;
- this.convexPolyhedronRepresentation = null;
- this.updateConvexPolyhedronRepresentation();
- this.updateBoundingSphereRadius();
- }
- r.prototype = new i();
- r.prototype.constructor = r;
- r.prototype.updateConvexPolyhedronRepresentation = function() {
- var t = this.halfExtents.x, e = this.halfExtents.y, i = this.halfExtents.z, r = o, s = [ new r(-t, -e, -i), new r(t, -e, -i), new r(t, e, -i), new r(-t, e, -i), new r(-t, -e, i), new r(t, -e, i), new r(t, e, i), new r(-t, e, i) ], a = (new r(0, 0, 1),
- new r(0, 1, 0), new r(1, 0, 0), new n(s, [ [ 3, 2, 1, 0 ], [ 4, 5, 6, 7 ], [ 5, 4, 0, 1 ], [ 2, 3, 7, 6 ], [ 0, 4, 7, 3 ], [ 1, 2, 6, 5 ] ]));
- this.convexPolyhedronRepresentation = a;
- a.material = this.material;
- };
- r.prototype.calculateLocalInertia = function(t, e) {
- e = e || new o();
- r.calculateInertia(this.halfExtents, t, e);
- return e;
- };
- r.calculateInertia = function(t, e, i) {
- var o = t;
- if (o.isZero()) {
- i.x = 2 / 12 * e;
- i.y = 2 / 12 * e;
- i.z = 2 / 12 * e;
- } else {
- i.x = 1 / 12 * e * (4 * o.y * o.y + 4 * o.z * o.z);
- i.y = 1 / 12 * e * (4 * o.x * o.x + 4 * o.z * o.z);
- i.z = 1 / 12 * e * (4 * o.y * o.y + 4 * o.x * o.x);
- }
- };
- r.prototype.getSideNormals = function(t, e) {
- var i = t, o = this.halfExtents;
- i[0].set(o.x, 0, 0);
- i[1].set(0, o.y, 0);
- i[2].set(0, 0, o.z);
- i[3].set(-o.x, 0, 0);
- i[4].set(0, -o.y, 0);
- i[5].set(0, 0, -o.z);
- if (void 0 !== e) for (var n = 0; n !== i.length; n++) e.vmult(i[n], i[n]);
- return i;
- };
- r.prototype.volume = function() {
- return 8 * this.halfExtents.x * this.halfExtents.y * this.halfExtents.z;
- };
- r.prototype.updateBoundingSphereRadius = function() {
- this.boundingSphereRadius = this.halfExtents.norm();
- };
- var s = new o();
- new o();
- r.prototype.forEachWorldCorner = function(t, e, i) {
- for (var o = this.halfExtents, n = [ [ o.x, o.y, o.z ], [ -o.x, o.y, o.z ], [ -o.x, -o.y, o.z ], [ -o.x, -o.y, -o.z ], [ o.x, -o.y, -o.z ], [ o.x, o.y, -o.z ], [ -o.x, o.y, -o.z ], [ o.x, -o.y, o.z ] ], r = 0; r < n.length; r++) {
- s.set(n[r][0], n[r][1], n[r][2]);
- e.vmult(s, s);
- t.vadd(s, s);
- i(s.x, s.y, s.z);
- }
- };
- var a = [ new o(), new o(), new o(), new o(), new o(), new o(), new o(), new o() ];
- r.prototype.calculateWorldAABB = function(t, e, i, o) {
- var n = this.halfExtents;
- a[0].set(n.x, n.y, n.z);
- a[1].set(-n.x, n.y, n.z);
- a[2].set(-n.x, -n.y, n.z);
- a[3].set(-n.x, -n.y, -n.z);
- a[4].set(n.x, -n.y, -n.z);
- a[5].set(n.x, n.y, -n.z);
- a[6].set(-n.x, n.y, -n.z);
- a[7].set(n.x, -n.y, n.z);
- var r = a[0];
- e.vmult(r, r);
- t.vadd(r, r);
- o.copy(r);
- i.copy(r);
- for (var s = 1; s < 8; s++) {
- r = a[s];
- e.vmult(r, r);
- t.vadd(r, r);
- var l = r.x, h = r.y, c = r.z;
- l > o.x && (o.x = l);
- h > o.y && (o.y = h);
- c > o.z && (o.z = c);
- l < i.x && (i.x = l);
- h < i.y && (i.y = h);
- c < i.z && (i.z = c);
- }
- };
- }, {
- "../math/Vec3": 32,
- "./ConvexPolyhedron": 40,
- "./Shape": 45
- } ],
- 40: [ function(t, e) {
- e.exports = r;
- var i = t("./Shape"), o = t("../math/Vec3"), n = (t("../math/Quaternion"), t("../math/Transform"));
- function r(t, e, o) {
- i.call(this, {
- type: i.types.CONVEXPOLYHEDRON
- });
- this.vertices = t || [];
- this.worldVertices = [];
- this.worldVerticesNeedsUpdate = !0;
- this.faces = e || [];
- this.faceNormals = [];
- this.computeNormals();
- this.worldFaceNormalsNeedsUpdate = !0;
- this.worldFaceNormals = [];
- this.uniqueEdges = [];
- this.uniqueAxes = o ? o.slice() : null;
- this.computeEdges();
- this.updateBoundingSphereRadius();
- }
- r.prototype = new i();
- r.prototype.constructor = r;
- var s = new o();
- r.prototype.computeEdges = function() {
- var t = this.faces, e = this.vertices, i = (e.length, this.uniqueEdges);
- i.length = 0;
- for (var o = s, n = 0; n !== t.length; n++) for (var r = t[n], a = r.length, l = 0; l !== a; l++) {
- var h = (l + 1) % a;
- e[r[l]].vsub(e[r[h]], o);
- o.normalize();
- for (var c = !1, u = 0; u !== i.length; u++) if (i[u].almostEquals(o) || i[u].almostEquals(o)) {
- c = !0;
- break;
- }
- c || i.push(o.clone());
- }
- };
- r.prototype.computeNormals = function() {
- this.faceNormals.length = this.faces.length;
- for (var t = 0; t < this.faces.length; t++) {
- for (var e = 0; e < this.faces[t].length; e++) if (!this.vertices[this.faces[t][e]]) throw new Error("Vertex " + this.faces[t][e] + " not found!");
- var i = this.faceNormals[t] || new o();
- this.getFaceNormal(t, i);
- i.negate(i);
- this.faceNormals[t] = i;
- var n = this.vertices[this.faces[t][0]];
- if (i.dot(n) < 0) {
- console.error(".faceNormals[" + t + "] = Vec3(" + i.toString() + ") looks like it points into the shape? The vertices follow. Make sure they are ordered CCW around the normal, using the right hand rule.");
- for (e = 0; e < this.faces[t].length; e++) console.warn(".vertices[" + this.faces[t][e] + "] = Vec3(" + this.vertices[this.faces[t][e]].toString() + ")");
- }
- }
- };
- var a = new o(), l = new o();
- r.computeNormal = function(t, e, i, o) {
- e.vsub(t, l);
- i.vsub(e, a);
- a.cross(l, o);
- o.isZero() || o.normalize();
- };
- r.prototype.getFaceNormal = function(t, e) {
- var i = this.faces[t], o = this.vertices[i[0]], n = this.vertices[i[1]], s = this.vertices[i[2]];
- return r.computeNormal(o, n, s, e);
- };
- var h = new o();
- r.prototype.clipAgainstHull = function(t, e, i, n, r, s, a, l, c) {
- for (var u = h, p = -1, d = -Number.MAX_VALUE, y = 0; y < i.faces.length; y++) {
- u.copy(i.faceNormals[y]);
- r.vmult(u, u);
- var f = u.dot(s);
- if (f > d) {
- d = f;
- p = y;
- }
- }
- for (var v = [], m = i.faces[p], g = m.length, b = 0; b < g; b++) {
- var w = i.vertices[m[b]], x = new o();
- x.copy(w);
- r.vmult(x, x);
- n.vadd(x, x);
- v.push(x);
- }
- p >= 0 && this.clipFaceAgainstHull(s, t, e, v, a, l, c);
- };
- var c = new o(), u = new o(), p = new o(), d = new o(), y = new o(), f = new o();
- r.prototype.findSeparatingAxis = function(t, e, i, o, n, r, s, a) {
- var l = c, h = u, v = p, m = d, g = y, b = f, w = Number.MAX_VALUE;
- if (this.uniqueAxes) for (_ = 0; _ !== this.uniqueAxes.length; _++) {
- i.vmult(this.uniqueAxes[_], l);
- if (!1 === (E = this.testSepAxis(l, t, e, i, o, n))) return !1;
- if (E < w) {
- w = E;
- r.copy(l);
- }
- } else for (var x = s ? s.length : this.faces.length, _ = 0; _ < x; _++) {
- var B = s ? s[_] : _;
- l.copy(this.faceNormals[B]);
- i.vmult(l, l);
- if (!1 === (E = this.testSepAxis(l, t, e, i, o, n))) return !1;
- if (E < w) {
- w = E;
- r.copy(l);
- }
- }
- if (t.uniqueAxes) for (_ = 0; _ !== t.uniqueAxes.length; _++) {
- n.vmult(t.uniqueAxes[_], h);
- if (!1 === (E = this.testSepAxis(h, t, e, i, o, n))) return !1;
- if (E < w) {
- w = E;
- r.copy(h);
- }
- } else {
- var S = a ? a.length : t.faces.length;
- for (_ = 0; _ < S; _++) {
- var E;
- B = a ? a[_] : _;
- h.copy(t.faceNormals[B]);
- n.vmult(h, h);
- if (!1 === (E = this.testSepAxis(h, t, e, i, o, n))) return !1;
- if (E < w) {
- w = E;
- r.copy(h);
- }
- }
- }
- for (var M = 0; M !== this.uniqueEdges.length; M++) {
- i.vmult(this.uniqueEdges[M], m);
- for (var C = 0; C !== t.uniqueEdges.length; C++) {
- n.vmult(t.uniqueEdges[C], g);
- m.cross(g, b);
- if (!b.almostZero()) {
- b.normalize();
- var A = this.testSepAxis(b, t, e, i, o, n);
- if (!1 === A) return !1;
- if (A < w) {
- w = A;
- r.copy(b);
- }
- }
- }
- }
- o.vsub(e, v);
- v.dot(r) > 0 && r.negate(r);
- return !0;
- };
- var v = [], m = [];
- r.prototype.testSepAxis = function(t, e, i, o, n, s) {
- r.project(this, t, i, o, v);
- r.project(e, t, n, s, m);
- var a = v[0], l = v[1], h = m[0], c = m[1];
- if (a < c || h < l) return !1;
- var u = a - c, p = h - l;
- return u < p ? u : p;
- };
- var g = new o(), b = new o();
- r.prototype.calculateLocalInertia = function(t, e) {
- this.computeLocalAABB(g, b);
- var i = b.x - g.x, o = b.y - g.y, n = b.z - g.z;
- e.x = 1 / 12 * t * (4 * o * o + 4 * n * n);
- e.y = 1 / 12 * t * (4 * i * i + 4 * n * n);
- e.z = 1 / 12 * t * (4 * o * o + 4 * i * i);
- };
- r.prototype.getPlaneConstantOfFace = function(t) {
- var e = this.faces[t], i = this.faceNormals[t], o = this.vertices[e[0]];
- return -i.dot(o);
- };
- var w = new o(), x = new o(), _ = new o(), B = new o(), S = new o(), E = new o(), M = new o(), C = new o();
- r.prototype.clipFaceAgainstHull = function(t, e, i, o, n, r, s) {
- for (var a = w, l = x, h = _, c = B, u = S, p = E, d = M, y = C, f = o, v = [], m = -1, g = Number.MAX_VALUE, b = 0; b < this.faces.length; b++) {
- a.copy(this.faceNormals[b]);
- i.vmult(a, a);
- var A = a.dot(t);
- if (A < g) {
- g = A;
- m = b;
- }
- }
- if (!(m < 0)) {
- var z = this.faces[m];
- z.connectedFaces = [];
- for (var F = 0; F < this.faces.length; F++) for (var R = 0; R < this.faces[F].length; R++) -1 !== z.indexOf(this.faces[F][R]) && F !== m && -1 === z.connectedFaces.indexOf(F) && z.connectedFaces.push(F);
- f.length;
- for (var T = z.length, P = 0; P < T; P++) {
- var q = this.vertices[z[P]], I = this.vertices[z[(P + 1) % T]];
- q.vsub(I, l);
- h.copy(l);
- i.vmult(h, h);
- e.vadd(h, h);
- c.copy(this.faceNormals[m]);
- i.vmult(c, c);
- e.vadd(c, c);
- h.cross(c, u);
- u.negate(u);
- p.copy(q);
- i.vmult(p, p);
- e.vadd(p, p);
- p.dot(u);
- var O = z.connectedFaces[P];
- d.copy(this.faceNormals[O]);
- var V = this.getPlaneConstantOfFace(O);
- y.copy(d);
- i.vmult(y, y);
- var j = V - y.dot(e);
- this.clipFaceAgainstPlane(f, v, y, j);
- for (;f.length; ) f.shift();
- for (;v.length; ) f.push(v.shift());
- }
- d.copy(this.faceNormals[m]);
- V = this.getPlaneConstantOfFace(m);
- y.copy(d);
- i.vmult(y, y);
- for (j = V - y.dot(e), F = 0; F < f.length; F++) {
- var k = y.dot(f[F]) + j;
- k <= n && (k = n);
- if (k <= r) {
- var N = f[F];
- if (k <= 0) {
- var L = {
- point: N,
- normal: y,
- depth: k
- };
- s.push(L);
- }
- }
- }
- }
- };
- r.prototype.clipFaceAgainstPlane = function(t, e, i, n) {
- var r, s, a = t.length;
- if (a < 2) return e;
- var l = t[t.length - 1], h = t[0];
- r = i.dot(l) + n;
- for (var c = 0; c < a; c++) {
- h = t[c];
- s = i.dot(h) + n;
- if (r < 0) if (s < 0) {
- (u = new o()).copy(h);
- e.push(u);
- } else {
- var u = new o();
- l.lerp(h, r / (r - s), u);
- e.push(u);
- } else if (s < 0) {
- u = new o();
- l.lerp(h, r / (r - s), u);
- e.push(u);
- e.push(h);
- }
- l = h;
- r = s;
- }
- return e;
- };
- r.prototype.computeWorldVertices = function(t, e) {
- for (var i = this.vertices.length; this.worldVertices.length < i; ) this.worldVertices.push(new o());
- for (var n = this.vertices, r = this.worldVertices, s = 0; s !== i; s++) {
- e.vmult(n[s], r[s]);
- t.vadd(r[s], r[s]);
- }
- this.worldVerticesNeedsUpdate = !1;
- };
- new o();
- r.prototype.computeLocalAABB = function(t, e) {
- var i = this.vertices.length, o = this.vertices;
- t.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
- e.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
- for (var n = 0; n < i; n++) {
- var r = o[n];
- r.x < t.x ? t.x = r.x : r.x > e.x && (e.x = r.x);
- r.y < t.y ? t.y = r.y : r.y > e.y && (e.y = r.y);
- r.z < t.z ? t.z = r.z : r.z > e.z && (e.z = r.z);
- }
- };
- r.prototype.computeWorldFaceNormals = function(t) {
- for (var e = this.faceNormals.length; this.worldFaceNormals.length < e; ) this.worldFaceNormals.push(new o());
- for (var i = this.faceNormals, n = this.worldFaceNormals, r = 0; r !== e; r++) t.vmult(i[r], n[r]);
- this.worldFaceNormalsNeedsUpdate = !1;
- };
- r.prototype.updateBoundingSphereRadius = function() {
- for (var t = 0, e = this.vertices, i = 0, o = e.length; i !== o; i++) {
- var n = e[i].norm2();
- n > t && (t = n);
- }
- this.boundingSphereRadius = Math.sqrt(t);
- };
- var A = new o();
- r.prototype.calculateWorldAABB = function(t, e, i, o) {
- for (var n, r, s, a, l, h, c = this.vertices.length, u = this.vertices, p = 0; p < c; p++) {
- A.copy(u[p]);
- e.vmult(A, A);
- t.vadd(A, A);
- var d = A;
- (d.x < n || void 0 === n) && (n = d.x);
- (d.x > a || void 0 === a) && (a = d.x);
- (d.y < r || void 0 === r) && (r = d.y);
- (d.y > l || void 0 === l) && (l = d.y);
- (d.z < s || void 0 === s) && (s = d.z);
- (d.z > h || void 0 === h) && (h = d.z);
- }
- i.set(n, r, s);
- o.set(a, l, h);
- };
- r.prototype.volume = function() {
- return 4 * Math.PI * this.boundingSphereRadius / 3;
- };
- r.prototype.getAveragePointLocal = function(t) {
- t = t || new o();
- for (var e = this.vertices.length, i = this.vertices, n = 0; n < e; n++) t.vadd(i[n], t);
- t.mult(1 / e, t);
- return t;
- };
- r.prototype.transformAllPoints = function(t, e) {
- var i = this.vertices.length, o = this.vertices;
- if (e) {
- for (var n = 0; n < i; n++) {
- var r = o[n];
- e.vmult(r, r);
- }
- for (n = 0; n < this.faceNormals.length; n++) {
- r = this.faceNormals[n];
- e.vmult(r, r);
- }
- }
- if (t) for (n = 0; n < i; n++) (r = o[n]).vadd(t, r);
- };
- var z = new o(), F = new o(), R = new o();
- r.prototype.pointIsInside = function(t) {
- var e = this.vertices.length, i = this.vertices, o = this.faces, n = this.faceNormals, r = this.faces.length, s = z;
- this.getAveragePointLocal(s);
- for (var a = 0; a < r; a++) {
- this.faces[a].length, e = n[a];
- var l = i[o[a][0]], h = F;
- t.vsub(l, h);
- var c = e.dot(h), u = R;
- s.vsub(l, u);
- var p = e.dot(u);
- if (c < 0 && p > 0 || c > 0 && p < 0) return !1;
- }
- return -1;
- };
- new o();
- var T = new o(), P = new o();
- r.project = function(t, e, i, o, r) {
- var s = t.vertices.length, a = T, l = 0, h = 0, c = P, u = t.vertices;
- c.setZero();
- n.vectorToLocalFrame(i, o, e, a);
- n.pointToLocalFrame(i, o, c, c);
- var p = c.dot(a);
- h = l = u[0].dot(a);
- for (var d = 1; d < s; d++) {
- var y = u[d].dot(a);
- y > l && (l = y);
- y < h && (h = y);
- }
- if ((h -= p) > (l -= p)) {
- var f = h;
- h = l;
- l = f;
- }
- r[0] = l;
- r[1] = h;
- };
- }, {
- "../math/Quaternion": 30,
- "../math/Transform": 31,
- "../math/Vec3": 32,
- "./Shape": 45
- } ],
- 41: [ function(t, e) {
- e.exports = r;
- t("./Shape");
- var i = t("../math/Vec3"), o = (t("../math/Quaternion"), t("./ConvexPolyhedron")), n = t("../math/CMath");
- function r(t, e, r, s, a) {
- if (a) {
- for (var l = s, h = n.cos, c = n.sin, u = r / 2, p = [], d = [], y = [ 0 ], f = [ 1 ], v = [], m = 2 * Math.PI / l, g = 0; g < l; g++) {
- p.push(new i(t * h(m * g), u, t * c(m * g)));
- p.push(new i(t * h(m * g), -u, t * c(m * g)));
- if (g < l - 1) {
- d.push([ 2 * g + 2, 2 * g + 3, 2 * g + 1, 2 * g ]);
- y.push(2 * g + 2);
- f.push(2 * g + 3);
- } else d.push([ 0, 1, 2 * g + 1, 2 * g ]);
- (l % 2 == 1 || g < l / 2) && v.push(new i(h(m * (g + .5)), 0, c(m * (g + .5))));
- }
- d.push(f);
- var b = [];
- for (g = 0; g < y.length; g++) b.push(y[y.length - g - 1]);
- d.push(b);
- v.push(new i(0, 1, 0));
- o.call(this, p, d, v);
- } else {
- l = s;
- var w = [], x = (v = [], []), _ = [], B = [];
- h = n.cos, c = n.sin;
- w.push(new i(e * h(0), e * c(0), .5 * -r));
- _.push(0);
- w.push(new i(t * h(0), t * c(0), .5 * r));
- B.push(1);
- for (g = 0; g < l; g++) {
- m = 2 * Math.PI / l * (g + 1);
- var S = 2 * Math.PI / l * (g + .5);
- if (g < l - 1) {
- w.push(new i(e * h(m), e * c(m), .5 * -r));
- _.push(2 * g + 2);
- w.push(new i(t * h(m), t * c(m), .5 * r));
- B.push(2 * g + 3);
- x.push([ 2 * g + 2, 2 * g + 3, 2 * g + 1, 2 * g ]);
- } else x.push([ 0, 1, 2 * g + 1, 2 * g ]);
- (l % 2 == 1 || g < l / 2) && v.push(new i(h(S), c(S), 0));
- }
- x.push(B);
- v.push(new i(0, 0, 1));
- for (b = [], g = 0; g < _.length; g++) b.push(_[_.length - g - 1]);
- x.push(b);
- o.call(this, w, x, v);
- }
- }
- r.prototype = new o();
- }, {
- "../math/CMath": 27,
- "../math/Quaternion": 30,
- "../math/Vec3": 32,
- "./ConvexPolyhedron": 40,
- "./Shape": 45
- } ],
- 42: [ function(t, e) {
- var i = t("./Shape"), o = t("./ConvexPolyhedron"), n = t("../math/Vec3"), r = t("../utils/Utils");
- e.exports = s;
- function s(t, e) {
- e = r.defaults(e, {
- maxValue: null,
- minValue: null,
- elementSize: 1
- });
- this.data = t;
- this.maxValue = e.maxValue;
- this.minValue = e.minValue;
- this.elementSize = e.elementSize;
- null === e.minValue && this.updateMinValue();
- null === e.maxValue && this.updateMaxValue();
- this.cacheEnabled = !0;
- i.call(this, {
- type: i.types.HEIGHTFIELD
- });
- this.pillarConvex = new o();
- this.pillarOffset = new n();
- this.updateBoundingSphereRadius();
- this._cachedPillars = {};
- }
- s.prototype = new i();
- s.prototype.update = function() {
- this._cachedPillars = {};
- };
- s.prototype.updateMinValue = function() {
- for (var t = this.data, e = t[0][0], i = 0; i !== t.length; i++) for (var o = 0; o !== t[i].length; o++) {
- var n = t[i][o];
- n < e && (e = n);
- }
- this.minValue = e;
- };
- s.prototype.updateMaxValue = function() {
- for (var t = this.data, e = t[0][0], i = 0; i !== t.length; i++) for (var o = 0; o !== t[i].length; o++) {
- var n = t[i][o];
- n > e && (e = n);
- }
- this.maxValue = e;
- };
- s.prototype.setHeightValueAtIndex = function(t, e, i) {
- this.data[t][e] = i;
- this.clearCachedConvexTrianglePillar(t, e, !1);
- if (t > 0) {
- this.clearCachedConvexTrianglePillar(t - 1, e, !0);
- this.clearCachedConvexTrianglePillar(t - 1, e, !1);
- }
- if (e > 0) {
- this.clearCachedConvexTrianglePillar(t, e - 1, !0);
- this.clearCachedConvexTrianglePillar(t, e - 1, !1);
- }
- e > 0 && t > 0 && this.clearCachedConvexTrianglePillar(t - 1, e - 1, !0);
- };
- s.prototype.getRectMinMax = function(t, e, i, o, n) {
- n = n || [];
- for (var r = this.data, s = this.minValue, a = t; a <= i; a++) for (var l = e; l <= o; l++) {
- var h = r[a][l];
- h > s && (s = h);
- }
- n[0] = this.minValue;
- n[1] = s;
- };
- s.prototype.getIndexOfPosition = function(t, e, i, o) {
- var n = this.elementSize, r = this.data, s = Math.floor(t / n), a = Math.floor(e / n);
- i[0] = s;
- i[1] = a;
- if (o) {
- s < 0 && (s = 0);
- a < 0 && (a = 0);
- s >= r.length - 1 && (s = r.length - 1);
- a >= r[0].length - 1 && (a = r[0].length - 1);
- }
- return !(s < 0 || a < 0 || s >= r.length - 1 || a >= r[0].length - 1);
- };
- var a = [], l = new n(), h = new n(), c = new n(), u = new n();
- s.prototype.getTriangleAt = function(t, e, i, o, n, r) {
- var s = a;
- this.getIndexOfPosition(t, e, s, i);
- var l = s[0], h = s[1], c = this.data;
- if (i) {
- l = Math.min(c.length - 2, Math.max(0, l));
- h = Math.min(c[0].length - 2, Math.max(0, h));
- }
- var u = this.elementSize, p = Math.pow(t / u - l, 2) + Math.pow(e / u - h, 2) > Math.pow(t / u - (l + 1), 2) + Math.pow(e / u - (h + 1), 2);
- this.getTriangle(l, h, p, o, n, r);
- return p;
- };
- var p = new n(), d = new n(), y = new n(), f = new n(), v = new n();
- s.prototype.getNormalAt = function(t, e, i, o) {
- var n = p, r = d, s = y, a = f, l = v;
- this.getTriangleAt(t, e, i, n, r, s);
- r.vsub(n, a);
- s.vsub(n, l);
- a.cross(l, o);
- o.normalize();
- };
- s.prototype.getAabbAtIndex = function(t, e, i) {
- var o = this.data, n = this.elementSize;
- i.lowerBound.set(t * n, e * n, o[t][e]);
- i.upperBound.set((t + 1) * n, (e + 1) * n, o[t + 1][e + 1]);
- };
- s.prototype.getHeightAt = function(t, e, i) {
- var o = this.data, n = h, r = c, s = u, p = a;
- this.getIndexOfPosition(t, e, p, i);
- var d = p[0], y = p[1];
- if (i) {
- d = Math.min(o.length - 2, Math.max(0, d));
- y = Math.min(o[0].length - 2, Math.max(0, y));
- }
- var f = this.getTriangleAt(t, e, i, n, r, s);
- m(t, e, n.x, n.y, r.x, r.y, s.x, s.y, l);
- var v = l;
- return f ? o[d + 1][y + 1] * v.x + o[d][y + 1] * v.y + o[d + 1][y] * v.z : o[d][y] * v.x + o[d + 1][y] * v.y + o[d][y + 1] * v.z;
- };
- function m(t, e, i, o, n, r, s, a, l) {
- l.x = ((r - a) * (t - s) + (s - n) * (e - a)) / ((r - a) * (i - s) + (s - n) * (o - a));
- l.y = ((a - o) * (t - s) + (i - s) * (e - a)) / ((r - a) * (i - s) + (s - n) * (o - a));
- l.z = 1 - l.x - l.y;
- }
- s.prototype.getCacheConvexTrianglePillarKey = function(t, e, i) {
- return t + "_" + e + "_" + (i ? 1 : 0);
- };
- s.prototype.getCachedConvexTrianglePillar = function(t, e, i) {
- return this._cachedPillars[this.getCacheConvexTrianglePillarKey(t, e, i)];
- };
- s.prototype.setCachedConvexTrianglePillar = function(t, e, i, o, n) {
- this._cachedPillars[this.getCacheConvexTrianglePillarKey(t, e, i)] = {
- convex: o,
- offset: n
- };
- };
- s.prototype.clearCachedConvexTrianglePillar = function(t, e, i) {
- delete this._cachedPillars[this.getCacheConvexTrianglePillarKey(t, e, i)];
- };
- s.prototype.getTriangle = function(t, e, i, o, n, r) {
- var s = this.data, a = this.elementSize;
- if (i) {
- o.set((t + 1) * a, (e + 1) * a, s[t + 1][e + 1]);
- n.set(t * a, (e + 1) * a, s[t][e + 1]);
- r.set((t + 1) * a, e * a, s[t + 1][e]);
- } else {
- o.set(t * a, e * a, s[t][e]);
- n.set((t + 1) * a, e * a, s[t + 1][e]);
- r.set(t * a, (e + 1) * a, s[t][e + 1]);
- }
- };
- s.prototype.getConvexTrianglePillar = function(t, e, i) {
- var r = this.pillarConvex, s = this.pillarOffset;
- if (this.cacheEnabled) {
- if (a = this.getCachedConvexTrianglePillar(t, e, i)) {
- this.pillarConvex = a.convex;
- this.pillarOffset = a.offset;
- return;
- }
- r = new o();
- s = new n();
- this.pillarConvex = r;
- this.pillarOffset = s;
- }
- var a = this.data, l = this.elementSize, h = r.faces;
- r.vertices.length = 6;
- for (var c = 0; c < 6; c++) r.vertices[c] || (r.vertices[c] = new n());
- h.length = 5;
- for (c = 0; c < 5; c++) h[c] || (h[c] = []);
- var u = r.vertices, p = (Math.min(a[t][e], a[t + 1][e], a[t][e + 1], a[t + 1][e + 1]) - this.minValue) / 2 + this.minValue;
- if (i) {
- s.set((t + .75) * l, (e + .75) * l, p);
- u[0].set(.25 * l, .25 * l, a[t + 1][e + 1] - p);
- u[1].set(-.75 * l, .25 * l, a[t][e + 1] - p);
- u[2].set(.25 * l, -.75 * l, a[t + 1][e] - p);
- u[3].set(.25 * l, .25 * l, -p - 1);
- u[4].set(-.75 * l, .25 * l, -p - 1);
- u[5].set(.25 * l, -.75 * l, -p - 1);
- h[0][0] = 0;
- h[0][1] = 1;
- h[0][2] = 2;
- h[1][0] = 5;
- h[1][1] = 4;
- h[1][2] = 3;
- h[2][0] = 2;
- h[2][1] = 5;
- h[2][2] = 3;
- h[2][3] = 0;
- h[3][0] = 3;
- h[3][1] = 4;
- h[3][2] = 1;
- h[3][3] = 0;
- h[4][0] = 1;
- h[4][1] = 4;
- h[4][2] = 5;
- h[4][3] = 2;
- } else {
- s.set((t + .25) * l, (e + .25) * l, p);
- u[0].set(-.25 * l, -.25 * l, a[t][e] - p);
- u[1].set(.75 * l, -.25 * l, a[t + 1][e] - p);
- u[2].set(-.25 * l, .75 * l, a[t][e + 1] - p);
- u[3].set(-.25 * l, -.25 * l, -p - 1);
- u[4].set(.75 * l, -.25 * l, -p - 1);
- u[5].set(-.25 * l, .75 * l, -p - 1);
- h[0][0] = 0;
- h[0][1] = 1;
- h[0][2] = 2;
- h[1][0] = 5;
- h[1][1] = 4;
- h[1][2] = 3;
- h[2][0] = 0;
- h[2][1] = 2;
- h[2][2] = 5;
- h[2][3] = 3;
- h[3][0] = 1;
- h[3][1] = 0;
- h[3][2] = 3;
- h[3][3] = 4;
- h[4][0] = 4;
- h[4][1] = 5;
- h[4][2] = 2;
- h[4][3] = 1;
- }
- r.computeNormals();
- r.computeEdges();
- r.updateBoundingSphereRadius();
- this.setCachedConvexTrianglePillar(t, e, i, r, s);
- };
- s.prototype.calculateLocalInertia = function(t, e) {
- (e = e || new n()).set(0, 0, 0);
- return e;
- };
- s.prototype.volume = function() {
- return Number.MAX_VALUE;
- };
- s.prototype.calculateWorldAABB = function(t, e, i, o) {
- i.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
- o.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
- };
- s.prototype.updateBoundingSphereRadius = function() {
- var t = this.data, e = this.elementSize;
- this.boundingSphereRadius = new n(t.length * e, t[0].length * e, Math.max(Math.abs(this.maxValue), Math.abs(this.minValue))).norm();
- };
- s.prototype.setHeightsFromImage = function(t, e) {
- var i = document.createElement("canvas");
- i.width = t.width;
- i.height = t.height;
- var o = i.getContext("2d");
- o.drawImage(t, 0, 0);
- var n = o.getImageData(0, 0, t.width, t.height), r = this.data;
- r.length = 0;
- this.elementSize = Math.abs(e.x) / n.width;
- for (var s = 0; s < n.height; s++) {
- for (var a = [], l = 0; l < n.width; l++) {
- var h = (n.data[4 * (s * n.height + l)] + n.data[4 * (s * n.height + l) + 1] + n.data[4 * (s * n.height + l) + 2]) / 4 / 255 * e.z;
- e.x < 0 ? a.push(h) : a.unshift(h);
- }
- e.y < 0 ? r.unshift(a) : r.push(a);
- }
- this.updateMaxValue();
- this.updateMinValue();
- this.update();
- };
- }, {
- "../math/Vec3": 32,
- "../utils/Utils": 55,
- "./ConvexPolyhedron": 40,
- "./Shape": 45
- } ],
- 43: [ function(t, e) {
- e.exports = n;
- var i = t("./Shape"), o = t("../math/Vec3");
- function n() {
- i.call(this, {
- type: i.types.PARTICLE
- });
- }
- n.prototype = new i();
- n.prototype.constructor = n;
- n.prototype.calculateLocalInertia = function(t, e) {
- (e = e || new o()).set(0, 0, 0);
- return e;
- };
- n.prototype.volume = function() {
- return 0;
- };
- n.prototype.updateBoundingSphereRadius = function() {
- this.boundingSphereRadius = 0;
- };
- n.prototype.calculateWorldAABB = function(t, e, i, o) {
- i.copy(t);
- o.copy(t);
- };
- }, {
- "../math/Vec3": 32,
- "./Shape": 45
- } ],
- 44: [ function(t, e) {
- e.exports = n;
- var i = t("./Shape"), o = t("../math/Vec3");
- function n() {
- i.call(this, {
- type: i.types.PLANE
- });
- this.worldNormal = new o();
- this.worldNormalNeedsUpdate = !0;
- this.boundingSphereRadius = Number.MAX_VALUE;
- }
- n.prototype = new i();
- n.prototype.constructor = n;
- n.prototype.computeWorldNormal = function(t) {
- var e = this.worldNormal;
- e.set(0, 0, 1);
- t.vmult(e, e);
- this.worldNormalNeedsUpdate = !1;
- };
- n.prototype.calculateLocalInertia = function(t, e) {
- return e || new o();
- };
- n.prototype.volume = function() {
- return Number.MAX_VALUE;
- };
- var r = new o();
- n.prototype.calculateWorldAABB = function(t, e, i, o) {
- r.set(0, 0, 1);
- e.vmult(r, r);
- var n = Number.MAX_VALUE;
- i.set(-n, -n, -n);
- o.set(n, n, n);
- 1 === r.x && (o.x = t.x);
- 1 === r.y && (o.y = t.y);
- 1 === r.z && (o.z = t.z);
- -1 === r.x && (i.x = t.x);
- -1 === r.y && (i.y = t.y);
- -1 === r.z && (i.z = t.z);
- };
- n.prototype.updateBoundingSphereRadius = function() {
- this.boundingSphereRadius = Number.MAX_VALUE;
- };
- }, {
- "../math/Vec3": 32,
- "./Shape": 45
- } ],
- 45: [ function(t, e) {
- e.exports = o;
- var i = t("../utils/EventTarget"), o = t("./Shape");
- t("../math/Vec3"), t("../math/Quaternion"), t("../material/Material");
- function o(t) {
- t = t || {};
- i.apply(this);
- this.id = o.idCounter++;
- this.type = t.type || 0;
- this.boundingSphereRadius = 0;
- this.collisionResponse = !t.collisionResponse || t.collisionResponse;
- this.collisionFilterGroup = void 0 !== t.collisionFilterGroup ? t.collisionFilterGroup : 1;
- this.collisionFilterMask = void 0 !== t.collisionFilterMask ? t.collisionFilterMask : -1;
- this.material = t.material ? t.material : null;
- this.body = null;
- }
- o.prototype = new i();
- o.prototype.constructor = o;
- o.prototype.updateBoundingSphereRadius = function() {
- throw "computeBoundingSphereRadius() not implemented for shape type " + this.type;
- };
- o.prototype.volume = function() {
- throw "volume() not implemented for shape type " + this.type;
- };
- o.prototype.calculateLocalInertia = function() {
- throw "calculateLocalInertia() not implemented for shape type " + this.type;
- };
- o.idCounter = 0;
- o.types = {
- SPHERE: 1,
- PLANE: 2,
- BOX: 4,
- COMPOUND: 8,
- CONVEXPOLYHEDRON: 16,
- HEIGHTFIELD: 32,
- PARTICLE: 64,
- CYLINDER: 128,
- TRIMESH: 256
- };
- }, {
- "../material/Material": 26,
- "../math/Quaternion": 30,
- "../math/Vec3": 32,
- "../utils/EventTarget": 51,
- "./Shape": 45
- } ],
- 46: [ function(t, e) {
- e.exports = n;
- var i = t("./Shape"), o = t("../math/Vec3");
- function n(t) {
- i.call(this, {
- type: i.types.SPHERE
- });
- this.radius = void 0 !== t ? t : 1;
- if (this.radius < 0) throw new Error("The sphere radius cannot be negative.");
- this.updateBoundingSphereRadius();
- }
- n.prototype = new i();
- n.prototype.constructor = n;
- n.prototype.calculateLocalInertia = function(t, e) {
- e = e || new o();
- var i = 2 * t * this.radius * this.radius / 5;
- e.x = i;
- e.y = i;
- e.z = i;
- return e;
- };
- n.prototype.volume = function() {
- return 4 * Math.PI * this.radius / 3;
- };
- n.prototype.updateBoundingSphereRadius = function() {
- this.boundingSphereRadius = this.radius;
- };
- n.prototype.calculateWorldAABB = function(t, e, i, o) {
- for (var n = this.radius, r = [ "x", "y", "z" ], s = 0; s < r.length; s++) {
- var a = r[s];
- i[a] = t[a] - n;
- o[a] = t[a] + n;
- }
- };
- }, {
- "../math/Vec3": 32,
- "./Shape": 45
- } ],
- 47: [ function(t, e) {
- e.exports = l;
- var i = t("./Shape"), o = t("../math/Vec3"), n = (t("../math/Quaternion"), t("../math/Transform")), r = t("../collision/AABB"), s = t("../utils/Octree"), a = t("../math/CMath");
- function l(t, e) {
- i.call(this, {
- type: i.types.TRIMESH
- });
- this.vertices = new Float32Array(t);
- this.indices = new Int16Array(e);
- this.normals = new Float32Array(e.length);
- this.aabb = new r();
- this.edges = null;
- this.scale = new o(1, 1, 1);
- this.tree = new s();
- this.updateEdges();
- this.updateNormals();
- this.updateAABB();
- this.updateBoundingSphereRadius();
- this.updateTree();
- }
- l.prototype = new i();
- l.prototype.constructor = l;
- var h = new o();
- l.prototype.updateTree = function() {
- var t = this.tree;
- t.reset();
- t.aabb.copy(this.aabb);
- var e = this.scale;
- t.aabb.lowerBound.x *= 1 / e.x;
- t.aabb.lowerBound.y *= 1 / e.y;
- t.aabb.lowerBound.z *= 1 / e.z;
- t.aabb.upperBound.x *= 1 / e.x;
- t.aabb.upperBound.y *= 1 / e.y;
- t.aabb.upperBound.z *= 1 / e.z;
- for (var i = new r(), n = new o(), s = new o(), a = new o(), l = [ n, s, a ], h = 0; h < this.indices.length / 3; h++) {
- var c = 3 * h;
- this._getUnscaledVertex(this.indices[c], n);
- this._getUnscaledVertex(this.indices[c + 1], s);
- this._getUnscaledVertex(this.indices[c + 2], a);
- i.setFromPoints(l);
- t.insert(i, h);
- }
- t.removeEmptyNodes();
- };
- var c = new r();
- l.prototype.getTrianglesInAABB = function(t, e) {
- c.copy(t);
- var i = this.scale, o = i.x, n = i.y, r = i.z, s = c.lowerBound, a = c.upperBound;
- s.x /= o;
- s.y /= n;
- s.z /= r;
- a.x /= o;
- a.y /= n;
- a.z /= r;
- return this.tree.aabbQuery(c, e);
- };
- l.prototype.setScale = function(t) {
- var e = this.scale.x === this.scale.y === this.scale.z, i = t.x === t.y === t.z;
- e && i || this.updateNormals();
- this.scale.copy(t);
- this.updateAABB();
- this.updateBoundingSphereRadius();
- };
- l.prototype.updateNormals = function() {
- for (var t = h, e = this.normals, i = 0; i < this.indices.length / 3; i++) {
- var o = 3 * i, n = this.indices[o], r = this.indices[o + 1], s = this.indices[o + 2];
- this.getVertex(n, f);
- this.getVertex(r, v);
- this.getVertex(s, m);
- l.computeNormal(v, f, m, t);
- e[o] = t.x;
- e[o + 1] = t.y;
- e[o + 2] = t.z;
- }
- };
- l.prototype.updateEdges = function() {
- for (var t = {}, e = function() {
- t[n < r ? n + "_" + r : r + "_" + n] = !0;
- }, i = 0; i < this.indices.length / 3; i++) {
- var o = 3 * i, n = this.indices[o], r = this.indices[o + 1];
- this.indices[o + 2];
- e();
- e();
- e();
- }
- var s = Object.keys(t);
- this.edges = new Int16Array(2 * s.length);
- for (i = 0; i < s.length; i++) {
- var a = s[i].split("_");
- this.edges[2 * i] = parseInt(a[0], 10);
- this.edges[2 * i + 1] = parseInt(a[1], 10);
- }
- };
- l.prototype.getEdgeVertex = function(t, e, i) {
- var o = this.edges[2 * t + (e ? 1 : 0)];
- this.getVertex(o, i);
- };
- var u = new o(), p = new o();
- l.prototype.getEdgeVector = function(t, e) {
- var i = u, o = p;
- this.getEdgeVertex(t, 0, i);
- this.getEdgeVertex(t, 1, o);
- o.vsub(i, e);
- };
- var d = new o(), y = new o();
- l.computeNormal = function(t, e, i, o) {
- e.vsub(t, y);
- i.vsub(e, d);
- d.cross(y, o);
- o.isZero() || o.normalize();
- };
- var f = new o(), v = new o(), m = new o();
- l.prototype.getVertex = function(t, e) {
- var i = this.scale;
- this._getUnscaledVertex(t, e);
- e.x *= i.x;
- e.y *= i.y;
- e.z *= i.z;
- return e;
- };
- l.prototype._getUnscaledVertex = function(t, e) {
- var i = 3 * t, o = this.vertices;
- return e.set(o[i], o[i + 1], o[i + 2]);
- };
- l.prototype.getWorldVertex = function(t, e, i, o) {
- this.getVertex(t, o);
- n.pointToWorldFrame(e, i, o, o);
- return o;
- };
- l.prototype.getTriangleVertices = function(t, e, i, o) {
- var n = 3 * t;
- this.getVertex(this.indices[n], e);
- this.getVertex(this.indices[n + 1], i);
- this.getVertex(this.indices[n + 2], o);
- };
- l.prototype.getNormal = function(t, e) {
- var i = 3 * t;
- return e.set(this.normals[i], this.normals[i + 1], this.normals[i + 2]);
- };
- var g = new r();
- l.prototype.calculateLocalInertia = function(t, e) {
- this.computeLocalAABB(g);
- var i = g.upperBound.x - g.lowerBound.x, o = g.upperBound.y - g.lowerBound.y, n = g.upperBound.z - g.lowerBound.z;
- return e.set(1 / 12 * t * (4 * o * o + 4 * n * n), 1 / 12 * t * (4 * i * i + 4 * n * n), 1 / 12 * t * (4 * o * o + 4 * i * i));
- };
- var b = new o();
- l.prototype.computeLocalAABB = function(t) {
- var e = t.lowerBound, i = t.upperBound, o = this.vertices.length, n = (this.vertices,
- b);
- this.getVertex(0, n);
- e.copy(n);
- i.copy(n);
- for (var r = 0; r !== o; r++) {
- this.getVertex(r, n);
- n.x < e.x ? e.x = n.x : n.x > i.x && (i.x = n.x);
- n.y < e.y ? e.y = n.y : n.y > i.y && (i.y = n.y);
- n.z < e.z ? e.z = n.z : n.z > i.z && (i.z = n.z);
- }
- };
- l.prototype.updateAABB = function() {
- this.computeLocalAABB(this.aabb);
- };
- l.prototype.updateBoundingSphereRadius = function() {
- for (var t = 0, e = this.vertices, i = new o(), n = 0, r = e.length / 3; n !== r; n++) {
- this.getVertex(n, i);
- var s = i.norm2();
- s > t && (t = s);
- }
- this.boundingSphereRadius = Math.sqrt(t);
- };
- new o();
- var w = new n(), x = new r();
- l.prototype.calculateWorldAABB = function(t, e, i, o) {
- var n = w, r = x;
- n.position = t;
- n.quaternion = e;
- this.aabb.toWorldFrame(n, r);
- i.copy(r.lowerBound);
- o.copy(r.upperBound);
- };
- l.prototype.volume = function() {
- return 4 * Math.PI * this.boundingSphereRadius / 3;
- };
- l.createTorus = function(t, e, i, o, n) {
- t = t || 1;
- e = e || .5;
- i = i || 8;
- o = o || 6;
- n = n || 2 * Math.PI;
- for (var r = [], s = [], h = 0; h <= i; h++) for (var c = 0; c <= o; c++) {
- var u = c / o * n, p = h / i * Math.PI * 2, d = (t + e * a.cos(p)) * a.cos(u), y = (t + e * a.cos(p)) * a.sin(u), f = e * a.sin(p);
- r.push(d, y, f);
- }
- for (h = 1; h <= i; h++) for (c = 1; c <= o; c++) {
- var v = (o + 1) * h + c - 1, m = (o + 1) * (h - 1) + c - 1, g = (o + 1) * (h - 1) + c, b = (o + 1) * h + c;
- s.push(v, m, b);
- s.push(m, g, b);
- }
- return new l(r, s);
- };
- }, {
- "../collision/AABB": 3,
- "../math/CMath": 27,
- "../math/Quaternion": 30,
- "../math/Transform": 31,
- "../math/Vec3": 32,
- "../utils/Octree": 52,
- "./Shape": 45
- } ],
- 48: [ function(t, e) {
- e.exports = o;
- t("../math/Vec3"), t("../math/Quaternion");
- var i = t("./Solver");
- function o() {
- i.call(this);
- this.iterations = 10;
- this.tolerance = 1e-7;
- }
- o.prototype = new i();
- var n = [], r = [], s = [];
- o.prototype.solve = function(t, e) {
- var i, o, a, l, h, c = 0, u = this.iterations, p = this.tolerance * this.tolerance, d = this.equations, y = d.length, f = e.bodies, v = f.length, m = t;
- if (0 !== y) for (var g = 0; g !== v; g++) f[g].updateSolveMassProperties();
- var b = r, w = s, x = n;
- b.length = y;
- w.length = y;
- x.length = y;
- for (g = 0; g !== y; g++) {
- var _ = d[g];
- x[g] = 0;
- w[g] = _.computeB(m);
- b[g] = 1 / _.computeC();
- }
- if (0 !== y) {
- for (g = 0; g !== v; g++) {
- var B = (M = f[g]).vlambda, S = M.wlambda;
- B.set(0, 0, 0);
- S.set(0, 0, 0);
- }
- for (c = 0; c !== u; c++) {
- l = 0;
- for (var E = 0; E !== y; E++) {
- _ = d[E];
- i = w[E];
- o = b[E];
- (h = x[E]) + (a = o * (i - _.computeGWlambda() - _.eps * h)) < _.minForce ? a = _.minForce - h : h + a > _.maxForce && (a = _.maxForce - h);
- x[E] += a;
- l += a > 0 ? a : -a;
- _.addToWlambda(a);
- }
- if (l * l < p) break;
- }
- for (g = 0; g !== v; g++) {
- var M, C = (M = f[g]).velocity, A = M.angularVelocity;
- M.vlambda.vmul(M.linearFactor, M.vlambda);
- C.vadd(M.vlambda, C);
- M.wlambda.vmul(M.angularFactor, M.wlambda);
- A.vadd(M.wlambda, A);
- }
- for (var z = d.length, F = 1 / m; z--; ) d[z].multiplier = x[z] * F;
- }
- return c;
- };
- }, {
- "../math/Quaternion": 30,
- "../math/Vec3": 32,
- "./Solver": 49
- } ],
- 49: [ function(t, e) {
- e.exports = i;
- function i() {
- this.equations = [];
- }
- i.prototype.solve = function() {
- return 0;
- };
- i.prototype.addEquation = function(t) {
- t.enabled && this.equations.push(t);
- };
- i.prototype.removeEquation = function(t) {
- var e = this.equations, i = e.indexOf(t);
- -1 !== i && e.splice(i, 1);
- };
- i.prototype.removeAllEquations = function() {
- this.equations.length = 0;
- };
- }, {} ],
- 50: [ function(t, e) {
- e.exports = n;
- t("../math/Vec3"), t("../math/Quaternion");
- var i = t("./Solver"), o = t("../objects/Body");
- function n(t) {
- i.call(this);
- this.iterations = 10;
- this.tolerance = 1e-7;
- this.subsolver = t;
- this.nodes = [];
- this.nodePool = [];
- for (;this.nodePool.length < 128; ) this.nodePool.push(this.createNode());
- }
- n.prototype = new i();
- var r = [], s = [], a = {
- bodies: []
- }, l = o.STATIC;
- function h(t) {
- for (var e = t.length, i = 0; i !== e; i++) {
- var o = t[i];
- if (!(o.visited || o.body.type & l)) return o;
- }
- return !1;
- }
- var c = [];
- function u(t, e, i, o) {
- c.push(t);
- t.visited = !0;
- e(t, i, o);
- for (;c.length; ) for (var n, r = c.pop(); n = h(r.children); ) {
- n.visited = !0;
- e(n, i, o);
- c.push(n);
- }
- }
- function p(t, e, i) {
- e.push(t.body);
- for (var o = t.eqs.length, n = 0; n !== o; n++) {
- var r = t.eqs[n];
- -1 === i.indexOf(r) && i.push(r);
- }
- }
- n.prototype.createNode = function() {
- return {
- body: null,
- children: [],
- eqs: [],
- visited: !1
- };
- };
- n.prototype.solve = function(t, e) {
- for (var i = r, o = this.nodePool, n = e.bodies, l = this.equations, c = l.length, y = n.length, f = this.subsolver; o.length < y; ) o.push(this.createNode());
- i.length = y;
- for (var v = 0; v < y; v++) i[v] = o[v];
- for (v = 0; v !== y; v++) {
- var m = i[v];
- m.body = n[v];
- m.children.length = 0;
- m.eqs.length = 0;
- m.visited = !1;
- }
- for (var g = 0; g !== c; g++) {
- var b = l[g], w = (v = n.indexOf(b.bi), n.indexOf(b.bj)), x = i[v], _ = i[w];
- x.children.push(_);
- x.eqs.push(b);
- _.children.push(x);
- _.eqs.push(b);
- }
- var B, S = 0, E = s;
- f.tolerance = this.tolerance;
- f.iterations = this.iterations;
- for (var M = a; B = h(i); ) {
- E.length = 0;
- M.bodies.length = 0;
- u(B, p, M.bodies, E);
- var C = E.length;
- E = E.sort(d);
- for (v = 0; v !== C; v++) f.addEquation(E[v]);
- f.solve(t, M);
- f.removeAllEquations();
- S++;
- }
- return S;
- };
- function d(t, e) {
- return e.id - t.id;
- }
- }, {
- "../math/Quaternion": 30,
- "../math/Vec3": 32,
- "../objects/Body": 33,
- "./Solver": 49
- } ],
- 51: [ function(t, e) {
- var i = function() {};
- e.exports = i;
- i.prototype = {
- constructor: i,
- addEventListener: function(t, e) {
- void 0 === this._listeners && (this._listeners = {});
- var i = this._listeners;
- void 0 === i[t] && (i[t] = []);
- -1 === i[t].indexOf(e) && i[t].push(e);
- return this;
- },
- hasEventListener: function(t, e) {
- if (void 0 === this._listeners) return !1;
- var i = this._listeners;
- return void 0 !== i[t] && -1 !== i[t].indexOf(e);
- },
- hasAnyEventListener: function(t) {
- return void 0 !== this._listeners && void 0 !== this._listeners[t];
- },
- removeEventListener: function(t, e) {
- if (void 0 === this._listeners) return this;
- var i = this._listeners;
- if (void 0 === i[t]) return this;
- var o = i[t].indexOf(e);
- -1 !== o && i[t].splice(o, 1);
- return this;
- },
- dispatchEvent: function(t) {
- if (void 0 === this._listeners) return this;
- var e = this._listeners[t.type];
- if (void 0 !== e) {
- t.target = this;
- for (var i = 0, o = e.length; i < o; i++) e[i].call(this, t);
- }
- return this;
- }
- };
- }, {} ],
- 52: [ function(t, e) {
- var i = t("../collision/AABB"), o = t("../math/Vec3");
- e.exports = r;
- function n(t) {
- t = t || {};
- this.root = t.root || null;
- this.aabb = t.aabb ? t.aabb.clone() : new i();
- this.data = [];
- this.children = [];
- }
- function r(t, e) {
- (e = e || {}).root = null;
- e.aabb = t;
- n.call(this, e);
- this.maxDepth = "undefined" != typeof e.maxDepth ? e.maxDepth : 8;
- }
- r.prototype = new n();
- n.prototype.reset = function() {
- this.children.length = this.data.length = 0;
- };
- n.prototype.insert = function(t, e, i) {
- var o = this.data;
- i = i || 0;
- if (!this.aabb.contains(t)) return !1;
- var n = this.children;
- if (i < (this.maxDepth || this.root.maxDepth)) {
- var r = !1;
- if (!n.length) {
- this.subdivide();
- r = !0;
- }
- for (var s = 0; 8 !== s; s++) if (n[s].insert(t, e, i + 1)) return !0;
- r && (n.length = 0);
- }
- o.push(e);
- return !0;
- };
- var s = new o();
- n.prototype.subdivide = function() {
- var t = this.aabb, e = t.lowerBound, r = t.upperBound, a = this.children;
- a.push(new n({
- aabb: new i({
- lowerBound: new o(0, 0, 0)
- })
- }), new n({
- aabb: new i({
- lowerBound: new o(1, 0, 0)
- })
- }), new n({
- aabb: new i({
- lowerBound: new o(1, 1, 0)
- })
- }), new n({
- aabb: new i({
- lowerBound: new o(1, 1, 1)
- })
- }), new n({
- aabb: new i({
- lowerBound: new o(0, 1, 1)
- })
- }), new n({
- aabb: new i({
- lowerBound: new o(0, 0, 1)
- })
- }), new n({
- aabb: new i({
- lowerBound: new o(1, 0, 1)
- })
- }), new n({
- aabb: new i({
- lowerBound: new o(0, 1, 0)
- })
- }));
- r.vsub(e, s);
- s.scale(.5, s);
- for (var l = this.root || this, h = 0; 8 !== h; h++) {
- var c = a[h];
- c.root = l;
- var u = c.aabb.lowerBound;
- u.x *= s.x;
- u.y *= s.y;
- u.z *= s.z;
- u.vadd(e, u);
- u.vadd(s, c.aabb.upperBound);
- }
- };
- n.prototype.aabbQuery = function(t, e) {
- this.data, this.children;
- for (var i = [ this ]; i.length; ) {
- var o = i.pop();
- o.aabb.overlaps(t) && Array.prototype.push.apply(e, o.data);
- Array.prototype.push.apply(i, o.children);
- }
- return e;
- };
- var a = new i();
- n.prototype.rayQuery = function(t, e, i) {
- t.getAABB(a);
- a.toLocalFrame(e, a);
- this.aabbQuery(a, i);
- return i;
- };
- n.prototype.removeEmptyNodes = function() {
- for (var t = this.children.length - 1; t >= 0; t--) {
- this.children[t].removeEmptyNodes();
- this.children[t].children.length || this.children[t].data.length || this.children.splice(t, 1);
- }
- };
- }, {
- "../collision/AABB": 3,
- "../math/Vec3": 32
- } ],
- 53: [ function(t, e) {
- e.exports = i;
- function i() {
- this.objects = [];
- this.type = Object;
- }
- i.prototype.release = function() {
- for (var t = arguments.length, e = 0; e !== t; e++) this.objects.push(arguments[e]);
- return this;
- };
- i.prototype.get = function() {
- return 0 === this.objects.length ? this.constructObject() : this.objects.pop();
- };
- i.prototype.constructObject = function() {
- throw new Error("constructObject() not implemented in this Pool subclass yet!");
- };
- i.prototype.resize = function(t) {
- for (var e = this.objects; e.length > t; ) e.pop();
- for (;e.length < t; ) e.push(this.constructObject());
- return this;
- };
- }, {} ],
- 54: [ function(t, e) {
- e.exports = i;
- function i() {
- this.data = {
- keys: []
- };
- }
- i.prototype.get = function(t, e) {
- if (t > e) {
- var i = e;
- e = t;
- t = i;
- }
- return this.data[t + "-" + e];
- };
- i.prototype.set = function(t, e, i) {
- if (t > e) {
- var o = e;
- e = t;
- t = o;
- }
- var n = t + "-" + e;
- this.get(t, e) || this.data.keys.push(n);
- this.data[n] = i;
- return this.data[n];
- };
- i.prototype.del = function(t, e) {
- if (t > e) {
- var i = e;
- e = t;
- t = i;
- }
- var o = t + "-" + e, n = this.data.keys.indexOf(o);
- if (n >= 0) {
- this.data.keys.splice(n, 1);
- delete this.data[o];
- return !0;
- }
- return !1;
- };
- i.prototype.reset = function() {
- this.data = {
- keys: []
- };
- };
- i.prototype.getLength = function() {
- return this.data.keys.length;
- };
- i.prototype.getKeyByIndex = function(t) {
- return this.data.keys[t];
- };
- i.prototype.getDataByKey = function(t) {
- return this.data[t];
- };
- }, {} ],
- 55: [ function(t, e) {
- function i() {}
- e.exports = i;
- i.defaults = function(t, e) {
- t = t || {};
- for (var i in e) i in t || (t[i] = e[i]);
- return t;
- };
- }, {} ],
- 56: [ function(t, e) {
- e.exports = n;
- var i = t("../math/Vec3"), o = t("./Pool");
- function n() {
- o.call(this);
- this.type = i;
- }
- n.prototype = new o();
- n.prototype.constructObject = function() {
- return new i();
- };
- }, {
- "../math/Vec3": 32,
- "./Pool": 53
- } ],
- 57: [ function(t, e) {
- e.exports = p;
- var i = t("../collision/AABB"), o = t("../objects/Body"), n = t("../shapes/Shape"), r = t("../collision/Ray"), s = t("../math/Vec3"), a = t("../math/Transform"), l = (t("../shapes/ConvexPolyhedron"),
- t("../math/Quaternion")), h = (t("../solver/Solver"), t("../utils/Vec3Pool")), c = t("../equations/ContactEquation"), u = t("../equations/FrictionEquation");
- function p(t) {
- this.contactPointPool = [];
- this.frictionEquationPool = [];
- this.result = [];
- this.frictionResult = [];
- this.v3pool = new h();
- this.world = t;
- this.currentContactMaterial = null;
- this.enableFrictionReduction = !1;
- }
- p.prototype.createContactEquation = function(t, e, i, o, n, r) {
- var s;
- if (this.contactPointPool.length) {
- (s = this.contactPointPool.pop()).bi = t;
- s.bj = e;
- } else s = new c(t, e);
- s.enabled = t.collisionResponse && e.collisionResponse && i.collisionResponse && o.collisionResponse;
- var a = this.currentContactMaterial;
- s.restitution = a.restitution;
- s.setSpookParams(a.contactEquationStiffness, a.contactEquationRelaxation, this.world.dt);
- var l = i.material || t.material, h = o.material || e.material;
- l && h && l.restitution >= 0 && h.restitution >= 0 && (s.restitution = l.restitution * h.restitution);
- s.si = n || i;
- s.sj = r || o;
- return s;
- };
- p.prototype.createFrictionEquationsFromContact = function(t, e) {
- var i = t.bi, o = t.bj, n = t.si, r = t.sj, s = this.world, a = this.currentContactMaterial, l = a.friction, h = n.material || i.material, c = r.material || o.material;
- h && c && h.friction >= 0 && c.friction >= 0 && (l = h.friction * c.friction);
- if (l > 0) {
- var p = l * s.gravity.length(), d = i.invMass + o.invMass;
- d > 0 && (d = 1 / d);
- var y = this.frictionEquationPool, f = y.length ? y.pop() : new u(i, o, p * d), v = y.length ? y.pop() : new u(i, o, p * d);
- f.bi = v.bi = i;
- f.bj = v.bj = o;
- f.minForce = v.minForce = -p * d;
- f.maxForce = v.maxForce = p * d;
- f.ri.copy(t.ri);
- f.rj.copy(t.rj);
- v.ri.copy(t.ri);
- v.rj.copy(t.rj);
- t.ni.tangents(f.t, v.t);
- f.setSpookParams(a.frictionEquationStiffness, a.frictionEquationRelaxation, s.dt);
- v.setSpookParams(a.frictionEquationStiffness, a.frictionEquationRelaxation, s.dt);
- f.enabled = v.enabled = t.enabled;
- e.push(f, v);
- return !0;
- }
- return !1;
- };
- var d = new s(), y = new s(), f = new s();
- p.prototype.createFrictionFromAverage = function(t) {
- var e = this.result[this.result.length - 1];
- if (this.createFrictionEquationsFromContact(e, this.frictionResult) && 1 !== t) {
- var i = this.frictionResult[this.frictionResult.length - 2], o = this.frictionResult[this.frictionResult.length - 1];
- d.setZero();
- y.setZero();
- f.setZero();
- for (var n = e.bi, r = (e.bj, 0); r !== t; r++) if ((e = this.result[this.result.length - 1 - r]).bodyA !== n) {
- d.vadd(e.ni, d);
- y.vadd(e.ri, y);
- f.vadd(e.rj, f);
- } else {
- d.vsub(e.ni, d);
- y.vadd(e.rj, y);
- f.vadd(e.ri, f);
- }
- var s = 1 / t;
- y.scale(s, i.ri);
- f.scale(s, i.rj);
- o.ri.copy(i.ri);
- o.rj.copy(i.rj);
- d.normalize();
- d.tangents(i.t, o.t);
- }
- };
- var v = new s(), m = new s(), g = new l(), b = new l();
- p.prototype.getContacts = function(t, e, i, n, r, s, a) {
- this.contactPointPool = r;
- this.frictionEquationPool = a;
- this.result = n;
- this.frictionResult = s;
- for (var l = g, h = b, c = v, u = m, p = 0, d = t.length; p !== d; p++) {
- var y = t[p], f = e[p], w = null;
- y.material && f.material && (w = i.getContactMaterial(y.material, f.material) || null);
- for (var x = 0 == y.collisionResponse || 0 == f.collisionResponse || y.type & o.KINEMATIC && f.type & o.STATIC || y.type & o.STATIC && f.type & o.KINEMATIC || y.type & o.KINEMATIC && f.type & o.KINEMATIC, _ = 0; _ < y.shapes.length; _++) {
- y.quaternion.mult(y.shapeOrientations[_], l);
- y.quaternion.vmult(y.shapeOffsets[_], c);
- c.vadd(y.position, c);
- for (var B = y.shapes[_], S = 0; S < f.shapes.length; S++) {
- f.quaternion.mult(f.shapeOrientations[S], h);
- f.quaternion.vmult(f.shapeOffsets[S], u);
- u.vadd(f.position, u);
- var E = f.shapes[S];
- if (B.collisionFilterMask & E.collisionFilterGroup && E.collisionFilterMask & B.collisionFilterGroup && !(c.distanceTo(u) > B.boundingSphereRadius + E.boundingSphereRadius)) {
- x |= 0 == B.collisionResponse || 0 == E.collisionResponse;
- var M = null;
- B.material && E.material && (M = i.getContactMaterial(B.material, E.material) || null);
- this.currentContactMaterial = M || w || i.defaultContactMaterial;
- var C = this[B.type | E.type];
- if (C && (B.type < E.type ? C.call(this, B, E, c, u, l, h, y, f, B, E, x) : C.call(this, E, B, u, c, h, l, f, y, B, E, x)) && x) {
- i.shapeOverlapKeeper.set(B.id, E.id);
- i.bodyOverlapKeeper.set(y.id, f.id);
- var A = {
- si: B,
- sj: E
- };
- i.triggerDic.set(B.id, E.id, A);
- i.oldTriggerDic.set(B.id, E.id, A);
- }
- }
- }
- }
- }
- };
- p.prototype[n.types.BOX | n.types.BOX] = p.prototype.boxBox = function(t, e, i, o, n, r, s, a, l, h, c) {
- t.convexPolyhedronRepresentation.material = t.material;
- e.convexPolyhedronRepresentation.material = e.material;
- t.convexPolyhedronRepresentation.collisionResponse = t.collisionResponse;
- e.convexPolyhedronRepresentation.collisionResponse = e.collisionResponse;
- return this.convexConvex(t.convexPolyhedronRepresentation, e.convexPolyhedronRepresentation, i, o, n, r, s, a, t, e, c);
- };
- p.prototype[n.types.BOX | n.types.CONVEXPOLYHEDRON] = p.prototype.boxConvex = function(t, e, i, o, n, r, s, a, l, h, c) {
- t.convexPolyhedronRepresentation.material = t.material;
- t.convexPolyhedronRepresentation.collisionResponse = t.collisionResponse;
- return this.convexConvex(t.convexPolyhedronRepresentation, e, i, o, n, r, s, a, t, e, c);
- };
- p.prototype[n.types.BOX | n.types.PARTICLE] = p.prototype.boxParticle = function(t, e, i, o, n, r, s, a, l, h, c) {
- t.convexPolyhedronRepresentation.material = t.material;
- t.convexPolyhedronRepresentation.collisionResponse = t.collisionResponse;
- return this.convexParticle(t.convexPolyhedronRepresentation, e, i, o, n, r, s, a, t, e, c);
- };
- p.prototype[n.types.SPHERE] = p.prototype.sphereSphere = function(t, e, i, o, n, r, s, a, l, h, c) {
- if (c) return i.distanceSquared(o) < Math.pow(t.radius + e.radius, 2);
- var u = this.createContactEquation(s, a, t, e, l, h);
- o.vsub(i, u.ni);
- u.ni.normalize();
- u.ri.copy(u.ni);
- u.rj.copy(u.ni);
- u.ri.mult(t.radius, u.ri);
- u.rj.mult(-e.radius, u.rj);
- u.ri.vadd(i, u.ri);
- u.ri.vsub(s.position, u.ri);
- u.rj.vadd(o, u.rj);
- u.rj.vsub(a.position, u.rj);
- this.result.push(u);
- this.createFrictionEquationsFromContact(u, this.frictionResult);
- };
- var w = new s(), x = new s(), _ = new s();
- p.prototype[n.types.PLANE | n.types.TRIMESH] = p.prototype.planeTrimesh = function(t, e, i, o, n, r, l, h, c, u, p) {
- var d = new s(), y = w;
- y.set(0, 0, 1);
- n.vmult(y, y);
- for (var f = 0; f < e.vertices.length / 3; f++) {
- e.getVertex(f, d);
- var v = new s();
- v.copy(d);
- a.pointToWorldFrame(o, r, v, d);
- var m = x;
- d.vsub(i, m);
- if (y.dot(m) <= 0) {
- if (p) return !0;
- var g = this.createContactEquation(l, h, t, e, c, u);
- g.ni.copy(y);
- var b = _;
- y.scale(m.dot(y), b);
- d.vsub(b, b);
- g.ri.copy(b);
- g.ri.vsub(l.position, g.ri);
- g.rj.copy(d);
- g.rj.vsub(h.position, g.rj);
- this.result.push(g);
- this.createFrictionEquationsFromContact(g, this.frictionResult);
- }
- }
- };
- var B = new s(), S = new s(), E = (new s(), new s()), M = new s(), C = new s(), A = new s(), z = new s(), F = new s(), R = new s(), T = new s(), P = new s(), q = new s(), I = new s(), O = new i(), V = [];
- p.prototype[n.types.SPHERE | n.types.TRIMESH] = p.prototype.sphereTrimesh = function(t, e, i, o, n, s, l, h, c, u, p) {
- var d = C, y = A, f = z, v = F, m = R, g = T, b = O, w = M, x = S, _ = V;
- a.pointToLocalFrame(o, s, i, m);
- var j = t.radius;
- b.lowerBound.set(m.x - j, m.y - j, m.z - j);
- b.upperBound.set(m.x + j, m.y + j, m.z + j);
- e.getTrianglesInAABB(b, _);
- for (var k = E, N = t.radius * t.radius, L = 0; L < _.length; L++) for (var W = 0; W < 3; W++) {
- e.getVertex(e.indices[3 * _[L] + W], k);
- k.vsub(m, x);
- if (x.norm2() <= N) {
- w.copy(k);
- a.pointToWorldFrame(o, s, w, k);
- k.vsub(i, x);
- if (p) return !0;
- (G = this.createContactEquation(l, h, t, e, c, u)).ni.copy(x);
- G.ni.normalize();
- G.ri.copy(G.ni);
- G.ri.scale(t.radius, G.ri);
- G.ri.vadd(i, G.ri);
- G.ri.vsub(l.position, G.ri);
- G.rj.copy(k);
- G.rj.vsub(h.position, G.rj);
- this.result.push(G);
- this.createFrictionEquationsFromContact(G, this.frictionResult);
- }
- }
- for (L = 0; L < _.length; L++) for (W = 0; W < 3; W++) {
- e.getVertex(e.indices[3 * _[L] + W], d);
- e.getVertex(e.indices[3 * _[L] + (W + 1) % 3], y);
- y.vsub(d, f);
- m.vsub(y, g);
- var D = g.dot(f);
- m.vsub(d, g);
- var U = g.dot(f);
- if (U > 0 && D < 0) {
- m.vsub(d, g);
- v.copy(f);
- v.normalize();
- U = g.dot(v);
- v.scale(U, g);
- g.vadd(d, g);
- if ((Z = g.distanceTo(m)) < t.radius) {
- if (p) return !0;
- var G = this.createContactEquation(l, h, t, e, c, u);
- g.vsub(m, G.ni);
- G.ni.normalize();
- G.ni.scale(t.radius, G.ri);
- a.pointToWorldFrame(o, s, g, g);
- g.vsub(h.position, G.rj);
- a.vectorToWorldFrame(s, G.ni, G.ni);
- a.vectorToWorldFrame(s, G.ri, G.ri);
- this.result.push(G);
- this.createFrictionEquationsFromContact(G, this.frictionResult);
- }
- }
- }
- for (var H = P, K = q, Q = I, X = B, Y = (L = 0, _.length); L !== Y; L++) {
- e.getTriangleVertices(_[L], H, K, Q);
- e.getNormal(_[L], X);
- m.vsub(H, g);
- var Z = g.dot(X);
- X.scale(Z, g);
- m.vsub(g, g);
- Z = g.distanceTo(m);
- if (r.pointInTriangle(g, H, K, Q) && Z < t.radius) {
- if (p) return !0;
- G = this.createContactEquation(l, h, t, e, c, u);
- g.vsub(m, G.ni);
- G.ni.normalize();
- G.ni.scale(t.radius, G.ri);
- a.pointToWorldFrame(o, s, g, g);
- g.vsub(h.position, G.rj);
- a.vectorToWorldFrame(s, G.ni, G.ni);
- a.vectorToWorldFrame(s, G.ri, G.ri);
- this.result.push(G);
- this.createFrictionEquationsFromContact(G, this.frictionResult);
- }
- }
- _.length = 0;
- };
- var j = new s(), k = new s(), N = new s(), L = new s(), W = new s();
- p.prototype[n.types.SPHERE | n.types.PLANE] = p.prototype.spherePlane = function(t, e, i, o, n, r, s, a, l, h, c) {
- N.set(0, 0, 1);
- r.vmult(N, N);
- N.negate(N);
- N.normalize();
- N.mult(t.radius, L);
- i.vsub(o, j);
- N.mult(N.dot(j), k);
- j.vsub(k, W);
- if (-j.dot(N) <= t.radius) {
- if (c) return !0;
- var u = this.createContactEquation(s, a, t, e, l, h);
- u.ni.copy(N);
- u.ri.copy(L);
- u.rj.copy(W);
- var p = u.ri, d = u.rj;
- p.vadd(i, p);
- p.vsub(s.position, p);
- d.vadd(o, d);
- d.vsub(a.position, d);
- this.result.push(u);
- this.createFrictionEquationsFromContact(u, this.frictionResult);
- }
- return !1;
- };
- var D = new s(), U = new s(), G = new s();
- function H(t, e, i) {
- for (var o = null, n = t.length, r = 0; r !== n; r++) {
- var s = t[r], a = D;
- t[(r + 1) % n].vsub(s, a);
- var l = U;
- a.cross(e, l);
- var h = G;
- i.vsub(s, h);
- var c = l.dot(h);
- if (!(null === o || c > 0 && !0 === o || c <= 0 && !1 === o)) return !1;
- null === o && (o = c > 0);
- }
- return !0;
- }
- var K = new s(), Q = new s(), X = new s(), Y = new s(), Z = [ new s(), new s(), new s(), new s(), new s(), new s() ], J = new s(), $ = new s(), tt = new s(), et = new s();
- p.prototype[n.types.SPHERE | n.types.BOX] = p.prototype.sphereBox = function(t, e, i, o, n, r, s, a, l, h, c) {
- var u = this.v3pool, p = Z;
- i.vsub(o, K);
- e.getSideNormals(p, r);
- for (var d = t.radius, y = !1, f = $, v = tt, m = et, g = null, b = 0, w = 0, x = 0, _ = null, B = 0, S = p.length; B !== S && !1 === y; B++) {
- var E = Q;
- E.copy(p[B]);
- var M = E.norm();
- E.normalize();
- var C = K.dot(E);
- if (C < M + d && C > 0) {
- var A = X, z = Y;
- A.copy(p[(B + 1) % 3]);
- z.copy(p[(B + 2) % 3]);
- var F = A.norm(), R = z.norm();
- A.normalize();
- z.normalize();
- var T = K.dot(A), P = K.dot(z);
- if (T < F && T > -F && P < R && P > -R) {
- var q = Math.abs(C - M - d);
- if (null === _ || q < _) {
- _ = q;
- w = T;
- x = P;
- g = M;
- f.copy(E);
- v.copy(A);
- m.copy(z);
- b++;
- if (c) return !0;
- }
- }
- }
- }
- if (b) {
- y = !0;
- var I = this.createContactEquation(s, a, t, e, l, h);
- f.mult(-d, I.ri);
- I.ni.copy(f);
- I.ni.negate(I.ni);
- f.mult(g, f);
- v.mult(w, v);
- f.vadd(v, f);
- m.mult(x, m);
- f.vadd(m, I.rj);
- I.ri.vadd(i, I.ri);
- I.ri.vsub(s.position, I.ri);
- I.rj.vadd(o, I.rj);
- I.rj.vsub(a.position, I.rj);
- this.result.push(I);
- this.createFrictionEquationsFromContact(I, this.frictionResult);
- }
- for (var O = u.get(), V = J, j = 0; 2 !== j && !y; j++) for (var k = 0; 2 !== k && !y; k++) for (var N = 0; 2 !== N && !y; N++) {
- O.set(0, 0, 0);
- j ? O.vadd(p[0], O) : O.vsub(p[0], O);
- k ? O.vadd(p[1], O) : O.vsub(p[1], O);
- N ? O.vadd(p[2], O) : O.vsub(p[2], O);
- o.vadd(O, V);
- V.vsub(i, V);
- if (V.norm2() < d * d) {
- if (c) return !0;
- y = !0;
- (I = this.createContactEquation(s, a, t, e, l, h)).ri.copy(V);
- I.ri.normalize();
- I.ni.copy(I.ri);
- I.ri.mult(d, I.ri);
- I.rj.copy(O);
- I.ri.vadd(i, I.ri);
- I.ri.vsub(s.position, I.ri);
- I.rj.vadd(o, I.rj);
- I.rj.vsub(a.position, I.rj);
- this.result.push(I);
- this.createFrictionEquationsFromContact(I, this.frictionResult);
- }
- }
- u.release(O);
- O = null;
- var L = u.get(), W = u.get(), D = (I = u.get(), u.get()), U = (q = u.get(), p.length);
- for (j = 0; j !== U && !y; j++) for (k = 0; k !== U && !y; k++) if (j % 3 != k % 3) {
- p[k].cross(p[j], L);
- L.normalize();
- p[j].vadd(p[k], W);
- I.copy(i);
- I.vsub(W, I);
- I.vsub(o, I);
- var G = I.dot(L);
- L.mult(G, D);
- for (N = 0; N === j % 3 || N === k % 3; ) N++;
- q.copy(i);
- q.vsub(D, q);
- q.vsub(W, q);
- q.vsub(o, q);
- var H = Math.abs(G), it = q.norm();
- if (H < p[N].norm() && it < d) {
- if (c) return !0;
- y = !0;
- var ot = this.createContactEquation(s, a, t, e, l, h);
- W.vadd(D, ot.rj);
- ot.rj.copy(ot.rj);
- q.negate(ot.ni);
- ot.ni.normalize();
- ot.ri.copy(ot.rj);
- ot.ri.vadd(o, ot.ri);
- ot.ri.vsub(i, ot.ri);
- ot.ri.normalize();
- ot.ri.mult(d, ot.ri);
- ot.ri.vadd(i, ot.ri);
- ot.ri.vsub(s.position, ot.ri);
- ot.rj.vadd(o, ot.rj);
- ot.rj.vsub(a.position, ot.rj);
- this.result.push(ot);
- this.createFrictionEquationsFromContact(ot, this.frictionResult);
- }
- }
- u.release(L, W, I, D, q);
- };
- var it = new s(), ot = new s(), nt = new s(), rt = new s(), st = new s(), at = new s(), lt = new s(), ht = new s(), ct = new s(), ut = new s();
- p.prototype[n.types.SPHERE | n.types.CONVEXPOLYHEDRON] = p.prototype.sphereConvex = function(t, e, i, o, n, r, s, a, l, h, c) {
- var u = this.v3pool;
- i.vsub(o, it);
- for (var p = e.faceNormals, d = e.faces, y = e.vertices, f = t.radius, v = 0; v !== y.length; v++) {
- var m = y[v], g = st;
- r.vmult(m, g);
- o.vadd(g, g);
- var b = rt;
- g.vsub(i, b);
- if (b.norm2() < f * f) {
- if (c) return !0;
- w = !0;
- (q = this.createContactEquation(s, a, t, e, l, h)).ri.copy(b);
- q.ri.normalize();
- q.ni.copy(q.ri);
- q.ri.mult(f, q.ri);
- g.vsub(o, q.rj);
- q.ri.vadd(i, q.ri);
- q.ri.vsub(s.position, q.ri);
- q.rj.vadd(o, q.rj);
- q.rj.vsub(a.position, q.rj);
- this.result.push(q);
- this.createFrictionEquationsFromContact(q, this.frictionResult);
- return;
- }
- }
- for (var w = !1, x = (v = 0, d.length); v !== x && !1 === w; v++) {
- var _ = p[v], B = d[v], S = at;
- r.vmult(_, S);
- var E = lt;
- r.vmult(y[B[0]], E);
- E.vadd(o, E);
- var M = ht;
- S.mult(-f, M);
- i.vadd(M, M);
- var C = ct;
- M.vsub(E, C);
- var A = C.dot(S), z = ut;
- i.vsub(E, z);
- if (A < 0 && z.dot(S) > 0) {
- for (var F = [], R = 0, T = B.length; R !== T; R++) {
- var P = u.get();
- r.vmult(y[B[R]], P);
- o.vadd(P, P);
- F.push(P);
- }
- if (H(F, S, i)) {
- if (c) return !0;
- w = !0;
- var q = this.createContactEquation(s, a, t, e, l, h);
- S.mult(-f, q.ri);
- S.negate(q.ni);
- var I = u.get();
- S.mult(-A, I);
- var O = u.get();
- S.mult(-f, O);
- i.vsub(o, q.rj);
- q.rj.vadd(O, q.rj);
- q.rj.vadd(I, q.rj);
- q.rj.vadd(o, q.rj);
- q.rj.vsub(a.position, q.rj);
- q.ri.vadd(i, q.ri);
- q.ri.vsub(s.position, q.ri);
- u.release(I);
- u.release(O);
- this.result.push(q);
- this.createFrictionEquationsFromContact(q, this.frictionResult);
- R = 0;
- for (var V = F.length; R !== V; R++) u.release(F[R]);
- return;
- }
- for (R = 0; R !== B.length; R++) {
- var j = u.get(), k = u.get();
- r.vmult(y[B[(R + 1) % B.length]], j);
- r.vmult(y[B[(R + 2) % B.length]], k);
- o.vadd(j, j);
- o.vadd(k, k);
- var N = ot;
- k.vsub(j, N);
- var L = nt;
- N.unit(L);
- var W = u.get(), D = u.get();
- i.vsub(j, D);
- var U = D.dot(L);
- L.mult(U, W);
- W.vadd(j, W);
- var G = u.get();
- W.vsub(i, G);
- if (U > 0 && U * U < N.norm2() && G.norm2() < f * f) {
- if (c) return !0;
- q = this.createContactEquation(s, a, t, e, l, h);
- W.vsub(o, q.rj);
- W.vsub(i, q.ni);
- q.ni.normalize();
- q.ni.mult(f, q.ri);
- q.rj.vadd(o, q.rj);
- q.rj.vsub(a.position, q.rj);
- q.ri.vadd(i, q.ri);
- q.ri.vsub(s.position, q.ri);
- this.result.push(q);
- this.createFrictionEquationsFromContact(q, this.frictionResult);
- for (R = 0, V = F.length; R !== V; R++) u.release(F[R]);
- u.release(j);
- u.release(k);
- u.release(W);
- u.release(G);
- u.release(D);
- return;
- }
- u.release(j);
- u.release(k);
- u.release(W);
- u.release(G);
- u.release(D);
- }
- for (R = 0, V = F.length; R !== V; R++) u.release(F[R]);
- }
- }
- };
- new s(), new s();
- p.prototype[n.types.PLANE | n.types.BOX] = p.prototype.planeBox = function(t, e, i, o, n, r, s, a, l, h, c) {
- e.convexPolyhedronRepresentation.material = e.material;
- e.convexPolyhedronRepresentation.collisionResponse = e.collisionResponse;
- e.convexPolyhedronRepresentation.id = e.id;
- return this.planeConvex(t, e.convexPolyhedronRepresentation, i, o, n, r, s, a, t, e, c);
- };
- var pt = new s(), dt = new s(), yt = new s(), ft = new s();
- p.prototype[n.types.PLANE | n.types.CONVEXPOLYHEDRON] = p.prototype.planeConvex = function(t, e, i, o, n, r, s, a, l, h, c) {
- var u = pt, p = dt;
- p.set(0, 0, 1);
- n.vmult(p, p);
- for (var d = 0, y = yt, f = 0; f !== e.vertices.length; f++) {
- u.copy(e.vertices[f]);
- r.vmult(u, u);
- o.vadd(u, u);
- u.vsub(i, y);
- if (p.dot(y) <= 0) {
- if (c) return !0;
- var v = this.createContactEquation(s, a, t, e, l, h), m = ft;
- p.mult(p.dot(y), m);
- u.vsub(m, m);
- m.vsub(i, v.ri);
- v.ni.copy(p);
- u.vsub(o, v.rj);
- v.ri.vadd(i, v.ri);
- v.ri.vsub(s.position, v.ri);
- v.rj.vadd(o, v.rj);
- v.rj.vsub(a.position, v.rj);
- this.result.push(v);
- d++;
- this.enableFrictionReduction || this.createFrictionEquationsFromContact(v, this.frictionResult);
- }
- }
- this.enableFrictionReduction && d && this.createFrictionFromAverage(d);
- };
- var vt = new s(), mt = new s();
- p.prototype[n.types.CONVEXPOLYHEDRON] = p.prototype.convexConvex = function(t, e, i, o, n, r, s, a, l, h, c, u, p) {
- var d = vt;
- if (!(i.distanceTo(o) > t.boundingSphereRadius + e.boundingSphereRadius) && t.findSeparatingAxis(e, i, n, o, r, d, u, p)) {
- var y = [], f = mt;
- t.clipAgainstHull(i, n, e, o, r, d, -100, 100, y);
- for (var v = 0, m = 0; m !== y.length; m++) {
- if (c) return !0;
- var g = this.createContactEquation(s, a, t, e, l, h), b = g.ri, w = g.rj;
- d.negate(g.ni);
- y[m].normal.negate(f);
- f.mult(y[m].depth, f);
- y[m].point.vadd(f, b);
- w.copy(y[m].point);
- b.vsub(i, b);
- w.vsub(o, w);
- b.vadd(i, b);
- b.vsub(s.position, b);
- w.vadd(o, w);
- w.vsub(a.position, w);
- this.result.push(g);
- v++;
- this.enableFrictionReduction || this.createFrictionEquationsFromContact(g, this.frictionResult);
- }
- this.enableFrictionReduction && v && this.createFrictionFromAverage(v);
- }
- };
- var gt = new s(), bt = new s(), wt = new s();
- p.prototype[n.types.PLANE | n.types.PARTICLE] = p.prototype.planeParticle = function(t, e, i, o, n, r, s, a, l, h, c) {
- var u = gt;
- u.set(0, 0, 1);
- s.quaternion.vmult(u, u);
- var p = bt;
- o.vsub(s.position, p);
- if (u.dot(p) <= 0) {
- if (c) return !0;
- var d = this.createContactEquation(a, s, e, t, l, h);
- d.ni.copy(u);
- d.ni.negate(d.ni);
- d.ri.set(0, 0, 0);
- var y = wt;
- u.mult(u.dot(o), y);
- o.vsub(y, y);
- d.rj.copy(y);
- this.result.push(d);
- this.createFrictionEquationsFromContact(d, this.frictionResult);
- }
- };
- var xt = new s();
- p.prototype[n.types.PARTICLE | n.types.SPHERE] = p.prototype.sphereParticle = function(t, e, i, o, n, r, s, a, l, h, c) {
- var u = xt;
- u.set(0, 0, 1);
- o.vsub(i, u);
- if (u.norm2() <= t.radius * t.radius) {
- if (c) return !0;
- var p = this.createContactEquation(a, s, e, t, l, h);
- u.normalize();
- p.rj.copy(u);
- p.rj.mult(t.radius, p.rj);
- p.ni.copy(u);
- p.ni.negate(p.ni);
- p.ri.set(0, 0, 0);
- this.result.push(p);
- this.createFrictionEquationsFromContact(p, this.frictionResult);
- }
- };
- var _t = new l(), Bt = new s(), St = (new s(), new s()), Et = new s(), Mt = new s();
- p.prototype[n.types.PARTICLE | n.types.CONVEXPOLYHEDRON] = p.prototype.convexParticle = function(t, e, i, o, n, r, s, a, l, h, c) {
- var u = -1, p = St, d = Mt, y = null, f = Bt;
- f.copy(o);
- f.vsub(i, f);
- n.conjugate(_t);
- _t.vmult(f, f);
- if (t.pointIsInside(f)) {
- t.worldVerticesNeedsUpdate && t.computeWorldVertices(i, n);
- t.worldFaceNormalsNeedsUpdate && t.computeWorldFaceNormals(n);
- for (var v = 0, m = t.faces.length; v !== m; v++) {
- var g = [ t.worldVertices[t.faces[v][0]] ], b = t.worldFaceNormals[v];
- o.vsub(g[0], Et);
- var w = -b.dot(Et);
- if (null === y || Math.abs(w) < Math.abs(y)) {
- if (c) return !0;
- y = w;
- u = v;
- p.copy(b);
- }
- }
- if (-1 !== u) {
- var x = this.createContactEquation(a, s, e, t, l, h);
- p.mult(y, d);
- d.vadd(o, d);
- d.vsub(i, d);
- x.rj.copy(d);
- p.negate(x.ni);
- x.ri.set(0, 0, 0);
- var _ = x.ri, B = x.rj;
- _.vadd(o, _);
- _.vsub(a.position, _);
- B.vadd(i, B);
- B.vsub(s.position, B);
- this.result.push(x);
- this.createFrictionEquationsFromContact(x, this.frictionResult);
- } else console.warn("Point found inside convex, but did not find penetrating face!");
- }
- };
- p.prototype[n.types.BOX | n.types.HEIGHTFIELD] = p.prototype.boxHeightfield = function(t, e, i, o, n, r, s, a, l, h, c) {
- t.convexPolyhedronRepresentation.material = t.material;
- t.convexPolyhedronRepresentation.collisionResponse = t.collisionResponse;
- return this.convexHeightfield(t.convexPolyhedronRepresentation, e, i, o, n, r, s, a, t, e, c);
- };
- var Ct = new s(), At = new s(), zt = [ 0 ];
- p.prototype[n.types.CONVEXPOLYHEDRON | n.types.HEIGHTFIELD] = p.prototype.convexHeightfield = function(t, e, i, o, n, r, s, l, h, c, u) {
- var p = e.data, d = e.elementSize, y = t.boundingSphereRadius, f = At, v = zt, m = Ct;
- a.pointToLocalFrame(o, r, i, m);
- var g = Math.floor((m.x - y) / d) - 1, b = Math.ceil((m.x + y) / d) + 1, w = Math.floor((m.y - y) / d) - 1, x = Math.ceil((m.y + y) / d) + 1;
- if (!(b < 0 || x < 0 || g > p.length || w > p[0].length)) {
- g < 0 && (g = 0);
- b < 0 && (b = 0);
- w < 0 && (w = 0);
- x < 0 && (x = 0);
- g >= p.length && (g = p.length - 1);
- b >= p.length && (b = p.length - 1);
- x >= p[0].length && (x = p[0].length - 1);
- w >= p[0].length && (w = p[0].length - 1);
- var _ = [];
- e.getRectMinMax(g, w, b, x, _);
- var B = _[0], S = _[1];
- if (!(m.z - y > S || m.z + y < B)) for (var E = g; E < b; E++) for (var M = w; M < x; M++) {
- var C = !1;
- e.getConvexTrianglePillar(E, M, !1);
- a.pointToWorldFrame(o, r, e.pillarOffset, f);
- i.distanceTo(f) < e.pillarConvex.boundingSphereRadius + t.boundingSphereRadius && (C = this.convexConvex(t, e.pillarConvex, i, f, n, r, s, l, h, c, u, v, null));
- if (u && C) return !0;
- e.getConvexTrianglePillar(E, M, !0);
- a.pointToWorldFrame(o, r, e.pillarOffset, f);
- i.distanceTo(f) < e.pillarConvex.boundingSphereRadius + t.boundingSphereRadius && (C = this.convexConvex(t, e.pillarConvex, i, f, n, r, s, l, h, c, u, v, null));
- if (u && C) return !0;
- }
- }
- };
- var Ft = new s(), Rt = new s();
- p.prototype[n.types.SPHERE | n.types.HEIGHTFIELD] = p.prototype.sphereHeightfield = function(t, e, i, o, n, r, s, l, h, c, u) {
- var p = e.data, d = t.radius, y = e.elementSize, f = Rt, v = Ft;
- a.pointToLocalFrame(o, r, i, v);
- var m = Math.floor((v.x - d) / y) - 1, g = Math.ceil((v.x + d) / y) + 1, b = Math.floor((v.y - d) / y) - 1, w = Math.ceil((v.y + d) / y) + 1;
- if (!(g < 0 || w < 0 || m > p.length || b > p[0].length)) {
- m < 0 && (m = 0);
- g < 0 && (g = 0);
- b < 0 && (b = 0);
- w < 0 && (w = 0);
- m >= p.length && (m = p.length - 1);
- g >= p.length && (g = p.length - 1);
- w >= p[0].length && (w = p[0].length - 1);
- b >= p[0].length && (b = p[0].length - 1);
- var x = [];
- e.getRectMinMax(m, b, g, w, x);
- var _ = x[0], B = x[1];
- if (!(v.z - d > B || v.z + d < _)) for (var S = this.result, E = m; E < g; E++) for (var M = b; M < w; M++) {
- var C = S.length, A = !1;
- e.getConvexTrianglePillar(E, M, !1);
- a.pointToWorldFrame(o, r, e.pillarOffset, f);
- i.distanceTo(f) < e.pillarConvex.boundingSphereRadius + t.boundingSphereRadius && (A = this.sphereConvex(t, e.pillarConvex, i, f, n, r, s, l, t, e, u));
- if (u && A) return !0;
- e.getConvexTrianglePillar(E, M, !0);
- a.pointToWorldFrame(o, r, e.pillarOffset, f);
- i.distanceTo(f) < e.pillarConvex.boundingSphereRadius + t.boundingSphereRadius && (A = this.sphereConvex(t, e.pillarConvex, i, f, n, r, s, l, t, e, u));
- if (u && A) return !0;
- if (S.length - C > 2) return;
- }
- }
- };
- }, {
- "../collision/AABB": 3,
- "../collision/Ray": 10,
- "../equations/ContactEquation": 20,
- "../equations/FrictionEquation": 22,
- "../math/Quaternion": 30,
- "../math/Transform": 31,
- "../math/Vec3": 32,
- "../objects/Body": 33,
- "../shapes/ConvexPolyhedron": 40,
- "../shapes/Shape": 45,
- "../solver/Solver": 49,
- "../utils/Vec3Pool": 56
- } ],
- 58: [ function(t, e) {
- e.exports = g;
- t("../shapes/Shape");
- var i = t("../math/Vec3"), o = t("../math/Quaternion"), n = t("../solver/GSSolver"), r = (t("../equations/ContactEquation"),
- t("../equations/FrictionEquation"), t("./Narrowphase")), s = t("../utils/EventTarget"), a = t("../collision/ArrayCollisionMatrix"), l = t("../collision/ObjectCollisionMatrix"), h = t("../collision/OverlapKeeper"), c = t("../material/Material"), u = t("../material/ContactMaterial"), p = t("../objects/Body"), d = t("../utils/TupleDictionary"), y = t("../collision/RaycastResult"), f = t("../collision/AABB"), v = t("../collision/Ray"), m = t("../collision/NaiveBroadphase");
- function g(t) {
- t = t || {};
- s.apply(this);
- this.dt = -1;
- this.allowSleep = !!t.allowSleep;
- this.contacts = [];
- this.frictionEquations = [];
- this.quatNormalizeSkip = void 0 !== t.quatNormalizeSkip ? t.quatNormalizeSkip : 0;
- this.quatNormalizeFast = void 0 !== t.quatNormalizeFast && t.quatNormalizeFast;
- this.time = 0;
- this.timeFixed = 0;
- this.stepnumber = 0;
- this.default_dt = 1 / 60;
- this.nextId = 0;
- this.gravity = new i();
- t.gravity && this.gravity.copy(t.gravity);
- this.broadphase = void 0 !== t.broadphase ? t.broadphase : new m();
- this.bodies = [];
- this.solver = void 0 !== t.solver ? t.solver : new n();
- this.constraints = [];
- this.narrowphase = new r(this);
- this.collisionMatrix = new a();
- this.collisionMatrixPrevious = new a();
- this.bodyOverlapKeeper = new h();
- this.shapeOverlapKeeper = new h();
- this.materials = [];
- this.contactmaterials = [];
- this.contactMaterialTable = new d();
- this.defaultMaterial = new c("default");
- this.defaultContactMaterial = new u(this.defaultMaterial, this.defaultMaterial, {
- friction: .3,
- restitution: 0
- });
- this.doProfiling = !1;
- this.profile = {
- solve: 0,
- makeContactConstraints: 0,
- broadphase: 0,
- integrate: 0,
- narrowphase: 0
- };
- this.accumulator = 0;
- this.subsystems = [];
- this.addBodyEvent = {
- type: "addBody",
- body: null
- };
- this.removeBodyEvent = {
- type: "removeBody",
- body: null
- };
- this.idToBodyMap = {};
- this.broadphase.setWorld(this);
- this.substeps = 0;
- this.cm = new l();
- this.tm = new l();
- this.triggerDic = new d();
- this.oldTriggerDic = new d();
- this.contactsDic = new d();
- this.oldContactsDic = new d();
- }
- g.idToBodyMap = {};
- g.idToShapeMap = {};
- g.prototype = new s();
- new f();
- var b = new v();
- g.prototype.getContactMaterial = function(t, e) {
- return this.contactMaterialTable.get(t.id, e.id);
- };
- g.prototype.numObjects = function() {
- return this.bodies.length;
- };
- g.prototype.collisionMatrixTick = function() {
- var t = this.collisionMatrixPrevious;
- this.collisionMatrixPrevious = this.collisionMatrix;
- this.collisionMatrix = t;
- this.collisionMatrix.reset();
- this.bodyOverlapKeeper.tick();
- this.shapeOverlapKeeper.tick();
- };
- g.prototype.add = g.prototype.addBody = function(t) {
- g.SLEEPING = !1;
- if (-1 === this.bodies.indexOf(t)) {
- t.index = this.bodies.length;
- this.bodies.push(t);
- t.world = this;
- t.initPosition.copy(t.position);
- t.initVelocity.copy(t.velocity);
- t.timeLastSleepy = this.time;
- if (t instanceof p) {
- t.initAngularVelocity.copy(t.angularVelocity);
- t.initQuaternion.copy(t.quaternion);
- }
- this.collisionMatrix.setNumObjects(this.bodies.length);
- this.addBodyEvent.body = t;
- this.cm.setNumObjects(this.bodies.length);
- g.idToBodyMap[t.id] = t;
- this.dispatchEvent(this.addBodyEvent);
- }
- };
- g.prototype.addConstraint = function(t) {
- g.SLEEPING = !1;
- this.constraints.push(t);
- };
- g.prototype.removeConstraint = function(t) {
- g.SLEEPING = !1;
- var e = this.constraints.indexOf(t);
- -1 !== e && this.constraints.splice(e, 1);
- };
- g.prototype.rayTest = function(t, e, i) {
- i instanceof y ? this.raycastClosest(t, e, {
- skipBackfaces: !0
- }, i) : this.raycastAll(t, e, {
- skipBackfaces: !0
- }, i);
- };
- g.prototype.raycastAll = function(t, e, i, o) {
- i.mode = v.ALL;
- i.from = t;
- i.to = e;
- i.callback = o;
- return b.intersectWorld(this, i);
- };
- g.prototype.raycastAny = function(t, e, i, o) {
- i.mode = v.ANY;
- i.from = t;
- i.to = e;
- i.result = o;
- return b.intersectWorld(this, i);
- };
- g.prototype.raycastClosest = function(t, e, i, o) {
- i.mode = v.CLOSEST;
- i.from = t;
- i.to = e;
- i.result = o;
- return b.intersectWorld(this, i);
- };
- g.prototype.remove = function(t) {
- g.SLEEPING = !1;
- t.world = null;
- var e = this.bodies.length - 1, i = this.bodies, o = i.indexOf(t);
- if (-1 !== o) {
- i.splice(o, 1);
- for (var n = 0; n !== i.length; n++) i[n].index = n;
- this.collisionMatrix.setNumObjects(e);
- this.removeBodyEvent.body = t;
- delete g.idToBodyMap[t.id];
- this.cm.setNumObjects(e);
- this.dispatchEvent(this.removeBodyEvent);
- }
- };
- g.prototype.removeBody = g.prototype.remove;
- g.prototype.getBodyById = function(t) {
- return g.idToBodyMap[t];
- };
- g.prototype.getShapeById = function(t) {
- return g.idToShapeMap[t];
- };
- g.prototype.addMaterial = function(t) {
- this.materials.push(t);
- };
- g.prototype.addContactMaterial = function(t) {
- this.contactmaterials.push(t);
- this.contactMaterialTable.set(t.materials[0].id, t.materials[1].id, t);
- };
- "undefined" == typeof performance && (performance = {});
- if (!performance.now) {
- var w = Date.now();
- performance.timing && performance.timing.navigationStart && (w = performance.timing.navigationStart);
- performance.now = function() {
- return Date.now() - w;
- };
- }
- new i();
- g.prototype.step = function(t, e, i) {
- i = i || 10;
- if (0 === (e = e || 0)) {
- this.internalStep(t);
- this.time += t;
- this.substeps = 1;
- } else {
- this.accumulator += e;
- this.substeps = 0;
- for (;this.accumulator >= t && this.substeps < i; ) {
- this.internalStep(t);
- this.accumulator -= t;
- this.substeps++;
- }
- for (var o = this.accumulator % t / t, n = 0; n !== this.bodies.length; n++) {
- var r = this.bodies[n];
- r.previousPosition.lerp(r.position, o, r.interpolatedPosition);
- r.previousQuaternion.slerp(r.quaternion, o, r.interpolatedQuaternion);
- r.previousQuaternion.normalize();
- }
- this.time += e;
- }
- };
- var x, _, B, S, E, M, C = {
- type: "postStep"
- }, A = {
- type: "preStep"
- }, z = {
- type: "collide",
- body: null,
- contact: null
- }, F = [], R = [], T = [], P = [];
- new i(), new i(), new i(), new i(), new i(), new i(), new i(), new i(), new i(),
- new o(), new o(), new o(), new i();
- g.prototype.internalStep = function(t) {
- this.dt = t;
- var e, i = this.contacts, o = T, n = P, r = this.numObjects(), s = this.bodies, a = this.solver, l = this.gravity, h = this.doProfiling, c = this.profile, u = p.DYNAMIC, d = this.constraints, y = R, f = (l.norm(),
- l.x), v = l.y, m = l.z, b = 0;
- h && (e = performance.now());
- for (b = 0; b !== r; b++) if ((V = s[b]).useGravity && V.type === u) {
- var w = V.force, x = V.mass;
- w.x += x * f;
- w.y += x * v;
- w.z += x * m;
- }
- b = 0;
- for (var _ = this.subsystems.length; b !== _; b++) this.subsystems[b].update();
- h && (e = performance.now());
- o.length = 0;
- n.length = 0;
- this.broadphase.collisionPairs(this, o, n);
- h && (c.broadphase = performance.now() - e);
- var B = d.length;
- for (b = 0; b !== B; b++) if (!(L = d[b]).collideConnected) for (var S = o.length - 1; S >= 0; S -= 1) if (L.bodyA === o[S] && L.bodyB === n[S] || L.bodyB === o[S] && L.bodyA === n[S]) {
- o.splice(S, 1);
- n.splice(S, 1);
- }
- this.collisionMatrixTick();
- h && (e = performance.now());
- var E = F, M = i.length;
- for (b = 0; b !== M; b++) E.push(i[b]);
- i.length = 0;
- var q = this.frictionEquations.length;
- for (b = 0; b !== q; b++) y.push(this.frictionEquations[b]);
- this.frictionEquations.length = 0;
- this.narrowphase.getContacts(o, n, this, i, E, this.frictionEquations, y);
- if (0 != i.length || !g.SLEEPING) {
- h && (c.narrowphase = performance.now() - e);
- h && (e = performance.now());
- for (b = 0; b < this.frictionEquations.length; b++) a.addEquation(this.frictionEquations[b]);
- for (var I = i.length, O = 0; O !== I; O++) {
- var V = (L = i[O]).bi, j = L.bj, k = L.si, N = L.sj;
- k.material && N.material ? k.material.restitution >= 0 && N.material.restitution >= 0 && (L.restitution = k.material.restitution * N.material.restitution) : V.material && j.material && V.material.restitution >= 0 && j.material.restitution >= 0 && (L.restitution = V.material.restitution * j.material.restitution);
- a.addEquation(L);
- V.allowSleep && V.type === p.DYNAMIC && V.sleepState === p.SLEEPING && j.sleepState === p.AWAKE && j.type !== p.STATIC && j.velocity.norm2() + j.angularVelocity.norm2() >= 2 * Math.pow(j.sleepSpeedLimit, 2) && (V._wakeUpAfterNarrowphase = !0);
- j.allowSleep && j.type === p.DYNAMIC && j.sleepState === p.SLEEPING && V.sleepState === p.AWAKE && V.type !== p.STATIC && V.velocity.norm2() + V.angularVelocity.norm2() >= 2 * Math.pow(V.sleepSpeedLimit, 2) && (j._wakeUpAfterNarrowphase = !0);
- this.collisionMatrix.set(V, j, !0);
- if (!this.collisionMatrixPrevious.get(V, j)) {
- z.body = j;
- z.contact = L;
- V.dispatchEvent(z);
- z.body = V;
- j.dispatchEvent(z);
- }
- this.bodyOverlapKeeper.set(V.id, j.id);
- this.shapeOverlapKeeper.set(k.id, N.id);
- }
- this.emitContactEvents();
- if (h) {
- c.makeContactConstraints = performance.now() - e;
- e = performance.now();
- }
- for (b = 0; b !== r; b++) if ((V = s[b])._wakeUpAfterNarrowphase) {
- V.wakeUp();
- V._wakeUpAfterNarrowphase = !1;
- }
- B = d.length;
- for (b = 0; b !== B; b++) {
- var L;
- (L = d[b]).update();
- S = 0;
- for (var W = L.equations.length; S !== W; S++) {
- var D = L.equations[S];
- a.addEquation(D);
- }
- }
- a.solve(t, this);
- h && (c.solve = performance.now() - e);
- a.removeAllEquations();
- var U = Math.pow;
- for (b = 0; b !== r; b++) if ((V = s[b]).type & u) {
- var G = U(1 - V.linearDamping, t), H = V.velocity;
- H.mult(G, H);
- var K = V.angularVelocity;
- if (K) {
- var Q = U(1 - V.angularDamping, t);
- K.mult(Q, K);
- }
- }
- this.dispatchEvent(A);
- for (b = 0; b !== r; b++) (V = s[b]).preStep && V.preStep.call(V);
- h && (e = performance.now());
- var X = this.stepnumber % (this.quatNormalizeSkip + 1) == 0, Y = this.quatNormalizeFast;
- for (b = 0; b !== r; b++) s[b].integrate(t, X, Y);
- this.clearForces();
- this.broadphase.dirty = !0;
- h && (c.integrate = performance.now() - e);
- this.time += t;
- this.timeFixed += t;
- this.stepnumber += 1;
- this.dispatchEvent(C);
- for (b = 0; b !== r; b++) {
- var Z = (V = s[b]).postStep;
- Z && Z.call(V);
- }
- if (this.allowSleep) {
- for (b = 0; b !== r; b++) s[b].sleepTick(this.time);
- g.SLEEPING = !0;
- for (b = 0; b !== r; b++) if ((V = s[b]).type != p.STATIC && !V.isSleeping()) {
- g.SLEEPING = !1;
- break;
- }
- } else g.SLEEPING = !1;
- }
- };
- g.prototype.emitContactEvents = (x = [], _ = [], B = {
- type: "beginContact",
- bodyA: null,
- bodyB: null
- }, S = {
- type: "endContact",
- bodyA: null,
- bodyB: null
- }, E = {
- type: "beginShapeContact",
- bodyA: null,
- bodyB: null,
- shapeA: null,
- shapeB: null
- }, M = {
- type: "endShapeContact",
- bodyA: null,
- bodyB: null,
- shapeA: null,
- shapeB: null
- }, function() {
- var t = this.hasAnyEventListener("beginContact"), e = this.hasAnyEventListener("endContact");
- (t || e) && this.bodyOverlapKeeper.getDiff(x, _);
- if (t) {
- for (var i = 0, o = x.length; i < o; i += 2) {
- B.bodyA = this.getBodyById(x[i]);
- B.bodyB = this.getBodyById(x[i + 1]);
- this.dispatchEvent(B);
- }
- B.bodyA = B.bodyB = null;
- }
- if (e) {
- for (i = 0, o = _.length; i < o; i += 2) {
- S.bodyA = this.getBodyById(_[i]);
- S.bodyB = this.getBodyById(_[i + 1]);
- this.dispatchEvent(S);
- }
- S.bodyA = S.bodyB = null;
- }
- x.length = _.length = 0;
- var n = this.hasAnyEventListener("beginShapeContact"), r = this.hasAnyEventListener("endShapeContact");
- (n || r) && this.shapeOverlapKeeper.getDiff(x, _);
- if (n) {
- for (i = 0, o = x.length; i < o; i += 2) {
- var s = this.getShapeById(x[i]), a = this.getShapeById(x[i + 1]);
- E.shapeA = s;
- E.shapeB = a;
- E.bodyA = s.body;
- E.bodyB = a.body;
- this.dispatchEvent(E);
- }
- E.bodyA = E.bodyB = E.shapeA = E.shapeB = null;
- }
- if (r) {
- for (i = 0, o = _.length; i < o; i += 2) {
- s = this.getShapeById(_[i]), a = this.getShapeById(_[i + 1]);
- M.shapeA = s;
- M.shapeB = a;
- M.bodyA = s.body;
- M.bodyB = a.body;
- this.dispatchEvent(M);
- }
- M.bodyA = M.bodyB = M.shapeA = M.shapeB = null;
- }
- });
- g.prototype.clearForces = function() {
- for (var t = this.bodies, e = t.length, i = 0; i !== e; i++) {
- var o = t[i];
- o.force, o.torque;
- o.force.set(0, 0, 0);
- o.torque.set(0, 0, 0);
- }
- };
- var q = {
- type: "cc-trigger",
- event: "",
- selfBody: null,
- otherBody: null,
- selfShape: null,
- otherShape: null
- }, I = {
- type: "cc-collide",
- event: "",
- body: null,
- selfShape: null,
- otherShape: null,
- contacts: null
- }, O = [];
- g.prototype.emitTriggeredEvents = function() {
- if (0 != this.substeps) {
- for (var t, e, i = this.triggerDic.getLength(); i--; ) {
- t = this.triggerDic.getKeyByIndex(i);
- if (null != (e = this.triggerDic.getDataByKey(t))) {
- var o = e.si, n = e.sj;
- if (this.tm.get(o, n)) q.event = "onTriggerStay"; else {
- this.tm.set(o, n, !0);
- q.event = "onTriggerEnter";
- }
- q.selfShape = o;
- q.otherShape = n;
- q.selfBody = o.body;
- q.otherBody = n.body;
- o.dispatchEvent(q);
- q.selfShape = n;
- q.otherShape = o;
- q.selfBody = n.body;
- q.otherBody = o.body;
- n.dispatchEvent(q);
- }
- }
- i = this.oldTriggerDic.getLength();
- for (;i > 0; ) {
- i--;
- t = this.oldTriggerDic.getKeyByIndex(i);
- if (null == this.triggerDic.getDataByKey(t) && null != (e = this.oldTriggerDic.getDataByKey(t))) {
- o = e.si, n = e.sj;
- this.tm.set(o, n, !1);
- this.oldTriggerDic.del(o.id, n.id) && i--;
- q.event = "onTriggerExit";
- q.selfShape = o;
- q.otherShape = n;
- q.selfBody = o.body;
- q.otherBody = n.body;
- o.dispatchEvent(q);
- q.selfShape = n;
- q.otherShape = o;
- q.selfBody = n.body;
- q.otherBody = o.body;
- n.dispatchEvent(q);
- }
- }
- this.triggerDic.reset();
- }
- };
- g.prototype.emitCollisionEvents = function() {
- if (0 != this.substeps) {
- for (var t, e, i = this.contacts, o = this.contacts.length; o--; ) {
- var n = (c = i[o]).si, r = c.sj, s = this.contactsDic.get(n.id, r.id);
- null == s && (s = this.contactsDic.set(n.id, r.id, []));
- s.push(c);
- }
- for (o = this.contactsDic.getLength(); o--; ) {
- t = this.contactsDic.getKeyByIndex(o);
- if (null != (e = this.contactsDic.getDataByKey(t))) {
- n = e[0].si, r = e[0].sj;
- var a = n.body, l = r.body;
- if (this.cm.get(a, l)) I.event = "onCollisionStay"; else {
- this.cm.set(a, l, !0);
- I.event = "onCollisionEnter";
- }
- I.bi = a;
- I.contact = e[0];
- I.contacts = e;
- I.body = l;
- I.selfShape = n;
- I.otherShape = r;
- a.dispatchEvent(I);
- I.body = a;
- I.selfShape = r;
- I.otherShape = n;
- l.dispatchEvent(I);
- }
- }
- var h = O;
- for (o = h.length; o--; ) {
- var c;
- n = (c = h[o]).si, r = c.sj;
- null == this.oldContactsDic.get(n.id, r.id) && this.oldContactsDic.set(n.id, r.id, c);
- }
- o = this.oldContactsDic.getLength();
- for (;o--; ) {
- t = this.oldContactsDic.getKeyByIndex(o);
- if (null == this.contactsDic.getDataByKey(t)) {
- n = (e = this.oldContactsDic.getDataByKey(t)).si, r = e.sj, a = n.body, l = r.body;
- if (this.cm.get(a, l) && (!a.isSleeping() || !l.isSleeping())) {
- this.cm.set(a, l, !1);
- I.bi = a;
- I.contact = e;
- I.event = "onCollisionExit";
- I.body = l;
- I.selfShape = n;
- I.otherShape = r;
- I.contacts.length = 0;
- I.contacts.push(e);
- a.dispatchEvent(I);
- I.body = a;
- I.selfShape = r;
- I.otherShape = n;
- l.dispatchEvent(I);
- }
- }
- }
- this.contactsDic.reset();
- this.oldContactsDic.reset();
- F = O;
- O = this.contacts.slice();
- this.contacts.length = 0;
- }
- };
- }, {
- "../collision/AABB": 3,
- "../collision/ArrayCollisionMatrix": 4,
- "../collision/NaiveBroadphase": 7,
- "../collision/ObjectCollisionMatrix": 8,
- "../collision/OverlapKeeper": 9,
- "../collision/Ray": 10,
- "../collision/RaycastResult": 11,
- "../equations/ContactEquation": 20,
- "../equations/FrictionEquation": 22,
- "../material/ContactMaterial": 25,
- "../material/Material": 26,
- "../math/Quaternion": 30,
- "../math/Vec3": 32,
- "../objects/Body": 33,
- "../shapes/Shape": 45,
- "../solver/GSSolver": 48,
- "../utils/EventTarget": 51,
- "../utils/TupleDictionary": 54,
- "./Narrowphase": 57
- } ]
- }, {}, [ 2 ])(2);
- });
- }).call(this, "undefined" != typeof global ? global : "undefined" != typeof self ? self : "undefined" != typeof window ? window : {});
- }, {} ]
- }, {}, [ 10, 9 ]);
|