physics.js 231 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672
  1. (function t(e, i, o) {
  2. function n(s, a) {
  3. if (!i[s]) {
  4. if (!e[s]) {
  5. var l = "function" == typeof require && require;
  6. if (!a && l) return l(s, !0);
  7. if (r) return r(s, !0);
  8. var h = new Error("Cannot find module '" + s + "'");
  9. throw h.code = "MODULE_NOT_FOUND", h;
  10. }
  11. var c = i[s] = {
  12. exports: {}
  13. };
  14. e[s][0].call(c.exports, function(t) {
  15. return n(e[s][1][t] || t);
  16. }, c, c.exports, t, e, i, o);
  17. }
  18. return i[s].exports;
  19. }
  20. for (var r = "function" == typeof require && require, s = 0; s < o.length; s++) n(o[s]);
  21. return n;
  22. })({
  23. 1: [ function(t, e, i) {
  24. "use strict";
  25. i.__esModule = !0;
  26. i.CannonRigidBody = void 0;
  27. var o, n = (o = t("../../../../../external/cannon/cannon")) && o.__esModule ? o : {
  28. default: o
  29. };
  30. function r(t, e) {
  31. for (var i = 0; i < e.length; i++) {
  32. var o = e[i];
  33. o.enumerable = o.enumerable || !1;
  34. o.configurable = !0;
  35. "value" in o && (o.writable = !0);
  36. Object.defineProperty(t, o.key, o);
  37. }
  38. }
  39. function s(t, e, i) {
  40. e && r(t.prototype, e);
  41. i && r(t, i);
  42. return t;
  43. }
  44. var a = new n.default.Vec3(), l = new n.default.Vec3(), h = cc.Vec3, c = function() {
  45. function t() {
  46. this._rigidBody = void 0;
  47. this._sharedBody = void 0;
  48. this._isEnabled = !1;
  49. }
  50. var e = t.prototype;
  51. e.__preload = function(t) {
  52. this._rigidBody = t;
  53. this._sharedBody = cc.director.getPhysics3DManager().physicsWorld.getSharedBody(this._rigidBody.node);
  54. this._sharedBody.reference = !0;
  55. this._sharedBody.wrappedBody = this;
  56. };
  57. e.onLoad = function() {};
  58. e.onEnable = function() {
  59. this._isEnabled = !0;
  60. this.mass = this._rigidBody.mass;
  61. this.allowSleep = this._rigidBody.allowSleep;
  62. this.linearDamping = this._rigidBody.linearDamping;
  63. this.angularDamping = this._rigidBody.angularDamping;
  64. this.useGravity = this._rigidBody.useGravity;
  65. this.isKinematic = this._rigidBody.isKinematic;
  66. this.fixedRotation = this._rigidBody.fixedRotation;
  67. this.linearFactor = this._rigidBody.linearFactor;
  68. this.angularFactor = this._rigidBody.angularFactor;
  69. this._sharedBody.enabled = !0;
  70. };
  71. e.onDisable = function() {
  72. this._isEnabled = !1;
  73. this._sharedBody.enabled = !1;
  74. };
  75. e.onDestroy = function() {
  76. this._sharedBody.reference = !1;
  77. this._rigidBody = null;
  78. this._sharedBody = null;
  79. };
  80. e.wakeUp = function() {
  81. return this._sharedBody.body.wakeUp();
  82. };
  83. e.sleep = function() {
  84. return this._sharedBody.body.sleep();
  85. };
  86. e.getLinearVelocity = function(t) {
  87. h.copy(t, this._sharedBody.body.velocity);
  88. return t;
  89. };
  90. e.setLinearVelocity = function(t) {
  91. var e = this._sharedBody.body;
  92. e.isSleeping() && e.wakeUp();
  93. h.copy(e.velocity, t);
  94. };
  95. e.getAngularVelocity = function(t) {
  96. h.copy(t, this._sharedBody.body.angularVelocity);
  97. return t;
  98. };
  99. e.setAngularVelocity = function(t) {
  100. var e = this._sharedBody.body;
  101. e.isSleeping() && e.wakeUp();
  102. h.copy(e.angularVelocity, t);
  103. };
  104. e.applyForce = function(t, e) {
  105. null == e && (e = h.ZERO);
  106. var i = this._sharedBody.body;
  107. i.isSleeping() && i.wakeUp();
  108. i.applyForce(h.copy(a, t), h.copy(l, e));
  109. };
  110. e.applyImpulse = function(t, e) {
  111. null == e && (e = h.ZERO);
  112. var i = this._sharedBody.body;
  113. i.isSleeping() && i.wakeUp();
  114. i.applyImpulse(h.copy(a, t), h.copy(l, e));
  115. };
  116. e.applyLocalForce = function(t, e) {
  117. null == e && (e = h.ZERO);
  118. var i = this._sharedBody.body;
  119. i.isSleeping() && i.wakeUp();
  120. i.applyLocalForce(h.copy(a, t), h.copy(l, e));
  121. };
  122. e.applyLocalImpulse = function(t, e) {
  123. null == e && (e = h.ZERO);
  124. var i = this._sharedBody.body;
  125. i.isSleeping() && i.wakeUp();
  126. i.applyLocalImpulse(h.copy(a, t), h.copy(l, e));
  127. };
  128. e.applyTorque = function(t) {
  129. var e = this._sharedBody.body;
  130. e.isSleeping() && e.wakeUp();
  131. e.torque.x += t.x;
  132. e.torque.y += t.y;
  133. e.torque.z += t.z;
  134. };
  135. e.applyLocalTorque = function(t) {
  136. var e = this._sharedBody.body;
  137. e.isSleeping() && e.wakeUp();
  138. h.copy(a, t);
  139. e.vectorToWorldFrame(a, a);
  140. e.torque.x += a.x;
  141. e.torque.y += a.y;
  142. e.torque.z += a.z;
  143. };
  144. s(t, [ {
  145. key: "isAwake",
  146. get: function() {
  147. return this._sharedBody.body.isAwake();
  148. }
  149. }, {
  150. key: "isSleepy",
  151. get: function() {
  152. return this._sharedBody.body.isSleepy();
  153. }
  154. }, {
  155. key: "isSleeping",
  156. get: function() {
  157. return this._sharedBody.body.isSleeping();
  158. }
  159. }, {
  160. key: "allowSleep",
  161. set: function(t) {
  162. var e = this._sharedBody.body;
  163. e.isSleeping() && e.wakeUp();
  164. e.allowSleep = t;
  165. }
  166. }, {
  167. key: "mass",
  168. set: function(t) {
  169. var e = this._sharedBody.body;
  170. e.mass = t;
  171. 0 == e.mass ? e.type = n.default.Body.STATIC : e.type = this._rigidBody.isKinematic ? n.default.Body.KINEMATIC : n.default.Body.DYNAMIC;
  172. e.updateMassProperties();
  173. e.isSleeping() && e.wakeUp();
  174. }
  175. }, {
  176. key: "isKinematic",
  177. set: function(t) {
  178. var e = this._sharedBody.body;
  179. 0 == e.mass ? e.type = n.default.Body.STATIC : e.type = t ? n.default.Body.KINEMATIC : n.default.Body.DYNAMIC;
  180. }
  181. }, {
  182. key: "fixedRotation",
  183. set: function(t) {
  184. var e = this._sharedBody.body;
  185. e.isSleeping() && e.wakeUp();
  186. e.fixedRotation = t;
  187. e.updateMassProperties();
  188. }
  189. }, {
  190. key: "linearDamping",
  191. set: function(t) {
  192. this._sharedBody.body.linearDamping = t;
  193. }
  194. }, {
  195. key: "angularDamping",
  196. set: function(t) {
  197. this._sharedBody.body.angularDamping = t;
  198. }
  199. }, {
  200. key: "useGravity",
  201. set: function(t) {
  202. var e = this._sharedBody.body;
  203. e.isSleeping() && e.wakeUp();
  204. e.useGravity = t;
  205. }
  206. }, {
  207. key: "linearFactor",
  208. set: function(t) {
  209. var e = this._sharedBody.body;
  210. e.isSleeping() && e.wakeUp();
  211. h.copy(e.linearFactor, t);
  212. }
  213. }, {
  214. key: "angularFactor",
  215. set: function(t) {
  216. var e = this._sharedBody.body;
  217. e.isSleeping() && e.wakeUp();
  218. h.copy(e.angularFactor, t);
  219. }
  220. }, {
  221. key: "rigidBody",
  222. get: function() {
  223. return this._rigidBody;
  224. }
  225. }, {
  226. key: "sharedBody",
  227. get: function() {
  228. return this._sharedBody;
  229. }
  230. }, {
  231. key: "isEnabled",
  232. get: function() {
  233. return this._isEnabled;
  234. }
  235. } ]);
  236. return t;
  237. }();
  238. i.CannonRigidBody = c;
  239. }, {
  240. "../../../../../external/cannon/cannon": 24
  241. } ],
  242. 2: [ function(t, e, i) {
  243. "use strict";
  244. i.__esModule = !0;
  245. i.CannonSharedBody = void 0;
  246. var o, n = (o = t("../../../../../external/cannon/cannon")) && o.__esModule ? o : {
  247. default: o
  248. }, r = t("../framework/physics-enum"), s = t("../framework/util"), a = t("./cannon-util");
  249. function l(t, e) {
  250. for (var i = 0; i < e.length; i++) {
  251. var o = e[i];
  252. o.enumerable = o.enumerable || !1;
  253. o.configurable = !0;
  254. "value" in o && (o.writable = !0);
  255. Object.defineProperty(t, o.key, o);
  256. }
  257. }
  258. function h(t, e, i) {
  259. e && l(t.prototype, e);
  260. i && l(t, i);
  261. return t;
  262. }
  263. 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 = {
  264. type: "collision-enter",
  265. selfCollider: null,
  266. otherCollider: null,
  267. contacts: []
  268. }, g = function() {
  269. t.getSharedBody = function(e, i) {
  270. var o = e._id;
  271. if (t.sharedBodiesMap.has(o)) return t.sharedBodiesMap.get(o);
  272. var n = new t(e, i);
  273. t.sharedBodiesMap.set(e._id, n);
  274. return n;
  275. };
  276. function t(t, e) {
  277. this.node = void 0;
  278. this.wrappedWorld = void 0;
  279. this.body = new n.default.Body();
  280. this.shapes = [];
  281. this.wrappedBody = null;
  282. this.index = -1;
  283. this.ref = 0;
  284. this.onCollidedListener = this.onCollided.bind(this);
  285. this.wrappedWorld = e;
  286. this.node = t;
  287. this.body.material = this.wrappedWorld.world.defaultMaterial;
  288. this.body.addEventListener("cc-collide", this.onCollidedListener);
  289. this._updateGroup();
  290. this.node.on(cc.Node.EventType.GROUP_CHANGED, this._updateGroup, this);
  291. }
  292. var e = t.prototype;
  293. e._updateGroup = function() {
  294. (0, a.groupIndexToBitMask)(this.node.groupIndex, this.body);
  295. };
  296. e.addShape = function(t) {
  297. if (this.shapes.indexOf(t) < 0) {
  298. var e = this.body.shapes.length;
  299. this.body.addShape(t.shape);
  300. this.shapes.push(t);
  301. t.setIndex(e);
  302. var i = this.body.shapeOffsets[e], o = this.body.shapeOrientations[e];
  303. t.setOffsetAndOrient(i, o);
  304. }
  305. };
  306. e.removeShape = function(t) {
  307. var e = this.shapes.indexOf(t);
  308. if (e >= 0) {
  309. d(this.shapes, e);
  310. this.body.removeShape(t.shape);
  311. t.setIndex(-1);
  312. }
  313. };
  314. e.syncSceneToPhysics = function(t) {
  315. void 0 === t && (t = !1);
  316. var e = this.node, i = (0, s.worldDirty)(e);
  317. if (t || i) {
  318. this.body.aabbNeedsUpdate = !0;
  319. e.getWorldPosition(y);
  320. e.getWorldRotation(f);
  321. p.copy(this.body.position, y);
  322. u.copy(this.body.quaternion, f);
  323. if (e._localMatDirty & c) {
  324. for (var o = e.__wscale, n = 0; n < this.shapes.length; n++) this.shapes[n].setScale(o);
  325. (0, a.commitShapeUpdates)(this.body);
  326. }
  327. this.body.isSleeping() && this.body.wakeUp();
  328. }
  329. };
  330. e.syncPhysicsToScene = function() {
  331. if (this.body.type != r.ERigidBodyType.STATIC && !this.body.isSleeping()) {
  332. p.copy(y, this.body.position);
  333. u.copy(f, this.body.quaternion);
  334. this.node.setWorldPosition(y);
  335. this.node.setWorldRotation(f);
  336. }
  337. };
  338. e.destroy = function() {
  339. this.body.removeEventListener("cc-collide", this.onCollidedListener);
  340. this.node.off(cc.Node.EventType.GROUP_CHANGED, this._updateGroup, this);
  341. t.sharedBodiesMap.delete(this.node._id);
  342. delete n.default.World.idToBodyMap[this.body.id];
  343. this.node = null;
  344. this.wrappedWorld = null;
  345. this.body = null;
  346. this.shapes = null;
  347. this.onCollidedListener = null;
  348. };
  349. e.onCollided = function(t) {
  350. m.type = t.event;
  351. var e = (0, s.getWrap)(t.selfShape), i = (0, s.getWrap)(t.otherShape);
  352. if (e) {
  353. m.selfCollider = e.collider;
  354. m.otherCollider = i ? i.collider : null;
  355. var o = 0;
  356. for (o = m.contacts.length; o--; ) v.push(m.contacts.pop());
  357. for (o = 0; o < t.contacts.length; o++) {
  358. var n = t.contacts[o];
  359. if (v.length > 0) {
  360. var r = v.pop();
  361. p.copy(r.contactA, n.ri);
  362. p.copy(r.contactB, n.rj);
  363. p.copy(r.normal, n.ni);
  364. m.contacts.push(r);
  365. } else {
  366. var l = {
  367. contactA: p.copy(new p(), n.ri),
  368. contactB: p.copy(new p(), n.rj),
  369. normal: p.copy(new p(), n.ni)
  370. };
  371. m.contacts.push(l);
  372. }
  373. }
  374. for (o = 0; o < this.shapes.length; o++) {
  375. var h = this.shapes[o];
  376. m.type = a.deprecatedEventMap[m.type];
  377. h.collider.emit(m.type, m);
  378. m.type = t.event;
  379. h.collider.emit(m.type, m);
  380. }
  381. }
  382. };
  383. h(t, [ {
  384. key: "enabled",
  385. set: function(t) {
  386. if (t) {
  387. if (this.index < 0) {
  388. this.index = this.wrappedWorld.bodies.length;
  389. this.wrappedWorld.addSharedBody(this);
  390. var e = this.node;
  391. this.body.aabbNeedsUpdate = !0;
  392. e.getWorldPosition(y);
  393. e.getWorldRotation(f);
  394. var i = this.body.position;
  395. i.x = parseFloat(y.x.toFixed(3));
  396. i.y = parseFloat(y.y.toFixed(3));
  397. i.z = parseFloat(y.z.toFixed(3));
  398. var o = this.body.quaternion;
  399. o.x = parseFloat(f.x.toFixed(12));
  400. o.y = parseFloat(f.y.toFixed(12));
  401. o.z = parseFloat(f.z.toFixed(12));
  402. o.w = parseFloat(f.w.toFixed(12));
  403. if (e._localMatDirty & c) {
  404. for (var n = e.__wscale, r = 0; r < this.shapes.length; r++) this.shapes[r].setScale(n);
  405. (0, a.commitShapeUpdates)(this.body);
  406. }
  407. this.body.isSleeping() && this.body.wakeUp();
  408. }
  409. } 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)) {
  410. this.body.sleep();
  411. this.index = -1;
  412. this.wrappedWorld.removeSharedBody(this);
  413. }
  414. }
  415. }, {
  416. key: "reference",
  417. set: function(t) {
  418. t ? this.ref++ : this.ref--;
  419. 0 == this.ref && this.destroy();
  420. }
  421. } ]);
  422. return t;
  423. }();
  424. i.CannonSharedBody = g;
  425. g.sharedBodiesMap = new Map();
  426. }, {
  427. "../../../../../external/cannon/cannon": 24,
  428. "../framework/physics-enum": 19,
  429. "../framework/util": 23,
  430. "./cannon-util": 3
  431. } ],
  432. 3: [ function(t, e, i) {
  433. "use strict";
  434. i.__esModule = !0;
  435. i.groupIndexToBitMask = r;
  436. i.toCannonRaycastOptions = function(t, e) {
  437. t.checkCollisionResponse = !e.queryTrigger;
  438. r(e.groupIndex, t);
  439. t.skipBackFaces = !1;
  440. };
  441. i.fillRaycastResult = function(t, e) {
  442. t._assign(n.copy(new n(), e.hitPointWorld), e.distance, (0, o.getWrap)(e.shape).collider);
  443. };
  444. i.commitShapeUpdates = function(t) {
  445. t.aabbNeedsUpdate = !0;
  446. t.updateMassProperties();
  447. t.updateBoundingRadius();
  448. };
  449. i.deprecatedEventMap = void 0;
  450. var o = t("../framework/util"), n = cc.Vec3;
  451. function r(t, e) {
  452. var i = 1 << t, o = 0, n = cc.game.collisionMatrix[t];
  453. if (n) {
  454. for (var r = 0; r < n.length; r++) n[r] && (o |= 1 << r);
  455. e.collisionFilterGroup = i;
  456. e.collisionFilterMask = o;
  457. } else cc.error("cannon-utils: group is not exist", t);
  458. }
  459. i.deprecatedEventMap = {
  460. onCollisionEnter: "collision-enter",
  461. onCollisionStay: "collision-stay",
  462. onCollisionExit: "collision-exit",
  463. onTriggerEnter: "trigger-enter",
  464. onTriggerStay: "trigger-stay",
  465. onTriggerExit: "trigger-exit"
  466. };
  467. }, {
  468. "../framework/util": 23
  469. } ],
  470. 4: [ function(t, e, i) {
  471. "use strict";
  472. i.__esModule = !0;
  473. i.CannonWorld = void 0;
  474. var o, n = (o = t("../../../../../external/cannon/cannon")) && o.__esModule ? o : {
  475. default: o
  476. }, r = t("./cannon-util"), s = t("./shapes/cannon-shape"), a = t("./cannon-shared-body"), l = t("../framework/util");
  477. function h(t, e) {
  478. for (var i = 0; i < e.length; i++) {
  479. var o = e[i];
  480. o.enumerable = o.enumerable || !1;
  481. o.configurable = !0;
  482. "value" in o && (o.writable = !0);
  483. Object.defineProperty(t, o.key, o);
  484. }
  485. }
  486. function c(t, e, i) {
  487. e && h(t.prototype, e);
  488. i && h(t, i);
  489. return t;
  490. }
  491. var u = cc.Vec3, p = cc.js.array.fastRemoveAt, d = function() {
  492. function t() {
  493. this.bodies = [];
  494. this._world = void 0;
  495. this._raycastResult = new n.default.RaycastResult();
  496. this._world = new n.default.World();
  497. this._world.broadphase = new n.default.NaiveBroadphase();
  498. this._world.addEventListener("postStep", this.onPostStep.bind(this));
  499. }
  500. var e = t.prototype;
  501. e.onPostStep = function() {
  502. var t = cc.director.getPhysics3DManager();
  503. if (t.useFixedDigit) for (var e = t.fixDigits.position, i = t.fixDigits.rotation, o = this._world.bodies, r = 0; r < o.length; r++) {
  504. var s = o[r];
  505. if (s.type != n.default.Body.STATIC && !s.isSleeping()) {
  506. var a = s.position;
  507. a.x = parseFloat(a.x.toFixed(e));
  508. a.y = parseFloat(a.y.toFixed(e));
  509. a.z = parseFloat(a.z.toFixed(e));
  510. var l = s.quaternion;
  511. l.x = parseFloat(l.x.toFixed(i));
  512. l.y = parseFloat(l.y.toFixed(i));
  513. l.z = parseFloat(l.z.toFixed(i));
  514. l.w = parseFloat(l.w.toFixed(i));
  515. var h = s.velocity;
  516. h.x = parseFloat(h.x.toFixed(e));
  517. h.y = parseFloat(h.y.toFixed(e));
  518. h.z = parseFloat(h.z.toFixed(e));
  519. var c = s.angularVelocity;
  520. c.x = parseFloat(c.x.toFixed(e));
  521. c.y = parseFloat(c.y.toFixed(e));
  522. c.z = parseFloat(c.z.toFixed(e));
  523. }
  524. }
  525. };
  526. e.step = function(t, e, i) {
  527. this.syncSceneToPhysics();
  528. this._world.step(t, e, i);
  529. this.syncPhysicsToScene();
  530. this.emitEvents();
  531. };
  532. e.syncSceneToPhysics = function() {
  533. (0, l.clearNodeTransformRecord)();
  534. for (var t = 0; t < this.bodies.length; t++) this.bodies[t].syncSceneToPhysics();
  535. (0, l.clearNodeTransformDirtyFlag)();
  536. };
  537. e.syncPhysicsToScene = function() {
  538. for (var t = 0; t < this.bodies.length; t++) this.bodies[t].syncPhysicsToScene();
  539. };
  540. e.emitEvents = function() {
  541. this._world.emitTriggeredEvents();
  542. this._world.emitCollisionEvents();
  543. };
  544. e.raycastClosest = function(t, e, i) {
  545. v(t, e.maxDistance);
  546. (0, r.toCannonRaycastOptions)(m, e);
  547. var o = this._world.raycastClosest(y, f, m, this._raycastResult);
  548. o && (0, r.fillRaycastResult)(i, this._raycastResult);
  549. return o;
  550. };
  551. e.raycast = function(t, e, i, o) {
  552. v(t, e.maxDistance);
  553. (0, r.toCannonRaycastOptions)(m, e);
  554. return this._world.raycastAll(y, f, m, function(t) {
  555. var e = i.add();
  556. (0, r.fillRaycastResult)(e, t);
  557. o.push(e);
  558. });
  559. };
  560. e.getSharedBody = function(t) {
  561. return a.CannonSharedBody.getSharedBody(t, this);
  562. };
  563. e.addSharedBody = function(t) {
  564. if (this.bodies.indexOf(t) < 0) {
  565. this.bodies.push(t);
  566. this._world.addBody(t.body);
  567. }
  568. };
  569. e.removeSharedBody = function(t) {
  570. var e = this.bodies.indexOf(t);
  571. if (e >= 0) {
  572. p(this.bodies, e);
  573. this._world.remove(t.body);
  574. }
  575. };
  576. c(t, [ {
  577. key: "world",
  578. get: function() {
  579. return this._world;
  580. }
  581. }, {
  582. key: "defaultMaterial",
  583. set: function(t) {
  584. this._world.defaultMaterial.friction = t.friction;
  585. this._world.defaultMaterial.restitution = t.restitution;
  586. null != s.CannonShape.idToMaterial[t._uuid] && (s.CannonShape.idToMaterial[t._uuid] = this._world.defaultMaterial);
  587. }
  588. }, {
  589. key: "allowSleep",
  590. set: function(t) {
  591. this._world.allowSleep = t;
  592. }
  593. }, {
  594. key: "gravity",
  595. set: function(t) {
  596. u.copy(this._world.gravity, t);
  597. }
  598. } ]);
  599. return t;
  600. }();
  601. i.CannonWorld = d;
  602. var y = new n.default.Vec3(), f = new n.default.Vec3();
  603. function v(t, e) {
  604. u.copy(y, t.o);
  605. t.computeHit(f, e);
  606. }
  607. var m = {
  608. checkCollisionResponse: !1,
  609. collisionFilterGroup: -1,
  610. collisionFilterMask: -1,
  611. skipBackFaces: !1
  612. };
  613. }, {
  614. "../../../../../external/cannon/cannon": 24,
  615. "../framework/util": 23,
  616. "./cannon-shared-body": 2,
  617. "./cannon-util": 3,
  618. "./shapes/cannon-shape": 7
  619. } ],
  620. 5: [ function(t) {
  621. "use strict";
  622. 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");
  623. (0, e.instantiate)(n.CannonBoxShape, r.CannonSphereShape, i.CannonRigidBody, o.CannonWorld);
  624. }, {
  625. "../framework/physics-selector": 22,
  626. "./cannon-rigid-body": 1,
  627. "./cannon-world": 4,
  628. "./shapes/cannon-box-shape": 6,
  629. "./shapes/cannon-sphere-shape": 8
  630. } ],
  631. 6: [ function(t, e, i) {
  632. "use strict";
  633. i.__esModule = !0;
  634. i.CannonBoxShape = void 0;
  635. var o, n = (o = t("../../../../../../external/cannon/cannon")) && o.__esModule ? o : {
  636. default: o
  637. }, r = t("../cannon-util"), s = t("./cannon-shape");
  638. function a(t, e) {
  639. for (var i = 0; i < e.length; i++) {
  640. var o = e[i];
  641. o.enumerable = o.enumerable || !1;
  642. o.configurable = !0;
  643. "value" in o && (o.writable = !0);
  644. Object.defineProperty(t, o.key, o);
  645. }
  646. }
  647. function l(t, e, i) {
  648. e && a(t.prototype, e);
  649. i && a(t, i);
  650. return t;
  651. }
  652. function h(t, e) {
  653. t.prototype = Object.create(e.prototype);
  654. t.prototype.constructor = t;
  655. c(t, e);
  656. }
  657. function c(t, e) {
  658. return (c = Object.setPrototypeOf || function(t, e) {
  659. t.__proto__ = e;
  660. return t;
  661. })(t, e);
  662. }
  663. var u = cc.Vec3, p = new u(), d = function(t) {
  664. h(e, t);
  665. function e(e) {
  666. var i;
  667. (i = t.call(this) || this).halfExtent = new n.default.Vec3();
  668. u.multiplyScalar(i.halfExtent, e, .5);
  669. i._shape = new n.default.Box(i.halfExtent.clone());
  670. return i;
  671. }
  672. var i = e.prototype;
  673. i.onLoad = function() {
  674. t.prototype.onLoad.call(this);
  675. this.size = this.boxCollider.size;
  676. };
  677. i.setScale = function(e) {
  678. t.prototype.setScale.call(this, e);
  679. this.size = this.boxCollider.size;
  680. };
  681. l(e, [ {
  682. key: "boxCollider",
  683. get: function() {
  684. return this.collider;
  685. }
  686. }, {
  687. key: "box",
  688. get: function() {
  689. return this._shape;
  690. }
  691. }, {
  692. key: "size",
  693. set: function(t) {
  694. this.collider.node.getWorldScale(p);
  695. p.x = Math.abs(p.x);
  696. p.y = Math.abs(p.y);
  697. p.z = Math.abs(p.z);
  698. u.multiplyScalar(this.halfExtent, t, .5);
  699. u.multiply(this.box.halfExtents, this.halfExtent, p);
  700. this.box.updateConvexPolyhedronRepresentation();
  701. -1 != this._index && (0, r.commitShapeUpdates)(this._body);
  702. }
  703. } ]);
  704. return e;
  705. }(s.CannonShape);
  706. i.CannonBoxShape = d;
  707. }, {
  708. "../../../../../../external/cannon/cannon": 24,
  709. "../cannon-util": 3,
  710. "./cannon-shape": 7
  711. } ],
  712. 7: [ function(t, e, i) {
  713. "use strict";
  714. i.__esModule = !0;
  715. i.CannonShape = void 0;
  716. var o, n = (o = t("../../../../../../external/cannon/cannon")) && o.__esModule ? o : {
  717. default: o
  718. }, r = t("../../framework/util"), s = t("../cannon-util");
  719. function a(t, e) {
  720. for (var i = 0; i < e.length; i++) {
  721. var o = e[i];
  722. o.enumerable = o.enumerable || !1;
  723. o.configurable = !0;
  724. "value" in o && (o.writable = !0);
  725. Object.defineProperty(t, o.key, o);
  726. }
  727. }
  728. function l(t, e, i) {
  729. e && a(t.prototype, e);
  730. i && a(t, i);
  731. return t;
  732. }
  733. var h = {
  734. type: "trigger-enter",
  735. selfCollider: null,
  736. otherCollider: null
  737. }, c = cc.Vec3, u = new c(), p = function() {
  738. function t() {
  739. this._collider = void 0;
  740. this._shape = void 0;
  741. this._offset = new n.default.Vec3();
  742. this._orient = new n.default.Quaternion();
  743. this._index = -1;
  744. this._sharedBody = void 0;
  745. this.onTriggerListener = this.onTrigger.bind(this);
  746. }
  747. var e = t.prototype;
  748. e.__preload = function(t) {
  749. this._collider = t;
  750. (0, r.setWrap)(this._shape, this);
  751. this._shape.addEventListener("cc-trigger", this.onTriggerListener);
  752. this._sharedBody = cc.director.getPhysics3DManager().physicsWorld.getSharedBody(this._collider.node);
  753. this._sharedBody.reference = !0;
  754. };
  755. e.onLoad = function() {
  756. this.center = this._collider.center;
  757. this.isTrigger = this._collider.isTrigger;
  758. };
  759. e.onEnable = function() {
  760. this._sharedBody.addShape(this);
  761. this._sharedBody.enabled = !0;
  762. };
  763. e.onDisable = function() {
  764. this._sharedBody.removeShape(this);
  765. this._sharedBody.enabled = !1;
  766. };
  767. e.onDestroy = function() {
  768. this._sharedBody.reference = !1;
  769. this._shape.removeEventListener("cc-trigger", this.onTriggerListener);
  770. delete n.default.World.idToShapeMap[this._shape.id];
  771. this._sharedBody = null;
  772. (0, r.setWrap)(this._shape, null);
  773. this._offset = null;
  774. this._orient = null;
  775. this._shape = null;
  776. this._collider = null;
  777. this.onTriggerListener = null;
  778. };
  779. e.setScale = function() {
  780. this._setCenter(this._collider.center);
  781. };
  782. e.setIndex = function(t) {
  783. this._index = t;
  784. };
  785. e.setOffsetAndOrient = function(t, e) {
  786. cc.Vec3.copy(t, this._offset);
  787. cc.Vec3.copy(e, this._orient);
  788. this._offset = t;
  789. this._orient = e;
  790. };
  791. e._setCenter = function(t) {
  792. var e = this._offset;
  793. c.copy(e, t);
  794. this._collider.node.getWorldScale(u);
  795. c.multiply(e, e, u);
  796. };
  797. e.onTrigger = function(t) {
  798. h.type = t.event;
  799. var e = (0, r.getWrap)(t.selfShape), i = (0, r.getWrap)(t.otherShape);
  800. if (e) {
  801. h.selfCollider = e.collider;
  802. h.otherCollider = i ? i.collider : null;
  803. h.type = s.deprecatedEventMap[h.type];
  804. this._collider.emit(h.type, h);
  805. h.type = t.event;
  806. this._collider.emit(h.type, h);
  807. }
  808. };
  809. l(t, [ {
  810. key: "shape",
  811. get: function() {
  812. return this._shape;
  813. }
  814. }, {
  815. key: "collider",
  816. get: function() {
  817. return this._collider;
  818. }
  819. }, {
  820. key: "attachedRigidBody",
  821. get: function() {
  822. return this._sharedBody.wrappedBody ? this._sharedBody.wrappedBody.rigidBody : null;
  823. }
  824. }, {
  825. key: "sharedBody",
  826. get: function() {
  827. return this._sharedBody;
  828. }
  829. }, {
  830. key: "material",
  831. set: function(e) {
  832. if (null == e) this._shape.material = null; else {
  833. null == t.idToMaterial[e._uuid] && (t.idToMaterial[e._uuid] = new n.default.Material(e._uuid));
  834. this._shape.material = t.idToMaterial[e._uuid];
  835. this._shape.material.friction = e.friction;
  836. this._shape.material.restitution = e.restitution;
  837. }
  838. }
  839. }, {
  840. key: "isTrigger",
  841. set: function(t) {
  842. this._shape.collisionResponse = !t;
  843. this._index >= 0 && this._body.updateHasTrigger();
  844. }
  845. }, {
  846. key: "center",
  847. set: function(t) {
  848. this._setCenter(t);
  849. this._index >= 0 && (0, s.commitShapeUpdates)(this._body);
  850. }
  851. }, {
  852. key: "_body",
  853. get: function() {
  854. return this._sharedBody.body;
  855. }
  856. } ]);
  857. return t;
  858. }();
  859. i.CannonShape = p;
  860. p.idToMaterial = {};
  861. }, {
  862. "../../../../../../external/cannon/cannon": 24,
  863. "../../framework/util": 23,
  864. "../cannon-util": 3
  865. } ],
  866. 8: [ function(t, e, i) {
  867. "use strict";
  868. i.__esModule = !0;
  869. i.CannonSphereShape = void 0;
  870. var o, n = (o = t("../../../../../../external/cannon/cannon")) && o.__esModule ? o : {
  871. default: o
  872. }, r = t("../cannon-util"), s = t("./cannon-shape");
  873. function a(t, e) {
  874. for (var i = 0; i < e.length; i++) {
  875. var o = e[i];
  876. o.enumerable = o.enumerable || !1;
  877. o.configurable = !0;
  878. "value" in o && (o.writable = !0);
  879. Object.defineProperty(t, o.key, o);
  880. }
  881. }
  882. function l(t, e, i) {
  883. e && a(t.prototype, e);
  884. i && a(t, i);
  885. return t;
  886. }
  887. function h(t, e) {
  888. t.prototype = Object.create(e.prototype);
  889. t.prototype.constructor = t;
  890. c(t, e);
  891. }
  892. function c(t, e) {
  893. return (c = Object.setPrototypeOf || function(t, e) {
  894. t.__proto__ = e;
  895. return t;
  896. })(t, e);
  897. }
  898. var u = new cc.Vec3(), p = function(t) {
  899. h(e, t);
  900. function e(e) {
  901. var i;
  902. (i = t.call(this) || this)._radius = void 0;
  903. i._radius = e;
  904. i._shape = new n.default.Sphere(i._radius);
  905. return i;
  906. }
  907. var i = e.prototype;
  908. i.onLoad = function() {
  909. t.prototype.onLoad.call(this);
  910. this.radius = this.sphereCollider.radius;
  911. };
  912. i.setScale = function(e) {
  913. t.prototype.setScale.call(this, e);
  914. this.radius = this.sphereCollider.radius;
  915. };
  916. l(e, [ {
  917. key: "sphereCollider",
  918. get: function() {
  919. return this.collider;
  920. }
  921. }, {
  922. key: "sphere",
  923. get: function() {
  924. return this._shape;
  925. }
  926. }, {
  927. key: "radius",
  928. get: function() {
  929. return this._radius;
  930. },
  931. set: function(t) {
  932. this.collider.node.getWorldScale(u);
  933. var e = u.maxAxis();
  934. this.sphere.radius = t * Math.abs(e);
  935. this.sphere.updateBoundingSphereRadius();
  936. -1 != this._index && (0, r.commitShapeUpdates)(this._body);
  937. }
  938. } ]);
  939. return e;
  940. }(s.CannonShape);
  941. i.CannonSphereShape = p;
  942. }, {
  943. "../../../../../../external/cannon/cannon": 24,
  944. "../cannon-util": 3,
  945. "./cannon-shape": 7
  946. } ],
  947. 9: [ function(t) {
  948. "use strict";
  949. t("../cannon/instantiate");
  950. var e, i = (e = t("../../../../../external/cannon/cannon")) && e.__esModule ? e : {
  951. default: e
  952. };
  953. window && (window.CANNON = i.default);
  954. }, {
  955. "../../../../../external/cannon/cannon": 24,
  956. "../cannon/instantiate": 5
  957. } ],
  958. 10: [ function(t, e, i) {
  959. "use strict";
  960. i.__esModule = !0;
  961. var o = t("../framework");
  962. Object.keys(o).forEach(function(t) {
  963. "default" !== t && "__esModule" !== t && (t in i && i[t] === o[t] || (i[t] = o[t]));
  964. });
  965. }, {
  966. "../framework": 17
  967. } ],
  968. 11: [ function(t, e, i) {
  969. "use strict";
  970. i.__esModule = !0;
  971. i.PhysicsMaterial = void 0;
  972. var o, n, r, s, a, l;
  973. function h(t, e, i, o) {
  974. i && Object.defineProperty(t, e, {
  975. enumerable: i.enumerable,
  976. configurable: i.configurable,
  977. writable: i.writable,
  978. value: i.initializer ? i.initializer.call(o) : void 0
  979. });
  980. }
  981. function c(t, e) {
  982. for (var i = 0; i < e.length; i++) {
  983. var o = e[i];
  984. o.enumerable = o.enumerable || !1;
  985. o.configurable = !0;
  986. "value" in o && (o.writable = !0);
  987. Object.defineProperty(t, o.key, o);
  988. }
  989. }
  990. function u(t, e, i) {
  991. e && c(t.prototype, e);
  992. i && c(t, i);
  993. return t;
  994. }
  995. function p(t) {
  996. if (void 0 === t) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  997. return t;
  998. }
  999. function d(t, e) {
  1000. t.prototype = Object.create(e.prototype);
  1001. t.prototype.constructor = t;
  1002. y(t, e);
  1003. }
  1004. function y(t, e) {
  1005. return (y = Object.setPrototypeOf || function(t, e) {
  1006. t.__proto__ = e;
  1007. return t;
  1008. })(t, e);
  1009. }
  1010. function f(t, e, i, o, n) {
  1011. var r = {};
  1012. Object.keys(o).forEach(function(t) {
  1013. r[t] = o[t];
  1014. });
  1015. r.enumerable = !!r.enumerable;
  1016. r.configurable = !!r.configurable;
  1017. ("value" in r || r.initializer) && (r.writable = !0);
  1018. r = i.slice().reverse().reduce(function(i, o) {
  1019. return o(t, e, i) || i;
  1020. }, r);
  1021. if (n && void 0 !== r.initializer) {
  1022. r.value = r.initializer ? r.initializer.call(n) : void 0;
  1023. r.initializer = void 0;
  1024. }
  1025. if (void 0 === r.initializer) {
  1026. Object.defineProperty(t, e, r);
  1027. r = null;
  1028. }
  1029. return r;
  1030. }
  1031. 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) {
  1032. d(e, t);
  1033. function e() {
  1034. var i;
  1035. h(i = t.call(this) || this, "_friction", r, p(i));
  1036. h(i, "_restitution", s, p(i));
  1037. cc.EventTarget.call(p(i));
  1038. e.allMaterials.push(p(i));
  1039. "" == i._uuid && (i._uuid = "pm_" + e._idCounter++);
  1040. return i;
  1041. }
  1042. var i = e.prototype;
  1043. i.clone = function() {
  1044. var t = new e();
  1045. t._friction = this._friction;
  1046. t._restitution = this._restitution;
  1047. return t;
  1048. };
  1049. i.destroy = function() {
  1050. if (t.prototype.destroy.call(this)) {
  1051. b(e.allMaterials, this);
  1052. return !0;
  1053. }
  1054. return !1;
  1055. };
  1056. u(e, [ {
  1057. key: "friction",
  1058. get: function() {
  1059. return this._friction;
  1060. },
  1061. set: function(t) {
  1062. if (!w(this._friction, t)) {
  1063. this._friction = t;
  1064. this.emit("physics_material_update");
  1065. }
  1066. }
  1067. }, {
  1068. key: "restitution",
  1069. get: function() {
  1070. return this._restitution;
  1071. },
  1072. set: function(t) {
  1073. if (!w(this._restitution, t)) {
  1074. this._restitution = t;
  1075. this.emit("physics_material_update");
  1076. }
  1077. }
  1078. } ]);
  1079. return e;
  1080. }(cc.Asset), a.allMaterials = [], a._idCounter = 0, l), r = f(n.prototype, "_friction", [ g ], {
  1081. configurable: !0,
  1082. enumerable: !0,
  1083. writable: !0,
  1084. initializer: function() {
  1085. return .1;
  1086. }
  1087. }), s = f(n.prototype, "_restitution", [ g ], {
  1088. configurable: !0,
  1089. enumerable: !0,
  1090. writable: !0,
  1091. initializer: function() {
  1092. return .1;
  1093. }
  1094. }), f(n.prototype, "friction", [ g ], Object.getOwnPropertyDescriptor(n.prototype, "friction"), n.prototype),
  1095. f(n.prototype, "restitution", [ g ], Object.getOwnPropertyDescriptor(n.prototype, "restitution"), n.prototype),
  1096. n)) || o;
  1097. i.PhysicsMaterial = x;
  1098. cc.js.mixin(x.prototype, cc.EventTarget.prototype);
  1099. cc.PhysicsMaterial = x;
  1100. }, {} ],
  1101. 12: [ function(t, e, i) {
  1102. "use strict";
  1103. i.__esModule = !0;
  1104. i.BoxCollider3D = void 0;
  1105. var o, n, r, s, a, l, h, c = t("../../instance"), u = t("./collider-component");
  1106. function p(t, e, i, o) {
  1107. i && Object.defineProperty(t, e, {
  1108. enumerable: i.enumerable,
  1109. configurable: i.configurable,
  1110. writable: i.writable,
  1111. value: i.initializer ? i.initializer.call(o) : void 0
  1112. });
  1113. }
  1114. function d(t, e) {
  1115. for (var i = 0; i < e.length; i++) {
  1116. var o = e[i];
  1117. o.enumerable = o.enumerable || !1;
  1118. o.configurable = !0;
  1119. "value" in o && (o.writable = !0);
  1120. Object.defineProperty(t, o.key, o);
  1121. }
  1122. }
  1123. function y(t, e, i) {
  1124. e && d(t.prototype, e);
  1125. i && d(t, i);
  1126. return t;
  1127. }
  1128. function f(t) {
  1129. if (void 0 === t) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  1130. return t;
  1131. }
  1132. function v(t, e) {
  1133. t.prototype = Object.create(e.prototype);
  1134. t.prototype.constructor = t;
  1135. m(t, e);
  1136. }
  1137. function m(t, e) {
  1138. return (m = Object.setPrototypeOf || function(t, e) {
  1139. t.__proto__ = e;
  1140. return t;
  1141. })(t, e);
  1142. }
  1143. function g(t, e, i, o, n) {
  1144. var r = {};
  1145. Object.keys(o).forEach(function(t) {
  1146. r[t] = o[t];
  1147. });
  1148. r.enumerable = !!r.enumerable;
  1149. r.configurable = !!r.configurable;
  1150. ("value" in r || r.initializer) && (r.writable = !0);
  1151. r = i.slice().reverse().reduce(function(i, o) {
  1152. return o(t, e, i) || i;
  1153. }, r);
  1154. if (n && void 0 !== r.initializer) {
  1155. r.value = r.initializer ? r.initializer.call(n) : void 0;
  1156. r.initializer = void 0;
  1157. }
  1158. if (void 0 === r.initializer) {
  1159. Object.defineProperty(t, e, r);
  1160. r = null;
  1161. }
  1162. return r;
  1163. }
  1164. 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"),
  1165. n = _(98), r = B("i18n:MAIN_MENU.component.physics/Collider/Box 3D"), s = S({
  1166. type: cc.Vec3
  1167. }), o(a = n(a = r(a = x(a = (g((l = function(t) {
  1168. v(e, t);
  1169. function e() {
  1170. var e;
  1171. p(e = t.call(this) || this, "_size", h, f(e));
  1172. e._shape = (0, c.createBoxShape)(e._size);
  1173. return e;
  1174. }
  1175. y(e, [ {
  1176. key: "size",
  1177. get: function() {
  1178. return this._size;
  1179. },
  1180. set: function(t) {
  1181. E.copy(this._size, t);
  1182. this.boxShape.size = this._size;
  1183. }
  1184. }, {
  1185. key: "boxShape",
  1186. get: function() {
  1187. return this._shape;
  1188. }
  1189. } ]);
  1190. return e;
  1191. }(u.Collider3D)).prototype, "size", [ s ], Object.getOwnPropertyDescriptor(l.prototype, "size"), l.prototype),
  1192. h = g(l.prototype, "_size", [ S ], {
  1193. configurable: !0,
  1194. enumerable: !0,
  1195. writable: !0,
  1196. initializer: function() {
  1197. return new E(1, 1, 1);
  1198. }
  1199. }), l)) || a) || a) || a) || a);
  1200. i.BoxCollider3D = M;
  1201. }, {
  1202. "../../instance": 18,
  1203. "./collider-component": 13
  1204. } ],
  1205. 13: [ function(t, e, i) {
  1206. "use strict";
  1207. i.__esModule = !0;
  1208. i.Collider3D = void 0;
  1209. var o, n, r, s, a, l, h, c, u, p, d = t("../../assets/physics-material");
  1210. function y(t, e, i, o) {
  1211. i && Object.defineProperty(t, e, {
  1212. enumerable: i.enumerable,
  1213. configurable: i.configurable,
  1214. writable: i.writable,
  1215. value: i.initializer ? i.initializer.call(o) : void 0
  1216. });
  1217. }
  1218. function f(t, e) {
  1219. for (var i = 0; i < e.length; i++) {
  1220. var o = e[i];
  1221. o.enumerable = o.enumerable || !1;
  1222. o.configurable = !0;
  1223. "value" in o && (o.writable = !0);
  1224. Object.defineProperty(t, o.key, o);
  1225. }
  1226. }
  1227. function v(t, e, i) {
  1228. e && f(t.prototype, e);
  1229. i && f(t, i);
  1230. return t;
  1231. }
  1232. function m(t) {
  1233. if (void 0 === t) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  1234. return t;
  1235. }
  1236. function g(t, e) {
  1237. t.prototype = Object.create(e.prototype);
  1238. t.prototype.constructor = t;
  1239. b(t, e);
  1240. }
  1241. function b(t, e) {
  1242. return (b = Object.setPrototypeOf || function(t, e) {
  1243. t.__proto__ = e;
  1244. return t;
  1245. })(t, e);
  1246. }
  1247. function w(t, e, i, o, n) {
  1248. var r = {};
  1249. Object.keys(o).forEach(function(t) {
  1250. r[t] = o[t];
  1251. });
  1252. r.enumerable = !!r.enumerable;
  1253. r.configurable = !!r.configurable;
  1254. ("value" in r || r.initializer) && (r.writable = !0);
  1255. r = i.slice().reverse().reduce(function(i, o) {
  1256. return o(t, e, i) || i;
  1257. }, r);
  1258. if (n && void 0 !== r.initializer) {
  1259. r.value = r.initializer ? r.initializer.call(n) : void 0;
  1260. r.initializer = void 0;
  1261. }
  1262. if (void 0 === r.initializer) {
  1263. Object.defineProperty(t, e, r);
  1264. r = null;
  1265. }
  1266. return r;
  1267. }
  1268. var x = cc._decorator, _ = x.ccclass, B = x.property, S = cc.Vec3, E = (o = _("cc.Collider3D"),
  1269. n = B({
  1270. type: d.PhysicsMaterial,
  1271. displayName: "Material",
  1272. displayOrder: -1
  1273. }), r = B({
  1274. displayOrder: 0
  1275. }), s = B({
  1276. type: cc.Vec3,
  1277. displayOrder: 1
  1278. }), a = B({
  1279. type: d.PhysicsMaterial
  1280. }), o(l = (w((h = function(t) {
  1281. g(e, t);
  1282. function e() {
  1283. var e;
  1284. (e = t.call(this) || this)._shape = void 0;
  1285. e._isSharedMaterial = !0;
  1286. y(e, "_material", c, m(e));
  1287. y(e, "_isTrigger", u, m(e));
  1288. y(e, "_center", p, m(e));
  1289. cc.EventTarget.call(m(e));
  1290. return e;
  1291. }
  1292. var i = e.prototype;
  1293. i.on = function() {};
  1294. i.off = function() {};
  1295. i.once = function() {};
  1296. i.emit = function() {};
  1297. i.__preload = function() {
  1298. this._shape.__preload(this);
  1299. };
  1300. i.onLoad = function() {
  1301. this.sharedMaterial = null == this._material ? cc.director.getPhysics3DManager().defaultMaterial : this._material;
  1302. this._shape.onLoad();
  1303. };
  1304. i.onEnable = function() {
  1305. this._shape.onEnable();
  1306. };
  1307. i.onDisable = function() {
  1308. this._shape.onDisable();
  1309. };
  1310. i.onDestroy = function() {
  1311. this._material && this._material.off("physics_material_update", this._updateMaterial, this);
  1312. this._shape.onDestroy();
  1313. };
  1314. i._updateMaterial = function() {
  1315. this._shape.material = this._material;
  1316. };
  1317. v(e, [ {
  1318. key: "sharedMaterial",
  1319. get: function() {
  1320. return this._material;
  1321. },
  1322. set: function(t) {
  1323. this.material = t;
  1324. }
  1325. }, {
  1326. key: "material",
  1327. get: function() {
  1328. if (this._isSharedMaterial && null != this._material) {
  1329. this._material.off("physics_material_update", this._updateMaterial, this);
  1330. this._material = this._material.clone();
  1331. this._material.on("physics_material_update", this._updateMaterial, this);
  1332. this._isSharedMaterial = !1;
  1333. }
  1334. return this._material;
  1335. },
  1336. set: function(t) {
  1337. if (null != t && null != this._material) {
  1338. if (this._material._uuid != t._uuid) {
  1339. this._material.off("physics_material_update", this._updateMaterial, this);
  1340. t.on("physics_material_update", this._updateMaterial, this);
  1341. this._isSharedMaterial = !1;
  1342. this._material = t;
  1343. }
  1344. } else if (null != t && null == this._material) {
  1345. t.on("physics_material_update", this._updateMaterial, this);
  1346. this._material = t;
  1347. } else if (null == t && null != this._material) {
  1348. this._material.off("physics_material_update", this._updateMaterial, this);
  1349. this._material = t;
  1350. }
  1351. this._updateMaterial();
  1352. }
  1353. }, {
  1354. key: "isTrigger",
  1355. get: function() {
  1356. return this._isTrigger;
  1357. },
  1358. set: function(t) {
  1359. this._isTrigger = t;
  1360. this._shape.isTrigger = this._isTrigger;
  1361. }
  1362. }, {
  1363. key: "center",
  1364. get: function() {
  1365. return this._center;
  1366. },
  1367. set: function(t) {
  1368. S.copy(this._center, t);
  1369. this._shape.center = this._center;
  1370. }
  1371. }, {
  1372. key: "attachedRigidbody",
  1373. get: function() {
  1374. return this.shape.attachedRigidBody;
  1375. }
  1376. }, {
  1377. key: "shape",
  1378. get: function() {
  1379. return this._shape;
  1380. }
  1381. }, {
  1382. key: "_assertOnload",
  1383. get: function() {
  1384. var t = 0 == this._isOnLoadCalled;
  1385. t && cc.error("Physics Error: Please make sure that the node has been added to the scene");
  1386. return !t;
  1387. }
  1388. } ]);
  1389. return e;
  1390. }(cc.Component)).prototype, "sharedMaterial", [ n ], Object.getOwnPropertyDescriptor(h.prototype, "sharedMaterial"), h.prototype),
  1391. w(h.prototype, "isTrigger", [ r ], Object.getOwnPropertyDescriptor(h.prototype, "isTrigger"), h.prototype),
  1392. w(h.prototype, "center", [ s ], Object.getOwnPropertyDescriptor(h.prototype, "center"), h.prototype),
  1393. c = w(h.prototype, "_material", [ a ], {
  1394. configurable: !0,
  1395. enumerable: !0,
  1396. writable: !0,
  1397. initializer: function() {
  1398. return null;
  1399. }
  1400. }), u = w(h.prototype, "_isTrigger", [ B ], {
  1401. configurable: !0,
  1402. enumerable: !0,
  1403. writable: !0,
  1404. initializer: function() {
  1405. return !1;
  1406. }
  1407. }), p = w(h.prototype, "_center", [ B ], {
  1408. configurable: !0,
  1409. enumerable: !0,
  1410. writable: !0,
  1411. initializer: function() {
  1412. return new S();
  1413. }
  1414. }), h)) || l);
  1415. i.Collider3D = E;
  1416. cc.js.mixin(E.prototype, cc.EventTarget.prototype);
  1417. }, {
  1418. "../../assets/physics-material": 11
  1419. } ],
  1420. 14: [ function(t, e, i) {
  1421. "use strict";
  1422. i.__esModule = !0;
  1423. i.SphereCollider3D = void 0;
  1424. var o, n, r, s = t("../../instance"), a = t("./collider-component");
  1425. function l(t, e, i, o) {
  1426. i && Object.defineProperty(t, e, {
  1427. enumerable: i.enumerable,
  1428. configurable: i.configurable,
  1429. writable: i.writable,
  1430. value: i.initializer ? i.initializer.call(o) : void 0
  1431. });
  1432. }
  1433. function h(t, e) {
  1434. for (var i = 0; i < e.length; i++) {
  1435. var o = e[i];
  1436. o.enumerable = o.enumerable || !1;
  1437. o.configurable = !0;
  1438. "value" in o && (o.writable = !0);
  1439. Object.defineProperty(t, o.key, o);
  1440. }
  1441. }
  1442. function c(t, e, i) {
  1443. e && h(t.prototype, e);
  1444. i && h(t, i);
  1445. return t;
  1446. }
  1447. function u(t) {
  1448. if (void 0 === t) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  1449. return t;
  1450. }
  1451. function p(t, e) {
  1452. t.prototype = Object.create(e.prototype);
  1453. t.prototype.constructor = t;
  1454. d(t, e);
  1455. }
  1456. function d(t, e) {
  1457. return (d = Object.setPrototypeOf || function(t, e) {
  1458. t.__proto__ = e;
  1459. return t;
  1460. })(t, e);
  1461. }
  1462. function y(t, e, i, o, n) {
  1463. var r = {};
  1464. Object.keys(o).forEach(function(t) {
  1465. r[t] = o[t];
  1466. });
  1467. r.enumerable = !!r.enumerable;
  1468. r.configurable = !!r.configurable;
  1469. ("value" in r || r.initializer) && (r.writable = !0);
  1470. r = i.slice().reverse().reduce(function(i, o) {
  1471. return o(t, e, i) || i;
  1472. }, r);
  1473. if (n && void 0 !== r.initializer) {
  1474. r.value = r.initializer ? r.initializer.call(n) : void 0;
  1475. r.initializer = void 0;
  1476. }
  1477. if (void 0 === r.initializer) {
  1478. Object.defineProperty(t, e, r);
  1479. r = null;
  1480. }
  1481. return r;
  1482. }
  1483. 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) {
  1484. p(e, t);
  1485. function e() {
  1486. var e;
  1487. l(e = t.call(this) || this, "_radius", r, u(e));
  1488. e._shape = (0, s.createSphereShape)(e._radius);
  1489. return e;
  1490. }
  1491. c(e, [ {
  1492. key: "radius",
  1493. get: function() {
  1494. return this._radius;
  1495. },
  1496. set: function(t) {
  1497. this._radius = t;
  1498. this.sphereShape.radius = this._radius;
  1499. }
  1500. }, {
  1501. key: "sphereShape",
  1502. get: function() {
  1503. return this._shape;
  1504. }
  1505. } ]);
  1506. return e;
  1507. }(a.Collider3D)).prototype, "radius", [ w ], Object.getOwnPropertyDescriptor(n.prototype, "radius"), n.prototype),
  1508. r = y(n.prototype, "_radius", [ w ], {
  1509. configurable: !0,
  1510. enumerable: !0,
  1511. writable: !0,
  1512. initializer: function() {
  1513. return .5;
  1514. }
  1515. }), n)) || o) || o) || o) || o;
  1516. i.SphereCollider3D = x;
  1517. }, {
  1518. "../../instance": 18,
  1519. "./collider-component": 13
  1520. } ],
  1521. 15: [ function(t, e, i) {
  1522. "use strict";
  1523. i.__esModule = !0;
  1524. i.ConstantForce = void 0;
  1525. var o, n, r, s, a, l, h, c, u, p, d, y, f, v, m = t("./rigid-body-component");
  1526. function g(t, e, i, o) {
  1527. i && Object.defineProperty(t, e, {
  1528. enumerable: i.enumerable,
  1529. configurable: i.configurable,
  1530. writable: i.writable,
  1531. value: i.initializer ? i.initializer.call(o) : void 0
  1532. });
  1533. }
  1534. function b(t, e) {
  1535. for (var i = 0; i < e.length; i++) {
  1536. var o = e[i];
  1537. o.enumerable = o.enumerable || !1;
  1538. o.configurable = !0;
  1539. "value" in o && (o.writable = !0);
  1540. Object.defineProperty(t, o.key, o);
  1541. }
  1542. }
  1543. function w(t, e, i) {
  1544. e && b(t.prototype, e);
  1545. i && b(t, i);
  1546. return t;
  1547. }
  1548. function x(t) {
  1549. if (void 0 === t) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  1550. return t;
  1551. }
  1552. function _(t, e) {
  1553. t.prototype = Object.create(e.prototype);
  1554. t.prototype.constructor = t;
  1555. B(t, e);
  1556. }
  1557. function B(t, e) {
  1558. return (B = Object.setPrototypeOf || function(t, e) {
  1559. t.__proto__ = e;
  1560. return t;
  1561. })(t, e);
  1562. }
  1563. function S(t, e, i, o, n) {
  1564. var r = {};
  1565. Object.keys(o).forEach(function(t) {
  1566. r[t] = o[t];
  1567. });
  1568. r.enumerable = !!r.enumerable;
  1569. r.configurable = !!r.configurable;
  1570. ("value" in r || r.initializer) && (r.writable = !0);
  1571. r = i.slice().reverse().reduce(function(i, o) {
  1572. return o(t, e, i) || i;
  1573. }, r);
  1574. if (n && void 0 !== r.initializer) {
  1575. r.value = r.initializer ? r.initializer.call(n) : void 0;
  1576. r.initializer = void 0;
  1577. }
  1578. if (void 0 === r.initializer) {
  1579. Object.defineProperty(t, e, r);
  1580. r = null;
  1581. }
  1582. return r;
  1583. }
  1584. 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"),
  1585. n = A(98), r = R(m.RigidBody3D), s = z("i18n:MAIN_MENU.component.physics/Constant Force 3D"),
  1586. a = F({
  1587. displayOrder: 0
  1588. }), l = F({
  1589. displayOrder: 1
  1590. }), h = F({
  1591. displayOrder: 2
  1592. }), c = F({
  1593. displayOrder: 3
  1594. }), o(u = n(u = r(u = s(u = T(u = C(u = (p = function(t) {
  1595. _(e, t);
  1596. function e() {
  1597. for (var e, i = arguments.length, o = new Array(i), n = 0; n < i; n++) o[n] = arguments[n];
  1598. (e = t.call.apply(t, [ this ].concat(o)) || this)._rigidbody = null;
  1599. g(e, "_force", d, x(e));
  1600. g(e, "_localForce", y, x(e));
  1601. g(e, "_torque", f, x(e));
  1602. g(e, "_localTorque", v, x(e));
  1603. e._mask = 0;
  1604. return e;
  1605. }
  1606. var i = e.prototype;
  1607. i.onLoad = function() {
  1608. this._rigidbody = this.node.getComponent(m.RigidBody3D);
  1609. this._maskUpdate(this._force, 1);
  1610. this._maskUpdate(this._localForce, 2);
  1611. this._maskUpdate(this._torque, 4);
  1612. this._maskUpdate(this._localTorque, 8);
  1613. };
  1614. i.lateUpdate = function() {
  1615. if (null != this._rigidbody && 0 != this._mask) {
  1616. 1 & this._mask && this._rigidbody.applyForce(this._force);
  1617. 2 & this._mask && this._rigidbody.applyLocalForce(this.localForce);
  1618. 4 & this._mask && this._rigidbody.applyTorque(this._torque);
  1619. 8 & this._mask && this._rigidbody.applyLocalTorque(this._localTorque);
  1620. }
  1621. };
  1622. i._maskUpdate = function(t, e) {
  1623. P.strictEquals(t, P.ZERO) ? this._mask &= ~e : this._mask |= e;
  1624. };
  1625. w(e, [ {
  1626. key: "force",
  1627. get: function() {
  1628. return this._force;
  1629. },
  1630. set: function(t) {
  1631. P.copy(this._force, t);
  1632. this._maskUpdate(this._force, 1);
  1633. }
  1634. }, {
  1635. key: "localForce",
  1636. get: function() {
  1637. return this._localForce;
  1638. },
  1639. set: function(t) {
  1640. P.copy(this._localForce, t);
  1641. this._maskUpdate(this.localForce, 2);
  1642. }
  1643. }, {
  1644. key: "torque",
  1645. get: function() {
  1646. return this._torque;
  1647. },
  1648. set: function(t) {
  1649. P.copy(this._torque, t);
  1650. this._maskUpdate(this._torque, 4);
  1651. }
  1652. }, {
  1653. key: "localTorque",
  1654. get: function() {
  1655. return this._localTorque;
  1656. },
  1657. set: function(t) {
  1658. P.copy(this._localTorque, t);
  1659. this._maskUpdate(this._localTorque, 8);
  1660. }
  1661. } ]);
  1662. return e;
  1663. }(cc.Component), d = S(p.prototype, "_force", [ F ], {
  1664. configurable: !0,
  1665. enumerable: !0,
  1666. writable: !0,
  1667. initializer: function() {
  1668. return new P();
  1669. }
  1670. }), y = S(p.prototype, "_localForce", [ F ], {
  1671. configurable: !0,
  1672. enumerable: !0,
  1673. writable: !0,
  1674. initializer: function() {
  1675. return new P();
  1676. }
  1677. }), f = S(p.prototype, "_torque", [ F ], {
  1678. configurable: !0,
  1679. enumerable: !0,
  1680. writable: !0,
  1681. initializer: function() {
  1682. return new P();
  1683. }
  1684. }), v = S(p.prototype, "_localTorque", [ F ], {
  1685. configurable: !0,
  1686. enumerable: !0,
  1687. writable: !0,
  1688. initializer: function() {
  1689. return new P();
  1690. }
  1691. }), S(p.prototype, "force", [ a ], Object.getOwnPropertyDescriptor(p.prototype, "force"), p.prototype),
  1692. S(p.prototype, "localForce", [ l ], Object.getOwnPropertyDescriptor(p.prototype, "localForce"), p.prototype),
  1693. S(p.prototype, "torque", [ h ], Object.getOwnPropertyDescriptor(p.prototype, "torque"), p.prototype),
  1694. S(p.prototype, "localTorque", [ c ], Object.getOwnPropertyDescriptor(p.prototype, "localTorque"), p.prototype),
  1695. p)) || u) || u) || u) || u) || u) || u);
  1696. i.ConstantForce = q;
  1697. }, {
  1698. "./rigid-body-component": 16
  1699. } ],
  1700. 16: [ function(t, e, i) {
  1701. "use strict";
  1702. i.__esModule = !0;
  1703. i.RigidBody3D = void 0;
  1704. var o, n, r, s, a, l, h, c, u, p, d, y, f, v, m, g, b, w, x, _, B, S = t("../instance");
  1705. function E(t, e, i, o) {
  1706. i && Object.defineProperty(t, e, {
  1707. enumerable: i.enumerable,
  1708. configurable: i.configurable,
  1709. writable: i.writable,
  1710. value: i.initializer ? i.initializer.call(o) : void 0
  1711. });
  1712. }
  1713. function M(t, e) {
  1714. for (var i = 0; i < e.length; i++) {
  1715. var o = e[i];
  1716. o.enumerable = o.enumerable || !1;
  1717. o.configurable = !0;
  1718. "value" in o && (o.writable = !0);
  1719. Object.defineProperty(t, o.key, o);
  1720. }
  1721. }
  1722. function C(t, e, i) {
  1723. e && M(t.prototype, e);
  1724. i && M(t, i);
  1725. return t;
  1726. }
  1727. function A(t) {
  1728. if (void 0 === t) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  1729. return t;
  1730. }
  1731. function z(t, e) {
  1732. t.prototype = Object.create(e.prototype);
  1733. t.prototype.constructor = t;
  1734. F(t, e);
  1735. }
  1736. function F(t, e) {
  1737. return (F = Object.setPrototypeOf || function(t, e) {
  1738. t.__proto__ = e;
  1739. return t;
  1740. })(t, e);
  1741. }
  1742. function R(t, e, i, o, n) {
  1743. var r = {};
  1744. Object.keys(o).forEach(function(t) {
  1745. r[t] = o[t];
  1746. });
  1747. r.enumerable = !!r.enumerable;
  1748. r.configurable = !!r.configurable;
  1749. ("value" in r || r.initializer) && (r.writable = !0);
  1750. r = i.slice().reverse().reduce(function(i, o) {
  1751. return o(t, e, i) || i;
  1752. }, r);
  1753. if (n && void 0 !== r.initializer) {
  1754. r.value = r.initializer ? r.initializer.call(n) : void 0;
  1755. r.initializer = void 0;
  1756. }
  1757. if (void 0 === r.initializer) {
  1758. Object.defineProperty(t, e, r);
  1759. r = null;
  1760. }
  1761. return r;
  1762. }
  1763. 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"),
  1764. n = O(99), r = V("i18n:MAIN_MENU.component.physics/Rigid Body 3D"), s = j({
  1765. displayOrder: 0
  1766. }), a = j({
  1767. displayOrder: 1
  1768. }), l = j({
  1769. displayOrder: 2
  1770. }), h = j({
  1771. displayOrder: 3
  1772. }), c = j({
  1773. displayOrder: 4
  1774. }), u = j({
  1775. displayOrder: 5
  1776. }), p = j({
  1777. displayOrder: 6
  1778. }), d = j({
  1779. displayOrder: 7
  1780. }), o(y = n(y = r(y = I(y = q(y = (R((f = function(t) {
  1781. z(e, t);
  1782. function e() {
  1783. var e;
  1784. (e = t.call(this) || this)._body = void 0;
  1785. e._allowSleep = !0;
  1786. E(e, "_mass", v, A(e));
  1787. E(e, "_linearDamping", m, A(e));
  1788. E(e, "_angularDamping", g, A(e));
  1789. E(e, "_fixedRotation", b, A(e));
  1790. E(e, "_isKinematic", w, A(e));
  1791. E(e, "_useGravity", x, A(e));
  1792. E(e, "_linearFactor", _, A(e));
  1793. E(e, "_angularFactor", B, A(e));
  1794. e._body = (0, S.createRigidBody)();
  1795. return e;
  1796. }
  1797. var i = e.prototype;
  1798. i.__preload = function() {
  1799. this._body.__preload(this);
  1800. };
  1801. i.onEnable = function() {
  1802. this._body.onEnable();
  1803. };
  1804. i.onDisable = function() {
  1805. this._body.onDisable();
  1806. };
  1807. i.onDestroy = function() {
  1808. this._body.onDestroy();
  1809. };
  1810. i.applyForce = function(t, e) {
  1811. this._assertOnload && this._body.applyForce(t, e);
  1812. };
  1813. i.applyLocalForce = function(t, e) {
  1814. this._assertOnload && this._body.applyLocalForce(t, e);
  1815. };
  1816. i.applyImpulse = function(t, e) {
  1817. this._assertOnload && this._body.applyImpulse(t, e);
  1818. };
  1819. i.applyLocalImpulse = function(t, e) {
  1820. this._assertOnload && this._body.applyLocalImpulse(t, e);
  1821. };
  1822. i.applyTorque = function(t) {
  1823. this._assertOnload && this._body.applyTorque(t);
  1824. };
  1825. i.applyLocalTorque = function(t) {
  1826. this._assertOnload && this._body.applyLocalTorque(t);
  1827. };
  1828. i.wakeUp = function() {
  1829. this._assertOnload && this._body.wakeUp();
  1830. };
  1831. i.sleep = function() {
  1832. this._assertOnload && this._body.sleep();
  1833. };
  1834. i.getLinearVelocity = function(t) {
  1835. this._assertOnload && this._body.getLinearVelocity(t);
  1836. };
  1837. i.setLinearVelocity = function(t) {
  1838. this._assertOnload && this._body.setLinearVelocity(t);
  1839. };
  1840. i.getAngularVelocity = function(t) {
  1841. this._assertOnload && this._body.getAngularVelocity(t);
  1842. };
  1843. i.setAngularVelocity = function(t) {
  1844. this._assertOnload && this._body.setAngularVelocity(t);
  1845. };
  1846. C(e, [ {
  1847. key: "allowSleep",
  1848. get: function() {
  1849. return this._allowSleep;
  1850. },
  1851. set: function(t) {
  1852. this._allowSleep = t;
  1853. this._body.allowSleep = t;
  1854. }
  1855. }, {
  1856. key: "mass",
  1857. get: function() {
  1858. return this._mass;
  1859. },
  1860. set: function(t) {
  1861. this._mass = t;
  1862. this._body.mass = t;
  1863. }
  1864. }, {
  1865. key: "linearDamping",
  1866. get: function() {
  1867. return this._linearDamping;
  1868. },
  1869. set: function(t) {
  1870. this._linearDamping = t;
  1871. this._body.linearDamping = t;
  1872. }
  1873. }, {
  1874. key: "angularDamping",
  1875. get: function() {
  1876. return this._angularDamping;
  1877. },
  1878. set: function(t) {
  1879. this._angularDamping = t;
  1880. this._body.angularDamping = t;
  1881. }
  1882. }, {
  1883. key: "isKinematic",
  1884. get: function() {
  1885. return this._isKinematic;
  1886. },
  1887. set: function(t) {
  1888. this._isKinematic = t;
  1889. this._body.isKinematic = t;
  1890. }
  1891. }, {
  1892. key: "useGravity",
  1893. get: function() {
  1894. return this._useGravity;
  1895. },
  1896. set: function(t) {
  1897. this._useGravity = t;
  1898. this._body.useGravity = t;
  1899. }
  1900. }, {
  1901. key: "fixedRotation",
  1902. get: function() {
  1903. return this._fixedRotation;
  1904. },
  1905. set: function(t) {
  1906. this._fixedRotation = t;
  1907. this._body.fixedRotation = t;
  1908. }
  1909. }, {
  1910. key: "linearFactor",
  1911. get: function() {
  1912. return this._linearFactor;
  1913. },
  1914. set: function(t) {
  1915. k.copy(this._linearFactor, t);
  1916. this._body.linearFactor = this._linearFactor;
  1917. }
  1918. }, {
  1919. key: "angularFactor",
  1920. get: function() {
  1921. return this._angularFactor;
  1922. },
  1923. set: function(t) {
  1924. k.copy(this._angularFactor, t);
  1925. this._body.angularFactor = this._angularFactor;
  1926. }
  1927. }, {
  1928. key: "isAwake",
  1929. get: function() {
  1930. return !!this._assertOnload && this._body.isAwake;
  1931. }
  1932. }, {
  1933. key: "isSleepy",
  1934. get: function() {
  1935. return !!this._assertOnload && this._body.isSleepy;
  1936. }
  1937. }, {
  1938. key: "isSleeping",
  1939. get: function() {
  1940. return !!this._assertOnload && this._body.isSleeping;
  1941. }
  1942. }, {
  1943. key: "rigidBody",
  1944. get: function() {
  1945. return this._body;
  1946. }
  1947. }, {
  1948. key: "_assertOnload",
  1949. get: function() {
  1950. var t = 0 == this._isOnLoadCalled;
  1951. t && cc.error("Physics Error: Please make sure that the node has been added to the scene");
  1952. return !t;
  1953. }
  1954. } ]);
  1955. return e;
  1956. }(cc.Component)).prototype, "mass", [ s ], Object.getOwnPropertyDescriptor(f.prototype, "mass"), f.prototype),
  1957. R(f.prototype, "linearDamping", [ a ], Object.getOwnPropertyDescriptor(f.prototype, "linearDamping"), f.prototype),
  1958. R(f.prototype, "angularDamping", [ l ], Object.getOwnPropertyDescriptor(f.prototype, "angularDamping"), f.prototype),
  1959. R(f.prototype, "isKinematic", [ h ], Object.getOwnPropertyDescriptor(f.prototype, "isKinematic"), f.prototype),
  1960. R(f.prototype, "useGravity", [ c ], Object.getOwnPropertyDescriptor(f.prototype, "useGravity"), f.prototype),
  1961. R(f.prototype, "fixedRotation", [ u ], Object.getOwnPropertyDescriptor(f.prototype, "fixedRotation"), f.prototype),
  1962. R(f.prototype, "linearFactor", [ p ], Object.getOwnPropertyDescriptor(f.prototype, "linearFactor"), f.prototype),
  1963. R(f.prototype, "angularFactor", [ d ], Object.getOwnPropertyDescriptor(f.prototype, "angularFactor"), f.prototype),
  1964. v = R(f.prototype, "_mass", [ j ], {
  1965. configurable: !0,
  1966. enumerable: !0,
  1967. writable: !0,
  1968. initializer: function() {
  1969. return 10;
  1970. }
  1971. }), m = R(f.prototype, "_linearDamping", [ j ], {
  1972. configurable: !0,
  1973. enumerable: !0,
  1974. writable: !0,
  1975. initializer: function() {
  1976. return .1;
  1977. }
  1978. }), g = R(f.prototype, "_angularDamping", [ j ], {
  1979. configurable: !0,
  1980. enumerable: !0,
  1981. writable: !0,
  1982. initializer: function() {
  1983. return .1;
  1984. }
  1985. }), b = R(f.prototype, "_fixedRotation", [ j ], {
  1986. configurable: !0,
  1987. enumerable: !0,
  1988. writable: !0,
  1989. initializer: function() {
  1990. return !1;
  1991. }
  1992. }), w = R(f.prototype, "_isKinematic", [ j ], {
  1993. configurable: !0,
  1994. enumerable: !0,
  1995. writable: !0,
  1996. initializer: function() {
  1997. return !1;
  1998. }
  1999. }), x = R(f.prototype, "_useGravity", [ j ], {
  2000. configurable: !0,
  2001. enumerable: !0,
  2002. writable: !0,
  2003. initializer: function() {
  2004. return !0;
  2005. }
  2006. }), _ = R(f.prototype, "_linearFactor", [ j ], {
  2007. configurable: !0,
  2008. enumerable: !0,
  2009. writable: !0,
  2010. initializer: function() {
  2011. return new k(1, 1, 1);
  2012. }
  2013. }), B = R(f.prototype, "_angularFactor", [ j ], {
  2014. configurable: !0,
  2015. enumerable: !0,
  2016. writable: !0,
  2017. initializer: function() {
  2018. return new k(1, 1, 1);
  2019. }
  2020. }), f)) || y) || y) || y) || y) || y);
  2021. i.RigidBody3D = N;
  2022. }, {
  2023. "../instance": 18
  2024. } ],
  2025. 17: [ function(t, e, i) {
  2026. "use strict";
  2027. i.__esModule = !0;
  2028. var o = t("./physics-manager");
  2029. i.Physics3DManager = o.Physics3DManager;
  2030. var n = t("./physics-ray-result");
  2031. i.PhysicsRayResult = n.PhysicsRayResult;
  2032. var r = t("./components/collider/box-collider-component");
  2033. i.BoxCollider3D = r.BoxCollider3D;
  2034. var s = t("./components/collider/collider-component");
  2035. i.Collider3D = s.Collider3D;
  2036. var a = t("./components/collider/sphere-collider-component");
  2037. i.SphereCollider3D = a.SphereCollider3D;
  2038. var l = t("./components/rigid-body-component");
  2039. i.RigidBody3D = l.RigidBody3D;
  2040. var h = t("./components/constant-force"), c = t("./assets/physics-material");
  2041. i.PhysicsMaterial = c.PhysicsMaterial;
  2042. cc.Physics3DManager = o.Physics3DManager;
  2043. cc.Collider3D = s.Collider3D;
  2044. cc.BoxCollider3D = r.BoxCollider3D;
  2045. cc.SphereCollider3D = a.SphereCollider3D;
  2046. cc.RigidBody3D = l.RigidBody3D;
  2047. cc.PhysicsRayResult = n.PhysicsRayResult;
  2048. cc.ConstantForce = h.ConstantForce;
  2049. }, {
  2050. "./assets/physics-material": 11,
  2051. "./components/collider/box-collider-component": 12,
  2052. "./components/collider/collider-component": 13,
  2053. "./components/collider/sphere-collider-component": 14,
  2054. "./components/constant-force": 15,
  2055. "./components/rigid-body-component": 16,
  2056. "./physics-manager": 20,
  2057. "./physics-ray-result": 21
  2058. } ],
  2059. 18: [ function(t, e, i) {
  2060. "use strict";
  2061. i.__esModule = !0;
  2062. i.createPhysicsWorld = function() {
  2063. return new o.PhysicsWorld();
  2064. };
  2065. i.createRigidBody = function() {
  2066. return new o.RigidBody();
  2067. };
  2068. i.createBoxShape = function(t) {
  2069. return new o.BoxShape(t);
  2070. };
  2071. i.createSphereShape = function(t) {
  2072. return new o.SphereShape(t);
  2073. };
  2074. var o = t("./physics-selector");
  2075. }, {
  2076. "./physics-selector": 22
  2077. } ],
  2078. 19: [ function(t, e, i) {
  2079. "use strict";
  2080. i.__esModule = !0;
  2081. i.ERigidBodyType = void 0;
  2082. var o;
  2083. i.ERigidBodyType = o;
  2084. (function(t) {
  2085. t[t.DYNAMIC = 1] = "DYNAMIC";
  2086. t[t.STATIC = 2] = "STATIC";
  2087. t[t.KINEMATIC = 4] = "KINEMATIC";
  2088. })(o || (i.ERigidBodyType = o = {}));
  2089. }, {} ],
  2090. 20: [ function(t, e, i) {
  2091. "use strict";
  2092. i.__esModule = !0;
  2093. i.Physics3DManager = void 0;
  2094. var o, n, r, s, a, l, h, c, u = t("./instance"), p = t("./assets/physics-material"), d = t("./physics-ray-result");
  2095. function y(t, e, i, o) {
  2096. i && Object.defineProperty(t, e, {
  2097. enumerable: i.enumerable,
  2098. configurable: i.configurable,
  2099. writable: i.writable,
  2100. value: i.initializer ? i.initializer.call(o) : void 0
  2101. });
  2102. }
  2103. function f(t, e) {
  2104. for (var i = 0; i < e.length; i++) {
  2105. var o = e[i];
  2106. o.enumerable = o.enumerable || !1;
  2107. o.configurable = !0;
  2108. "value" in o && (o.writable = !0);
  2109. Object.defineProperty(t, o.key, o);
  2110. }
  2111. }
  2112. function v(t, e, i) {
  2113. e && f(t.prototype, e);
  2114. i && f(t, i);
  2115. return t;
  2116. }
  2117. function m(t, e, i, o, n) {
  2118. var r = {};
  2119. Object.keys(o).forEach(function(t) {
  2120. r[t] = o[t];
  2121. });
  2122. r.enumerable = !!r.enumerable;
  2123. r.configurable = !!r.configurable;
  2124. ("value" in r || r.initializer) && (r.writable = !0);
  2125. r = i.slice().reverse().reduce(function(i, o) {
  2126. return o(t, e, i) || i;
  2127. }, r);
  2128. if (n && void 0 !== r.initializer) {
  2129. r.value = r.initializer ? r.initializer.call(n) : void 0;
  2130. r.initializer = void 0;
  2131. }
  2132. if (void 0 === r.initializer) {
  2133. Object.defineProperty(t, e, r);
  2134. r = null;
  2135. }
  2136. return r;
  2137. }
  2138. var g = cc._decorator, b = g.property, w = (0, g.ccclass)("cc.Physics3DManager")(o = (r = m((n = function() {
  2139. function t() {
  2140. this.physicsWorld = void 0;
  2141. this.raycastClosestResult = new d.PhysicsRayResult();
  2142. this.raycastResults = [];
  2143. y(this, "_enabled", r, this);
  2144. y(this, "_allowSleep", s, this);
  2145. y(this, "_gravity", a, this);
  2146. y(this, "_maxSubStep", l, this);
  2147. y(this, "_fixedTime", h, this);
  2148. y(this, "_useFixedTime", c, this);
  2149. this.useAccumulator = !1;
  2150. this._accumulator = 0;
  2151. this.useFixedDigit = !1;
  2152. this.useInternalTime = !1;
  2153. this.fixDigits = {
  2154. position: 5,
  2155. rotation: 12,
  2156. timeNow: 3
  2157. };
  2158. this._deltaTime = 0;
  2159. this._lastTime = 0;
  2160. this._material = null;
  2161. this.raycastOptions = {
  2162. groupIndex: -1,
  2163. queryTrigger: !0,
  2164. maxDistance: Infinity
  2165. };
  2166. this.raycastResultPool = new cc.RecyclePool(function() {
  2167. return new d.PhysicsRayResult();
  2168. }, 1);
  2169. cc.director._scheduler && cc.director._scheduler.enableForTarget(this);
  2170. this.physicsWorld = (0, u.createPhysicsWorld)();
  2171. this._lastTime = performance.now();
  2172. this.gravity = this._gravity;
  2173. this.allowSleep = this._allowSleep;
  2174. this._material = new p.PhysicsMaterial();
  2175. this._material.friction = .1;
  2176. this._material.restitution = .1;
  2177. this._material.on("physics_material_update", this._updateMaterial, this);
  2178. this.physicsWorld.defaultMaterial = this._material;
  2179. }
  2180. var e = t.prototype;
  2181. e.update = function(t) {
  2182. if (this._enabled) {
  2183. if (this.useInternalTime) {
  2184. var e = parseFloat(performance.now().toFixed(this.fixDigits.timeNow));
  2185. this._deltaTime = e > this._lastTime ? (e - this._lastTime) / 1e3 : 0;
  2186. this._lastTime = e;
  2187. } else this._deltaTime = t;
  2188. cc.director.emit(cc.Director.EVENT_BEFORE_PHYSICS);
  2189. if (this._useFixedTime) this.physicsWorld.step(this._fixedTime); else if (this.useAccumulator) {
  2190. var i = 0;
  2191. this._accumulator += this._deltaTime;
  2192. for (;i < this._maxSubStep && this._accumulator > this._fixedTime; ) {
  2193. this.physicsWorld.step(this._fixedTime);
  2194. this._accumulator -= this._fixedTime;
  2195. i++;
  2196. }
  2197. } else this.physicsWorld.step(this._fixedTime, this._deltaTime, this._maxSubStep);
  2198. cc.director.emit(cc.Director.EVENT_AFTER_PHYSICS);
  2199. }
  2200. };
  2201. e.raycast = function(t, e, i, o) {
  2202. void 0 === e && (e = 0);
  2203. void 0 === i && (i = Infinity);
  2204. void 0 === o && (o = !0);
  2205. this.raycastResultPool.reset();
  2206. this.raycastResults.length = 0;
  2207. if ("string" == typeof e) {
  2208. var n = cc.game.groupList.indexOf(e);
  2209. -1 == n && (n = 0);
  2210. this.raycastOptions.groupIndex = n;
  2211. } else this.raycastOptions.groupIndex = e;
  2212. this.raycastOptions.maxDistance = i;
  2213. this.raycastOptions.queryTrigger = o;
  2214. return this.physicsWorld.raycast(t, this.raycastOptions, this.raycastResultPool, this.raycastResults) ? this.raycastResults : null;
  2215. };
  2216. e.raycastClosest = function(t, e, i, o) {
  2217. void 0 === e && (e = 0);
  2218. void 0 === i && (i = Infinity);
  2219. void 0 === o && (o = !0);
  2220. if ("string" == typeof e) {
  2221. var n = cc.game.groupList.indexOf(e);
  2222. -1 == n && (n = 0);
  2223. this.raycastOptions.groupIndex = n;
  2224. } else this.raycastOptions.groupIndex = e;
  2225. this.raycastOptions.maxDistance = i;
  2226. this.raycastOptions.queryTrigger = o;
  2227. return this.physicsWorld.raycastClosest(t, this.raycastOptions, this.raycastClosestResult) ? this.raycastClosestResult : null;
  2228. };
  2229. e._updateMaterial = function() {
  2230. this.physicsWorld.defaultMaterial = this._material;
  2231. };
  2232. v(t, [ {
  2233. key: "enabled",
  2234. get: function() {
  2235. return this._enabled;
  2236. },
  2237. set: function(t) {
  2238. this._enabled = t;
  2239. }
  2240. }, {
  2241. key: "allowSleep",
  2242. get: function() {
  2243. return this._allowSleep;
  2244. },
  2245. set: function(t) {
  2246. this._allowSleep = t;
  2247. this.physicsWorld.allowSleep = this._allowSleep;
  2248. }
  2249. }, {
  2250. key: "maxSubStep",
  2251. get: function() {
  2252. return this._maxSubStep;
  2253. },
  2254. set: function(t) {
  2255. this._maxSubStep = t;
  2256. }
  2257. }, {
  2258. key: "deltaTime",
  2259. get: function() {
  2260. return this._fixedTime;
  2261. },
  2262. set: function(t) {
  2263. this._fixedTime = t;
  2264. }
  2265. }, {
  2266. key: "useFixedTime",
  2267. get: function() {
  2268. return this._useFixedTime;
  2269. },
  2270. set: function(t) {
  2271. this._useFixedTime = t;
  2272. }
  2273. }, {
  2274. key: "gravity",
  2275. get: function() {
  2276. return this._gravity;
  2277. },
  2278. set: function(t) {
  2279. this._gravity.set(t);
  2280. this.physicsWorld.gravity = t;
  2281. }
  2282. }, {
  2283. key: "defaultMaterial",
  2284. get: function() {
  2285. return this._material;
  2286. }
  2287. } ]);
  2288. return t;
  2289. }()).prototype, "_enabled", [ b ], {
  2290. configurable: !0,
  2291. enumerable: !0,
  2292. writable: !0,
  2293. initializer: function() {
  2294. return !1;
  2295. }
  2296. }), s = m(n.prototype, "_allowSleep", [ b ], {
  2297. configurable: !0,
  2298. enumerable: !0,
  2299. writable: !0,
  2300. initializer: function() {
  2301. return !0;
  2302. }
  2303. }), a = m(n.prototype, "_gravity", [ b ], {
  2304. configurable: !0,
  2305. enumerable: !0,
  2306. writable: !0,
  2307. initializer: function() {
  2308. return new cc.Vec3(0, -10, 0);
  2309. }
  2310. }), l = m(n.prototype, "_maxSubStep", [ b ], {
  2311. configurable: !0,
  2312. enumerable: !0,
  2313. writable: !0,
  2314. initializer: function() {
  2315. return 1;
  2316. }
  2317. }), h = m(n.prototype, "_fixedTime", [ b ], {
  2318. configurable: !0,
  2319. enumerable: !0,
  2320. writable: !0,
  2321. initializer: function() {
  2322. return 1 / 60;
  2323. }
  2324. }), c = m(n.prototype, "_useFixedTime", [ b ], {
  2325. configurable: !0,
  2326. enumerable: !0,
  2327. writable: !0,
  2328. initializer: function() {
  2329. return !0;
  2330. }
  2331. }), n)) || o;
  2332. i.Physics3DManager = w;
  2333. }, {
  2334. "./assets/physics-material": 11,
  2335. "./instance": 18,
  2336. "./physics-ray-result": 21
  2337. } ],
  2338. 21: [ function(t, e, i) {
  2339. "use strict";
  2340. i.__esModule = !0;
  2341. i.PhysicsRayResult = void 0;
  2342. function o(t, e) {
  2343. for (var i = 0; i < e.length; i++) {
  2344. var o = e[i];
  2345. o.enumerable = o.enumerable || !1;
  2346. o.configurable = !0;
  2347. "value" in o && (o.writable = !0);
  2348. Object.defineProperty(t, o.key, o);
  2349. }
  2350. }
  2351. function n(t, e, i) {
  2352. e && o(t.prototype, e);
  2353. i && o(t, i);
  2354. return t;
  2355. }
  2356. var r = cc.Vec3, s = function() {
  2357. function t() {
  2358. this._hitPoint = new r();
  2359. this._distance = 0;
  2360. this._collidier = null;
  2361. }
  2362. var e = t.prototype;
  2363. e._assign = function(t, e, i) {
  2364. r.copy(this._hitPoint, t);
  2365. this._distance = e;
  2366. this._collidier = i;
  2367. };
  2368. e.clone = function() {
  2369. var e = new t();
  2370. r.copy(e._hitPoint, this._hitPoint);
  2371. e._distance = this._distance;
  2372. e._collidier = this._collidier;
  2373. return e;
  2374. };
  2375. n(t, [ {
  2376. key: "hitPoint",
  2377. get: function() {
  2378. return this._hitPoint;
  2379. }
  2380. }, {
  2381. key: "distance",
  2382. get: function() {
  2383. return this._distance;
  2384. }
  2385. }, {
  2386. key: "collider",
  2387. get: function() {
  2388. return this._collidier;
  2389. }
  2390. } ]);
  2391. return t;
  2392. }();
  2393. i.PhysicsRayResult = s;
  2394. }, {} ],
  2395. 22: [ function(t, e, i) {
  2396. "use strict";
  2397. i.__esModule = !0;
  2398. i.instantiate = function(t, e, a, l) {
  2399. i.BoxShape = o = t;
  2400. i.SphereShape = n = e;
  2401. i.RigidBody = r = a;
  2402. i.PhysicsWorld = s = l;
  2403. };
  2404. i.PhysicsWorld = i.RigidBody = i.SphereShape = i.BoxShape = void 0;
  2405. var o, n, r, s;
  2406. i.BoxShape = o;
  2407. i.SphereShape = n;
  2408. i.RigidBody = r;
  2409. i.PhysicsWorld = s;
  2410. }, {} ],
  2411. 23: [ function(t, e, i) {
  2412. "use strict";
  2413. i.__esModule = !0;
  2414. i.stringfyVec3 = function(t) {
  2415. return "(x: " + t.x + ", y: " + t.y + ", z: " + t.z + ")";
  2416. };
  2417. i.stringfyQuat = function(t) {
  2418. return "(x: " + t.x + ", y: " + t.y + ", z: " + t.z + ", w: " + t.w + ")";
  2419. };
  2420. i.setWrap = function(t, e) {
  2421. t.__cc_wrapper__ = e;
  2422. };
  2423. i.getWrap = function(t) {
  2424. return t.__cc_wrapper__;
  2425. };
  2426. i.clearNodeTransformDirtyFlag = function() {
  2427. for (var t in b) {
  2428. var e = b[t];
  2429. e._localMatDirty &= ~r;
  2430. e._localMatDirty & s || (e._worldMatDirty = !1);
  2431. }
  2432. b = {};
  2433. p.length = 0;
  2434. };
  2435. i.clearNodeTransformRecord = function() {
  2436. b = {};
  2437. p.length = 0;
  2438. };
  2439. i.updateWorldTransform = w;
  2440. i.updateWorldRT = function(t, e, i) {
  2441. var o = t.parent;
  2442. if (o) {
  2443. w(o, !0);
  2444. h.transformMat4(d, e, l.invert(g, o._worldMatrix));
  2445. c.multiply(m, c.conjugate(m, o.__wrot), i);
  2446. t.setPosition(d);
  2447. t.setRotation(m);
  2448. } else {
  2449. t.setPosition(e);
  2450. t.setRotation(i);
  2451. }
  2452. };
  2453. i.worldDirty = function(t) {
  2454. for (var e = t; e; ) {
  2455. if (e._worldMatDirty) return !0;
  2456. e = e._parent;
  2457. }
  2458. return !1;
  2459. };
  2460. var o = cc.Node._LocalDirtyFlag, n = o.PHYSICS_TRS, r = o.ALL_TRS, s = o.SKEW, a = (cc.RenderFlow.FLAG_TRANSFORM,
  2461. 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 = {};
  2462. function w(t, e) {
  2463. void 0 === e && (e = !1);
  2464. for (var i, o, r, s, g, w, x, _, B = t, S = 0, E = !1, M = 0; B; ) {
  2465. if (!e && b[B._id]) {
  2466. M |= B._localMatDirty & n;
  2467. E = E || !!M;
  2468. break;
  2469. }
  2470. p[S++] = B;
  2471. B._localMatDirty & n && (E = !0);
  2472. B = B._parent;
  2473. }
  2474. if (!E) return !1;
  2475. p.length = S;
  2476. for (;S; ) {
  2477. i = p[--S];
  2478. !e && (b[i._id] = i);
  2479. o = i._worldMatrix;
  2480. g = i._matrix;
  2481. s = i._trs;
  2482. w = i.__wpos = i.__wpos || cc.v3();
  2483. x = i.__wrot = i.__wrot || cc.quat();
  2484. _ = i.__wscale = i.__wscale || cc.v3();
  2485. i._localMatDirty & n && u.toMat4(g, s);
  2486. i._localMatDirty |= M;
  2487. if ((M |= i._localMatDirty & n) & n) {
  2488. if (B) {
  2489. r = B._worldMatrix;
  2490. u.toPosition(d, s);
  2491. h.transformMat4(w, d, r);
  2492. l.multiply(o, r, g);
  2493. u.toRotation(y, s);
  2494. c.multiply(x, B.__wrot, y);
  2495. a.fromQuat(f, c.conjugate(m, x));
  2496. a.multiplyMat4(f, f, o);
  2497. _.x = v[0];
  2498. _.y = v[4];
  2499. _.z = v[8];
  2500. } else {
  2501. u.toPosition(w, s);
  2502. u.toRotation(x, s);
  2503. u.toScale(_, s);
  2504. l.copy(o, g);
  2505. }
  2506. B = i;
  2507. } else B = i;
  2508. }
  2509. return !0;
  2510. }
  2511. }, {} ],
  2512. 24: [ function(t, e, i) {
  2513. (function(o) {
  2514. "use strict";
  2515. !function(t) {
  2516. if ("object" == typeof i && "undefined" != typeof e) e.exports = t(); else if ("function" == typeof define && define.amd) define([], t); else {
  2517. var n;
  2518. "undefined" != typeof window ? n = window : "undefined" != typeof o ? n = o : "undefined" != typeof self && (n = self),
  2519. n.CANNON = t();
  2520. }
  2521. }(function() {
  2522. return function e(i, o, n) {
  2523. function r(a, l) {
  2524. if (!o[a]) {
  2525. if (!i[a]) {
  2526. var h = "function" == typeof t && t;
  2527. if (!l && h) return h(a, !0);
  2528. if (s) return s(a, !0);
  2529. throw new Error("Cannot find module '" + a + "'");
  2530. }
  2531. var c = o[a] = {
  2532. exports: {}
  2533. };
  2534. i[a][0].call(c.exports, function(t) {
  2535. return r(i[a][1][t] || t);
  2536. }, c, c.exports, e, i, o, n);
  2537. }
  2538. return o[a].exports;
  2539. }
  2540. for (var s = "function" == typeof t && t, a = 0; a < n.length; a++) r(n[a]);
  2541. return r;
  2542. }({
  2543. 1: [ function(t, e) {
  2544. e.exports = {
  2545. name: "@cocos/cannon",
  2546. version: "1.1.1-exp.3",
  2547. description: "A lightweight 3D physics engine written in JavaScript.",
  2548. homepage: "https://github.com/cocos-creator/cannon.js",
  2549. author: "Stefan Hedman <schteppe@gmail.com> (http://steffe.se), JayceLai",
  2550. keywords: [ "cannon.js", "cocos", "creator", "physics", "engine", "3d" ],
  2551. scripts: {
  2552. build: "grunt && npm run preprocess && grunt addLicense && grunt addDate",
  2553. preprocess: "node node_modules/uglify-js/bin/uglifyjs build/cannon.js -o build/cannon.min.js -c -m"
  2554. },
  2555. main: "./build/cannon.min.js",
  2556. engines: {
  2557. node: "*"
  2558. },
  2559. repository: {
  2560. type: "git",
  2561. url: "https://github.com/cocos-creator/cannon.js.git"
  2562. },
  2563. bugs: {
  2564. url: "https://github.com/cocos-creator/cannon.js/issues"
  2565. },
  2566. licenses: [ {
  2567. type: "MIT"
  2568. } ],
  2569. devDependencies: {
  2570. jshint: "latest",
  2571. "uglify-js": "latest",
  2572. nodeunit: "^0.9.0",
  2573. grunt: "~0.4.0",
  2574. "grunt-contrib-jshint": "~0.1.1",
  2575. "grunt-contrib-nodeunit": "^0.4.1",
  2576. "grunt-contrib-concat": "~0.1.3",
  2577. "grunt-contrib-uglify": "^0.5.1",
  2578. "grunt-browserify": "^2.1.4",
  2579. "grunt-contrib-yuidoc": "^0.5.2",
  2580. browserify: "*"
  2581. },
  2582. dependencies: {}
  2583. };
  2584. }, {} ],
  2585. 2: [ function(t, e) {
  2586. e.exports = {
  2587. version: t("../package.json").version,
  2588. AABB: t("./collision/AABB"),
  2589. ArrayCollisionMatrix: t("./collision/ArrayCollisionMatrix"),
  2590. Body: t("./objects/Body"),
  2591. Box: t("./shapes/Box"),
  2592. Broadphase: t("./collision/Broadphase"),
  2593. Constraint: t("./constraints/Constraint"),
  2594. ContactEquation: t("./equations/ContactEquation"),
  2595. Narrowphase: t("./world/Narrowphase"),
  2596. ConeTwistConstraint: t("./constraints/ConeTwistConstraint"),
  2597. ContactMaterial: t("./material/ContactMaterial"),
  2598. ConvexPolyhedron: t("./shapes/ConvexPolyhedron"),
  2599. Cylinder: t("./shapes/Cylinder"),
  2600. DistanceConstraint: t("./constraints/DistanceConstraint"),
  2601. Equation: t("./equations/Equation"),
  2602. EventTarget: t("./utils/EventTarget"),
  2603. FrictionEquation: t("./equations/FrictionEquation"),
  2604. GSSolver: t("./solver/GSSolver"),
  2605. GridBroadphase: t("./collision/GridBroadphase"),
  2606. Heightfield: t("./shapes/Heightfield"),
  2607. HingeConstraint: t("./constraints/HingeConstraint"),
  2608. LockConstraint: t("./constraints/LockConstraint"),
  2609. Mat3: t("./math/Mat3"),
  2610. Material: t("./material/Material"),
  2611. NaiveBroadphase: t("./collision/NaiveBroadphase"),
  2612. ObjectCollisionMatrix: t("./collision/ObjectCollisionMatrix"),
  2613. Pool: t("./utils/Pool"),
  2614. Particle: t("./shapes/Particle"),
  2615. Plane: t("./shapes/Plane"),
  2616. PointToPointConstraint: t("./constraints/PointToPointConstraint"),
  2617. Quaternion: t("./math/Quaternion"),
  2618. Ray: t("./collision/Ray"),
  2619. RaycastVehicle: t("./objects/RaycastVehicle"),
  2620. RaycastResult: t("./collision/RaycastResult"),
  2621. RigidVehicle: t("./objects/RigidVehicle"),
  2622. RotationalEquation: t("./equations/RotationalEquation"),
  2623. RotationalMotorEquation: t("./equations/RotationalMotorEquation"),
  2624. SAPBroadphase: t("./collision/SAPBroadphase"),
  2625. SPHSystem: t("./objects/SPHSystem"),
  2626. Shape: t("./shapes/Shape"),
  2627. Solver: t("./solver/Solver"),
  2628. Sphere: t("./shapes/Sphere"),
  2629. SplitSolver: t("./solver/SplitSolver"),
  2630. Spring: t("./objects/Spring"),
  2631. Transform: t("./math/Transform"),
  2632. Trimesh: t("./shapes/Trimesh"),
  2633. Vec3: t("./math/Vec3"),
  2634. Vec3Pool: t("./utils/Vec3Pool"),
  2635. World: t("./world/World"),
  2636. Octree: t("./utils/Octree"),
  2637. CMath: t("./math/CMath")
  2638. };
  2639. }, {
  2640. "../package.json": 1,
  2641. "./collision/AABB": 3,
  2642. "./collision/ArrayCollisionMatrix": 4,
  2643. "./collision/Broadphase": 5,
  2644. "./collision/GridBroadphase": 6,
  2645. "./collision/NaiveBroadphase": 7,
  2646. "./collision/ObjectCollisionMatrix": 8,
  2647. "./collision/Ray": 10,
  2648. "./collision/RaycastResult": 11,
  2649. "./collision/SAPBroadphase": 12,
  2650. "./constraints/ConeTwistConstraint": 13,
  2651. "./constraints/Constraint": 14,
  2652. "./constraints/DistanceConstraint": 15,
  2653. "./constraints/HingeConstraint": 16,
  2654. "./constraints/LockConstraint": 17,
  2655. "./constraints/PointToPointConstraint": 18,
  2656. "./equations/ContactEquation": 20,
  2657. "./equations/Equation": 21,
  2658. "./equations/FrictionEquation": 22,
  2659. "./equations/RotationalEquation": 23,
  2660. "./equations/RotationalMotorEquation": 24,
  2661. "./material/ContactMaterial": 25,
  2662. "./material/Material": 26,
  2663. "./math/CMath": 27,
  2664. "./math/Mat3": 29,
  2665. "./math/Quaternion": 30,
  2666. "./math/Transform": 31,
  2667. "./math/Vec3": 32,
  2668. "./objects/Body": 33,
  2669. "./objects/RaycastVehicle": 34,
  2670. "./objects/RigidVehicle": 35,
  2671. "./objects/SPHSystem": 36,
  2672. "./objects/Spring": 37,
  2673. "./shapes/Box": 39,
  2674. "./shapes/ConvexPolyhedron": 40,
  2675. "./shapes/Cylinder": 41,
  2676. "./shapes/Heightfield": 42,
  2677. "./shapes/Particle": 43,
  2678. "./shapes/Plane": 44,
  2679. "./shapes/Shape": 45,
  2680. "./shapes/Sphere": 46,
  2681. "./shapes/Trimesh": 47,
  2682. "./solver/GSSolver": 48,
  2683. "./solver/Solver": 49,
  2684. "./solver/SplitSolver": 50,
  2685. "./utils/EventTarget": 51,
  2686. "./utils/Octree": 52,
  2687. "./utils/Pool": 53,
  2688. "./utils/Vec3Pool": 56,
  2689. "./world/Narrowphase": 57,
  2690. "./world/World": 58
  2691. } ],
  2692. 3: [ function(t, e) {
  2693. var i = t("../math/Vec3");
  2694. t("../utils/Utils");
  2695. e.exports = o;
  2696. function o(t) {
  2697. t = t || {};
  2698. this.lowerBound = new i();
  2699. t.lowerBound && this.lowerBound.copy(t.lowerBound);
  2700. this.upperBound = new i();
  2701. t.upperBound && this.upperBound.copy(t.upperBound);
  2702. }
  2703. var n = new i();
  2704. o.prototype.setFromPoints = function(t, e, i, o) {
  2705. var r = this.lowerBound, s = this.upperBound, a = i;
  2706. r.copy(t[0]);
  2707. a && a.vmult(r, r);
  2708. s.copy(r);
  2709. for (var l = 1; l < t.length; l++) {
  2710. var h = t[l];
  2711. if (a) {
  2712. a.vmult(h, n);
  2713. h = n;
  2714. }
  2715. h.x > s.x && (s.x = h.x);
  2716. h.x < r.x && (r.x = h.x);
  2717. h.y > s.y && (s.y = h.y);
  2718. h.y < r.y && (r.y = h.y);
  2719. h.z > s.z && (s.z = h.z);
  2720. h.z < r.z && (r.z = h.z);
  2721. }
  2722. if (e) {
  2723. e.vadd(r, r);
  2724. e.vadd(s, s);
  2725. }
  2726. if (o) {
  2727. r.x -= o;
  2728. r.y -= o;
  2729. r.z -= o;
  2730. s.x += o;
  2731. s.y += o;
  2732. s.z += o;
  2733. }
  2734. return this;
  2735. };
  2736. o.prototype.copy = function(t) {
  2737. this.lowerBound.copy(t.lowerBound);
  2738. this.upperBound.copy(t.upperBound);
  2739. return this;
  2740. };
  2741. o.prototype.clone = function() {
  2742. return new o().copy(this);
  2743. };
  2744. o.prototype.extend = function(t) {
  2745. this.lowerBound.x = Math.min(this.lowerBound.x, t.lowerBound.x);
  2746. this.upperBound.x = Math.max(this.upperBound.x, t.upperBound.x);
  2747. this.lowerBound.y = Math.min(this.lowerBound.y, t.lowerBound.y);
  2748. this.upperBound.y = Math.max(this.upperBound.y, t.upperBound.y);
  2749. this.lowerBound.z = Math.min(this.lowerBound.z, t.lowerBound.z);
  2750. this.upperBound.z = Math.max(this.upperBound.z, t.upperBound.z);
  2751. };
  2752. o.prototype.overlaps = function(t) {
  2753. 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;
  2754. return r && s && a;
  2755. };
  2756. o.prototype.volume = function() {
  2757. var t = this.lowerBound, e = this.upperBound;
  2758. return (e.x - t.x) * (e.y - t.y) * (e.z - t.z);
  2759. };
  2760. o.prototype.contains = function(t) {
  2761. var e = this.lowerBound, i = this.upperBound, o = t.lowerBound, n = t.upperBound;
  2762. 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;
  2763. };
  2764. o.prototype.getCorners = function(t, e, i, o, n, r, s, a) {
  2765. var l = this.lowerBound, h = this.upperBound;
  2766. t.copy(l);
  2767. e.set(h.x, l.y, l.z);
  2768. i.set(h.x, h.y, l.z);
  2769. o.set(l.x, h.y, h.z);
  2770. n.set(h.x, l.y, h.z);
  2771. r.set(l.x, h.y, l.z);
  2772. s.set(l.x, l.y, h.z);
  2773. a.copy(h);
  2774. };
  2775. var r = [ new i(), new i(), new i(), new i(), new i(), new i(), new i(), new i() ];
  2776. o.prototype.toLocalFrame = function(t, e) {
  2777. 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];
  2778. this.getCorners(o, n, s, a, l, h, c, u);
  2779. for (var p = 0; 8 !== p; p++) {
  2780. var d = i[p];
  2781. t.pointToLocal(d, d);
  2782. }
  2783. return e.setFromPoints(i);
  2784. };
  2785. o.prototype.toWorldFrame = function(t, e) {
  2786. 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];
  2787. this.getCorners(o, n, s, a, l, h, c, u);
  2788. for (var p = 0; 8 !== p; p++) {
  2789. var d = i[p];
  2790. t.pointToWorld(d, d);
  2791. }
  2792. return e.setFromPoints(i);
  2793. };
  2794. o.prototype.overlapsRay = function(t) {
  2795. 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));
  2796. return !(u < 0 || c > u);
  2797. };
  2798. }, {
  2799. "../math/Vec3": 32,
  2800. "../utils/Utils": 55
  2801. } ],
  2802. 4: [ function(t, e) {
  2803. e.exports = i;
  2804. function i() {
  2805. this.matrix = [];
  2806. }
  2807. i.prototype.get = function(t, e) {
  2808. t = t.index;
  2809. if ((e = e.index) > t) {
  2810. var i = e;
  2811. e = t;
  2812. t = i;
  2813. }
  2814. return this.matrix[(t * (t + 1) >> 1) + e - 1];
  2815. };
  2816. i.prototype.set = function(t, e, i) {
  2817. t = t.index;
  2818. if ((e = e.index) > t) {
  2819. var o = e;
  2820. e = t;
  2821. t = o;
  2822. }
  2823. this.matrix[(t * (t + 1) >> 1) + e - 1] = i ? 1 : 0;
  2824. };
  2825. i.prototype.reset = function() {
  2826. for (var t = 0, e = this.matrix.length; t !== e; t++) this.matrix[t] = 0;
  2827. };
  2828. i.prototype.setNumObjects = function(t) {
  2829. this.matrix.length = t * (t - 1) >> 1;
  2830. };
  2831. }, {} ],
  2832. 5: [ function(t, e) {
  2833. var i = t("../objects/Body"), o = t("../math/Vec3"), n = t("../math/Quaternion");
  2834. t("../shapes/Shape"), t("../shapes/Plane");
  2835. e.exports = r;
  2836. function r() {
  2837. this.world = null;
  2838. this.useBoundingBoxes = !1;
  2839. this.dirty = !0;
  2840. }
  2841. r.prototype.collisionPairs = function() {
  2842. throw new Error("collisionPairs not implemented for this BroadPhase class!");
  2843. };
  2844. r.prototype.needBroadphaseCollision = function(t, e) {
  2845. 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);
  2846. };
  2847. r.prototype.intersectionTest = function(t, e, i, o) {
  2848. this.useBoundingBoxes ? this.doBoundingBoxBroadphase(t, e, i, o) : this.doBoundingSphereBroadphase(t, e, i, o);
  2849. };
  2850. var s = new o();
  2851. new o(), new n(), new o();
  2852. r.prototype.doBoundingSphereBroadphase = function(t, e, i, o) {
  2853. var n = s;
  2854. e.position.vsub(t.position, n);
  2855. var r = Math.pow(t.boundingRadius + e.boundingRadius, 2);
  2856. if (n.norm2() < r) {
  2857. i.push(t);
  2858. o.push(e);
  2859. }
  2860. };
  2861. r.prototype.doBoundingBoxBroadphase = function(t, e, i, o) {
  2862. t.aabbNeedsUpdate && t.computeAABB();
  2863. e.aabbNeedsUpdate && e.computeAABB();
  2864. if (t.aabb.overlaps(e.aabb)) {
  2865. i.push(t);
  2866. o.push(e);
  2867. }
  2868. };
  2869. var a = {
  2870. keys: []
  2871. }, l = [], h = [];
  2872. r.prototype.makePairsUnique = function(t, e) {
  2873. for (var i = a, o = l, n = h, r = t.length, s = 0; s !== r; s++) {
  2874. o[s] = t[s];
  2875. n[s] = e[s];
  2876. }
  2877. t.length = 0;
  2878. e.length = 0;
  2879. for (s = 0; s !== r; s++) {
  2880. var c = o[s].id, u = n[s].id;
  2881. i[p = c < u ? c + "," + u : u + "," + c] = s;
  2882. i.keys.push(p);
  2883. }
  2884. for (s = 0; s !== i.keys.length; s++) {
  2885. var p = i.keys.pop(), d = i[p];
  2886. t.push(o[d]);
  2887. e.push(n[d]);
  2888. delete i[p];
  2889. }
  2890. };
  2891. r.prototype.setWorld = function() {};
  2892. var c = new o();
  2893. r.boundingSphereCheck = function(t, e) {
  2894. var i = c;
  2895. t.position.vsub(e.position, i);
  2896. return Math.pow(t.shape.boundingSphereRadius + e.shape.boundingSphereRadius, 2) > i.norm2();
  2897. };
  2898. r.prototype.aabbQuery = function() {
  2899. console.warn(".aabbQuery is not implemented in this Broadphase subclass.");
  2900. return [];
  2901. };
  2902. }, {
  2903. "../math/Quaternion": 30,
  2904. "../math/Vec3": 32,
  2905. "../objects/Body": 33,
  2906. "../shapes/Plane": 44,
  2907. "../shapes/Shape": 45
  2908. } ],
  2909. 6: [ function(t, e) {
  2910. e.exports = r;
  2911. var i = t("./Broadphase"), o = t("../math/Vec3"), n = t("../shapes/Shape");
  2912. function r(t, e, n, r, s) {
  2913. i.apply(this);
  2914. this.nx = n || 10;
  2915. this.ny = r || 10;
  2916. this.nz = s || 10;
  2917. this.aabbMin = t || new o(100, 100, 100);
  2918. this.aabbMax = e || new o(-100, -100, -100);
  2919. var a = this.nx * this.ny * this.nz;
  2920. if (a <= 0) throw "GridBroadphase: Each dimension's n must be >0";
  2921. this.bins = [];
  2922. this.binLengths = [];
  2923. this.bins.length = a;
  2924. this.binLengths.length = a;
  2925. for (var l = 0; l < a; l++) {
  2926. this.bins[l] = [];
  2927. this.binLengths[l] = 0;
  2928. }
  2929. }
  2930. r.prototype = new i();
  2931. r.prototype.constructor = r;
  2932. var s = new o();
  2933. new o();
  2934. r.prototype.collisionPairs = function(t, e, i) {
  2935. 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,
  2936. A.COMPOUND, A.CONVEXPOLYHEDRON, this.bins), T = this.binLengths, P = this.bins.length, q = 0; q !== P; q++) T[q] = 0;
  2937. var I = Math.ceil;
  2938. l = Math.min, a = Math.max;
  2939. function O(t, e, i, o, n, r, s) {
  2940. 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);
  2941. a < 0 ? a = 0 : a >= h && (a = h - 1);
  2942. l < 0 ? l = 0 : l >= c && (l = c - 1);
  2943. f < 0 ? f = 0 : f >= u && (f = u - 1);
  2944. v < 0 ? v = 0 : v >= h && (v = h - 1);
  2945. m < 0 ? m = 0 : m >= c && (m = c - 1);
  2946. S < 0 ? S = 0 : S >= u && (S = u - 1);
  2947. l *= d;
  2948. f *= y;
  2949. v *= p;
  2950. m *= d;
  2951. S *= y;
  2952. 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) {
  2953. var A = E + M + C;
  2954. R[A][T[A]++] = s;
  2955. }
  2956. }
  2957. for (q = 0; q !== o; q++) {
  2958. var V = (it = r[q]).shape;
  2959. switch (V.type) {
  2960. case z:
  2961. var j = it.position.x, k = it.position.y, N = it.position.z, L = V.radius;
  2962. O(j - L, k - L, N - L, j + L, k + L, N + L, it);
  2963. break;
  2964. case F:
  2965. V.worldNormalNeedsUpdate && V.computeWorldNormal(it.quaternion);
  2966. 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;
  2967. H.set(D, U, G);
  2968. 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++,
  2969. 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) {
  2970. var $ = Q + Y + J;
  2971. R[$][T[$]++] = it;
  2972. }
  2973. break;
  2974. default:
  2975. it.aabbNeedsUpdate && it.computeAABB();
  2976. 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);
  2977. }
  2978. }
  2979. for (q = 0; q !== P; q++) {
  2980. var tt = T[q];
  2981. if (tt > 1) {
  2982. var et = R[q];
  2983. for (K = 0; K !== tt; K++) {
  2984. var it = et[K];
  2985. for (X = 0; X !== K; X++) {
  2986. var ot = et[X];
  2987. this.needBroadphaseCollision(it, ot) && this.intersectionTest(it, ot, e, i);
  2988. }
  2989. }
  2990. }
  2991. }
  2992. this.makePairsUnique(e, i);
  2993. };
  2994. }, {
  2995. "../math/Vec3": 32,
  2996. "../shapes/Shape": 45,
  2997. "./Broadphase": 5
  2998. } ],
  2999. 7: [ function(t, e) {
  3000. e.exports = n;
  3001. var i = t("./Broadphase"), o = t("./AABB");
  3002. function n() {
  3003. i.apply(this);
  3004. }
  3005. n.prototype = new i();
  3006. n.prototype.constructor = n;
  3007. n.prototype.collisionPairs = function(t, e, i) {
  3008. var o, n, r, s, a = t.bodies, l = a.length;
  3009. for (o = 0; o !== l; o++) for (n = 0; n !== o; n++) {
  3010. r = a[o];
  3011. s = a[n];
  3012. this.needBroadphaseCollision(r, s) && this.intersectionTest(r, s, e, i);
  3013. }
  3014. };
  3015. new o();
  3016. n.prototype.aabbQuery = function(t, e, i) {
  3017. i = i || [];
  3018. for (var o = 0; o < t.bodies.length; o++) {
  3019. var n = t.bodies[o];
  3020. n.aabbNeedsUpdate && n.computeAABB();
  3021. n.aabb.overlaps(e) && i.push(n);
  3022. }
  3023. return i;
  3024. };
  3025. }, {
  3026. "./AABB": 3,
  3027. "./Broadphase": 5
  3028. } ],
  3029. 8: [ function(t, e) {
  3030. e.exports = i;
  3031. function i() {
  3032. this.matrix = {};
  3033. }
  3034. i.prototype.get = function(t, e) {
  3035. t = t.id;
  3036. if ((e = e.id) > t) {
  3037. var i = e;
  3038. e = t;
  3039. t = i;
  3040. }
  3041. return t + "-" + e in this.matrix;
  3042. };
  3043. i.prototype.set = function(t, e, i) {
  3044. t = t.id;
  3045. if ((e = e.id) > t) {
  3046. var o = e;
  3047. e = t;
  3048. t = o;
  3049. }
  3050. i ? this.matrix[t + "-" + e] = !0 : delete this.matrix[t + "-" + e];
  3051. };
  3052. i.prototype.reset = function() {
  3053. this.matrix = {};
  3054. };
  3055. i.prototype.setNumObjects = function() {};
  3056. }, {} ],
  3057. 9: [ function(t, e) {
  3058. e.exports = i;
  3059. function i() {
  3060. this.current = [];
  3061. this.previous = [];
  3062. }
  3063. i.prototype.getKey = function(t, e) {
  3064. if (e < t) {
  3065. var i = e;
  3066. e = t;
  3067. t = i;
  3068. }
  3069. return t << 16 | e;
  3070. };
  3071. i.prototype.set = function(t, e) {
  3072. for (var i = this.getKey(t, e), o = this.current, n = 0; i > o[n]; ) n++;
  3073. if (i !== o[n]) {
  3074. for (e = o.length - 1; e >= n; e--) o[e + 1] = o[e];
  3075. o[n] = i;
  3076. }
  3077. };
  3078. i.prototype.tick = function() {
  3079. var t = this.current;
  3080. this.current = this.previous;
  3081. this.previous = t;
  3082. this.current.length = 0;
  3083. };
  3084. function o(t, e) {
  3085. t.push((4294901760 & e) >> 16, 65535 & e);
  3086. }
  3087. i.prototype.getDiff = function(t, e) {
  3088. for (var i = this.current, n = this.previous, r = i.length, s = n.length, a = 0, l = 0; l < r; l++) {
  3089. for (var h = i[l]; h > n[a]; ) a++;
  3090. h === n[a] || o(t, h);
  3091. }
  3092. a = 0;
  3093. for (l = 0; l < s; l++) {
  3094. for (var c = n[l]; c > i[a]; ) a++;
  3095. i[a] === c || o(e, c);
  3096. }
  3097. };
  3098. }, {} ],
  3099. 10: [ function(t, e) {
  3100. e.exports = l;
  3101. var i = t("../math/Vec3"), o = t("../math/Quaternion"), n = t("../math/Transform"), r = (t("../shapes/ConvexPolyhedron"),
  3102. t("../shapes/Box"), t("../collision/RaycastResult")), s = t("../shapes/Shape"), a = t("../collision/AABB");
  3103. function l(t, e) {
  3104. this.from = t ? t.clone() : new i();
  3105. this.to = e ? e.clone() : new i();
  3106. this._direction = new i();
  3107. this.precision = 1e-4;
  3108. this.checkCollisionResponse = !0;
  3109. this.skipBackfaces = !1;
  3110. this.collisionFilterMask = -1;
  3111. this.collisionFilterGroup = -1;
  3112. this.mode = l.ANY;
  3113. this.result = new r();
  3114. this.hasHit = !1;
  3115. this.callback = function() {};
  3116. }
  3117. l.prototype.constructor = l;
  3118. l.CLOSEST = 1;
  3119. l.ANY = 2;
  3120. l.ALL = 4;
  3121. var h = new a(), c = [];
  3122. l.prototype.intersectWorld = function(t, e) {
  3123. this.mode = e.mode || l.ANY;
  3124. this.result = e.result || new r();
  3125. this.skipBackfaces = !!e.skipBackfaces;
  3126. this.checkCollisionResponse = !!e.checkCollisionResponse;
  3127. this.collisionFilterMask = "undefined" != typeof e.collisionFilterMask ? e.collisionFilterMask : -1;
  3128. this.collisionFilterGroup = "undefined" != typeof e.collisionFilterGroup ? e.collisionFilterGroup : -1;
  3129. e.from && this.from.copy(e.from);
  3130. e.to && this.to.copy(e.to);
  3131. this.callback = e.callback || function() {};
  3132. this.hasHit = !1;
  3133. this.result.reset();
  3134. this._updateDirection();
  3135. this.getAABB(h);
  3136. c.length = 0;
  3137. t.broadphase.aabbQuery(t, h, c);
  3138. this.intersectBodies(c);
  3139. return this.hasHit;
  3140. };
  3141. var u = new i(), p = new i();
  3142. l.pointInTriangle = d;
  3143. function d(t, e, i, o) {
  3144. o.vsub(e, O);
  3145. i.vsub(e, u);
  3146. t.vsub(e, p);
  3147. var n, r, s = O.dot(O), a = O.dot(u), l = O.dot(p), h = u.dot(u), c = u.dot(p);
  3148. return (n = h * l - a * c) >= 0 && (r = s * c - a * l) >= 0 && n + r < s * h - a * a;
  3149. }
  3150. var y = new i(), f = new o();
  3151. l.prototype.intersectBody = function(t, e) {
  3152. if (e) {
  3153. this.result = e;
  3154. this._updateDirection();
  3155. }
  3156. var i = this.checkCollisionResponse;
  3157. 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++) {
  3158. var a = t.shapes[r];
  3159. if (!i || a.collisionResponse) {
  3160. t.quaternion.mult(t.shapeOrientations[r], n);
  3161. t.quaternion.vmult(t.shapeOffsets[r], o);
  3162. o.vadd(t.position, o);
  3163. this.intersectShape(a, n, o, t);
  3164. if (this.result._shouldStop) break;
  3165. }
  3166. }
  3167. };
  3168. l.prototype.intersectBodies = function(t, e) {
  3169. if (e) {
  3170. this.result = e;
  3171. this._updateDirection();
  3172. }
  3173. for (var i = 0, o = t.length; !this.result._shouldStop && i < o; i++) this.intersectBody(t[i]);
  3174. };
  3175. l.prototype._updateDirection = function() {
  3176. this.to.vsub(this.from, this._direction);
  3177. this._direction.normalize();
  3178. };
  3179. l.prototype.intersectShape = function(t, e, i, o) {
  3180. if (!(j(this.from, this._direction, i) > t.boundingSphereRadius)) {
  3181. var n = this[t.type];
  3182. n && n.call(this, t, e, i, o, t);
  3183. }
  3184. };
  3185. new i(), new i();
  3186. var v = new i(), m = new i(), g = new i(), b = new i();
  3187. new i(), new r();
  3188. l.prototype.intersectBox = function(t, e, i, o, n) {
  3189. return this.intersectConvex(t.convexPolyhedronRepresentation, e, i, o, n);
  3190. };
  3191. l.prototype[s.types.BOX] = l.prototype.intersectBox;
  3192. l.prototype.intersectPlane = function(t, e, o, n, r) {
  3193. var s = this.from, a = this.to, l = this._direction, h = new i(0, 0, 1);
  3194. e.vmult(h, h);
  3195. var c = new i();
  3196. s.vsub(o, c);
  3197. var u = c.dot(h);
  3198. a.vsub(o, c);
  3199. if (!(u * c.dot(h) > 0 || s.distanceTo(a) < u)) {
  3200. var p = h.dot(l);
  3201. if (!(Math.abs(p) < this.precision)) {
  3202. var d = new i(), y = new i(), f = new i();
  3203. s.vsub(o, d);
  3204. var v = -h.dot(d) / p;
  3205. l.scale(v, y);
  3206. s.vadd(y, f);
  3207. this.reportIntersection(h, f, r, n, -1);
  3208. }
  3209. }
  3210. };
  3211. l.prototype[s.types.PLANE] = l.prototype.intersectPlane;
  3212. l.prototype.getAABB = function(t) {
  3213. var e = this.to, i = this.from;
  3214. t.lowerBound.x = Math.min(e.x, i.x);
  3215. t.lowerBound.y = Math.min(e.y, i.y);
  3216. t.lowerBound.z = Math.min(e.z, i.z);
  3217. t.upperBound.x = Math.max(e.x, i.x);
  3218. t.upperBound.y = Math.max(e.y, i.y);
  3219. t.upperBound.z = Math.max(e.z, i.z);
  3220. };
  3221. var w = {
  3222. faceList: [ 0 ]
  3223. }, x = new i(), _ = new l(), B = [];
  3224. l.prototype.intersectHeightfield = function(t, e, i, o, r) {
  3225. t.data, t.elementSize;
  3226. var s = _;
  3227. s.from.copy(this.from);
  3228. s.to.copy(this.to);
  3229. n.pointToLocalFrame(i, e, s.from, s.from);
  3230. n.pointToLocalFrame(i, e, s.to, s.to);
  3231. s._updateDirection();
  3232. var l, h, c, u, p = B;
  3233. l = h = 0;
  3234. c = u = t.data.length - 1;
  3235. var d = new a();
  3236. s.getAABB(d);
  3237. t.getIndexOfPosition(d.lowerBound.x, d.lowerBound.y, p, !0);
  3238. l = Math.max(l, p[0]);
  3239. h = Math.max(h, p[1]);
  3240. t.getIndexOfPosition(d.upperBound.x, d.upperBound.y, p, !0);
  3241. c = Math.min(c, p[0] + 1);
  3242. u = Math.min(u, p[1] + 1);
  3243. for (var y = l; y < c; y++) for (var f = h; f < u; f++) {
  3244. if (this.result._shouldStop) return;
  3245. t.getAabbAtIndex(y, f, d);
  3246. if (d.overlapsRay(s)) {
  3247. t.getConvexTrianglePillar(y, f, !1);
  3248. n.pointToWorldFrame(i, e, t.pillarOffset, x);
  3249. this.intersectConvex(t.pillarConvex, e, x, o, r, w);
  3250. if (this.result._shouldStop) return;
  3251. t.getConvexTrianglePillar(y, f, !0);
  3252. n.pointToWorldFrame(i, e, t.pillarOffset, x);
  3253. this.intersectConvex(t.pillarConvex, e, x, o, r, w);
  3254. }
  3255. }
  3256. };
  3257. l.prototype[s.types.HEIGHTFIELD] = l.prototype.intersectHeightfield;
  3258. var S = new i(), E = new i();
  3259. l.prototype.intersectSphere = function(t, e, i, o, n) {
  3260. 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;
  3261. if (!(u < 0)) if (0 === u) {
  3262. r.lerp(s, u, p);
  3263. p.vsub(i, d);
  3264. d.normalize();
  3265. this.reportIntersection(d, p, n, o, -1);
  3266. } else {
  3267. var y = (-h - Math.sqrt(u)) / (2 * l), f = (-h + Math.sqrt(u)) / (2 * l);
  3268. if (y >= 0 && y <= 1) {
  3269. r.lerp(s, y, p);
  3270. p.vsub(i, d);
  3271. d.normalize();
  3272. this.reportIntersection(d, p, n, o, -1);
  3273. }
  3274. if (this.result._shouldStop) return;
  3275. if (f >= 0 && f <= 1) {
  3276. r.lerp(s, f, p);
  3277. p.vsub(i, d);
  3278. d.normalize();
  3279. this.reportIntersection(d, p, n, o, -1);
  3280. }
  3281. }
  3282. };
  3283. l.prototype[s.types.SPHERE] = l.prototype.intersectSphere;
  3284. var M = new i(), C = (new i(), new i(), new i());
  3285. l.prototype.intersectConvex = function(t, e, i, o, n, r) {
  3286. 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++) {
  3287. var S = l ? l[B] : B, E = h[S], A = u[S], z = e, F = i;
  3288. a.copy(c[E[0]]);
  3289. z.vmult(a, a);
  3290. a.vadd(F, a);
  3291. a.vsub(y, a);
  3292. z.vmult(A, s);
  3293. var R = p.dot(s);
  3294. if (!(Math.abs(R) < this.precision)) {
  3295. var T = s.dot(a) / R;
  3296. if (!(T < 0)) {
  3297. p.mult(T, v);
  3298. v.vadd(y, v);
  3299. m.copy(c[E[0]]);
  3300. z.vmult(m, m);
  3301. F.vadd(m, m);
  3302. for (var P = 1; !_._shouldStop && P < E.length - 1; P++) {
  3303. g.copy(c[E[P]]);
  3304. b.copy(c[E[P + 1]]);
  3305. z.vmult(g, g);
  3306. z.vmult(b, b);
  3307. F.vadd(g, g);
  3308. F.vadd(b, b);
  3309. var q = v.distanceTo(y);
  3310. !d(v, m, g, b) && !d(v, g, m, b) || q > w || this.reportIntersection(s, v, n, o, S);
  3311. }
  3312. }
  3313. }
  3314. }
  3315. };
  3316. l.prototype[s.types.CONVEXPOLYHEDRON] = l.prototype.intersectConvex;
  3317. var A = new i(), z = new i(), F = new i(), R = new i(), T = new i(), P = new i(), q = (new a(),
  3318. []), I = new n();
  3319. l.prototype.intersectTrimesh = function(t, e, i, o, r, s) {
  3320. var a = A, l = q, h = I, c = C, u = z, p = F, y = R, f = P, w = T, x = (s && s.faceList,
  3321. t.indices), _ = (t.vertices, t.faceNormals, this.from), B = this.to, S = this._direction;
  3322. h.position.copy(i);
  3323. h.quaternion.copy(e);
  3324. n.vectorToLocalFrame(i, e, S, u);
  3325. n.pointToLocalFrame(i, e, _, p);
  3326. n.pointToLocalFrame(i, e, B, y);
  3327. y.x *= t.scale.x;
  3328. y.y *= t.scale.y;
  3329. y.z *= t.scale.z;
  3330. p.x *= t.scale.x;
  3331. p.y *= t.scale.y;
  3332. p.z *= t.scale.z;
  3333. y.vsub(p, u);
  3334. u.normalize();
  3335. var E = p.distanceSquared(y);
  3336. t.tree.rayQuery(this, h, l);
  3337. for (var M = 0, O = l.length; !this.result._shouldStop && M !== O; M++) {
  3338. var V = l[M];
  3339. t.getNormal(V, a);
  3340. t.getVertex(x[3 * V], m);
  3341. m.vsub(p, c);
  3342. var j = u.dot(a), k = a.dot(c) / j;
  3343. if (!(k < 0)) {
  3344. u.scale(k, v);
  3345. v.vadd(p, v);
  3346. t.getVertex(x[3 * V + 1], g);
  3347. t.getVertex(x[3 * V + 2], b);
  3348. var N = v.distanceSquared(p);
  3349. if (!(!d(v, g, m, b) && !d(v, m, g, b) || N > E)) {
  3350. n.vectorToWorldFrame(e, a, w);
  3351. n.pointToWorldFrame(i, e, v, f);
  3352. this.reportIntersection(w, f, r, o, V);
  3353. }
  3354. }
  3355. }
  3356. l.length = 0;
  3357. };
  3358. l.prototype[s.types.TRIMESH] = l.prototype.intersectTrimesh;
  3359. l.prototype.reportIntersection = function(t, e, i, o, n) {
  3360. var r = this.from, s = this.to, a = r.distanceTo(e), h = this.result;
  3361. if (!(this.skipBackfaces && t.dot(this._direction) > 0)) {
  3362. h.hitFaceIndex = "undefined" != typeof n ? n : -1;
  3363. switch (this.mode) {
  3364. case l.ALL:
  3365. this.hasHit = !0;
  3366. h.set(r, s, t, e, i, o, a);
  3367. h.hasHit = !0;
  3368. this.callback(h);
  3369. break;
  3370. case l.CLOSEST:
  3371. if (a < h.distance || !h.hasHit) {
  3372. this.hasHit = !0;
  3373. h.hasHit = !0;
  3374. h.set(r, s, t, e, i, o, a);
  3375. }
  3376. break;
  3377. case l.ANY:
  3378. this.hasHit = !0;
  3379. h.hasHit = !0;
  3380. h.set(r, s, t, e, i, o, a);
  3381. h._shouldStop = !0;
  3382. }
  3383. }
  3384. };
  3385. var O = new i(), V = new i();
  3386. function j(t, e, i) {
  3387. i.vsub(t, O);
  3388. var o = O.dot(e);
  3389. e.mult(o, V);
  3390. V.vadd(t, V);
  3391. return i.distanceTo(V);
  3392. }
  3393. }, {
  3394. "../collision/AABB": 3,
  3395. "../collision/RaycastResult": 11,
  3396. "../math/Quaternion": 30,
  3397. "../math/Transform": 31,
  3398. "../math/Vec3": 32,
  3399. "../shapes/Box": 39,
  3400. "../shapes/ConvexPolyhedron": 40,
  3401. "../shapes/Shape": 45
  3402. } ],
  3403. 11: [ function(t, e) {
  3404. var i = t("../math/Vec3");
  3405. e.exports = o;
  3406. function o() {
  3407. this.rayFromWorld = new i();
  3408. this.rayToWorld = new i();
  3409. this.hitNormalWorld = new i();
  3410. this.hitPointWorld = new i();
  3411. this.hasHit = !1;
  3412. this.shape = null;
  3413. this.body = null;
  3414. this.hitFaceIndex = -1;
  3415. this.distance = -1;
  3416. this._shouldStop = !1;
  3417. }
  3418. o.prototype.reset = function() {
  3419. this.rayFromWorld.setZero();
  3420. this.rayToWorld.setZero();
  3421. this.hitNormalWorld.setZero();
  3422. this.hitPointWorld.setZero();
  3423. this.hasHit = !1;
  3424. this.shape = null;
  3425. this.body = null;
  3426. this.hitFaceIndex = -1;
  3427. this.distance = -1;
  3428. this._shouldStop = !1;
  3429. };
  3430. o.prototype.abort = function() {
  3431. this._shouldStop = !0;
  3432. };
  3433. o.prototype.set = function(t, e, i, o, n, r, s) {
  3434. this.rayFromWorld.copy(t);
  3435. this.rayToWorld.copy(e);
  3436. this.hitNormalWorld.copy(i);
  3437. this.hitPointWorld.copy(o);
  3438. this.shape = n;
  3439. this.body = r;
  3440. this.distance = s;
  3441. };
  3442. }, {
  3443. "../math/Vec3": 32
  3444. } ],
  3445. 12: [ function(t, e) {
  3446. t("../shapes/Shape");
  3447. var i = t("../collision/Broadphase");
  3448. e.exports = o;
  3449. function o(t) {
  3450. i.apply(this);
  3451. this.axisList = [];
  3452. this.world = null;
  3453. this.axisIndex = 0;
  3454. var e = this.axisList;
  3455. this._addBodyHandler = function(t) {
  3456. e.push(t.body);
  3457. };
  3458. this._removeBodyHandler = function(t) {
  3459. var i = e.indexOf(t.body);
  3460. -1 !== i && e.splice(i, 1);
  3461. };
  3462. t && this.setWorld(t);
  3463. }
  3464. o.prototype = new i();
  3465. o.prototype.setWorld = function(t) {
  3466. this.axisList.length = 0;
  3467. for (var e = 0; e < t.bodies.length; e++) this.axisList.push(t.bodies[e]);
  3468. t.removeEventListener("addBody", this._addBodyHandler);
  3469. t.removeEventListener("removeBody", this._removeBodyHandler);
  3470. t.addEventListener("addBody", this._addBodyHandler);
  3471. t.addEventListener("removeBody", this._removeBodyHandler);
  3472. this.world = t;
  3473. this.dirty = !0;
  3474. };
  3475. o.insertionSortX = function(t) {
  3476. for (var e = 1, i = t.length; e < i; e++) {
  3477. 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];
  3478. t[n + 1] = o;
  3479. }
  3480. return t;
  3481. };
  3482. o.insertionSortY = function(t) {
  3483. for (var e = 1, i = t.length; e < i; e++) {
  3484. 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];
  3485. t[n + 1] = o;
  3486. }
  3487. return t;
  3488. };
  3489. o.insertionSortZ = function(t) {
  3490. for (var e = 1, i = t.length; e < i; e++) {
  3491. 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];
  3492. t[n + 1] = o;
  3493. }
  3494. return t;
  3495. };
  3496. o.prototype.collisionPairs = function(t, e, i) {
  3497. var n, r, s = this.axisList, a = s.length, l = this.axisIndex;
  3498. if (this.dirty) {
  3499. this.sortList();
  3500. this.dirty = !1;
  3501. }
  3502. for (n = 0; n !== a; n++) {
  3503. var h = s[n];
  3504. for (r = n + 1; r < a; r++) {
  3505. var c = s[r];
  3506. if (this.needBroadphaseCollision(h, c)) {
  3507. if (!o.checkBounds(h, c, l)) break;
  3508. this.intersectionTest(h, c, e, i);
  3509. }
  3510. }
  3511. }
  3512. };
  3513. o.prototype.sortList = function() {
  3514. for (var t = this.axisList, e = this.axisIndex, i = t.length, n = 0; n !== i; n++) {
  3515. var r = t[n];
  3516. r.aabbNeedsUpdate && r.computeAABB();
  3517. }
  3518. 0 === e ? o.insertionSortX(t) : 1 === e ? o.insertionSortY(t) : 2 === e && o.insertionSortZ(t);
  3519. };
  3520. o.checkBounds = function(t, e, i) {
  3521. var o, n;
  3522. if (0 === i) {
  3523. o = t.position.x;
  3524. n = e.position.x;
  3525. } else if (1 === i) {
  3526. o = t.position.y;
  3527. n = e.position.y;
  3528. } else if (2 === i) {
  3529. o = t.position.z;
  3530. n = e.position.z;
  3531. }
  3532. var r = t.boundingRadius;
  3533. return n - e.boundingRadius < o + r;
  3534. };
  3535. o.prototype.autoDetectAxis = function() {
  3536. 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++) {
  3537. var c = s[h], u = c.position.x;
  3538. t += u;
  3539. e += u * u;
  3540. var p = c.position.y;
  3541. i += p;
  3542. o += p * p;
  3543. var d = c.position.z;
  3544. n += d;
  3545. r += d * d;
  3546. }
  3547. var y = e - t * t * l, f = o - i * i * l, v = r - n * n * l;
  3548. this.axisIndex = y > f ? y > v ? 0 : 2 : f > v ? 1 : 2;
  3549. };
  3550. o.prototype.aabbQuery = function(t, e, i) {
  3551. i = i || [];
  3552. if (this.dirty) {
  3553. this.sortList();
  3554. this.dirty = !1;
  3555. }
  3556. var o = this.axisIndex, n = "x";
  3557. 1 === o && (n = "y");
  3558. 2 === o && (n = "z");
  3559. for (var r = this.axisList, s = (e.lowerBound[n], e.upperBound[n], 0); s < r.length; s++) {
  3560. var a = r[s];
  3561. a.aabbNeedsUpdate && a.computeAABB();
  3562. a.aabb.overlaps(e) && i.push(a);
  3563. }
  3564. return i;
  3565. };
  3566. }, {
  3567. "../collision/Broadphase": 5,
  3568. "../shapes/Shape": 45
  3569. } ],
  3570. 13: [ function(t, e) {
  3571. e.exports = s;
  3572. t("./Constraint");
  3573. var i = t("./PointToPointConstraint"), o = t("../equations/ConeEquation"), n = t("../equations/RotationalEquation"), r = (t("../equations/ContactEquation"),
  3574. t("../math/Vec3"));
  3575. function s(t, e, s) {
  3576. 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();
  3577. this.axisA = s.axisA ? s.axisA.clone() : new r();
  3578. this.axisB = s.axisB ? s.axisB.clone() : new r();
  3579. i.call(this, t, l, e, h, a);
  3580. this.collideConnected = !!s.collideConnected;
  3581. this.angle = "undefined" != typeof s.angle ? s.angle : 0;
  3582. var c = this.coneEquation = new o(t, e, s), u = this.twistEquation = new n(t, e, s);
  3583. this.twistAngle = "undefined" != typeof s.twistAngle ? s.twistAngle : 0;
  3584. c.maxForce = 0;
  3585. c.minForce = -a;
  3586. u.maxForce = 0;
  3587. u.minForce = -a;
  3588. this.equations.push(c, u);
  3589. }
  3590. s.prototype = new i();
  3591. s.constructor = s;
  3592. new r(), new r();
  3593. s.prototype.update = function() {
  3594. var t = this.bodyA, e = this.bodyB, o = this.coneEquation, n = this.twistEquation;
  3595. i.prototype.update.call(this);
  3596. t.vectorToWorldFrame(this.axisA, o.axisA);
  3597. e.vectorToWorldFrame(this.axisB, o.axisB);
  3598. this.axisA.tangents(n.axisA, n.axisA);
  3599. t.vectorToWorldFrame(n.axisA, n.axisA);
  3600. this.axisB.tangents(n.axisB, n.axisB);
  3601. e.vectorToWorldFrame(n.axisB, n.axisB);
  3602. o.angle = this.angle;
  3603. n.maxAngle = this.twistAngle;
  3604. };
  3605. }, {
  3606. "../equations/ConeEquation": 19,
  3607. "../equations/ContactEquation": 20,
  3608. "../equations/RotationalEquation": 23,
  3609. "../math/Vec3": 32,
  3610. "./Constraint": 14,
  3611. "./PointToPointConstraint": 18
  3612. } ],
  3613. 14: [ function(t, e) {
  3614. e.exports = o;
  3615. var i = t("../utils/Utils");
  3616. function o(t, e, n) {
  3617. n = i.defaults(n, {
  3618. collideConnected: !0,
  3619. wakeUpBodies: !0
  3620. });
  3621. this.equations = [];
  3622. this.bodyA = t;
  3623. this.bodyB = e;
  3624. this.id = o.idCounter++;
  3625. this.collideConnected = n.collideConnected;
  3626. if (n.wakeUpBodies) {
  3627. t && t.wakeUp();
  3628. e && e.wakeUp();
  3629. }
  3630. }
  3631. o.prototype.update = function() {
  3632. throw new Error("method update() not implmemented in this Constraint subclass!");
  3633. };
  3634. o.prototype.enable = function() {
  3635. for (var t = this.equations, e = 0; e < t.length; e++) t[e].enabled = !0;
  3636. };
  3637. o.prototype.disable = function() {
  3638. for (var t = this.equations, e = 0; e < t.length; e++) t[e].enabled = !1;
  3639. };
  3640. o.idCounter = 0;
  3641. }, {
  3642. "../utils/Utils": 55
  3643. } ],
  3644. 15: [ function(t, e) {
  3645. e.exports = n;
  3646. var i = t("./Constraint"), o = t("../equations/ContactEquation");
  3647. function n(t, e, n, r) {
  3648. i.call(this, t, e);
  3649. "undefined" == typeof n && (n = t.position.distanceTo(e.position));
  3650. "undefined" == typeof r && (r = 1e6);
  3651. this.distance = n;
  3652. var s = this.distanceEquation = new o(t, e);
  3653. this.equations.push(s);
  3654. s.minForce = -r;
  3655. s.maxForce = r;
  3656. }
  3657. n.prototype = new i();
  3658. n.prototype.update = function() {
  3659. var t = this.bodyA, e = this.bodyB, i = this.distanceEquation, o = .5 * this.distance, n = i.ni;
  3660. e.position.vsub(t.position, n);
  3661. n.normalize();
  3662. n.mult(o, i.ri);
  3663. n.mult(-o, i.rj);
  3664. };
  3665. }, {
  3666. "../equations/ContactEquation": 20,
  3667. "./Constraint": 14
  3668. } ],
  3669. 16: [ function(t, e) {
  3670. e.exports = s;
  3671. t("./Constraint");
  3672. var i = t("./PointToPointConstraint"), o = t("../equations/RotationalEquation"), n = t("../equations/RotationalMotorEquation"), r = (t("../equations/ContactEquation"),
  3673. t("../math/Vec3"));
  3674. function s(t, e, s) {
  3675. 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();
  3676. i.call(this, t, l, e, h, a);
  3677. (this.axisA = s.axisA ? s.axisA.clone() : new r(1, 0, 0)).normalize();
  3678. (this.axisB = s.axisB ? s.axisB.clone() : new r(1, 0, 0)).normalize();
  3679. 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);
  3680. p.enabled = !1;
  3681. this.equations.push(c, u, p);
  3682. }
  3683. s.prototype = new i();
  3684. s.constructor = s;
  3685. s.prototype.enableMotor = function() {
  3686. this.motorEquation.enabled = !0;
  3687. };
  3688. s.prototype.disableMotor = function() {
  3689. this.motorEquation.enabled = !1;
  3690. };
  3691. s.prototype.setMotorSpeed = function(t) {
  3692. this.motorEquation.targetVelocity = t;
  3693. };
  3694. s.prototype.setMotorMaxForce = function(t) {
  3695. this.motorEquation.maxForce = t;
  3696. this.motorEquation.minForce = -t;
  3697. };
  3698. var a = new r(), l = new r();
  3699. s.prototype.update = function() {
  3700. 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;
  3701. i.prototype.update.call(this);
  3702. t.quaternion.vmult(c, s);
  3703. e.quaternion.vmult(u, h);
  3704. s.tangents(n.axisA, r.axisA);
  3705. n.axisB.copy(h);
  3706. r.axisB.copy(h);
  3707. if (this.motorEquation.enabled) {
  3708. t.quaternion.vmult(this.axisA, o.axisA);
  3709. e.quaternion.vmult(this.axisB, o.axisB);
  3710. }
  3711. };
  3712. }, {
  3713. "../equations/ContactEquation": 20,
  3714. "../equations/RotationalEquation": 23,
  3715. "../equations/RotationalMotorEquation": 24,
  3716. "../math/Vec3": 32,
  3717. "./Constraint": 14,
  3718. "./PointToPointConstraint": 18
  3719. } ],
  3720. 17: [ function(t, e) {
  3721. e.exports = r;
  3722. t("./Constraint");
  3723. var i = t("./PointToPointConstraint"), o = t("../equations/RotationalEquation"), n = (t("../equations/RotationalMotorEquation"),
  3724. t("../equations/ContactEquation"), t("../math/Vec3"));
  3725. function r(t, e, r) {
  3726. var s = "undefined" != typeof (r = r || {}).maxForce ? r.maxForce : 1e6, a = new n(), l = new n(), h = new n();
  3727. t.position.vadd(e.position, h);
  3728. h.scale(.5, h);
  3729. e.pointToLocalFrame(h, l);
  3730. t.pointToLocalFrame(h, a);
  3731. i.call(this, t, a, e, l, s);
  3732. this.xA = t.vectorToLocalFrame(n.UNIT_X);
  3733. this.xB = e.vectorToLocalFrame(n.UNIT_X);
  3734. this.yA = t.vectorToLocalFrame(n.UNIT_Y);
  3735. this.yB = e.vectorToLocalFrame(n.UNIT_Y);
  3736. this.zA = t.vectorToLocalFrame(n.UNIT_Z);
  3737. this.zB = e.vectorToLocalFrame(n.UNIT_Z);
  3738. 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);
  3739. this.equations.push(c, u, p);
  3740. }
  3741. r.prototype = new i();
  3742. r.constructor = r;
  3743. new n(), new n();
  3744. r.prototype.update = function() {
  3745. var t = this.bodyA, e = this.bodyB, o = (this.motorEquation, this.rotationalEquation1), n = this.rotationalEquation2, r = this.rotationalEquation3;
  3746. i.prototype.update.call(this);
  3747. t.vectorToWorldFrame(this.xA, o.axisA);
  3748. e.vectorToWorldFrame(this.yB, o.axisB);
  3749. t.vectorToWorldFrame(this.yA, n.axisA);
  3750. e.vectorToWorldFrame(this.zB, n.axisB);
  3751. t.vectorToWorldFrame(this.zA, r.axisA);
  3752. e.vectorToWorldFrame(this.xB, r.axisB);
  3753. };
  3754. }, {
  3755. "../equations/ContactEquation": 20,
  3756. "../equations/RotationalEquation": 23,
  3757. "../equations/RotationalMotorEquation": 24,
  3758. "../math/Vec3": 32,
  3759. "./Constraint": 14,
  3760. "./PointToPointConstraint": 18
  3761. } ],
  3762. 18: [ function(t, e) {
  3763. e.exports = r;
  3764. var i = t("./Constraint"), o = t("../equations/ContactEquation"), n = t("../math/Vec3");
  3765. function r(t, e, r, s, a) {
  3766. i.call(this, t, r);
  3767. a = "undefined" != typeof a ? a : 1e6;
  3768. this.pivotA = e ? e.clone() : new n();
  3769. this.pivotB = s ? s.clone() : new n();
  3770. var l = this.equationX = new o(t, r), h = this.equationY = new o(t, r), c = this.equationZ = new o(t, r);
  3771. this.equations.push(l, h, c);
  3772. l.minForce = h.minForce = c.minForce = -a;
  3773. l.maxForce = h.maxForce = c.maxForce = a;
  3774. l.ni.set(1, 0, 0);
  3775. h.ni.set(0, 1, 0);
  3776. c.ni.set(0, 0, 1);
  3777. }
  3778. r.prototype = new i();
  3779. r.prototype.update = function() {
  3780. var t = this.bodyA, e = this.bodyB, i = this.equationX, o = this.equationY, n = this.equationZ;
  3781. t.quaternion.vmult(this.pivotA, i.ri);
  3782. e.quaternion.vmult(this.pivotB, i.rj);
  3783. o.ri.copy(i.ri);
  3784. o.rj.copy(i.rj);
  3785. n.ri.copy(i.ri);
  3786. n.rj.copy(i.rj);
  3787. };
  3788. }, {
  3789. "../equations/ContactEquation": 20,
  3790. "../math/Vec3": 32,
  3791. "./Constraint": 14
  3792. } ],
  3793. 19: [ function(t, e) {
  3794. e.exports = r;
  3795. var i = t("../math/Vec3"), o = (t("../math/Mat3"), t("./Equation")), n = t("../math/CMath");
  3796. function r(t, e, n) {
  3797. var r = "undefined" != typeof (n = n || {}).maxForce ? n.maxForce : 1e6;
  3798. o.call(this, t, e, -r, r);
  3799. this.axisA = n.axisA ? n.axisA.clone() : new i(1, 0, 0);
  3800. this.axisB = n.axisB ? n.axisB.clone() : new i(0, 1, 0);
  3801. this.angle = "undefined" != typeof n.angle ? n.angle : 0;
  3802. }
  3803. r.prototype = new o();
  3804. r.prototype.constructor = r;
  3805. var s = new i(), a = new i();
  3806. r.prototype.computeB = function(t) {
  3807. var e = this.a, i = this.b, o = this.axisA, r = this.axisB, l = s, h = a, c = this.jacobianElementA, u = this.jacobianElementB;
  3808. o.cross(r, l);
  3809. r.cross(o, h);
  3810. c.rotational.copy(h);
  3811. u.rotational.copy(l);
  3812. return -(n.cos(this.angle) - o.dot(r)) * e - this.computeGW() * i - t * this.computeGiMf();
  3813. };
  3814. }, {
  3815. "../math/CMath": 27,
  3816. "../math/Mat3": 29,
  3817. "../math/Vec3": 32,
  3818. "./Equation": 21
  3819. } ],
  3820. 20: [ function(t, e) {
  3821. e.exports = n;
  3822. var i = t("./Equation"), o = t("../math/Vec3");
  3823. t("../math/Mat3");
  3824. function n(t, e, n) {
  3825. n = "undefined" != typeof n ? n : 1e6;
  3826. i.call(this, t, e, 0, n);
  3827. this.si = null;
  3828. this.sj = null;
  3829. this.restitution = 0;
  3830. this.ri = new o();
  3831. this.rj = new o();
  3832. this.ni = new o();
  3833. }
  3834. n.prototype = new i();
  3835. n.prototype.constructor = n;
  3836. var r = new o(), s = new o(), a = new o();
  3837. n.prototype.computeB = function(t) {
  3838. 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,
  3839. o.torque, n.velocity), f = n.angularVelocity, v = (n.force, n.torque, a), m = this.jacobianElementA, g = this.jacobianElementB, b = this.ni;
  3840. l.cross(b, c);
  3841. h.cross(b, u);
  3842. b.negate(m.spatial);
  3843. c.negate(m.rotational);
  3844. g.spatial.copy(b);
  3845. g.rotational.copy(u);
  3846. v.copy(n.position);
  3847. v.vadd(h, v);
  3848. v.vsub(o.position, v);
  3849. v.vsub(l, v);
  3850. var w = b.dot(v), x = this.restitution + 1;
  3851. return -w * e - (x * y.dot(b) - x * p.dot(b) + f.dot(u) - d.dot(c)) * i - t * this.computeGiMf();
  3852. };
  3853. var l = new o(), h = new o(), c = new o(), u = new o(), p = new o();
  3854. n.prototype.getImpactVelocityAlongNormal = function() {
  3855. var t = l, e = h, i = c, o = u, n = p;
  3856. this.bi.position.vadd(this.ri, i);
  3857. this.bj.position.vadd(this.rj, o);
  3858. this.bi.getVelocityAtWorldPoint(i, t);
  3859. this.bj.getVelocityAtWorldPoint(o, e);
  3860. t.vsub(e, n);
  3861. return this.ni.dot(n);
  3862. };
  3863. }, {
  3864. "../math/Mat3": 29,
  3865. "../math/Vec3": 32,
  3866. "./Equation": 21
  3867. } ],
  3868. 21: [ function(t, e) {
  3869. e.exports = n;
  3870. var i = t("../math/JacobianElement"), o = t("../math/Vec3");
  3871. function n(t, e, o, r) {
  3872. this.id = n.id++;
  3873. this.minForce = "undefined" == typeof o ? -1e6 : o;
  3874. this.maxForce = "undefined" == typeof r ? 1e6 : r;
  3875. this.bi = t;
  3876. this.bj = e;
  3877. this.a = 0;
  3878. this.b = 0;
  3879. this.eps = 0;
  3880. this.jacobianElementA = new i();
  3881. this.jacobianElementB = new i();
  3882. this.enabled = !0;
  3883. this.multiplier = 0;
  3884. this.setSpookParams(1e7, 4, 1 / 60);
  3885. }
  3886. n.prototype.constructor = n;
  3887. n.id = 0;
  3888. n.prototype.setSpookParams = function(t, e, i) {
  3889. var o = e, n = t, r = i;
  3890. this.a = 4 / (r * (1 + 4 * o));
  3891. this.b = 4 * o / (1 + 4 * o);
  3892. this.eps = 4 / (r * r * n * (1 + 4 * o));
  3893. };
  3894. n.prototype.computeB = function(t, e, i) {
  3895. var o = this.computeGW();
  3896. return -this.computeGq() * t - o * e - this.computeGiMf() * i;
  3897. };
  3898. n.prototype.computeGq = function() {
  3899. var t = this.jacobianElementA, e = this.jacobianElementB, i = this.bi, o = this.bj, n = i.position, r = o.position;
  3900. return t.spatial.dot(n) + e.spatial.dot(r);
  3901. };
  3902. new o();
  3903. n.prototype.computeGW = function() {
  3904. 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;
  3905. return t.multiplyVectors(n, s) + e.multiplyVectors(r, a);
  3906. };
  3907. n.prototype.computeGWlambda = function() {
  3908. 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;
  3909. return t.multiplyVectors(n, s) + e.multiplyVectors(r, a);
  3910. };
  3911. var r = new o(), s = new o(), a = new o(), l = new o();
  3912. n.prototype.computeGiMf = function() {
  3913. 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;
  3914. n.scale(p, r);
  3915. c.scale(d, s);
  3916. i.invInertiaWorldSolve.vmult(h, a);
  3917. o.invInertiaWorldSolve.vmult(u, l);
  3918. return t.multiplyVectors(r, a) + e.multiplyVectors(s, l);
  3919. };
  3920. var h = new o();
  3921. n.prototype.computeGiMGt = function() {
  3922. 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;
  3923. s.vmult(t.rotational, h);
  3924. l += h.dot(t.rotational);
  3925. a.vmult(e.rotational, h);
  3926. return l + h.dot(e.rotational);
  3927. };
  3928. var c = new o();
  3929. new o(), new o(), new o(), new o(), new o();
  3930. n.prototype.addToWlambda = function(t) {
  3931. var e = this.jacobianElementA, i = this.jacobianElementB, o = this.bi, n = this.bj, r = c;
  3932. o.vlambda.addScaledVector(o.invMassSolve * t, e.spatial, o.vlambda);
  3933. n.vlambda.addScaledVector(n.invMassSolve * t, i.spatial, n.vlambda);
  3934. o.invInertiaWorldSolve.vmult(e.rotational, r);
  3935. o.wlambda.addScaledVector(t, r, o.wlambda);
  3936. n.invInertiaWorldSolve.vmult(i.rotational, r);
  3937. n.wlambda.addScaledVector(t, r, n.wlambda);
  3938. };
  3939. n.prototype.computeC = function() {
  3940. return this.computeGiMGt() + this.eps;
  3941. };
  3942. }, {
  3943. "../math/JacobianElement": 28,
  3944. "../math/Vec3": 32
  3945. } ],
  3946. 22: [ function(t, e) {
  3947. e.exports = n;
  3948. var i = t("./Equation"), o = t("../math/Vec3");
  3949. t("../math/Mat3");
  3950. function n(t, e, n) {
  3951. i.call(this, t, e, -n, n);
  3952. this.ri = new o();
  3953. this.rj = new o();
  3954. this.t = new o();
  3955. }
  3956. n.prototype = new i();
  3957. n.prototype.constructor = n;
  3958. var r = new o(), s = new o();
  3959. n.prototype.computeB = function(t) {
  3960. this.a;
  3961. var e = this.b, i = (this.bi, this.bj, this.ri), o = this.rj, n = r, a = s, l = this.t;
  3962. i.cross(l, n);
  3963. o.cross(l, a);
  3964. var h = this.jacobianElementA, c = this.jacobianElementB;
  3965. l.negate(h.spatial);
  3966. n.negate(h.rotational);
  3967. c.spatial.copy(l);
  3968. c.rotational.copy(a);
  3969. return -this.computeGW() * e - t * this.computeGiMf();
  3970. };
  3971. }, {
  3972. "../math/Mat3": 29,
  3973. "../math/Vec3": 32,
  3974. "./Equation": 21
  3975. } ],
  3976. 23: [ function(t, e) {
  3977. e.exports = r;
  3978. var i = t("../math/Vec3"), o = (t("../math/Mat3"), t("./Equation")), n = t("../math/CMath");
  3979. function r(t, e, n) {
  3980. var r = "undefined" != typeof (n = n || {}).maxForce ? n.maxForce : 1e6;
  3981. o.call(this, t, e, -r, r);
  3982. this.axisA = n.axisA ? n.axisA.clone() : new i(1, 0, 0);
  3983. this.axisB = n.axisB ? n.axisB.clone() : new i(0, 1, 0);
  3984. this.maxAngle = Math.PI / 2;
  3985. }
  3986. r.prototype = new o();
  3987. r.prototype.constructor = r;
  3988. var s = new i(), a = new i();
  3989. r.prototype.computeB = function(t) {
  3990. var e = this.a, i = this.b, o = this.axisA, r = this.axisB, l = s, h = a, c = this.jacobianElementA, u = this.jacobianElementB;
  3991. o.cross(r, l);
  3992. r.cross(o, h);
  3993. c.rotational.copy(h);
  3994. u.rotational.copy(l);
  3995. return -(n.cos(this.maxAngle) - o.dot(r)) * e - this.computeGW() * i - t * this.computeGiMf();
  3996. };
  3997. }, {
  3998. "../math/CMath": 27,
  3999. "../math/Mat3": 29,
  4000. "../math/Vec3": 32,
  4001. "./Equation": 21
  4002. } ],
  4003. 24: [ function(t, e) {
  4004. e.exports = n;
  4005. var i = t("../math/Vec3"), o = (t("../math/Mat3"), t("./Equation"));
  4006. function n(t, e, n) {
  4007. n = "undefined" != typeof n ? n : 1e6;
  4008. o.call(this, t, e, -n, n);
  4009. this.axisA = new i();
  4010. this.axisB = new i();
  4011. this.targetVelocity = 0;
  4012. }
  4013. n.prototype = new o();
  4014. n.prototype.constructor = n;
  4015. n.prototype.computeB = function(t) {
  4016. this.a;
  4017. var e = this.b, i = (this.bi, this.bj, this.axisA), o = this.axisB, n = this.jacobianElementA, r = this.jacobianElementB;
  4018. n.rotational.copy(i);
  4019. o.negate(r.rotational);
  4020. return -(this.computeGW() - this.targetVelocity) * e - t * this.computeGiMf();
  4021. };
  4022. }, {
  4023. "../math/Mat3": 29,
  4024. "../math/Vec3": 32,
  4025. "./Equation": 21
  4026. } ],
  4027. 25: [ function(t, e) {
  4028. var i = t("../utils/Utils");
  4029. e.exports = o;
  4030. function o(t, e, n) {
  4031. n = i.defaults(n, {
  4032. friction: .3,
  4033. restitution: .3,
  4034. contactEquationStiffness: 1e7,
  4035. contactEquationRelaxation: 3,
  4036. frictionEquationStiffness: 1e7,
  4037. frictionEquationRelaxation: 3
  4038. });
  4039. this.id = o.idCounter++;
  4040. this.materials = [ t, e ];
  4041. this.friction = n.friction;
  4042. this.restitution = n.restitution;
  4043. this.contactEquationStiffness = n.contactEquationStiffness;
  4044. this.contactEquationRelaxation = n.contactEquationRelaxation;
  4045. this.frictionEquationStiffness = n.frictionEquationStiffness;
  4046. this.frictionEquationRelaxation = n.frictionEquationRelaxation;
  4047. }
  4048. o.idCounter = 0;
  4049. }, {
  4050. "../utils/Utils": 55
  4051. } ],
  4052. 26: [ function(t, e) {
  4053. e.exports = i;
  4054. function i(t) {
  4055. var e = "";
  4056. if ("string" == typeof (t = t || {})) {
  4057. e = t;
  4058. t = {};
  4059. } else "object" == typeof t && (e = "");
  4060. this.name = e;
  4061. this.id = i.idCounter++;
  4062. this.friction = "undefined" != typeof t.friction ? t.friction : -1;
  4063. this.restitution = "undefined" != typeof t.restitution ? t.restitution : -1;
  4064. }
  4065. i.idCounter = 0;
  4066. }, {} ],
  4067. 27: [ function(t, e) {
  4068. var i = 180 / Math.PI;
  4069. function o(t) {
  4070. return t * i;
  4071. }
  4072. var n = {};
  4073. function r(t) {
  4074. if (n.digit != t) {
  4075. for (var e = 1 / Math.pow(10, t), o = 0; o <= 90; o += e) n[o.toFixed(t)] = Math.sin(o / i);
  4076. n.digit = t;
  4077. }
  4078. }
  4079. function s(t, e) {
  4080. 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)];
  4081. }
  4082. function a(t) {
  4083. var e = o(t) % 360;
  4084. e < 0 && (e += 360);
  4085. return s(e, u._digit);
  4086. }
  4087. function l(t) {
  4088. var e = (o(t) + 90) % 360;
  4089. e < 0 && (e += 360);
  4090. return s(e, u._digit);
  4091. }
  4092. function h(t) {
  4093. return Math.sin(t).toFixed(u.digit);
  4094. }
  4095. function c(t) {
  4096. return Math.cos(t).toFixed(u.digit);
  4097. }
  4098. var u = {
  4099. sin: Math.sin,
  4100. cos: Math.cos,
  4101. atan2: Math.atan2
  4102. };
  4103. u._sin = a;
  4104. u._cos = l;
  4105. u._sinArr = n;
  4106. u._sin360 = s;
  4107. u._sinNative = h;
  4108. u._cosNative = c;
  4109. u._radian2angle = o;
  4110. u._calculateSinByDigit = r;
  4111. u._digit = 1;
  4112. Object.defineProperty(u, "digit", {
  4113. get: function() {
  4114. return this._digit;
  4115. },
  4116. set: function(t) {
  4117. this._digit = t;
  4118. 1 == this._mode && r(t);
  4119. }
  4120. });
  4121. u._mode = 0;
  4122. Object.defineProperty(u, "mode", {
  4123. get: function() {
  4124. return this._mode;
  4125. },
  4126. set: function(t) {
  4127. if (this._mode != t) {
  4128. this._mode = t;
  4129. if (0 == t) {
  4130. u.sin = Math.sin;
  4131. u.cos = Math.cos;
  4132. } else if (1 == t) {
  4133. u.digit = u._digit;
  4134. u.sin = a;
  4135. u.cos = l;
  4136. } else if (2 == t) {
  4137. u.sin = h;
  4138. u.cos = c;
  4139. }
  4140. }
  4141. }
  4142. });
  4143. e.exports = u;
  4144. }, {} ],
  4145. 28: [ function(t, e) {
  4146. e.exports = o;
  4147. var i = t("./Vec3");
  4148. function o() {
  4149. this.spatial = new i();
  4150. this.rotational = new i();
  4151. }
  4152. o.prototype.multiplyElement = function(t) {
  4153. return t.spatial.dot(this.spatial) + t.rotational.dot(this.rotational);
  4154. };
  4155. o.prototype.multiplyVectors = function(t, e) {
  4156. return t.dot(this.spatial) + e.dot(this.rotational);
  4157. };
  4158. }, {
  4159. "./Vec3": 32
  4160. } ],
  4161. 29: [ function(t, e) {
  4162. e.exports = o;
  4163. var i = t("./Vec3");
  4164. function o(t) {
  4165. this.elements = t || [ 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
  4166. }
  4167. o.prototype.identity = function() {
  4168. var t = this.elements;
  4169. t[0] = 1;
  4170. t[1] = 0;
  4171. t[2] = 0;
  4172. t[3] = 0;
  4173. t[4] = 1;
  4174. t[5] = 0;
  4175. t[6] = 0;
  4176. t[7] = 0;
  4177. t[8] = 1;
  4178. };
  4179. o.prototype.setZero = function() {
  4180. var t = this.elements;
  4181. t[0] = 0;
  4182. t[1] = 0;
  4183. t[2] = 0;
  4184. t[3] = 0;
  4185. t[4] = 0;
  4186. t[5] = 0;
  4187. t[6] = 0;
  4188. t[7] = 0;
  4189. t[8] = 0;
  4190. };
  4191. o.prototype.setTrace = function(t) {
  4192. var e = this.elements;
  4193. e[0] = t.x;
  4194. e[4] = t.y;
  4195. e[8] = t.z;
  4196. };
  4197. o.prototype.getTrace = function(t) {
  4198. t = t || new i();
  4199. var e = this.elements;
  4200. t.x = e[0];
  4201. t.y = e[4];
  4202. t.z = e[8];
  4203. };
  4204. o.prototype.vmult = function(t, e) {
  4205. e = e || new i();
  4206. var o = this.elements, n = t.x, r = t.y, s = t.z;
  4207. e.x = o[0] * n + o[1] * r + o[2] * s;
  4208. e.y = o[3] * n + o[4] * r + o[5] * s;
  4209. e.z = o[6] * n + o[7] * r + o[8] * s;
  4210. return e;
  4211. };
  4212. o.prototype.smult = function(t) {
  4213. for (var e = 0; e < this.elements.length; e++) this.elements[e] *= t;
  4214. };
  4215. o.prototype.mmult = function(t, e) {
  4216. for (var i = e || new o(), n = 0; n < 3; n++) for (var r = 0; r < 3; r++) {
  4217. for (var s = 0, a = 0; a < 3; a++) s += t.elements[n + 3 * a] * this.elements[a + 3 * r];
  4218. i.elements[n + 3 * r] = s;
  4219. }
  4220. return i;
  4221. };
  4222. o.prototype.scale = function(t, e) {
  4223. e = e || new o();
  4224. for (var i = this.elements, n = e.elements, r = 0; 3 !== r; r++) {
  4225. n[3 * r + 0] = t.x * i[3 * r + 0];
  4226. n[3 * r + 1] = t.y * i[3 * r + 1];
  4227. n[3 * r + 2] = t.z * i[3 * r + 2];
  4228. }
  4229. return e;
  4230. };
  4231. o.prototype.solve = function(t, e) {
  4232. e = e || new i();
  4233. for (var o, n = [], r = 0; r < 12; r++) n.push(0);
  4234. for (r = 0; r < 3; r++) for (o = 0; o < 3; o++) n[r + 4 * o] = this.elements[r + 3 * o];
  4235. n[3] = t.x;
  4236. n[7] = t.y;
  4237. n[11] = t.z;
  4238. var s, a, l = 3, h = l;
  4239. do {
  4240. if (0 === n[(r = h - l) + 4 * r]) for (o = r + 1; o < h; o++) if (0 !== n[r + 4 * o]) {
  4241. s = 4;
  4242. do {
  4243. n[(a = 4 - s) + 4 * r] += n[a + 4 * o];
  4244. } while (--s);
  4245. break;
  4246. }
  4247. if (0 !== n[r + 4 * r]) for (o = r + 1; o < h; o++) {
  4248. var c = n[r + 4 * o] / n[r + 4 * r];
  4249. s = 4;
  4250. do {
  4251. n[(a = 4 - s) + 4 * o] = a <= r ? 0 : n[a + 4 * o] - n[a + 4 * r] * c;
  4252. } while (--s);
  4253. }
  4254. } while (--l);
  4255. e.z = n[11] / n[10];
  4256. e.y = (n[7] - n[6] * e.z) / n[5];
  4257. e.x = (n[3] - n[2] * e.z - n[1] * e.y) / n[0];
  4258. 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() + "]";
  4259. return e;
  4260. };
  4261. o.prototype.e = function(t, e, i) {
  4262. if (void 0 === i) return this.elements[e + 3 * t];
  4263. this.elements[e + 3 * t] = i;
  4264. };
  4265. o.prototype.copy = function(t) {
  4266. for (var e = 0; e < t.elements.length; e++) this.elements[e] = t.elements[e];
  4267. return this;
  4268. };
  4269. o.prototype.toString = function() {
  4270. for (var t = "", e = 0; e < 9; e++) t += this.elements[e] + ",";
  4271. return t;
  4272. };
  4273. o.prototype.reverse = function(t) {
  4274. t = t || new o();
  4275. for (var e, i = [], n = 0; n < 18; n++) i.push(0);
  4276. for (n = 0; n < 3; n++) for (e = 0; e < 3; e++) i[n + 6 * e] = this.elements[n + 3 * e];
  4277. i[3] = 1;
  4278. i[9] = 0;
  4279. i[15] = 0;
  4280. i[4] = 0;
  4281. i[10] = 1;
  4282. i[16] = 0;
  4283. i[5] = 0;
  4284. i[11] = 0;
  4285. i[17] = 1;
  4286. var r, s, a = 3, l = a;
  4287. do {
  4288. if (0 === i[(n = l - a) + 6 * n]) for (e = n + 1; e < l; e++) if (0 !== i[n + 6 * e]) {
  4289. r = 6;
  4290. do {
  4291. i[(s = 6 - r) + 6 * n] += i[s + 6 * e];
  4292. } while (--r);
  4293. break;
  4294. }
  4295. if (0 !== i[n + 6 * n]) for (e = n + 1; e < l; e++) {
  4296. var h = i[n + 6 * e] / i[n + 6 * n];
  4297. r = 6;
  4298. do {
  4299. i[(s = 6 - r) + 6 * e] = s <= n ? 0 : i[s + 6 * e] - i[s + 6 * n] * h;
  4300. } while (--r);
  4301. }
  4302. } while (--a);
  4303. n = 2;
  4304. do {
  4305. e = n - 1;
  4306. do {
  4307. h = i[n + 6 * e] / i[n + 6 * n];
  4308. r = 6;
  4309. do {
  4310. i[(s = 6 - r) + 6 * e] = i[s + 6 * e] - i[s + 6 * n] * h;
  4311. } while (--r);
  4312. } while (e--);
  4313. } while (--n);
  4314. n = 2;
  4315. do {
  4316. h = 1 / i[n + 6 * n];
  4317. r = 6;
  4318. do {
  4319. i[(s = 6 - r) + 6 * n] = i[s + 6 * n] * h;
  4320. } while (--r);
  4321. } while (n--);
  4322. n = 2;
  4323. do {
  4324. e = 2;
  4325. do {
  4326. s = i[3 + e + 6 * n];
  4327. if (isNaN(s) || Infinity === s) throw "Could not reverse! A=[" + this.toString() + "]";
  4328. t.e(n, e, s);
  4329. } while (e--);
  4330. } while (n--);
  4331. return t;
  4332. };
  4333. o.prototype.setRotationFromQuaternion = function(t) {
  4334. 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;
  4335. m[0] = 1 - (u + d);
  4336. m[1] = h - v;
  4337. m[2] = c + f;
  4338. m[3] = h + v;
  4339. m[4] = 1 - (l + d);
  4340. m[5] = p - y;
  4341. m[6] = c - f;
  4342. m[7] = p + y;
  4343. m[8] = 1 - (l + u);
  4344. return this;
  4345. };
  4346. o.prototype.transpose = function(t) {
  4347. 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];
  4348. return t;
  4349. };
  4350. }, {
  4351. "./Vec3": 32
  4352. } ],
  4353. 30: [ function(t, e) {
  4354. e.exports = n;
  4355. var i = t("./Vec3"), o = t("./CMath");
  4356. function n(t, e, i, o) {
  4357. this.x = void 0 !== t ? t : 0;
  4358. this.y = void 0 !== e ? e : 0;
  4359. this.z = void 0 !== i ? i : 0;
  4360. this.w = void 0 !== o ? o : 1;
  4361. }
  4362. n.prototype.set = function(t, e, i, o) {
  4363. this.x = t;
  4364. this.y = e;
  4365. this.z = i;
  4366. this.w = o;
  4367. return this;
  4368. };
  4369. n.prototype.toString = function() {
  4370. return this.x + "," + this.y + "," + this.z + "," + this.w;
  4371. };
  4372. n.prototype.toArray = function() {
  4373. return [ this.x, this.y, this.z, this.w ];
  4374. };
  4375. n.prototype.setFromAxisAngle = function(t, e) {
  4376. var i = o.sin(.5 * e);
  4377. this.x = t.x * i;
  4378. this.y = t.y * i;
  4379. this.z = t.z * i;
  4380. this.w = o.cos(.5 * e);
  4381. return this;
  4382. };
  4383. n.prototype.toAxisAngle = function(t) {
  4384. t = t || new i();
  4385. this.normalize();
  4386. var e = 2 * Math.acos(this.w), o = Math.sqrt(1 - this.w * this.w);
  4387. if (o < .001) {
  4388. t.x = this.x;
  4389. t.y = this.y;
  4390. t.z = this.z;
  4391. } else {
  4392. t.x = this.x / o;
  4393. t.y = this.y / o;
  4394. t.z = this.z / o;
  4395. }
  4396. return [ t, e ];
  4397. };
  4398. var r = new i(), s = new i();
  4399. n.prototype.setFromVectors = function(t, e) {
  4400. if (t.isAntiparallelTo(e)) {
  4401. var i = r, o = s;
  4402. t.tangents(i, o);
  4403. this.setFromAxisAngle(i, Math.PI);
  4404. } else {
  4405. var n = t.cross(e);
  4406. this.x = n.x;
  4407. this.y = n.y;
  4408. this.z = n.z;
  4409. this.w = Math.sqrt(Math.pow(t.norm(), 2) * Math.pow(e.norm(), 2)) + t.dot(e);
  4410. this.normalize();
  4411. }
  4412. return this;
  4413. };
  4414. new i(), new i(), new i();
  4415. n.prototype.mult = function(t, e) {
  4416. e = e || new n();
  4417. 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;
  4418. e.x = i * c + s * a + o * h - r * l;
  4419. e.y = o * c + s * l + r * a - i * h;
  4420. e.z = r * c + s * h + i * l - o * a;
  4421. e.w = s * c - i * a - o * l - r * h;
  4422. return e;
  4423. };
  4424. n.prototype.inverse = function(t) {
  4425. var e = this.x, i = this.y, o = this.z, r = this.w;
  4426. t = t || new n();
  4427. this.conjugate(t);
  4428. var s = 1 / (e * e + i * i + o * o + r * r);
  4429. t.x *= s;
  4430. t.y *= s;
  4431. t.z *= s;
  4432. t.w *= s;
  4433. return t;
  4434. };
  4435. n.prototype.conjugate = function(t) {
  4436. (t = t || new n()).x = -this.x;
  4437. t.y = -this.y;
  4438. t.z = -this.z;
  4439. t.w = this.w;
  4440. return t;
  4441. };
  4442. n.prototype.normalize = function() {
  4443. var t = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
  4444. if (0 === t) {
  4445. this.x = 0;
  4446. this.y = 0;
  4447. this.z = 0;
  4448. this.w = 0;
  4449. } else {
  4450. t = 1 / t;
  4451. this.x *= t;
  4452. this.y *= t;
  4453. this.z *= t;
  4454. this.w *= t;
  4455. }
  4456. return this;
  4457. };
  4458. n.prototype.normalizeFast = function() {
  4459. var t = (3 - (this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w)) / 2;
  4460. if (0 === t) {
  4461. this.x = 0;
  4462. this.y = 0;
  4463. this.z = 0;
  4464. this.w = 0;
  4465. } else {
  4466. this.x *= t;
  4467. this.y *= t;
  4468. this.z *= t;
  4469. this.w *= t;
  4470. }
  4471. return this;
  4472. };
  4473. n.prototype.vmult = function(t, e) {
  4474. e = e || new i();
  4475. 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;
  4476. e.x = c * h + d * -s + u * -l - p * -a;
  4477. e.y = u * h + d * -a + p * -s - c * -l;
  4478. e.z = p * h + d * -l + c * -a - u * -s;
  4479. return e;
  4480. };
  4481. n.prototype.copy = function(t) {
  4482. this.x = t.x;
  4483. this.y = t.y;
  4484. this.z = t.z;
  4485. this.w = t.w;
  4486. return this;
  4487. };
  4488. n.prototype.toEuler = function(t, e) {
  4489. e = e || "YZX";
  4490. var i, n, r, s = this.x, a = this.y, l = this.z, h = this.w;
  4491. switch (e) {
  4492. case "YZX":
  4493. var c = s * a + l * h;
  4494. if (c > .499) {
  4495. i = 2 * o.atan2(s, h);
  4496. n = Math.PI / 2;
  4497. r = 0;
  4498. }
  4499. if (c < -.499) {
  4500. i = -2 * o.atan2(s, h);
  4501. n = -Math.PI / 2;
  4502. r = 0;
  4503. }
  4504. if (isNaN(i)) {
  4505. var u = s * s, p = a * a, d = l * l;
  4506. i = o.atan2(2 * a * h - 2 * s * l, 1 - 2 * p - 2 * d);
  4507. n = Math.asin(2 * c);
  4508. r = o.atan2(2 * s * h - 2 * a * l, 1 - 2 * u - 2 * d);
  4509. }
  4510. break;
  4511. default:
  4512. throw new Error("Euler order " + e + " not supported yet.");
  4513. }
  4514. t.y = i;
  4515. t.z = n;
  4516. t.x = r;
  4517. };
  4518. n.prototype.setFromEuler = function(t, e, i, n) {
  4519. n = n || "XYZ";
  4520. 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);
  4521. if ("XYZ" === n) {
  4522. this.x = l * s * a + r * h * c;
  4523. this.y = r * h * a - l * s * c;
  4524. this.z = r * s * c + l * h * a;
  4525. this.w = r * s * a - l * h * c;
  4526. } else if ("YXZ" === n) {
  4527. this.x = l * s * a + r * h * c;
  4528. this.y = r * h * a - l * s * c;
  4529. this.z = r * s * c - l * h * a;
  4530. this.w = r * s * a + l * h * c;
  4531. } else if ("ZXY" === n) {
  4532. this.x = l * s * a - r * h * c;
  4533. this.y = r * h * a + l * s * c;
  4534. this.z = r * s * c + l * h * a;
  4535. this.w = r * s * a - l * h * c;
  4536. } else if ("ZYX" === n) {
  4537. this.x = l * s * a - r * h * c;
  4538. this.y = r * h * a + l * s * c;
  4539. this.z = r * s * c - l * h * a;
  4540. this.w = r * s * a + l * h * c;
  4541. } else if ("YZX" === n) {
  4542. this.x = l * s * a + r * h * c;
  4543. this.y = r * h * a + l * s * c;
  4544. this.z = r * s * c - l * h * a;
  4545. this.w = r * s * a - l * h * c;
  4546. } else if ("XZY" === n) {
  4547. this.x = l * s * a - r * h * c;
  4548. this.y = r * h * a - l * s * c;
  4549. this.z = r * s * c + l * h * a;
  4550. this.w = r * s * a + l * h * c;
  4551. }
  4552. return this;
  4553. };
  4554. n.prototype.clone = function() {
  4555. return new n(this.x, this.y, this.z, this.w);
  4556. };
  4557. n.prototype.slerp = function(t, e, i) {
  4558. i = i || new n();
  4559. 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;
  4560. if ((s = c * y + u * f + p * v + d * m) < 0) {
  4561. s = -s;
  4562. y = -y;
  4563. f = -f;
  4564. v = -v;
  4565. m = -m;
  4566. }
  4567. if (1 - s > 1e-6) {
  4568. r = Math.acos(s);
  4569. a = o.sin(r);
  4570. l = o.sin((1 - e) * r) / a;
  4571. h = o.sin(e * r) / a;
  4572. } else {
  4573. l = 1 - e;
  4574. h = e;
  4575. }
  4576. i.x = l * c + h * y;
  4577. i.y = l * u + h * f;
  4578. i.z = l * p + h * v;
  4579. i.w = l * d + h * m;
  4580. return i;
  4581. };
  4582. n.prototype.integrate = function(t, e, i, o) {
  4583. o = o || new n();
  4584. 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;
  4585. o.x += p * (r * u + s * c - a * h);
  4586. o.y += p * (s * u + a * l - r * c);
  4587. o.z += p * (a * u + r * h - s * l);
  4588. o.w += p * (-r * l - s * h - a * c);
  4589. return o;
  4590. };
  4591. }, {
  4592. "./CMath": 27,
  4593. "./Vec3": 32
  4594. } ],
  4595. 31: [ function(t, e) {
  4596. var i = t("./Vec3"), o = t("./Quaternion");
  4597. e.exports = n;
  4598. function n(t) {
  4599. t = t || {};
  4600. this.position = new i();
  4601. t.position && this.position.copy(t.position);
  4602. this.quaternion = new o();
  4603. t.quaternion && this.quaternion.copy(t.quaternion);
  4604. }
  4605. var r = new o();
  4606. n.pointToLocalFrame = function(t, e, o, n) {
  4607. n = n || new i();
  4608. o.vsub(t, n);
  4609. e.conjugate(r);
  4610. r.vmult(n, n);
  4611. return n;
  4612. };
  4613. n.prototype.pointToLocal = function(t, e) {
  4614. return n.pointToLocalFrame(this.position, this.quaternion, t, e);
  4615. };
  4616. n.pointToWorldFrame = function(t, e, o, n) {
  4617. n = n || new i();
  4618. e.vmult(o, n);
  4619. n.vadd(t, n);
  4620. return n;
  4621. };
  4622. n.prototype.pointToWorld = function(t, e) {
  4623. return n.pointToWorldFrame(this.position, this.quaternion, t, e);
  4624. };
  4625. n.prototype.vectorToWorldFrame = function(t, e) {
  4626. e = e || new i();
  4627. this.quaternion.vmult(t, e);
  4628. return e;
  4629. };
  4630. n.vectorToWorldFrame = function(t, e, i) {
  4631. t.vmult(e, i);
  4632. return i;
  4633. };
  4634. n.vectorToLocalFrame = function(t, e, o, n) {
  4635. n = n || new i();
  4636. e.w *= -1;
  4637. e.vmult(o, n);
  4638. e.w *= -1;
  4639. return n;
  4640. };
  4641. }, {
  4642. "./Quaternion": 30,
  4643. "./Vec3": 32
  4644. } ],
  4645. 32: [ function(t, e) {
  4646. e.exports = o;
  4647. var i = t("./Mat3");
  4648. function o(t, e, i) {
  4649. this.x = t || 0;
  4650. this.y = e || 0;
  4651. this.z = i || 0;
  4652. }
  4653. o.ZERO = new o(0, 0, 0);
  4654. o.UNIT_X = new o(1, 0, 0);
  4655. o.UNIT_Y = new o(0, 1, 0);
  4656. o.UNIT_Z = new o(0, 0, 1);
  4657. o.prototype.cross = function(t, e) {
  4658. var i = t.x, n = t.y, r = t.z, s = this.x, a = this.y, l = this.z;
  4659. (e = e || new o()).x = a * r - l * n;
  4660. e.y = l * i - s * r;
  4661. e.z = s * n - a * i;
  4662. return e;
  4663. };
  4664. o.prototype.set = function(t, e, i) {
  4665. this.x = t;
  4666. this.y = e;
  4667. this.z = i;
  4668. return this;
  4669. };
  4670. o.prototype.setZero = function() {
  4671. this.x = this.y = this.z = 0;
  4672. };
  4673. o.prototype.vadd = function(t, e) {
  4674. if (!e) return new o(this.x + t.x, this.y + t.y, this.z + t.z);
  4675. e.x = t.x + this.x;
  4676. e.y = t.y + this.y;
  4677. e.z = t.z + this.z;
  4678. };
  4679. o.prototype.vsub = function(t, e) {
  4680. if (!e) return new o(this.x - t.x, this.y - t.y, this.z - t.z);
  4681. e.x = this.x - t.x;
  4682. e.y = this.y - t.y;
  4683. e.z = this.z - t.z;
  4684. };
  4685. o.prototype.crossmat = function() {
  4686. return new i([ 0, -this.z, this.y, this.z, 0, -this.x, -this.y, this.x, 0 ]);
  4687. };
  4688. o.prototype.normalize = function() {
  4689. var t = this.x, e = this.y, i = this.z, o = Math.sqrt(t * t + e * e + i * i);
  4690. if (o > 0) {
  4691. var n = 1 / o;
  4692. this.x *= n;
  4693. this.y *= n;
  4694. this.z *= n;
  4695. } else {
  4696. this.x = 0;
  4697. this.y = 0;
  4698. this.z = 0;
  4699. }
  4700. return o;
  4701. };
  4702. o.prototype.unit = function(t) {
  4703. t = t || new o();
  4704. var e = this.x, i = this.y, n = this.z, r = Math.sqrt(e * e + i * i + n * n);
  4705. if (r > 0) {
  4706. r = 1 / r;
  4707. t.x = e * r;
  4708. t.y = i * r;
  4709. t.z = n * r;
  4710. } else {
  4711. t.x = 1;
  4712. t.y = 0;
  4713. t.z = 0;
  4714. }
  4715. return t;
  4716. };
  4717. o.prototype.norm = function() {
  4718. var t = this.x, e = this.y, i = this.z;
  4719. return Math.sqrt(t * t + e * e + i * i);
  4720. };
  4721. o.prototype.length = o.prototype.norm;
  4722. o.prototype.norm2 = function() {
  4723. return this.dot(this);
  4724. };
  4725. o.prototype.lengthSquared = o.prototype.norm2;
  4726. o.prototype.distanceTo = function(t) {
  4727. var e = this.x, i = this.y, o = this.z, n = t.x, r = t.y, s = t.z;
  4728. return Math.sqrt((n - e) * (n - e) + (r - i) * (r - i) + (s - o) * (s - o));
  4729. };
  4730. o.prototype.distanceSquared = function(t) {
  4731. var e = this.x, i = this.y, o = this.z, n = t.x, r = t.y, s = t.z;
  4732. return (n - e) * (n - e) + (r - i) * (r - i) + (s - o) * (s - o);
  4733. };
  4734. o.prototype.mult = function(t, e) {
  4735. e = e || new o();
  4736. var i = this.x, n = this.y, r = this.z;
  4737. e.x = t * i;
  4738. e.y = t * n;
  4739. e.z = t * r;
  4740. return e;
  4741. };
  4742. o.prototype.vmul = function(t, e) {
  4743. (e = e || new o()).x = t.x * this.x;
  4744. e.y = t.y * this.y;
  4745. e.z = t.z * this.z;
  4746. return e;
  4747. };
  4748. o.prototype.scale = o.prototype.mult;
  4749. o.prototype.addScaledVector = function(t, e, i) {
  4750. (i = i || new o()).x = this.x + t * e.x;
  4751. i.y = this.y + t * e.y;
  4752. i.z = this.z + t * e.z;
  4753. return i;
  4754. };
  4755. o.prototype.dot = function(t) {
  4756. return this.x * t.x + this.y * t.y + this.z * t.z;
  4757. };
  4758. o.prototype.isZero = function() {
  4759. return 0 === this.x && 0 === this.y && 0 === this.z;
  4760. };
  4761. o.prototype.negate = function(t) {
  4762. (t = t || new o()).x = -this.x;
  4763. t.y = -this.y;
  4764. t.z = -this.z;
  4765. return t;
  4766. };
  4767. var n = new o(), r = new o();
  4768. o.prototype.tangents = function(t, e) {
  4769. var i = this.norm();
  4770. if (i > 0) {
  4771. var o = n, s = 1 / i;
  4772. o.set(this.x * s, this.y * s, this.z * s);
  4773. var a = r;
  4774. if (Math.abs(o.x) < .9) {
  4775. a.set(1, 0, 0);
  4776. o.cross(a, t);
  4777. } else {
  4778. a.set(0, 1, 0);
  4779. o.cross(a, t);
  4780. }
  4781. o.cross(t, e);
  4782. } else {
  4783. t.set(1, 0, 0);
  4784. e.set(0, 1, 0);
  4785. }
  4786. };
  4787. o.prototype.toString = function() {
  4788. return this.x + "," + this.y + "," + this.z;
  4789. };
  4790. o.prototype.toArray = function() {
  4791. return [ this.x, this.y, this.z ];
  4792. };
  4793. o.prototype.copy = function(t) {
  4794. this.x = t.x;
  4795. this.y = t.y;
  4796. this.z = t.z;
  4797. return this;
  4798. };
  4799. o.prototype.lerp = function(t, e, i) {
  4800. var o = this.x, n = this.y, r = this.z;
  4801. i.x = o + (t.x - o) * e;
  4802. i.y = n + (t.y - n) * e;
  4803. i.z = r + (t.z - r) * e;
  4804. };
  4805. o.prototype.almostEquals = function(t, e) {
  4806. void 0 === e && (e = 1e-6);
  4807. return !(Math.abs(this.x - t.x) > e || Math.abs(this.y - t.y) > e || Math.abs(this.z - t.z) > e);
  4808. };
  4809. o.prototype.almostZero = function(t) {
  4810. void 0 === t && (t = 1e-6);
  4811. return !(Math.abs(this.x) > t || Math.abs(this.y) > t || Math.abs(this.z) > t);
  4812. };
  4813. var s = new o();
  4814. o.prototype.isAntiparallelTo = function(t, e) {
  4815. this.negate(s);
  4816. return s.almostEquals(t, e);
  4817. };
  4818. o.prototype.clone = function() {
  4819. return new o(this.x, this.y, this.z);
  4820. };
  4821. }, {
  4822. "./Mat3": 29
  4823. } ],
  4824. 33: [ function(t, e) {
  4825. e.exports = h;
  4826. var i = t("../utils/EventTarget"), o = (t("../shapes/Shape"), t("../math/Vec3")), n = t("../math/Mat3"), r = t("../math/Quaternion"), s = (t("../material/Material"),
  4827. t("../collision/AABB")), a = t("../shapes/Box"), l = t("../world/World");
  4828. function h(t) {
  4829. t = t || {};
  4830. i.apply(this);
  4831. this.id = h.idCounter++;
  4832. this.world = null;
  4833. this.preStep = null;
  4834. this.postStep = null;
  4835. this.vlambda = new o();
  4836. this.collisionFilterGroup = "number" == typeof t.collisionFilterGroup ? t.collisionFilterGroup : 1;
  4837. this.collisionFilterMask = "number" == typeof t.collisionFilterMask ? t.collisionFilterMask : -1;
  4838. this.collisionResponse = !0;
  4839. this.position = new o();
  4840. this.previousPosition = new o();
  4841. this.interpolatedPosition = new o();
  4842. this.initPosition = new o();
  4843. if (t.position) {
  4844. this.position.copy(t.position);
  4845. this.previousPosition.copy(t.position);
  4846. this.interpolatedPosition.copy(t.position);
  4847. this.initPosition.copy(t.position);
  4848. }
  4849. this.velocity = new o();
  4850. t.velocity && this.velocity.copy(t.velocity);
  4851. this.initVelocity = new o();
  4852. this.force = new o();
  4853. var e = "number" == typeof t.mass ? t.mass : 0;
  4854. this.mass = e;
  4855. this.invMass = e > 0 ? 1 / e : 0;
  4856. this.material = t.material || null;
  4857. this.linearDamping = "number" == typeof t.linearDamping ? t.linearDamping : .01;
  4858. this.type = e <= 0 ? h.STATIC : h.DYNAMIC;
  4859. typeof t.type == typeof h.STATIC && (this.type = t.type);
  4860. this.allowSleep = "undefined" == typeof t.allowSleep || t.allowSleep;
  4861. this.sleepState = 0;
  4862. this.sleepSpeedLimit = "undefined" != typeof t.sleepSpeedLimit ? t.sleepSpeedLimit : .1;
  4863. this.sleepTimeLimit = "undefined" != typeof t.sleepTimeLimit ? t.sleepTimeLimit : 1;
  4864. this.timeLastSleepy = 0;
  4865. this._wakeUpAfterNarrowphase = !1;
  4866. this.torque = new o();
  4867. this.quaternion = new r();
  4868. this.initQuaternion = new r();
  4869. this.previousQuaternion = new r();
  4870. this.interpolatedQuaternion = new r();
  4871. if (t.quaternion) {
  4872. this.quaternion.copy(t.quaternion);
  4873. this.initQuaternion.copy(t.quaternion);
  4874. this.previousQuaternion.copy(t.quaternion);
  4875. this.interpolatedQuaternion.copy(t.quaternion);
  4876. }
  4877. this.angularVelocity = new o();
  4878. t.angularVelocity && this.angularVelocity.copy(t.angularVelocity);
  4879. this.initAngularVelocity = new o();
  4880. this.shapes = [];
  4881. this.shapeOffsets = [];
  4882. this.shapeOrientations = [];
  4883. this.inertia = new o();
  4884. this.invInertia = new o();
  4885. this.invInertiaWorld = new n();
  4886. this.invMassSolve = 0;
  4887. this.invInertiaSolve = new o();
  4888. this.invInertiaWorldSolve = new n();
  4889. this.fixedRotation = "undefined" != typeof t.fixedRotation && t.fixedRotation;
  4890. this.useGravity = !0;
  4891. this.angularDamping = "undefined" != typeof t.angularDamping ? t.angularDamping : .01;
  4892. this.linearFactor = new o(1, 1, 1);
  4893. t.linearFactor && this.linearFactor.copy(t.linearFactor);
  4894. this.angularFactor = new o(1, 1, 1);
  4895. t.angularFactor && this.angularFactor.copy(t.angularFactor);
  4896. this.aabb = new s();
  4897. this.aabbNeedsUpdate = !0;
  4898. this.boundingRadius = 0;
  4899. this.wlambda = new o();
  4900. t.shape && this.addShape(t.shape);
  4901. this.hasTrigger = !0;
  4902. this.updateMassProperties();
  4903. }
  4904. h.prototype = new i();
  4905. h.prototype.constructor = h;
  4906. h.COLLIDE_EVENT_NAME = "collide";
  4907. h.DYNAMIC = 1;
  4908. h.STATIC = 2;
  4909. h.KINEMATIC = 4;
  4910. h.AWAKE = 0;
  4911. h.SLEEPY = 1;
  4912. h.SLEEPING = 2;
  4913. h.idCounter = 0;
  4914. h.wakeupEvent = {
  4915. type: "wakeup"
  4916. };
  4917. h.prototype.wakeUp = function() {
  4918. l.SLEEPING = !1;
  4919. var t = this.sleepState;
  4920. this.sleepState = 0;
  4921. this._wakeUpAfterNarrowphase = !1;
  4922. t === h.SLEEPING && this.dispatchEvent(h.wakeupEvent);
  4923. };
  4924. h.prototype.sleep = function() {
  4925. this.sleepState = h.SLEEPING;
  4926. this.velocity.set(0, 0, 0);
  4927. this.angularVelocity.set(0, 0, 0);
  4928. this._wakeUpAfterNarrowphase = !1;
  4929. };
  4930. h.sleepyEvent = {
  4931. type: "sleepy"
  4932. };
  4933. h.sleepEvent = {
  4934. type: "sleep"
  4935. };
  4936. h.prototype.sleepTick = function(t) {
  4937. if (this.allowSleep) {
  4938. var e = this.sleepState, i = this.velocity.norm2() + this.angularVelocity.norm2(), o = Math.pow(this.sleepSpeedLimit, 2);
  4939. if (e === h.AWAKE && i < o) {
  4940. this.sleepState = h.SLEEPY;
  4941. this.timeLastSleepy = t;
  4942. this.dispatchEvent(h.sleepyEvent);
  4943. } else if (e === h.SLEEPY && i > o) this.wakeUp(); else if (e === h.SLEEPY && t - this.timeLastSleepy > this.sleepTimeLimit) {
  4944. this.sleep();
  4945. this.dispatchEvent(h.sleepEvent);
  4946. }
  4947. }
  4948. };
  4949. h.prototype.updateSolveMassProperties = function() {
  4950. if (this.sleepState === h.SLEEPING || this.type === h.KINEMATIC) {
  4951. this.invMassSolve = 0;
  4952. this.invInertiaSolve.setZero();
  4953. this.invInertiaWorldSolve.setZero();
  4954. } else {
  4955. this.invMassSolve = this.invMass;
  4956. this.invInertiaSolve.copy(this.invInertia);
  4957. this.invInertiaWorldSolve.copy(this.invInertiaWorld);
  4958. }
  4959. };
  4960. h.prototype.pointToLocalFrame = function(t, e) {
  4961. e = e || new o();
  4962. t.vsub(this.position, e);
  4963. this.quaternion.conjugate().vmult(e, e);
  4964. return e;
  4965. };
  4966. h.prototype.vectorToLocalFrame = function(t, e) {
  4967. e = e || new o();
  4968. this.quaternion.conjugate().vmult(t, e);
  4969. return e;
  4970. };
  4971. h.prototype.pointToWorldFrame = function(t, e) {
  4972. e = e || new o();
  4973. this.quaternion.vmult(t, e);
  4974. e.vadd(this.position, e);
  4975. return e;
  4976. };
  4977. h.prototype.vectorToWorldFrame = function(t, e) {
  4978. e = e || new o();
  4979. this.quaternion.vmult(t, e);
  4980. return e;
  4981. };
  4982. var c = new o(), u = new r();
  4983. h.prototype.addShape = function(t, e, i) {
  4984. var n = new o(), s = new r();
  4985. e && n.copy(e);
  4986. i && s.copy(i);
  4987. this.shapes.push(t);
  4988. this.shapeOffsets.push(n);
  4989. this.shapeOrientations.push(s);
  4990. this.aabbNeedsUpdate = !0;
  4991. this.updateMassProperties();
  4992. this.updateBoundingRadius();
  4993. this.updateHasTrigger();
  4994. l.idToShapeMap[t.id] = t;
  4995. t.body = this;
  4996. return this;
  4997. };
  4998. h.prototype.removeShape = function(t) {
  4999. var e = this.shapes.indexOf(t);
  5000. if (-1 !== e) {
  5001. this.shapes.splice(e, 1);
  5002. this.shapeOffsets.splice(e, 1);
  5003. this.shapeOrientations.splice(e, 1);
  5004. this.aabbNeedsUpdate = !0;
  5005. this.updateMassProperties();
  5006. this.updateBoundingRadius();
  5007. this.updateHasTrigger();
  5008. }
  5009. };
  5010. h.prototype.updateBoundingRadius = function() {
  5011. for (var t = this.shapes, e = this.shapeOffsets, i = t.length, o = 0, n = 0; n !== i; n++) {
  5012. var r = t[n];
  5013. r.updateBoundingSphereRadius();
  5014. var s = e[n].norm(), a = r.boundingSphereRadius;
  5015. s + a > o && (o = s + a);
  5016. }
  5017. this.boundingRadius = o;
  5018. };
  5019. var p = new s();
  5020. h.prototype.computeAABB = function() {
  5021. 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++) {
  5022. var d = t[h];
  5023. s.vmult(e[h], n);
  5024. n.vadd(this.position, n);
  5025. i[h].mult(s, r);
  5026. d.calculateWorldAABB(n, r, l.lowerBound, l.upperBound);
  5027. 0 === h ? a.copy(l) : a.extend(l);
  5028. }
  5029. this.aabbNeedsUpdate = !1;
  5030. };
  5031. var d = new n(), y = new n();
  5032. new n();
  5033. h.prototype.updateInertiaWorld = function(t) {
  5034. var e = this.invInertia;
  5035. if (e.x !== e.y || e.y !== e.z || t) {
  5036. var i = d, o = y;
  5037. i.setRotationFromQuaternion(this.quaternion);
  5038. i.transpose(o);
  5039. i.scale(e, i);
  5040. i.mmult(o, this.invInertiaWorld);
  5041. }
  5042. };
  5043. new o();
  5044. var f = new o();
  5045. h.prototype.applyForce = function(t, e) {
  5046. if (this.type === h.DYNAMIC) {
  5047. var i = f;
  5048. e.cross(t, i);
  5049. this.force.vadd(t, this.force);
  5050. this.torque.vadd(i, this.torque);
  5051. }
  5052. };
  5053. var v = new o(), m = new o();
  5054. h.prototype.applyLocalForce = function(t, e) {
  5055. if (this.type === h.DYNAMIC) {
  5056. var i = v, o = m;
  5057. this.vectorToWorldFrame(t, i);
  5058. this.vectorToWorldFrame(e, o);
  5059. this.applyForce(i, o);
  5060. }
  5061. };
  5062. new o();
  5063. var g = new o(), b = new o();
  5064. h.prototype.applyImpulse = function(t, e) {
  5065. if (this.type === h.DYNAMIC) {
  5066. var i = e, o = g;
  5067. o.copy(t);
  5068. o.mult(this.invMass, o);
  5069. this.velocity.vadd(o, this.velocity);
  5070. var n = b;
  5071. i.cross(t, n);
  5072. this.invInertiaWorld.vmult(n, n);
  5073. this.angularVelocity.vadd(n, this.angularVelocity);
  5074. }
  5075. };
  5076. var w = new o(), x = new o();
  5077. h.prototype.applyLocalImpulse = function(t, e) {
  5078. if (this.type === h.DYNAMIC) {
  5079. var i = w, o = x;
  5080. this.vectorToWorldFrame(t, i);
  5081. this.vectorToWorldFrame(e, o);
  5082. this.applyImpulse(i, o);
  5083. }
  5084. };
  5085. var _ = new o();
  5086. h.prototype.updateMassProperties = function() {
  5087. var t = _;
  5088. this.invMass = this.mass > 0 ? 1 / this.mass : 0;
  5089. var e = this.inertia, i = this.fixedRotation;
  5090. this.computeAABB();
  5091. 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);
  5092. a.calculateInertia(t, this.mass, e);
  5093. 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);
  5094. this.updateInertiaWorld(!0);
  5095. };
  5096. h.prototype.getVelocityAtWorldPoint = function(t, e) {
  5097. var i = new o();
  5098. t.vsub(this.position, i);
  5099. this.angularVelocity.cross(i, e);
  5100. this.velocity.vadd(e, e);
  5101. return e;
  5102. };
  5103. new o(), new o(), new r(), new r();
  5104. h.prototype.integrate = function(t, e, i) {
  5105. this.previousPosition.copy(this.position);
  5106. this.previousQuaternion.copy(this.quaternion);
  5107. if ((this.type === h.DYNAMIC || this.type === h.KINEMATIC) && this.sleepState !== h.SLEEPING) {
  5108. 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;
  5109. o.x += s.x * d * p.x;
  5110. o.y += s.y * d * p.y;
  5111. o.z += s.z * d * p.z;
  5112. var y = u.elements, f = this.angularFactor, v = a.x * f.x, m = a.y * f.y, g = a.z * f.z;
  5113. n.x += t * (y[0] * v + y[1] * m + y[2] * g);
  5114. n.y += t * (y[3] * v + y[4] * m + y[5] * g);
  5115. n.z += t * (y[6] * v + y[7] * m + y[8] * g);
  5116. r.x += o.x * t;
  5117. r.y += o.y * t;
  5118. r.z += o.z * t;
  5119. l.integrate(this.angularVelocity, t, this.angularFactor, l);
  5120. e && (i ? l.normalizeFast() : l.normalize());
  5121. this.aabbNeedsUpdate = !0;
  5122. this.updateInertiaWorld();
  5123. }
  5124. };
  5125. h.prototype.isSleeping = function() {
  5126. return this.sleepState === h.SLEEPING;
  5127. };
  5128. h.prototype.isSleepy = function() {
  5129. return this.sleepState === h.SLEEPY;
  5130. };
  5131. h.prototype.isAwake = function() {
  5132. return this.sleepState === h.AWAKE;
  5133. };
  5134. h.prototype.updateHasTrigger = function() {
  5135. for (var t = this.shapes.length; t--; ) {
  5136. this.hasTrigger = !this.shapes[t].collisionResponse;
  5137. if (this.hasTrigger) break;
  5138. }
  5139. };
  5140. }, {
  5141. "../collision/AABB": 3,
  5142. "../material/Material": 26,
  5143. "../math/Mat3": 29,
  5144. "../math/Quaternion": 30,
  5145. "../math/Vec3": 32,
  5146. "../shapes/Box": 39,
  5147. "../shapes/Shape": 45,
  5148. "../utils/EventTarget": 51,
  5149. "../world/World": 58
  5150. } ],
  5151. 34: [ function(t, e) {
  5152. t("./Body");
  5153. var i = t("../math/Vec3"), o = t("../math/Quaternion"), n = (t("../collision/RaycastResult"),
  5154. t("../collision/Ray")), r = t("../objects/WheelInfo");
  5155. e.exports = s;
  5156. function s(t) {
  5157. this.chassisBody = t.chassisBody;
  5158. this.wheelInfos = [];
  5159. this.sliding = !1;
  5160. this.world = null;
  5161. this.indexRightAxis = "undefined" != typeof t.indexRightAxis ? t.indexRightAxis : 1;
  5162. this.indexForwardAxis = "undefined" != typeof t.indexForwardAxis ? t.indexForwardAxis : 0;
  5163. this.indexUpAxis = "undefined" != typeof t.indexUpAxis ? t.indexUpAxis : 2;
  5164. }
  5165. new i(), new i(), new i();
  5166. var a = new i(), l = new i(), h = new i();
  5167. new n();
  5168. s.prototype.addWheel = function(t) {
  5169. var e = new r(t = t || {}), i = this.wheelInfos.length;
  5170. this.wheelInfos.push(e);
  5171. return i;
  5172. };
  5173. s.prototype.setSteeringValue = function(t, e) {
  5174. this.wheelInfos[e].steering = t;
  5175. };
  5176. new i();
  5177. s.prototype.applyEngineForce = function(t, e) {
  5178. this.wheelInfos[e].engineForce = t;
  5179. };
  5180. s.prototype.setBrake = function(t, e) {
  5181. this.wheelInfos[e].brake = t;
  5182. };
  5183. s.prototype.addToWorld = function(t) {
  5184. this.constraints;
  5185. t.addBody(this.chassisBody);
  5186. var e = this;
  5187. this.preStepCallback = function() {
  5188. e.updateVehicle(t.dt);
  5189. };
  5190. t.addEventListener("preStep", this.preStepCallback);
  5191. this.world = t;
  5192. };
  5193. s.prototype.getVehicleAxisWorld = function(t, e) {
  5194. e.set(0 === t ? 1 : 0, 1 === t ? 1 : 0, 2 === t ? 1 : 0);
  5195. this.chassisBody.vectorToWorldFrame(e, e);
  5196. };
  5197. s.prototype.updateVehicle = function(t) {
  5198. for (var e = this.wheelInfos, o = e.length, n = this.chassisBody, r = 0; r < o; r++) this.updateWheelTransform(r);
  5199. this.currentVehicleSpeedKmHour = 3.6 * n.velocity.norm();
  5200. var s = new i();
  5201. this.getVehicleAxisWorld(this.indexForwardAxis, s);
  5202. s.dot(n.velocity) < 0 && (this.currentVehicleSpeedKmHour *= -1);
  5203. for (r = 0; r < o; r++) this.castRay(e[r]);
  5204. this.updateSuspension(t);
  5205. var a = new i(), l = new i();
  5206. for (r = 0; r < o; r++) {
  5207. var h = (d = e[r]).suspensionForce;
  5208. h > d.maxSuspensionForce && (h = d.maxSuspensionForce);
  5209. d.raycastResult.hitNormalWorld.scale(h * t, a);
  5210. d.raycastResult.hitPointWorld.vsub(n.position, l);
  5211. n.applyImpulse(a, l);
  5212. }
  5213. this.updateFriction(t);
  5214. var c = new i(), u = new i(), p = new i();
  5215. for (r = 0; r < o; r++) {
  5216. var d = e[r];
  5217. n.getVelocityAtWorldPoint(d.chassisConnectionPointWorld, p);
  5218. var y = 1;
  5219. switch (this.indexUpAxis) {
  5220. case 1:
  5221. y = -1;
  5222. }
  5223. if (d.isInContact) {
  5224. this.getVehicleAxisWorld(this.indexForwardAxis, u);
  5225. var f = u.dot(d.raycastResult.hitNormalWorld);
  5226. d.raycastResult.hitNormalWorld.scale(f, c);
  5227. u.vsub(c, u);
  5228. var v = u.dot(p);
  5229. d.deltaRotation = y * v * t / d.radius;
  5230. }
  5231. !d.sliding && d.isInContact || 0 === d.engineForce || !d.useCustomSlidingRotationalSpeed || (d.deltaRotation = (d.engineForce > 0 ? 1 : -1) * d.customSlidingRotationalSpeed * t);
  5232. Math.abs(d.brake) > Math.abs(d.engineForce) && (d.deltaRotation = 0);
  5233. d.rotation += d.deltaRotation;
  5234. d.deltaRotation *= .99;
  5235. }
  5236. };
  5237. s.prototype.updateSuspension = function() {
  5238. for (var t = this.chassisBody.mass, e = this.wheelInfos, i = e.length, o = 0; o < i; o++) {
  5239. var n = e[o];
  5240. if (n.isInContact) {
  5241. var r, s = n.suspensionRestLength - n.suspensionLength;
  5242. r = n.suspensionStiffness * s * n.clippedInvContactDotSuspension;
  5243. var a = n.suspensionRelativeVelocity;
  5244. r -= (a < 0 ? n.dampingCompression : n.dampingRelaxation) * a;
  5245. n.suspensionForce = r * t;
  5246. n.suspensionForce < 0 && (n.suspensionForce = 0);
  5247. } else n.suspensionForce = 0;
  5248. }
  5249. };
  5250. s.prototype.removeFromWorld = function(t) {
  5251. this.constraints;
  5252. t.remove(this.chassisBody);
  5253. t.removeEventListener("preStep", this.preStepCallback);
  5254. this.world = null;
  5255. };
  5256. var c = new i(), u = new i();
  5257. s.prototype.castRay = function(t) {
  5258. var e = c, o = u;
  5259. this.updateWheelTransformWorld(t);
  5260. var n = this.chassisBody, r = -1, s = t.suspensionRestLength + t.radius;
  5261. t.directionWorld.scale(s, e);
  5262. var a = t.chassisConnectionPointWorld;
  5263. a.vadd(e, o);
  5264. var l = t.raycastResult;
  5265. l.reset();
  5266. var h = n.collisionResponse;
  5267. n.collisionResponse = !1;
  5268. this.world.rayTest(a, o, l);
  5269. n.collisionResponse = h;
  5270. var p = l.body;
  5271. t.raycastResult.groundObject = 0;
  5272. if (p) {
  5273. r = l.distance;
  5274. t.raycastResult.hitNormalWorld = l.hitNormalWorld;
  5275. t.isInContact = !0;
  5276. var d = l.distance;
  5277. t.suspensionLength = d - t.radius;
  5278. var y = t.suspensionRestLength - t.maxSuspensionTravel, f = t.suspensionRestLength + t.maxSuspensionTravel;
  5279. t.suspensionLength < y && (t.suspensionLength = y);
  5280. if (t.suspensionLength > f) {
  5281. t.suspensionLength = f;
  5282. t.raycastResult.reset();
  5283. }
  5284. var v = t.raycastResult.hitNormalWorld.dot(t.directionWorld), m = new i();
  5285. n.getVelocityAtWorldPoint(t.raycastResult.hitPointWorld, m);
  5286. var g = t.raycastResult.hitNormalWorld.dot(m);
  5287. if (v >= -.1) {
  5288. t.suspensionRelativeVelocity = 0;
  5289. t.clippedInvContactDotSuspension = 10;
  5290. } else {
  5291. var b = -1 / v;
  5292. t.suspensionRelativeVelocity = g * b;
  5293. t.clippedInvContactDotSuspension = b;
  5294. }
  5295. } else {
  5296. t.suspensionLength = t.suspensionRestLength + 0 * t.maxSuspensionTravel;
  5297. t.suspensionRelativeVelocity = 0;
  5298. t.directionWorld.scale(-1, t.raycastResult.hitNormalWorld);
  5299. t.clippedInvContactDotSuspension = 1;
  5300. }
  5301. return r;
  5302. };
  5303. s.prototype.updateWheelTransformWorld = function(t) {
  5304. t.isInContact = !1;
  5305. var e = this.chassisBody;
  5306. e.pointToWorldFrame(t.chassisConnectionPointLocal, t.chassisConnectionPointWorld);
  5307. e.vectorToWorldFrame(t.directionLocal, t.directionWorld);
  5308. e.vectorToWorldFrame(t.axleLocal, t.axleWorld);
  5309. };
  5310. s.prototype.updateWheelTransform = function(t) {
  5311. var e = a, i = l, n = h, r = this.wheelInfos[t];
  5312. this.updateWheelTransformWorld(r);
  5313. r.directionLocal.scale(-1, e);
  5314. i.copy(r.axleLocal);
  5315. e.cross(i, n);
  5316. n.normalize();
  5317. i.normalize();
  5318. var s = r.steering, c = new o();
  5319. c.setFromAxisAngle(e, s);
  5320. var u = new o();
  5321. u.setFromAxisAngle(i, r.rotation);
  5322. var p = r.worldTransform.quaternion;
  5323. this.chassisBody.quaternion.mult(c, p);
  5324. p.mult(u, p);
  5325. p.normalize();
  5326. var d = r.worldTransform.position;
  5327. d.copy(r.directionWorld);
  5328. d.scale(r.suspensionLength, d);
  5329. d.vadd(r.chassisConnectionPointWorld, d);
  5330. };
  5331. var p = [ new i(1, 0, 0), new i(0, 1, 0), new i(0, 0, 1) ];
  5332. s.prototype.getWheelTransformWorld = function(t) {
  5333. return this.wheelInfos[t].worldTransform;
  5334. };
  5335. var d = new i(), y = [], f = [];
  5336. s.prototype.updateFriction = function(t) {
  5337. for (var e = d, o = this.wheelInfos, n = o.length, r = this.chassisBody, s = f, a = y, l = 0; l < n; l++) {
  5338. v = (M = o[l]).raycastResult.body;
  5339. M.sideImpulse = 0;
  5340. M.forwardImpulse = 0;
  5341. s[l] || (s[l] = new i());
  5342. a[l] || (a[l] = new i());
  5343. }
  5344. for (l = 0; l < n; l++) if (v = (M = o[l]).raycastResult.body) {
  5345. var h = a[l];
  5346. this.getWheelTransformWorld(l).vectorToWorldFrame(p[this.indexRightAxis], h);
  5347. var c = M.raycastResult.hitNormalWorld, u = h.dot(c);
  5348. c.scale(u, e);
  5349. h.vsub(e, h);
  5350. h.normalize();
  5351. c.cross(h, s[l]);
  5352. s[l].normalize();
  5353. M.sideImpulse = A(r, M.raycastResult.hitPointWorld, v, M.raycastResult.hitPointWorld, h);
  5354. M.sideImpulse *= 1;
  5355. }
  5356. this.sliding = !1;
  5357. for (l = 0; l < n; l++) {
  5358. var v = (M = o[l]).raycastResult.body, m = 0;
  5359. M.slipInfo = 1;
  5360. if (v) {
  5361. var g = M.brake ? M.brake : 0;
  5362. m = b(r, v, M.raycastResult.hitPointWorld, s[l], g);
  5363. var w = g / (m += M.engineForce * t);
  5364. M.slipInfo *= w;
  5365. }
  5366. M.forwardImpulse = 0;
  5367. M.skidInfo = 1;
  5368. if (v) {
  5369. M.skidInfo = 1;
  5370. var x = M.suspensionForce * t * M.frictionSlip, _ = x * x;
  5371. M.forwardImpulse = m;
  5372. var B = .5 * M.forwardImpulse, S = 1 * M.sideImpulse, E = B * B + S * S;
  5373. M.sliding = !1;
  5374. if (E > _) {
  5375. this.sliding = !0;
  5376. M.sliding = !0;
  5377. w = x / Math.sqrt(E);
  5378. M.skidInfo *= w;
  5379. }
  5380. }
  5381. }
  5382. if (this.sliding) for (l = 0; l < n; l++) if (0 !== (M = o[l]).sideImpulse && M.skidInfo < 1) {
  5383. M.forwardImpulse *= M.skidInfo;
  5384. M.sideImpulse *= M.skidInfo;
  5385. }
  5386. for (l = 0; l < n; l++) {
  5387. var M = o[l], C = new i();
  5388. M.raycastResult.hitPointWorld.vsub(r.position, C);
  5389. if (0 !== M.forwardImpulse) {
  5390. var z = new i();
  5391. s[l].scale(M.forwardImpulse, z);
  5392. r.applyImpulse(z, C);
  5393. }
  5394. if (0 !== M.sideImpulse) {
  5395. v = M.raycastResult.body;
  5396. var F = new i();
  5397. M.raycastResult.hitPointWorld.vsub(v.position, F);
  5398. var R = new i();
  5399. a[l].scale(M.sideImpulse, R);
  5400. r.vectorToLocalFrame(C, C);
  5401. C["xyz"[this.indexUpAxis]] *= M.rollInfluence;
  5402. r.vectorToWorldFrame(C, C);
  5403. r.applyImpulse(R, C);
  5404. R.scale(-1, R);
  5405. v.applyImpulse(R, F);
  5406. }
  5407. }
  5408. };
  5409. var v = new i(), m = new i(), g = new i();
  5410. function b(t, e, i, o, n) {
  5411. var r = 0, s = i, a = v, l = m, h = g;
  5412. t.getVelocityAtWorldPoint(s, a);
  5413. e.getVelocityAtWorldPoint(s, l);
  5414. a.vsub(l, h);
  5415. n < (r = -o.dot(h) * (1 / (S(t, i, o) + S(e, i, o)))) && (r = n);
  5416. r < -n && (r = -n);
  5417. return r;
  5418. }
  5419. var w = new i(), x = new i(), _ = new i(), B = new i();
  5420. function S(t, e, i) {
  5421. var o = w, n = x, r = _, s = B;
  5422. e.vsub(t.position, o);
  5423. o.cross(i, n);
  5424. t.invInertiaWorld.vmult(n, s);
  5425. s.cross(o, r);
  5426. return t.invMass + i.dot(r);
  5427. }
  5428. var E = new i(), M = new i(), C = new i();
  5429. function A(t, e, i, o, n) {
  5430. if (n.norm2() > 1.1) return 0;
  5431. var r = E, s = M, a = C;
  5432. t.getVelocityAtWorldPoint(e, r);
  5433. i.getVelocityAtWorldPoint(o, s);
  5434. r.vsub(s, a);
  5435. return -.2 * n.dot(a) * (1 / (t.invMass + i.invMass));
  5436. }
  5437. }, {
  5438. "../collision/Ray": 10,
  5439. "../collision/RaycastResult": 11,
  5440. "../math/Quaternion": 30,
  5441. "../math/Vec3": 32,
  5442. "../objects/WheelInfo": 38,
  5443. "./Body": 33
  5444. } ],
  5445. 35: [ function(t, e) {
  5446. var i = t("./Body"), o = t("../shapes/Sphere"), n = t("../shapes/Box"), r = t("../math/Vec3"), s = t("../constraints/HingeConstraint"), a = t("../math/CMath");
  5447. e.exports = l;
  5448. function l(t) {
  5449. this.wheelBodies = [];
  5450. this.coordinateSystem = "undefined" == typeof t.coordinateSystem ? new r(1, 2, 3) : t.coordinateSystem.clone();
  5451. this.chassisBody = t.chassisBody;
  5452. if (!this.chassisBody) {
  5453. var e = new n(new r(5, 2, .5));
  5454. this.chassisBody = new i(1, e);
  5455. }
  5456. this.constraints = [];
  5457. this.wheelAxes = [];
  5458. this.wheelForces = [];
  5459. }
  5460. l.prototype.addWheel = function(t) {
  5461. var e = (t = t || {}).body;
  5462. e || (e = new i(1, new o(1.2)));
  5463. this.wheelBodies.push(e);
  5464. this.wheelForces.push(0);
  5465. new r();
  5466. var n = "undefined" != typeof t.position ? t.position.clone() : new r(), a = new r();
  5467. this.chassisBody.pointToWorldFrame(n, a);
  5468. e.position.set(a.x, a.y, a.z);
  5469. var l = "undefined" != typeof t.axis ? t.axis.clone() : new r(0, 1, 0);
  5470. this.wheelAxes.push(l);
  5471. var h = new s(this.chassisBody, e, {
  5472. pivotA: n,
  5473. axisA: l,
  5474. pivotB: r.ZERO,
  5475. axisB: l,
  5476. collideConnected: !1
  5477. });
  5478. this.constraints.push(h);
  5479. return this.wheelBodies.length - 1;
  5480. };
  5481. l.prototype.setSteeringValue = function(t, e) {
  5482. var i = this.wheelAxes[e], o = a.cos(t), n = a.sin(t), r = i.x, s = i.y;
  5483. this.constraints[e].axisA.set(o * r - n * s, n * r + o * s, 0);
  5484. };
  5485. l.prototype.setMotorSpeed = function(t, e) {
  5486. var i = this.constraints[e];
  5487. i.enableMotor();
  5488. i.motorTargetVelocity = t;
  5489. };
  5490. l.prototype.disableMotor = function(t) {
  5491. this.constraints[t].disableMotor();
  5492. };
  5493. var h = new r();
  5494. l.prototype.setWheelForce = function(t, e) {
  5495. this.wheelForces[e] = t;
  5496. };
  5497. l.prototype.applyWheelForce = function(t, e) {
  5498. var i = this.wheelAxes[e], o = this.wheelBodies[e], n = o.torque;
  5499. i.scale(t, h);
  5500. o.vectorToWorldFrame(h, h);
  5501. n.vadd(h, n);
  5502. };
  5503. l.prototype.addToWorld = function(t) {
  5504. for (var e = this.constraints, i = this.wheelBodies.concat([ this.chassisBody ]), o = 0; o < i.length; o++) t.addBody(i[o]);
  5505. for (o = 0; o < e.length; o++) t.addConstraint(e[o]);
  5506. t.addEventListener("preStep", this._update.bind(this));
  5507. };
  5508. l.prototype._update = function() {
  5509. for (var t = this.wheelForces, e = 0; e < t.length; e++) this.applyWheelForce(t[e], e);
  5510. };
  5511. l.prototype.removeFromWorld = function(t) {
  5512. for (var e = this.constraints, i = this.wheelBodies.concat([ this.chassisBody ]), o = 0; o < i.length; o++) t.remove(i[o]);
  5513. for (o = 0; o < e.length; o++) t.removeConstraint(e[o]);
  5514. };
  5515. var c = new r();
  5516. l.prototype.getWheelSpeed = function(t) {
  5517. var e = this.wheelAxes[t], i = this.wheelBodies[t].angularVelocity;
  5518. this.chassisBody.vectorToWorldFrame(e, c);
  5519. return i.dot(c);
  5520. };
  5521. }, {
  5522. "../constraints/HingeConstraint": 16,
  5523. "../math/CMath": 27,
  5524. "../math/Vec3": 32,
  5525. "../shapes/Box": 39,
  5526. "../shapes/Sphere": 46,
  5527. "./Body": 33
  5528. } ],
  5529. 36: [ function(t, e) {
  5530. e.exports = o;
  5531. t("../shapes/Shape");
  5532. var i = t("../math/Vec3");
  5533. t("../math/Quaternion"), t("../shapes/Particle"), t("../objects/Body"), t("../material/Material");
  5534. function o() {
  5535. this.particles = [];
  5536. this.density = 1;
  5537. this.smoothingRadius = 1;
  5538. this.speedOfSound = 1;
  5539. this.viscosity = .01;
  5540. this.eps = 1e-6;
  5541. this.pressures = [];
  5542. this.densities = [];
  5543. this.neighbors = [];
  5544. }
  5545. o.prototype.add = function(t) {
  5546. this.particles.push(t);
  5547. this.neighbors.length < this.particles.length && this.neighbors.push([]);
  5548. };
  5549. o.prototype.remove = function(t) {
  5550. var e = this.particles.indexOf(t);
  5551. if (-1 !== e) {
  5552. this.particles.splice(e, 1);
  5553. this.neighbors.length > this.particles.length && this.neighbors.pop();
  5554. }
  5555. };
  5556. var n = new i();
  5557. o.prototype.getNeighbors = function(t, e) {
  5558. for (var i = this.particles.length, o = t.id, r = this.smoothingRadius * this.smoothingRadius, s = n, a = 0; a !== i; a++) {
  5559. var l = this.particles[a];
  5560. l.position.vsub(t.position, s);
  5561. o !== l.id && s.norm2() < r && e.push(l);
  5562. }
  5563. };
  5564. var r = new i(), s = new i(), a = new i(), l = new i(), h = new i(), c = new i();
  5565. o.prototype.update = function() {
  5566. for (var t = this.particles.length, e = r, i = this.speedOfSound, o = this.eps, n = 0; n !== t; n++) {
  5567. var u = this.particles[n];
  5568. (S = this.neighbors[n]).length = 0;
  5569. this.getNeighbors(u, S);
  5570. S.push(this.particles[n]);
  5571. for (var p = S.length, d = 0, y = 0; y !== p; y++) {
  5572. u.position.vsub(S[y].position, e);
  5573. var f = e.norm(), v = this.w(f);
  5574. d += S[y].mass * v;
  5575. }
  5576. this.densities[n] = d;
  5577. this.pressures[n] = i * i * (this.densities[n] - this.density);
  5578. }
  5579. var m = s, g = a, b = l, w = h, x = c;
  5580. for (n = 0; n !== t; n++) {
  5581. var _, B, S, E = this.particles[n];
  5582. m.set(0, 0, 0);
  5583. g.set(0, 0, 0);
  5584. for (p = (S = this.neighbors[n]).length, y = 0; y !== p; y++) {
  5585. var M = S[y];
  5586. E.position.vsub(M.position, w);
  5587. var C = w.norm();
  5588. _ = -M.mass * (this.pressures[n] / (this.densities[n] * this.densities[n] + o) + this.pressures[y] / (this.densities[y] * this.densities[y] + o));
  5589. this.gradw(w, b);
  5590. b.mult(_, b);
  5591. m.vadd(b, m);
  5592. M.velocity.vsub(E.velocity, x);
  5593. x.mult(1 / (1e-4 + this.densities[n] * this.densities[y]) * this.viscosity * M.mass, x);
  5594. B = this.nablaw(C);
  5595. x.mult(B, x);
  5596. g.vadd(x, g);
  5597. }
  5598. g.mult(E.mass, g);
  5599. m.mult(E.mass, m);
  5600. E.force.vadd(g, E.force);
  5601. E.force.vadd(m, E.force);
  5602. }
  5603. };
  5604. o.prototype.w = function(t) {
  5605. var e = this.smoothingRadius;
  5606. return 315 / (64 * Math.PI * Math.pow(e, 9)) * Math.pow(e * e - t * t, 3);
  5607. };
  5608. o.prototype.gradw = function(t, e) {
  5609. var i = t.norm(), o = this.smoothingRadius;
  5610. t.mult(945 / (32 * Math.PI * Math.pow(o, 9)) * Math.pow(o * o - i * i, 2), e);
  5611. };
  5612. o.prototype.nablaw = function(t) {
  5613. var e = this.smoothingRadius;
  5614. return 945 / (32 * Math.PI * Math.pow(e, 9)) * (e * e - t * t) * (7 * t * t - 3 * e * e);
  5615. };
  5616. }, {
  5617. "../material/Material": 26,
  5618. "../math/Quaternion": 30,
  5619. "../math/Vec3": 32,
  5620. "../objects/Body": 33,
  5621. "../shapes/Particle": 43,
  5622. "../shapes/Shape": 45
  5623. } ],
  5624. 37: [ function(t, e) {
  5625. var i = t("../math/Vec3");
  5626. e.exports = o;
  5627. function o(t, e, o) {
  5628. o = o || {};
  5629. this.restLength = "number" == typeof o.restLength ? o.restLength : 1;
  5630. this.stiffness = o.stiffness || 100;
  5631. this.damping = o.damping || 1;
  5632. this.bodyA = t;
  5633. this.bodyB = e;
  5634. this.localAnchorA = new i();
  5635. this.localAnchorB = new i();
  5636. o.localAnchorA && this.localAnchorA.copy(o.localAnchorA);
  5637. o.localAnchorB && this.localAnchorB.copy(o.localAnchorB);
  5638. o.worldAnchorA && this.setWorldAnchorA(o.worldAnchorA);
  5639. o.worldAnchorB && this.setWorldAnchorB(o.worldAnchorB);
  5640. }
  5641. o.prototype.setWorldAnchorA = function(t) {
  5642. this.bodyA.pointToLocalFrame(t, this.localAnchorA);
  5643. };
  5644. o.prototype.setWorldAnchorB = function(t) {
  5645. this.bodyB.pointToLocalFrame(t, this.localAnchorB);
  5646. };
  5647. o.prototype.getWorldAnchorA = function(t) {
  5648. this.bodyA.pointToWorldFrame(this.localAnchorA, t);
  5649. };
  5650. o.prototype.getWorldAnchorB = function(t) {
  5651. this.bodyB.pointToWorldFrame(this.localAnchorB, t);
  5652. };
  5653. 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();
  5654. o.prototype.applyForce = function() {
  5655. 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;
  5656. this.getWorldAnchorA(x);
  5657. this.getWorldAnchorB(_);
  5658. x.vsub(o.position, B);
  5659. _.vsub(f.position, S);
  5660. _.vsub(x, v);
  5661. var C = v.norm();
  5662. m.copy(v);
  5663. m.normalize();
  5664. f.velocity.vsub(o.velocity, g);
  5665. f.angularVelocity.cross(S, w);
  5666. g.vadd(w, g);
  5667. o.angularVelocity.cross(B, w);
  5668. g.vsub(w, g);
  5669. m.mult(-t * (C - i) - e * g.dot(m), b);
  5670. o.force.vsub(b, o.force);
  5671. f.force.vadd(b, f.force);
  5672. B.cross(b, E);
  5673. S.cross(b, M);
  5674. o.torque.vsub(E, o.torque);
  5675. f.torque.vadd(M, f.torque);
  5676. };
  5677. }, {
  5678. "../math/Vec3": 32
  5679. } ],
  5680. 38: [ function(t, e) {
  5681. var i = t("../math/Vec3"), o = t("../math/Transform"), n = t("../collision/RaycastResult"), r = t("../utils/Utils");
  5682. e.exports = s;
  5683. function s(t) {
  5684. t = r.defaults(t, {
  5685. chassisConnectionPointLocal: new i(),
  5686. chassisConnectionPointWorld: new i(),
  5687. directionLocal: new i(),
  5688. directionWorld: new i(),
  5689. axleLocal: new i(),
  5690. axleWorld: new i(),
  5691. suspensionRestLength: 1,
  5692. suspensionMaxLength: 2,
  5693. radius: 1,
  5694. suspensionStiffness: 100,
  5695. dampingCompression: 10,
  5696. dampingRelaxation: 10,
  5697. frictionSlip: 1e4,
  5698. steering: 0,
  5699. rotation: 0,
  5700. deltaRotation: 0,
  5701. rollInfluence: .01,
  5702. maxSuspensionForce: Number.MAX_VALUE,
  5703. isFrontWheel: !0,
  5704. clippedInvContactDotSuspension: 1,
  5705. suspensionRelativeVelocity: 0,
  5706. suspensionForce: 0,
  5707. skidInfo: 0,
  5708. suspensionLength: 0,
  5709. maxSuspensionTravel: 1,
  5710. useCustomSlidingRotationalSpeed: !1,
  5711. customSlidingRotationalSpeed: -.1
  5712. });
  5713. this.maxSuspensionTravel = t.maxSuspensionTravel;
  5714. this.customSlidingRotationalSpeed = t.customSlidingRotationalSpeed;
  5715. this.useCustomSlidingRotationalSpeed = t.useCustomSlidingRotationalSpeed;
  5716. this.sliding = !1;
  5717. this.chassisConnectionPointLocal = t.chassisConnectionPointLocal.clone();
  5718. this.chassisConnectionPointWorld = t.chassisConnectionPointWorld.clone();
  5719. this.directionLocal = t.directionLocal.clone();
  5720. this.directionWorld = t.directionWorld.clone();
  5721. this.axleLocal = t.axleLocal.clone();
  5722. this.axleWorld = t.axleWorld.clone();
  5723. this.suspensionRestLength = t.suspensionRestLength;
  5724. this.suspensionMaxLength = t.suspensionMaxLength;
  5725. this.radius = t.radius;
  5726. this.suspensionStiffness = t.suspensionStiffness;
  5727. this.dampingCompression = t.dampingCompression;
  5728. this.dampingRelaxation = t.dampingRelaxation;
  5729. this.frictionSlip = t.frictionSlip;
  5730. this.steering = 0;
  5731. this.rotation = 0;
  5732. this.deltaRotation = 0;
  5733. this.rollInfluence = t.rollInfluence;
  5734. this.maxSuspensionForce = t.maxSuspensionForce;
  5735. this.engineForce = 0;
  5736. this.brake = 0;
  5737. this.isFrontWheel = t.isFrontWheel;
  5738. this.clippedInvContactDotSuspension = 1;
  5739. this.suspensionRelativeVelocity = 0;
  5740. this.suspensionForce = 0;
  5741. this.skidInfo = 0;
  5742. this.suspensionLength = 0;
  5743. this.sideImpulse = 0;
  5744. this.forwardImpulse = 0;
  5745. this.raycastResult = new n();
  5746. this.worldTransform = new o();
  5747. this.isInContact = !1;
  5748. }
  5749. var a = new i(), l = new i();
  5750. a = new i();
  5751. s.prototype.updateWheel = function(t) {
  5752. var e = this.raycastResult;
  5753. if (this.isInContact) {
  5754. var i = e.hitNormalWorld.dot(e.directionWorld);
  5755. e.hitPointWorld.vsub(t.position, l);
  5756. t.getVelocityAtWorldPoint(l, a);
  5757. var o = e.hitNormalWorld.dot(a);
  5758. if (i >= -.1) {
  5759. this.suspensionRelativeVelocity = 0;
  5760. this.clippedInvContactDotSuspension = 10;
  5761. } else {
  5762. var n = -1 / i;
  5763. this.suspensionRelativeVelocity = o * n;
  5764. this.clippedInvContactDotSuspension = n;
  5765. }
  5766. } else {
  5767. e.suspensionLength = this.suspensionRestLength;
  5768. this.suspensionRelativeVelocity = 0;
  5769. e.directionWorld.scale(-1, e.hitNormalWorld);
  5770. this.clippedInvContactDotSuspension = 1;
  5771. }
  5772. };
  5773. }, {
  5774. "../collision/RaycastResult": 11,
  5775. "../math/Transform": 31,
  5776. "../math/Vec3": 32,
  5777. "../utils/Utils": 55
  5778. } ],
  5779. 39: [ function(t, e) {
  5780. e.exports = r;
  5781. var i = t("./Shape"), o = t("../math/Vec3"), n = t("./ConvexPolyhedron");
  5782. function r(t) {
  5783. i.call(this, {
  5784. type: i.types.BOX
  5785. });
  5786. this.halfExtents = t;
  5787. this.convexPolyhedronRepresentation = null;
  5788. this.updateConvexPolyhedronRepresentation();
  5789. this.updateBoundingSphereRadius();
  5790. }
  5791. r.prototype = new i();
  5792. r.prototype.constructor = r;
  5793. r.prototype.updateConvexPolyhedronRepresentation = function() {
  5794. 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),
  5795. 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 ] ]));
  5796. this.convexPolyhedronRepresentation = a;
  5797. a.material = this.material;
  5798. };
  5799. r.prototype.calculateLocalInertia = function(t, e) {
  5800. e = e || new o();
  5801. r.calculateInertia(this.halfExtents, t, e);
  5802. return e;
  5803. };
  5804. r.calculateInertia = function(t, e, i) {
  5805. var o = t;
  5806. if (o.isZero()) {
  5807. i.x = 2 / 12 * e;
  5808. i.y = 2 / 12 * e;
  5809. i.z = 2 / 12 * e;
  5810. } else {
  5811. i.x = 1 / 12 * e * (4 * o.y * o.y + 4 * o.z * o.z);
  5812. i.y = 1 / 12 * e * (4 * o.x * o.x + 4 * o.z * o.z);
  5813. i.z = 1 / 12 * e * (4 * o.y * o.y + 4 * o.x * o.x);
  5814. }
  5815. };
  5816. r.prototype.getSideNormals = function(t, e) {
  5817. var i = t, o = this.halfExtents;
  5818. i[0].set(o.x, 0, 0);
  5819. i[1].set(0, o.y, 0);
  5820. i[2].set(0, 0, o.z);
  5821. i[3].set(-o.x, 0, 0);
  5822. i[4].set(0, -o.y, 0);
  5823. i[5].set(0, 0, -o.z);
  5824. if (void 0 !== e) for (var n = 0; n !== i.length; n++) e.vmult(i[n], i[n]);
  5825. return i;
  5826. };
  5827. r.prototype.volume = function() {
  5828. return 8 * this.halfExtents.x * this.halfExtents.y * this.halfExtents.z;
  5829. };
  5830. r.prototype.updateBoundingSphereRadius = function() {
  5831. this.boundingSphereRadius = this.halfExtents.norm();
  5832. };
  5833. var s = new o();
  5834. new o();
  5835. r.prototype.forEachWorldCorner = function(t, e, i) {
  5836. 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++) {
  5837. s.set(n[r][0], n[r][1], n[r][2]);
  5838. e.vmult(s, s);
  5839. t.vadd(s, s);
  5840. i(s.x, s.y, s.z);
  5841. }
  5842. };
  5843. var a = [ new o(), new o(), new o(), new o(), new o(), new o(), new o(), new o() ];
  5844. r.prototype.calculateWorldAABB = function(t, e, i, o) {
  5845. var n = this.halfExtents;
  5846. a[0].set(n.x, n.y, n.z);
  5847. a[1].set(-n.x, n.y, n.z);
  5848. a[2].set(-n.x, -n.y, n.z);
  5849. a[3].set(-n.x, -n.y, -n.z);
  5850. a[4].set(n.x, -n.y, -n.z);
  5851. a[5].set(n.x, n.y, -n.z);
  5852. a[6].set(-n.x, n.y, -n.z);
  5853. a[7].set(n.x, -n.y, n.z);
  5854. var r = a[0];
  5855. e.vmult(r, r);
  5856. t.vadd(r, r);
  5857. o.copy(r);
  5858. i.copy(r);
  5859. for (var s = 1; s < 8; s++) {
  5860. r = a[s];
  5861. e.vmult(r, r);
  5862. t.vadd(r, r);
  5863. var l = r.x, h = r.y, c = r.z;
  5864. l > o.x && (o.x = l);
  5865. h > o.y && (o.y = h);
  5866. c > o.z && (o.z = c);
  5867. l < i.x && (i.x = l);
  5868. h < i.y && (i.y = h);
  5869. c < i.z && (i.z = c);
  5870. }
  5871. };
  5872. }, {
  5873. "../math/Vec3": 32,
  5874. "./ConvexPolyhedron": 40,
  5875. "./Shape": 45
  5876. } ],
  5877. 40: [ function(t, e) {
  5878. e.exports = r;
  5879. var i = t("./Shape"), o = t("../math/Vec3"), n = (t("../math/Quaternion"), t("../math/Transform"));
  5880. function r(t, e, o) {
  5881. i.call(this, {
  5882. type: i.types.CONVEXPOLYHEDRON
  5883. });
  5884. this.vertices = t || [];
  5885. this.worldVertices = [];
  5886. this.worldVerticesNeedsUpdate = !0;
  5887. this.faces = e || [];
  5888. this.faceNormals = [];
  5889. this.computeNormals();
  5890. this.worldFaceNormalsNeedsUpdate = !0;
  5891. this.worldFaceNormals = [];
  5892. this.uniqueEdges = [];
  5893. this.uniqueAxes = o ? o.slice() : null;
  5894. this.computeEdges();
  5895. this.updateBoundingSphereRadius();
  5896. }
  5897. r.prototype = new i();
  5898. r.prototype.constructor = r;
  5899. var s = new o();
  5900. r.prototype.computeEdges = function() {
  5901. var t = this.faces, e = this.vertices, i = (e.length, this.uniqueEdges);
  5902. i.length = 0;
  5903. for (var o = s, n = 0; n !== t.length; n++) for (var r = t[n], a = r.length, l = 0; l !== a; l++) {
  5904. var h = (l + 1) % a;
  5905. e[r[l]].vsub(e[r[h]], o);
  5906. o.normalize();
  5907. for (var c = !1, u = 0; u !== i.length; u++) if (i[u].almostEquals(o) || i[u].almostEquals(o)) {
  5908. c = !0;
  5909. break;
  5910. }
  5911. c || i.push(o.clone());
  5912. }
  5913. };
  5914. r.prototype.computeNormals = function() {
  5915. this.faceNormals.length = this.faces.length;
  5916. for (var t = 0; t < this.faces.length; t++) {
  5917. 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!");
  5918. var i = this.faceNormals[t] || new o();
  5919. this.getFaceNormal(t, i);
  5920. i.negate(i);
  5921. this.faceNormals[t] = i;
  5922. var n = this.vertices[this.faces[t][0]];
  5923. if (i.dot(n) < 0) {
  5924. 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.");
  5925. for (e = 0; e < this.faces[t].length; e++) console.warn(".vertices[" + this.faces[t][e] + "] = Vec3(" + this.vertices[this.faces[t][e]].toString() + ")");
  5926. }
  5927. }
  5928. };
  5929. var a = new o(), l = new o();
  5930. r.computeNormal = function(t, e, i, o) {
  5931. e.vsub(t, l);
  5932. i.vsub(e, a);
  5933. a.cross(l, o);
  5934. o.isZero() || o.normalize();
  5935. };
  5936. r.prototype.getFaceNormal = function(t, e) {
  5937. var i = this.faces[t], o = this.vertices[i[0]], n = this.vertices[i[1]], s = this.vertices[i[2]];
  5938. return r.computeNormal(o, n, s, e);
  5939. };
  5940. var h = new o();
  5941. r.prototype.clipAgainstHull = function(t, e, i, n, r, s, a, l, c) {
  5942. for (var u = h, p = -1, d = -Number.MAX_VALUE, y = 0; y < i.faces.length; y++) {
  5943. u.copy(i.faceNormals[y]);
  5944. r.vmult(u, u);
  5945. var f = u.dot(s);
  5946. if (f > d) {
  5947. d = f;
  5948. p = y;
  5949. }
  5950. }
  5951. for (var v = [], m = i.faces[p], g = m.length, b = 0; b < g; b++) {
  5952. var w = i.vertices[m[b]], x = new o();
  5953. x.copy(w);
  5954. r.vmult(x, x);
  5955. n.vadd(x, x);
  5956. v.push(x);
  5957. }
  5958. p >= 0 && this.clipFaceAgainstHull(s, t, e, v, a, l, c);
  5959. };
  5960. var c = new o(), u = new o(), p = new o(), d = new o(), y = new o(), f = new o();
  5961. r.prototype.findSeparatingAxis = function(t, e, i, o, n, r, s, a) {
  5962. var l = c, h = u, v = p, m = d, g = y, b = f, w = Number.MAX_VALUE;
  5963. if (this.uniqueAxes) for (_ = 0; _ !== this.uniqueAxes.length; _++) {
  5964. i.vmult(this.uniqueAxes[_], l);
  5965. if (!1 === (E = this.testSepAxis(l, t, e, i, o, n))) return !1;
  5966. if (E < w) {
  5967. w = E;
  5968. r.copy(l);
  5969. }
  5970. } else for (var x = s ? s.length : this.faces.length, _ = 0; _ < x; _++) {
  5971. var B = s ? s[_] : _;
  5972. l.copy(this.faceNormals[B]);
  5973. i.vmult(l, l);
  5974. if (!1 === (E = this.testSepAxis(l, t, e, i, o, n))) return !1;
  5975. if (E < w) {
  5976. w = E;
  5977. r.copy(l);
  5978. }
  5979. }
  5980. if (t.uniqueAxes) for (_ = 0; _ !== t.uniqueAxes.length; _++) {
  5981. n.vmult(t.uniqueAxes[_], h);
  5982. if (!1 === (E = this.testSepAxis(h, t, e, i, o, n))) return !1;
  5983. if (E < w) {
  5984. w = E;
  5985. r.copy(h);
  5986. }
  5987. } else {
  5988. var S = a ? a.length : t.faces.length;
  5989. for (_ = 0; _ < S; _++) {
  5990. var E;
  5991. B = a ? a[_] : _;
  5992. h.copy(t.faceNormals[B]);
  5993. n.vmult(h, h);
  5994. if (!1 === (E = this.testSepAxis(h, t, e, i, o, n))) return !1;
  5995. if (E < w) {
  5996. w = E;
  5997. r.copy(h);
  5998. }
  5999. }
  6000. }
  6001. for (var M = 0; M !== this.uniqueEdges.length; M++) {
  6002. i.vmult(this.uniqueEdges[M], m);
  6003. for (var C = 0; C !== t.uniqueEdges.length; C++) {
  6004. n.vmult(t.uniqueEdges[C], g);
  6005. m.cross(g, b);
  6006. if (!b.almostZero()) {
  6007. b.normalize();
  6008. var A = this.testSepAxis(b, t, e, i, o, n);
  6009. if (!1 === A) return !1;
  6010. if (A < w) {
  6011. w = A;
  6012. r.copy(b);
  6013. }
  6014. }
  6015. }
  6016. }
  6017. o.vsub(e, v);
  6018. v.dot(r) > 0 && r.negate(r);
  6019. return !0;
  6020. };
  6021. var v = [], m = [];
  6022. r.prototype.testSepAxis = function(t, e, i, o, n, s) {
  6023. r.project(this, t, i, o, v);
  6024. r.project(e, t, n, s, m);
  6025. var a = v[0], l = v[1], h = m[0], c = m[1];
  6026. if (a < c || h < l) return !1;
  6027. var u = a - c, p = h - l;
  6028. return u < p ? u : p;
  6029. };
  6030. var g = new o(), b = new o();
  6031. r.prototype.calculateLocalInertia = function(t, e) {
  6032. this.computeLocalAABB(g, b);
  6033. var i = b.x - g.x, o = b.y - g.y, n = b.z - g.z;
  6034. e.x = 1 / 12 * t * (4 * o * o + 4 * n * n);
  6035. e.y = 1 / 12 * t * (4 * i * i + 4 * n * n);
  6036. e.z = 1 / 12 * t * (4 * o * o + 4 * i * i);
  6037. };
  6038. r.prototype.getPlaneConstantOfFace = function(t) {
  6039. var e = this.faces[t], i = this.faceNormals[t], o = this.vertices[e[0]];
  6040. return -i.dot(o);
  6041. };
  6042. var w = new o(), x = new o(), _ = new o(), B = new o(), S = new o(), E = new o(), M = new o(), C = new o();
  6043. r.prototype.clipFaceAgainstHull = function(t, e, i, o, n, r, s) {
  6044. 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++) {
  6045. a.copy(this.faceNormals[b]);
  6046. i.vmult(a, a);
  6047. var A = a.dot(t);
  6048. if (A < g) {
  6049. g = A;
  6050. m = b;
  6051. }
  6052. }
  6053. if (!(m < 0)) {
  6054. var z = this.faces[m];
  6055. z.connectedFaces = [];
  6056. 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);
  6057. f.length;
  6058. for (var T = z.length, P = 0; P < T; P++) {
  6059. var q = this.vertices[z[P]], I = this.vertices[z[(P + 1) % T]];
  6060. q.vsub(I, l);
  6061. h.copy(l);
  6062. i.vmult(h, h);
  6063. e.vadd(h, h);
  6064. c.copy(this.faceNormals[m]);
  6065. i.vmult(c, c);
  6066. e.vadd(c, c);
  6067. h.cross(c, u);
  6068. u.negate(u);
  6069. p.copy(q);
  6070. i.vmult(p, p);
  6071. e.vadd(p, p);
  6072. p.dot(u);
  6073. var O = z.connectedFaces[P];
  6074. d.copy(this.faceNormals[O]);
  6075. var V = this.getPlaneConstantOfFace(O);
  6076. y.copy(d);
  6077. i.vmult(y, y);
  6078. var j = V - y.dot(e);
  6079. this.clipFaceAgainstPlane(f, v, y, j);
  6080. for (;f.length; ) f.shift();
  6081. for (;v.length; ) f.push(v.shift());
  6082. }
  6083. d.copy(this.faceNormals[m]);
  6084. V = this.getPlaneConstantOfFace(m);
  6085. y.copy(d);
  6086. i.vmult(y, y);
  6087. for (j = V - y.dot(e), F = 0; F < f.length; F++) {
  6088. var k = y.dot(f[F]) + j;
  6089. k <= n && (k = n);
  6090. if (k <= r) {
  6091. var N = f[F];
  6092. if (k <= 0) {
  6093. var L = {
  6094. point: N,
  6095. normal: y,
  6096. depth: k
  6097. };
  6098. s.push(L);
  6099. }
  6100. }
  6101. }
  6102. }
  6103. };
  6104. r.prototype.clipFaceAgainstPlane = function(t, e, i, n) {
  6105. var r, s, a = t.length;
  6106. if (a < 2) return e;
  6107. var l = t[t.length - 1], h = t[0];
  6108. r = i.dot(l) + n;
  6109. for (var c = 0; c < a; c++) {
  6110. h = t[c];
  6111. s = i.dot(h) + n;
  6112. if (r < 0) if (s < 0) {
  6113. (u = new o()).copy(h);
  6114. e.push(u);
  6115. } else {
  6116. var u = new o();
  6117. l.lerp(h, r / (r - s), u);
  6118. e.push(u);
  6119. } else if (s < 0) {
  6120. u = new o();
  6121. l.lerp(h, r / (r - s), u);
  6122. e.push(u);
  6123. e.push(h);
  6124. }
  6125. l = h;
  6126. r = s;
  6127. }
  6128. return e;
  6129. };
  6130. r.prototype.computeWorldVertices = function(t, e) {
  6131. for (var i = this.vertices.length; this.worldVertices.length < i; ) this.worldVertices.push(new o());
  6132. for (var n = this.vertices, r = this.worldVertices, s = 0; s !== i; s++) {
  6133. e.vmult(n[s], r[s]);
  6134. t.vadd(r[s], r[s]);
  6135. }
  6136. this.worldVerticesNeedsUpdate = !1;
  6137. };
  6138. new o();
  6139. r.prototype.computeLocalAABB = function(t, e) {
  6140. var i = this.vertices.length, o = this.vertices;
  6141. t.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
  6142. e.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
  6143. for (var n = 0; n < i; n++) {
  6144. var r = o[n];
  6145. r.x < t.x ? t.x = r.x : r.x > e.x && (e.x = r.x);
  6146. r.y < t.y ? t.y = r.y : r.y > e.y && (e.y = r.y);
  6147. r.z < t.z ? t.z = r.z : r.z > e.z && (e.z = r.z);
  6148. }
  6149. };
  6150. r.prototype.computeWorldFaceNormals = function(t) {
  6151. for (var e = this.faceNormals.length; this.worldFaceNormals.length < e; ) this.worldFaceNormals.push(new o());
  6152. for (var i = this.faceNormals, n = this.worldFaceNormals, r = 0; r !== e; r++) t.vmult(i[r], n[r]);
  6153. this.worldFaceNormalsNeedsUpdate = !1;
  6154. };
  6155. r.prototype.updateBoundingSphereRadius = function() {
  6156. for (var t = 0, e = this.vertices, i = 0, o = e.length; i !== o; i++) {
  6157. var n = e[i].norm2();
  6158. n > t && (t = n);
  6159. }
  6160. this.boundingSphereRadius = Math.sqrt(t);
  6161. };
  6162. var A = new o();
  6163. r.prototype.calculateWorldAABB = function(t, e, i, o) {
  6164. for (var n, r, s, a, l, h, c = this.vertices.length, u = this.vertices, p = 0; p < c; p++) {
  6165. A.copy(u[p]);
  6166. e.vmult(A, A);
  6167. t.vadd(A, A);
  6168. var d = A;
  6169. (d.x < n || void 0 === n) && (n = d.x);
  6170. (d.x > a || void 0 === a) && (a = d.x);
  6171. (d.y < r || void 0 === r) && (r = d.y);
  6172. (d.y > l || void 0 === l) && (l = d.y);
  6173. (d.z < s || void 0 === s) && (s = d.z);
  6174. (d.z > h || void 0 === h) && (h = d.z);
  6175. }
  6176. i.set(n, r, s);
  6177. o.set(a, l, h);
  6178. };
  6179. r.prototype.volume = function() {
  6180. return 4 * Math.PI * this.boundingSphereRadius / 3;
  6181. };
  6182. r.prototype.getAveragePointLocal = function(t) {
  6183. t = t || new o();
  6184. for (var e = this.vertices.length, i = this.vertices, n = 0; n < e; n++) t.vadd(i[n], t);
  6185. t.mult(1 / e, t);
  6186. return t;
  6187. };
  6188. r.prototype.transformAllPoints = function(t, e) {
  6189. var i = this.vertices.length, o = this.vertices;
  6190. if (e) {
  6191. for (var n = 0; n < i; n++) {
  6192. var r = o[n];
  6193. e.vmult(r, r);
  6194. }
  6195. for (n = 0; n < this.faceNormals.length; n++) {
  6196. r = this.faceNormals[n];
  6197. e.vmult(r, r);
  6198. }
  6199. }
  6200. if (t) for (n = 0; n < i; n++) (r = o[n]).vadd(t, r);
  6201. };
  6202. var z = new o(), F = new o(), R = new o();
  6203. r.prototype.pointIsInside = function(t) {
  6204. var e = this.vertices.length, i = this.vertices, o = this.faces, n = this.faceNormals, r = this.faces.length, s = z;
  6205. this.getAveragePointLocal(s);
  6206. for (var a = 0; a < r; a++) {
  6207. this.faces[a].length, e = n[a];
  6208. var l = i[o[a][0]], h = F;
  6209. t.vsub(l, h);
  6210. var c = e.dot(h), u = R;
  6211. s.vsub(l, u);
  6212. var p = e.dot(u);
  6213. if (c < 0 && p > 0 || c > 0 && p < 0) return !1;
  6214. }
  6215. return -1;
  6216. };
  6217. new o();
  6218. var T = new o(), P = new o();
  6219. r.project = function(t, e, i, o, r) {
  6220. var s = t.vertices.length, a = T, l = 0, h = 0, c = P, u = t.vertices;
  6221. c.setZero();
  6222. n.vectorToLocalFrame(i, o, e, a);
  6223. n.pointToLocalFrame(i, o, c, c);
  6224. var p = c.dot(a);
  6225. h = l = u[0].dot(a);
  6226. for (var d = 1; d < s; d++) {
  6227. var y = u[d].dot(a);
  6228. y > l && (l = y);
  6229. y < h && (h = y);
  6230. }
  6231. if ((h -= p) > (l -= p)) {
  6232. var f = h;
  6233. h = l;
  6234. l = f;
  6235. }
  6236. r[0] = l;
  6237. r[1] = h;
  6238. };
  6239. }, {
  6240. "../math/Quaternion": 30,
  6241. "../math/Transform": 31,
  6242. "../math/Vec3": 32,
  6243. "./Shape": 45
  6244. } ],
  6245. 41: [ function(t, e) {
  6246. e.exports = r;
  6247. t("./Shape");
  6248. var i = t("../math/Vec3"), o = (t("../math/Quaternion"), t("./ConvexPolyhedron")), n = t("../math/CMath");
  6249. function r(t, e, r, s, a) {
  6250. if (a) {
  6251. 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++) {
  6252. p.push(new i(t * h(m * g), u, t * c(m * g)));
  6253. p.push(new i(t * h(m * g), -u, t * c(m * g)));
  6254. if (g < l - 1) {
  6255. d.push([ 2 * g + 2, 2 * g + 3, 2 * g + 1, 2 * g ]);
  6256. y.push(2 * g + 2);
  6257. f.push(2 * g + 3);
  6258. } else d.push([ 0, 1, 2 * g + 1, 2 * g ]);
  6259. (l % 2 == 1 || g < l / 2) && v.push(new i(h(m * (g + .5)), 0, c(m * (g + .5))));
  6260. }
  6261. d.push(f);
  6262. var b = [];
  6263. for (g = 0; g < y.length; g++) b.push(y[y.length - g - 1]);
  6264. d.push(b);
  6265. v.push(new i(0, 1, 0));
  6266. o.call(this, p, d, v);
  6267. } else {
  6268. l = s;
  6269. var w = [], x = (v = [], []), _ = [], B = [];
  6270. h = n.cos, c = n.sin;
  6271. w.push(new i(e * h(0), e * c(0), .5 * -r));
  6272. _.push(0);
  6273. w.push(new i(t * h(0), t * c(0), .5 * r));
  6274. B.push(1);
  6275. for (g = 0; g < l; g++) {
  6276. m = 2 * Math.PI / l * (g + 1);
  6277. var S = 2 * Math.PI / l * (g + .5);
  6278. if (g < l - 1) {
  6279. w.push(new i(e * h(m), e * c(m), .5 * -r));
  6280. _.push(2 * g + 2);
  6281. w.push(new i(t * h(m), t * c(m), .5 * r));
  6282. B.push(2 * g + 3);
  6283. x.push([ 2 * g + 2, 2 * g + 3, 2 * g + 1, 2 * g ]);
  6284. } else x.push([ 0, 1, 2 * g + 1, 2 * g ]);
  6285. (l % 2 == 1 || g < l / 2) && v.push(new i(h(S), c(S), 0));
  6286. }
  6287. x.push(B);
  6288. v.push(new i(0, 0, 1));
  6289. for (b = [], g = 0; g < _.length; g++) b.push(_[_.length - g - 1]);
  6290. x.push(b);
  6291. o.call(this, w, x, v);
  6292. }
  6293. }
  6294. r.prototype = new o();
  6295. }, {
  6296. "../math/CMath": 27,
  6297. "../math/Quaternion": 30,
  6298. "../math/Vec3": 32,
  6299. "./ConvexPolyhedron": 40,
  6300. "./Shape": 45
  6301. } ],
  6302. 42: [ function(t, e) {
  6303. var i = t("./Shape"), o = t("./ConvexPolyhedron"), n = t("../math/Vec3"), r = t("../utils/Utils");
  6304. e.exports = s;
  6305. function s(t, e) {
  6306. e = r.defaults(e, {
  6307. maxValue: null,
  6308. minValue: null,
  6309. elementSize: 1
  6310. });
  6311. this.data = t;
  6312. this.maxValue = e.maxValue;
  6313. this.minValue = e.minValue;
  6314. this.elementSize = e.elementSize;
  6315. null === e.minValue && this.updateMinValue();
  6316. null === e.maxValue && this.updateMaxValue();
  6317. this.cacheEnabled = !0;
  6318. i.call(this, {
  6319. type: i.types.HEIGHTFIELD
  6320. });
  6321. this.pillarConvex = new o();
  6322. this.pillarOffset = new n();
  6323. this.updateBoundingSphereRadius();
  6324. this._cachedPillars = {};
  6325. }
  6326. s.prototype = new i();
  6327. s.prototype.update = function() {
  6328. this._cachedPillars = {};
  6329. };
  6330. s.prototype.updateMinValue = function() {
  6331. for (var t = this.data, e = t[0][0], i = 0; i !== t.length; i++) for (var o = 0; o !== t[i].length; o++) {
  6332. var n = t[i][o];
  6333. n < e && (e = n);
  6334. }
  6335. this.minValue = e;
  6336. };
  6337. s.prototype.updateMaxValue = function() {
  6338. for (var t = this.data, e = t[0][0], i = 0; i !== t.length; i++) for (var o = 0; o !== t[i].length; o++) {
  6339. var n = t[i][o];
  6340. n > e && (e = n);
  6341. }
  6342. this.maxValue = e;
  6343. };
  6344. s.prototype.setHeightValueAtIndex = function(t, e, i) {
  6345. this.data[t][e] = i;
  6346. this.clearCachedConvexTrianglePillar(t, e, !1);
  6347. if (t > 0) {
  6348. this.clearCachedConvexTrianglePillar(t - 1, e, !0);
  6349. this.clearCachedConvexTrianglePillar(t - 1, e, !1);
  6350. }
  6351. if (e > 0) {
  6352. this.clearCachedConvexTrianglePillar(t, e - 1, !0);
  6353. this.clearCachedConvexTrianglePillar(t, e - 1, !1);
  6354. }
  6355. e > 0 && t > 0 && this.clearCachedConvexTrianglePillar(t - 1, e - 1, !0);
  6356. };
  6357. s.prototype.getRectMinMax = function(t, e, i, o, n) {
  6358. n = n || [];
  6359. for (var r = this.data, s = this.minValue, a = t; a <= i; a++) for (var l = e; l <= o; l++) {
  6360. var h = r[a][l];
  6361. h > s && (s = h);
  6362. }
  6363. n[0] = this.minValue;
  6364. n[1] = s;
  6365. };
  6366. s.prototype.getIndexOfPosition = function(t, e, i, o) {
  6367. var n = this.elementSize, r = this.data, s = Math.floor(t / n), a = Math.floor(e / n);
  6368. i[0] = s;
  6369. i[1] = a;
  6370. if (o) {
  6371. s < 0 && (s = 0);
  6372. a < 0 && (a = 0);
  6373. s >= r.length - 1 && (s = r.length - 1);
  6374. a >= r[0].length - 1 && (a = r[0].length - 1);
  6375. }
  6376. return !(s < 0 || a < 0 || s >= r.length - 1 || a >= r[0].length - 1);
  6377. };
  6378. var a = [], l = new n(), h = new n(), c = new n(), u = new n();
  6379. s.prototype.getTriangleAt = function(t, e, i, o, n, r) {
  6380. var s = a;
  6381. this.getIndexOfPosition(t, e, s, i);
  6382. var l = s[0], h = s[1], c = this.data;
  6383. if (i) {
  6384. l = Math.min(c.length - 2, Math.max(0, l));
  6385. h = Math.min(c[0].length - 2, Math.max(0, h));
  6386. }
  6387. 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);
  6388. this.getTriangle(l, h, p, o, n, r);
  6389. return p;
  6390. };
  6391. var p = new n(), d = new n(), y = new n(), f = new n(), v = new n();
  6392. s.prototype.getNormalAt = function(t, e, i, o) {
  6393. var n = p, r = d, s = y, a = f, l = v;
  6394. this.getTriangleAt(t, e, i, n, r, s);
  6395. r.vsub(n, a);
  6396. s.vsub(n, l);
  6397. a.cross(l, o);
  6398. o.normalize();
  6399. };
  6400. s.prototype.getAabbAtIndex = function(t, e, i) {
  6401. var o = this.data, n = this.elementSize;
  6402. i.lowerBound.set(t * n, e * n, o[t][e]);
  6403. i.upperBound.set((t + 1) * n, (e + 1) * n, o[t + 1][e + 1]);
  6404. };
  6405. s.prototype.getHeightAt = function(t, e, i) {
  6406. var o = this.data, n = h, r = c, s = u, p = a;
  6407. this.getIndexOfPosition(t, e, p, i);
  6408. var d = p[0], y = p[1];
  6409. if (i) {
  6410. d = Math.min(o.length - 2, Math.max(0, d));
  6411. y = Math.min(o[0].length - 2, Math.max(0, y));
  6412. }
  6413. var f = this.getTriangleAt(t, e, i, n, r, s);
  6414. m(t, e, n.x, n.y, r.x, r.y, s.x, s.y, l);
  6415. var v = l;
  6416. 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;
  6417. };
  6418. function m(t, e, i, o, n, r, s, a, l) {
  6419. l.x = ((r - a) * (t - s) + (s - n) * (e - a)) / ((r - a) * (i - s) + (s - n) * (o - a));
  6420. l.y = ((a - o) * (t - s) + (i - s) * (e - a)) / ((r - a) * (i - s) + (s - n) * (o - a));
  6421. l.z = 1 - l.x - l.y;
  6422. }
  6423. s.prototype.getCacheConvexTrianglePillarKey = function(t, e, i) {
  6424. return t + "_" + e + "_" + (i ? 1 : 0);
  6425. };
  6426. s.prototype.getCachedConvexTrianglePillar = function(t, e, i) {
  6427. return this._cachedPillars[this.getCacheConvexTrianglePillarKey(t, e, i)];
  6428. };
  6429. s.prototype.setCachedConvexTrianglePillar = function(t, e, i, o, n) {
  6430. this._cachedPillars[this.getCacheConvexTrianglePillarKey(t, e, i)] = {
  6431. convex: o,
  6432. offset: n
  6433. };
  6434. };
  6435. s.prototype.clearCachedConvexTrianglePillar = function(t, e, i) {
  6436. delete this._cachedPillars[this.getCacheConvexTrianglePillarKey(t, e, i)];
  6437. };
  6438. s.prototype.getTriangle = function(t, e, i, o, n, r) {
  6439. var s = this.data, a = this.elementSize;
  6440. if (i) {
  6441. o.set((t + 1) * a, (e + 1) * a, s[t + 1][e + 1]);
  6442. n.set(t * a, (e + 1) * a, s[t][e + 1]);
  6443. r.set((t + 1) * a, e * a, s[t + 1][e]);
  6444. } else {
  6445. o.set(t * a, e * a, s[t][e]);
  6446. n.set((t + 1) * a, e * a, s[t + 1][e]);
  6447. r.set(t * a, (e + 1) * a, s[t][e + 1]);
  6448. }
  6449. };
  6450. s.prototype.getConvexTrianglePillar = function(t, e, i) {
  6451. var r = this.pillarConvex, s = this.pillarOffset;
  6452. if (this.cacheEnabled) {
  6453. if (a = this.getCachedConvexTrianglePillar(t, e, i)) {
  6454. this.pillarConvex = a.convex;
  6455. this.pillarOffset = a.offset;
  6456. return;
  6457. }
  6458. r = new o();
  6459. s = new n();
  6460. this.pillarConvex = r;
  6461. this.pillarOffset = s;
  6462. }
  6463. var a = this.data, l = this.elementSize, h = r.faces;
  6464. r.vertices.length = 6;
  6465. for (var c = 0; c < 6; c++) r.vertices[c] || (r.vertices[c] = new n());
  6466. h.length = 5;
  6467. for (c = 0; c < 5; c++) h[c] || (h[c] = []);
  6468. 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;
  6469. if (i) {
  6470. s.set((t + .75) * l, (e + .75) * l, p);
  6471. u[0].set(.25 * l, .25 * l, a[t + 1][e + 1] - p);
  6472. u[1].set(-.75 * l, .25 * l, a[t][e + 1] - p);
  6473. u[2].set(.25 * l, -.75 * l, a[t + 1][e] - p);
  6474. u[3].set(.25 * l, .25 * l, -p - 1);
  6475. u[4].set(-.75 * l, .25 * l, -p - 1);
  6476. u[5].set(.25 * l, -.75 * l, -p - 1);
  6477. h[0][0] = 0;
  6478. h[0][1] = 1;
  6479. h[0][2] = 2;
  6480. h[1][0] = 5;
  6481. h[1][1] = 4;
  6482. h[1][2] = 3;
  6483. h[2][0] = 2;
  6484. h[2][1] = 5;
  6485. h[2][2] = 3;
  6486. h[2][3] = 0;
  6487. h[3][0] = 3;
  6488. h[3][1] = 4;
  6489. h[3][2] = 1;
  6490. h[3][3] = 0;
  6491. h[4][0] = 1;
  6492. h[4][1] = 4;
  6493. h[4][2] = 5;
  6494. h[4][3] = 2;
  6495. } else {
  6496. s.set((t + .25) * l, (e + .25) * l, p);
  6497. u[0].set(-.25 * l, -.25 * l, a[t][e] - p);
  6498. u[1].set(.75 * l, -.25 * l, a[t + 1][e] - p);
  6499. u[2].set(-.25 * l, .75 * l, a[t][e + 1] - p);
  6500. u[3].set(-.25 * l, -.25 * l, -p - 1);
  6501. u[4].set(.75 * l, -.25 * l, -p - 1);
  6502. u[5].set(-.25 * l, .75 * l, -p - 1);
  6503. h[0][0] = 0;
  6504. h[0][1] = 1;
  6505. h[0][2] = 2;
  6506. h[1][0] = 5;
  6507. h[1][1] = 4;
  6508. h[1][2] = 3;
  6509. h[2][0] = 0;
  6510. h[2][1] = 2;
  6511. h[2][2] = 5;
  6512. h[2][3] = 3;
  6513. h[3][0] = 1;
  6514. h[3][1] = 0;
  6515. h[3][2] = 3;
  6516. h[3][3] = 4;
  6517. h[4][0] = 4;
  6518. h[4][1] = 5;
  6519. h[4][2] = 2;
  6520. h[4][3] = 1;
  6521. }
  6522. r.computeNormals();
  6523. r.computeEdges();
  6524. r.updateBoundingSphereRadius();
  6525. this.setCachedConvexTrianglePillar(t, e, i, r, s);
  6526. };
  6527. s.prototype.calculateLocalInertia = function(t, e) {
  6528. (e = e || new n()).set(0, 0, 0);
  6529. return e;
  6530. };
  6531. s.prototype.volume = function() {
  6532. return Number.MAX_VALUE;
  6533. };
  6534. s.prototype.calculateWorldAABB = function(t, e, i, o) {
  6535. i.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
  6536. o.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
  6537. };
  6538. s.prototype.updateBoundingSphereRadius = function() {
  6539. var t = this.data, e = this.elementSize;
  6540. this.boundingSphereRadius = new n(t.length * e, t[0].length * e, Math.max(Math.abs(this.maxValue), Math.abs(this.minValue))).norm();
  6541. };
  6542. s.prototype.setHeightsFromImage = function(t, e) {
  6543. var i = document.createElement("canvas");
  6544. i.width = t.width;
  6545. i.height = t.height;
  6546. var o = i.getContext("2d");
  6547. o.drawImage(t, 0, 0);
  6548. var n = o.getImageData(0, 0, t.width, t.height), r = this.data;
  6549. r.length = 0;
  6550. this.elementSize = Math.abs(e.x) / n.width;
  6551. for (var s = 0; s < n.height; s++) {
  6552. for (var a = [], l = 0; l < n.width; l++) {
  6553. 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;
  6554. e.x < 0 ? a.push(h) : a.unshift(h);
  6555. }
  6556. e.y < 0 ? r.unshift(a) : r.push(a);
  6557. }
  6558. this.updateMaxValue();
  6559. this.updateMinValue();
  6560. this.update();
  6561. };
  6562. }, {
  6563. "../math/Vec3": 32,
  6564. "../utils/Utils": 55,
  6565. "./ConvexPolyhedron": 40,
  6566. "./Shape": 45
  6567. } ],
  6568. 43: [ function(t, e) {
  6569. e.exports = n;
  6570. var i = t("./Shape"), o = t("../math/Vec3");
  6571. function n() {
  6572. i.call(this, {
  6573. type: i.types.PARTICLE
  6574. });
  6575. }
  6576. n.prototype = new i();
  6577. n.prototype.constructor = n;
  6578. n.prototype.calculateLocalInertia = function(t, e) {
  6579. (e = e || new o()).set(0, 0, 0);
  6580. return e;
  6581. };
  6582. n.prototype.volume = function() {
  6583. return 0;
  6584. };
  6585. n.prototype.updateBoundingSphereRadius = function() {
  6586. this.boundingSphereRadius = 0;
  6587. };
  6588. n.prototype.calculateWorldAABB = function(t, e, i, o) {
  6589. i.copy(t);
  6590. o.copy(t);
  6591. };
  6592. }, {
  6593. "../math/Vec3": 32,
  6594. "./Shape": 45
  6595. } ],
  6596. 44: [ function(t, e) {
  6597. e.exports = n;
  6598. var i = t("./Shape"), o = t("../math/Vec3");
  6599. function n() {
  6600. i.call(this, {
  6601. type: i.types.PLANE
  6602. });
  6603. this.worldNormal = new o();
  6604. this.worldNormalNeedsUpdate = !0;
  6605. this.boundingSphereRadius = Number.MAX_VALUE;
  6606. }
  6607. n.prototype = new i();
  6608. n.prototype.constructor = n;
  6609. n.prototype.computeWorldNormal = function(t) {
  6610. var e = this.worldNormal;
  6611. e.set(0, 0, 1);
  6612. t.vmult(e, e);
  6613. this.worldNormalNeedsUpdate = !1;
  6614. };
  6615. n.prototype.calculateLocalInertia = function(t, e) {
  6616. return e || new o();
  6617. };
  6618. n.prototype.volume = function() {
  6619. return Number.MAX_VALUE;
  6620. };
  6621. var r = new o();
  6622. n.prototype.calculateWorldAABB = function(t, e, i, o) {
  6623. r.set(0, 0, 1);
  6624. e.vmult(r, r);
  6625. var n = Number.MAX_VALUE;
  6626. i.set(-n, -n, -n);
  6627. o.set(n, n, n);
  6628. 1 === r.x && (o.x = t.x);
  6629. 1 === r.y && (o.y = t.y);
  6630. 1 === r.z && (o.z = t.z);
  6631. -1 === r.x && (i.x = t.x);
  6632. -1 === r.y && (i.y = t.y);
  6633. -1 === r.z && (i.z = t.z);
  6634. };
  6635. n.prototype.updateBoundingSphereRadius = function() {
  6636. this.boundingSphereRadius = Number.MAX_VALUE;
  6637. };
  6638. }, {
  6639. "../math/Vec3": 32,
  6640. "./Shape": 45
  6641. } ],
  6642. 45: [ function(t, e) {
  6643. e.exports = o;
  6644. var i = t("../utils/EventTarget"), o = t("./Shape");
  6645. t("../math/Vec3"), t("../math/Quaternion"), t("../material/Material");
  6646. function o(t) {
  6647. t = t || {};
  6648. i.apply(this);
  6649. this.id = o.idCounter++;
  6650. this.type = t.type || 0;
  6651. this.boundingSphereRadius = 0;
  6652. this.collisionResponse = !t.collisionResponse || t.collisionResponse;
  6653. this.collisionFilterGroup = void 0 !== t.collisionFilterGroup ? t.collisionFilterGroup : 1;
  6654. this.collisionFilterMask = void 0 !== t.collisionFilterMask ? t.collisionFilterMask : -1;
  6655. this.material = t.material ? t.material : null;
  6656. this.body = null;
  6657. }
  6658. o.prototype = new i();
  6659. o.prototype.constructor = o;
  6660. o.prototype.updateBoundingSphereRadius = function() {
  6661. throw "computeBoundingSphereRadius() not implemented for shape type " + this.type;
  6662. };
  6663. o.prototype.volume = function() {
  6664. throw "volume() not implemented for shape type " + this.type;
  6665. };
  6666. o.prototype.calculateLocalInertia = function() {
  6667. throw "calculateLocalInertia() not implemented for shape type " + this.type;
  6668. };
  6669. o.idCounter = 0;
  6670. o.types = {
  6671. SPHERE: 1,
  6672. PLANE: 2,
  6673. BOX: 4,
  6674. COMPOUND: 8,
  6675. CONVEXPOLYHEDRON: 16,
  6676. HEIGHTFIELD: 32,
  6677. PARTICLE: 64,
  6678. CYLINDER: 128,
  6679. TRIMESH: 256
  6680. };
  6681. }, {
  6682. "../material/Material": 26,
  6683. "../math/Quaternion": 30,
  6684. "../math/Vec3": 32,
  6685. "../utils/EventTarget": 51,
  6686. "./Shape": 45
  6687. } ],
  6688. 46: [ function(t, e) {
  6689. e.exports = n;
  6690. var i = t("./Shape"), o = t("../math/Vec3");
  6691. function n(t) {
  6692. i.call(this, {
  6693. type: i.types.SPHERE
  6694. });
  6695. this.radius = void 0 !== t ? t : 1;
  6696. if (this.radius < 0) throw new Error("The sphere radius cannot be negative.");
  6697. this.updateBoundingSphereRadius();
  6698. }
  6699. n.prototype = new i();
  6700. n.prototype.constructor = n;
  6701. n.prototype.calculateLocalInertia = function(t, e) {
  6702. e = e || new o();
  6703. var i = 2 * t * this.radius * this.radius / 5;
  6704. e.x = i;
  6705. e.y = i;
  6706. e.z = i;
  6707. return e;
  6708. };
  6709. n.prototype.volume = function() {
  6710. return 4 * Math.PI * this.radius / 3;
  6711. };
  6712. n.prototype.updateBoundingSphereRadius = function() {
  6713. this.boundingSphereRadius = this.radius;
  6714. };
  6715. n.prototype.calculateWorldAABB = function(t, e, i, o) {
  6716. for (var n = this.radius, r = [ "x", "y", "z" ], s = 0; s < r.length; s++) {
  6717. var a = r[s];
  6718. i[a] = t[a] - n;
  6719. o[a] = t[a] + n;
  6720. }
  6721. };
  6722. }, {
  6723. "../math/Vec3": 32,
  6724. "./Shape": 45
  6725. } ],
  6726. 47: [ function(t, e) {
  6727. e.exports = l;
  6728. 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");
  6729. function l(t, e) {
  6730. i.call(this, {
  6731. type: i.types.TRIMESH
  6732. });
  6733. this.vertices = new Float32Array(t);
  6734. this.indices = new Int16Array(e);
  6735. this.normals = new Float32Array(e.length);
  6736. this.aabb = new r();
  6737. this.edges = null;
  6738. this.scale = new o(1, 1, 1);
  6739. this.tree = new s();
  6740. this.updateEdges();
  6741. this.updateNormals();
  6742. this.updateAABB();
  6743. this.updateBoundingSphereRadius();
  6744. this.updateTree();
  6745. }
  6746. l.prototype = new i();
  6747. l.prototype.constructor = l;
  6748. var h = new o();
  6749. l.prototype.updateTree = function() {
  6750. var t = this.tree;
  6751. t.reset();
  6752. t.aabb.copy(this.aabb);
  6753. var e = this.scale;
  6754. t.aabb.lowerBound.x *= 1 / e.x;
  6755. t.aabb.lowerBound.y *= 1 / e.y;
  6756. t.aabb.lowerBound.z *= 1 / e.z;
  6757. t.aabb.upperBound.x *= 1 / e.x;
  6758. t.aabb.upperBound.y *= 1 / e.y;
  6759. t.aabb.upperBound.z *= 1 / e.z;
  6760. 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++) {
  6761. var c = 3 * h;
  6762. this._getUnscaledVertex(this.indices[c], n);
  6763. this._getUnscaledVertex(this.indices[c + 1], s);
  6764. this._getUnscaledVertex(this.indices[c + 2], a);
  6765. i.setFromPoints(l);
  6766. t.insert(i, h);
  6767. }
  6768. t.removeEmptyNodes();
  6769. };
  6770. var c = new r();
  6771. l.prototype.getTrianglesInAABB = function(t, e) {
  6772. c.copy(t);
  6773. var i = this.scale, o = i.x, n = i.y, r = i.z, s = c.lowerBound, a = c.upperBound;
  6774. s.x /= o;
  6775. s.y /= n;
  6776. s.z /= r;
  6777. a.x /= o;
  6778. a.y /= n;
  6779. a.z /= r;
  6780. return this.tree.aabbQuery(c, e);
  6781. };
  6782. l.prototype.setScale = function(t) {
  6783. var e = this.scale.x === this.scale.y === this.scale.z, i = t.x === t.y === t.z;
  6784. e && i || this.updateNormals();
  6785. this.scale.copy(t);
  6786. this.updateAABB();
  6787. this.updateBoundingSphereRadius();
  6788. };
  6789. l.prototype.updateNormals = function() {
  6790. for (var t = h, e = this.normals, i = 0; i < this.indices.length / 3; i++) {
  6791. var o = 3 * i, n = this.indices[o], r = this.indices[o + 1], s = this.indices[o + 2];
  6792. this.getVertex(n, f);
  6793. this.getVertex(r, v);
  6794. this.getVertex(s, m);
  6795. l.computeNormal(v, f, m, t);
  6796. e[o] = t.x;
  6797. e[o + 1] = t.y;
  6798. e[o + 2] = t.z;
  6799. }
  6800. };
  6801. l.prototype.updateEdges = function() {
  6802. for (var t = {}, e = function() {
  6803. t[n < r ? n + "_" + r : r + "_" + n] = !0;
  6804. }, i = 0; i < this.indices.length / 3; i++) {
  6805. var o = 3 * i, n = this.indices[o], r = this.indices[o + 1];
  6806. this.indices[o + 2];
  6807. e();
  6808. e();
  6809. e();
  6810. }
  6811. var s = Object.keys(t);
  6812. this.edges = new Int16Array(2 * s.length);
  6813. for (i = 0; i < s.length; i++) {
  6814. var a = s[i].split("_");
  6815. this.edges[2 * i] = parseInt(a[0], 10);
  6816. this.edges[2 * i + 1] = parseInt(a[1], 10);
  6817. }
  6818. };
  6819. l.prototype.getEdgeVertex = function(t, e, i) {
  6820. var o = this.edges[2 * t + (e ? 1 : 0)];
  6821. this.getVertex(o, i);
  6822. };
  6823. var u = new o(), p = new o();
  6824. l.prototype.getEdgeVector = function(t, e) {
  6825. var i = u, o = p;
  6826. this.getEdgeVertex(t, 0, i);
  6827. this.getEdgeVertex(t, 1, o);
  6828. o.vsub(i, e);
  6829. };
  6830. var d = new o(), y = new o();
  6831. l.computeNormal = function(t, e, i, o) {
  6832. e.vsub(t, y);
  6833. i.vsub(e, d);
  6834. d.cross(y, o);
  6835. o.isZero() || o.normalize();
  6836. };
  6837. var f = new o(), v = new o(), m = new o();
  6838. l.prototype.getVertex = function(t, e) {
  6839. var i = this.scale;
  6840. this._getUnscaledVertex(t, e);
  6841. e.x *= i.x;
  6842. e.y *= i.y;
  6843. e.z *= i.z;
  6844. return e;
  6845. };
  6846. l.prototype._getUnscaledVertex = function(t, e) {
  6847. var i = 3 * t, o = this.vertices;
  6848. return e.set(o[i], o[i + 1], o[i + 2]);
  6849. };
  6850. l.prototype.getWorldVertex = function(t, e, i, o) {
  6851. this.getVertex(t, o);
  6852. n.pointToWorldFrame(e, i, o, o);
  6853. return o;
  6854. };
  6855. l.prototype.getTriangleVertices = function(t, e, i, o) {
  6856. var n = 3 * t;
  6857. this.getVertex(this.indices[n], e);
  6858. this.getVertex(this.indices[n + 1], i);
  6859. this.getVertex(this.indices[n + 2], o);
  6860. };
  6861. l.prototype.getNormal = function(t, e) {
  6862. var i = 3 * t;
  6863. return e.set(this.normals[i], this.normals[i + 1], this.normals[i + 2]);
  6864. };
  6865. var g = new r();
  6866. l.prototype.calculateLocalInertia = function(t, e) {
  6867. this.computeLocalAABB(g);
  6868. var i = g.upperBound.x - g.lowerBound.x, o = g.upperBound.y - g.lowerBound.y, n = g.upperBound.z - g.lowerBound.z;
  6869. 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));
  6870. };
  6871. var b = new o();
  6872. l.prototype.computeLocalAABB = function(t) {
  6873. var e = t.lowerBound, i = t.upperBound, o = this.vertices.length, n = (this.vertices,
  6874. b);
  6875. this.getVertex(0, n);
  6876. e.copy(n);
  6877. i.copy(n);
  6878. for (var r = 0; r !== o; r++) {
  6879. this.getVertex(r, n);
  6880. n.x < e.x ? e.x = n.x : n.x > i.x && (i.x = n.x);
  6881. n.y < e.y ? e.y = n.y : n.y > i.y && (i.y = n.y);
  6882. n.z < e.z ? e.z = n.z : n.z > i.z && (i.z = n.z);
  6883. }
  6884. };
  6885. l.prototype.updateAABB = function() {
  6886. this.computeLocalAABB(this.aabb);
  6887. };
  6888. l.prototype.updateBoundingSphereRadius = function() {
  6889. for (var t = 0, e = this.vertices, i = new o(), n = 0, r = e.length / 3; n !== r; n++) {
  6890. this.getVertex(n, i);
  6891. var s = i.norm2();
  6892. s > t && (t = s);
  6893. }
  6894. this.boundingSphereRadius = Math.sqrt(t);
  6895. };
  6896. new o();
  6897. var w = new n(), x = new r();
  6898. l.prototype.calculateWorldAABB = function(t, e, i, o) {
  6899. var n = w, r = x;
  6900. n.position = t;
  6901. n.quaternion = e;
  6902. this.aabb.toWorldFrame(n, r);
  6903. i.copy(r.lowerBound);
  6904. o.copy(r.upperBound);
  6905. };
  6906. l.prototype.volume = function() {
  6907. return 4 * Math.PI * this.boundingSphereRadius / 3;
  6908. };
  6909. l.createTorus = function(t, e, i, o, n) {
  6910. t = t || 1;
  6911. e = e || .5;
  6912. i = i || 8;
  6913. o = o || 6;
  6914. n = n || 2 * Math.PI;
  6915. for (var r = [], s = [], h = 0; h <= i; h++) for (var c = 0; c <= o; c++) {
  6916. 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);
  6917. r.push(d, y, f);
  6918. }
  6919. for (h = 1; h <= i; h++) for (c = 1; c <= o; c++) {
  6920. 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;
  6921. s.push(v, m, b);
  6922. s.push(m, g, b);
  6923. }
  6924. return new l(r, s);
  6925. };
  6926. }, {
  6927. "../collision/AABB": 3,
  6928. "../math/CMath": 27,
  6929. "../math/Quaternion": 30,
  6930. "../math/Transform": 31,
  6931. "../math/Vec3": 32,
  6932. "../utils/Octree": 52,
  6933. "./Shape": 45
  6934. } ],
  6935. 48: [ function(t, e) {
  6936. e.exports = o;
  6937. t("../math/Vec3"), t("../math/Quaternion");
  6938. var i = t("./Solver");
  6939. function o() {
  6940. i.call(this);
  6941. this.iterations = 10;
  6942. this.tolerance = 1e-7;
  6943. }
  6944. o.prototype = new i();
  6945. var n = [], r = [], s = [];
  6946. o.prototype.solve = function(t, e) {
  6947. 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;
  6948. if (0 !== y) for (var g = 0; g !== v; g++) f[g].updateSolveMassProperties();
  6949. var b = r, w = s, x = n;
  6950. b.length = y;
  6951. w.length = y;
  6952. x.length = y;
  6953. for (g = 0; g !== y; g++) {
  6954. var _ = d[g];
  6955. x[g] = 0;
  6956. w[g] = _.computeB(m);
  6957. b[g] = 1 / _.computeC();
  6958. }
  6959. if (0 !== y) {
  6960. for (g = 0; g !== v; g++) {
  6961. var B = (M = f[g]).vlambda, S = M.wlambda;
  6962. B.set(0, 0, 0);
  6963. S.set(0, 0, 0);
  6964. }
  6965. for (c = 0; c !== u; c++) {
  6966. l = 0;
  6967. for (var E = 0; E !== y; E++) {
  6968. _ = d[E];
  6969. i = w[E];
  6970. o = b[E];
  6971. (h = x[E]) + (a = o * (i - _.computeGWlambda() - _.eps * h)) < _.minForce ? a = _.minForce - h : h + a > _.maxForce && (a = _.maxForce - h);
  6972. x[E] += a;
  6973. l += a > 0 ? a : -a;
  6974. _.addToWlambda(a);
  6975. }
  6976. if (l * l < p) break;
  6977. }
  6978. for (g = 0; g !== v; g++) {
  6979. var M, C = (M = f[g]).velocity, A = M.angularVelocity;
  6980. M.vlambda.vmul(M.linearFactor, M.vlambda);
  6981. C.vadd(M.vlambda, C);
  6982. M.wlambda.vmul(M.angularFactor, M.wlambda);
  6983. A.vadd(M.wlambda, A);
  6984. }
  6985. for (var z = d.length, F = 1 / m; z--; ) d[z].multiplier = x[z] * F;
  6986. }
  6987. return c;
  6988. };
  6989. }, {
  6990. "../math/Quaternion": 30,
  6991. "../math/Vec3": 32,
  6992. "./Solver": 49
  6993. } ],
  6994. 49: [ function(t, e) {
  6995. e.exports = i;
  6996. function i() {
  6997. this.equations = [];
  6998. }
  6999. i.prototype.solve = function() {
  7000. return 0;
  7001. };
  7002. i.prototype.addEquation = function(t) {
  7003. t.enabled && this.equations.push(t);
  7004. };
  7005. i.prototype.removeEquation = function(t) {
  7006. var e = this.equations, i = e.indexOf(t);
  7007. -1 !== i && e.splice(i, 1);
  7008. };
  7009. i.prototype.removeAllEquations = function() {
  7010. this.equations.length = 0;
  7011. };
  7012. }, {} ],
  7013. 50: [ function(t, e) {
  7014. e.exports = n;
  7015. t("../math/Vec3"), t("../math/Quaternion");
  7016. var i = t("./Solver"), o = t("../objects/Body");
  7017. function n(t) {
  7018. i.call(this);
  7019. this.iterations = 10;
  7020. this.tolerance = 1e-7;
  7021. this.subsolver = t;
  7022. this.nodes = [];
  7023. this.nodePool = [];
  7024. for (;this.nodePool.length < 128; ) this.nodePool.push(this.createNode());
  7025. }
  7026. n.prototype = new i();
  7027. var r = [], s = [], a = {
  7028. bodies: []
  7029. }, l = o.STATIC;
  7030. function h(t) {
  7031. for (var e = t.length, i = 0; i !== e; i++) {
  7032. var o = t[i];
  7033. if (!(o.visited || o.body.type & l)) return o;
  7034. }
  7035. return !1;
  7036. }
  7037. var c = [];
  7038. function u(t, e, i, o) {
  7039. c.push(t);
  7040. t.visited = !0;
  7041. e(t, i, o);
  7042. for (;c.length; ) for (var n, r = c.pop(); n = h(r.children); ) {
  7043. n.visited = !0;
  7044. e(n, i, o);
  7045. c.push(n);
  7046. }
  7047. }
  7048. function p(t, e, i) {
  7049. e.push(t.body);
  7050. for (var o = t.eqs.length, n = 0; n !== o; n++) {
  7051. var r = t.eqs[n];
  7052. -1 === i.indexOf(r) && i.push(r);
  7053. }
  7054. }
  7055. n.prototype.createNode = function() {
  7056. return {
  7057. body: null,
  7058. children: [],
  7059. eqs: [],
  7060. visited: !1
  7061. };
  7062. };
  7063. n.prototype.solve = function(t, e) {
  7064. 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());
  7065. i.length = y;
  7066. for (var v = 0; v < y; v++) i[v] = o[v];
  7067. for (v = 0; v !== y; v++) {
  7068. var m = i[v];
  7069. m.body = n[v];
  7070. m.children.length = 0;
  7071. m.eqs.length = 0;
  7072. m.visited = !1;
  7073. }
  7074. for (var g = 0; g !== c; g++) {
  7075. var b = l[g], w = (v = n.indexOf(b.bi), n.indexOf(b.bj)), x = i[v], _ = i[w];
  7076. x.children.push(_);
  7077. x.eqs.push(b);
  7078. _.children.push(x);
  7079. _.eqs.push(b);
  7080. }
  7081. var B, S = 0, E = s;
  7082. f.tolerance = this.tolerance;
  7083. f.iterations = this.iterations;
  7084. for (var M = a; B = h(i); ) {
  7085. E.length = 0;
  7086. M.bodies.length = 0;
  7087. u(B, p, M.bodies, E);
  7088. var C = E.length;
  7089. E = E.sort(d);
  7090. for (v = 0; v !== C; v++) f.addEquation(E[v]);
  7091. f.solve(t, M);
  7092. f.removeAllEquations();
  7093. S++;
  7094. }
  7095. return S;
  7096. };
  7097. function d(t, e) {
  7098. return e.id - t.id;
  7099. }
  7100. }, {
  7101. "../math/Quaternion": 30,
  7102. "../math/Vec3": 32,
  7103. "../objects/Body": 33,
  7104. "./Solver": 49
  7105. } ],
  7106. 51: [ function(t, e) {
  7107. var i = function() {};
  7108. e.exports = i;
  7109. i.prototype = {
  7110. constructor: i,
  7111. addEventListener: function(t, e) {
  7112. void 0 === this._listeners && (this._listeners = {});
  7113. var i = this._listeners;
  7114. void 0 === i[t] && (i[t] = []);
  7115. -1 === i[t].indexOf(e) && i[t].push(e);
  7116. return this;
  7117. },
  7118. hasEventListener: function(t, e) {
  7119. if (void 0 === this._listeners) return !1;
  7120. var i = this._listeners;
  7121. return void 0 !== i[t] && -1 !== i[t].indexOf(e);
  7122. },
  7123. hasAnyEventListener: function(t) {
  7124. return void 0 !== this._listeners && void 0 !== this._listeners[t];
  7125. },
  7126. removeEventListener: function(t, e) {
  7127. if (void 0 === this._listeners) return this;
  7128. var i = this._listeners;
  7129. if (void 0 === i[t]) return this;
  7130. var o = i[t].indexOf(e);
  7131. -1 !== o && i[t].splice(o, 1);
  7132. return this;
  7133. },
  7134. dispatchEvent: function(t) {
  7135. if (void 0 === this._listeners) return this;
  7136. var e = this._listeners[t.type];
  7137. if (void 0 !== e) {
  7138. t.target = this;
  7139. for (var i = 0, o = e.length; i < o; i++) e[i].call(this, t);
  7140. }
  7141. return this;
  7142. }
  7143. };
  7144. }, {} ],
  7145. 52: [ function(t, e) {
  7146. var i = t("../collision/AABB"), o = t("../math/Vec3");
  7147. e.exports = r;
  7148. function n(t) {
  7149. t = t || {};
  7150. this.root = t.root || null;
  7151. this.aabb = t.aabb ? t.aabb.clone() : new i();
  7152. this.data = [];
  7153. this.children = [];
  7154. }
  7155. function r(t, e) {
  7156. (e = e || {}).root = null;
  7157. e.aabb = t;
  7158. n.call(this, e);
  7159. this.maxDepth = "undefined" != typeof e.maxDepth ? e.maxDepth : 8;
  7160. }
  7161. r.prototype = new n();
  7162. n.prototype.reset = function() {
  7163. this.children.length = this.data.length = 0;
  7164. };
  7165. n.prototype.insert = function(t, e, i) {
  7166. var o = this.data;
  7167. i = i || 0;
  7168. if (!this.aabb.contains(t)) return !1;
  7169. var n = this.children;
  7170. if (i < (this.maxDepth || this.root.maxDepth)) {
  7171. var r = !1;
  7172. if (!n.length) {
  7173. this.subdivide();
  7174. r = !0;
  7175. }
  7176. for (var s = 0; 8 !== s; s++) if (n[s].insert(t, e, i + 1)) return !0;
  7177. r && (n.length = 0);
  7178. }
  7179. o.push(e);
  7180. return !0;
  7181. };
  7182. var s = new o();
  7183. n.prototype.subdivide = function() {
  7184. var t = this.aabb, e = t.lowerBound, r = t.upperBound, a = this.children;
  7185. a.push(new n({
  7186. aabb: new i({
  7187. lowerBound: new o(0, 0, 0)
  7188. })
  7189. }), new n({
  7190. aabb: new i({
  7191. lowerBound: new o(1, 0, 0)
  7192. })
  7193. }), new n({
  7194. aabb: new i({
  7195. lowerBound: new o(1, 1, 0)
  7196. })
  7197. }), new n({
  7198. aabb: new i({
  7199. lowerBound: new o(1, 1, 1)
  7200. })
  7201. }), new n({
  7202. aabb: new i({
  7203. lowerBound: new o(0, 1, 1)
  7204. })
  7205. }), new n({
  7206. aabb: new i({
  7207. lowerBound: new o(0, 0, 1)
  7208. })
  7209. }), new n({
  7210. aabb: new i({
  7211. lowerBound: new o(1, 0, 1)
  7212. })
  7213. }), new n({
  7214. aabb: new i({
  7215. lowerBound: new o(0, 1, 0)
  7216. })
  7217. }));
  7218. r.vsub(e, s);
  7219. s.scale(.5, s);
  7220. for (var l = this.root || this, h = 0; 8 !== h; h++) {
  7221. var c = a[h];
  7222. c.root = l;
  7223. var u = c.aabb.lowerBound;
  7224. u.x *= s.x;
  7225. u.y *= s.y;
  7226. u.z *= s.z;
  7227. u.vadd(e, u);
  7228. u.vadd(s, c.aabb.upperBound);
  7229. }
  7230. };
  7231. n.prototype.aabbQuery = function(t, e) {
  7232. this.data, this.children;
  7233. for (var i = [ this ]; i.length; ) {
  7234. var o = i.pop();
  7235. o.aabb.overlaps(t) && Array.prototype.push.apply(e, o.data);
  7236. Array.prototype.push.apply(i, o.children);
  7237. }
  7238. return e;
  7239. };
  7240. var a = new i();
  7241. n.prototype.rayQuery = function(t, e, i) {
  7242. t.getAABB(a);
  7243. a.toLocalFrame(e, a);
  7244. this.aabbQuery(a, i);
  7245. return i;
  7246. };
  7247. n.prototype.removeEmptyNodes = function() {
  7248. for (var t = this.children.length - 1; t >= 0; t--) {
  7249. this.children[t].removeEmptyNodes();
  7250. this.children[t].children.length || this.children[t].data.length || this.children.splice(t, 1);
  7251. }
  7252. };
  7253. }, {
  7254. "../collision/AABB": 3,
  7255. "../math/Vec3": 32
  7256. } ],
  7257. 53: [ function(t, e) {
  7258. e.exports = i;
  7259. function i() {
  7260. this.objects = [];
  7261. this.type = Object;
  7262. }
  7263. i.prototype.release = function() {
  7264. for (var t = arguments.length, e = 0; e !== t; e++) this.objects.push(arguments[e]);
  7265. return this;
  7266. };
  7267. i.prototype.get = function() {
  7268. return 0 === this.objects.length ? this.constructObject() : this.objects.pop();
  7269. };
  7270. i.prototype.constructObject = function() {
  7271. throw new Error("constructObject() not implemented in this Pool subclass yet!");
  7272. };
  7273. i.prototype.resize = function(t) {
  7274. for (var e = this.objects; e.length > t; ) e.pop();
  7275. for (;e.length < t; ) e.push(this.constructObject());
  7276. return this;
  7277. };
  7278. }, {} ],
  7279. 54: [ function(t, e) {
  7280. e.exports = i;
  7281. function i() {
  7282. this.data = {
  7283. keys: []
  7284. };
  7285. }
  7286. i.prototype.get = function(t, e) {
  7287. if (t > e) {
  7288. var i = e;
  7289. e = t;
  7290. t = i;
  7291. }
  7292. return this.data[t + "-" + e];
  7293. };
  7294. i.prototype.set = function(t, e, i) {
  7295. if (t > e) {
  7296. var o = e;
  7297. e = t;
  7298. t = o;
  7299. }
  7300. var n = t + "-" + e;
  7301. this.get(t, e) || this.data.keys.push(n);
  7302. this.data[n] = i;
  7303. return this.data[n];
  7304. };
  7305. i.prototype.del = function(t, e) {
  7306. if (t > e) {
  7307. var i = e;
  7308. e = t;
  7309. t = i;
  7310. }
  7311. var o = t + "-" + e, n = this.data.keys.indexOf(o);
  7312. if (n >= 0) {
  7313. this.data.keys.splice(n, 1);
  7314. delete this.data[o];
  7315. return !0;
  7316. }
  7317. return !1;
  7318. };
  7319. i.prototype.reset = function() {
  7320. this.data = {
  7321. keys: []
  7322. };
  7323. };
  7324. i.prototype.getLength = function() {
  7325. return this.data.keys.length;
  7326. };
  7327. i.prototype.getKeyByIndex = function(t) {
  7328. return this.data.keys[t];
  7329. };
  7330. i.prototype.getDataByKey = function(t) {
  7331. return this.data[t];
  7332. };
  7333. }, {} ],
  7334. 55: [ function(t, e) {
  7335. function i() {}
  7336. e.exports = i;
  7337. i.defaults = function(t, e) {
  7338. t = t || {};
  7339. for (var i in e) i in t || (t[i] = e[i]);
  7340. return t;
  7341. };
  7342. }, {} ],
  7343. 56: [ function(t, e) {
  7344. e.exports = n;
  7345. var i = t("../math/Vec3"), o = t("./Pool");
  7346. function n() {
  7347. o.call(this);
  7348. this.type = i;
  7349. }
  7350. n.prototype = new o();
  7351. n.prototype.constructObject = function() {
  7352. return new i();
  7353. };
  7354. }, {
  7355. "../math/Vec3": 32,
  7356. "./Pool": 53
  7357. } ],
  7358. 57: [ function(t, e) {
  7359. e.exports = p;
  7360. 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"),
  7361. t("../math/Quaternion")), h = (t("../solver/Solver"), t("../utils/Vec3Pool")), c = t("../equations/ContactEquation"), u = t("../equations/FrictionEquation");
  7362. function p(t) {
  7363. this.contactPointPool = [];
  7364. this.frictionEquationPool = [];
  7365. this.result = [];
  7366. this.frictionResult = [];
  7367. this.v3pool = new h();
  7368. this.world = t;
  7369. this.currentContactMaterial = null;
  7370. this.enableFrictionReduction = !1;
  7371. }
  7372. p.prototype.createContactEquation = function(t, e, i, o, n, r) {
  7373. var s;
  7374. if (this.contactPointPool.length) {
  7375. (s = this.contactPointPool.pop()).bi = t;
  7376. s.bj = e;
  7377. } else s = new c(t, e);
  7378. s.enabled = t.collisionResponse && e.collisionResponse && i.collisionResponse && o.collisionResponse;
  7379. var a = this.currentContactMaterial;
  7380. s.restitution = a.restitution;
  7381. s.setSpookParams(a.contactEquationStiffness, a.contactEquationRelaxation, this.world.dt);
  7382. var l = i.material || t.material, h = o.material || e.material;
  7383. l && h && l.restitution >= 0 && h.restitution >= 0 && (s.restitution = l.restitution * h.restitution);
  7384. s.si = n || i;
  7385. s.sj = r || o;
  7386. return s;
  7387. };
  7388. p.prototype.createFrictionEquationsFromContact = function(t, e) {
  7389. 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;
  7390. h && c && h.friction >= 0 && c.friction >= 0 && (l = h.friction * c.friction);
  7391. if (l > 0) {
  7392. var p = l * s.gravity.length(), d = i.invMass + o.invMass;
  7393. d > 0 && (d = 1 / d);
  7394. 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);
  7395. f.bi = v.bi = i;
  7396. f.bj = v.bj = o;
  7397. f.minForce = v.minForce = -p * d;
  7398. f.maxForce = v.maxForce = p * d;
  7399. f.ri.copy(t.ri);
  7400. f.rj.copy(t.rj);
  7401. v.ri.copy(t.ri);
  7402. v.rj.copy(t.rj);
  7403. t.ni.tangents(f.t, v.t);
  7404. f.setSpookParams(a.frictionEquationStiffness, a.frictionEquationRelaxation, s.dt);
  7405. v.setSpookParams(a.frictionEquationStiffness, a.frictionEquationRelaxation, s.dt);
  7406. f.enabled = v.enabled = t.enabled;
  7407. e.push(f, v);
  7408. return !0;
  7409. }
  7410. return !1;
  7411. };
  7412. var d = new s(), y = new s(), f = new s();
  7413. p.prototype.createFrictionFromAverage = function(t) {
  7414. var e = this.result[this.result.length - 1];
  7415. if (this.createFrictionEquationsFromContact(e, this.frictionResult) && 1 !== t) {
  7416. var i = this.frictionResult[this.frictionResult.length - 2], o = this.frictionResult[this.frictionResult.length - 1];
  7417. d.setZero();
  7418. y.setZero();
  7419. f.setZero();
  7420. for (var n = e.bi, r = (e.bj, 0); r !== t; r++) if ((e = this.result[this.result.length - 1 - r]).bodyA !== n) {
  7421. d.vadd(e.ni, d);
  7422. y.vadd(e.ri, y);
  7423. f.vadd(e.rj, f);
  7424. } else {
  7425. d.vsub(e.ni, d);
  7426. y.vadd(e.rj, y);
  7427. f.vadd(e.ri, f);
  7428. }
  7429. var s = 1 / t;
  7430. y.scale(s, i.ri);
  7431. f.scale(s, i.rj);
  7432. o.ri.copy(i.ri);
  7433. o.rj.copy(i.rj);
  7434. d.normalize();
  7435. d.tangents(i.t, o.t);
  7436. }
  7437. };
  7438. var v = new s(), m = new s(), g = new l(), b = new l();
  7439. p.prototype.getContacts = function(t, e, i, n, r, s, a) {
  7440. this.contactPointPool = r;
  7441. this.frictionEquationPool = a;
  7442. this.result = n;
  7443. this.frictionResult = s;
  7444. for (var l = g, h = b, c = v, u = m, p = 0, d = t.length; p !== d; p++) {
  7445. var y = t[p], f = e[p], w = null;
  7446. y.material && f.material && (w = i.getContactMaterial(y.material, f.material) || null);
  7447. 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; _++) {
  7448. y.quaternion.mult(y.shapeOrientations[_], l);
  7449. y.quaternion.vmult(y.shapeOffsets[_], c);
  7450. c.vadd(y.position, c);
  7451. for (var B = y.shapes[_], S = 0; S < f.shapes.length; S++) {
  7452. f.quaternion.mult(f.shapeOrientations[S], h);
  7453. f.quaternion.vmult(f.shapeOffsets[S], u);
  7454. u.vadd(f.position, u);
  7455. var E = f.shapes[S];
  7456. if (B.collisionFilterMask & E.collisionFilterGroup && E.collisionFilterMask & B.collisionFilterGroup && !(c.distanceTo(u) > B.boundingSphereRadius + E.boundingSphereRadius)) {
  7457. x |= 0 == B.collisionResponse || 0 == E.collisionResponse;
  7458. var M = null;
  7459. B.material && E.material && (M = i.getContactMaterial(B.material, E.material) || null);
  7460. this.currentContactMaterial = M || w || i.defaultContactMaterial;
  7461. var C = this[B.type | E.type];
  7462. 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) {
  7463. i.shapeOverlapKeeper.set(B.id, E.id);
  7464. i.bodyOverlapKeeper.set(y.id, f.id);
  7465. var A = {
  7466. si: B,
  7467. sj: E
  7468. };
  7469. i.triggerDic.set(B.id, E.id, A);
  7470. i.oldTriggerDic.set(B.id, E.id, A);
  7471. }
  7472. }
  7473. }
  7474. }
  7475. }
  7476. };
  7477. p.prototype[n.types.BOX | n.types.BOX] = p.prototype.boxBox = function(t, e, i, o, n, r, s, a, l, h, c) {
  7478. t.convexPolyhedronRepresentation.material = t.material;
  7479. e.convexPolyhedronRepresentation.material = e.material;
  7480. t.convexPolyhedronRepresentation.collisionResponse = t.collisionResponse;
  7481. e.convexPolyhedronRepresentation.collisionResponse = e.collisionResponse;
  7482. return this.convexConvex(t.convexPolyhedronRepresentation, e.convexPolyhedronRepresentation, i, o, n, r, s, a, t, e, c);
  7483. };
  7484. p.prototype[n.types.BOX | n.types.CONVEXPOLYHEDRON] = p.prototype.boxConvex = function(t, e, i, o, n, r, s, a, l, h, c) {
  7485. t.convexPolyhedronRepresentation.material = t.material;
  7486. t.convexPolyhedronRepresentation.collisionResponse = t.collisionResponse;
  7487. return this.convexConvex(t.convexPolyhedronRepresentation, e, i, o, n, r, s, a, t, e, c);
  7488. };
  7489. p.prototype[n.types.BOX | n.types.PARTICLE] = p.prototype.boxParticle = function(t, e, i, o, n, r, s, a, l, h, c) {
  7490. t.convexPolyhedronRepresentation.material = t.material;
  7491. t.convexPolyhedronRepresentation.collisionResponse = t.collisionResponse;
  7492. return this.convexParticle(t.convexPolyhedronRepresentation, e, i, o, n, r, s, a, t, e, c);
  7493. };
  7494. p.prototype[n.types.SPHERE] = p.prototype.sphereSphere = function(t, e, i, o, n, r, s, a, l, h, c) {
  7495. if (c) return i.distanceSquared(o) < Math.pow(t.radius + e.radius, 2);
  7496. var u = this.createContactEquation(s, a, t, e, l, h);
  7497. o.vsub(i, u.ni);
  7498. u.ni.normalize();
  7499. u.ri.copy(u.ni);
  7500. u.rj.copy(u.ni);
  7501. u.ri.mult(t.radius, u.ri);
  7502. u.rj.mult(-e.radius, u.rj);
  7503. u.ri.vadd(i, u.ri);
  7504. u.ri.vsub(s.position, u.ri);
  7505. u.rj.vadd(o, u.rj);
  7506. u.rj.vsub(a.position, u.rj);
  7507. this.result.push(u);
  7508. this.createFrictionEquationsFromContact(u, this.frictionResult);
  7509. };
  7510. var w = new s(), x = new s(), _ = new s();
  7511. p.prototype[n.types.PLANE | n.types.TRIMESH] = p.prototype.planeTrimesh = function(t, e, i, o, n, r, l, h, c, u, p) {
  7512. var d = new s(), y = w;
  7513. y.set(0, 0, 1);
  7514. n.vmult(y, y);
  7515. for (var f = 0; f < e.vertices.length / 3; f++) {
  7516. e.getVertex(f, d);
  7517. var v = new s();
  7518. v.copy(d);
  7519. a.pointToWorldFrame(o, r, v, d);
  7520. var m = x;
  7521. d.vsub(i, m);
  7522. if (y.dot(m) <= 0) {
  7523. if (p) return !0;
  7524. var g = this.createContactEquation(l, h, t, e, c, u);
  7525. g.ni.copy(y);
  7526. var b = _;
  7527. y.scale(m.dot(y), b);
  7528. d.vsub(b, b);
  7529. g.ri.copy(b);
  7530. g.ri.vsub(l.position, g.ri);
  7531. g.rj.copy(d);
  7532. g.rj.vsub(h.position, g.rj);
  7533. this.result.push(g);
  7534. this.createFrictionEquationsFromContact(g, this.frictionResult);
  7535. }
  7536. }
  7537. };
  7538. 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 = [];
  7539. p.prototype[n.types.SPHERE | n.types.TRIMESH] = p.prototype.sphereTrimesh = function(t, e, i, o, n, s, l, h, c, u, p) {
  7540. var d = C, y = A, f = z, v = F, m = R, g = T, b = O, w = M, x = S, _ = V;
  7541. a.pointToLocalFrame(o, s, i, m);
  7542. var j = t.radius;
  7543. b.lowerBound.set(m.x - j, m.y - j, m.z - j);
  7544. b.upperBound.set(m.x + j, m.y + j, m.z + j);
  7545. e.getTrianglesInAABB(b, _);
  7546. for (var k = E, N = t.radius * t.radius, L = 0; L < _.length; L++) for (var W = 0; W < 3; W++) {
  7547. e.getVertex(e.indices[3 * _[L] + W], k);
  7548. k.vsub(m, x);
  7549. if (x.norm2() <= N) {
  7550. w.copy(k);
  7551. a.pointToWorldFrame(o, s, w, k);
  7552. k.vsub(i, x);
  7553. if (p) return !0;
  7554. (G = this.createContactEquation(l, h, t, e, c, u)).ni.copy(x);
  7555. G.ni.normalize();
  7556. G.ri.copy(G.ni);
  7557. G.ri.scale(t.radius, G.ri);
  7558. G.ri.vadd(i, G.ri);
  7559. G.ri.vsub(l.position, G.ri);
  7560. G.rj.copy(k);
  7561. G.rj.vsub(h.position, G.rj);
  7562. this.result.push(G);
  7563. this.createFrictionEquationsFromContact(G, this.frictionResult);
  7564. }
  7565. }
  7566. for (L = 0; L < _.length; L++) for (W = 0; W < 3; W++) {
  7567. e.getVertex(e.indices[3 * _[L] + W], d);
  7568. e.getVertex(e.indices[3 * _[L] + (W + 1) % 3], y);
  7569. y.vsub(d, f);
  7570. m.vsub(y, g);
  7571. var D = g.dot(f);
  7572. m.vsub(d, g);
  7573. var U = g.dot(f);
  7574. if (U > 0 && D < 0) {
  7575. m.vsub(d, g);
  7576. v.copy(f);
  7577. v.normalize();
  7578. U = g.dot(v);
  7579. v.scale(U, g);
  7580. g.vadd(d, g);
  7581. if ((Z = g.distanceTo(m)) < t.radius) {
  7582. if (p) return !0;
  7583. var G = this.createContactEquation(l, h, t, e, c, u);
  7584. g.vsub(m, G.ni);
  7585. G.ni.normalize();
  7586. G.ni.scale(t.radius, G.ri);
  7587. a.pointToWorldFrame(o, s, g, g);
  7588. g.vsub(h.position, G.rj);
  7589. a.vectorToWorldFrame(s, G.ni, G.ni);
  7590. a.vectorToWorldFrame(s, G.ri, G.ri);
  7591. this.result.push(G);
  7592. this.createFrictionEquationsFromContact(G, this.frictionResult);
  7593. }
  7594. }
  7595. }
  7596. for (var H = P, K = q, Q = I, X = B, Y = (L = 0, _.length); L !== Y; L++) {
  7597. e.getTriangleVertices(_[L], H, K, Q);
  7598. e.getNormal(_[L], X);
  7599. m.vsub(H, g);
  7600. var Z = g.dot(X);
  7601. X.scale(Z, g);
  7602. m.vsub(g, g);
  7603. Z = g.distanceTo(m);
  7604. if (r.pointInTriangle(g, H, K, Q) && Z < t.radius) {
  7605. if (p) return !0;
  7606. G = this.createContactEquation(l, h, t, e, c, u);
  7607. g.vsub(m, G.ni);
  7608. G.ni.normalize();
  7609. G.ni.scale(t.radius, G.ri);
  7610. a.pointToWorldFrame(o, s, g, g);
  7611. g.vsub(h.position, G.rj);
  7612. a.vectorToWorldFrame(s, G.ni, G.ni);
  7613. a.vectorToWorldFrame(s, G.ri, G.ri);
  7614. this.result.push(G);
  7615. this.createFrictionEquationsFromContact(G, this.frictionResult);
  7616. }
  7617. }
  7618. _.length = 0;
  7619. };
  7620. var j = new s(), k = new s(), N = new s(), L = new s(), W = new s();
  7621. p.prototype[n.types.SPHERE | n.types.PLANE] = p.prototype.spherePlane = function(t, e, i, o, n, r, s, a, l, h, c) {
  7622. N.set(0, 0, 1);
  7623. r.vmult(N, N);
  7624. N.negate(N);
  7625. N.normalize();
  7626. N.mult(t.radius, L);
  7627. i.vsub(o, j);
  7628. N.mult(N.dot(j), k);
  7629. j.vsub(k, W);
  7630. if (-j.dot(N) <= t.radius) {
  7631. if (c) return !0;
  7632. var u = this.createContactEquation(s, a, t, e, l, h);
  7633. u.ni.copy(N);
  7634. u.ri.copy(L);
  7635. u.rj.copy(W);
  7636. var p = u.ri, d = u.rj;
  7637. p.vadd(i, p);
  7638. p.vsub(s.position, p);
  7639. d.vadd(o, d);
  7640. d.vsub(a.position, d);
  7641. this.result.push(u);
  7642. this.createFrictionEquationsFromContact(u, this.frictionResult);
  7643. }
  7644. return !1;
  7645. };
  7646. var D = new s(), U = new s(), G = new s();
  7647. function H(t, e, i) {
  7648. for (var o = null, n = t.length, r = 0; r !== n; r++) {
  7649. var s = t[r], a = D;
  7650. t[(r + 1) % n].vsub(s, a);
  7651. var l = U;
  7652. a.cross(e, l);
  7653. var h = G;
  7654. i.vsub(s, h);
  7655. var c = l.dot(h);
  7656. if (!(null === o || c > 0 && !0 === o || c <= 0 && !1 === o)) return !1;
  7657. null === o && (o = c > 0);
  7658. }
  7659. return !0;
  7660. }
  7661. 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();
  7662. p.prototype[n.types.SPHERE | n.types.BOX] = p.prototype.sphereBox = function(t, e, i, o, n, r, s, a, l, h, c) {
  7663. var u = this.v3pool, p = Z;
  7664. i.vsub(o, K);
  7665. e.getSideNormals(p, r);
  7666. 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++) {
  7667. var E = Q;
  7668. E.copy(p[B]);
  7669. var M = E.norm();
  7670. E.normalize();
  7671. var C = K.dot(E);
  7672. if (C < M + d && C > 0) {
  7673. var A = X, z = Y;
  7674. A.copy(p[(B + 1) % 3]);
  7675. z.copy(p[(B + 2) % 3]);
  7676. var F = A.norm(), R = z.norm();
  7677. A.normalize();
  7678. z.normalize();
  7679. var T = K.dot(A), P = K.dot(z);
  7680. if (T < F && T > -F && P < R && P > -R) {
  7681. var q = Math.abs(C - M - d);
  7682. if (null === _ || q < _) {
  7683. _ = q;
  7684. w = T;
  7685. x = P;
  7686. g = M;
  7687. f.copy(E);
  7688. v.copy(A);
  7689. m.copy(z);
  7690. b++;
  7691. if (c) return !0;
  7692. }
  7693. }
  7694. }
  7695. }
  7696. if (b) {
  7697. y = !0;
  7698. var I = this.createContactEquation(s, a, t, e, l, h);
  7699. f.mult(-d, I.ri);
  7700. I.ni.copy(f);
  7701. I.ni.negate(I.ni);
  7702. f.mult(g, f);
  7703. v.mult(w, v);
  7704. f.vadd(v, f);
  7705. m.mult(x, m);
  7706. f.vadd(m, I.rj);
  7707. I.ri.vadd(i, I.ri);
  7708. I.ri.vsub(s.position, I.ri);
  7709. I.rj.vadd(o, I.rj);
  7710. I.rj.vsub(a.position, I.rj);
  7711. this.result.push(I);
  7712. this.createFrictionEquationsFromContact(I, this.frictionResult);
  7713. }
  7714. 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++) {
  7715. O.set(0, 0, 0);
  7716. j ? O.vadd(p[0], O) : O.vsub(p[0], O);
  7717. k ? O.vadd(p[1], O) : O.vsub(p[1], O);
  7718. N ? O.vadd(p[2], O) : O.vsub(p[2], O);
  7719. o.vadd(O, V);
  7720. V.vsub(i, V);
  7721. if (V.norm2() < d * d) {
  7722. if (c) return !0;
  7723. y = !0;
  7724. (I = this.createContactEquation(s, a, t, e, l, h)).ri.copy(V);
  7725. I.ri.normalize();
  7726. I.ni.copy(I.ri);
  7727. I.ri.mult(d, I.ri);
  7728. I.rj.copy(O);
  7729. I.ri.vadd(i, I.ri);
  7730. I.ri.vsub(s.position, I.ri);
  7731. I.rj.vadd(o, I.rj);
  7732. I.rj.vsub(a.position, I.rj);
  7733. this.result.push(I);
  7734. this.createFrictionEquationsFromContact(I, this.frictionResult);
  7735. }
  7736. }
  7737. u.release(O);
  7738. O = null;
  7739. var L = u.get(), W = u.get(), D = (I = u.get(), u.get()), U = (q = u.get(), p.length);
  7740. for (j = 0; j !== U && !y; j++) for (k = 0; k !== U && !y; k++) if (j % 3 != k % 3) {
  7741. p[k].cross(p[j], L);
  7742. L.normalize();
  7743. p[j].vadd(p[k], W);
  7744. I.copy(i);
  7745. I.vsub(W, I);
  7746. I.vsub(o, I);
  7747. var G = I.dot(L);
  7748. L.mult(G, D);
  7749. for (N = 0; N === j % 3 || N === k % 3; ) N++;
  7750. q.copy(i);
  7751. q.vsub(D, q);
  7752. q.vsub(W, q);
  7753. q.vsub(o, q);
  7754. var H = Math.abs(G), it = q.norm();
  7755. if (H < p[N].norm() && it < d) {
  7756. if (c) return !0;
  7757. y = !0;
  7758. var ot = this.createContactEquation(s, a, t, e, l, h);
  7759. W.vadd(D, ot.rj);
  7760. ot.rj.copy(ot.rj);
  7761. q.negate(ot.ni);
  7762. ot.ni.normalize();
  7763. ot.ri.copy(ot.rj);
  7764. ot.ri.vadd(o, ot.ri);
  7765. ot.ri.vsub(i, ot.ri);
  7766. ot.ri.normalize();
  7767. ot.ri.mult(d, ot.ri);
  7768. ot.ri.vadd(i, ot.ri);
  7769. ot.ri.vsub(s.position, ot.ri);
  7770. ot.rj.vadd(o, ot.rj);
  7771. ot.rj.vsub(a.position, ot.rj);
  7772. this.result.push(ot);
  7773. this.createFrictionEquationsFromContact(ot, this.frictionResult);
  7774. }
  7775. }
  7776. u.release(L, W, I, D, q);
  7777. };
  7778. 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();
  7779. p.prototype[n.types.SPHERE | n.types.CONVEXPOLYHEDRON] = p.prototype.sphereConvex = function(t, e, i, o, n, r, s, a, l, h, c) {
  7780. var u = this.v3pool;
  7781. i.vsub(o, it);
  7782. for (var p = e.faceNormals, d = e.faces, y = e.vertices, f = t.radius, v = 0; v !== y.length; v++) {
  7783. var m = y[v], g = st;
  7784. r.vmult(m, g);
  7785. o.vadd(g, g);
  7786. var b = rt;
  7787. g.vsub(i, b);
  7788. if (b.norm2() < f * f) {
  7789. if (c) return !0;
  7790. w = !0;
  7791. (q = this.createContactEquation(s, a, t, e, l, h)).ri.copy(b);
  7792. q.ri.normalize();
  7793. q.ni.copy(q.ri);
  7794. q.ri.mult(f, q.ri);
  7795. g.vsub(o, q.rj);
  7796. q.ri.vadd(i, q.ri);
  7797. q.ri.vsub(s.position, q.ri);
  7798. q.rj.vadd(o, q.rj);
  7799. q.rj.vsub(a.position, q.rj);
  7800. this.result.push(q);
  7801. this.createFrictionEquationsFromContact(q, this.frictionResult);
  7802. return;
  7803. }
  7804. }
  7805. for (var w = !1, x = (v = 0, d.length); v !== x && !1 === w; v++) {
  7806. var _ = p[v], B = d[v], S = at;
  7807. r.vmult(_, S);
  7808. var E = lt;
  7809. r.vmult(y[B[0]], E);
  7810. E.vadd(o, E);
  7811. var M = ht;
  7812. S.mult(-f, M);
  7813. i.vadd(M, M);
  7814. var C = ct;
  7815. M.vsub(E, C);
  7816. var A = C.dot(S), z = ut;
  7817. i.vsub(E, z);
  7818. if (A < 0 && z.dot(S) > 0) {
  7819. for (var F = [], R = 0, T = B.length; R !== T; R++) {
  7820. var P = u.get();
  7821. r.vmult(y[B[R]], P);
  7822. o.vadd(P, P);
  7823. F.push(P);
  7824. }
  7825. if (H(F, S, i)) {
  7826. if (c) return !0;
  7827. w = !0;
  7828. var q = this.createContactEquation(s, a, t, e, l, h);
  7829. S.mult(-f, q.ri);
  7830. S.negate(q.ni);
  7831. var I = u.get();
  7832. S.mult(-A, I);
  7833. var O = u.get();
  7834. S.mult(-f, O);
  7835. i.vsub(o, q.rj);
  7836. q.rj.vadd(O, q.rj);
  7837. q.rj.vadd(I, q.rj);
  7838. q.rj.vadd(o, q.rj);
  7839. q.rj.vsub(a.position, q.rj);
  7840. q.ri.vadd(i, q.ri);
  7841. q.ri.vsub(s.position, q.ri);
  7842. u.release(I);
  7843. u.release(O);
  7844. this.result.push(q);
  7845. this.createFrictionEquationsFromContact(q, this.frictionResult);
  7846. R = 0;
  7847. for (var V = F.length; R !== V; R++) u.release(F[R]);
  7848. return;
  7849. }
  7850. for (R = 0; R !== B.length; R++) {
  7851. var j = u.get(), k = u.get();
  7852. r.vmult(y[B[(R + 1) % B.length]], j);
  7853. r.vmult(y[B[(R + 2) % B.length]], k);
  7854. o.vadd(j, j);
  7855. o.vadd(k, k);
  7856. var N = ot;
  7857. k.vsub(j, N);
  7858. var L = nt;
  7859. N.unit(L);
  7860. var W = u.get(), D = u.get();
  7861. i.vsub(j, D);
  7862. var U = D.dot(L);
  7863. L.mult(U, W);
  7864. W.vadd(j, W);
  7865. var G = u.get();
  7866. W.vsub(i, G);
  7867. if (U > 0 && U * U < N.norm2() && G.norm2() < f * f) {
  7868. if (c) return !0;
  7869. q = this.createContactEquation(s, a, t, e, l, h);
  7870. W.vsub(o, q.rj);
  7871. W.vsub(i, q.ni);
  7872. q.ni.normalize();
  7873. q.ni.mult(f, q.ri);
  7874. q.rj.vadd(o, q.rj);
  7875. q.rj.vsub(a.position, q.rj);
  7876. q.ri.vadd(i, q.ri);
  7877. q.ri.vsub(s.position, q.ri);
  7878. this.result.push(q);
  7879. this.createFrictionEquationsFromContact(q, this.frictionResult);
  7880. for (R = 0, V = F.length; R !== V; R++) u.release(F[R]);
  7881. u.release(j);
  7882. u.release(k);
  7883. u.release(W);
  7884. u.release(G);
  7885. u.release(D);
  7886. return;
  7887. }
  7888. u.release(j);
  7889. u.release(k);
  7890. u.release(W);
  7891. u.release(G);
  7892. u.release(D);
  7893. }
  7894. for (R = 0, V = F.length; R !== V; R++) u.release(F[R]);
  7895. }
  7896. }
  7897. };
  7898. new s(), new s();
  7899. p.prototype[n.types.PLANE | n.types.BOX] = p.prototype.planeBox = function(t, e, i, o, n, r, s, a, l, h, c) {
  7900. e.convexPolyhedronRepresentation.material = e.material;
  7901. e.convexPolyhedronRepresentation.collisionResponse = e.collisionResponse;
  7902. e.convexPolyhedronRepresentation.id = e.id;
  7903. return this.planeConvex(t, e.convexPolyhedronRepresentation, i, o, n, r, s, a, t, e, c);
  7904. };
  7905. var pt = new s(), dt = new s(), yt = new s(), ft = new s();
  7906. p.prototype[n.types.PLANE | n.types.CONVEXPOLYHEDRON] = p.prototype.planeConvex = function(t, e, i, o, n, r, s, a, l, h, c) {
  7907. var u = pt, p = dt;
  7908. p.set(0, 0, 1);
  7909. n.vmult(p, p);
  7910. for (var d = 0, y = yt, f = 0; f !== e.vertices.length; f++) {
  7911. u.copy(e.vertices[f]);
  7912. r.vmult(u, u);
  7913. o.vadd(u, u);
  7914. u.vsub(i, y);
  7915. if (p.dot(y) <= 0) {
  7916. if (c) return !0;
  7917. var v = this.createContactEquation(s, a, t, e, l, h), m = ft;
  7918. p.mult(p.dot(y), m);
  7919. u.vsub(m, m);
  7920. m.vsub(i, v.ri);
  7921. v.ni.copy(p);
  7922. u.vsub(o, v.rj);
  7923. v.ri.vadd(i, v.ri);
  7924. v.ri.vsub(s.position, v.ri);
  7925. v.rj.vadd(o, v.rj);
  7926. v.rj.vsub(a.position, v.rj);
  7927. this.result.push(v);
  7928. d++;
  7929. this.enableFrictionReduction || this.createFrictionEquationsFromContact(v, this.frictionResult);
  7930. }
  7931. }
  7932. this.enableFrictionReduction && d && this.createFrictionFromAverage(d);
  7933. };
  7934. var vt = new s(), mt = new s();
  7935. p.prototype[n.types.CONVEXPOLYHEDRON] = p.prototype.convexConvex = function(t, e, i, o, n, r, s, a, l, h, c, u, p) {
  7936. var d = vt;
  7937. if (!(i.distanceTo(o) > t.boundingSphereRadius + e.boundingSphereRadius) && t.findSeparatingAxis(e, i, n, o, r, d, u, p)) {
  7938. var y = [], f = mt;
  7939. t.clipAgainstHull(i, n, e, o, r, d, -100, 100, y);
  7940. for (var v = 0, m = 0; m !== y.length; m++) {
  7941. if (c) return !0;
  7942. var g = this.createContactEquation(s, a, t, e, l, h), b = g.ri, w = g.rj;
  7943. d.negate(g.ni);
  7944. y[m].normal.negate(f);
  7945. f.mult(y[m].depth, f);
  7946. y[m].point.vadd(f, b);
  7947. w.copy(y[m].point);
  7948. b.vsub(i, b);
  7949. w.vsub(o, w);
  7950. b.vadd(i, b);
  7951. b.vsub(s.position, b);
  7952. w.vadd(o, w);
  7953. w.vsub(a.position, w);
  7954. this.result.push(g);
  7955. v++;
  7956. this.enableFrictionReduction || this.createFrictionEquationsFromContact(g, this.frictionResult);
  7957. }
  7958. this.enableFrictionReduction && v && this.createFrictionFromAverage(v);
  7959. }
  7960. };
  7961. var gt = new s(), bt = new s(), wt = new s();
  7962. p.prototype[n.types.PLANE | n.types.PARTICLE] = p.prototype.planeParticle = function(t, e, i, o, n, r, s, a, l, h, c) {
  7963. var u = gt;
  7964. u.set(0, 0, 1);
  7965. s.quaternion.vmult(u, u);
  7966. var p = bt;
  7967. o.vsub(s.position, p);
  7968. if (u.dot(p) <= 0) {
  7969. if (c) return !0;
  7970. var d = this.createContactEquation(a, s, e, t, l, h);
  7971. d.ni.copy(u);
  7972. d.ni.negate(d.ni);
  7973. d.ri.set(0, 0, 0);
  7974. var y = wt;
  7975. u.mult(u.dot(o), y);
  7976. o.vsub(y, y);
  7977. d.rj.copy(y);
  7978. this.result.push(d);
  7979. this.createFrictionEquationsFromContact(d, this.frictionResult);
  7980. }
  7981. };
  7982. var xt = new s();
  7983. p.prototype[n.types.PARTICLE | n.types.SPHERE] = p.prototype.sphereParticle = function(t, e, i, o, n, r, s, a, l, h, c) {
  7984. var u = xt;
  7985. u.set(0, 0, 1);
  7986. o.vsub(i, u);
  7987. if (u.norm2() <= t.radius * t.radius) {
  7988. if (c) return !0;
  7989. var p = this.createContactEquation(a, s, e, t, l, h);
  7990. u.normalize();
  7991. p.rj.copy(u);
  7992. p.rj.mult(t.radius, p.rj);
  7993. p.ni.copy(u);
  7994. p.ni.negate(p.ni);
  7995. p.ri.set(0, 0, 0);
  7996. this.result.push(p);
  7997. this.createFrictionEquationsFromContact(p, this.frictionResult);
  7998. }
  7999. };
  8000. var _t = new l(), Bt = new s(), St = (new s(), new s()), Et = new s(), Mt = new s();
  8001. p.prototype[n.types.PARTICLE | n.types.CONVEXPOLYHEDRON] = p.prototype.convexParticle = function(t, e, i, o, n, r, s, a, l, h, c) {
  8002. var u = -1, p = St, d = Mt, y = null, f = Bt;
  8003. f.copy(o);
  8004. f.vsub(i, f);
  8005. n.conjugate(_t);
  8006. _t.vmult(f, f);
  8007. if (t.pointIsInside(f)) {
  8008. t.worldVerticesNeedsUpdate && t.computeWorldVertices(i, n);
  8009. t.worldFaceNormalsNeedsUpdate && t.computeWorldFaceNormals(n);
  8010. for (var v = 0, m = t.faces.length; v !== m; v++) {
  8011. var g = [ t.worldVertices[t.faces[v][0]] ], b = t.worldFaceNormals[v];
  8012. o.vsub(g[0], Et);
  8013. var w = -b.dot(Et);
  8014. if (null === y || Math.abs(w) < Math.abs(y)) {
  8015. if (c) return !0;
  8016. y = w;
  8017. u = v;
  8018. p.copy(b);
  8019. }
  8020. }
  8021. if (-1 !== u) {
  8022. var x = this.createContactEquation(a, s, e, t, l, h);
  8023. p.mult(y, d);
  8024. d.vadd(o, d);
  8025. d.vsub(i, d);
  8026. x.rj.copy(d);
  8027. p.negate(x.ni);
  8028. x.ri.set(0, 0, 0);
  8029. var _ = x.ri, B = x.rj;
  8030. _.vadd(o, _);
  8031. _.vsub(a.position, _);
  8032. B.vadd(i, B);
  8033. B.vsub(s.position, B);
  8034. this.result.push(x);
  8035. this.createFrictionEquationsFromContact(x, this.frictionResult);
  8036. } else console.warn("Point found inside convex, but did not find penetrating face!");
  8037. }
  8038. };
  8039. p.prototype[n.types.BOX | n.types.HEIGHTFIELD] = p.prototype.boxHeightfield = function(t, e, i, o, n, r, s, a, l, h, c) {
  8040. t.convexPolyhedronRepresentation.material = t.material;
  8041. t.convexPolyhedronRepresentation.collisionResponse = t.collisionResponse;
  8042. return this.convexHeightfield(t.convexPolyhedronRepresentation, e, i, o, n, r, s, a, t, e, c);
  8043. };
  8044. var Ct = new s(), At = new s(), zt = [ 0 ];
  8045. p.prototype[n.types.CONVEXPOLYHEDRON | n.types.HEIGHTFIELD] = p.prototype.convexHeightfield = function(t, e, i, o, n, r, s, l, h, c, u) {
  8046. var p = e.data, d = e.elementSize, y = t.boundingSphereRadius, f = At, v = zt, m = Ct;
  8047. a.pointToLocalFrame(o, r, i, m);
  8048. 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;
  8049. if (!(b < 0 || x < 0 || g > p.length || w > p[0].length)) {
  8050. g < 0 && (g = 0);
  8051. b < 0 && (b = 0);
  8052. w < 0 && (w = 0);
  8053. x < 0 && (x = 0);
  8054. g >= p.length && (g = p.length - 1);
  8055. b >= p.length && (b = p.length - 1);
  8056. x >= p[0].length && (x = p[0].length - 1);
  8057. w >= p[0].length && (w = p[0].length - 1);
  8058. var _ = [];
  8059. e.getRectMinMax(g, w, b, x, _);
  8060. var B = _[0], S = _[1];
  8061. if (!(m.z - y > S || m.z + y < B)) for (var E = g; E < b; E++) for (var M = w; M < x; M++) {
  8062. var C = !1;
  8063. e.getConvexTrianglePillar(E, M, !1);
  8064. a.pointToWorldFrame(o, r, e.pillarOffset, f);
  8065. 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));
  8066. if (u && C) return !0;
  8067. e.getConvexTrianglePillar(E, M, !0);
  8068. a.pointToWorldFrame(o, r, e.pillarOffset, f);
  8069. 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));
  8070. if (u && C) return !0;
  8071. }
  8072. }
  8073. };
  8074. var Ft = new s(), Rt = new s();
  8075. p.prototype[n.types.SPHERE | n.types.HEIGHTFIELD] = p.prototype.sphereHeightfield = function(t, e, i, o, n, r, s, l, h, c, u) {
  8076. var p = e.data, d = t.radius, y = e.elementSize, f = Rt, v = Ft;
  8077. a.pointToLocalFrame(o, r, i, v);
  8078. 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;
  8079. if (!(g < 0 || w < 0 || m > p.length || b > p[0].length)) {
  8080. m < 0 && (m = 0);
  8081. g < 0 && (g = 0);
  8082. b < 0 && (b = 0);
  8083. w < 0 && (w = 0);
  8084. m >= p.length && (m = p.length - 1);
  8085. g >= p.length && (g = p.length - 1);
  8086. w >= p[0].length && (w = p[0].length - 1);
  8087. b >= p[0].length && (b = p[0].length - 1);
  8088. var x = [];
  8089. e.getRectMinMax(m, b, g, w, x);
  8090. var _ = x[0], B = x[1];
  8091. 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++) {
  8092. var C = S.length, A = !1;
  8093. e.getConvexTrianglePillar(E, M, !1);
  8094. a.pointToWorldFrame(o, r, e.pillarOffset, f);
  8095. i.distanceTo(f) < e.pillarConvex.boundingSphereRadius + t.boundingSphereRadius && (A = this.sphereConvex(t, e.pillarConvex, i, f, n, r, s, l, t, e, u));
  8096. if (u && A) return !0;
  8097. e.getConvexTrianglePillar(E, M, !0);
  8098. a.pointToWorldFrame(o, r, e.pillarOffset, f);
  8099. i.distanceTo(f) < e.pillarConvex.boundingSphereRadius + t.boundingSphereRadius && (A = this.sphereConvex(t, e.pillarConvex, i, f, n, r, s, l, t, e, u));
  8100. if (u && A) return !0;
  8101. if (S.length - C > 2) return;
  8102. }
  8103. }
  8104. };
  8105. }, {
  8106. "../collision/AABB": 3,
  8107. "../collision/Ray": 10,
  8108. "../equations/ContactEquation": 20,
  8109. "../equations/FrictionEquation": 22,
  8110. "../math/Quaternion": 30,
  8111. "../math/Transform": 31,
  8112. "../math/Vec3": 32,
  8113. "../objects/Body": 33,
  8114. "../shapes/ConvexPolyhedron": 40,
  8115. "../shapes/Shape": 45,
  8116. "../solver/Solver": 49,
  8117. "../utils/Vec3Pool": 56
  8118. } ],
  8119. 58: [ function(t, e) {
  8120. e.exports = g;
  8121. t("../shapes/Shape");
  8122. var i = t("../math/Vec3"), o = t("../math/Quaternion"), n = t("../solver/GSSolver"), r = (t("../equations/ContactEquation"),
  8123. 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");
  8124. function g(t) {
  8125. t = t || {};
  8126. s.apply(this);
  8127. this.dt = -1;
  8128. this.allowSleep = !!t.allowSleep;
  8129. this.contacts = [];
  8130. this.frictionEquations = [];
  8131. this.quatNormalizeSkip = void 0 !== t.quatNormalizeSkip ? t.quatNormalizeSkip : 0;
  8132. this.quatNormalizeFast = void 0 !== t.quatNormalizeFast && t.quatNormalizeFast;
  8133. this.time = 0;
  8134. this.timeFixed = 0;
  8135. this.stepnumber = 0;
  8136. this.default_dt = 1 / 60;
  8137. this.nextId = 0;
  8138. this.gravity = new i();
  8139. t.gravity && this.gravity.copy(t.gravity);
  8140. this.broadphase = void 0 !== t.broadphase ? t.broadphase : new m();
  8141. this.bodies = [];
  8142. this.solver = void 0 !== t.solver ? t.solver : new n();
  8143. this.constraints = [];
  8144. this.narrowphase = new r(this);
  8145. this.collisionMatrix = new a();
  8146. this.collisionMatrixPrevious = new a();
  8147. this.bodyOverlapKeeper = new h();
  8148. this.shapeOverlapKeeper = new h();
  8149. this.materials = [];
  8150. this.contactmaterials = [];
  8151. this.contactMaterialTable = new d();
  8152. this.defaultMaterial = new c("default");
  8153. this.defaultContactMaterial = new u(this.defaultMaterial, this.defaultMaterial, {
  8154. friction: .3,
  8155. restitution: 0
  8156. });
  8157. this.doProfiling = !1;
  8158. this.profile = {
  8159. solve: 0,
  8160. makeContactConstraints: 0,
  8161. broadphase: 0,
  8162. integrate: 0,
  8163. narrowphase: 0
  8164. };
  8165. this.accumulator = 0;
  8166. this.subsystems = [];
  8167. this.addBodyEvent = {
  8168. type: "addBody",
  8169. body: null
  8170. };
  8171. this.removeBodyEvent = {
  8172. type: "removeBody",
  8173. body: null
  8174. };
  8175. this.idToBodyMap = {};
  8176. this.broadphase.setWorld(this);
  8177. this.substeps = 0;
  8178. this.cm = new l();
  8179. this.tm = new l();
  8180. this.triggerDic = new d();
  8181. this.oldTriggerDic = new d();
  8182. this.contactsDic = new d();
  8183. this.oldContactsDic = new d();
  8184. }
  8185. g.idToBodyMap = {};
  8186. g.idToShapeMap = {};
  8187. g.prototype = new s();
  8188. new f();
  8189. var b = new v();
  8190. g.prototype.getContactMaterial = function(t, e) {
  8191. return this.contactMaterialTable.get(t.id, e.id);
  8192. };
  8193. g.prototype.numObjects = function() {
  8194. return this.bodies.length;
  8195. };
  8196. g.prototype.collisionMatrixTick = function() {
  8197. var t = this.collisionMatrixPrevious;
  8198. this.collisionMatrixPrevious = this.collisionMatrix;
  8199. this.collisionMatrix = t;
  8200. this.collisionMatrix.reset();
  8201. this.bodyOverlapKeeper.tick();
  8202. this.shapeOverlapKeeper.tick();
  8203. };
  8204. g.prototype.add = g.prototype.addBody = function(t) {
  8205. g.SLEEPING = !1;
  8206. if (-1 === this.bodies.indexOf(t)) {
  8207. t.index = this.bodies.length;
  8208. this.bodies.push(t);
  8209. t.world = this;
  8210. t.initPosition.copy(t.position);
  8211. t.initVelocity.copy(t.velocity);
  8212. t.timeLastSleepy = this.time;
  8213. if (t instanceof p) {
  8214. t.initAngularVelocity.copy(t.angularVelocity);
  8215. t.initQuaternion.copy(t.quaternion);
  8216. }
  8217. this.collisionMatrix.setNumObjects(this.bodies.length);
  8218. this.addBodyEvent.body = t;
  8219. this.cm.setNumObjects(this.bodies.length);
  8220. g.idToBodyMap[t.id] = t;
  8221. this.dispatchEvent(this.addBodyEvent);
  8222. }
  8223. };
  8224. g.prototype.addConstraint = function(t) {
  8225. g.SLEEPING = !1;
  8226. this.constraints.push(t);
  8227. };
  8228. g.prototype.removeConstraint = function(t) {
  8229. g.SLEEPING = !1;
  8230. var e = this.constraints.indexOf(t);
  8231. -1 !== e && this.constraints.splice(e, 1);
  8232. };
  8233. g.prototype.rayTest = function(t, e, i) {
  8234. i instanceof y ? this.raycastClosest(t, e, {
  8235. skipBackfaces: !0
  8236. }, i) : this.raycastAll(t, e, {
  8237. skipBackfaces: !0
  8238. }, i);
  8239. };
  8240. g.prototype.raycastAll = function(t, e, i, o) {
  8241. i.mode = v.ALL;
  8242. i.from = t;
  8243. i.to = e;
  8244. i.callback = o;
  8245. return b.intersectWorld(this, i);
  8246. };
  8247. g.prototype.raycastAny = function(t, e, i, o) {
  8248. i.mode = v.ANY;
  8249. i.from = t;
  8250. i.to = e;
  8251. i.result = o;
  8252. return b.intersectWorld(this, i);
  8253. };
  8254. g.prototype.raycastClosest = function(t, e, i, o) {
  8255. i.mode = v.CLOSEST;
  8256. i.from = t;
  8257. i.to = e;
  8258. i.result = o;
  8259. return b.intersectWorld(this, i);
  8260. };
  8261. g.prototype.remove = function(t) {
  8262. g.SLEEPING = !1;
  8263. t.world = null;
  8264. var e = this.bodies.length - 1, i = this.bodies, o = i.indexOf(t);
  8265. if (-1 !== o) {
  8266. i.splice(o, 1);
  8267. for (var n = 0; n !== i.length; n++) i[n].index = n;
  8268. this.collisionMatrix.setNumObjects(e);
  8269. this.removeBodyEvent.body = t;
  8270. delete g.idToBodyMap[t.id];
  8271. this.cm.setNumObjects(e);
  8272. this.dispatchEvent(this.removeBodyEvent);
  8273. }
  8274. };
  8275. g.prototype.removeBody = g.prototype.remove;
  8276. g.prototype.getBodyById = function(t) {
  8277. return g.idToBodyMap[t];
  8278. };
  8279. g.prototype.getShapeById = function(t) {
  8280. return g.idToShapeMap[t];
  8281. };
  8282. g.prototype.addMaterial = function(t) {
  8283. this.materials.push(t);
  8284. };
  8285. g.prototype.addContactMaterial = function(t) {
  8286. this.contactmaterials.push(t);
  8287. this.contactMaterialTable.set(t.materials[0].id, t.materials[1].id, t);
  8288. };
  8289. "undefined" == typeof performance && (performance = {});
  8290. if (!performance.now) {
  8291. var w = Date.now();
  8292. performance.timing && performance.timing.navigationStart && (w = performance.timing.navigationStart);
  8293. performance.now = function() {
  8294. return Date.now() - w;
  8295. };
  8296. }
  8297. new i();
  8298. g.prototype.step = function(t, e, i) {
  8299. i = i || 10;
  8300. if (0 === (e = e || 0)) {
  8301. this.internalStep(t);
  8302. this.time += t;
  8303. this.substeps = 1;
  8304. } else {
  8305. this.accumulator += e;
  8306. this.substeps = 0;
  8307. for (;this.accumulator >= t && this.substeps < i; ) {
  8308. this.internalStep(t);
  8309. this.accumulator -= t;
  8310. this.substeps++;
  8311. }
  8312. for (var o = this.accumulator % t / t, n = 0; n !== this.bodies.length; n++) {
  8313. var r = this.bodies[n];
  8314. r.previousPosition.lerp(r.position, o, r.interpolatedPosition);
  8315. r.previousQuaternion.slerp(r.quaternion, o, r.interpolatedQuaternion);
  8316. r.previousQuaternion.normalize();
  8317. }
  8318. this.time += e;
  8319. }
  8320. };
  8321. var x, _, B, S, E, M, C = {
  8322. type: "postStep"
  8323. }, A = {
  8324. type: "preStep"
  8325. }, z = {
  8326. type: "collide",
  8327. body: null,
  8328. contact: null
  8329. }, F = [], R = [], T = [], P = [];
  8330. new i(), new i(), new i(), new i(), new i(), new i(), new i(), new i(), new i(),
  8331. new o(), new o(), new o(), new i();
  8332. g.prototype.internalStep = function(t) {
  8333. this.dt = t;
  8334. 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(),
  8335. l.x), v = l.y, m = l.z, b = 0;
  8336. h && (e = performance.now());
  8337. for (b = 0; b !== r; b++) if ((V = s[b]).useGravity && V.type === u) {
  8338. var w = V.force, x = V.mass;
  8339. w.x += x * f;
  8340. w.y += x * v;
  8341. w.z += x * m;
  8342. }
  8343. b = 0;
  8344. for (var _ = this.subsystems.length; b !== _; b++) this.subsystems[b].update();
  8345. h && (e = performance.now());
  8346. o.length = 0;
  8347. n.length = 0;
  8348. this.broadphase.collisionPairs(this, o, n);
  8349. h && (c.broadphase = performance.now() - e);
  8350. var B = d.length;
  8351. 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]) {
  8352. o.splice(S, 1);
  8353. n.splice(S, 1);
  8354. }
  8355. this.collisionMatrixTick();
  8356. h && (e = performance.now());
  8357. var E = F, M = i.length;
  8358. for (b = 0; b !== M; b++) E.push(i[b]);
  8359. i.length = 0;
  8360. var q = this.frictionEquations.length;
  8361. for (b = 0; b !== q; b++) y.push(this.frictionEquations[b]);
  8362. this.frictionEquations.length = 0;
  8363. this.narrowphase.getContacts(o, n, this, i, E, this.frictionEquations, y);
  8364. if (0 != i.length || !g.SLEEPING) {
  8365. h && (c.narrowphase = performance.now() - e);
  8366. h && (e = performance.now());
  8367. for (b = 0; b < this.frictionEquations.length; b++) a.addEquation(this.frictionEquations[b]);
  8368. for (var I = i.length, O = 0; O !== I; O++) {
  8369. var V = (L = i[O]).bi, j = L.bj, k = L.si, N = L.sj;
  8370. 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);
  8371. a.addEquation(L);
  8372. 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);
  8373. 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);
  8374. this.collisionMatrix.set(V, j, !0);
  8375. if (!this.collisionMatrixPrevious.get(V, j)) {
  8376. z.body = j;
  8377. z.contact = L;
  8378. V.dispatchEvent(z);
  8379. z.body = V;
  8380. j.dispatchEvent(z);
  8381. }
  8382. this.bodyOverlapKeeper.set(V.id, j.id);
  8383. this.shapeOverlapKeeper.set(k.id, N.id);
  8384. }
  8385. this.emitContactEvents();
  8386. if (h) {
  8387. c.makeContactConstraints = performance.now() - e;
  8388. e = performance.now();
  8389. }
  8390. for (b = 0; b !== r; b++) if ((V = s[b])._wakeUpAfterNarrowphase) {
  8391. V.wakeUp();
  8392. V._wakeUpAfterNarrowphase = !1;
  8393. }
  8394. B = d.length;
  8395. for (b = 0; b !== B; b++) {
  8396. var L;
  8397. (L = d[b]).update();
  8398. S = 0;
  8399. for (var W = L.equations.length; S !== W; S++) {
  8400. var D = L.equations[S];
  8401. a.addEquation(D);
  8402. }
  8403. }
  8404. a.solve(t, this);
  8405. h && (c.solve = performance.now() - e);
  8406. a.removeAllEquations();
  8407. var U = Math.pow;
  8408. for (b = 0; b !== r; b++) if ((V = s[b]).type & u) {
  8409. var G = U(1 - V.linearDamping, t), H = V.velocity;
  8410. H.mult(G, H);
  8411. var K = V.angularVelocity;
  8412. if (K) {
  8413. var Q = U(1 - V.angularDamping, t);
  8414. K.mult(Q, K);
  8415. }
  8416. }
  8417. this.dispatchEvent(A);
  8418. for (b = 0; b !== r; b++) (V = s[b]).preStep && V.preStep.call(V);
  8419. h && (e = performance.now());
  8420. var X = this.stepnumber % (this.quatNormalizeSkip + 1) == 0, Y = this.quatNormalizeFast;
  8421. for (b = 0; b !== r; b++) s[b].integrate(t, X, Y);
  8422. this.clearForces();
  8423. this.broadphase.dirty = !0;
  8424. h && (c.integrate = performance.now() - e);
  8425. this.time += t;
  8426. this.timeFixed += t;
  8427. this.stepnumber += 1;
  8428. this.dispatchEvent(C);
  8429. for (b = 0; b !== r; b++) {
  8430. var Z = (V = s[b]).postStep;
  8431. Z && Z.call(V);
  8432. }
  8433. if (this.allowSleep) {
  8434. for (b = 0; b !== r; b++) s[b].sleepTick(this.time);
  8435. g.SLEEPING = !0;
  8436. for (b = 0; b !== r; b++) if ((V = s[b]).type != p.STATIC && !V.isSleeping()) {
  8437. g.SLEEPING = !1;
  8438. break;
  8439. }
  8440. } else g.SLEEPING = !1;
  8441. }
  8442. };
  8443. g.prototype.emitContactEvents = (x = [], _ = [], B = {
  8444. type: "beginContact",
  8445. bodyA: null,
  8446. bodyB: null
  8447. }, S = {
  8448. type: "endContact",
  8449. bodyA: null,
  8450. bodyB: null
  8451. }, E = {
  8452. type: "beginShapeContact",
  8453. bodyA: null,
  8454. bodyB: null,
  8455. shapeA: null,
  8456. shapeB: null
  8457. }, M = {
  8458. type: "endShapeContact",
  8459. bodyA: null,
  8460. bodyB: null,
  8461. shapeA: null,
  8462. shapeB: null
  8463. }, function() {
  8464. var t = this.hasAnyEventListener("beginContact"), e = this.hasAnyEventListener("endContact");
  8465. (t || e) && this.bodyOverlapKeeper.getDiff(x, _);
  8466. if (t) {
  8467. for (var i = 0, o = x.length; i < o; i += 2) {
  8468. B.bodyA = this.getBodyById(x[i]);
  8469. B.bodyB = this.getBodyById(x[i + 1]);
  8470. this.dispatchEvent(B);
  8471. }
  8472. B.bodyA = B.bodyB = null;
  8473. }
  8474. if (e) {
  8475. for (i = 0, o = _.length; i < o; i += 2) {
  8476. S.bodyA = this.getBodyById(_[i]);
  8477. S.bodyB = this.getBodyById(_[i + 1]);
  8478. this.dispatchEvent(S);
  8479. }
  8480. S.bodyA = S.bodyB = null;
  8481. }
  8482. x.length = _.length = 0;
  8483. var n = this.hasAnyEventListener("beginShapeContact"), r = this.hasAnyEventListener("endShapeContact");
  8484. (n || r) && this.shapeOverlapKeeper.getDiff(x, _);
  8485. if (n) {
  8486. for (i = 0, o = x.length; i < o; i += 2) {
  8487. var s = this.getShapeById(x[i]), a = this.getShapeById(x[i + 1]);
  8488. E.shapeA = s;
  8489. E.shapeB = a;
  8490. E.bodyA = s.body;
  8491. E.bodyB = a.body;
  8492. this.dispatchEvent(E);
  8493. }
  8494. E.bodyA = E.bodyB = E.shapeA = E.shapeB = null;
  8495. }
  8496. if (r) {
  8497. for (i = 0, o = _.length; i < o; i += 2) {
  8498. s = this.getShapeById(_[i]), a = this.getShapeById(_[i + 1]);
  8499. M.shapeA = s;
  8500. M.shapeB = a;
  8501. M.bodyA = s.body;
  8502. M.bodyB = a.body;
  8503. this.dispatchEvent(M);
  8504. }
  8505. M.bodyA = M.bodyB = M.shapeA = M.shapeB = null;
  8506. }
  8507. });
  8508. g.prototype.clearForces = function() {
  8509. for (var t = this.bodies, e = t.length, i = 0; i !== e; i++) {
  8510. var o = t[i];
  8511. o.force, o.torque;
  8512. o.force.set(0, 0, 0);
  8513. o.torque.set(0, 0, 0);
  8514. }
  8515. };
  8516. var q = {
  8517. type: "cc-trigger",
  8518. event: "",
  8519. selfBody: null,
  8520. otherBody: null,
  8521. selfShape: null,
  8522. otherShape: null
  8523. }, I = {
  8524. type: "cc-collide",
  8525. event: "",
  8526. body: null,
  8527. selfShape: null,
  8528. otherShape: null,
  8529. contacts: null
  8530. }, O = [];
  8531. g.prototype.emitTriggeredEvents = function() {
  8532. if (0 != this.substeps) {
  8533. for (var t, e, i = this.triggerDic.getLength(); i--; ) {
  8534. t = this.triggerDic.getKeyByIndex(i);
  8535. if (null != (e = this.triggerDic.getDataByKey(t))) {
  8536. var o = e.si, n = e.sj;
  8537. if (this.tm.get(o, n)) q.event = "onTriggerStay"; else {
  8538. this.tm.set(o, n, !0);
  8539. q.event = "onTriggerEnter";
  8540. }
  8541. q.selfShape = o;
  8542. q.otherShape = n;
  8543. q.selfBody = o.body;
  8544. q.otherBody = n.body;
  8545. o.dispatchEvent(q);
  8546. q.selfShape = n;
  8547. q.otherShape = o;
  8548. q.selfBody = n.body;
  8549. q.otherBody = o.body;
  8550. n.dispatchEvent(q);
  8551. }
  8552. }
  8553. i = this.oldTriggerDic.getLength();
  8554. for (;i > 0; ) {
  8555. i--;
  8556. t = this.oldTriggerDic.getKeyByIndex(i);
  8557. if (null == this.triggerDic.getDataByKey(t) && null != (e = this.oldTriggerDic.getDataByKey(t))) {
  8558. o = e.si, n = e.sj;
  8559. this.tm.set(o, n, !1);
  8560. this.oldTriggerDic.del(o.id, n.id) && i--;
  8561. q.event = "onTriggerExit";
  8562. q.selfShape = o;
  8563. q.otherShape = n;
  8564. q.selfBody = o.body;
  8565. q.otherBody = n.body;
  8566. o.dispatchEvent(q);
  8567. q.selfShape = n;
  8568. q.otherShape = o;
  8569. q.selfBody = n.body;
  8570. q.otherBody = o.body;
  8571. n.dispatchEvent(q);
  8572. }
  8573. }
  8574. this.triggerDic.reset();
  8575. }
  8576. };
  8577. g.prototype.emitCollisionEvents = function() {
  8578. if (0 != this.substeps) {
  8579. for (var t, e, i = this.contacts, o = this.contacts.length; o--; ) {
  8580. var n = (c = i[o]).si, r = c.sj, s = this.contactsDic.get(n.id, r.id);
  8581. null == s && (s = this.contactsDic.set(n.id, r.id, []));
  8582. s.push(c);
  8583. }
  8584. for (o = this.contactsDic.getLength(); o--; ) {
  8585. t = this.contactsDic.getKeyByIndex(o);
  8586. if (null != (e = this.contactsDic.getDataByKey(t))) {
  8587. n = e[0].si, r = e[0].sj;
  8588. var a = n.body, l = r.body;
  8589. if (this.cm.get(a, l)) I.event = "onCollisionStay"; else {
  8590. this.cm.set(a, l, !0);
  8591. I.event = "onCollisionEnter";
  8592. }
  8593. I.bi = a;
  8594. I.contact = e[0];
  8595. I.contacts = e;
  8596. I.body = l;
  8597. I.selfShape = n;
  8598. I.otherShape = r;
  8599. a.dispatchEvent(I);
  8600. I.body = a;
  8601. I.selfShape = r;
  8602. I.otherShape = n;
  8603. l.dispatchEvent(I);
  8604. }
  8605. }
  8606. var h = O;
  8607. for (o = h.length; o--; ) {
  8608. var c;
  8609. n = (c = h[o]).si, r = c.sj;
  8610. null == this.oldContactsDic.get(n.id, r.id) && this.oldContactsDic.set(n.id, r.id, c);
  8611. }
  8612. o = this.oldContactsDic.getLength();
  8613. for (;o--; ) {
  8614. t = this.oldContactsDic.getKeyByIndex(o);
  8615. if (null == this.contactsDic.getDataByKey(t)) {
  8616. n = (e = this.oldContactsDic.getDataByKey(t)).si, r = e.sj, a = n.body, l = r.body;
  8617. if (this.cm.get(a, l) && (!a.isSleeping() || !l.isSleeping())) {
  8618. this.cm.set(a, l, !1);
  8619. I.bi = a;
  8620. I.contact = e;
  8621. I.event = "onCollisionExit";
  8622. I.body = l;
  8623. I.selfShape = n;
  8624. I.otherShape = r;
  8625. I.contacts.length = 0;
  8626. I.contacts.push(e);
  8627. a.dispatchEvent(I);
  8628. I.body = a;
  8629. I.selfShape = r;
  8630. I.otherShape = n;
  8631. l.dispatchEvent(I);
  8632. }
  8633. }
  8634. }
  8635. this.contactsDic.reset();
  8636. this.oldContactsDic.reset();
  8637. F = O;
  8638. O = this.contacts.slice();
  8639. this.contacts.length = 0;
  8640. }
  8641. };
  8642. }, {
  8643. "../collision/AABB": 3,
  8644. "../collision/ArrayCollisionMatrix": 4,
  8645. "../collision/NaiveBroadphase": 7,
  8646. "../collision/ObjectCollisionMatrix": 8,
  8647. "../collision/OverlapKeeper": 9,
  8648. "../collision/Ray": 10,
  8649. "../collision/RaycastResult": 11,
  8650. "../equations/ContactEquation": 20,
  8651. "../equations/FrictionEquation": 22,
  8652. "../material/ContactMaterial": 25,
  8653. "../material/Material": 26,
  8654. "../math/Quaternion": 30,
  8655. "../math/Vec3": 32,
  8656. "../objects/Body": 33,
  8657. "../shapes/Shape": 45,
  8658. "../solver/GSSolver": 48,
  8659. "../utils/EventTarget": 51,
  8660. "../utils/TupleDictionary": 54,
  8661. "./Narrowphase": 57
  8662. } ]
  8663. }, {}, [ 2 ])(2);
  8664. });
  8665. }).call(this, "undefined" != typeof global ? global : "undefined" != typeof self ? self : "undefined" != typeof window ? window : {});
  8666. }, {} ]
  8667. }, {}, [ 10, 9 ]);