OimoPhysics.js 1.1 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071
  1. // Generated by Haxe 4.2.0
  2. var oimo = oimo || {};
  3. if(!oimo.collision) oimo.collision = {};
  4. if(!oimo.collision.broadphase) oimo.collision.broadphase = {};
  5. oimo.collision.broadphase.BroadPhase = class oimo_collision_broadphase_BroadPhase {
  6. constructor(type) {
  7. this._type = type;
  8. this._numProxies = 0;
  9. this._proxyList = null;
  10. this._proxyListLast = null;
  11. this._proxyPairList = null;
  12. this._incremental = false;
  13. this._testCount = 0;
  14. this._proxyPairPool = null;
  15. this._idCount = 0;
  16. this._convexSweep = new oimo.collision.broadphase._BroadPhase.ConvexSweepGeometry();
  17. this._aabb = new oimo.collision.broadphase._BroadPhase.AabbGeometry();
  18. this.identity = new oimo.common.Transform();
  19. this.zero = new oimo.common.Vec3();
  20. this.rayCastHit = new oimo.collision.geometry.RayCastHit();
  21. }
  22. createProxy(userData,aabb) {
  23. return null;
  24. }
  25. destroyProxy(proxy) {
  26. }
  27. moveProxy(proxy,aabb,displacement) {
  28. }
  29. isOverlapping(proxy1,proxy2) {
  30. if(proxy1._aabbMinX < proxy2._aabbMaxX && proxy1._aabbMaxX > proxy2._aabbMinX && proxy1._aabbMinY < proxy2._aabbMaxY && proxy1._aabbMaxY > proxy2._aabbMinY && proxy1._aabbMinZ < proxy2._aabbMaxZ) {
  31. return proxy1._aabbMaxZ > proxy2._aabbMinZ;
  32. } else {
  33. return false;
  34. }
  35. }
  36. collectPairs() {
  37. }
  38. getProxyPairList() {
  39. return this._proxyPairList;
  40. }
  41. isIncremental() {
  42. return this._incremental;
  43. }
  44. getTestCount() {
  45. return this._testCount;
  46. }
  47. rayCast(begin,end,callback) {
  48. }
  49. convexCast(convex,begin,translation,callback) {
  50. }
  51. aabbTest(aabb,callback) {
  52. }
  53. }
  54. if(!oimo.collision.geometry) oimo.collision.geometry = {};
  55. oimo.collision.geometry.Geometry = class oimo_collision_geometry_Geometry {
  56. constructor(type) {
  57. this._type = type;
  58. this._volume = 0;
  59. }
  60. _updateMass() {
  61. }
  62. _computeAabb(aabb,tf) {
  63. }
  64. _rayCastLocal(beginX,beginY,beginZ,endX,endY,endZ,hit) {
  65. return false;
  66. }
  67. getType() {
  68. return this._type;
  69. }
  70. getVolume() {
  71. return this._volume;
  72. }
  73. rayCast(begin,end,transform,hit) {
  74. let beginLocalX;
  75. let beginLocalY;
  76. let beginLocalZ;
  77. let endLocalX;
  78. let endLocalY;
  79. let endLocalZ;
  80. beginLocalX = begin.x;
  81. beginLocalY = begin.y;
  82. beginLocalZ = begin.z;
  83. endLocalX = end.x;
  84. endLocalY = end.y;
  85. endLocalZ = end.z;
  86. beginLocalX -= transform._positionX;
  87. beginLocalY -= transform._positionY;
  88. beginLocalZ -= transform._positionZ;
  89. endLocalX -= transform._positionX;
  90. endLocalY -= transform._positionY;
  91. endLocalZ -= transform._positionZ;
  92. let __tmp__X;
  93. let __tmp__Y;
  94. let __tmp__Z;
  95. __tmp__X = transform._rotation00 * beginLocalX + transform._rotation10 * beginLocalY + transform._rotation20 * beginLocalZ;
  96. __tmp__Y = transform._rotation01 * beginLocalX + transform._rotation11 * beginLocalY + transform._rotation21 * beginLocalZ;
  97. __tmp__Z = transform._rotation02 * beginLocalX + transform._rotation12 * beginLocalY + transform._rotation22 * beginLocalZ;
  98. beginLocalX = __tmp__X;
  99. beginLocalY = __tmp__Y;
  100. beginLocalZ = __tmp__Z;
  101. let __tmp__X1;
  102. let __tmp__Y1;
  103. let __tmp__Z1;
  104. __tmp__X1 = transform._rotation00 * endLocalX + transform._rotation10 * endLocalY + transform._rotation20 * endLocalZ;
  105. __tmp__Y1 = transform._rotation01 * endLocalX + transform._rotation11 * endLocalY + transform._rotation21 * endLocalZ;
  106. __tmp__Z1 = transform._rotation02 * endLocalX + transform._rotation12 * endLocalY + transform._rotation22 * endLocalZ;
  107. endLocalX = __tmp__X1;
  108. endLocalY = __tmp__Y1;
  109. endLocalZ = __tmp__Z1;
  110. if(this._rayCastLocal(beginLocalX,beginLocalY,beginLocalZ,endLocalX,endLocalY,endLocalZ,hit)) {
  111. let localPosX;
  112. let localPosY;
  113. let localPosZ;
  114. let localNormalX;
  115. let localNormalY;
  116. let localNormalZ;
  117. let v = hit.position;
  118. localPosX = v.x;
  119. localPosY = v.y;
  120. localPosZ = v.z;
  121. let v1 = hit.normal;
  122. localNormalX = v1.x;
  123. localNormalY = v1.y;
  124. localNormalZ = v1.z;
  125. let __tmp__X;
  126. let __tmp__Y;
  127. let __tmp__Z;
  128. __tmp__X = transform._rotation00 * localPosX + transform._rotation01 * localPosY + transform._rotation02 * localPosZ;
  129. __tmp__Y = transform._rotation10 * localPosX + transform._rotation11 * localPosY + transform._rotation12 * localPosZ;
  130. __tmp__Z = transform._rotation20 * localPosX + transform._rotation21 * localPosY + transform._rotation22 * localPosZ;
  131. localPosX = __tmp__X;
  132. localPosY = __tmp__Y;
  133. localPosZ = __tmp__Z;
  134. let __tmp__X1;
  135. let __tmp__Y1;
  136. let __tmp__Z1;
  137. __tmp__X1 = transform._rotation00 * localNormalX + transform._rotation01 * localNormalY + transform._rotation02 * localNormalZ;
  138. __tmp__Y1 = transform._rotation10 * localNormalX + transform._rotation11 * localNormalY + transform._rotation12 * localNormalZ;
  139. __tmp__Z1 = transform._rotation20 * localNormalX + transform._rotation21 * localNormalY + transform._rotation22 * localNormalZ;
  140. localNormalX = __tmp__X1;
  141. localNormalY = __tmp__Y1;
  142. localNormalZ = __tmp__Z1;
  143. localPosX += transform._positionX;
  144. localPosY += transform._positionY;
  145. localPosZ += transform._positionZ;
  146. let v2 = hit.position;
  147. v2.x = localPosX;
  148. v2.y = localPosY;
  149. v2.z = localPosZ;
  150. let v3 = hit.normal;
  151. v3.x = localNormalX;
  152. v3.y = localNormalY;
  153. v3.z = localNormalZ;
  154. return true;
  155. }
  156. return false;
  157. }
  158. }
  159. oimo.collision.geometry.ConvexGeometry = class oimo_collision_geometry_ConvexGeometry extends oimo.collision.geometry.Geometry {
  160. constructor(type) {
  161. super(type);
  162. this._gjkMargin = oimo.common.Setting.defaultGJKMargin;
  163. this._useGjkRayCast = false;
  164. }
  165. getGjkMergin() {
  166. return this._gjkMargin;
  167. }
  168. setGjkMergin(gjkMergin) {
  169. if(gjkMergin < 0) {
  170. gjkMergin = 0;
  171. }
  172. this._gjkMargin = gjkMergin;
  173. }
  174. computeLocalSupportingVertex(dir,out) {
  175. }
  176. rayCast(begin,end,transform,hit) {
  177. if(this._useGjkRayCast) {
  178. return oimo.collision.narrowphase.detector.gjkepa.GjkEpa.instance.rayCast(this,transform,begin,end,hit);
  179. } else {
  180. return super.rayCast(begin,end,transform,hit);
  181. }
  182. }
  183. }
  184. if(!oimo.collision.broadphase._BroadPhase) oimo.collision.broadphase._BroadPhase = {};
  185. oimo.collision.broadphase._BroadPhase.ConvexSweepGeometry = class oimo_collision_broadphase__$BroadPhase_ConvexSweepGeometry extends oimo.collision.geometry.ConvexGeometry {
  186. constructor() {
  187. super(-1);
  188. }
  189. init(c,transform,translation) {
  190. this.c = c;
  191. let trX;
  192. let trY;
  193. let trZ;
  194. trX = translation.x;
  195. trY = translation.y;
  196. trZ = translation.z;
  197. let localTrX;
  198. let localTrY;
  199. let localTrZ;
  200. let __tmp__X;
  201. let __tmp__Y;
  202. let __tmp__Z;
  203. __tmp__X = transform._rotation00 * trX + transform._rotation10 * trY + transform._rotation20 * trZ;
  204. __tmp__Y = transform._rotation01 * trX + transform._rotation11 * trY + transform._rotation21 * trZ;
  205. __tmp__Z = transform._rotation02 * trX + transform._rotation12 * trY + transform._rotation22 * trZ;
  206. localTrX = __tmp__X;
  207. localTrY = __tmp__Y;
  208. localTrZ = __tmp__Z;
  209. this.localTranslation = new oimo.common.Vec3();
  210. let v = this.localTranslation;
  211. v.x = localTrX;
  212. v.y = localTrY;
  213. v.z = localTrZ;
  214. this._gjkMargin = c._gjkMargin;
  215. }
  216. computeLocalSupportingVertex(dir,out) {
  217. this.c.computeLocalSupportingVertex(dir,out);
  218. let v = this.localTranslation;
  219. if(dir.x * v.x + dir.y * v.y + dir.z * v.z > 0) {
  220. let v = this.localTranslation;
  221. out.x += v.x;
  222. out.y += v.y;
  223. out.z += v.z;
  224. }
  225. }
  226. }
  227. oimo.collision.broadphase._BroadPhase.AabbGeometry = class oimo_collision_broadphase__$BroadPhase_AabbGeometry extends oimo.collision.geometry.ConvexGeometry {
  228. constructor() {
  229. super(-1);
  230. this.min = new oimo.common.Vec3();
  231. this.max = new oimo.common.Vec3();
  232. }
  233. computeLocalSupportingVertex(dir,out) {
  234. out.x = dir.x > 0 ? this.max.x : this.min.x;
  235. out.y = dir.y > 0 ? this.max.y : this.min.y;
  236. out.z = dir.z > 0 ? this.max.z : this.min.z;
  237. }
  238. }
  239. oimo.collision.broadphase.BroadPhaseProxyCallback = class oimo_collision_broadphase_BroadPhaseProxyCallback {
  240. constructor() {
  241. }
  242. process(proxy) {
  243. }
  244. }
  245. oimo.collision.broadphase.BroadPhaseType = class oimo_collision_broadphase_BroadPhaseType {
  246. }
  247. oimo.collision.broadphase.Proxy = class oimo_collision_broadphase_Proxy {
  248. constructor(userData,id) {
  249. this.userData = userData;
  250. this._id = id;
  251. this._prev = null;
  252. this._next = null;
  253. this._aabbMinX = 0;
  254. this._aabbMinY = 0;
  255. this._aabbMinZ = 0;
  256. this._aabbMaxX = 0;
  257. this._aabbMaxY = 0;
  258. this._aabbMaxZ = 0;
  259. }
  260. getId() {
  261. return this._id;
  262. }
  263. getFatAabb() {
  264. let aabb = new oimo.collision.geometry.Aabb();
  265. aabb._minX = this._aabbMinX;
  266. aabb._minY = this._aabbMinY;
  267. aabb._minZ = this._aabbMinZ;
  268. aabb._maxX = this._aabbMaxX;
  269. aabb._maxY = this._aabbMaxY;
  270. aabb._maxZ = this._aabbMaxZ;
  271. return aabb;
  272. }
  273. getFatAabbTo(aabb) {
  274. aabb._minX = this._aabbMinX;
  275. aabb._minY = this._aabbMinY;
  276. aabb._minZ = this._aabbMinZ;
  277. aabb._maxX = this._aabbMaxX;
  278. aabb._maxY = this._aabbMaxY;
  279. aabb._maxZ = this._aabbMaxZ;
  280. }
  281. }
  282. oimo.collision.broadphase.ProxyPair = class oimo_collision_broadphase_ProxyPair {
  283. constructor() {
  284. this._p1 = null;
  285. this._p2 = null;
  286. }
  287. getProxy1() {
  288. return this._p1;
  289. }
  290. getProxy2() {
  291. return this._p2;
  292. }
  293. getNext() {
  294. return this._next;
  295. }
  296. }
  297. if(!oimo.collision.broadphase.bruteforce) oimo.collision.broadphase.bruteforce = {};
  298. oimo.collision.broadphase.bruteforce.BruteForceBroadPhase = class oimo_collision_broadphase_bruteforce_BruteForceBroadPhase extends oimo.collision.broadphase.BroadPhase {
  299. constructor() {
  300. super(1);
  301. this._incremental = false;
  302. }
  303. createProxy(userData,aabb) {
  304. let proxy = new oimo.collision.broadphase.Proxy(userData,this._idCount++);
  305. this._numProxies++;
  306. if(this._proxyList == null) {
  307. this._proxyList = proxy;
  308. this._proxyListLast = proxy;
  309. } else {
  310. this._proxyListLast._next = proxy;
  311. proxy._prev = this._proxyListLast;
  312. this._proxyListLast = proxy;
  313. }
  314. proxy._aabbMinX = aabb._minX;
  315. proxy._aabbMinY = aabb._minY;
  316. proxy._aabbMinZ = aabb._minZ;
  317. proxy._aabbMaxX = aabb._maxX;
  318. proxy._aabbMaxY = aabb._maxY;
  319. proxy._aabbMaxZ = aabb._maxZ;
  320. return proxy;
  321. }
  322. destroyProxy(proxy) {
  323. this._numProxies--;
  324. let prev = proxy._prev;
  325. let next = proxy._next;
  326. if(prev != null) {
  327. prev._next = next;
  328. }
  329. if(next != null) {
  330. next._prev = prev;
  331. }
  332. if(proxy == this._proxyList) {
  333. this._proxyList = this._proxyList._next;
  334. }
  335. if(proxy == this._proxyListLast) {
  336. this._proxyListLast = this._proxyListLast._prev;
  337. }
  338. proxy._next = null;
  339. proxy._prev = null;
  340. proxy.userData = null;
  341. }
  342. moveProxy(proxy,aabb,dislacement) {
  343. proxy._aabbMinX = aabb._minX;
  344. proxy._aabbMinY = aabb._minY;
  345. proxy._aabbMinZ = aabb._minZ;
  346. proxy._aabbMaxX = aabb._maxX;
  347. proxy._aabbMaxY = aabb._maxY;
  348. proxy._aabbMaxZ = aabb._maxZ;
  349. }
  350. collectPairs() {
  351. let p = this._proxyPairList;
  352. if(p != null) {
  353. while(true) {
  354. p._p1 = null;
  355. p._p2 = null;
  356. p = p._next;
  357. if(!(p != null)) {
  358. break;
  359. }
  360. }
  361. this._proxyPairList._next = this._proxyPairPool;
  362. this._proxyPairPool = this._proxyPairList;
  363. this._proxyPairList = null;
  364. }
  365. this._testCount = 0;
  366. let p1 = this._proxyList;
  367. while(p1 != null) {
  368. let n = p1._next;
  369. let p2 = p1._next;
  370. while(p2 != null) {
  371. let n = p2._next;
  372. this._testCount++;
  373. if(p1._aabbMinX < p2._aabbMaxX && p1._aabbMaxX > p2._aabbMinX && p1._aabbMinY < p2._aabbMaxY && p1._aabbMaxY > p2._aabbMinY && p1._aabbMinZ < p2._aabbMaxZ && p1._aabbMaxZ > p2._aabbMinZ) {
  374. let first = this._proxyPairPool;
  375. if(first != null) {
  376. this._proxyPairPool = first._next;
  377. first._next = null;
  378. } else {
  379. first = new oimo.collision.broadphase.ProxyPair();
  380. }
  381. let pp = first;
  382. if(this._proxyPairList == null) {
  383. this._proxyPairList = pp;
  384. } else {
  385. pp._next = this._proxyPairList;
  386. this._proxyPairList = pp;
  387. }
  388. pp._p1 = p1;
  389. pp._p2 = p2;
  390. }
  391. p2 = n;
  392. }
  393. p1 = n;
  394. }
  395. }
  396. rayCast(begin,end,callback) {
  397. let p1X;
  398. let p1Y;
  399. let p1Z;
  400. let p2X;
  401. let p2Y;
  402. let p2Z;
  403. p1X = begin.x;
  404. p1Y = begin.y;
  405. p1Z = begin.z;
  406. p2X = end.x;
  407. p2Y = end.y;
  408. p2Z = end.z;
  409. let p = this._proxyList;
  410. while(p != null) {
  411. let n = p._next;
  412. let x1 = p1X;
  413. let y1 = p1Y;
  414. let z1 = p1Z;
  415. let x2 = p2X;
  416. let y2 = p2Y;
  417. let z2 = p2Z;
  418. let pminx = p._aabbMinX;
  419. let pminy = p._aabbMinY;
  420. let pminz = p._aabbMinZ;
  421. let pmaxx = p._aabbMaxX;
  422. let pmaxy = p._aabbMaxY;
  423. let pmaxz = p._aabbMaxZ;
  424. let tmp;
  425. if(pminx > (x1 > x2 ? x1 : x2) || pmaxx < (x1 < x2 ? x1 : x2) || pminy > (y1 > y2 ? y1 : y2) || pmaxy < (y1 < y2 ? y1 : y2) || pminz > (z1 > z2 ? z1 : z2) || pmaxz < (z1 < z2 ? z1 : z2)) {
  426. tmp = false;
  427. } else {
  428. let dx = x2 - x1;
  429. let dy = y2 - y1;
  430. let dz = z2 - z1;
  431. let adx = dx < 0 ? -dx : dx;
  432. let ady = dy < 0 ? -dy : dy;
  433. let adz = dz < 0 ? -dz : dz;
  434. let pextx = (pmaxx - pminx) * 0.5;
  435. let pexty = (pmaxy - pminy) * 0.5;
  436. let pextz = (pmaxz - pminz) * 0.5;
  437. let cpx = x1 - (pmaxx + pminx) * 0.5;
  438. let cpy = y1 - (pmaxy + pminy) * 0.5;
  439. let cpz = z1 - (pmaxz + pminz) * 0.5;
  440. let tmp1;
  441. let tmp2;
  442. let x = cpy * dz - cpz * dy;
  443. if(!((x < 0 ? -x : x) - (pexty * adz + pextz * ady) > 0)) {
  444. let x = cpz * dx - cpx * dz;
  445. tmp2 = (x < 0 ? -x : x) - (pextz * adx + pextx * adz) > 0;
  446. } else {
  447. tmp2 = true;
  448. }
  449. if(!tmp2) {
  450. let x = cpx * dy - cpy * dx;
  451. tmp1 = (x < 0 ? -x : x) - (pextx * ady + pexty * adx) > 0;
  452. } else {
  453. tmp1 = true;
  454. }
  455. tmp = tmp1 ? false : true;
  456. }
  457. if(tmp) {
  458. callback.process(p);
  459. }
  460. p = n;
  461. }
  462. }
  463. convexCast(convex,begin,translation,callback) {
  464. let p = this._proxyList;
  465. while(p != null) {
  466. let n = p._next;
  467. let v = this._aabb.min;
  468. v.x = p._aabbMinX;
  469. v.y = p._aabbMinY;
  470. v.z = p._aabbMinZ;
  471. let v1 = this._aabb.max;
  472. v1.x = p._aabbMaxX;
  473. v1.y = p._aabbMaxY;
  474. v1.z = p._aabbMaxZ;
  475. this._convexSweep.init(convex,begin,translation);
  476. let gjkEpa = oimo.collision.narrowphase.detector.gjkepa.GjkEpa.instance;
  477. if(gjkEpa.computeClosestPointsImpl(this._convexSweep,this._aabb,begin,this.identity,null,false) == 0 && gjkEpa.distance <= 0) {
  478. callback.process(p);
  479. }
  480. p = n;
  481. }
  482. }
  483. aabbTest(aabb,callback) {
  484. let p = this._proxyList;
  485. while(p != null) {
  486. let n = p._next;
  487. if(aabb._minX < p._aabbMaxX && aabb._maxX > p._aabbMinX && aabb._minY < p._aabbMaxY && aabb._maxY > p._aabbMinY && aabb._minZ < p._aabbMaxZ && aabb._maxZ > p._aabbMinZ) {
  488. callback.process(p);
  489. }
  490. p = n;
  491. }
  492. }
  493. }
  494. if(!oimo.collision.broadphase.bvh) oimo.collision.broadphase.bvh = {};
  495. oimo.collision.broadphase.bvh.BvhBroadPhase = class oimo_collision_broadphase_bvh_BvhBroadPhase extends oimo.collision.broadphase.BroadPhase {
  496. constructor() {
  497. super(2);
  498. this._incremental = true;
  499. this._tree = new oimo.collision.broadphase.bvh.BvhTree();
  500. this.movedProxies = new Array(1024);
  501. this.numMovedProxies = 0;
  502. }
  503. collide(n1,n2) {
  504. this._testCount++;
  505. let l1 = n1._height == 0;
  506. let l2 = n2._height == 0;
  507. if(n1 == n2) {
  508. if(l1) {
  509. return;
  510. }
  511. this.collide(n1._children[0],n2);
  512. this.collide(n1._children[1],n2);
  513. return;
  514. }
  515. if(!(n1._aabbMinX < n2._aabbMaxX && n1._aabbMaxX > n2._aabbMinX && n1._aabbMinY < n2._aabbMaxY && n1._aabbMaxY > n2._aabbMinY && n1._aabbMinZ < n2._aabbMaxZ && n1._aabbMaxZ > n2._aabbMinZ)) {
  516. return;
  517. }
  518. if(l1 && l2) {
  519. let first = this._proxyPairPool;
  520. if(first != null) {
  521. this._proxyPairPool = first._next;
  522. first._next = null;
  523. } else {
  524. first = new oimo.collision.broadphase.ProxyPair();
  525. }
  526. let pp = first;
  527. if(this._proxyPairList == null) {
  528. this._proxyPairList = pp;
  529. } else {
  530. pp._next = this._proxyPairList;
  531. this._proxyPairList = pp;
  532. }
  533. pp._p1 = n1._proxy;
  534. pp._p2 = n2._proxy;
  535. return;
  536. }
  537. if(l2 || n1._height > n2._height) {
  538. this.collide(n1._children[0],n2);
  539. this.collide(n1._children[1],n2);
  540. } else {
  541. this.collide(n2._children[0],n1);
  542. this.collide(n2._children[1],n1);
  543. }
  544. }
  545. rayCastRecursive(node,_p1X,_p1Y,_p1Z,_p2X,_p2Y,_p2Z,callback) {
  546. let x1 = _p1X;
  547. let y1 = _p1Y;
  548. let z1 = _p1Z;
  549. let x2 = _p2X;
  550. let y2 = _p2Y;
  551. let z2 = _p2Z;
  552. let pminx = node._aabbMinX;
  553. let pminy = node._aabbMinY;
  554. let pminz = node._aabbMinZ;
  555. let pmaxx = node._aabbMaxX;
  556. let pmaxy = node._aabbMaxY;
  557. let pmaxz = node._aabbMaxZ;
  558. let tmp;
  559. if(pminx > (x1 > x2 ? x1 : x2) || pmaxx < (x1 < x2 ? x1 : x2) || pminy > (y1 > y2 ? y1 : y2) || pmaxy < (y1 < y2 ? y1 : y2) || pminz > (z1 > z2 ? z1 : z2) || pmaxz < (z1 < z2 ? z1 : z2)) {
  560. tmp = false;
  561. } else {
  562. let dx = x2 - x1;
  563. let dy = y2 - y1;
  564. let dz = z2 - z1;
  565. let adx = dx < 0 ? -dx : dx;
  566. let ady = dy < 0 ? -dy : dy;
  567. let adz = dz < 0 ? -dz : dz;
  568. let pextx = (pmaxx - pminx) * 0.5;
  569. let pexty = (pmaxy - pminy) * 0.5;
  570. let pextz = (pmaxz - pminz) * 0.5;
  571. let cpx = x1 - (pmaxx + pminx) * 0.5;
  572. let cpy = y1 - (pmaxy + pminy) * 0.5;
  573. let cpz = z1 - (pmaxz + pminz) * 0.5;
  574. let tmp1;
  575. let tmp2;
  576. let x = cpy * dz - cpz * dy;
  577. if(!((x < 0 ? -x : x) - (pexty * adz + pextz * ady) > 0)) {
  578. let x = cpz * dx - cpx * dz;
  579. tmp2 = (x < 0 ? -x : x) - (pextz * adx + pextx * adz) > 0;
  580. } else {
  581. tmp2 = true;
  582. }
  583. if(!tmp2) {
  584. let x = cpx * dy - cpy * dx;
  585. tmp1 = (x < 0 ? -x : x) - (pextx * ady + pexty * adx) > 0;
  586. } else {
  587. tmp1 = true;
  588. }
  589. tmp = tmp1 ? false : true;
  590. }
  591. if(!tmp) {
  592. return;
  593. }
  594. if(node._height == 0) {
  595. callback.process(node._proxy);
  596. return;
  597. }
  598. this.rayCastRecursive(node._children[0],_p1X,_p1Y,_p1Z,_p2X,_p2Y,_p2Z,callback);
  599. this.rayCastRecursive(node._children[1],_p1X,_p1Y,_p1Z,_p2X,_p2Y,_p2Z,callback);
  600. }
  601. convexCastRecursive(node,convex,begin,translation,callback) {
  602. let v = this._aabb.min;
  603. v.x = node._aabbMinX;
  604. v.y = node._aabbMinY;
  605. v.z = node._aabbMinZ;
  606. let v1 = this._aabb.max;
  607. v1.x = node._aabbMaxX;
  608. v1.y = node._aabbMaxY;
  609. v1.z = node._aabbMaxZ;
  610. this._convexSweep.init(convex,begin,translation);
  611. let gjkEpa = oimo.collision.narrowphase.detector.gjkepa.GjkEpa.instance;
  612. if(!(gjkEpa.computeClosestPointsImpl(this._convexSweep,this._aabb,begin,this.identity,null,false) == 0 && gjkEpa.distance <= 0)) {
  613. return;
  614. }
  615. if(node._height == 0) {
  616. callback.process(node._proxy);
  617. return;
  618. }
  619. this.convexCastRecursive(node._children[0],convex,begin,translation,callback);
  620. this.convexCastRecursive(node._children[1],convex,begin,translation,callback);
  621. }
  622. aabbTestRecursive(node,aabb,callback) {
  623. if(!(node._aabbMinX < aabb._maxX && node._aabbMaxX > aabb._minX && node._aabbMinY < aabb._maxY && node._aabbMaxY > aabb._minY && node._aabbMinZ < aabb._maxZ && node._aabbMaxZ > aabb._minZ)) {
  624. return;
  625. }
  626. if(node._height == 0) {
  627. callback.process(node._proxy);
  628. return;
  629. }
  630. this.aabbTestRecursive(node._children[0],aabb,callback);
  631. this.aabbTestRecursive(node._children[1],aabb,callback);
  632. }
  633. createProxy(userData,aabb) {
  634. let p = new oimo.collision.broadphase.bvh.BvhProxy(userData,this._idCount++);
  635. this._numProxies++;
  636. if(this._proxyList == null) {
  637. this._proxyList = p;
  638. this._proxyListLast = p;
  639. } else {
  640. this._proxyListLast._next = p;
  641. p._prev = this._proxyListLast;
  642. this._proxyListLast = p;
  643. }
  644. p._aabbMinX = aabb._minX;
  645. p._aabbMinY = aabb._minY;
  646. p._aabbMinZ = aabb._minZ;
  647. p._aabbMaxX = aabb._maxX;
  648. p._aabbMaxY = aabb._maxY;
  649. p._aabbMaxZ = aabb._maxZ;
  650. let padding = oimo.common.Setting.bvhProxyPadding;
  651. p._aabbMinX -= padding;
  652. p._aabbMinY -= padding;
  653. p._aabbMinZ -= padding;
  654. p._aabbMaxX += padding;
  655. p._aabbMaxY += padding;
  656. p._aabbMaxZ += padding;
  657. let _this = this._tree;
  658. let first = _this._nodePool;
  659. if(first != null) {
  660. _this._nodePool = first._next;
  661. first._next = null;
  662. } else {
  663. first = new oimo.collision.broadphase.bvh.BvhNode();
  664. }
  665. let leaf = first;
  666. leaf._proxy = p;
  667. p._leaf = leaf;
  668. leaf._aabbMinX = p._aabbMinX;
  669. leaf._aabbMinY = p._aabbMinY;
  670. leaf._aabbMinZ = p._aabbMinZ;
  671. leaf._aabbMaxX = p._aabbMaxX;
  672. leaf._aabbMaxY = p._aabbMaxY;
  673. leaf._aabbMaxZ = p._aabbMaxZ;
  674. _this._numLeaves++;
  675. if(_this.leafList == null) {
  676. _this.leafList = leaf;
  677. _this.leafListLast = leaf;
  678. } else {
  679. _this.leafListLast._nextLeaf = leaf;
  680. leaf._prevLeaf = _this.leafListLast;
  681. _this.leafListLast = leaf;
  682. }
  683. if(_this._root == null) {
  684. _this._root = leaf;
  685. } else {
  686. let sibling = _this._root;
  687. while(sibling._height > 0) {
  688. let nextStep = _this._strategy._decideInsertion(sibling,leaf);
  689. if(nextStep == -1) {
  690. break;
  691. } else {
  692. sibling = sibling._children[nextStep];
  693. }
  694. }
  695. let parent = sibling._parent;
  696. let first = _this._nodePool;
  697. if(first != null) {
  698. _this._nodePool = first._next;
  699. first._next = null;
  700. } else {
  701. first = new oimo.collision.broadphase.bvh.BvhNode();
  702. }
  703. let node = first;
  704. if(parent == null) {
  705. _this._root = node;
  706. } else {
  707. let index = sibling._childIndex;
  708. parent._children[index] = node;
  709. node._parent = parent;
  710. node._childIndex = index;
  711. }
  712. let index = sibling._childIndex;
  713. node._children[index] = sibling;
  714. sibling._parent = node;
  715. sibling._childIndex = index;
  716. let index1 = sibling._childIndex ^ 1;
  717. node._children[index1] = leaf;
  718. leaf._parent = node;
  719. leaf._childIndex = index1;
  720. while(node != null) {
  721. if(_this._strategy._balancingEnabled) {
  722. if(node._height >= 2) {
  723. let p = node._parent;
  724. let l = node._children[0];
  725. let r = node._children[1];
  726. let balance = l._height - r._height;
  727. let nodeIndex = node._childIndex;
  728. if(balance > 1) {
  729. let ll = l._children[0];
  730. let lr = l._children[1];
  731. if(ll._height > lr._height) {
  732. l._children[1] = node;
  733. node._parent = l;
  734. node._childIndex = 1;
  735. node._children[0] = lr;
  736. lr._parent = node;
  737. lr._childIndex = 0;
  738. let c1 = l._children[0];
  739. let c2 = l._children[1];
  740. l._aabbMinX = c1._aabbMinX < c2._aabbMinX ? c1._aabbMinX : c2._aabbMinX;
  741. l._aabbMinY = c1._aabbMinY < c2._aabbMinY ? c1._aabbMinY : c2._aabbMinY;
  742. l._aabbMinZ = c1._aabbMinZ < c2._aabbMinZ ? c1._aabbMinZ : c2._aabbMinZ;
  743. l._aabbMaxX = c1._aabbMaxX > c2._aabbMaxX ? c1._aabbMaxX : c2._aabbMaxX;
  744. l._aabbMaxY = c1._aabbMaxY > c2._aabbMaxY ? c1._aabbMaxY : c2._aabbMaxY;
  745. l._aabbMaxZ = c1._aabbMaxZ > c2._aabbMaxZ ? c1._aabbMaxZ : c2._aabbMaxZ;
  746. let h1 = l._children[0]._height;
  747. let h2 = l._children[1]._height;
  748. l._height = (h1 > h2 ? h1 : h2) + 1;
  749. let c11 = node._children[0];
  750. let c21 = node._children[1];
  751. node._aabbMinX = c11._aabbMinX < c21._aabbMinX ? c11._aabbMinX : c21._aabbMinX;
  752. node._aabbMinY = c11._aabbMinY < c21._aabbMinY ? c11._aabbMinY : c21._aabbMinY;
  753. node._aabbMinZ = c11._aabbMinZ < c21._aabbMinZ ? c11._aabbMinZ : c21._aabbMinZ;
  754. node._aabbMaxX = c11._aabbMaxX > c21._aabbMaxX ? c11._aabbMaxX : c21._aabbMaxX;
  755. node._aabbMaxY = c11._aabbMaxY > c21._aabbMaxY ? c11._aabbMaxY : c21._aabbMaxY;
  756. node._aabbMaxZ = c11._aabbMaxZ > c21._aabbMaxZ ? c11._aabbMaxZ : c21._aabbMaxZ;
  757. let h11 = node._children[0]._height;
  758. let h21 = node._children[1]._height;
  759. node._height = (h11 > h21 ? h11 : h21) + 1;
  760. } else {
  761. l._children[0] = node;
  762. node._parent = l;
  763. node._childIndex = 0;
  764. node._children[0] = ll;
  765. ll._parent = node;
  766. ll._childIndex = 0;
  767. let c1 = l._children[0];
  768. let c2 = l._children[1];
  769. l._aabbMinX = c1._aabbMinX < c2._aabbMinX ? c1._aabbMinX : c2._aabbMinX;
  770. l._aabbMinY = c1._aabbMinY < c2._aabbMinY ? c1._aabbMinY : c2._aabbMinY;
  771. l._aabbMinZ = c1._aabbMinZ < c2._aabbMinZ ? c1._aabbMinZ : c2._aabbMinZ;
  772. l._aabbMaxX = c1._aabbMaxX > c2._aabbMaxX ? c1._aabbMaxX : c2._aabbMaxX;
  773. l._aabbMaxY = c1._aabbMaxY > c2._aabbMaxY ? c1._aabbMaxY : c2._aabbMaxY;
  774. l._aabbMaxZ = c1._aabbMaxZ > c2._aabbMaxZ ? c1._aabbMaxZ : c2._aabbMaxZ;
  775. let h1 = l._children[0]._height;
  776. let h2 = l._children[1]._height;
  777. l._height = (h1 > h2 ? h1 : h2) + 1;
  778. let c11 = node._children[0];
  779. let c21 = node._children[1];
  780. node._aabbMinX = c11._aabbMinX < c21._aabbMinX ? c11._aabbMinX : c21._aabbMinX;
  781. node._aabbMinY = c11._aabbMinY < c21._aabbMinY ? c11._aabbMinY : c21._aabbMinY;
  782. node._aabbMinZ = c11._aabbMinZ < c21._aabbMinZ ? c11._aabbMinZ : c21._aabbMinZ;
  783. node._aabbMaxX = c11._aabbMaxX > c21._aabbMaxX ? c11._aabbMaxX : c21._aabbMaxX;
  784. node._aabbMaxY = c11._aabbMaxY > c21._aabbMaxY ? c11._aabbMaxY : c21._aabbMaxY;
  785. node._aabbMaxZ = c11._aabbMaxZ > c21._aabbMaxZ ? c11._aabbMaxZ : c21._aabbMaxZ;
  786. let h11 = node._children[0]._height;
  787. let h21 = node._children[1]._height;
  788. node._height = (h11 > h21 ? h11 : h21) + 1;
  789. }
  790. if(p != null) {
  791. p._children[nodeIndex] = l;
  792. l._parent = p;
  793. l._childIndex = nodeIndex;
  794. } else {
  795. _this._root = l;
  796. l._parent = null;
  797. }
  798. node = l;
  799. } else if(balance < -1) {
  800. let rl = r._children[0];
  801. let rr = r._children[1];
  802. if(rl._height > rr._height) {
  803. r._children[1] = node;
  804. node._parent = r;
  805. node._childIndex = 1;
  806. node._children[1] = rr;
  807. rr._parent = node;
  808. rr._childIndex = 1;
  809. let c1 = r._children[0];
  810. let c2 = r._children[1];
  811. r._aabbMinX = c1._aabbMinX < c2._aabbMinX ? c1._aabbMinX : c2._aabbMinX;
  812. r._aabbMinY = c1._aabbMinY < c2._aabbMinY ? c1._aabbMinY : c2._aabbMinY;
  813. r._aabbMinZ = c1._aabbMinZ < c2._aabbMinZ ? c1._aabbMinZ : c2._aabbMinZ;
  814. r._aabbMaxX = c1._aabbMaxX > c2._aabbMaxX ? c1._aabbMaxX : c2._aabbMaxX;
  815. r._aabbMaxY = c1._aabbMaxY > c2._aabbMaxY ? c1._aabbMaxY : c2._aabbMaxY;
  816. r._aabbMaxZ = c1._aabbMaxZ > c2._aabbMaxZ ? c1._aabbMaxZ : c2._aabbMaxZ;
  817. let h1 = r._children[0]._height;
  818. let h2 = r._children[1]._height;
  819. r._height = (h1 > h2 ? h1 : h2) + 1;
  820. let c11 = node._children[0];
  821. let c21 = node._children[1];
  822. node._aabbMinX = c11._aabbMinX < c21._aabbMinX ? c11._aabbMinX : c21._aabbMinX;
  823. node._aabbMinY = c11._aabbMinY < c21._aabbMinY ? c11._aabbMinY : c21._aabbMinY;
  824. node._aabbMinZ = c11._aabbMinZ < c21._aabbMinZ ? c11._aabbMinZ : c21._aabbMinZ;
  825. node._aabbMaxX = c11._aabbMaxX > c21._aabbMaxX ? c11._aabbMaxX : c21._aabbMaxX;
  826. node._aabbMaxY = c11._aabbMaxY > c21._aabbMaxY ? c11._aabbMaxY : c21._aabbMaxY;
  827. node._aabbMaxZ = c11._aabbMaxZ > c21._aabbMaxZ ? c11._aabbMaxZ : c21._aabbMaxZ;
  828. let h11 = node._children[0]._height;
  829. let h21 = node._children[1]._height;
  830. node._height = (h11 > h21 ? h11 : h21) + 1;
  831. } else {
  832. r._children[0] = node;
  833. node._parent = r;
  834. node._childIndex = 0;
  835. node._children[1] = rl;
  836. rl._parent = node;
  837. rl._childIndex = 1;
  838. let c1 = r._children[0];
  839. let c2 = r._children[1];
  840. r._aabbMinX = c1._aabbMinX < c2._aabbMinX ? c1._aabbMinX : c2._aabbMinX;
  841. r._aabbMinY = c1._aabbMinY < c2._aabbMinY ? c1._aabbMinY : c2._aabbMinY;
  842. r._aabbMinZ = c1._aabbMinZ < c2._aabbMinZ ? c1._aabbMinZ : c2._aabbMinZ;
  843. r._aabbMaxX = c1._aabbMaxX > c2._aabbMaxX ? c1._aabbMaxX : c2._aabbMaxX;
  844. r._aabbMaxY = c1._aabbMaxY > c2._aabbMaxY ? c1._aabbMaxY : c2._aabbMaxY;
  845. r._aabbMaxZ = c1._aabbMaxZ > c2._aabbMaxZ ? c1._aabbMaxZ : c2._aabbMaxZ;
  846. let h1 = r._children[0]._height;
  847. let h2 = r._children[1]._height;
  848. r._height = (h1 > h2 ? h1 : h2) + 1;
  849. let c11 = node._children[0];
  850. let c21 = node._children[1];
  851. node._aabbMinX = c11._aabbMinX < c21._aabbMinX ? c11._aabbMinX : c21._aabbMinX;
  852. node._aabbMinY = c11._aabbMinY < c21._aabbMinY ? c11._aabbMinY : c21._aabbMinY;
  853. node._aabbMinZ = c11._aabbMinZ < c21._aabbMinZ ? c11._aabbMinZ : c21._aabbMinZ;
  854. node._aabbMaxX = c11._aabbMaxX > c21._aabbMaxX ? c11._aabbMaxX : c21._aabbMaxX;
  855. node._aabbMaxY = c11._aabbMaxY > c21._aabbMaxY ? c11._aabbMaxY : c21._aabbMaxY;
  856. node._aabbMaxZ = c11._aabbMaxZ > c21._aabbMaxZ ? c11._aabbMaxZ : c21._aabbMaxZ;
  857. let h11 = node._children[0]._height;
  858. let h21 = node._children[1]._height;
  859. node._height = (h11 > h21 ? h11 : h21) + 1;
  860. }
  861. if(p != null) {
  862. p._children[nodeIndex] = r;
  863. r._parent = p;
  864. r._childIndex = nodeIndex;
  865. } else {
  866. _this._root = r;
  867. r._parent = null;
  868. }
  869. node = r;
  870. }
  871. }
  872. }
  873. let h1 = node._children[0]._height;
  874. let h2 = node._children[1]._height;
  875. node._height = (h1 > h2 ? h1 : h2) + 1;
  876. let c1 = node._children[0];
  877. let c2 = node._children[1];
  878. node._aabbMinX = c1._aabbMinX < c2._aabbMinX ? c1._aabbMinX : c2._aabbMinX;
  879. node._aabbMinY = c1._aabbMinY < c2._aabbMinY ? c1._aabbMinY : c2._aabbMinY;
  880. node._aabbMinZ = c1._aabbMinZ < c2._aabbMinZ ? c1._aabbMinZ : c2._aabbMinZ;
  881. node._aabbMaxX = c1._aabbMaxX > c2._aabbMaxX ? c1._aabbMaxX : c2._aabbMaxX;
  882. node._aabbMaxY = c1._aabbMaxY > c2._aabbMaxY ? c1._aabbMaxY : c2._aabbMaxY;
  883. node._aabbMaxZ = c1._aabbMaxZ > c2._aabbMaxZ ? c1._aabbMaxZ : c2._aabbMaxZ;
  884. node = node._parent;
  885. }
  886. }
  887. if(!p._moved) {
  888. p._moved = true;
  889. if(this.movedProxies.length == this.numMovedProxies) {
  890. let newArray = new Array(this.numMovedProxies << 1);
  891. let _g = 0;
  892. let _g1 = this.numMovedProxies;
  893. while(_g < _g1) {
  894. let i = _g++;
  895. newArray[i] = this.movedProxies[i];
  896. this.movedProxies[i] = null;
  897. }
  898. this.movedProxies = newArray;
  899. }
  900. this.movedProxies[this.numMovedProxies++] = p;
  901. }
  902. return p;
  903. }
  904. destroyProxy(proxy) {
  905. this._numProxies--;
  906. let prev = proxy._prev;
  907. let next = proxy._next;
  908. if(prev != null) {
  909. prev._next = next;
  910. }
  911. if(next != null) {
  912. next._prev = prev;
  913. }
  914. if(proxy == this._proxyList) {
  915. this._proxyList = this._proxyList._next;
  916. }
  917. if(proxy == this._proxyListLast) {
  918. this._proxyListLast = this._proxyListLast._prev;
  919. }
  920. proxy._next = null;
  921. proxy._prev = null;
  922. let bvhProxy = proxy;
  923. let _this = this._tree;
  924. let leaf = bvhProxy._leaf;
  925. _this._numLeaves--;
  926. let prev1 = leaf._prevLeaf;
  927. let next1 = leaf._nextLeaf;
  928. if(prev1 != null) {
  929. prev1._nextLeaf = next1;
  930. }
  931. if(next1 != null) {
  932. next1._prevLeaf = prev1;
  933. }
  934. if(leaf == _this.leafList) {
  935. _this.leafList = _this.leafList._nextLeaf;
  936. }
  937. if(leaf == _this.leafListLast) {
  938. _this.leafListLast = _this.leafListLast._prevLeaf;
  939. }
  940. leaf._nextLeaf = null;
  941. leaf._prevLeaf = null;
  942. if(_this._root == leaf) {
  943. _this._root = null;
  944. } else {
  945. let parent = leaf._parent;
  946. let sibling = parent._children[leaf._childIndex ^ 1];
  947. let grandParent = parent._parent;
  948. if(grandParent == null) {
  949. sibling._parent = null;
  950. sibling._childIndex = 0;
  951. _this._root = sibling;
  952. parent._next = null;
  953. parent._childIndex = 0;
  954. parent._children[0] = null;
  955. parent._children[1] = null;
  956. parent._childIndex = 0;
  957. parent._parent = null;
  958. parent._height = 0;
  959. parent._proxy = null;
  960. parent._next = _this._nodePool;
  961. _this._nodePool = parent;
  962. } else {
  963. sibling._parent = grandParent;
  964. let index = parent._childIndex;
  965. grandParent._children[index] = sibling;
  966. sibling._parent = grandParent;
  967. sibling._childIndex = index;
  968. parent._next = null;
  969. parent._childIndex = 0;
  970. parent._children[0] = null;
  971. parent._children[1] = null;
  972. parent._childIndex = 0;
  973. parent._parent = null;
  974. parent._height = 0;
  975. parent._proxy = null;
  976. parent._next = _this._nodePool;
  977. _this._nodePool = parent;
  978. let node = grandParent;
  979. while(node != null) {
  980. if(_this._strategy._balancingEnabled) {
  981. if(node._height >= 2) {
  982. let p = node._parent;
  983. let l = node._children[0];
  984. let r = node._children[1];
  985. let balance = l._height - r._height;
  986. let nodeIndex = node._childIndex;
  987. if(balance > 1) {
  988. let ll = l._children[0];
  989. let lr = l._children[1];
  990. if(ll._height > lr._height) {
  991. l._children[1] = node;
  992. node._parent = l;
  993. node._childIndex = 1;
  994. node._children[0] = lr;
  995. lr._parent = node;
  996. lr._childIndex = 0;
  997. let c1 = l._children[0];
  998. let c2 = l._children[1];
  999. l._aabbMinX = c1._aabbMinX < c2._aabbMinX ? c1._aabbMinX : c2._aabbMinX;
  1000. l._aabbMinY = c1._aabbMinY < c2._aabbMinY ? c1._aabbMinY : c2._aabbMinY;
  1001. l._aabbMinZ = c1._aabbMinZ < c2._aabbMinZ ? c1._aabbMinZ : c2._aabbMinZ;
  1002. l._aabbMaxX = c1._aabbMaxX > c2._aabbMaxX ? c1._aabbMaxX : c2._aabbMaxX;
  1003. l._aabbMaxY = c1._aabbMaxY > c2._aabbMaxY ? c1._aabbMaxY : c2._aabbMaxY;
  1004. l._aabbMaxZ = c1._aabbMaxZ > c2._aabbMaxZ ? c1._aabbMaxZ : c2._aabbMaxZ;
  1005. let h1 = l._children[0]._height;
  1006. let h2 = l._children[1]._height;
  1007. l._height = (h1 > h2 ? h1 : h2) + 1;
  1008. let c11 = node._children[0];
  1009. let c21 = node._children[1];
  1010. node._aabbMinX = c11._aabbMinX < c21._aabbMinX ? c11._aabbMinX : c21._aabbMinX;
  1011. node._aabbMinY = c11._aabbMinY < c21._aabbMinY ? c11._aabbMinY : c21._aabbMinY;
  1012. node._aabbMinZ = c11._aabbMinZ < c21._aabbMinZ ? c11._aabbMinZ : c21._aabbMinZ;
  1013. node._aabbMaxX = c11._aabbMaxX > c21._aabbMaxX ? c11._aabbMaxX : c21._aabbMaxX;
  1014. node._aabbMaxY = c11._aabbMaxY > c21._aabbMaxY ? c11._aabbMaxY : c21._aabbMaxY;
  1015. node._aabbMaxZ = c11._aabbMaxZ > c21._aabbMaxZ ? c11._aabbMaxZ : c21._aabbMaxZ;
  1016. let h11 = node._children[0]._height;
  1017. let h21 = node._children[1]._height;
  1018. node._height = (h11 > h21 ? h11 : h21) + 1;
  1019. } else {
  1020. l._children[0] = node;
  1021. node._parent = l;
  1022. node._childIndex = 0;
  1023. node._children[0] = ll;
  1024. ll._parent = node;
  1025. ll._childIndex = 0;
  1026. let c1 = l._children[0];
  1027. let c2 = l._children[1];
  1028. l._aabbMinX = c1._aabbMinX < c2._aabbMinX ? c1._aabbMinX : c2._aabbMinX;
  1029. l._aabbMinY = c1._aabbMinY < c2._aabbMinY ? c1._aabbMinY : c2._aabbMinY;
  1030. l._aabbMinZ = c1._aabbMinZ < c2._aabbMinZ ? c1._aabbMinZ : c2._aabbMinZ;
  1031. l._aabbMaxX = c1._aabbMaxX > c2._aabbMaxX ? c1._aabbMaxX : c2._aabbMaxX;
  1032. l._aabbMaxY = c1._aabbMaxY > c2._aabbMaxY ? c1._aabbMaxY : c2._aabbMaxY;
  1033. l._aabbMaxZ = c1._aabbMaxZ > c2._aabbMaxZ ? c1._aabbMaxZ : c2._aabbMaxZ;
  1034. let h1 = l._children[0]._height;
  1035. let h2 = l._children[1]._height;
  1036. l._height = (h1 > h2 ? h1 : h2) + 1;
  1037. let c11 = node._children[0];
  1038. let c21 = node._children[1];
  1039. node._aabbMinX = c11._aabbMinX < c21._aabbMinX ? c11._aabbMinX : c21._aabbMinX;
  1040. node._aabbMinY = c11._aabbMinY < c21._aabbMinY ? c11._aabbMinY : c21._aabbMinY;
  1041. node._aabbMinZ = c11._aabbMinZ < c21._aabbMinZ ? c11._aabbMinZ : c21._aabbMinZ;
  1042. node._aabbMaxX = c11._aabbMaxX > c21._aabbMaxX ? c11._aabbMaxX : c21._aabbMaxX;
  1043. node._aabbMaxY = c11._aabbMaxY > c21._aabbMaxY ? c11._aabbMaxY : c21._aabbMaxY;
  1044. node._aabbMaxZ = c11._aabbMaxZ > c21._aabbMaxZ ? c11._aabbMaxZ : c21._aabbMaxZ;
  1045. let h11 = node._children[0]._height;
  1046. let h21 = node._children[1]._height;
  1047. node._height = (h11 > h21 ? h11 : h21) + 1;
  1048. }
  1049. if(p != null) {
  1050. p._children[nodeIndex] = l;
  1051. l._parent = p;
  1052. l._childIndex = nodeIndex;
  1053. } else {
  1054. _this._root = l;
  1055. l._parent = null;
  1056. }
  1057. node = l;
  1058. } else if(balance < -1) {
  1059. let rl = r._children[0];
  1060. let rr = r._children[1];
  1061. if(rl._height > rr._height) {
  1062. r._children[1] = node;
  1063. node._parent = r;
  1064. node._childIndex = 1;
  1065. node._children[1] = rr;
  1066. rr._parent = node;
  1067. rr._childIndex = 1;
  1068. let c1 = r._children[0];
  1069. let c2 = r._children[1];
  1070. r._aabbMinX = c1._aabbMinX < c2._aabbMinX ? c1._aabbMinX : c2._aabbMinX;
  1071. r._aabbMinY = c1._aabbMinY < c2._aabbMinY ? c1._aabbMinY : c2._aabbMinY;
  1072. r._aabbMinZ = c1._aabbMinZ < c2._aabbMinZ ? c1._aabbMinZ : c2._aabbMinZ;
  1073. r._aabbMaxX = c1._aabbMaxX > c2._aabbMaxX ? c1._aabbMaxX : c2._aabbMaxX;
  1074. r._aabbMaxY = c1._aabbMaxY > c2._aabbMaxY ? c1._aabbMaxY : c2._aabbMaxY;
  1075. r._aabbMaxZ = c1._aabbMaxZ > c2._aabbMaxZ ? c1._aabbMaxZ : c2._aabbMaxZ;
  1076. let h1 = r._children[0]._height;
  1077. let h2 = r._children[1]._height;
  1078. r._height = (h1 > h2 ? h1 : h2) + 1;
  1079. let c11 = node._children[0];
  1080. let c21 = node._children[1];
  1081. node._aabbMinX = c11._aabbMinX < c21._aabbMinX ? c11._aabbMinX : c21._aabbMinX;
  1082. node._aabbMinY = c11._aabbMinY < c21._aabbMinY ? c11._aabbMinY : c21._aabbMinY;
  1083. node._aabbMinZ = c11._aabbMinZ < c21._aabbMinZ ? c11._aabbMinZ : c21._aabbMinZ;
  1084. node._aabbMaxX = c11._aabbMaxX > c21._aabbMaxX ? c11._aabbMaxX : c21._aabbMaxX;
  1085. node._aabbMaxY = c11._aabbMaxY > c21._aabbMaxY ? c11._aabbMaxY : c21._aabbMaxY;
  1086. node._aabbMaxZ = c11._aabbMaxZ > c21._aabbMaxZ ? c11._aabbMaxZ : c21._aabbMaxZ;
  1087. let h11 = node._children[0]._height;
  1088. let h21 = node._children[1]._height;
  1089. node._height = (h11 > h21 ? h11 : h21) + 1;
  1090. } else {
  1091. r._children[0] = node;
  1092. node._parent = r;
  1093. node._childIndex = 0;
  1094. node._children[1] = rl;
  1095. rl._parent = node;
  1096. rl._childIndex = 1;
  1097. let c1 = r._children[0];
  1098. let c2 = r._children[1];
  1099. r._aabbMinX = c1._aabbMinX < c2._aabbMinX ? c1._aabbMinX : c2._aabbMinX;
  1100. r._aabbMinY = c1._aabbMinY < c2._aabbMinY ? c1._aabbMinY : c2._aabbMinY;
  1101. r._aabbMinZ = c1._aabbMinZ < c2._aabbMinZ ? c1._aabbMinZ : c2._aabbMinZ;
  1102. r._aabbMaxX = c1._aabbMaxX > c2._aabbMaxX ? c1._aabbMaxX : c2._aabbMaxX;
  1103. r._aabbMaxY = c1._aabbMaxY > c2._aabbMaxY ? c1._aabbMaxY : c2._aabbMaxY;
  1104. r._aabbMaxZ = c1._aabbMaxZ > c2._aabbMaxZ ? c1._aabbMaxZ : c2._aabbMaxZ;
  1105. let h1 = r._children[0]._height;
  1106. let h2 = r._children[1]._height;
  1107. r._height = (h1 > h2 ? h1 : h2) + 1;
  1108. let c11 = node._children[0];
  1109. let c21 = node._children[1];
  1110. node._aabbMinX = c11._aabbMinX < c21._aabbMinX ? c11._aabbMinX : c21._aabbMinX;
  1111. node._aabbMinY = c11._aabbMinY < c21._aabbMinY ? c11._aabbMinY : c21._aabbMinY;
  1112. node._aabbMinZ = c11._aabbMinZ < c21._aabbMinZ ? c11._aabbMinZ : c21._aabbMinZ;
  1113. node._aabbMaxX = c11._aabbMaxX > c21._aabbMaxX ? c11._aabbMaxX : c21._aabbMaxX;
  1114. node._aabbMaxY = c11._aabbMaxY > c21._aabbMaxY ? c11._aabbMaxY : c21._aabbMaxY;
  1115. node._aabbMaxZ = c11._aabbMaxZ > c21._aabbMaxZ ? c11._aabbMaxZ : c21._aabbMaxZ;
  1116. let h11 = node._children[0]._height;
  1117. let h21 = node._children[1]._height;
  1118. node._height = (h11 > h21 ? h11 : h21) + 1;
  1119. }
  1120. if(p != null) {
  1121. p._children[nodeIndex] = r;
  1122. r._parent = p;
  1123. r._childIndex = nodeIndex;
  1124. } else {
  1125. _this._root = r;
  1126. r._parent = null;
  1127. }
  1128. node = r;
  1129. }
  1130. }
  1131. }
  1132. let h1 = node._children[0]._height;
  1133. let h2 = node._children[1]._height;
  1134. node._height = (h1 > h2 ? h1 : h2) + 1;
  1135. let c1 = node._children[0];
  1136. let c2 = node._children[1];
  1137. node._aabbMinX = c1._aabbMinX < c2._aabbMinX ? c1._aabbMinX : c2._aabbMinX;
  1138. node._aabbMinY = c1._aabbMinY < c2._aabbMinY ? c1._aabbMinY : c2._aabbMinY;
  1139. node._aabbMinZ = c1._aabbMinZ < c2._aabbMinZ ? c1._aabbMinZ : c2._aabbMinZ;
  1140. node._aabbMaxX = c1._aabbMaxX > c2._aabbMaxX ? c1._aabbMaxX : c2._aabbMaxX;
  1141. node._aabbMaxY = c1._aabbMaxY > c2._aabbMaxY ? c1._aabbMaxY : c2._aabbMaxY;
  1142. node._aabbMaxZ = c1._aabbMaxZ > c2._aabbMaxZ ? c1._aabbMaxZ : c2._aabbMaxZ;
  1143. node = node._parent;
  1144. }
  1145. }
  1146. }
  1147. bvhProxy._leaf = null;
  1148. leaf._next = null;
  1149. leaf._childIndex = 0;
  1150. leaf._children[0] = null;
  1151. leaf._children[1] = null;
  1152. leaf._childIndex = 0;
  1153. leaf._parent = null;
  1154. leaf._height = 0;
  1155. leaf._proxy = null;
  1156. leaf._next = _this._nodePool;
  1157. _this._nodePool = leaf;
  1158. bvhProxy.userData = null;
  1159. bvhProxy._next = null;
  1160. bvhProxy._prev = null;
  1161. if(bvhProxy._moved) {
  1162. bvhProxy._moved = false;
  1163. }
  1164. }
  1165. moveProxy(proxy,aabb,displacement) {
  1166. let p = proxy;
  1167. if(p._aabbMinX <= aabb._minX && p._aabbMaxX >= aabb._maxX && p._aabbMinY <= aabb._minY && p._aabbMaxY >= aabb._maxY && p._aabbMinZ <= aabb._minZ && p._aabbMaxZ >= aabb._maxZ) {
  1168. return;
  1169. }
  1170. p._aabbMinX = aabb._minX;
  1171. p._aabbMinY = aabb._minY;
  1172. p._aabbMinZ = aabb._minZ;
  1173. p._aabbMaxX = aabb._maxX;
  1174. p._aabbMaxY = aabb._maxY;
  1175. p._aabbMaxZ = aabb._maxZ;
  1176. let padding = oimo.common.Setting.bvhProxyPadding;
  1177. p._aabbMinX -= padding;
  1178. p._aabbMinY -= padding;
  1179. p._aabbMinZ -= padding;
  1180. p._aabbMaxX += padding;
  1181. p._aabbMaxY += padding;
  1182. p._aabbMaxZ += padding;
  1183. if(displacement != null) {
  1184. let dX;
  1185. let dY;
  1186. let dZ;
  1187. let zeroX;
  1188. let zeroY;
  1189. let zeroZ;
  1190. let addToMinX;
  1191. let addToMinY;
  1192. let addToMinZ;
  1193. let addToMaxX;
  1194. let addToMaxY;
  1195. let addToMaxZ;
  1196. zeroX = 0;
  1197. zeroY = 0;
  1198. zeroZ = 0;
  1199. dX = displacement.x;
  1200. dY = displacement.y;
  1201. dZ = displacement.z;
  1202. addToMinX = zeroX < dX ? zeroX : dX;
  1203. addToMinY = zeroY < dY ? zeroY : dY;
  1204. addToMinZ = zeroZ < dZ ? zeroZ : dZ;
  1205. addToMaxX = zeroX > dX ? zeroX : dX;
  1206. addToMaxY = zeroY > dY ? zeroY : dY;
  1207. addToMaxZ = zeroZ > dZ ? zeroZ : dZ;
  1208. p._aabbMinX += addToMinX;
  1209. p._aabbMinY += addToMinY;
  1210. p._aabbMinZ += addToMinZ;
  1211. p._aabbMaxX += addToMaxX;
  1212. p._aabbMaxY += addToMaxY;
  1213. p._aabbMaxZ += addToMaxZ;
  1214. }
  1215. if(!p._moved) {
  1216. p._moved = true;
  1217. if(this.movedProxies.length == this.numMovedProxies) {
  1218. let newArray = new Array(this.numMovedProxies << 1);
  1219. let _g = 0;
  1220. let _g1 = this.numMovedProxies;
  1221. while(_g < _g1) {
  1222. let i = _g++;
  1223. newArray[i] = this.movedProxies[i];
  1224. this.movedProxies[i] = null;
  1225. }
  1226. this.movedProxies = newArray;
  1227. }
  1228. this.movedProxies[this.numMovedProxies++] = p;
  1229. }
  1230. }
  1231. collectPairs() {
  1232. let p = this._proxyPairList;
  1233. if(p != null) {
  1234. while(true) {
  1235. p._p1 = null;
  1236. p._p2 = null;
  1237. p = p._next;
  1238. if(!(p != null)) {
  1239. break;
  1240. }
  1241. }
  1242. this._proxyPairList._next = this._proxyPairPool;
  1243. this._proxyPairPool = this._proxyPairList;
  1244. this._proxyPairList = null;
  1245. }
  1246. this._testCount = 0;
  1247. if(this._numProxies < 2) {
  1248. return;
  1249. }
  1250. let incrementalCollision = this.numMovedProxies / this._numProxies < oimo.common.Setting.bvhIncrementalCollisionThreshold;
  1251. let _g = 0;
  1252. let _g1 = this.numMovedProxies;
  1253. while(_g < _g1) {
  1254. let i = _g++;
  1255. let p = this.movedProxies[i];
  1256. if(p._moved) {
  1257. let _this = this._tree;
  1258. let leaf = p._leaf;
  1259. _this._numLeaves--;
  1260. let prev = leaf._prevLeaf;
  1261. let next = leaf._nextLeaf;
  1262. if(prev != null) {
  1263. prev._nextLeaf = next;
  1264. }
  1265. if(next != null) {
  1266. next._prevLeaf = prev;
  1267. }
  1268. if(leaf == _this.leafList) {
  1269. _this.leafList = _this.leafList._nextLeaf;
  1270. }
  1271. if(leaf == _this.leafListLast) {
  1272. _this.leafListLast = _this.leafListLast._prevLeaf;
  1273. }
  1274. leaf._nextLeaf = null;
  1275. leaf._prevLeaf = null;
  1276. if(_this._root == leaf) {
  1277. _this._root = null;
  1278. } else {
  1279. let parent = leaf._parent;
  1280. let sibling = parent._children[leaf._childIndex ^ 1];
  1281. let grandParent = parent._parent;
  1282. if(grandParent == null) {
  1283. sibling._parent = null;
  1284. sibling._childIndex = 0;
  1285. _this._root = sibling;
  1286. parent._next = null;
  1287. parent._childIndex = 0;
  1288. parent._children[0] = null;
  1289. parent._children[1] = null;
  1290. parent._childIndex = 0;
  1291. parent._parent = null;
  1292. parent._height = 0;
  1293. parent._proxy = null;
  1294. parent._next = _this._nodePool;
  1295. _this._nodePool = parent;
  1296. } else {
  1297. sibling._parent = grandParent;
  1298. let index = parent._childIndex;
  1299. grandParent._children[index] = sibling;
  1300. sibling._parent = grandParent;
  1301. sibling._childIndex = index;
  1302. parent._next = null;
  1303. parent._childIndex = 0;
  1304. parent._children[0] = null;
  1305. parent._children[1] = null;
  1306. parent._childIndex = 0;
  1307. parent._parent = null;
  1308. parent._height = 0;
  1309. parent._proxy = null;
  1310. parent._next = _this._nodePool;
  1311. _this._nodePool = parent;
  1312. let node = grandParent;
  1313. while(node != null) {
  1314. if(_this._strategy._balancingEnabled) {
  1315. if(node._height >= 2) {
  1316. let p = node._parent;
  1317. let l = node._children[0];
  1318. let r = node._children[1];
  1319. let balance = l._height - r._height;
  1320. let nodeIndex = node._childIndex;
  1321. if(balance > 1) {
  1322. let ll = l._children[0];
  1323. let lr = l._children[1];
  1324. if(ll._height > lr._height) {
  1325. l._children[1] = node;
  1326. node._parent = l;
  1327. node._childIndex = 1;
  1328. node._children[0] = lr;
  1329. lr._parent = node;
  1330. lr._childIndex = 0;
  1331. let c1 = l._children[0];
  1332. let c2 = l._children[1];
  1333. l._aabbMinX = c1._aabbMinX < c2._aabbMinX ? c1._aabbMinX : c2._aabbMinX;
  1334. l._aabbMinY = c1._aabbMinY < c2._aabbMinY ? c1._aabbMinY : c2._aabbMinY;
  1335. l._aabbMinZ = c1._aabbMinZ < c2._aabbMinZ ? c1._aabbMinZ : c2._aabbMinZ;
  1336. l._aabbMaxX = c1._aabbMaxX > c2._aabbMaxX ? c1._aabbMaxX : c2._aabbMaxX;
  1337. l._aabbMaxY = c1._aabbMaxY > c2._aabbMaxY ? c1._aabbMaxY : c2._aabbMaxY;
  1338. l._aabbMaxZ = c1._aabbMaxZ > c2._aabbMaxZ ? c1._aabbMaxZ : c2._aabbMaxZ;
  1339. let h1 = l._children[0]._height;
  1340. let h2 = l._children[1]._height;
  1341. l._height = (h1 > h2 ? h1 : h2) + 1;
  1342. let c11 = node._children[0];
  1343. let c21 = node._children[1];
  1344. node._aabbMinX = c11._aabbMinX < c21._aabbMinX ? c11._aabbMinX : c21._aabbMinX;
  1345. node._aabbMinY = c11._aabbMinY < c21._aabbMinY ? c11._aabbMinY : c21._aabbMinY;
  1346. node._aabbMinZ = c11._aabbMinZ < c21._aabbMinZ ? c11._aabbMinZ : c21._aabbMinZ;
  1347. node._aabbMaxX = c11._aabbMaxX > c21._aabbMaxX ? c11._aabbMaxX : c21._aabbMaxX;
  1348. node._aabbMaxY = c11._aabbMaxY > c21._aabbMaxY ? c11._aabbMaxY : c21._aabbMaxY;
  1349. node._aabbMaxZ = c11._aabbMaxZ > c21._aabbMaxZ ? c11._aabbMaxZ : c21._aabbMaxZ;
  1350. let h11 = node._children[0]._height;
  1351. let h21 = node._children[1]._height;
  1352. node._height = (h11 > h21 ? h11 : h21) + 1;
  1353. } else {
  1354. l._children[0] = node;
  1355. node._parent = l;
  1356. node._childIndex = 0;
  1357. node._children[0] = ll;
  1358. ll._parent = node;
  1359. ll._childIndex = 0;
  1360. let c1 = l._children[0];
  1361. let c2 = l._children[1];
  1362. l._aabbMinX = c1._aabbMinX < c2._aabbMinX ? c1._aabbMinX : c2._aabbMinX;
  1363. l._aabbMinY = c1._aabbMinY < c2._aabbMinY ? c1._aabbMinY : c2._aabbMinY;
  1364. l._aabbMinZ = c1._aabbMinZ < c2._aabbMinZ ? c1._aabbMinZ : c2._aabbMinZ;
  1365. l._aabbMaxX = c1._aabbMaxX > c2._aabbMaxX ? c1._aabbMaxX : c2._aabbMaxX;
  1366. l._aabbMaxY = c1._aabbMaxY > c2._aabbMaxY ? c1._aabbMaxY : c2._aabbMaxY;
  1367. l._aabbMaxZ = c1._aabbMaxZ > c2._aabbMaxZ ? c1._aabbMaxZ : c2._aabbMaxZ;
  1368. let h1 = l._children[0]._height;
  1369. let h2 = l._children[1]._height;
  1370. l._height = (h1 > h2 ? h1 : h2) + 1;
  1371. let c11 = node._children[0];
  1372. let c21 = node._children[1];
  1373. node._aabbMinX = c11._aabbMinX < c21._aabbMinX ? c11._aabbMinX : c21._aabbMinX;
  1374. node._aabbMinY = c11._aabbMinY < c21._aabbMinY ? c11._aabbMinY : c21._aabbMinY;
  1375. node._aabbMinZ = c11._aabbMinZ < c21._aabbMinZ ? c11._aabbMinZ : c21._aabbMinZ;
  1376. node._aabbMaxX = c11._aabbMaxX > c21._aabbMaxX ? c11._aabbMaxX : c21._aabbMaxX;
  1377. node._aabbMaxY = c11._aabbMaxY > c21._aabbMaxY ? c11._aabbMaxY : c21._aabbMaxY;
  1378. node._aabbMaxZ = c11._aabbMaxZ > c21._aabbMaxZ ? c11._aabbMaxZ : c21._aabbMaxZ;
  1379. let h11 = node._children[0]._height;
  1380. let h21 = node._children[1]._height;
  1381. node._height = (h11 > h21 ? h11 : h21) + 1;
  1382. }
  1383. if(p != null) {
  1384. p._children[nodeIndex] = l;
  1385. l._parent = p;
  1386. l._childIndex = nodeIndex;
  1387. } else {
  1388. _this._root = l;
  1389. l._parent = null;
  1390. }
  1391. node = l;
  1392. } else if(balance < -1) {
  1393. let rl = r._children[0];
  1394. let rr = r._children[1];
  1395. if(rl._height > rr._height) {
  1396. r._children[1] = node;
  1397. node._parent = r;
  1398. node._childIndex = 1;
  1399. node._children[1] = rr;
  1400. rr._parent = node;
  1401. rr._childIndex = 1;
  1402. let c1 = r._children[0];
  1403. let c2 = r._children[1];
  1404. r._aabbMinX = c1._aabbMinX < c2._aabbMinX ? c1._aabbMinX : c2._aabbMinX;
  1405. r._aabbMinY = c1._aabbMinY < c2._aabbMinY ? c1._aabbMinY : c2._aabbMinY;
  1406. r._aabbMinZ = c1._aabbMinZ < c2._aabbMinZ ? c1._aabbMinZ : c2._aabbMinZ;
  1407. r._aabbMaxX = c1._aabbMaxX > c2._aabbMaxX ? c1._aabbMaxX : c2._aabbMaxX;
  1408. r._aabbMaxY = c1._aabbMaxY > c2._aabbMaxY ? c1._aabbMaxY : c2._aabbMaxY;
  1409. r._aabbMaxZ = c1._aabbMaxZ > c2._aabbMaxZ ? c1._aabbMaxZ : c2._aabbMaxZ;
  1410. let h1 = r._children[0]._height;
  1411. let h2 = r._children[1]._height;
  1412. r._height = (h1 > h2 ? h1 : h2) + 1;
  1413. let c11 = node._children[0];
  1414. let c21 = node._children[1];
  1415. node._aabbMinX = c11._aabbMinX < c21._aabbMinX ? c11._aabbMinX : c21._aabbMinX;
  1416. node._aabbMinY = c11._aabbMinY < c21._aabbMinY ? c11._aabbMinY : c21._aabbMinY;
  1417. node._aabbMinZ = c11._aabbMinZ < c21._aabbMinZ ? c11._aabbMinZ : c21._aabbMinZ;
  1418. node._aabbMaxX = c11._aabbMaxX > c21._aabbMaxX ? c11._aabbMaxX : c21._aabbMaxX;
  1419. node._aabbMaxY = c11._aabbMaxY > c21._aabbMaxY ? c11._aabbMaxY : c21._aabbMaxY;
  1420. node._aabbMaxZ = c11._aabbMaxZ > c21._aabbMaxZ ? c11._aabbMaxZ : c21._aabbMaxZ;
  1421. let h11 = node._children[0]._height;
  1422. let h21 = node._children[1]._height;
  1423. node._height = (h11 > h21 ? h11 : h21) + 1;
  1424. } else {
  1425. r._children[0] = node;
  1426. node._parent = r;
  1427. node._childIndex = 0;
  1428. node._children[1] = rl;
  1429. rl._parent = node;
  1430. rl._childIndex = 1;
  1431. let c1 = r._children[0];
  1432. let c2 = r._children[1];
  1433. r._aabbMinX = c1._aabbMinX < c2._aabbMinX ? c1._aabbMinX : c2._aabbMinX;
  1434. r._aabbMinY = c1._aabbMinY < c2._aabbMinY ? c1._aabbMinY : c2._aabbMinY;
  1435. r._aabbMinZ = c1._aabbMinZ < c2._aabbMinZ ? c1._aabbMinZ : c2._aabbMinZ;
  1436. r._aabbMaxX = c1._aabbMaxX > c2._aabbMaxX ? c1._aabbMaxX : c2._aabbMaxX;
  1437. r._aabbMaxY = c1._aabbMaxY > c2._aabbMaxY ? c1._aabbMaxY : c2._aabbMaxY;
  1438. r._aabbMaxZ = c1._aabbMaxZ > c2._aabbMaxZ ? c1._aabbMaxZ : c2._aabbMaxZ;
  1439. let h1 = r._children[0]._height;
  1440. let h2 = r._children[1]._height;
  1441. r._height = (h1 > h2 ? h1 : h2) + 1;
  1442. let c11 = node._children[0];
  1443. let c21 = node._children[1];
  1444. node._aabbMinX = c11._aabbMinX < c21._aabbMinX ? c11._aabbMinX : c21._aabbMinX;
  1445. node._aabbMinY = c11._aabbMinY < c21._aabbMinY ? c11._aabbMinY : c21._aabbMinY;
  1446. node._aabbMinZ = c11._aabbMinZ < c21._aabbMinZ ? c11._aabbMinZ : c21._aabbMinZ;
  1447. node._aabbMaxX = c11._aabbMaxX > c21._aabbMaxX ? c11._aabbMaxX : c21._aabbMaxX;
  1448. node._aabbMaxY = c11._aabbMaxY > c21._aabbMaxY ? c11._aabbMaxY : c21._aabbMaxY;
  1449. node._aabbMaxZ = c11._aabbMaxZ > c21._aabbMaxZ ? c11._aabbMaxZ : c21._aabbMaxZ;
  1450. let h11 = node._children[0]._height;
  1451. let h21 = node._children[1]._height;
  1452. node._height = (h11 > h21 ? h11 : h21) + 1;
  1453. }
  1454. if(p != null) {
  1455. p._children[nodeIndex] = r;
  1456. r._parent = p;
  1457. r._childIndex = nodeIndex;
  1458. } else {
  1459. _this._root = r;
  1460. r._parent = null;
  1461. }
  1462. node = r;
  1463. }
  1464. }
  1465. }
  1466. let h1 = node._children[0]._height;
  1467. let h2 = node._children[1]._height;
  1468. node._height = (h1 > h2 ? h1 : h2) + 1;
  1469. let c1 = node._children[0];
  1470. let c2 = node._children[1];
  1471. node._aabbMinX = c1._aabbMinX < c2._aabbMinX ? c1._aabbMinX : c2._aabbMinX;
  1472. node._aabbMinY = c1._aabbMinY < c2._aabbMinY ? c1._aabbMinY : c2._aabbMinY;
  1473. node._aabbMinZ = c1._aabbMinZ < c2._aabbMinZ ? c1._aabbMinZ : c2._aabbMinZ;
  1474. node._aabbMaxX = c1._aabbMaxX > c2._aabbMaxX ? c1._aabbMaxX : c2._aabbMaxX;
  1475. node._aabbMaxY = c1._aabbMaxY > c2._aabbMaxY ? c1._aabbMaxY : c2._aabbMaxY;
  1476. node._aabbMaxZ = c1._aabbMaxZ > c2._aabbMaxZ ? c1._aabbMaxZ : c2._aabbMaxZ;
  1477. node = node._parent;
  1478. }
  1479. }
  1480. }
  1481. p._leaf = null;
  1482. leaf._next = null;
  1483. leaf._childIndex = 0;
  1484. leaf._children[0] = null;
  1485. leaf._children[1] = null;
  1486. leaf._childIndex = 0;
  1487. leaf._parent = null;
  1488. leaf._height = 0;
  1489. leaf._proxy = null;
  1490. leaf._next = _this._nodePool;
  1491. _this._nodePool = leaf;
  1492. let _this1 = this._tree;
  1493. let first = _this1._nodePool;
  1494. if(first != null) {
  1495. _this1._nodePool = first._next;
  1496. first._next = null;
  1497. } else {
  1498. first = new oimo.collision.broadphase.bvh.BvhNode();
  1499. }
  1500. let leaf1 = first;
  1501. leaf1._proxy = p;
  1502. p._leaf = leaf1;
  1503. leaf1._aabbMinX = p._aabbMinX;
  1504. leaf1._aabbMinY = p._aabbMinY;
  1505. leaf1._aabbMinZ = p._aabbMinZ;
  1506. leaf1._aabbMaxX = p._aabbMaxX;
  1507. leaf1._aabbMaxY = p._aabbMaxY;
  1508. leaf1._aabbMaxZ = p._aabbMaxZ;
  1509. _this1._numLeaves++;
  1510. if(_this1.leafList == null) {
  1511. _this1.leafList = leaf1;
  1512. _this1.leafListLast = leaf1;
  1513. } else {
  1514. _this1.leafListLast._nextLeaf = leaf1;
  1515. leaf1._prevLeaf = _this1.leafListLast;
  1516. _this1.leafListLast = leaf1;
  1517. }
  1518. if(_this1._root == null) {
  1519. _this1._root = leaf1;
  1520. } else {
  1521. let sibling = _this1._root;
  1522. while(sibling._height > 0) {
  1523. let nextStep = _this1._strategy._decideInsertion(sibling,leaf1);
  1524. if(nextStep == -1) {
  1525. break;
  1526. } else {
  1527. sibling = sibling._children[nextStep];
  1528. }
  1529. }
  1530. let parent = sibling._parent;
  1531. let first = _this1._nodePool;
  1532. if(first != null) {
  1533. _this1._nodePool = first._next;
  1534. first._next = null;
  1535. } else {
  1536. first = new oimo.collision.broadphase.bvh.BvhNode();
  1537. }
  1538. let node = first;
  1539. if(parent == null) {
  1540. _this1._root = node;
  1541. } else {
  1542. let index = sibling._childIndex;
  1543. parent._children[index] = node;
  1544. node._parent = parent;
  1545. node._childIndex = index;
  1546. }
  1547. let index = sibling._childIndex;
  1548. node._children[index] = sibling;
  1549. sibling._parent = node;
  1550. sibling._childIndex = index;
  1551. let index1 = sibling._childIndex ^ 1;
  1552. node._children[index1] = leaf1;
  1553. leaf1._parent = node;
  1554. leaf1._childIndex = index1;
  1555. while(node != null) {
  1556. if(_this1._strategy._balancingEnabled) {
  1557. if(node._height >= 2) {
  1558. let p = node._parent;
  1559. let l = node._children[0];
  1560. let r = node._children[1];
  1561. let balance = l._height - r._height;
  1562. let nodeIndex = node._childIndex;
  1563. if(balance > 1) {
  1564. let ll = l._children[0];
  1565. let lr = l._children[1];
  1566. if(ll._height > lr._height) {
  1567. l._children[1] = node;
  1568. node._parent = l;
  1569. node._childIndex = 1;
  1570. node._children[0] = lr;
  1571. lr._parent = node;
  1572. lr._childIndex = 0;
  1573. let c1 = l._children[0];
  1574. let c2 = l._children[1];
  1575. l._aabbMinX = c1._aabbMinX < c2._aabbMinX ? c1._aabbMinX : c2._aabbMinX;
  1576. l._aabbMinY = c1._aabbMinY < c2._aabbMinY ? c1._aabbMinY : c2._aabbMinY;
  1577. l._aabbMinZ = c1._aabbMinZ < c2._aabbMinZ ? c1._aabbMinZ : c2._aabbMinZ;
  1578. l._aabbMaxX = c1._aabbMaxX > c2._aabbMaxX ? c1._aabbMaxX : c2._aabbMaxX;
  1579. l._aabbMaxY = c1._aabbMaxY > c2._aabbMaxY ? c1._aabbMaxY : c2._aabbMaxY;
  1580. l._aabbMaxZ = c1._aabbMaxZ > c2._aabbMaxZ ? c1._aabbMaxZ : c2._aabbMaxZ;
  1581. let h1 = l._children[0]._height;
  1582. let h2 = l._children[1]._height;
  1583. l._height = (h1 > h2 ? h1 : h2) + 1;
  1584. let c11 = node._children[0];
  1585. let c21 = node._children[1];
  1586. node._aabbMinX = c11._aabbMinX < c21._aabbMinX ? c11._aabbMinX : c21._aabbMinX;
  1587. node._aabbMinY = c11._aabbMinY < c21._aabbMinY ? c11._aabbMinY : c21._aabbMinY;
  1588. node._aabbMinZ = c11._aabbMinZ < c21._aabbMinZ ? c11._aabbMinZ : c21._aabbMinZ;
  1589. node._aabbMaxX = c11._aabbMaxX > c21._aabbMaxX ? c11._aabbMaxX : c21._aabbMaxX;
  1590. node._aabbMaxY = c11._aabbMaxY > c21._aabbMaxY ? c11._aabbMaxY : c21._aabbMaxY;
  1591. node._aabbMaxZ = c11._aabbMaxZ > c21._aabbMaxZ ? c11._aabbMaxZ : c21._aabbMaxZ;
  1592. let h11 = node._children[0]._height;
  1593. let h21 = node._children[1]._height;
  1594. node._height = (h11 > h21 ? h11 : h21) + 1;
  1595. } else {
  1596. l._children[0] = node;
  1597. node._parent = l;
  1598. node._childIndex = 0;
  1599. node._children[0] = ll;
  1600. ll._parent = node;
  1601. ll._childIndex = 0;
  1602. let c1 = l._children[0];
  1603. let c2 = l._children[1];
  1604. l._aabbMinX = c1._aabbMinX < c2._aabbMinX ? c1._aabbMinX : c2._aabbMinX;
  1605. l._aabbMinY = c1._aabbMinY < c2._aabbMinY ? c1._aabbMinY : c2._aabbMinY;
  1606. l._aabbMinZ = c1._aabbMinZ < c2._aabbMinZ ? c1._aabbMinZ : c2._aabbMinZ;
  1607. l._aabbMaxX = c1._aabbMaxX > c2._aabbMaxX ? c1._aabbMaxX : c2._aabbMaxX;
  1608. l._aabbMaxY = c1._aabbMaxY > c2._aabbMaxY ? c1._aabbMaxY : c2._aabbMaxY;
  1609. l._aabbMaxZ = c1._aabbMaxZ > c2._aabbMaxZ ? c1._aabbMaxZ : c2._aabbMaxZ;
  1610. let h1 = l._children[0]._height;
  1611. let h2 = l._children[1]._height;
  1612. l._height = (h1 > h2 ? h1 : h2) + 1;
  1613. let c11 = node._children[0];
  1614. let c21 = node._children[1];
  1615. node._aabbMinX = c11._aabbMinX < c21._aabbMinX ? c11._aabbMinX : c21._aabbMinX;
  1616. node._aabbMinY = c11._aabbMinY < c21._aabbMinY ? c11._aabbMinY : c21._aabbMinY;
  1617. node._aabbMinZ = c11._aabbMinZ < c21._aabbMinZ ? c11._aabbMinZ : c21._aabbMinZ;
  1618. node._aabbMaxX = c11._aabbMaxX > c21._aabbMaxX ? c11._aabbMaxX : c21._aabbMaxX;
  1619. node._aabbMaxY = c11._aabbMaxY > c21._aabbMaxY ? c11._aabbMaxY : c21._aabbMaxY;
  1620. node._aabbMaxZ = c11._aabbMaxZ > c21._aabbMaxZ ? c11._aabbMaxZ : c21._aabbMaxZ;
  1621. let h11 = node._children[0]._height;
  1622. let h21 = node._children[1]._height;
  1623. node._height = (h11 > h21 ? h11 : h21) + 1;
  1624. }
  1625. if(p != null) {
  1626. p._children[nodeIndex] = l;
  1627. l._parent = p;
  1628. l._childIndex = nodeIndex;
  1629. } else {
  1630. _this1._root = l;
  1631. l._parent = null;
  1632. }
  1633. node = l;
  1634. } else if(balance < -1) {
  1635. let rl = r._children[0];
  1636. let rr = r._children[1];
  1637. if(rl._height > rr._height) {
  1638. r._children[1] = node;
  1639. node._parent = r;
  1640. node._childIndex = 1;
  1641. node._children[1] = rr;
  1642. rr._parent = node;
  1643. rr._childIndex = 1;
  1644. let c1 = r._children[0];
  1645. let c2 = r._children[1];
  1646. r._aabbMinX = c1._aabbMinX < c2._aabbMinX ? c1._aabbMinX : c2._aabbMinX;
  1647. r._aabbMinY = c1._aabbMinY < c2._aabbMinY ? c1._aabbMinY : c2._aabbMinY;
  1648. r._aabbMinZ = c1._aabbMinZ < c2._aabbMinZ ? c1._aabbMinZ : c2._aabbMinZ;
  1649. r._aabbMaxX = c1._aabbMaxX > c2._aabbMaxX ? c1._aabbMaxX : c2._aabbMaxX;
  1650. r._aabbMaxY = c1._aabbMaxY > c2._aabbMaxY ? c1._aabbMaxY : c2._aabbMaxY;
  1651. r._aabbMaxZ = c1._aabbMaxZ > c2._aabbMaxZ ? c1._aabbMaxZ : c2._aabbMaxZ;
  1652. let h1 = r._children[0]._height;
  1653. let h2 = r._children[1]._height;
  1654. r._height = (h1 > h2 ? h1 : h2) + 1;
  1655. let c11 = node._children[0];
  1656. let c21 = node._children[1];
  1657. node._aabbMinX = c11._aabbMinX < c21._aabbMinX ? c11._aabbMinX : c21._aabbMinX;
  1658. node._aabbMinY = c11._aabbMinY < c21._aabbMinY ? c11._aabbMinY : c21._aabbMinY;
  1659. node._aabbMinZ = c11._aabbMinZ < c21._aabbMinZ ? c11._aabbMinZ : c21._aabbMinZ;
  1660. node._aabbMaxX = c11._aabbMaxX > c21._aabbMaxX ? c11._aabbMaxX : c21._aabbMaxX;
  1661. node._aabbMaxY = c11._aabbMaxY > c21._aabbMaxY ? c11._aabbMaxY : c21._aabbMaxY;
  1662. node._aabbMaxZ = c11._aabbMaxZ > c21._aabbMaxZ ? c11._aabbMaxZ : c21._aabbMaxZ;
  1663. let h11 = node._children[0]._height;
  1664. let h21 = node._children[1]._height;
  1665. node._height = (h11 > h21 ? h11 : h21) + 1;
  1666. } else {
  1667. r._children[0] = node;
  1668. node._parent = r;
  1669. node._childIndex = 0;
  1670. node._children[1] = rl;
  1671. rl._parent = node;
  1672. rl._childIndex = 1;
  1673. let c1 = r._children[0];
  1674. let c2 = r._children[1];
  1675. r._aabbMinX = c1._aabbMinX < c2._aabbMinX ? c1._aabbMinX : c2._aabbMinX;
  1676. r._aabbMinY = c1._aabbMinY < c2._aabbMinY ? c1._aabbMinY : c2._aabbMinY;
  1677. r._aabbMinZ = c1._aabbMinZ < c2._aabbMinZ ? c1._aabbMinZ : c2._aabbMinZ;
  1678. r._aabbMaxX = c1._aabbMaxX > c2._aabbMaxX ? c1._aabbMaxX : c2._aabbMaxX;
  1679. r._aabbMaxY = c1._aabbMaxY > c2._aabbMaxY ? c1._aabbMaxY : c2._aabbMaxY;
  1680. r._aabbMaxZ = c1._aabbMaxZ > c2._aabbMaxZ ? c1._aabbMaxZ : c2._aabbMaxZ;
  1681. let h1 = r._children[0]._height;
  1682. let h2 = r._children[1]._height;
  1683. r._height = (h1 > h2 ? h1 : h2) + 1;
  1684. let c11 = node._children[0];
  1685. let c21 = node._children[1];
  1686. node._aabbMinX = c11._aabbMinX < c21._aabbMinX ? c11._aabbMinX : c21._aabbMinX;
  1687. node._aabbMinY = c11._aabbMinY < c21._aabbMinY ? c11._aabbMinY : c21._aabbMinY;
  1688. node._aabbMinZ = c11._aabbMinZ < c21._aabbMinZ ? c11._aabbMinZ : c21._aabbMinZ;
  1689. node._aabbMaxX = c11._aabbMaxX > c21._aabbMaxX ? c11._aabbMaxX : c21._aabbMaxX;
  1690. node._aabbMaxY = c11._aabbMaxY > c21._aabbMaxY ? c11._aabbMaxY : c21._aabbMaxY;
  1691. node._aabbMaxZ = c11._aabbMaxZ > c21._aabbMaxZ ? c11._aabbMaxZ : c21._aabbMaxZ;
  1692. let h11 = node._children[0]._height;
  1693. let h21 = node._children[1]._height;
  1694. node._height = (h11 > h21 ? h11 : h21) + 1;
  1695. }
  1696. if(p != null) {
  1697. p._children[nodeIndex] = r;
  1698. r._parent = p;
  1699. r._childIndex = nodeIndex;
  1700. } else {
  1701. _this1._root = r;
  1702. r._parent = null;
  1703. }
  1704. node = r;
  1705. }
  1706. }
  1707. }
  1708. let h1 = node._children[0]._height;
  1709. let h2 = node._children[1]._height;
  1710. node._height = (h1 > h2 ? h1 : h2) + 1;
  1711. let c1 = node._children[0];
  1712. let c2 = node._children[1];
  1713. node._aabbMinX = c1._aabbMinX < c2._aabbMinX ? c1._aabbMinX : c2._aabbMinX;
  1714. node._aabbMinY = c1._aabbMinY < c2._aabbMinY ? c1._aabbMinY : c2._aabbMinY;
  1715. node._aabbMinZ = c1._aabbMinZ < c2._aabbMinZ ? c1._aabbMinZ : c2._aabbMinZ;
  1716. node._aabbMaxX = c1._aabbMaxX > c2._aabbMaxX ? c1._aabbMaxX : c2._aabbMaxX;
  1717. node._aabbMaxY = c1._aabbMaxY > c2._aabbMaxY ? c1._aabbMaxY : c2._aabbMaxY;
  1718. node._aabbMaxZ = c1._aabbMaxZ > c2._aabbMaxZ ? c1._aabbMaxZ : c2._aabbMaxZ;
  1719. node = node._parent;
  1720. }
  1721. }
  1722. if(incrementalCollision) {
  1723. this.collide(this._tree._root,p._leaf);
  1724. }
  1725. p._moved = false;
  1726. }
  1727. this.movedProxies[i] = null;
  1728. }
  1729. if(!incrementalCollision) {
  1730. this.collide(this._tree._root,this._tree._root);
  1731. }
  1732. this.numMovedProxies = 0;
  1733. }
  1734. rayCast(begin,end,callback) {
  1735. if(this._tree._root == null) {
  1736. return;
  1737. }
  1738. let p1X;
  1739. let p1Y;
  1740. let p1Z;
  1741. let p2X;
  1742. let p2Y;
  1743. let p2Z;
  1744. p1X = begin.x;
  1745. p1Y = begin.y;
  1746. p1Z = begin.z;
  1747. p2X = end.x;
  1748. p2Y = end.y;
  1749. p2Z = end.z;
  1750. this.rayCastRecursive(this._tree._root,p1X,p1Y,p1Z,p2X,p2Y,p2Z,callback);
  1751. }
  1752. convexCast(convex,begin,translation,callback) {
  1753. if(this._tree._root == null) {
  1754. return;
  1755. }
  1756. this.convexCastRecursive(this._tree._root,convex,begin,translation,callback);
  1757. }
  1758. aabbTest(aabb,callback) {
  1759. if(this._tree._root == null) {
  1760. return;
  1761. }
  1762. this.aabbTestRecursive(this._tree._root,aabb,callback);
  1763. }
  1764. getTreeBalance() {
  1765. return this._tree._getBalance();
  1766. }
  1767. }
  1768. oimo.collision.broadphase.bvh.BvhInsertionStrategy = class oimo_collision_broadphase_bvh_BvhInsertionStrategy {
  1769. }
  1770. oimo.collision.broadphase.bvh.BvhNode = class oimo_collision_broadphase_bvh_BvhNode {
  1771. constructor() {
  1772. this._next = null;
  1773. this._prevLeaf = null;
  1774. this._nextLeaf = null;
  1775. this._children = new Array(2);
  1776. this._childIndex = 0;
  1777. this._parent = null;
  1778. this._height = 0;
  1779. this._proxy = null;
  1780. this._aabbMinX = 0;
  1781. this._aabbMinY = 0;
  1782. this._aabbMinZ = 0;
  1783. this._aabbMaxX = 0;
  1784. this._aabbMaxY = 0;
  1785. this._aabbMaxZ = 0;
  1786. }
  1787. }
  1788. oimo.collision.broadphase.bvh.BvhProxy = class oimo_collision_broadphase_bvh_BvhProxy extends oimo.collision.broadphase.Proxy {
  1789. constructor(userData,id) {
  1790. super(userData,id);
  1791. this._leaf = null;
  1792. this._moved = false;
  1793. }
  1794. }
  1795. oimo.collision.broadphase.bvh.BvhStrategy = class oimo_collision_broadphase_bvh_BvhStrategy {
  1796. constructor() {
  1797. this._insertionStrategy = 0;
  1798. this._balancingEnabled = false;
  1799. }
  1800. _decideInsertion(currentNode,leaf) {
  1801. switch(this._insertionStrategy) {
  1802. case 0:
  1803. let centerX;
  1804. let centerY;
  1805. let centerZ;
  1806. centerX = leaf._aabbMinX + leaf._aabbMaxX;
  1807. centerY = leaf._aabbMinY + leaf._aabbMaxY;
  1808. centerZ = leaf._aabbMinZ + leaf._aabbMaxZ;
  1809. let c1 = currentNode._children[0];
  1810. let c2 = currentNode._children[1];
  1811. let diff1X;
  1812. let diff1Y;
  1813. let diff1Z;
  1814. let diff2X;
  1815. let diff2Y;
  1816. let diff2Z;
  1817. diff1X = c1._aabbMinX + c1._aabbMaxX;
  1818. diff1Y = c1._aabbMinY + c1._aabbMaxY;
  1819. diff1Z = c1._aabbMinZ + c1._aabbMaxZ;
  1820. diff2X = c2._aabbMinX + c2._aabbMaxX;
  1821. diff2Y = c2._aabbMinY + c2._aabbMaxY;
  1822. diff2Z = c2._aabbMinZ + c2._aabbMaxZ;
  1823. diff1X -= centerX;
  1824. diff1Y -= centerY;
  1825. diff1Z -= centerZ;
  1826. diff2X -= centerX;
  1827. diff2Y -= centerY;
  1828. diff2Z -= centerZ;
  1829. if(diff1X * diff1X + diff1Y * diff1Y + diff1Z * diff1Z < diff2X * diff2X + diff2Y * diff2Y + diff2Z * diff2Z) {
  1830. return 0;
  1831. } else {
  1832. return 1;
  1833. }
  1834. break;
  1835. case 1:
  1836. let c11 = currentNode._children[0];
  1837. let c21 = currentNode._children[1];
  1838. let ey = currentNode._aabbMaxY - currentNode._aabbMinY;
  1839. let ez = currentNode._aabbMaxZ - currentNode._aabbMinZ;
  1840. let combinedMinX;
  1841. let combinedMinY;
  1842. let combinedMinZ;
  1843. let combinedMaxX;
  1844. let combinedMaxY;
  1845. let combinedMaxZ;
  1846. combinedMinX = currentNode._aabbMinX < leaf._aabbMinX ? currentNode._aabbMinX : leaf._aabbMinX;
  1847. combinedMinY = currentNode._aabbMinY < leaf._aabbMinY ? currentNode._aabbMinY : leaf._aabbMinY;
  1848. combinedMinZ = currentNode._aabbMinZ < leaf._aabbMinZ ? currentNode._aabbMinZ : leaf._aabbMinZ;
  1849. combinedMaxX = currentNode._aabbMaxX > leaf._aabbMaxX ? currentNode._aabbMaxX : leaf._aabbMaxX;
  1850. combinedMaxY = currentNode._aabbMaxY > leaf._aabbMaxY ? currentNode._aabbMaxY : leaf._aabbMaxY;
  1851. combinedMaxZ = currentNode._aabbMaxZ > leaf._aabbMaxZ ? currentNode._aabbMaxZ : leaf._aabbMaxZ;
  1852. let ey1 = combinedMaxY - combinedMinY;
  1853. let ez1 = combinedMaxZ - combinedMinZ;
  1854. let newArea = ((combinedMaxX - combinedMinX) * (ey1 + ez1) + ey1 * ez1) * 2;
  1855. let creatingCost = newArea * 2;
  1856. let incrementalCost = (newArea - ((currentNode._aabbMaxX - currentNode._aabbMinX) * (ey + ez) + ey * ez) * 2) * 2;
  1857. let descendingCost1;
  1858. combinedMinX = c11._aabbMinX < leaf._aabbMinX ? c11._aabbMinX : leaf._aabbMinX;
  1859. combinedMinY = c11._aabbMinY < leaf._aabbMinY ? c11._aabbMinY : leaf._aabbMinY;
  1860. combinedMinZ = c11._aabbMinZ < leaf._aabbMinZ ? c11._aabbMinZ : leaf._aabbMinZ;
  1861. combinedMaxX = c11._aabbMaxX > leaf._aabbMaxX ? c11._aabbMaxX : leaf._aabbMaxX;
  1862. combinedMaxY = c11._aabbMaxY > leaf._aabbMaxY ? c11._aabbMaxY : leaf._aabbMaxY;
  1863. combinedMaxZ = c11._aabbMaxZ > leaf._aabbMaxZ ? c11._aabbMaxZ : leaf._aabbMaxZ;
  1864. if(c11._height == 0) {
  1865. let ey = combinedMaxY - combinedMinY;
  1866. let ez = combinedMaxZ - combinedMinZ;
  1867. descendingCost1 = incrementalCost + ((combinedMaxX - combinedMinX) * (ey + ez) + ey * ez) * 2;
  1868. } else {
  1869. let ey = combinedMaxY - combinedMinY;
  1870. let ez = combinedMaxZ - combinedMinZ;
  1871. let ey1 = c11._aabbMaxY - c11._aabbMinY;
  1872. let ez1 = c11._aabbMaxZ - c11._aabbMinZ;
  1873. descendingCost1 = incrementalCost + (((combinedMaxX - combinedMinX) * (ey + ez) + ey * ez) * 2 - ((c11._aabbMaxX - c11._aabbMinX) * (ey1 + ez1) + ey1 * ez1) * 2);
  1874. }
  1875. let descendingCost2;
  1876. combinedMinX = c21._aabbMinX < leaf._aabbMinX ? c21._aabbMinX : leaf._aabbMinX;
  1877. combinedMinY = c21._aabbMinY < leaf._aabbMinY ? c21._aabbMinY : leaf._aabbMinY;
  1878. combinedMinZ = c21._aabbMinZ < leaf._aabbMinZ ? c21._aabbMinZ : leaf._aabbMinZ;
  1879. combinedMaxX = c21._aabbMaxX > leaf._aabbMaxX ? c21._aabbMaxX : leaf._aabbMaxX;
  1880. combinedMaxY = c21._aabbMaxY > leaf._aabbMaxY ? c21._aabbMaxY : leaf._aabbMaxY;
  1881. combinedMaxZ = c21._aabbMaxZ > leaf._aabbMaxZ ? c21._aabbMaxZ : leaf._aabbMaxZ;
  1882. if(c21._height == 0) {
  1883. let ey = combinedMaxY - combinedMinY;
  1884. let ez = combinedMaxZ - combinedMinZ;
  1885. descendingCost2 = incrementalCost + ((combinedMaxX - combinedMinX) * (ey + ez) + ey * ez) * 2;
  1886. } else {
  1887. let ey = combinedMaxY - combinedMinY;
  1888. let ez = combinedMaxZ - combinedMinZ;
  1889. let ey1 = c21._aabbMaxY - c21._aabbMinY;
  1890. let ez1 = c21._aabbMaxZ - c21._aabbMinZ;
  1891. descendingCost2 = incrementalCost + (((combinedMaxX - combinedMinX) * (ey + ez) + ey * ez) * 2 - ((c21._aabbMaxX - c21._aabbMinX) * (ey1 + ez1) + ey1 * ez1) * 2);
  1892. }
  1893. if(creatingCost < descendingCost1) {
  1894. if(creatingCost < descendingCost2) {
  1895. return -1;
  1896. } else {
  1897. return 1;
  1898. }
  1899. } else if(descendingCost1 < descendingCost2) {
  1900. return 0;
  1901. } else {
  1902. return 1;
  1903. }
  1904. break;
  1905. default:
  1906. console.log("src/oimo/collision/broadphase/bvh/BvhStrategy.hx:37:","invalid BVH insertion strategy: " + this._insertionStrategy);
  1907. return -1;
  1908. }
  1909. }
  1910. _splitLeaves(leaves,from,until) {
  1911. let invN = 1.0 / (until - from);
  1912. let centerMeanX;
  1913. let centerMeanY;
  1914. let centerMeanZ;
  1915. centerMeanX = 0;
  1916. centerMeanY = 0;
  1917. centerMeanZ = 0;
  1918. let _g = from;
  1919. while(_g < until) {
  1920. let leaf = leaves[_g++];
  1921. leaf._tmpX = leaf._aabbMaxX + leaf._aabbMinX;
  1922. leaf._tmpY = leaf._aabbMaxY + leaf._aabbMinY;
  1923. leaf._tmpZ = leaf._aabbMaxZ + leaf._aabbMinZ;
  1924. centerMeanX += leaf._tmpX;
  1925. centerMeanY += leaf._tmpY;
  1926. centerMeanZ += leaf._tmpZ;
  1927. }
  1928. centerMeanX *= invN;
  1929. centerMeanY *= invN;
  1930. centerMeanZ *= invN;
  1931. let varianceX;
  1932. let varianceY;
  1933. let varianceZ;
  1934. varianceX = 0;
  1935. varianceY = 0;
  1936. varianceZ = 0;
  1937. let _g1 = from;
  1938. while(_g1 < until) {
  1939. let leaf = leaves[_g1++];
  1940. let diffX;
  1941. let diffY;
  1942. let diffZ;
  1943. diffX = leaf._tmpX - centerMeanX;
  1944. diffY = leaf._tmpY - centerMeanY;
  1945. diffZ = leaf._tmpZ - centerMeanZ;
  1946. diffX *= diffX;
  1947. diffY *= diffY;
  1948. diffZ *= diffZ;
  1949. varianceX += diffX;
  1950. varianceY += diffY;
  1951. varianceZ += diffZ;
  1952. }
  1953. let varX = varianceX;
  1954. let varY = varianceY;
  1955. let varZ = varianceZ;
  1956. let l = from;
  1957. let r = until - 1;
  1958. if(varX > varY) {
  1959. if(varX > varZ) {
  1960. let mean = centerMeanX;
  1961. while(true) {
  1962. while(!(leaves[l]._tmpX <= mean)) ++l;
  1963. while(!(leaves[r]._tmpX >= mean)) --r;
  1964. if(l >= r) {
  1965. break;
  1966. }
  1967. let tmp = leaves[l];
  1968. leaves[l] = leaves[r];
  1969. leaves[r] = tmp;
  1970. ++l;
  1971. --r;
  1972. }
  1973. } else {
  1974. let mean = centerMeanZ;
  1975. while(true) {
  1976. while(!(leaves[l]._tmpZ <= mean)) ++l;
  1977. while(!(leaves[r]._tmpZ >= mean)) --r;
  1978. if(l >= r) {
  1979. break;
  1980. }
  1981. let tmp = leaves[l];
  1982. leaves[l] = leaves[r];
  1983. leaves[r] = tmp;
  1984. ++l;
  1985. --r;
  1986. }
  1987. }
  1988. } else if(varY > varZ) {
  1989. let mean = centerMeanY;
  1990. while(true) {
  1991. while(!(leaves[l]._tmpY <= mean)) ++l;
  1992. while(!(leaves[r]._tmpY >= mean)) --r;
  1993. if(l >= r) {
  1994. break;
  1995. }
  1996. let tmp = leaves[l];
  1997. leaves[l] = leaves[r];
  1998. leaves[r] = tmp;
  1999. ++l;
  2000. --r;
  2001. }
  2002. } else {
  2003. let mean = centerMeanZ;
  2004. while(true) {
  2005. while(!(leaves[l]._tmpZ <= mean)) ++l;
  2006. while(!(leaves[r]._tmpZ >= mean)) --r;
  2007. if(l >= r) {
  2008. break;
  2009. }
  2010. let tmp = leaves[l];
  2011. leaves[l] = leaves[r];
  2012. leaves[r] = tmp;
  2013. ++l;
  2014. --r;
  2015. }
  2016. }
  2017. return l;
  2018. }
  2019. }
  2020. oimo.collision.broadphase.bvh.BvhTree = class oimo_collision_broadphase_bvh_BvhTree {
  2021. constructor() {
  2022. this._root = null;
  2023. this._numLeaves = 0;
  2024. this._strategy = new oimo.collision.broadphase.bvh.BvhStrategy();
  2025. this._nodePool = null;
  2026. this.leafList = null;
  2027. this.leafListLast = null;
  2028. this.tmp = new Array(1024);
  2029. }
  2030. _print(root,indent) {
  2031. if(indent == null) {
  2032. indent = "";
  2033. }
  2034. if(root == null) {
  2035. return;
  2036. }
  2037. if(root._height == 0) {
  2038. console.log("src/oimo/collision/broadphase/bvh/BvhTree.hx:39:",indent + root._proxy._id);
  2039. } else {
  2040. this._print(root._children[0],indent + " ");
  2041. let tmp;
  2042. let sizeX;
  2043. let sizeY;
  2044. let sizeZ;
  2045. sizeX = root._aabbMaxX - root._aabbMinX;
  2046. sizeY = root._aabbMaxY - root._aabbMinY;
  2047. sizeZ = root._aabbMaxZ - root._aabbMinZ;
  2048. let y = sizeY;
  2049. let z = sizeZ;
  2050. if(sizeX * (y + z) + y * z > 0) {
  2051. let sizeX;
  2052. let sizeY;
  2053. let sizeZ;
  2054. sizeX = root._aabbMaxX - root._aabbMinX;
  2055. sizeY = root._aabbMaxY - root._aabbMinY;
  2056. sizeZ = root._aabbMaxZ - root._aabbMinZ;
  2057. let y = sizeY;
  2058. let z = sizeZ;
  2059. tmp = ((sizeX * (y + z) + y * z) * 1000 + 0.5 | 0) / 1000;
  2060. } else {
  2061. let sizeX;
  2062. let sizeY;
  2063. let sizeZ;
  2064. sizeX = root._aabbMaxX - root._aabbMinX;
  2065. sizeY = root._aabbMaxY - root._aabbMinY;
  2066. sizeZ = root._aabbMaxZ - root._aabbMinZ;
  2067. let y = sizeY;
  2068. let z = sizeZ;
  2069. tmp = ((sizeX * (y + z) + y * z) * 1000 - 0.5 | 0) / 1000;
  2070. }
  2071. console.log("src/oimo/collision/broadphase/bvh/BvhTree.hx:42:",indent + "#" + root._height + ", " + tmp);
  2072. this._print(root._children[1],indent + " ");
  2073. }
  2074. }
  2075. _getBalance() {
  2076. return this.getBalanceRecursive(this._root);
  2077. }
  2078. deleteRecursive(root) {
  2079. if(root._height == 0) {
  2080. let prev = root._prevLeaf;
  2081. let next = root._nextLeaf;
  2082. if(prev != null) {
  2083. prev._nextLeaf = next;
  2084. }
  2085. if(next != null) {
  2086. next._prevLeaf = prev;
  2087. }
  2088. if(root == this.leafList) {
  2089. this.leafList = this.leafList._nextLeaf;
  2090. }
  2091. if(root == this.leafListLast) {
  2092. this.leafListLast = this.leafListLast._prevLeaf;
  2093. }
  2094. root._nextLeaf = null;
  2095. root._prevLeaf = null;
  2096. root._proxy._leaf = null;
  2097. root._next = null;
  2098. root._childIndex = 0;
  2099. root._children[0] = null;
  2100. root._children[1] = null;
  2101. root._childIndex = 0;
  2102. root._parent = null;
  2103. root._height = 0;
  2104. root._proxy = null;
  2105. root._next = this._nodePool;
  2106. this._nodePool = root;
  2107. return;
  2108. }
  2109. this.deleteRecursive(root._children[0]);
  2110. this.deleteRecursive(root._children[1]);
  2111. root._next = null;
  2112. root._childIndex = 0;
  2113. root._children[0] = null;
  2114. root._children[1] = null;
  2115. root._childIndex = 0;
  2116. root._parent = null;
  2117. root._height = 0;
  2118. root._proxy = null;
  2119. root._next = this._nodePool;
  2120. this._nodePool = root;
  2121. }
  2122. decomposeRecursive(root) {
  2123. if(root._height == 0) {
  2124. root._childIndex = 0;
  2125. root._parent = null;
  2126. return;
  2127. }
  2128. this.decomposeRecursive(root._children[0]);
  2129. this.decomposeRecursive(root._children[1]);
  2130. root._next = null;
  2131. root._childIndex = 0;
  2132. root._children[0] = null;
  2133. root._children[1] = null;
  2134. root._childIndex = 0;
  2135. root._parent = null;
  2136. root._height = 0;
  2137. root._proxy = null;
  2138. root._next = this._nodePool;
  2139. this._nodePool = root;
  2140. }
  2141. buildTopDownRecursive(leaves,from,until) {
  2142. if(until - from == 1) {
  2143. let leaf = leaves[from];
  2144. let proxy = leaf._proxy;
  2145. leaf._aabbMinX = proxy._aabbMinX;
  2146. leaf._aabbMinY = proxy._aabbMinY;
  2147. leaf._aabbMinZ = proxy._aabbMinZ;
  2148. leaf._aabbMaxX = proxy._aabbMaxX;
  2149. leaf._aabbMaxY = proxy._aabbMaxY;
  2150. leaf._aabbMaxZ = proxy._aabbMaxZ;
  2151. return leaf;
  2152. }
  2153. let splitAt = this._strategy._splitLeaves(leaves,from,until);
  2154. let child1 = this.buildTopDownRecursive(leaves,from,splitAt);
  2155. let child2 = this.buildTopDownRecursive(leaves,splitAt,until);
  2156. let first = this._nodePool;
  2157. if(first != null) {
  2158. this._nodePool = first._next;
  2159. first._next = null;
  2160. } else {
  2161. first = new oimo.collision.broadphase.bvh.BvhNode();
  2162. }
  2163. let parent = first;
  2164. parent._children[0] = child1;
  2165. child1._parent = parent;
  2166. child1._childIndex = 0;
  2167. parent._children[1] = child2;
  2168. child2._parent = parent;
  2169. child2._childIndex = 1;
  2170. let c1 = parent._children[0];
  2171. let c2 = parent._children[1];
  2172. parent._aabbMinX = c1._aabbMinX < c2._aabbMinX ? c1._aabbMinX : c2._aabbMinX;
  2173. parent._aabbMinY = c1._aabbMinY < c2._aabbMinY ? c1._aabbMinY : c2._aabbMinY;
  2174. parent._aabbMinZ = c1._aabbMinZ < c2._aabbMinZ ? c1._aabbMinZ : c2._aabbMinZ;
  2175. parent._aabbMaxX = c1._aabbMaxX > c2._aabbMaxX ? c1._aabbMaxX : c2._aabbMaxX;
  2176. parent._aabbMaxY = c1._aabbMaxY > c2._aabbMaxY ? c1._aabbMaxY : c2._aabbMaxY;
  2177. parent._aabbMaxZ = c1._aabbMaxZ > c2._aabbMaxZ ? c1._aabbMaxZ : c2._aabbMaxZ;
  2178. let h1 = parent._children[0]._height;
  2179. let h2 = parent._children[1]._height;
  2180. parent._height = (h1 > h2 ? h1 : h2) + 1;
  2181. return parent;
  2182. }
  2183. getBalanceRecursive(root) {
  2184. if(root == null || root._height == 0) {
  2185. return 0;
  2186. }
  2187. let balance = root._children[0]._height - root._children[1]._height;
  2188. if(balance < 0) {
  2189. balance = -balance;
  2190. }
  2191. return balance + this.getBalanceRecursive(root._children[0]) + this.getBalanceRecursive(root._children[1]);
  2192. }
  2193. }
  2194. oimo.collision.geometry.Aabb = class oimo_collision_geometry_Aabb {
  2195. constructor() {
  2196. this._minX = 0;
  2197. this._minY = 0;
  2198. this._minZ = 0;
  2199. this._maxX = 0;
  2200. this._maxY = 0;
  2201. this._maxZ = 0;
  2202. }
  2203. init(min,max) {
  2204. this._minX = min.x;
  2205. this._minY = min.y;
  2206. this._minZ = min.z;
  2207. this._maxX = max.x;
  2208. this._maxY = max.y;
  2209. this._maxZ = max.z;
  2210. return this;
  2211. }
  2212. getMin() {
  2213. let min = new oimo.common.Vec3();
  2214. min.x = this._minX;
  2215. min.y = this._minY;
  2216. min.z = this._minZ;
  2217. return min;
  2218. }
  2219. getMinTo(min) {
  2220. min.x = this._minX;
  2221. min.y = this._minY;
  2222. min.z = this._minZ;
  2223. }
  2224. setMin(min) {
  2225. this._minX = min.x;
  2226. this._minY = min.y;
  2227. this._minZ = min.z;
  2228. return this;
  2229. }
  2230. getMax() {
  2231. let max = new oimo.common.Vec3();
  2232. max.x = this._maxX;
  2233. max.y = this._maxY;
  2234. max.z = this._maxZ;
  2235. return max;
  2236. }
  2237. getMaxTo(max) {
  2238. max.x = this._maxX;
  2239. max.y = this._maxY;
  2240. max.z = this._maxZ;
  2241. }
  2242. setMax(max) {
  2243. this._maxX = max.x;
  2244. this._maxY = max.y;
  2245. this._maxZ = max.z;
  2246. return this;
  2247. }
  2248. getCenter() {
  2249. let v = new oimo.common.Vec3();
  2250. let cX;
  2251. let cY;
  2252. let cZ;
  2253. cX = this._minX + this._maxX;
  2254. cY = this._minY + this._maxY;
  2255. cZ = this._minZ + this._maxZ;
  2256. cX *= 0.5;
  2257. cY *= 0.5;
  2258. cZ *= 0.5;
  2259. v.x = cX;
  2260. v.y = cY;
  2261. v.z = cZ;
  2262. return v;
  2263. }
  2264. getCenterTo(center) {
  2265. let cX;
  2266. let cY;
  2267. let cZ;
  2268. cX = this._minX + this._maxX;
  2269. cY = this._minY + this._maxY;
  2270. cZ = this._minZ + this._maxZ;
  2271. cX *= 0.5;
  2272. cY *= 0.5;
  2273. cZ *= 0.5;
  2274. center.x = cX;
  2275. center.y = cY;
  2276. center.z = cZ;
  2277. }
  2278. getExtents() {
  2279. let v = new oimo.common.Vec3();
  2280. let cX;
  2281. let cY;
  2282. let cZ;
  2283. cX = this._maxX - this._minX;
  2284. cY = this._maxY - this._minY;
  2285. cZ = this._maxZ - this._minZ;
  2286. cX *= 0.5;
  2287. cY *= 0.5;
  2288. cZ *= 0.5;
  2289. v.x = cX;
  2290. v.y = cY;
  2291. v.z = cZ;
  2292. return v;
  2293. }
  2294. getExtentsTo(halfExtents) {
  2295. let cX;
  2296. let cY;
  2297. let cZ;
  2298. cX = this._maxX - this._minX;
  2299. cY = this._maxY - this._minY;
  2300. cZ = this._maxZ - this._minZ;
  2301. cX *= 0.5;
  2302. cY *= 0.5;
  2303. cZ *= 0.5;
  2304. halfExtents.x = cX;
  2305. halfExtents.y = cY;
  2306. halfExtents.z = cZ;
  2307. }
  2308. combine(other) {
  2309. this._minX = this._minX < other._minX ? this._minX : other._minX;
  2310. this._minY = this._minY < other._minY ? this._minY : other._minY;
  2311. this._minZ = this._minZ < other._minZ ? this._minZ : other._minZ;
  2312. this._maxX = this._maxX > other._maxX ? this._maxX : other._maxX;
  2313. this._maxY = this._maxY > other._maxY ? this._maxY : other._maxY;
  2314. this._maxZ = this._maxZ > other._maxZ ? this._maxZ : other._maxZ;
  2315. return this;
  2316. }
  2317. combined(other) {
  2318. let aabb = new oimo.collision.geometry.Aabb();
  2319. aabb._minX = this._minX < other._minX ? this._minX : other._minX;
  2320. aabb._minY = this._minY < other._minY ? this._minY : other._minY;
  2321. aabb._minZ = this._minZ < other._minZ ? this._minZ : other._minZ;
  2322. aabb._maxX = this._maxX > other._maxX ? this._maxX : other._maxX;
  2323. aabb._maxY = this._maxY > other._maxY ? this._maxY : other._maxY;
  2324. aabb._maxZ = this._maxZ > other._maxZ ? this._maxZ : other._maxZ;
  2325. return aabb;
  2326. }
  2327. overlap(other) {
  2328. if(this._minX < other._maxX && this._maxX > other._minX && this._minY < other._maxY && this._maxY > other._minY && this._minZ < other._maxZ) {
  2329. return this._maxZ > other._minZ;
  2330. } else {
  2331. return false;
  2332. }
  2333. }
  2334. getIntersection(other) {
  2335. let aabb = new oimo.collision.geometry.Aabb();
  2336. aabb._minX = this._minX > other._minX ? this._minX : other._minX;
  2337. aabb._minY = this._minY > other._minY ? this._minY : other._minY;
  2338. aabb._minZ = this._minZ > other._minZ ? this._minZ : other._minZ;
  2339. aabb._maxX = this._maxX < other._maxX ? this._maxX : other._maxX;
  2340. aabb._maxY = this._maxY < other._maxY ? this._maxY : other._maxY;
  2341. aabb._maxZ = this._maxZ < other._maxZ ? this._maxZ : other._maxZ;
  2342. return aabb;
  2343. }
  2344. getIntersectionTo(other,intersection) {
  2345. intersection._minX = this._minX > other._minX ? this._minX : other._minX;
  2346. intersection._minY = this._minY > other._minY ? this._minY : other._minY;
  2347. intersection._minZ = this._minZ > other._minZ ? this._minZ : other._minZ;
  2348. intersection._maxX = this._maxX < other._maxX ? this._maxX : other._maxX;
  2349. intersection._maxY = this._maxY < other._maxY ? this._maxY : other._maxY;
  2350. intersection._maxZ = this._maxZ < other._maxZ ? this._maxZ : other._maxZ;
  2351. }
  2352. copyFrom(aabb) {
  2353. this._minX = aabb._minX;
  2354. this._minY = aabb._minY;
  2355. this._minZ = aabb._minZ;
  2356. this._maxX = aabb._maxX;
  2357. this._maxY = aabb._maxY;
  2358. this._maxZ = aabb._maxZ;
  2359. return this;
  2360. }
  2361. clone() {
  2362. let aabb = new oimo.collision.geometry.Aabb();
  2363. aabb._minX = this._minX;
  2364. aabb._minY = this._minY;
  2365. aabb._minZ = this._minZ;
  2366. aabb._maxX = this._maxX;
  2367. aabb._maxY = this._maxY;
  2368. aabb._maxZ = this._maxZ;
  2369. return aabb;
  2370. }
  2371. }
  2372. oimo.collision.geometry.BoxGeometry = class oimo_collision_geometry_BoxGeometry extends oimo.collision.geometry.ConvexGeometry {
  2373. constructor(halfExtents) {
  2374. super(1);
  2375. this._halfExtentsX = halfExtents.x;
  2376. this._halfExtentsY = halfExtents.y;
  2377. this._halfExtentsZ = halfExtents.z;
  2378. this._halfAxisXX = halfExtents.x;
  2379. this._halfAxisXY = 0;
  2380. this._halfAxisXZ = 0;
  2381. this._halfAxisYX = 0;
  2382. this._halfAxisYY = halfExtents.y;
  2383. this._halfAxisYZ = 0;
  2384. this._halfAxisZX = 0;
  2385. this._halfAxisZY = 0;
  2386. this._halfAxisZZ = halfExtents.z;
  2387. this._updateMass();
  2388. let minHalfExtents = halfExtents.x < halfExtents.y ? halfExtents.z < halfExtents.x ? halfExtents.z : halfExtents.x : halfExtents.z < halfExtents.y ? halfExtents.z : halfExtents.y;
  2389. if(this._gjkMargin > minHalfExtents * 0.2) {
  2390. this._gjkMargin = minHalfExtents * 0.2;
  2391. }
  2392. }
  2393. getHalfExtents() {
  2394. let v = new oimo.common.Vec3();
  2395. v.x = this._halfExtentsX;
  2396. v.y = this._halfExtentsY;
  2397. v.z = this._halfExtentsZ;
  2398. return v;
  2399. }
  2400. getHalfExtentsTo(halfExtents) {
  2401. halfExtents.x = this._halfExtentsX;
  2402. halfExtents.y = this._halfExtentsY;
  2403. halfExtents.z = this._halfExtentsZ;
  2404. }
  2405. _updateMass() {
  2406. this._volume = 8 * (this._halfExtentsX * this._halfExtentsY * this._halfExtentsZ);
  2407. let sqX;
  2408. let sqY;
  2409. let sqZ;
  2410. sqX = this._halfExtentsX * this._halfExtentsX;
  2411. sqY = this._halfExtentsY * this._halfExtentsY;
  2412. sqZ = this._halfExtentsZ * this._halfExtentsZ;
  2413. this._inertiaCoeff00 = 0.33333333333333331 * (sqY + sqZ);
  2414. this._inertiaCoeff01 = 0;
  2415. this._inertiaCoeff02 = 0;
  2416. this._inertiaCoeff10 = 0;
  2417. this._inertiaCoeff11 = 0.33333333333333331 * (sqZ + sqX);
  2418. this._inertiaCoeff12 = 0;
  2419. this._inertiaCoeff20 = 0;
  2420. this._inertiaCoeff21 = 0;
  2421. this._inertiaCoeff22 = 0.33333333333333331 * (sqX + sqY);
  2422. }
  2423. _computeAabb(aabb,tf) {
  2424. let tfxX;
  2425. let tfxY;
  2426. let tfxZ;
  2427. let tfyX;
  2428. let tfyY;
  2429. let tfyZ;
  2430. let tfzX;
  2431. let tfzY;
  2432. let tfzZ;
  2433. let __tmp__X;
  2434. let __tmp__Y;
  2435. let __tmp__Z;
  2436. __tmp__X = tf._rotation00 * this._halfAxisXX + tf._rotation01 * this._halfAxisXY + tf._rotation02 * this._halfAxisXZ;
  2437. __tmp__Y = tf._rotation10 * this._halfAxisXX + tf._rotation11 * this._halfAxisXY + tf._rotation12 * this._halfAxisXZ;
  2438. __tmp__Z = tf._rotation20 * this._halfAxisXX + tf._rotation21 * this._halfAxisXY + tf._rotation22 * this._halfAxisXZ;
  2439. tfxX = __tmp__X;
  2440. tfxY = __tmp__Y;
  2441. tfxZ = __tmp__Z;
  2442. let __tmp__X1;
  2443. let __tmp__Y1;
  2444. let __tmp__Z1;
  2445. __tmp__X1 = tf._rotation00 * this._halfAxisYX + tf._rotation01 * this._halfAxisYY + tf._rotation02 * this._halfAxisYZ;
  2446. __tmp__Y1 = tf._rotation10 * this._halfAxisYX + tf._rotation11 * this._halfAxisYY + tf._rotation12 * this._halfAxisYZ;
  2447. __tmp__Z1 = tf._rotation20 * this._halfAxisYX + tf._rotation21 * this._halfAxisYY + tf._rotation22 * this._halfAxisYZ;
  2448. tfyX = __tmp__X1;
  2449. tfyY = __tmp__Y1;
  2450. tfyZ = __tmp__Z1;
  2451. let __tmp__X2;
  2452. let __tmp__Y2;
  2453. let __tmp__Z2;
  2454. __tmp__X2 = tf._rotation00 * this._halfAxisZX + tf._rotation01 * this._halfAxisZY + tf._rotation02 * this._halfAxisZZ;
  2455. __tmp__Y2 = tf._rotation10 * this._halfAxisZX + tf._rotation11 * this._halfAxisZY + tf._rotation12 * this._halfAxisZZ;
  2456. __tmp__Z2 = tf._rotation20 * this._halfAxisZX + tf._rotation21 * this._halfAxisZY + tf._rotation22 * this._halfAxisZZ;
  2457. tfzX = __tmp__X2;
  2458. tfzY = __tmp__Y2;
  2459. tfzZ = __tmp__Z2;
  2460. if(tfxX < 0) {
  2461. tfxX = -tfxX;
  2462. }
  2463. if(tfxY < 0) {
  2464. tfxY = -tfxY;
  2465. }
  2466. if(tfxZ < 0) {
  2467. tfxZ = -tfxZ;
  2468. }
  2469. if(tfyX < 0) {
  2470. tfyX = -tfyX;
  2471. }
  2472. if(tfyY < 0) {
  2473. tfyY = -tfyY;
  2474. }
  2475. if(tfyZ < 0) {
  2476. tfyZ = -tfyZ;
  2477. }
  2478. if(tfzX < 0) {
  2479. tfzX = -tfzX;
  2480. }
  2481. if(tfzY < 0) {
  2482. tfzY = -tfzY;
  2483. }
  2484. if(tfzZ < 0) {
  2485. tfzZ = -tfzZ;
  2486. }
  2487. let tfsX;
  2488. let tfsY;
  2489. let tfsZ;
  2490. tfsX = tfxX + tfyX;
  2491. tfsY = tfxY + tfyY;
  2492. tfsZ = tfxZ + tfyZ;
  2493. tfsX += tfzX;
  2494. tfsY += tfzY;
  2495. tfsZ += tfzZ;
  2496. aabb._minX = tf._positionX - tfsX;
  2497. aabb._minY = tf._positionY - tfsY;
  2498. aabb._minZ = tf._positionZ - tfsZ;
  2499. aabb._maxX = tf._positionX + tfsX;
  2500. aabb._maxY = tf._positionY + tfsY;
  2501. aabb._maxZ = tf._positionZ + tfsZ;
  2502. }
  2503. computeLocalSupportingVertex(dir,out) {
  2504. let gjkMarginsX;
  2505. let gjkMarginsY;
  2506. let gjkMarginsZ;
  2507. let coreExtentsX;
  2508. let coreExtentsY;
  2509. let coreExtentsZ;
  2510. gjkMarginsX = this._gjkMargin;
  2511. gjkMarginsY = this._gjkMargin;
  2512. gjkMarginsZ = this._gjkMargin;
  2513. if(!(gjkMarginsX < this._halfExtentsX)) {
  2514. gjkMarginsX = this._halfExtentsX;
  2515. }
  2516. if(!(gjkMarginsY < this._halfExtentsY)) {
  2517. gjkMarginsY = this._halfExtentsY;
  2518. }
  2519. if(!(gjkMarginsZ < this._halfExtentsZ)) {
  2520. gjkMarginsZ = this._halfExtentsZ;
  2521. }
  2522. coreExtentsX = this._halfExtentsX - gjkMarginsX;
  2523. coreExtentsY = this._halfExtentsY - gjkMarginsY;
  2524. coreExtentsZ = this._halfExtentsZ - gjkMarginsZ;
  2525. out.x = dir.x > 0 ? coreExtentsX : -coreExtentsX;
  2526. out.y = dir.y > 0 ? coreExtentsY : -coreExtentsY;
  2527. out.z = dir.z > 0 ? coreExtentsZ : -coreExtentsZ;
  2528. }
  2529. _rayCastLocal(beginX,beginY,beginZ,endX,endY,endZ,hit) {
  2530. let halfW = this._halfExtentsX;
  2531. let halfH = this._halfExtentsY;
  2532. let halfD = this._halfExtentsZ;
  2533. let dx = endX - beginX;
  2534. let dy = endY - beginY;
  2535. let dz = endZ - beginZ;
  2536. let tminx = 0;
  2537. let tminy = 0;
  2538. let tminz = 0;
  2539. let tmaxx = 1;
  2540. let tmaxy = 1;
  2541. let tmaxz = 1;
  2542. if(dx > -1e-6 && dx < 1e-6) {
  2543. if(beginX <= -halfW || beginX >= halfW) {
  2544. return false;
  2545. }
  2546. } else {
  2547. let invDx = 1 / dx;
  2548. let t1 = (-halfW - beginX) * invDx;
  2549. let t2 = (halfW - beginX) * invDx;
  2550. if(t1 > t2) {
  2551. let tmp = t1;
  2552. t1 = t2;
  2553. t2 = tmp;
  2554. }
  2555. if(t1 > 0) {
  2556. tminx = t1;
  2557. }
  2558. if(t2 < 1) {
  2559. tmaxx = t2;
  2560. }
  2561. }
  2562. if(dy > -1e-6 && dy < 1e-6) {
  2563. if(beginY <= -halfH || beginY >= halfH) {
  2564. return false;
  2565. }
  2566. } else {
  2567. let invDy = 1 / dy;
  2568. let t1 = (-halfH - beginY) * invDy;
  2569. let t2 = (halfH - beginY) * invDy;
  2570. if(t1 > t2) {
  2571. let tmp = t1;
  2572. t1 = t2;
  2573. t2 = tmp;
  2574. }
  2575. if(t1 > 0) {
  2576. tminy = t1;
  2577. }
  2578. if(t2 < 1) {
  2579. tmaxy = t2;
  2580. }
  2581. }
  2582. if(dz > -1e-6 && dz < 1e-6) {
  2583. if(beginZ <= -halfD || beginZ >= halfD) {
  2584. return false;
  2585. }
  2586. } else {
  2587. let invDz = 1 / dz;
  2588. let t1 = (-halfD - beginZ) * invDz;
  2589. let t2 = (halfD - beginZ) * invDz;
  2590. if(t1 > t2) {
  2591. let tmp = t1;
  2592. t1 = t2;
  2593. t2 = tmp;
  2594. }
  2595. if(t1 > 0) {
  2596. tminz = t1;
  2597. }
  2598. if(t2 < 1) {
  2599. tmaxz = t2;
  2600. }
  2601. }
  2602. if(tminx >= 1 || tminy >= 1 || tminz >= 1 || tmaxx <= 0 || tmaxy <= 0 || tmaxz <= 0) {
  2603. return false;
  2604. }
  2605. let min = tminx;
  2606. let max = tmaxx;
  2607. let hitDirection = 0;
  2608. if(tminy > min) {
  2609. min = tminy;
  2610. hitDirection = 1;
  2611. }
  2612. if(tminz > min) {
  2613. min = tminz;
  2614. hitDirection = 2;
  2615. }
  2616. if(tmaxy < max) {
  2617. max = tmaxy;
  2618. }
  2619. if(tmaxz < max) {
  2620. max = tmaxz;
  2621. }
  2622. if(min > max) {
  2623. return false;
  2624. }
  2625. if(min == 0) {
  2626. return false;
  2627. }
  2628. switch(hitDirection) {
  2629. case 0:
  2630. hit.normal.init(dx > 0 ? -1 : 1,0,0);
  2631. break;
  2632. case 1:
  2633. hit.normal.init(0,dy > 0 ? -1 : 1,0);
  2634. break;
  2635. case 2:
  2636. hit.normal.init(0,0,dz > 0 ? -1 : 1);
  2637. break;
  2638. }
  2639. hit.position.init(beginX + min * dx,beginY + min * dy,beginZ + min * dz);
  2640. hit.fraction = min;
  2641. return true;
  2642. }
  2643. }
  2644. oimo.collision.geometry.CapsuleGeometry = class oimo_collision_geometry_CapsuleGeometry extends oimo.collision.geometry.ConvexGeometry {
  2645. constructor(radius,halfHeight) {
  2646. super(4);
  2647. this._radius = radius;
  2648. this._halfHeight = halfHeight;
  2649. this._gjkMargin = this._radius;
  2650. this._updateMass();
  2651. }
  2652. getRadius() {
  2653. return this._radius;
  2654. }
  2655. getHalfHeight() {
  2656. return this._halfHeight;
  2657. }
  2658. _updateMass() {
  2659. let r2 = this._radius * this._radius;
  2660. let hh2 = this._halfHeight * this._halfHeight;
  2661. let cylinderVolume = 6.28318530717958 * r2 * this._halfHeight;
  2662. let sphereVolume = 3.14159265358979 * r2 * this._radius * 4 / 3;
  2663. this._volume = cylinderVolume + sphereVolume;
  2664. let invVolume = this._volume == 0 ? 0 : 1 / this._volume;
  2665. let inertiaXZ = invVolume * (cylinderVolume * (r2 * 0.25 + hh2 / 3) + sphereVolume * (r2 * 0.4 + this._halfHeight * this._radius * 0.75 + hh2));
  2666. this._inertiaCoeff00 = inertiaXZ;
  2667. this._inertiaCoeff01 = 0;
  2668. this._inertiaCoeff02 = 0;
  2669. this._inertiaCoeff10 = 0;
  2670. this._inertiaCoeff11 = invVolume * (cylinderVolume * r2 * 0.5 + sphereVolume * r2 * 0.4);
  2671. this._inertiaCoeff12 = 0;
  2672. this._inertiaCoeff20 = 0;
  2673. this._inertiaCoeff21 = 0;
  2674. this._inertiaCoeff22 = inertiaXZ;
  2675. }
  2676. _computeAabb(aabb,tf) {
  2677. let radVecX;
  2678. let radVecY;
  2679. let radVecZ;
  2680. radVecX = this._radius;
  2681. radVecY = this._radius;
  2682. radVecZ = this._radius;
  2683. let axisX;
  2684. let axisY;
  2685. let axisZ;
  2686. axisX = tf._rotation01;
  2687. axisY = tf._rotation11;
  2688. axisZ = tf._rotation21;
  2689. if(axisX < 0) {
  2690. axisX = -axisX;
  2691. }
  2692. if(axisY < 0) {
  2693. axisY = -axisY;
  2694. }
  2695. if(axisZ < 0) {
  2696. axisZ = -axisZ;
  2697. }
  2698. axisX *= this._halfHeight;
  2699. axisY *= this._halfHeight;
  2700. axisZ *= this._halfHeight;
  2701. radVecX += axisX;
  2702. radVecY += axisY;
  2703. radVecZ += axisZ;
  2704. aabb._minX = tf._positionX - radVecX;
  2705. aabb._minY = tf._positionY - radVecY;
  2706. aabb._minZ = tf._positionZ - radVecZ;
  2707. aabb._maxX = tf._positionX + radVecX;
  2708. aabb._maxY = tf._positionY + radVecY;
  2709. aabb._maxZ = tf._positionZ + radVecZ;
  2710. }
  2711. computeLocalSupportingVertex(dir,out) {
  2712. if(dir.y > 0) {
  2713. out.init(0,this._halfHeight,0);
  2714. } else {
  2715. out.init(0,-this._halfHeight,0);
  2716. }
  2717. }
  2718. _rayCastLocal(beginX,beginY,beginZ,endX,endY,endZ,hit) {
  2719. let halfH = this._halfHeight;
  2720. let dx = endX - beginX;
  2721. let dz = endZ - beginZ;
  2722. let tminxz = 0;
  2723. let tmaxxz;
  2724. let a = dx * dx + dz * dz;
  2725. let b = beginX * dx + beginZ * dz;
  2726. let c = beginX * beginX + beginZ * beginZ - this._radius * this._radius;
  2727. let D = b * b - a * c;
  2728. if(D < 0) {
  2729. return false;
  2730. }
  2731. if(a > 0) {
  2732. let sqrtD = Math.sqrt(D);
  2733. tminxz = (-b - sqrtD) / a;
  2734. tmaxxz = (-b + sqrtD) / a;
  2735. if(tminxz >= 1 || tmaxxz <= 0) {
  2736. return false;
  2737. }
  2738. } else {
  2739. if(c >= 0) {
  2740. return false;
  2741. }
  2742. tminxz = 0;
  2743. }
  2744. let crossY = beginY + (endY - beginY) * tminxz;
  2745. let min;
  2746. if(crossY > -halfH && crossY < halfH) {
  2747. if(tminxz > 0) {
  2748. min = tminxz;
  2749. let _this = hit.normal.init(beginX + dx * min,0,beginZ + dz * min);
  2750. let invLen = Math.sqrt(_this.x * _this.x + _this.y * _this.y + _this.z * _this.z);
  2751. if(invLen > 0) {
  2752. invLen = 1 / invLen;
  2753. }
  2754. _this.x *= invLen;
  2755. _this.y *= invLen;
  2756. _this.z *= invLen;
  2757. hit.position.init(beginX + min * dx,crossY,beginZ + min * dz);
  2758. hit.fraction = min;
  2759. return true;
  2760. }
  2761. return false;
  2762. }
  2763. let spherePosX;
  2764. let spherePosY;
  2765. let spherePosZ;
  2766. let sphereToBeginX;
  2767. let sphereToBeginY;
  2768. let sphereToBeginZ;
  2769. spherePosX = 0;
  2770. spherePosY = crossY < 0 ? -halfH : halfH;
  2771. spherePosZ = 0;
  2772. sphereToBeginX = beginX - spherePosX;
  2773. sphereToBeginY = beginY - spherePosY;
  2774. sphereToBeginZ = beginZ - spherePosZ;
  2775. let dX;
  2776. let dY;
  2777. let dZ;
  2778. dX = endX - beginX;
  2779. dY = endY - beginY;
  2780. dZ = endZ - beginZ;
  2781. a = dX * dX + dY * dY + dZ * dZ;
  2782. b = sphereToBeginX * dX + sphereToBeginY * dY + sphereToBeginZ * dZ;
  2783. c = sphereToBeginX * sphereToBeginX + sphereToBeginY * sphereToBeginY + sphereToBeginZ * sphereToBeginZ - this._radius * this._radius;
  2784. D = b * b - a * c;
  2785. if(D < 0) {
  2786. return false;
  2787. }
  2788. let t = (-b - Math.sqrt(D)) / a;
  2789. if(t < 0 || t > 1) {
  2790. return false;
  2791. }
  2792. let hitPosX;
  2793. let hitPosY;
  2794. let hitPosZ;
  2795. let hitNormalX;
  2796. let hitNormalY;
  2797. let hitNormalZ;
  2798. hitPosX = sphereToBeginX + dX * t;
  2799. hitPosY = sphereToBeginY + dY * t;
  2800. hitPosZ = sphereToBeginZ + dZ * t;
  2801. let l = hitPosX * hitPosX + hitPosY * hitPosY + hitPosZ * hitPosZ;
  2802. if(l > 0) {
  2803. l = 1 / Math.sqrt(l);
  2804. }
  2805. hitNormalX = hitPosX * l;
  2806. hitNormalY = hitPosY * l;
  2807. hitNormalZ = hitPosZ * l;
  2808. hitPosX += spherePosX;
  2809. hitPosY += spherePosY;
  2810. hitPosZ += spherePosZ;
  2811. let v = hit.position;
  2812. v.x = hitPosX;
  2813. v.y = hitPosY;
  2814. v.z = hitPosZ;
  2815. let v1 = hit.normal;
  2816. v1.x = hitNormalX;
  2817. v1.y = hitNormalY;
  2818. v1.z = hitNormalZ;
  2819. hit.fraction = t;
  2820. return true;
  2821. }
  2822. }
  2823. oimo.collision.geometry.ConeGeometry = class oimo_collision_geometry_ConeGeometry extends oimo.collision.geometry.ConvexGeometry {
  2824. constructor(radius,halfHeight) {
  2825. super(3);
  2826. this._radius = radius;
  2827. this._halfHeight = halfHeight;
  2828. this.sinTheta = radius / Math.sqrt(radius * radius + 4 * halfHeight * halfHeight);
  2829. this.cosTheta = 2 * halfHeight / Math.sqrt(radius * radius + 4 * halfHeight * halfHeight);
  2830. this._updateMass();
  2831. }
  2832. getRadius() {
  2833. return this._radius;
  2834. }
  2835. getHalfHeight() {
  2836. return this._halfHeight;
  2837. }
  2838. _updateMass() {
  2839. let r2 = this._radius * this._radius;
  2840. let h2 = this._halfHeight * this._halfHeight * 4;
  2841. this._volume = 3.14159265358979 * r2 * this._halfHeight * 2 / 3;
  2842. this._inertiaCoeff00 = 0.05 * (3 * r2 + 2 * h2);
  2843. this._inertiaCoeff01 = 0;
  2844. this._inertiaCoeff02 = 0;
  2845. this._inertiaCoeff10 = 0;
  2846. this._inertiaCoeff11 = 0.3 * r2;
  2847. this._inertiaCoeff12 = 0;
  2848. this._inertiaCoeff20 = 0;
  2849. this._inertiaCoeff21 = 0;
  2850. this._inertiaCoeff22 = 0.05 * (3 * r2 + 2 * h2);
  2851. }
  2852. _computeAabb(aabb,tf) {
  2853. let axisX;
  2854. let axisY;
  2855. let axisZ;
  2856. let axis2X;
  2857. let axis2Y;
  2858. let axis2Z;
  2859. let ehX;
  2860. let ehY;
  2861. let ehZ;
  2862. let erX;
  2863. let erY;
  2864. let erZ;
  2865. axisX = tf._rotation01;
  2866. axisY = tf._rotation11;
  2867. axisZ = tf._rotation21;
  2868. axis2X = axisX * axisX;
  2869. axis2Y = axisY * axisY;
  2870. axis2Z = axisZ * axisZ;
  2871. erX = Math.sqrt(1 - axis2X);
  2872. erY = Math.sqrt(1 - axis2Y);
  2873. erZ = Math.sqrt(1 - axis2Z);
  2874. erX *= this._radius;
  2875. erY *= this._radius;
  2876. erZ *= this._radius;
  2877. ehX = axisX * this._halfHeight;
  2878. ehY = axisY * this._halfHeight;
  2879. ehZ = axisZ * this._halfHeight;
  2880. let rminX;
  2881. let rminY;
  2882. let rminZ;
  2883. let rmaxX;
  2884. let rmaxY;
  2885. let rmaxZ;
  2886. rminX = -ehX;
  2887. rminY = -ehY;
  2888. rminZ = -ehZ;
  2889. rminX -= erX;
  2890. rminY -= erY;
  2891. rminZ -= erZ;
  2892. rmaxX = -ehX;
  2893. rmaxY = -ehY;
  2894. rmaxZ = -ehZ;
  2895. rmaxX += erX;
  2896. rmaxY += erY;
  2897. rmaxZ += erZ;
  2898. let maxX;
  2899. let maxY;
  2900. let maxZ;
  2901. let minX;
  2902. let minY;
  2903. let minZ;
  2904. maxX = rminX > rmaxX ? rminX : rmaxX;
  2905. maxY = rminY > rmaxY ? rminY : rmaxY;
  2906. maxZ = rminZ > rmaxZ ? rminZ : rmaxZ;
  2907. if(!(maxX > ehX)) {
  2908. maxX = ehX;
  2909. }
  2910. if(!(maxY > ehY)) {
  2911. maxY = ehY;
  2912. }
  2913. if(!(maxZ > ehZ)) {
  2914. maxZ = ehZ;
  2915. }
  2916. minX = rminX < rmaxX ? rminX : rmaxX;
  2917. minY = rminY < rmaxY ? rminY : rmaxY;
  2918. minZ = rminZ < rmaxZ ? rminZ : rmaxZ;
  2919. if(!(minX < ehX)) {
  2920. minX = ehX;
  2921. }
  2922. if(!(minY < ehY)) {
  2923. minY = ehY;
  2924. }
  2925. if(!(minZ < ehZ)) {
  2926. minZ = ehZ;
  2927. }
  2928. aabb._minX = tf._positionX + minX;
  2929. aabb._minY = tf._positionY + minY;
  2930. aabb._minZ = tf._positionZ + minZ;
  2931. aabb._maxX = tf._positionX + maxX;
  2932. aabb._maxY = tf._positionY + maxY;
  2933. aabb._maxZ = tf._positionZ + maxZ;
  2934. }
  2935. computeLocalSupportingVertex(dir,out) {
  2936. let dx = dir.x;
  2937. let dy = dir.y;
  2938. let dz = dir.z;
  2939. if(dy > 0 && dy * dy > this.sinTheta * this.sinTheta * (dx * dx + dy * dy + dz * dz)) {
  2940. out.init(0,this._halfHeight - this._gjkMargin / this.sinTheta,0);
  2941. if(out.y < 0) {
  2942. out.y = 0;
  2943. }
  2944. return;
  2945. }
  2946. let rx = dir.x;
  2947. let rz = dir.z;
  2948. let len = rx * rx + rz * rz;
  2949. let height = 2 * this._halfHeight;
  2950. let coreRadius = (height - this._gjkMargin) / height * this._radius - this._gjkMargin / this.cosTheta;
  2951. if(coreRadius < 0) {
  2952. coreRadius = 0;
  2953. }
  2954. let invLen = len > 0 ? coreRadius / Math.sqrt(len) : 0;
  2955. let coreHalfHeight = this._halfHeight - this._gjkMargin;
  2956. if(coreHalfHeight < 0) {
  2957. coreHalfHeight = 0;
  2958. }
  2959. out.x = rx * invLen;
  2960. out.y = -coreHalfHeight;
  2961. out.z = rz * invLen;
  2962. }
  2963. _rayCastLocal(beginX,beginY,beginZ,endX,endY,endZ,hit) {
  2964. let p1y;
  2965. let halfH = this._halfHeight;
  2966. let dx = endX - beginX;
  2967. let dy = endY - beginY;
  2968. let dz = endZ - beginZ;
  2969. let tminy = 0;
  2970. let tmaxy = 1;
  2971. if(dy > -1e-6 && dy < 1e-6) {
  2972. if(beginY <= -halfH || beginY >= halfH) {
  2973. return false;
  2974. }
  2975. } else {
  2976. let invDy = 1 / dy;
  2977. let t1 = (-halfH - beginY) * invDy;
  2978. let t2 = (halfH - beginY) * invDy;
  2979. if(t1 > t2) {
  2980. let tmp = t1;
  2981. t1 = t2;
  2982. t2 = tmp;
  2983. }
  2984. if(t1 > 0) {
  2985. tminy = t1;
  2986. }
  2987. if(t2 < 1) {
  2988. tmaxy = t2;
  2989. }
  2990. }
  2991. if(tminy >= 1 || tmaxy <= 0) {
  2992. return false;
  2993. }
  2994. let tminxz = 0;
  2995. let tmaxxz = 0;
  2996. p1y = beginY - halfH;
  2997. let cos2 = this.cosTheta * this.cosTheta;
  2998. let a = cos2 * (dx * dx + dy * dy + dz * dz) - dy * dy;
  2999. let b = cos2 * (beginX * dx + p1y * dy + beginZ * dz) - p1y * dy;
  3000. let c = cos2 * (beginX * beginX + p1y * p1y + beginZ * beginZ) - p1y * p1y;
  3001. let D = b * b - a * c;
  3002. if(a != 0) {
  3003. if(D < 0) {
  3004. return false;
  3005. }
  3006. let sqrtD = Math.sqrt(D);
  3007. if(a < 0) {
  3008. if(dy > 0) {
  3009. tminxz = 0;
  3010. tmaxxz = (-b + sqrtD) / a;
  3011. if(tmaxxz <= 0) {
  3012. return false;
  3013. }
  3014. } else {
  3015. tminxz = (-b - sqrtD) / a;
  3016. tmaxxz = 1;
  3017. if(tminxz >= 1) {
  3018. return false;
  3019. }
  3020. }
  3021. } else {
  3022. tminxz = (-b - sqrtD) / a;
  3023. tmaxxz = (-b + sqrtD) / a;
  3024. if(tminxz >= 1 || tmaxxz <= 0) {
  3025. return false;
  3026. }
  3027. }
  3028. } else {
  3029. let t = -c / (2 * b);
  3030. if(b > 0) {
  3031. tminxz = 0;
  3032. tmaxxz = t;
  3033. if(t <= 0) {
  3034. return false;
  3035. }
  3036. } else {
  3037. tminxz = t;
  3038. tmaxxz = 1;
  3039. if(t >= 1) {
  3040. return false;
  3041. }
  3042. }
  3043. }
  3044. p1y += halfH;
  3045. let min;
  3046. if(tmaxxz <= tminy || tmaxy <= tminxz) {
  3047. return false;
  3048. }
  3049. if(tminxz < tminy) {
  3050. min = tminy;
  3051. if(min == 0) {
  3052. return false;
  3053. }
  3054. hit.normal.init(0,dy > 0 ? -1 : 1,0);
  3055. } else {
  3056. min = tminxz;
  3057. if(min == 0) {
  3058. return false;
  3059. }
  3060. let _this = hit.normal.init(beginX + dx * min,0,beginZ + dz * min);
  3061. let invLen = Math.sqrt(_this.x * _this.x + _this.y * _this.y + _this.z * _this.z);
  3062. if(invLen > 0) {
  3063. invLen = 1 / invLen;
  3064. }
  3065. _this.x *= invLen;
  3066. _this.y *= invLen;
  3067. _this.z *= invLen;
  3068. let s = this.cosTheta;
  3069. _this.x *= s;
  3070. _this.y *= s;
  3071. _this.z *= s;
  3072. hit.normal.y += this.sinTheta;
  3073. }
  3074. hit.position.init(beginX + min * dx,p1y + min * dy,beginZ + min * dz);
  3075. hit.fraction = min;
  3076. return true;
  3077. }
  3078. }
  3079. oimo.collision.geometry.ConvexHullGeometry = class oimo_collision_geometry_ConvexHullGeometry extends oimo.collision.geometry.ConvexGeometry {
  3080. constructor(vertices) {
  3081. super(5);
  3082. this._numVertices = vertices.length;
  3083. this._vertices = new Array(this._numVertices);
  3084. this._tmpVertices = new Array(this._numVertices);
  3085. let _g = 0;
  3086. let _g1 = this._numVertices;
  3087. while(_g < _g1) {
  3088. let i = _g++;
  3089. this._vertices[i] = vertices[i];
  3090. this._tmpVertices[i] = new oimo.common.Vec3();
  3091. }
  3092. this._useGjkRayCast = true;
  3093. this._updateMass();
  3094. }
  3095. getVertices() {
  3096. return this._vertices;
  3097. }
  3098. _updateMass() {
  3099. this._volume = 1;
  3100. this._inertiaCoeff00 = 1;
  3101. this._inertiaCoeff01 = 0;
  3102. this._inertiaCoeff02 = 0;
  3103. this._inertiaCoeff10 = 0;
  3104. this._inertiaCoeff11 = 1;
  3105. this._inertiaCoeff12 = 0;
  3106. this._inertiaCoeff20 = 0;
  3107. this._inertiaCoeff21 = 0;
  3108. this._inertiaCoeff22 = 1;
  3109. let minx = this._vertices[0].x;
  3110. let miny = this._vertices[0].y;
  3111. let minz = this._vertices[0].z;
  3112. let maxx = this._vertices[0].x;
  3113. let maxy = this._vertices[0].y;
  3114. let maxz = this._vertices[0].z;
  3115. let _g = 1;
  3116. let _g1 = this._numVertices;
  3117. while(_g < _g1) {
  3118. let i = _g++;
  3119. let vx = this._vertices[i].x;
  3120. let vy = this._vertices[i].y;
  3121. let vz = this._vertices[i].z;
  3122. if(vx < minx) {
  3123. minx = vx;
  3124. } else if(vx > maxx) {
  3125. maxx = vx;
  3126. }
  3127. if(vy < miny) {
  3128. miny = vy;
  3129. } else if(vy > maxy) {
  3130. maxy = vy;
  3131. }
  3132. if(vz < minz) {
  3133. minz = vz;
  3134. } else if(vz > maxz) {
  3135. maxz = vz;
  3136. }
  3137. }
  3138. let sizex = maxx - minx;
  3139. let sizey = maxy - miny;
  3140. let sizez = maxz - minz;
  3141. this._volume = sizex * sizey * sizez;
  3142. let diffCog = ((minx + maxx) * (minx + maxx) + (miny + maxy) * (miny + maxy) + (minz + maxz) * (minz + maxz)) * 0.25;
  3143. sizex = sizex * sizex * 0.25;
  3144. sizey = sizey * sizey * 0.25;
  3145. sizez = sizez * sizez * 0.25;
  3146. this._inertiaCoeff00 = 0.33333333333333331 * (sizey + sizez) + diffCog;
  3147. this._inertiaCoeff01 = 0;
  3148. this._inertiaCoeff02 = 0;
  3149. this._inertiaCoeff10 = 0;
  3150. this._inertiaCoeff11 = 0.33333333333333331 * (sizez + sizex) + diffCog;
  3151. this._inertiaCoeff12 = 0;
  3152. this._inertiaCoeff20 = 0;
  3153. this._inertiaCoeff21 = 0;
  3154. this._inertiaCoeff22 = 0.33333333333333331 * (sizex + sizey) + diffCog;
  3155. }
  3156. _computeAabb(aabb,tf) {
  3157. let minX;
  3158. let minY;
  3159. let minZ;
  3160. let maxX;
  3161. let maxY;
  3162. let maxZ;
  3163. let marginX;
  3164. let marginY;
  3165. let marginZ;
  3166. marginX = this._gjkMargin;
  3167. marginY = this._gjkMargin;
  3168. marginZ = this._gjkMargin;
  3169. let localVX;
  3170. let localVY;
  3171. let localVZ;
  3172. let v = this._vertices[0];
  3173. localVX = v.x;
  3174. localVY = v.y;
  3175. localVZ = v.z;
  3176. let worldVX;
  3177. let worldVY;
  3178. let worldVZ;
  3179. let __tmp__X;
  3180. let __tmp__Y;
  3181. let __tmp__Z;
  3182. __tmp__X = tf._rotation00 * localVX + tf._rotation01 * localVY + tf._rotation02 * localVZ;
  3183. __tmp__Y = tf._rotation10 * localVX + tf._rotation11 * localVY + tf._rotation12 * localVZ;
  3184. __tmp__Z = tf._rotation20 * localVX + tf._rotation21 * localVY + tf._rotation22 * localVZ;
  3185. worldVX = __tmp__X;
  3186. worldVY = __tmp__Y;
  3187. worldVZ = __tmp__Z;
  3188. worldVX += tf._positionX;
  3189. worldVY += tf._positionY;
  3190. worldVZ += tf._positionZ;
  3191. minX = worldVX;
  3192. minY = worldVY;
  3193. minZ = worldVZ;
  3194. maxX = worldVX;
  3195. maxY = worldVY;
  3196. maxZ = worldVZ;
  3197. let _g = 1;
  3198. let _g1 = this._numVertices;
  3199. while(_g < _g1) {
  3200. let v = this._vertices[_g++];
  3201. localVX = v.x;
  3202. localVY = v.y;
  3203. localVZ = v.z;
  3204. let __tmp__X;
  3205. let __tmp__Y;
  3206. let __tmp__Z;
  3207. __tmp__X = tf._rotation00 * localVX + tf._rotation01 * localVY + tf._rotation02 * localVZ;
  3208. __tmp__Y = tf._rotation10 * localVX + tf._rotation11 * localVY + tf._rotation12 * localVZ;
  3209. __tmp__Z = tf._rotation20 * localVX + tf._rotation21 * localVY + tf._rotation22 * localVZ;
  3210. worldVX = __tmp__X;
  3211. worldVY = __tmp__Y;
  3212. worldVZ = __tmp__Z;
  3213. worldVX += tf._positionX;
  3214. worldVY += tf._positionY;
  3215. worldVZ += tf._positionZ;
  3216. if(!(minX < worldVX)) {
  3217. minX = worldVX;
  3218. }
  3219. if(!(minY < worldVY)) {
  3220. minY = worldVY;
  3221. }
  3222. if(!(minZ < worldVZ)) {
  3223. minZ = worldVZ;
  3224. }
  3225. if(!(maxX > worldVX)) {
  3226. maxX = worldVX;
  3227. }
  3228. if(!(maxY > worldVY)) {
  3229. maxY = worldVY;
  3230. }
  3231. if(!(maxZ > worldVZ)) {
  3232. maxZ = worldVZ;
  3233. }
  3234. }
  3235. aabb._minX = minX - marginX;
  3236. aabb._minY = minY - marginY;
  3237. aabb._minZ = minZ - marginZ;
  3238. aabb._maxX = maxX + marginX;
  3239. aabb._maxY = maxY + marginY;
  3240. aabb._maxZ = maxZ + marginZ;
  3241. }
  3242. computeLocalSupportingVertex(dir,out) {
  3243. let _this = this._vertices[0];
  3244. let maxDot = _this.x * dir.x + _this.y * dir.y + _this.z * dir.z;
  3245. let maxIndex = 0;
  3246. let _g = 1;
  3247. let _g1 = this._numVertices;
  3248. while(_g < _g1) {
  3249. let i = _g++;
  3250. let _this = this._vertices[i];
  3251. let dot = _this.x * dir.x + _this.y * dir.y + _this.z * dir.z;
  3252. if(dot > maxDot) {
  3253. maxDot = dot;
  3254. maxIndex = i;
  3255. }
  3256. }
  3257. let v = this._vertices[maxIndex];
  3258. out.x = v.x;
  3259. out.y = v.y;
  3260. out.z = v.z;
  3261. }
  3262. }
  3263. oimo.collision.geometry.CylinderGeometry = class oimo_collision_geometry_CylinderGeometry extends oimo.collision.geometry.ConvexGeometry {
  3264. constructor(radius,halfHeight) {
  3265. super(2);
  3266. this._radius = radius;
  3267. this._halfHeight = halfHeight;
  3268. this._updateMass();
  3269. }
  3270. getRadius() {
  3271. return this._radius;
  3272. }
  3273. getHalfHeight() {
  3274. return this._halfHeight;
  3275. }
  3276. _updateMass() {
  3277. let r2 = this._radius * this._radius;
  3278. let h2 = this._halfHeight * this._halfHeight * 4;
  3279. this._volume = 3.14159265358979 * r2 * this._halfHeight * 2;
  3280. this._inertiaCoeff00 = 0.083333333333333329 * (3 * r2 + h2);
  3281. this._inertiaCoeff01 = 0;
  3282. this._inertiaCoeff02 = 0;
  3283. this._inertiaCoeff10 = 0;
  3284. this._inertiaCoeff11 = 0.5 * r2;
  3285. this._inertiaCoeff12 = 0;
  3286. this._inertiaCoeff20 = 0;
  3287. this._inertiaCoeff21 = 0;
  3288. this._inertiaCoeff22 = 0.083333333333333329 * (3 * r2 + h2);
  3289. }
  3290. _computeAabb(aabb,tf) {
  3291. let axisX;
  3292. let axisY;
  3293. let axisZ;
  3294. let axis2X;
  3295. let axis2Y;
  3296. let axis2Z;
  3297. let ehX;
  3298. let ehY;
  3299. let ehZ;
  3300. let erX;
  3301. let erY;
  3302. let erZ;
  3303. axisX = tf._rotation01;
  3304. axisY = tf._rotation11;
  3305. axisZ = tf._rotation21;
  3306. if(axisX < 0) {
  3307. axisX = -axisX;
  3308. }
  3309. if(axisY < 0) {
  3310. axisY = -axisY;
  3311. }
  3312. if(axisZ < 0) {
  3313. axisZ = -axisZ;
  3314. }
  3315. axis2X = axisX * axisX;
  3316. axis2Y = axisY * axisY;
  3317. axis2Z = axisZ * axisZ;
  3318. erX = Math.sqrt(1 - axis2X);
  3319. erY = Math.sqrt(1 - axis2Y);
  3320. erZ = Math.sqrt(1 - axis2Z);
  3321. erX *= this._radius;
  3322. erY *= this._radius;
  3323. erZ *= this._radius;
  3324. ehX = axisX * this._halfHeight;
  3325. ehY = axisY * this._halfHeight;
  3326. ehZ = axisZ * this._halfHeight;
  3327. let maxX;
  3328. let maxY;
  3329. let maxZ;
  3330. maxX = erX + ehX;
  3331. maxY = erY + ehY;
  3332. maxZ = erZ + ehZ;
  3333. aabb._minX = tf._positionX - maxX;
  3334. aabb._minY = tf._positionY - maxY;
  3335. aabb._minZ = tf._positionZ - maxZ;
  3336. aabb._maxX = tf._positionX + maxX;
  3337. aabb._maxY = tf._positionY + maxY;
  3338. aabb._maxZ = tf._positionZ + maxZ;
  3339. }
  3340. computeLocalSupportingVertex(dir,out) {
  3341. let rx = dir.x;
  3342. let rz = dir.z;
  3343. let len = rx * rx + rz * rz;
  3344. let coreRadius = this._radius - this._gjkMargin;
  3345. if(coreRadius < 0) {
  3346. coreRadius = 0;
  3347. }
  3348. let invLen = len > 0 ? coreRadius / Math.sqrt(len) : 0;
  3349. let coreHeight = this._halfHeight - this._gjkMargin;
  3350. if(coreHeight < 0) {
  3351. coreHeight = 0;
  3352. }
  3353. out.x = rx * invLen;
  3354. out.y = dir.y > 0 ? coreHeight : -coreHeight;
  3355. out.z = rz * invLen;
  3356. }
  3357. _rayCastLocal(beginX,beginY,beginZ,endX,endY,endZ,hit) {
  3358. let halfH = this._halfHeight;
  3359. let dx = endX - beginX;
  3360. let dy = endY - beginY;
  3361. let dz = endZ - beginZ;
  3362. let tminy = 0;
  3363. let tmaxy = 1;
  3364. if(dy > -1e-6 && dy < 1e-6) {
  3365. if(beginY <= -halfH || beginY >= halfH) {
  3366. return false;
  3367. }
  3368. } else {
  3369. let invDy = 1 / dy;
  3370. let t1 = (-halfH - beginY) * invDy;
  3371. let t2 = (halfH - beginY) * invDy;
  3372. if(t1 > t2) {
  3373. let tmp = t1;
  3374. t1 = t2;
  3375. t2 = tmp;
  3376. }
  3377. if(t1 > 0) {
  3378. tminy = t1;
  3379. }
  3380. if(t2 < 1) {
  3381. tmaxy = t2;
  3382. }
  3383. }
  3384. if(tminy >= 1 || tmaxy <= 0) {
  3385. return false;
  3386. }
  3387. let tminxz = 0;
  3388. let tmaxxz;
  3389. let a = dx * dx + dz * dz;
  3390. let b = beginX * dx + beginZ * dz;
  3391. let c = beginX * beginX + beginZ * beginZ - this._radius * this._radius;
  3392. let D = b * b - a * c;
  3393. if(D < 0) {
  3394. return false;
  3395. }
  3396. if(a > 0) {
  3397. let sqrtD = Math.sqrt(D);
  3398. tminxz = (-b - sqrtD) / a;
  3399. tmaxxz = (-b + sqrtD) / a;
  3400. if(tminxz >= 1 || tmaxxz <= 0) {
  3401. return false;
  3402. }
  3403. } else {
  3404. if(c >= 0) {
  3405. return false;
  3406. }
  3407. tminxz = 0;
  3408. tmaxxz = 1;
  3409. }
  3410. let min;
  3411. if(tmaxxz <= tminy || tmaxy <= tminxz) {
  3412. return false;
  3413. }
  3414. if(tminxz < tminy) {
  3415. min = tminy;
  3416. if(min == 0) {
  3417. return false;
  3418. }
  3419. hit.normal.init(0,dy > 0 ? -1 : 1,0);
  3420. } else {
  3421. min = tminxz;
  3422. if(min == 0) {
  3423. return false;
  3424. }
  3425. let _this = hit.normal.init(beginX + dx * min,0,beginZ + dz * min);
  3426. let invLen = Math.sqrt(_this.x * _this.x + _this.y * _this.y + _this.z * _this.z);
  3427. if(invLen > 0) {
  3428. invLen = 1 / invLen;
  3429. }
  3430. _this.x *= invLen;
  3431. _this.y *= invLen;
  3432. _this.z *= invLen;
  3433. }
  3434. hit.position.init(beginX + min * dx,beginY + min * dy,beginZ + min * dz);
  3435. hit.fraction = min;
  3436. return true;
  3437. }
  3438. }
  3439. oimo.collision.geometry.GeometryType = class oimo_collision_geometry_GeometryType {
  3440. }
  3441. oimo.collision.geometry.RayCastHit = class oimo_collision_geometry_RayCastHit {
  3442. constructor() {
  3443. this.position = new oimo.common.Vec3();
  3444. this.normal = new oimo.common.Vec3();
  3445. this.fraction = 0;
  3446. }
  3447. }
  3448. oimo.collision.geometry.SphereGeometry = class oimo_collision_geometry_SphereGeometry extends oimo.collision.geometry.ConvexGeometry {
  3449. constructor(radius) {
  3450. super(0);
  3451. this._radius = radius;
  3452. this._gjkMargin = this._radius;
  3453. this._updateMass();
  3454. }
  3455. getRadius() {
  3456. return this._radius;
  3457. }
  3458. _updateMass() {
  3459. this._volume = 4.1887902047863861 * this._radius * this._radius * this._radius;
  3460. this._inertiaCoeff00 = 0.4 * this._radius * this._radius;
  3461. this._inertiaCoeff01 = 0;
  3462. this._inertiaCoeff02 = 0;
  3463. this._inertiaCoeff10 = 0;
  3464. this._inertiaCoeff11 = 0.4 * this._radius * this._radius;
  3465. this._inertiaCoeff12 = 0;
  3466. this._inertiaCoeff20 = 0;
  3467. this._inertiaCoeff21 = 0;
  3468. this._inertiaCoeff22 = 0.4 * this._radius * this._radius;
  3469. }
  3470. _computeAabb(aabb,tf) {
  3471. let radVecX;
  3472. let radVecY;
  3473. let radVecZ;
  3474. radVecX = this._radius;
  3475. radVecY = this._radius;
  3476. radVecZ = this._radius;
  3477. aabb._minX = tf._positionX - radVecX;
  3478. aabb._minY = tf._positionY - radVecY;
  3479. aabb._minZ = tf._positionZ - radVecZ;
  3480. aabb._maxX = tf._positionX + radVecX;
  3481. aabb._maxY = tf._positionY + radVecY;
  3482. aabb._maxZ = tf._positionZ + radVecZ;
  3483. }
  3484. computeLocalSupportingVertex(dir,out) {
  3485. out.zero();
  3486. }
  3487. _rayCastLocal(beginX,beginY,beginZ,endX,endY,endZ,hit) {
  3488. let dX;
  3489. let dY;
  3490. let dZ;
  3491. dX = endX - beginX;
  3492. dY = endY - beginY;
  3493. dZ = endZ - beginZ;
  3494. let a = dX * dX + dY * dY + dZ * dZ;
  3495. let b = beginX * dX + beginY * dY + beginZ * dZ;
  3496. let D = b * b - a * (beginX * beginX + beginY * beginY + beginZ * beginZ - this._radius * this._radius);
  3497. if(D < 0) {
  3498. return false;
  3499. }
  3500. let t = (-b - Math.sqrt(D)) / a;
  3501. if(t < 0 || t > 1) {
  3502. return false;
  3503. }
  3504. let hitPosX;
  3505. let hitPosY;
  3506. let hitPosZ;
  3507. let hitNormalX;
  3508. let hitNormalY;
  3509. let hitNormalZ;
  3510. hitPosX = beginX + dX * t;
  3511. hitPosY = beginY + dY * t;
  3512. hitPosZ = beginZ + dZ * t;
  3513. let l = hitPosX * hitPosX + hitPosY * hitPosY + hitPosZ * hitPosZ;
  3514. if(l > 0) {
  3515. l = 1 / Math.sqrt(l);
  3516. }
  3517. hitNormalX = hitPosX * l;
  3518. hitNormalY = hitPosY * l;
  3519. hitNormalZ = hitPosZ * l;
  3520. let v = hit.position;
  3521. v.x = hitPosX;
  3522. v.y = hitPosY;
  3523. v.z = hitPosZ;
  3524. let v1 = hit.normal;
  3525. v1.x = hitNormalX;
  3526. v1.y = hitNormalY;
  3527. v1.z = hitNormalZ;
  3528. hit.fraction = t;
  3529. return true;
  3530. }
  3531. }
  3532. if(!oimo.collision.narrowphase) oimo.collision.narrowphase = {};
  3533. oimo.collision.narrowphase.CollisionMatrix = class oimo_collision_narrowphase_CollisionMatrix {
  3534. constructor() {
  3535. this.detectors = new Array(8);
  3536. this.detectors[0] = new Array(8);
  3537. this.detectors[1] = new Array(8);
  3538. this.detectors[2] = new Array(8);
  3539. this.detectors[3] = new Array(8);
  3540. this.detectors[4] = new Array(8);
  3541. this.detectors[5] = new Array(8);
  3542. let gjkEpaDetector = new oimo.collision.narrowphase.detector.GjkEpaDetector();
  3543. this.detectors[0][0] = new oimo.collision.narrowphase.detector.SphereSphereDetector();
  3544. this.detectors[0][1] = new oimo.collision.narrowphase.detector.SphereBoxDetector(false);
  3545. this.detectors[0][2] = gjkEpaDetector;
  3546. this.detectors[0][3] = gjkEpaDetector;
  3547. this.detectors[0][4] = new oimo.collision.narrowphase.detector.SphereCapsuleDetector(false);
  3548. this.detectors[0][5] = gjkEpaDetector;
  3549. this.detectors[1][0] = new oimo.collision.narrowphase.detector.SphereBoxDetector(true);
  3550. this.detectors[1][1] = new oimo.collision.narrowphase.detector.BoxBoxDetector();
  3551. this.detectors[1][2] = gjkEpaDetector;
  3552. this.detectors[1][3] = gjkEpaDetector;
  3553. this.detectors[1][4] = gjkEpaDetector;
  3554. this.detectors[1][5] = gjkEpaDetector;
  3555. this.detectors[2][0] = gjkEpaDetector;
  3556. this.detectors[2][1] = gjkEpaDetector;
  3557. this.detectors[2][2] = gjkEpaDetector;
  3558. this.detectors[2][3] = gjkEpaDetector;
  3559. this.detectors[2][4] = gjkEpaDetector;
  3560. this.detectors[2][5] = gjkEpaDetector;
  3561. this.detectors[3][0] = gjkEpaDetector;
  3562. this.detectors[3][1] = gjkEpaDetector;
  3563. this.detectors[3][2] = gjkEpaDetector;
  3564. this.detectors[3][3] = gjkEpaDetector;
  3565. this.detectors[3][4] = gjkEpaDetector;
  3566. this.detectors[3][5] = gjkEpaDetector;
  3567. this.detectors[4][0] = new oimo.collision.narrowphase.detector.SphereCapsuleDetector(true);
  3568. this.detectors[4][1] = gjkEpaDetector;
  3569. this.detectors[4][2] = gjkEpaDetector;
  3570. this.detectors[4][3] = gjkEpaDetector;
  3571. this.detectors[4][4] = new oimo.collision.narrowphase.detector.CapsuleCapsuleDetector();
  3572. this.detectors[4][5] = gjkEpaDetector;
  3573. this.detectors[5][0] = gjkEpaDetector;
  3574. this.detectors[5][1] = gjkEpaDetector;
  3575. this.detectors[5][2] = gjkEpaDetector;
  3576. this.detectors[5][3] = gjkEpaDetector;
  3577. this.detectors[5][4] = gjkEpaDetector;
  3578. this.detectors[5][5] = gjkEpaDetector;
  3579. }
  3580. getDetector(geomType1,geomType2) {
  3581. return this.detectors[geomType1][geomType2];
  3582. }
  3583. }
  3584. oimo.collision.narrowphase.DetectorResult = class oimo_collision_narrowphase_DetectorResult {
  3585. constructor() {
  3586. this.numPoints = 0;
  3587. this.normal = new oimo.common.Vec3();
  3588. this.points = new Array(oimo.common.Setting.maxManifoldPoints);
  3589. this.incremental = false;
  3590. let _g = 0;
  3591. let _g1 = oimo.common.Setting.maxManifoldPoints;
  3592. while(_g < _g1) this.points[_g++] = new oimo.collision.narrowphase.DetectorResultPoint();
  3593. }
  3594. getMaxDepth() {
  3595. let max = 0;
  3596. let _g = 0;
  3597. let _g1 = this.numPoints;
  3598. while(_g < _g1) {
  3599. let i = _g++;
  3600. if(this.points[i].depth > max) {
  3601. max = this.points[i].depth;
  3602. }
  3603. }
  3604. return max;
  3605. }
  3606. clear() {
  3607. this.numPoints = 0;
  3608. let _g = 0;
  3609. let _g1 = this.points;
  3610. while(_g < _g1.length) {
  3611. let p = _g1[_g];
  3612. ++_g;
  3613. p.position1.zero();
  3614. p.position2.zero();
  3615. p.depth = 0;
  3616. p.id = 0;
  3617. }
  3618. this.normal.zero();
  3619. }
  3620. }
  3621. oimo.collision.narrowphase.DetectorResultPoint = class oimo_collision_narrowphase_DetectorResultPoint {
  3622. constructor() {
  3623. this.position1 = new oimo.common.Vec3();
  3624. this.position2 = new oimo.common.Vec3();
  3625. this.depth = 0;
  3626. this.id = 0;
  3627. }
  3628. }
  3629. if(!oimo.collision.narrowphase.detector) oimo.collision.narrowphase.detector = {};
  3630. oimo.collision.narrowphase.detector.Detector = class oimo_collision_narrowphase_detector_Detector {
  3631. constructor(swapped) {
  3632. this.swapped = swapped;
  3633. }
  3634. setNormal(result,nX,nY,nZ) {
  3635. let v = result.normal;
  3636. v.x = nX;
  3637. v.y = nY;
  3638. v.z = nZ;
  3639. if(this.swapped) {
  3640. let _this = result.normal;
  3641. _this.x = -_this.x;
  3642. _this.y = -_this.y;
  3643. _this.z = -_this.z;
  3644. }
  3645. }
  3646. addPoint(result,pos1X,pos1Y,pos1Z,pos2X,pos2Y,pos2Z,depth,id) {
  3647. let p = result.points[result.numPoints++];
  3648. p.depth = depth;
  3649. p.id = id;
  3650. if(this.swapped) {
  3651. let v = p.position1;
  3652. v.x = pos2X;
  3653. v.y = pos2Y;
  3654. v.z = pos2Z;
  3655. let v1 = p.position2;
  3656. v1.x = pos1X;
  3657. v1.y = pos1Y;
  3658. v1.z = pos1Z;
  3659. } else {
  3660. let v = p.position1;
  3661. v.x = pos1X;
  3662. v.y = pos1Y;
  3663. v.z = pos1Z;
  3664. let v1 = p.position2;
  3665. v1.x = pos2X;
  3666. v1.y = pos2Y;
  3667. v1.z = pos2Z;
  3668. }
  3669. }
  3670. detectImpl(result,geom1,geom2,tf1,tf2,cachedData) {
  3671. }
  3672. detect(result,geom1,geom2,transform1,transform2,cachedData) {
  3673. result.numPoints = 0;
  3674. let _g = 0;
  3675. let _g1 = result.points;
  3676. while(_g < _g1.length) {
  3677. let p = _g1[_g];
  3678. ++_g;
  3679. p.position1.zero();
  3680. p.position2.zero();
  3681. p.depth = 0;
  3682. p.id = 0;
  3683. }
  3684. result.normal.zero();
  3685. if(this.swapped) {
  3686. this.detectImpl(result,geom2,geom1,transform2,transform1,cachedData);
  3687. } else {
  3688. this.detectImpl(result,geom1,geom2,transform1,transform2,cachedData);
  3689. }
  3690. }
  3691. }
  3692. oimo.collision.narrowphase.detector.BoxBoxDetector = class oimo_collision_narrowphase_detector_BoxBoxDetector extends oimo.collision.narrowphase.detector.Detector {
  3693. constructor() {
  3694. super(false);
  3695. this.clipper = new oimo.collision.narrowphase.detector._BoxBoxDetector.FaceClipper();
  3696. }
  3697. detectImpl(result,geom1,geom2,tf1,tf2,cachedData) {
  3698. let b1 = geom1;
  3699. let b2 = geom2;
  3700. result.incremental = false;
  3701. let c1X;
  3702. let c1Y;
  3703. let c1Z;
  3704. let c2X;
  3705. let c2Y;
  3706. let c2Z;
  3707. let c12X;
  3708. let c12Y;
  3709. let c12Z;
  3710. c1X = tf1._positionX;
  3711. c1Y = tf1._positionY;
  3712. c1Z = tf1._positionZ;
  3713. c2X = tf2._positionX;
  3714. c2Y = tf2._positionY;
  3715. c2Z = tf2._positionZ;
  3716. c12X = c2X - c1X;
  3717. c12Y = c2Y - c1Y;
  3718. c12Z = c2Z - c1Z;
  3719. let x1X;
  3720. let x1Y;
  3721. let x1Z;
  3722. let y1X;
  3723. let y1Y;
  3724. let y1Z;
  3725. let z1X;
  3726. let z1Y;
  3727. let z1Z;
  3728. let x2X;
  3729. let x2Y;
  3730. let x2Z;
  3731. let y2X;
  3732. let y2Y;
  3733. let y2Z;
  3734. let z2X;
  3735. let z2Y;
  3736. let z2Z;
  3737. x1X = tf1._rotation00;
  3738. x1Y = tf1._rotation10;
  3739. x1Z = tf1._rotation20;
  3740. y1X = tf1._rotation01;
  3741. y1Y = tf1._rotation11;
  3742. y1Z = tf1._rotation21;
  3743. z1X = tf1._rotation02;
  3744. z1Y = tf1._rotation12;
  3745. z1Z = tf1._rotation22;
  3746. x2X = tf2._rotation00;
  3747. x2Y = tf2._rotation10;
  3748. x2Z = tf2._rotation20;
  3749. y2X = tf2._rotation01;
  3750. y2Y = tf2._rotation11;
  3751. y2Z = tf2._rotation21;
  3752. z2X = tf2._rotation02;
  3753. z2Y = tf2._rotation12;
  3754. z2Z = tf2._rotation22;
  3755. let w1 = b1._halfExtentsX;
  3756. let h1 = b1._halfExtentsY;
  3757. let d1 = b1._halfExtentsZ;
  3758. let w2 = b2._halfExtentsX;
  3759. let h2 = b2._halfExtentsY;
  3760. let d2 = b2._halfExtentsZ;
  3761. let sx1X;
  3762. let sx1Y;
  3763. let sx1Z;
  3764. let sy1X;
  3765. let sy1Y;
  3766. let sy1Z;
  3767. let sz1X;
  3768. let sz1Y;
  3769. let sz1Z;
  3770. let sx2X;
  3771. let sx2Y;
  3772. let sx2Z;
  3773. let sy2X;
  3774. let sy2Y;
  3775. let sy2Z;
  3776. let sz2X;
  3777. let sz2Y;
  3778. let sz2Z;
  3779. sx1X = x1X * w1;
  3780. sx1Y = x1Y * w1;
  3781. sx1Z = x1Z * w1;
  3782. sy1X = y1X * h1;
  3783. sy1Y = y1Y * h1;
  3784. sy1Z = y1Z * h1;
  3785. sz1X = z1X * d1;
  3786. sz1Y = z1Y * d1;
  3787. sz1Z = z1Z * d1;
  3788. sx2X = x2X * w2;
  3789. sx2Y = x2Y * w2;
  3790. sx2Z = x2Z * w2;
  3791. sy2X = y2X * h2;
  3792. sy2Y = y2Y * h2;
  3793. sy2Z = y2Z * h2;
  3794. sz2X = z2X * d2;
  3795. sz2Y = z2Y * d2;
  3796. sz2Z = z2Z * d2;
  3797. let mDepth = 1e65536;
  3798. let mId = -1;
  3799. let mSign = 0;
  3800. let mAxisX;
  3801. let mAxisY;
  3802. let mAxisZ;
  3803. mAxisX = 0;
  3804. mAxisY = 0;
  3805. mAxisZ = 0;
  3806. let proj1 = w1;
  3807. let dx = x1X * sx2X + x1Y * sx2Y + x1Z * sx2Z;
  3808. let dy = x1X * sy2X + x1Y * sy2Y + x1Z * sy2Z;
  3809. let dz = x1X * sz2X + x1Y * sz2Y + x1Z * sz2Z;
  3810. if(dx < 0) {
  3811. dx = -dx;
  3812. }
  3813. if(dy < 0) {
  3814. dy = -dy;
  3815. }
  3816. if(dz < 0) {
  3817. dz = -dz;
  3818. }
  3819. let proj2 = dx + dy + dz;
  3820. let projC12 = x1X * c12X + x1Y * c12Y + x1Z * c12Z;
  3821. let sum = proj1 + proj2;
  3822. let neg = projC12 < 0;
  3823. let abs = neg ? -projC12 : projC12;
  3824. if(abs < sum) {
  3825. let depth = sum - abs;
  3826. if(depth < 1e65536) {
  3827. mDepth = depth;
  3828. mId = 0;
  3829. mAxisX = x1X;
  3830. mAxisY = x1Y;
  3831. mAxisZ = x1Z;
  3832. mSign = neg ? -1 : 1;
  3833. }
  3834. } else {
  3835. return;
  3836. }
  3837. proj1 = h1;
  3838. let dx1 = y1X * sx2X + y1Y * sx2Y + y1Z * sx2Z;
  3839. let dy1 = y1X * sy2X + y1Y * sy2Y + y1Z * sy2Z;
  3840. let dz1 = y1X * sz2X + y1Y * sz2Y + y1Z * sz2Z;
  3841. if(dx1 < 0) {
  3842. dx1 = -dx1;
  3843. }
  3844. if(dy1 < 0) {
  3845. dy1 = -dy1;
  3846. }
  3847. if(dz1 < 0) {
  3848. dz1 = -dz1;
  3849. }
  3850. proj2 = dx1 + dy1 + dz1;
  3851. projC12 = y1X * c12X + y1Y * c12Y + y1Z * c12Z;
  3852. let sum1 = proj1 + proj2;
  3853. let neg1 = projC12 < 0;
  3854. let abs1 = neg1 ? -projC12 : projC12;
  3855. if(abs1 < sum1) {
  3856. let depth = sum1 - abs1;
  3857. if(depth < mDepth) {
  3858. mDepth = depth;
  3859. mId = 1;
  3860. mAxisX = y1X;
  3861. mAxisY = y1Y;
  3862. mAxisZ = y1Z;
  3863. mSign = neg1 ? -1 : 1;
  3864. }
  3865. } else {
  3866. return;
  3867. }
  3868. proj1 = d1;
  3869. let dx2 = z1X * sx2X + z1Y * sx2Y + z1Z * sx2Z;
  3870. let dy2 = z1X * sy2X + z1Y * sy2Y + z1Z * sy2Z;
  3871. let dz2 = z1X * sz2X + z1Y * sz2Y + z1Z * sz2Z;
  3872. if(dx2 < 0) {
  3873. dx2 = -dx2;
  3874. }
  3875. if(dy2 < 0) {
  3876. dy2 = -dy2;
  3877. }
  3878. if(dz2 < 0) {
  3879. dz2 = -dz2;
  3880. }
  3881. proj2 = dx2 + dy2 + dz2;
  3882. projC12 = z1X * c12X + z1Y * c12Y + z1Z * c12Z;
  3883. let sum2 = proj1 + proj2;
  3884. let neg2 = projC12 < 0;
  3885. let abs2 = neg2 ? -projC12 : projC12;
  3886. if(abs2 < sum2) {
  3887. let depth = sum2 - abs2;
  3888. if(depth < mDepth) {
  3889. mDepth = depth;
  3890. mId = 2;
  3891. mAxisX = z1X;
  3892. mAxisY = z1Y;
  3893. mAxisZ = z1Z;
  3894. mSign = neg2 ? -1 : 1;
  3895. }
  3896. } else {
  3897. return;
  3898. }
  3899. if(mDepth > oimo.common.Setting.linearSlop) {
  3900. mDepth -= oimo.common.Setting.linearSlop;
  3901. } else {
  3902. mDepth = 0;
  3903. }
  3904. let dx3 = x2X * sx1X + x2Y * sx1Y + x2Z * sx1Z;
  3905. let dy3 = x2X * sy1X + x2Y * sy1Y + x2Z * sy1Z;
  3906. let dz3 = x2X * sz1X + x2Y * sz1Y + x2Z * sz1Z;
  3907. if(dx3 < 0) {
  3908. dx3 = -dx3;
  3909. }
  3910. if(dy3 < 0) {
  3911. dy3 = -dy3;
  3912. }
  3913. if(dz3 < 0) {
  3914. dz3 = -dz3;
  3915. }
  3916. proj1 = dx3 + dy3 + dz3;
  3917. proj2 = w2;
  3918. projC12 = x2X * c12X + x2Y * c12Y + x2Z * c12Z;
  3919. let sum3 = proj1 + proj2;
  3920. let neg3 = projC12 < 0;
  3921. let abs3 = neg3 ? -projC12 : projC12;
  3922. if(abs3 < sum3) {
  3923. let depth = sum3 - abs3;
  3924. if(depth < mDepth) {
  3925. mDepth = depth;
  3926. mId = 3;
  3927. mAxisX = x2X;
  3928. mAxisY = x2Y;
  3929. mAxisZ = x2Z;
  3930. mSign = neg3 ? -1 : 1;
  3931. }
  3932. } else {
  3933. return;
  3934. }
  3935. let dx4 = y2X * sx1X + y2Y * sx1Y + y2Z * sx1Z;
  3936. let dy4 = y2X * sy1X + y2Y * sy1Y + y2Z * sy1Z;
  3937. let dz4 = y2X * sz1X + y2Y * sz1Y + y2Z * sz1Z;
  3938. if(dx4 < 0) {
  3939. dx4 = -dx4;
  3940. }
  3941. if(dy4 < 0) {
  3942. dy4 = -dy4;
  3943. }
  3944. if(dz4 < 0) {
  3945. dz4 = -dz4;
  3946. }
  3947. proj1 = dx4 + dy4 + dz4;
  3948. proj2 = h2;
  3949. projC12 = y2X * c12X + y2Y * c12Y + y2Z * c12Z;
  3950. let sum4 = proj1 + proj2;
  3951. let neg4 = projC12 < 0;
  3952. let abs4 = neg4 ? -projC12 : projC12;
  3953. if(abs4 < sum4) {
  3954. let depth = sum4 - abs4;
  3955. if(depth < mDepth) {
  3956. mDepth = depth;
  3957. mId = 4;
  3958. mAxisX = y2X;
  3959. mAxisY = y2Y;
  3960. mAxisZ = y2Z;
  3961. mSign = neg4 ? -1 : 1;
  3962. }
  3963. } else {
  3964. return;
  3965. }
  3966. let dx5 = z2X * sx1X + z2Y * sx1Y + z2Z * sx1Z;
  3967. let dy5 = z2X * sy1X + z2Y * sy1Y + z2Z * sy1Z;
  3968. let dz5 = z2X * sz1X + z2Y * sz1Y + z2Z * sz1Z;
  3969. if(dx5 < 0) {
  3970. dx5 = -dx5;
  3971. }
  3972. if(dy5 < 0) {
  3973. dy5 = -dy5;
  3974. }
  3975. if(dz5 < 0) {
  3976. dz5 = -dz5;
  3977. }
  3978. proj1 = dx5 + dy5 + dz5;
  3979. proj2 = d2;
  3980. projC12 = z2X * c12X + z2Y * c12Y + z2Z * c12Z;
  3981. let sum5 = proj1 + proj2;
  3982. let neg5 = projC12 < 0;
  3983. let abs5 = neg5 ? -projC12 : projC12;
  3984. if(abs5 < sum5) {
  3985. let depth = sum5 - abs5;
  3986. if(depth < mDepth) {
  3987. mDepth = depth;
  3988. mId = 5;
  3989. mAxisX = z2X;
  3990. mAxisY = z2Y;
  3991. mAxisZ = z2Z;
  3992. mSign = neg5 ? -1 : 1;
  3993. }
  3994. } else {
  3995. return;
  3996. }
  3997. if(mDepth > oimo.common.Setting.linearSlop) {
  3998. mDepth -= oimo.common.Setting.linearSlop;
  3999. } else {
  4000. mDepth = 0;
  4001. }
  4002. let edgeAxisX;
  4003. let edgeAxisY;
  4004. let edgeAxisZ;
  4005. edgeAxisX = x1Y * x2Z - x1Z * x2Y;
  4006. edgeAxisY = x1Z * x2X - x1X * x2Z;
  4007. edgeAxisZ = x1X * x2Y - x1Y * x2X;
  4008. if(!(edgeAxisX == 0 && edgeAxisY == 0 && edgeAxisZ == 0)) {
  4009. let l = edgeAxisX * edgeAxisX + edgeAxisY * edgeAxisY + edgeAxisZ * edgeAxisZ;
  4010. if(l > 0) {
  4011. l = 1 / Math.sqrt(l);
  4012. }
  4013. edgeAxisX *= l;
  4014. edgeAxisY *= l;
  4015. edgeAxisZ *= l;
  4016. let dx = edgeAxisX * sy1X + edgeAxisY * sy1Y + edgeAxisZ * sy1Z;
  4017. let dy = edgeAxisX * sz1X + edgeAxisY * sz1Y + edgeAxisZ * sz1Z;
  4018. if(dx < 0) {
  4019. dx = -dx;
  4020. }
  4021. if(dy < 0) {
  4022. dy = -dy;
  4023. }
  4024. proj1 = dx + dy;
  4025. let dx1 = edgeAxisX * sy2X + edgeAxisY * sy2Y + edgeAxisZ * sy2Z;
  4026. let dy1 = edgeAxisX * sz2X + edgeAxisY * sz2Y + edgeAxisZ * sz2Z;
  4027. if(dx1 < 0) {
  4028. dx1 = -dx1;
  4029. }
  4030. if(dy1 < 0) {
  4031. dy1 = -dy1;
  4032. }
  4033. proj2 = dx1 + dy1;
  4034. projC12 = edgeAxisX * c12X + edgeAxisY * c12Y + edgeAxisZ * c12Z;
  4035. let sum = proj1 + proj2;
  4036. let neg = projC12 < 0;
  4037. let abs = neg ? -projC12 : projC12;
  4038. if(abs < sum) {
  4039. let depth = sum - abs;
  4040. if(depth < mDepth) {
  4041. mDepth = depth;
  4042. mId = 6;
  4043. mAxisX = edgeAxisX;
  4044. mAxisY = edgeAxisY;
  4045. mAxisZ = edgeAxisZ;
  4046. mSign = neg ? -1 : 1;
  4047. }
  4048. } else {
  4049. return;
  4050. }
  4051. }
  4052. edgeAxisX = x1Y * y2Z - x1Z * y2Y;
  4053. edgeAxisY = x1Z * y2X - x1X * y2Z;
  4054. edgeAxisZ = x1X * y2Y - x1Y * y2X;
  4055. if(!(edgeAxisX == 0 && edgeAxisY == 0 && edgeAxisZ == 0)) {
  4056. let l = edgeAxisX * edgeAxisX + edgeAxisY * edgeAxisY + edgeAxisZ * edgeAxisZ;
  4057. if(l > 0) {
  4058. l = 1 / Math.sqrt(l);
  4059. }
  4060. edgeAxisX *= l;
  4061. edgeAxisY *= l;
  4062. edgeAxisZ *= l;
  4063. let dx = edgeAxisX * sy1X + edgeAxisY * sy1Y + edgeAxisZ * sy1Z;
  4064. let dy = edgeAxisX * sz1X + edgeAxisY * sz1Y + edgeAxisZ * sz1Z;
  4065. if(dx < 0) {
  4066. dx = -dx;
  4067. }
  4068. if(dy < 0) {
  4069. dy = -dy;
  4070. }
  4071. proj1 = dx + dy;
  4072. let dx1 = edgeAxisX * sx2X + edgeAxisY * sx2Y + edgeAxisZ * sx2Z;
  4073. let dy1 = edgeAxisX * sz2X + edgeAxisY * sz2Y + edgeAxisZ * sz2Z;
  4074. if(dx1 < 0) {
  4075. dx1 = -dx1;
  4076. }
  4077. if(dy1 < 0) {
  4078. dy1 = -dy1;
  4079. }
  4080. proj2 = dx1 + dy1;
  4081. projC12 = edgeAxisX * c12X + edgeAxisY * c12Y + edgeAxisZ * c12Z;
  4082. let sum = proj1 + proj2;
  4083. let neg = projC12 < 0;
  4084. let abs = neg ? -projC12 : projC12;
  4085. if(abs < sum) {
  4086. let depth = sum - abs;
  4087. if(depth < mDepth) {
  4088. mDepth = depth;
  4089. mId = 7;
  4090. mAxisX = edgeAxisX;
  4091. mAxisY = edgeAxisY;
  4092. mAxisZ = edgeAxisZ;
  4093. mSign = neg ? -1 : 1;
  4094. }
  4095. } else {
  4096. return;
  4097. }
  4098. }
  4099. edgeAxisX = x1Y * z2Z - x1Z * z2Y;
  4100. edgeAxisY = x1Z * z2X - x1X * z2Z;
  4101. edgeAxisZ = x1X * z2Y - x1Y * z2X;
  4102. if(!(edgeAxisX == 0 && edgeAxisY == 0 && edgeAxisZ == 0)) {
  4103. let l = edgeAxisX * edgeAxisX + edgeAxisY * edgeAxisY + edgeAxisZ * edgeAxisZ;
  4104. if(l > 0) {
  4105. l = 1 / Math.sqrt(l);
  4106. }
  4107. edgeAxisX *= l;
  4108. edgeAxisY *= l;
  4109. edgeAxisZ *= l;
  4110. let dx = edgeAxisX * sy1X + edgeAxisY * sy1Y + edgeAxisZ * sy1Z;
  4111. let dy = edgeAxisX * sz1X + edgeAxisY * sz1Y + edgeAxisZ * sz1Z;
  4112. if(dx < 0) {
  4113. dx = -dx;
  4114. }
  4115. if(dy < 0) {
  4116. dy = -dy;
  4117. }
  4118. proj1 = dx + dy;
  4119. let dx1 = edgeAxisX * sx2X + edgeAxisY * sx2Y + edgeAxisZ * sx2Z;
  4120. let dy1 = edgeAxisX * sy2X + edgeAxisY * sy2Y + edgeAxisZ * sy2Z;
  4121. if(dx1 < 0) {
  4122. dx1 = -dx1;
  4123. }
  4124. if(dy1 < 0) {
  4125. dy1 = -dy1;
  4126. }
  4127. proj2 = dx1 + dy1;
  4128. projC12 = edgeAxisX * c12X + edgeAxisY * c12Y + edgeAxisZ * c12Z;
  4129. let sum = proj1 + proj2;
  4130. let neg = projC12 < 0;
  4131. let abs = neg ? -projC12 : projC12;
  4132. if(abs < sum) {
  4133. let depth = sum - abs;
  4134. if(depth < mDepth) {
  4135. mDepth = depth;
  4136. mId = 8;
  4137. mAxisX = edgeAxisX;
  4138. mAxisY = edgeAxisY;
  4139. mAxisZ = edgeAxisZ;
  4140. mSign = neg ? -1 : 1;
  4141. }
  4142. } else {
  4143. return;
  4144. }
  4145. }
  4146. edgeAxisX = y1Y * x2Z - y1Z * x2Y;
  4147. edgeAxisY = y1Z * x2X - y1X * x2Z;
  4148. edgeAxisZ = y1X * x2Y - y1Y * x2X;
  4149. if(!(edgeAxisX == 0 && edgeAxisY == 0 && edgeAxisZ == 0)) {
  4150. let l = edgeAxisX * edgeAxisX + edgeAxisY * edgeAxisY + edgeAxisZ * edgeAxisZ;
  4151. if(l > 0) {
  4152. l = 1 / Math.sqrt(l);
  4153. }
  4154. edgeAxisX *= l;
  4155. edgeAxisY *= l;
  4156. edgeAxisZ *= l;
  4157. let dx = edgeAxisX * sx1X + edgeAxisY * sx1Y + edgeAxisZ * sx1Z;
  4158. let dy = edgeAxisX * sz1X + edgeAxisY * sz1Y + edgeAxisZ * sz1Z;
  4159. if(dx < 0) {
  4160. dx = -dx;
  4161. }
  4162. if(dy < 0) {
  4163. dy = -dy;
  4164. }
  4165. proj1 = dx + dy;
  4166. let dx1 = edgeAxisX * sy2X + edgeAxisY * sy2Y + edgeAxisZ * sy2Z;
  4167. let dy1 = edgeAxisX * sz2X + edgeAxisY * sz2Y + edgeAxisZ * sz2Z;
  4168. if(dx1 < 0) {
  4169. dx1 = -dx1;
  4170. }
  4171. if(dy1 < 0) {
  4172. dy1 = -dy1;
  4173. }
  4174. proj2 = dx1 + dy1;
  4175. projC12 = edgeAxisX * c12X + edgeAxisY * c12Y + edgeAxisZ * c12Z;
  4176. let sum = proj1 + proj2;
  4177. let neg = projC12 < 0;
  4178. let abs = neg ? -projC12 : projC12;
  4179. if(abs < sum) {
  4180. let depth = sum - abs;
  4181. if(depth < mDepth) {
  4182. mDepth = depth;
  4183. mId = 9;
  4184. mAxisX = edgeAxisX;
  4185. mAxisY = edgeAxisY;
  4186. mAxisZ = edgeAxisZ;
  4187. mSign = neg ? -1 : 1;
  4188. }
  4189. } else {
  4190. return;
  4191. }
  4192. }
  4193. edgeAxisX = y1Y * y2Z - y1Z * y2Y;
  4194. edgeAxisY = y1Z * y2X - y1X * y2Z;
  4195. edgeAxisZ = y1X * y2Y - y1Y * y2X;
  4196. if(!(edgeAxisX == 0 && edgeAxisY == 0 && edgeAxisZ == 0)) {
  4197. let l = edgeAxisX * edgeAxisX + edgeAxisY * edgeAxisY + edgeAxisZ * edgeAxisZ;
  4198. if(l > 0) {
  4199. l = 1 / Math.sqrt(l);
  4200. }
  4201. edgeAxisX *= l;
  4202. edgeAxisY *= l;
  4203. edgeAxisZ *= l;
  4204. let dx = edgeAxisX * sx1X + edgeAxisY * sx1Y + edgeAxisZ * sx1Z;
  4205. let dy = edgeAxisX * sz1X + edgeAxisY * sz1Y + edgeAxisZ * sz1Z;
  4206. if(dx < 0) {
  4207. dx = -dx;
  4208. }
  4209. if(dy < 0) {
  4210. dy = -dy;
  4211. }
  4212. proj1 = dx + dy;
  4213. let dx1 = edgeAxisX * sx2X + edgeAxisY * sx2Y + edgeAxisZ * sx2Z;
  4214. let dy1 = edgeAxisX * sz2X + edgeAxisY * sz2Y + edgeAxisZ * sz2Z;
  4215. if(dx1 < 0) {
  4216. dx1 = -dx1;
  4217. }
  4218. if(dy1 < 0) {
  4219. dy1 = -dy1;
  4220. }
  4221. proj2 = dx1 + dy1;
  4222. projC12 = edgeAxisX * c12X + edgeAxisY * c12Y + edgeAxisZ * c12Z;
  4223. let sum = proj1 + proj2;
  4224. let neg = projC12 < 0;
  4225. let abs = neg ? -projC12 : projC12;
  4226. if(abs < sum) {
  4227. let depth = sum - abs;
  4228. if(depth < mDepth) {
  4229. mDepth = depth;
  4230. mId = 10;
  4231. mAxisX = edgeAxisX;
  4232. mAxisY = edgeAxisY;
  4233. mAxisZ = edgeAxisZ;
  4234. mSign = neg ? -1 : 1;
  4235. }
  4236. } else {
  4237. return;
  4238. }
  4239. }
  4240. edgeAxisX = y1Y * z2Z - y1Z * z2Y;
  4241. edgeAxisY = y1Z * z2X - y1X * z2Z;
  4242. edgeAxisZ = y1X * z2Y - y1Y * z2X;
  4243. if(!(edgeAxisX == 0 && edgeAxisY == 0 && edgeAxisZ == 0)) {
  4244. let l = edgeAxisX * edgeAxisX + edgeAxisY * edgeAxisY + edgeAxisZ * edgeAxisZ;
  4245. if(l > 0) {
  4246. l = 1 / Math.sqrt(l);
  4247. }
  4248. edgeAxisX *= l;
  4249. edgeAxisY *= l;
  4250. edgeAxisZ *= l;
  4251. let dx = edgeAxisX * sx1X + edgeAxisY * sx1Y + edgeAxisZ * sx1Z;
  4252. let dy = edgeAxisX * sz1X + edgeAxisY * sz1Y + edgeAxisZ * sz1Z;
  4253. if(dx < 0) {
  4254. dx = -dx;
  4255. }
  4256. if(dy < 0) {
  4257. dy = -dy;
  4258. }
  4259. proj1 = dx + dy;
  4260. let dx1 = edgeAxisX * sx2X + edgeAxisY * sx2Y + edgeAxisZ * sx2Z;
  4261. let dy1 = edgeAxisX * sy2X + edgeAxisY * sy2Y + edgeAxisZ * sy2Z;
  4262. if(dx1 < 0) {
  4263. dx1 = -dx1;
  4264. }
  4265. if(dy1 < 0) {
  4266. dy1 = -dy1;
  4267. }
  4268. proj2 = dx1 + dy1;
  4269. projC12 = edgeAxisX * c12X + edgeAxisY * c12Y + edgeAxisZ * c12Z;
  4270. let sum = proj1 + proj2;
  4271. let neg = projC12 < 0;
  4272. let abs = neg ? -projC12 : projC12;
  4273. if(abs < sum) {
  4274. let depth = sum - abs;
  4275. if(depth < mDepth) {
  4276. mDepth = depth;
  4277. mId = 11;
  4278. mAxisX = edgeAxisX;
  4279. mAxisY = edgeAxisY;
  4280. mAxisZ = edgeAxisZ;
  4281. mSign = neg ? -1 : 1;
  4282. }
  4283. } else {
  4284. return;
  4285. }
  4286. }
  4287. edgeAxisX = z1Y * x2Z - z1Z * x2Y;
  4288. edgeAxisY = z1Z * x2X - z1X * x2Z;
  4289. edgeAxisZ = z1X * x2Y - z1Y * x2X;
  4290. if(!(edgeAxisX == 0 && edgeAxisY == 0 && edgeAxisZ == 0)) {
  4291. let l = edgeAxisX * edgeAxisX + edgeAxisY * edgeAxisY + edgeAxisZ * edgeAxisZ;
  4292. if(l > 0) {
  4293. l = 1 / Math.sqrt(l);
  4294. }
  4295. edgeAxisX *= l;
  4296. edgeAxisY *= l;
  4297. edgeAxisZ *= l;
  4298. let dx = edgeAxisX * sx1X + edgeAxisY * sx1Y + edgeAxisZ * sx1Z;
  4299. let dy = edgeAxisX * sy1X + edgeAxisY * sy1Y + edgeAxisZ * sy1Z;
  4300. if(dx < 0) {
  4301. dx = -dx;
  4302. }
  4303. if(dy < 0) {
  4304. dy = -dy;
  4305. }
  4306. proj1 = dx + dy;
  4307. let dx1 = edgeAxisX * sy2X + edgeAxisY * sy2Y + edgeAxisZ * sy2Z;
  4308. let dy1 = edgeAxisX * sz2X + edgeAxisY * sz2Y + edgeAxisZ * sz2Z;
  4309. if(dx1 < 0) {
  4310. dx1 = -dx1;
  4311. }
  4312. if(dy1 < 0) {
  4313. dy1 = -dy1;
  4314. }
  4315. proj2 = dx1 + dy1;
  4316. projC12 = edgeAxisX * c12X + edgeAxisY * c12Y + edgeAxisZ * c12Z;
  4317. let sum = proj1 + proj2;
  4318. let neg = projC12 < 0;
  4319. let abs = neg ? -projC12 : projC12;
  4320. if(abs < sum) {
  4321. let depth = sum - abs;
  4322. if(depth < mDepth) {
  4323. mDepth = depth;
  4324. mId = 12;
  4325. mAxisX = edgeAxisX;
  4326. mAxisY = edgeAxisY;
  4327. mAxisZ = edgeAxisZ;
  4328. mSign = neg ? -1 : 1;
  4329. }
  4330. } else {
  4331. return;
  4332. }
  4333. }
  4334. edgeAxisX = z1Y * y2Z - z1Z * y2Y;
  4335. edgeAxisY = z1Z * y2X - z1X * y2Z;
  4336. edgeAxisZ = z1X * y2Y - z1Y * y2X;
  4337. if(!(edgeAxisX == 0 && edgeAxisY == 0 && edgeAxisZ == 0)) {
  4338. let l = edgeAxisX * edgeAxisX + edgeAxisY * edgeAxisY + edgeAxisZ * edgeAxisZ;
  4339. if(l > 0) {
  4340. l = 1 / Math.sqrt(l);
  4341. }
  4342. edgeAxisX *= l;
  4343. edgeAxisY *= l;
  4344. edgeAxisZ *= l;
  4345. let dx = edgeAxisX * sx1X + edgeAxisY * sx1Y + edgeAxisZ * sx1Z;
  4346. let dy = edgeAxisX * sy1X + edgeAxisY * sy1Y + edgeAxisZ * sy1Z;
  4347. if(dx < 0) {
  4348. dx = -dx;
  4349. }
  4350. if(dy < 0) {
  4351. dy = -dy;
  4352. }
  4353. proj1 = dx + dy;
  4354. let dx1 = edgeAxisX * sx2X + edgeAxisY * sx2Y + edgeAxisZ * sx2Z;
  4355. let dy1 = edgeAxisX * sz2X + edgeAxisY * sz2Y + edgeAxisZ * sz2Z;
  4356. if(dx1 < 0) {
  4357. dx1 = -dx1;
  4358. }
  4359. if(dy1 < 0) {
  4360. dy1 = -dy1;
  4361. }
  4362. proj2 = dx1 + dy1;
  4363. projC12 = edgeAxisX * c12X + edgeAxisY * c12Y + edgeAxisZ * c12Z;
  4364. let sum = proj1 + proj2;
  4365. let neg = projC12 < 0;
  4366. let abs = neg ? -projC12 : projC12;
  4367. if(abs < sum) {
  4368. let depth = sum - abs;
  4369. if(depth < mDepth) {
  4370. mDepth = depth;
  4371. mId = 13;
  4372. mAxisX = edgeAxisX;
  4373. mAxisY = edgeAxisY;
  4374. mAxisZ = edgeAxisZ;
  4375. mSign = neg ? -1 : 1;
  4376. }
  4377. } else {
  4378. return;
  4379. }
  4380. }
  4381. edgeAxisX = z1Y * z2Z - z1Z * z2Y;
  4382. edgeAxisY = z1Z * z2X - z1X * z2Z;
  4383. edgeAxisZ = z1X * z2Y - z1Y * z2X;
  4384. if(!(edgeAxisX == 0 && edgeAxisY == 0 && edgeAxisZ == 0)) {
  4385. let l = edgeAxisX * edgeAxisX + edgeAxisY * edgeAxisY + edgeAxisZ * edgeAxisZ;
  4386. if(l > 0) {
  4387. l = 1 / Math.sqrt(l);
  4388. }
  4389. edgeAxisX *= l;
  4390. edgeAxisY *= l;
  4391. edgeAxisZ *= l;
  4392. let dx = edgeAxisX * sx1X + edgeAxisY * sx1Y + edgeAxisZ * sx1Z;
  4393. let dy = edgeAxisX * sy1X + edgeAxisY * sy1Y + edgeAxisZ * sy1Z;
  4394. if(dx < 0) {
  4395. dx = -dx;
  4396. }
  4397. if(dy < 0) {
  4398. dy = -dy;
  4399. }
  4400. proj1 = dx + dy;
  4401. let dx1 = edgeAxisX * sx2X + edgeAxisY * sx2Y + edgeAxisZ * sx2Z;
  4402. let dy1 = edgeAxisX * sy2X + edgeAxisY * sy2Y + edgeAxisZ * sy2Z;
  4403. if(dx1 < 0) {
  4404. dx1 = -dx1;
  4405. }
  4406. if(dy1 < 0) {
  4407. dy1 = -dy1;
  4408. }
  4409. proj2 = dx1 + dy1;
  4410. projC12 = edgeAxisX * c12X + edgeAxisY * c12Y + edgeAxisZ * c12Z;
  4411. let sum = proj1 + proj2;
  4412. let neg = projC12 < 0;
  4413. let abs = neg ? -projC12 : projC12;
  4414. if(abs < sum) {
  4415. let depth = sum - abs;
  4416. if(depth < mDepth) {
  4417. mDepth = depth;
  4418. mId = 14;
  4419. mAxisX = edgeAxisX;
  4420. mAxisY = edgeAxisY;
  4421. mAxisZ = edgeAxisZ;
  4422. mSign = neg ? -1 : 1;
  4423. }
  4424. } else {
  4425. return;
  4426. }
  4427. }
  4428. if(mId >= 6) {
  4429. mAxisX *= mSign;
  4430. mAxisY *= mSign;
  4431. mAxisZ *= mSign;
  4432. let id1 = (mId - 6) / 3 | 0;
  4433. let id2 = mId - 6 - id1 * 3;
  4434. let p1X;
  4435. let p1Y;
  4436. let p1Z;
  4437. let p2X;
  4438. let p2Y;
  4439. let p2Z;
  4440. let d1X;
  4441. let d1Y;
  4442. let d1Z;
  4443. let d2X;
  4444. let d2Y;
  4445. let d2Z;
  4446. switch(id1) {
  4447. case 0:
  4448. d1X = x1X;
  4449. d1Y = x1Y;
  4450. d1Z = x1Z;
  4451. let signY = sz1X * mAxisX + sz1Y * mAxisY + sz1Z * mAxisZ > 0;
  4452. if(sy1X * mAxisX + sy1Y * mAxisY + sy1Z * mAxisZ > 0) {
  4453. if(signY) {
  4454. p1X = sy1X + sz1X;
  4455. p1Y = sy1Y + sz1Y;
  4456. p1Z = sy1Z + sz1Z;
  4457. } else {
  4458. p1X = sy1X - sz1X;
  4459. p1Y = sy1Y - sz1Y;
  4460. p1Z = sy1Z - sz1Z;
  4461. }
  4462. } else if(signY) {
  4463. p1X = sz1X - sy1X;
  4464. p1Y = sz1Y - sy1Y;
  4465. p1Z = sz1Z - sy1Z;
  4466. } else {
  4467. p1X = sy1X + sz1X;
  4468. p1Y = sy1Y + sz1Y;
  4469. p1Z = sy1Z + sz1Z;
  4470. p1X = -p1X;
  4471. p1Y = -p1Y;
  4472. p1Z = -p1Z;
  4473. }
  4474. break;
  4475. case 1:
  4476. d1X = y1X;
  4477. d1Y = y1Y;
  4478. d1Z = y1Z;
  4479. let signY1 = sz1X * mAxisX + sz1Y * mAxisY + sz1Z * mAxisZ > 0;
  4480. if(sx1X * mAxisX + sx1Y * mAxisY + sx1Z * mAxisZ > 0) {
  4481. if(signY1) {
  4482. p1X = sx1X + sz1X;
  4483. p1Y = sx1Y + sz1Y;
  4484. p1Z = sx1Z + sz1Z;
  4485. } else {
  4486. p1X = sx1X - sz1X;
  4487. p1Y = sx1Y - sz1Y;
  4488. p1Z = sx1Z - sz1Z;
  4489. }
  4490. } else if(signY1) {
  4491. p1X = sz1X - sx1X;
  4492. p1Y = sz1Y - sx1Y;
  4493. p1Z = sz1Z - sx1Z;
  4494. } else {
  4495. p1X = sx1X + sz1X;
  4496. p1Y = sx1Y + sz1Y;
  4497. p1Z = sx1Z + sz1Z;
  4498. p1X = -p1X;
  4499. p1Y = -p1Y;
  4500. p1Z = -p1Z;
  4501. }
  4502. break;
  4503. default:
  4504. d1X = z1X;
  4505. d1Y = z1Y;
  4506. d1Z = z1Z;
  4507. let signY2 = sy1X * mAxisX + sy1Y * mAxisY + sy1Z * mAxisZ > 0;
  4508. if(sx1X * mAxisX + sx1Y * mAxisY + sx1Z * mAxisZ > 0) {
  4509. if(signY2) {
  4510. p1X = sx1X + sy1X;
  4511. p1Y = sx1Y + sy1Y;
  4512. p1Z = sx1Z + sy1Z;
  4513. } else {
  4514. p1X = sx1X - sy1X;
  4515. p1Y = sx1Y - sy1Y;
  4516. p1Z = sx1Z - sy1Z;
  4517. }
  4518. } else if(signY2) {
  4519. p1X = sy1X - sx1X;
  4520. p1Y = sy1Y - sx1Y;
  4521. p1Z = sy1Z - sx1Z;
  4522. } else {
  4523. p1X = sx1X + sy1X;
  4524. p1Y = sx1Y + sy1Y;
  4525. p1Z = sx1Z + sy1Z;
  4526. p1X = -p1X;
  4527. p1Y = -p1Y;
  4528. p1Z = -p1Z;
  4529. }
  4530. }
  4531. p1X = c1X + p1X;
  4532. p1Y = c1Y + p1Y;
  4533. p1Z = c1Z + p1Z;
  4534. switch(id2) {
  4535. case 0:
  4536. d2X = x2X;
  4537. d2Y = x2Y;
  4538. d2Z = x2Z;
  4539. let signY3 = sz2X * mAxisX + sz2Y * mAxisY + sz2Z * mAxisZ > 0;
  4540. if(sy2X * mAxisX + sy2Y * mAxisY + sy2Z * mAxisZ > 0) {
  4541. if(signY3) {
  4542. p2X = sy2X + sz2X;
  4543. p2Y = sy2Y + sz2Y;
  4544. p2Z = sy2Z + sz2Z;
  4545. } else {
  4546. p2X = sy2X - sz2X;
  4547. p2Y = sy2Y - sz2Y;
  4548. p2Z = sy2Z - sz2Z;
  4549. }
  4550. } else if(signY3) {
  4551. p2X = sz2X - sy2X;
  4552. p2Y = sz2Y - sy2Y;
  4553. p2Z = sz2Z - sy2Z;
  4554. } else {
  4555. p2X = sy2X + sz2X;
  4556. p2Y = sy2Y + sz2Y;
  4557. p2Z = sy2Z + sz2Z;
  4558. p2X = -p2X;
  4559. p2Y = -p2Y;
  4560. p2Z = -p2Z;
  4561. }
  4562. break;
  4563. case 1:
  4564. d2X = y2X;
  4565. d2Y = y2Y;
  4566. d2Z = y2Z;
  4567. let signY4 = sz2X * mAxisX + sz2Y * mAxisY + sz2Z * mAxisZ > 0;
  4568. if(sx2X * mAxisX + sx2Y * mAxisY + sx2Z * mAxisZ > 0) {
  4569. if(signY4) {
  4570. p2X = sx2X + sz2X;
  4571. p2Y = sx2Y + sz2Y;
  4572. p2Z = sx2Z + sz2Z;
  4573. } else {
  4574. p2X = sx2X - sz2X;
  4575. p2Y = sx2Y - sz2Y;
  4576. p2Z = sx2Z - sz2Z;
  4577. }
  4578. } else if(signY4) {
  4579. p2X = sz2X - sx2X;
  4580. p2Y = sz2Y - sx2Y;
  4581. p2Z = sz2Z - sx2Z;
  4582. } else {
  4583. p2X = sx2X + sz2X;
  4584. p2Y = sx2Y + sz2Y;
  4585. p2Z = sx2Z + sz2Z;
  4586. p2X = -p2X;
  4587. p2Y = -p2Y;
  4588. p2Z = -p2Z;
  4589. }
  4590. break;
  4591. default:
  4592. d2X = z2X;
  4593. d2Y = z2Y;
  4594. d2Z = z2Z;
  4595. let signY5 = sy2X * mAxisX + sy2Y * mAxisY + sy2Z * mAxisZ > 0;
  4596. if(sx2X * mAxisX + sx2Y * mAxisY + sx2Z * mAxisZ > 0) {
  4597. if(signY5) {
  4598. p2X = sx2X + sy2X;
  4599. p2Y = sx2Y + sy2Y;
  4600. p2Z = sx2Z + sy2Z;
  4601. } else {
  4602. p2X = sx2X - sy2X;
  4603. p2Y = sx2Y - sy2Y;
  4604. p2Z = sx2Z - sy2Z;
  4605. }
  4606. } else if(signY5) {
  4607. p2X = sy2X - sx2X;
  4608. p2Y = sy2Y - sx2Y;
  4609. p2Z = sy2Z - sx2Z;
  4610. } else {
  4611. p2X = sx2X + sy2X;
  4612. p2Y = sx2Y + sy2Y;
  4613. p2Z = sx2Z + sy2Z;
  4614. p2X = -p2X;
  4615. p2Y = -p2Y;
  4616. p2Z = -p2Z;
  4617. }
  4618. }
  4619. p2X = c2X - p2X;
  4620. p2Y = c2Y - p2Y;
  4621. p2Z = c2Z - p2Z;
  4622. let rX;
  4623. let rY;
  4624. let rZ;
  4625. rX = p1X - p2X;
  4626. rY = p1Y - p2Y;
  4627. rZ = p1Z - p2Z;
  4628. let dot12 = d1X * d2X + d1Y * d2Y + d1Z * d2Z;
  4629. let dot1r = d1X * rX + d1Y * rY + d1Z * rZ;
  4630. let dot2r = d2X * rX + d2Y * rY + d2Z * rZ;
  4631. let invDet = 1 / (1 - dot12 * dot12);
  4632. let t1 = (dot12 * dot2r - dot1r) * invDet;
  4633. let t2 = (dot2r - dot12 * dot1r) * invDet;
  4634. let cp1X;
  4635. let cp1Y;
  4636. let cp1Z;
  4637. let cp2X;
  4638. let cp2Y;
  4639. let cp2Z;
  4640. cp1X = p1X + d1X * t1;
  4641. cp1Y = p1Y + d1Y * t1;
  4642. cp1Z = p1Z + d1Z * t1;
  4643. cp2X = p2X + d2X * t2;
  4644. cp2Y = p2Y + d2Y * t2;
  4645. cp2Z = p2Z + d2Z * t2;
  4646. let normalX;
  4647. let normalY;
  4648. let normalZ;
  4649. normalX = -mAxisX;
  4650. normalY = -mAxisY;
  4651. normalZ = -mAxisZ;
  4652. this.setNormal(result,normalX,normalY,normalZ);
  4653. this.addPoint(result,cp1X,cp1Y,cp1Z,cp2X,cp2Y,cp2Z,mDepth,4);
  4654. return;
  4655. }
  4656. let tmpX;
  4657. let tmpY;
  4658. let tmpZ;
  4659. let swapped;
  4660. if(mId >= 3) {
  4661. mSign = -mSign;
  4662. c12X = -c12X;
  4663. c12Y = -c12Y;
  4664. c12Z = -c12Z;
  4665. w1 = w2;
  4666. h1 = h2;
  4667. d1 = d2;
  4668. c1X = c2X;
  4669. c1Y = c2Y;
  4670. c1Z = c2Z;
  4671. tmpX = x1X;
  4672. tmpY = x1Y;
  4673. tmpZ = x1Z;
  4674. x1X = x2X;
  4675. x1Y = x2Y;
  4676. x1Z = x2Z;
  4677. x2X = tmpX;
  4678. x2Y = tmpY;
  4679. x2Z = tmpZ;
  4680. tmpX = y1X;
  4681. tmpY = y1Y;
  4682. tmpZ = y1Z;
  4683. y1X = y2X;
  4684. y1Y = y2Y;
  4685. y1Z = y2Z;
  4686. y2X = tmpX;
  4687. y2Y = tmpY;
  4688. y2Z = tmpZ;
  4689. tmpX = z1X;
  4690. tmpY = z1Y;
  4691. tmpZ = z1Z;
  4692. z1X = z2X;
  4693. z1Y = z2Y;
  4694. z1Z = z2Z;
  4695. z2X = tmpX;
  4696. z2Y = tmpY;
  4697. z2Z = tmpZ;
  4698. tmpX = sx1X;
  4699. tmpY = sx1Y;
  4700. tmpZ = sx1Z;
  4701. sx1X = sx2X;
  4702. sx1Y = sx2Y;
  4703. sx1Z = sx2Z;
  4704. sx2X = tmpX;
  4705. sx2Y = tmpY;
  4706. sx2Z = tmpZ;
  4707. tmpX = sy1X;
  4708. tmpY = sy1Y;
  4709. tmpZ = sy1Z;
  4710. sy1X = sy2X;
  4711. sy1Y = sy2Y;
  4712. sy1Z = sy2Z;
  4713. sy2X = tmpX;
  4714. sy2Y = tmpY;
  4715. sy2Z = tmpZ;
  4716. tmpX = sz1X;
  4717. tmpY = sz1Y;
  4718. tmpZ = sz1Z;
  4719. sz1X = sz2X;
  4720. sz1Y = sz2Y;
  4721. sz1Z = sz2Z;
  4722. sz2X = tmpX;
  4723. sz2Y = tmpY;
  4724. sz2Z = tmpZ;
  4725. mId -= 3;
  4726. swapped = true;
  4727. } else {
  4728. swapped = false;
  4729. }
  4730. let refCenterX;
  4731. let refCenterY;
  4732. let refCenterZ;
  4733. let refNormalX;
  4734. let refNormalY;
  4735. let refNormalZ;
  4736. let refXX;
  4737. let refXY;
  4738. let refXZ;
  4739. let refYX;
  4740. let refYY;
  4741. let refYZ;
  4742. let refW;
  4743. let refH;
  4744. switch(mId) {
  4745. case 0:
  4746. refCenterX = sx1X;
  4747. refCenterY = sx1Y;
  4748. refCenterZ = sx1Z;
  4749. refNormalX = x1X;
  4750. refNormalY = x1Y;
  4751. refNormalZ = x1Z;
  4752. refXX = y1X;
  4753. refXY = y1Y;
  4754. refXZ = y1Z;
  4755. refYX = z1X;
  4756. refYY = z1Y;
  4757. refYZ = z1Z;
  4758. refW = h1;
  4759. refH = d1;
  4760. break;
  4761. case 1:
  4762. refCenterX = sy1X;
  4763. refCenterY = sy1Y;
  4764. refCenterZ = sy1Z;
  4765. refNormalX = y1X;
  4766. refNormalY = y1Y;
  4767. refNormalZ = y1Z;
  4768. refXX = z1X;
  4769. refXY = z1Y;
  4770. refXZ = z1Z;
  4771. refYX = x1X;
  4772. refYY = x1Y;
  4773. refYZ = x1Z;
  4774. refW = d1;
  4775. refH = w1;
  4776. break;
  4777. default:
  4778. refCenterX = sz1X;
  4779. refCenterY = sz1Y;
  4780. refCenterZ = sz1Z;
  4781. refNormalX = z1X;
  4782. refNormalY = z1Y;
  4783. refNormalZ = z1Z;
  4784. refXX = x1X;
  4785. refXY = x1Y;
  4786. refXZ = x1Z;
  4787. refYX = y1X;
  4788. refYY = y1Y;
  4789. refYZ = y1Z;
  4790. refW = w1;
  4791. refH = h1;
  4792. }
  4793. if(mSign < 0) {
  4794. refCenterX = -refCenterX;
  4795. refCenterY = -refCenterY;
  4796. refCenterZ = -refCenterZ;
  4797. refNormalX = -refNormalX;
  4798. refNormalY = -refNormalY;
  4799. refNormalZ = -refNormalZ;
  4800. tmpX = refXX;
  4801. tmpY = refXY;
  4802. tmpZ = refXZ;
  4803. refXX = refYX;
  4804. refXY = refYY;
  4805. refXZ = refYZ;
  4806. refYX = tmpX;
  4807. refYY = tmpY;
  4808. refYZ = tmpZ;
  4809. let tmp = refW;
  4810. refW = refH;
  4811. refH = tmp;
  4812. }
  4813. refCenterX += c1X;
  4814. refCenterY += c1Y;
  4815. refCenterZ += c1Z;
  4816. let minIncDot = 1;
  4817. let incId = 0;
  4818. let incDot = refNormalX * x2X + refNormalY * x2Y + refNormalZ * x2Z;
  4819. if(incDot < minIncDot) {
  4820. minIncDot = incDot;
  4821. incId = 0;
  4822. }
  4823. if(-incDot < minIncDot) {
  4824. minIncDot = -incDot;
  4825. incId = 1;
  4826. }
  4827. incDot = refNormalX * y2X + refNormalY * y2Y + refNormalZ * y2Z;
  4828. if(incDot < minIncDot) {
  4829. minIncDot = incDot;
  4830. incId = 2;
  4831. }
  4832. if(-incDot < minIncDot) {
  4833. minIncDot = -incDot;
  4834. incId = 3;
  4835. }
  4836. incDot = refNormalX * z2X + refNormalY * z2Y + refNormalZ * z2Z;
  4837. if(incDot < minIncDot) {
  4838. minIncDot = incDot;
  4839. incId = 4;
  4840. }
  4841. if(-incDot < minIncDot) {
  4842. incId = 5;
  4843. }
  4844. let incV1X;
  4845. let incV1Y;
  4846. let incV1Z;
  4847. let incV2X;
  4848. let incV2Y;
  4849. let incV2Z;
  4850. let incV3X;
  4851. let incV3Y;
  4852. let incV3Z;
  4853. let incV4X;
  4854. let incV4Y;
  4855. let incV4Z;
  4856. switch(incId) {
  4857. case 0:
  4858. incV1X = sx2X + sy2X;
  4859. incV1Y = sx2Y + sy2Y;
  4860. incV1Z = sx2Z + sy2Z;
  4861. incV1X += sz2X;
  4862. incV1Y += sz2Y;
  4863. incV1Z += sz2Z;
  4864. incV2X = sx2X - sy2X;
  4865. incV2Y = sx2Y - sy2Y;
  4866. incV2Z = sx2Z - sy2Z;
  4867. incV2X += sz2X;
  4868. incV2Y += sz2Y;
  4869. incV2Z += sz2Z;
  4870. incV3X = sx2X - sy2X;
  4871. incV3Y = sx2Y - sy2Y;
  4872. incV3Z = sx2Z - sy2Z;
  4873. incV3X -= sz2X;
  4874. incV3Y -= sz2Y;
  4875. incV3Z -= sz2Z;
  4876. incV4X = sx2X + sy2X;
  4877. incV4Y = sx2Y + sy2Y;
  4878. incV4Z = sx2Z + sy2Z;
  4879. incV4X -= sz2X;
  4880. incV4Y -= sz2Y;
  4881. incV4Z -= sz2Z;
  4882. break;
  4883. case 1:
  4884. incV1X = sy2X - sx2X;
  4885. incV1Y = sy2Y - sx2Y;
  4886. incV1Z = sy2Z - sx2Z;
  4887. incV1X += sz2X;
  4888. incV1Y += sz2Y;
  4889. incV1Z += sz2Z;
  4890. incV2X = sy2X - sx2X;
  4891. incV2Y = sy2Y - sx2Y;
  4892. incV2Z = sy2Z - sx2Z;
  4893. incV2X -= sz2X;
  4894. incV2Y -= sz2Y;
  4895. incV2Z -= sz2Z;
  4896. incV3X = sx2X + sy2X;
  4897. incV3Y = sx2Y + sy2Y;
  4898. incV3Z = sx2Z + sy2Z;
  4899. incV3X = -incV3X;
  4900. incV3Y = -incV3Y;
  4901. incV3Z = -incV3Z;
  4902. incV3X -= sz2X;
  4903. incV3Y -= sz2Y;
  4904. incV3Z -= sz2Z;
  4905. incV4X = sx2X + sy2X;
  4906. incV4Y = sx2Y + sy2Y;
  4907. incV4Z = sx2Z + sy2Z;
  4908. incV4X = -incV4X;
  4909. incV4Y = -incV4Y;
  4910. incV4Z = -incV4Z;
  4911. incV4X += sz2X;
  4912. incV4Y += sz2Y;
  4913. incV4Z += sz2Z;
  4914. break;
  4915. case 2:
  4916. incV1X = sx2X + sy2X;
  4917. incV1Y = sx2Y + sy2Y;
  4918. incV1Z = sx2Z + sy2Z;
  4919. incV1X += sz2X;
  4920. incV1Y += sz2Y;
  4921. incV1Z += sz2Z;
  4922. incV2X = sx2X + sy2X;
  4923. incV2Y = sx2Y + sy2Y;
  4924. incV2Z = sx2Z + sy2Z;
  4925. incV2X -= sz2X;
  4926. incV2Y -= sz2Y;
  4927. incV2Z -= sz2Z;
  4928. incV3X = sy2X - sx2X;
  4929. incV3Y = sy2Y - sx2Y;
  4930. incV3Z = sy2Z - sx2Z;
  4931. incV3X -= sz2X;
  4932. incV3Y -= sz2Y;
  4933. incV3Z -= sz2Z;
  4934. incV4X = sy2X - sx2X;
  4935. incV4Y = sy2Y - sx2Y;
  4936. incV4Z = sy2Z - sx2Z;
  4937. incV4X += sz2X;
  4938. incV4Y += sz2Y;
  4939. incV4Z += sz2Z;
  4940. break;
  4941. case 3:
  4942. incV1X = sx2X - sy2X;
  4943. incV1Y = sx2Y - sy2Y;
  4944. incV1Z = sx2Z - sy2Z;
  4945. incV1X += sz2X;
  4946. incV1Y += sz2Y;
  4947. incV1Z += sz2Z;
  4948. incV2X = sx2X + sy2X;
  4949. incV2Y = sx2Y + sy2Y;
  4950. incV2Z = sx2Z + sy2Z;
  4951. incV2X = -incV2X;
  4952. incV2Y = -incV2Y;
  4953. incV2Z = -incV2Z;
  4954. incV2X += sz2X;
  4955. incV2Y += sz2Y;
  4956. incV2Z += sz2Z;
  4957. incV3X = sx2X + sy2X;
  4958. incV3Y = sx2Y + sy2Y;
  4959. incV3Z = sx2Z + sy2Z;
  4960. incV3X = -incV3X;
  4961. incV3Y = -incV3Y;
  4962. incV3Z = -incV3Z;
  4963. incV3X -= sz2X;
  4964. incV3Y -= sz2Y;
  4965. incV3Z -= sz2Z;
  4966. incV4X = sx2X - sy2X;
  4967. incV4Y = sx2Y - sy2Y;
  4968. incV4Z = sx2Z - sy2Z;
  4969. incV4X -= sz2X;
  4970. incV4Y -= sz2Y;
  4971. incV4Z -= sz2Z;
  4972. break;
  4973. case 4:
  4974. incV1X = sx2X + sy2X;
  4975. incV1Y = sx2Y + sy2Y;
  4976. incV1Z = sx2Z + sy2Z;
  4977. incV1X += sz2X;
  4978. incV1Y += sz2Y;
  4979. incV1Z += sz2Z;
  4980. incV2X = sy2X - sx2X;
  4981. incV2Y = sy2Y - sx2Y;
  4982. incV2Z = sy2Z - sx2Z;
  4983. incV2X += sz2X;
  4984. incV2Y += sz2Y;
  4985. incV2Z += sz2Z;
  4986. incV3X = sx2X + sy2X;
  4987. incV3Y = sx2Y + sy2Y;
  4988. incV3Z = sx2Z + sy2Z;
  4989. incV3X = -incV3X;
  4990. incV3Y = -incV3Y;
  4991. incV3Z = -incV3Z;
  4992. incV3X += sz2X;
  4993. incV3Y += sz2Y;
  4994. incV3Z += sz2Z;
  4995. incV4X = sx2X - sy2X;
  4996. incV4Y = sx2Y - sy2Y;
  4997. incV4Z = sx2Z - sy2Z;
  4998. incV4X += sz2X;
  4999. incV4Y += sz2Y;
  5000. incV4Z += sz2Z;
  5001. break;
  5002. default:
  5003. incV1X = sx2X + sy2X;
  5004. incV1Y = sx2Y + sy2Y;
  5005. incV1Z = sx2Z + sy2Z;
  5006. incV1X -= sz2X;
  5007. incV1Y -= sz2Y;
  5008. incV1Z -= sz2Z;
  5009. incV2X = sx2X - sy2X;
  5010. incV2Y = sx2Y - sy2Y;
  5011. incV2Z = sx2Z - sy2Z;
  5012. incV2X -= sz2X;
  5013. incV2Y -= sz2Y;
  5014. incV2Z -= sz2Z;
  5015. incV3X = sx2X + sy2X;
  5016. incV3Y = sx2Y + sy2Y;
  5017. incV3Z = sx2Z + sy2Z;
  5018. incV3X = -incV3X;
  5019. incV3Y = -incV3Y;
  5020. incV3Z = -incV3Z;
  5021. incV3X -= sz2X;
  5022. incV3Y -= sz2Y;
  5023. incV3Z -= sz2Z;
  5024. incV4X = sy2X - sx2X;
  5025. incV4Y = sy2Y - sx2Y;
  5026. incV4Z = sy2Z - sx2Z;
  5027. incV4X -= sz2X;
  5028. incV4Y -= sz2Y;
  5029. incV4Z -= sz2Z;
  5030. }
  5031. incV1X += c12X;
  5032. incV1Y += c12Y;
  5033. incV1Z += c12Z;
  5034. incV2X += c12X;
  5035. incV2Y += c12Y;
  5036. incV2Z += c12Z;
  5037. incV3X += c12X;
  5038. incV3Y += c12Y;
  5039. incV3Z += c12Z;
  5040. incV4X += c12X;
  5041. incV4Y += c12Y;
  5042. incV4Z += c12Z;
  5043. let _this = this.clipper;
  5044. _this.w = refW;
  5045. _this.h = refH;
  5046. _this.numVertices = 0;
  5047. _this.numTmpVertices = 0;
  5048. let _this1 = this.clipper;
  5049. let _this2 = _this1.vertices[_this1.numVertices++];
  5050. _this2.x = incV1X * refXX + incV1Y * refXY + incV1Z * refXZ;
  5051. _this2.y = incV1X * refYX + incV1Y * refYY + incV1Z * refYZ;
  5052. _this2.wx = incV1X;
  5053. _this2.wy = incV1Y;
  5054. _this2.wz = incV1Z;
  5055. let _this3 = this.clipper;
  5056. let _this4 = _this3.vertices[_this3.numVertices++];
  5057. _this4.x = incV2X * refXX + incV2Y * refXY + incV2Z * refXZ;
  5058. _this4.y = incV2X * refYX + incV2Y * refYY + incV2Z * refYZ;
  5059. _this4.wx = incV2X;
  5060. _this4.wy = incV2Y;
  5061. _this4.wz = incV2Z;
  5062. let _this5 = this.clipper;
  5063. let _this6 = _this5.vertices[_this5.numVertices++];
  5064. _this6.x = incV3X * refXX + incV3Y * refXY + incV3Z * refXZ;
  5065. _this6.y = incV3X * refYX + incV3Y * refYY + incV3Z * refYZ;
  5066. _this6.wx = incV3X;
  5067. _this6.wy = incV3Y;
  5068. _this6.wz = incV3Z;
  5069. let _this7 = this.clipper;
  5070. let _this8 = _this7.vertices[_this7.numVertices++];
  5071. _this8.x = incV4X * refXX + incV4Y * refXY + incV4Z * refXZ;
  5072. _this8.y = incV4X * refYX + incV4Y * refYY + incV4Z * refYZ;
  5073. _this8.wx = incV4X;
  5074. _this8.wy = incV4Y;
  5075. _this8.wz = incV4Z;
  5076. this.clipper.clip();
  5077. this.clipper.reduce();
  5078. let normalX;
  5079. let normalY;
  5080. let normalZ;
  5081. if(swapped) {
  5082. normalX = refNormalX;
  5083. normalY = refNormalY;
  5084. normalZ = refNormalZ;
  5085. } else {
  5086. normalX = -refNormalX;
  5087. normalY = -refNormalY;
  5088. normalZ = -refNormalZ;
  5089. }
  5090. this.setNormal(result,normalX,normalY,normalZ);
  5091. let _g = 0;
  5092. let _g1 = this.clipper.numVertices;
  5093. while(_g < _g1) {
  5094. let i = _g++;
  5095. let v = this.clipper.vertices[i];
  5096. let clippedVertexX;
  5097. let clippedVertexY;
  5098. let clippedVertexZ;
  5099. clippedVertexX = v.wx;
  5100. clippedVertexY = v.wy;
  5101. clippedVertexZ = v.wz;
  5102. clippedVertexX += c1X;
  5103. clippedVertexY += c1Y;
  5104. clippedVertexZ += c1Z;
  5105. let clippedVertexToRefCenterX;
  5106. let clippedVertexToRefCenterY;
  5107. let clippedVertexToRefCenterZ;
  5108. clippedVertexToRefCenterX = refCenterX - clippedVertexX;
  5109. clippedVertexToRefCenterY = refCenterY - clippedVertexY;
  5110. clippedVertexToRefCenterZ = refCenterZ - clippedVertexZ;
  5111. let depth = clippedVertexToRefCenterX * refNormalX + clippedVertexToRefCenterY * refNormalY + clippedVertexToRefCenterZ * refNormalZ;
  5112. let clippedVertexOnRefFaceX;
  5113. let clippedVertexOnRefFaceY;
  5114. let clippedVertexOnRefFaceZ;
  5115. clippedVertexOnRefFaceX = clippedVertexX + refNormalX * depth;
  5116. clippedVertexOnRefFaceY = clippedVertexY + refNormalY * depth;
  5117. clippedVertexOnRefFaceZ = clippedVertexZ + refNormalZ * depth;
  5118. if(depth > -oimo.common.Setting.contactPersistenceThreshold) {
  5119. if(swapped) {
  5120. this.addPoint(result,clippedVertexX,clippedVertexY,clippedVertexZ,clippedVertexOnRefFaceX,clippedVertexOnRefFaceY,clippedVertexOnRefFaceZ,depth,i);
  5121. } else {
  5122. this.addPoint(result,clippedVertexOnRefFaceX,clippedVertexOnRefFaceY,clippedVertexOnRefFaceZ,clippedVertexX,clippedVertexY,clippedVertexZ,depth,i);
  5123. }
  5124. }
  5125. }
  5126. }
  5127. }
  5128. if(!oimo.collision.narrowphase.detector._BoxBoxDetector) oimo.collision.narrowphase.detector._BoxBoxDetector = {};
  5129. oimo.collision.narrowphase.detector._BoxBoxDetector.IncidentVertex = class oimo_collision_narrowphase_detector__$BoxBoxDetector_IncidentVertex {
  5130. constructor() {
  5131. this.x = 0;
  5132. this.y = 0;
  5133. this.wx = 0;
  5134. this.wy = 0;
  5135. this.wz = 0;
  5136. }
  5137. }
  5138. oimo.collision.narrowphase.detector._BoxBoxDetector.FaceClipper = class oimo_collision_narrowphase_detector__$BoxBoxDetector_FaceClipper {
  5139. constructor() {
  5140. this.w = 0;
  5141. this.h = 0;
  5142. this.numVertices = 0;
  5143. this.numTmpVertices = 0;
  5144. this.vertices = new Array(8);
  5145. this.tmpVertices = new Array(8);
  5146. this.vertices[0] = new oimo.collision.narrowphase.detector._BoxBoxDetector.IncidentVertex();
  5147. this.tmpVertices[0] = new oimo.collision.narrowphase.detector._BoxBoxDetector.IncidentVertex();
  5148. this.vertices[1] = new oimo.collision.narrowphase.detector._BoxBoxDetector.IncidentVertex();
  5149. this.tmpVertices[1] = new oimo.collision.narrowphase.detector._BoxBoxDetector.IncidentVertex();
  5150. this.vertices[2] = new oimo.collision.narrowphase.detector._BoxBoxDetector.IncidentVertex();
  5151. this.tmpVertices[2] = new oimo.collision.narrowphase.detector._BoxBoxDetector.IncidentVertex();
  5152. this.vertices[3] = new oimo.collision.narrowphase.detector._BoxBoxDetector.IncidentVertex();
  5153. this.tmpVertices[3] = new oimo.collision.narrowphase.detector._BoxBoxDetector.IncidentVertex();
  5154. this.vertices[4] = new oimo.collision.narrowphase.detector._BoxBoxDetector.IncidentVertex();
  5155. this.tmpVertices[4] = new oimo.collision.narrowphase.detector._BoxBoxDetector.IncidentVertex();
  5156. this.vertices[5] = new oimo.collision.narrowphase.detector._BoxBoxDetector.IncidentVertex();
  5157. this.tmpVertices[5] = new oimo.collision.narrowphase.detector._BoxBoxDetector.IncidentVertex();
  5158. this.vertices[6] = new oimo.collision.narrowphase.detector._BoxBoxDetector.IncidentVertex();
  5159. this.tmpVertices[6] = new oimo.collision.narrowphase.detector._BoxBoxDetector.IncidentVertex();
  5160. this.vertices[7] = new oimo.collision.narrowphase.detector._BoxBoxDetector.IncidentVertex();
  5161. this.tmpVertices[7] = new oimo.collision.narrowphase.detector._BoxBoxDetector.IncidentVertex();
  5162. }
  5163. clip() {
  5164. let _g = 0;
  5165. let _g1 = this.numVertices;
  5166. while(_g < _g1) {
  5167. let i = _g++;
  5168. let v1 = this.vertices[i];
  5169. let v2 = this.vertices[(i + 1) % this.numVertices];
  5170. let s1 = this.w + v1.x;
  5171. let s2 = this.w + v2.x;
  5172. if(s1 > 0 && s2 > 0) {
  5173. let _this = this.tmpVertices[this.numTmpVertices++];
  5174. _this.x = v1.x;
  5175. _this.y = v1.y;
  5176. _this.wx = v1.wx;
  5177. _this.wy = v1.wy;
  5178. _this.wz = v1.wz;
  5179. } else if(s1 > 0 && s2 <= 0) {
  5180. let _this = this.tmpVertices[this.numTmpVertices++];
  5181. _this.x = v1.x;
  5182. _this.y = v1.y;
  5183. _this.wx = v1.wx;
  5184. _this.wy = v1.wy;
  5185. _this.wz = v1.wz;
  5186. let t = s1 / (s1 - s2);
  5187. let _this1 = this.tmpVertices[this.numTmpVertices++];
  5188. _this1.x = v1.x + (v2.x - v1.x) * t;
  5189. _this1.y = v1.y + (v2.y - v1.y) * t;
  5190. _this1.wx = v1.wx + (v2.wx - v1.wx) * t;
  5191. _this1.wy = v1.wy + (v2.wy - v1.wy) * t;
  5192. _this1.wz = v1.wz + (v2.wz - v1.wz) * t;
  5193. } else if(s1 <= 0 && s2 > 0) {
  5194. let t = s1 / (s1 - s2);
  5195. let _this = this.tmpVertices[this.numTmpVertices++];
  5196. _this.x = v1.x + (v2.x - v1.x) * t;
  5197. _this.y = v1.y + (v2.y - v1.y) * t;
  5198. _this.wx = v1.wx + (v2.wx - v1.wx) * t;
  5199. _this.wy = v1.wy + (v2.wy - v1.wy) * t;
  5200. _this.wz = v1.wz + (v2.wz - v1.wz) * t;
  5201. }
  5202. }
  5203. let tmp = this.vertices;
  5204. this.vertices = this.tmpVertices;
  5205. this.tmpVertices = tmp;
  5206. this.numVertices = this.numTmpVertices;
  5207. this.numTmpVertices = 0;
  5208. let _g2 = 0;
  5209. let _g3 = this.numVertices;
  5210. while(_g2 < _g3) {
  5211. let i = _g2++;
  5212. let v1 = this.vertices[i];
  5213. let v2 = this.vertices[(i + 1) % this.numVertices];
  5214. let s1 = this.w - v1.x;
  5215. let s2 = this.w - v2.x;
  5216. if(s1 > 0 && s2 > 0) {
  5217. let _this = this.tmpVertices[this.numTmpVertices++];
  5218. _this.x = v1.x;
  5219. _this.y = v1.y;
  5220. _this.wx = v1.wx;
  5221. _this.wy = v1.wy;
  5222. _this.wz = v1.wz;
  5223. } else if(s1 > 0 && s2 <= 0) {
  5224. let _this = this.tmpVertices[this.numTmpVertices++];
  5225. _this.x = v1.x;
  5226. _this.y = v1.y;
  5227. _this.wx = v1.wx;
  5228. _this.wy = v1.wy;
  5229. _this.wz = v1.wz;
  5230. let t = s1 / (s1 - s2);
  5231. let _this1 = this.tmpVertices[this.numTmpVertices++];
  5232. _this1.x = v1.x + (v2.x - v1.x) * t;
  5233. _this1.y = v1.y + (v2.y - v1.y) * t;
  5234. _this1.wx = v1.wx + (v2.wx - v1.wx) * t;
  5235. _this1.wy = v1.wy + (v2.wy - v1.wy) * t;
  5236. _this1.wz = v1.wz + (v2.wz - v1.wz) * t;
  5237. } else if(s1 <= 0 && s2 > 0) {
  5238. let t = s1 / (s1 - s2);
  5239. let _this = this.tmpVertices[this.numTmpVertices++];
  5240. _this.x = v1.x + (v2.x - v1.x) * t;
  5241. _this.y = v1.y + (v2.y - v1.y) * t;
  5242. _this.wx = v1.wx + (v2.wx - v1.wx) * t;
  5243. _this.wy = v1.wy + (v2.wy - v1.wy) * t;
  5244. _this.wz = v1.wz + (v2.wz - v1.wz) * t;
  5245. }
  5246. }
  5247. let tmp1 = this.vertices;
  5248. this.vertices = this.tmpVertices;
  5249. this.tmpVertices = tmp1;
  5250. this.numVertices = this.numTmpVertices;
  5251. this.numTmpVertices = 0;
  5252. let _g4 = 0;
  5253. let _g5 = this.numVertices;
  5254. while(_g4 < _g5) {
  5255. let i = _g4++;
  5256. let v1 = this.vertices[i];
  5257. let v2 = this.vertices[(i + 1) % this.numVertices];
  5258. let s1 = this.h + v1.y;
  5259. let s2 = this.h + v2.y;
  5260. if(s1 > 0 && s2 > 0) {
  5261. let _this = this.tmpVertices[this.numTmpVertices++];
  5262. _this.x = v1.x;
  5263. _this.y = v1.y;
  5264. _this.wx = v1.wx;
  5265. _this.wy = v1.wy;
  5266. _this.wz = v1.wz;
  5267. } else if(s1 > 0 && s2 <= 0) {
  5268. let _this = this.tmpVertices[this.numTmpVertices++];
  5269. _this.x = v1.x;
  5270. _this.y = v1.y;
  5271. _this.wx = v1.wx;
  5272. _this.wy = v1.wy;
  5273. _this.wz = v1.wz;
  5274. let t = s1 / (s1 - s2);
  5275. let _this1 = this.tmpVertices[this.numTmpVertices++];
  5276. _this1.x = v1.x + (v2.x - v1.x) * t;
  5277. _this1.y = v1.y + (v2.y - v1.y) * t;
  5278. _this1.wx = v1.wx + (v2.wx - v1.wx) * t;
  5279. _this1.wy = v1.wy + (v2.wy - v1.wy) * t;
  5280. _this1.wz = v1.wz + (v2.wz - v1.wz) * t;
  5281. } else if(s1 <= 0 && s2 > 0) {
  5282. let t = s1 / (s1 - s2);
  5283. let _this = this.tmpVertices[this.numTmpVertices++];
  5284. _this.x = v1.x + (v2.x - v1.x) * t;
  5285. _this.y = v1.y + (v2.y - v1.y) * t;
  5286. _this.wx = v1.wx + (v2.wx - v1.wx) * t;
  5287. _this.wy = v1.wy + (v2.wy - v1.wy) * t;
  5288. _this.wz = v1.wz + (v2.wz - v1.wz) * t;
  5289. }
  5290. }
  5291. let tmp2 = this.vertices;
  5292. this.vertices = this.tmpVertices;
  5293. this.tmpVertices = tmp2;
  5294. this.numVertices = this.numTmpVertices;
  5295. this.numTmpVertices = 0;
  5296. let _g6 = 0;
  5297. let _g7 = this.numVertices;
  5298. while(_g6 < _g7) {
  5299. let i = _g6++;
  5300. let v1 = this.vertices[i];
  5301. let v2 = this.vertices[(i + 1) % this.numVertices];
  5302. let s1 = this.h - v1.y;
  5303. let s2 = this.h - v2.y;
  5304. if(s1 > 0 && s2 > 0) {
  5305. let _this = this.tmpVertices[this.numTmpVertices++];
  5306. _this.x = v1.x;
  5307. _this.y = v1.y;
  5308. _this.wx = v1.wx;
  5309. _this.wy = v1.wy;
  5310. _this.wz = v1.wz;
  5311. } else if(s1 > 0 && s2 <= 0) {
  5312. let _this = this.tmpVertices[this.numTmpVertices++];
  5313. _this.x = v1.x;
  5314. _this.y = v1.y;
  5315. _this.wx = v1.wx;
  5316. _this.wy = v1.wy;
  5317. _this.wz = v1.wz;
  5318. let t = s1 / (s1 - s2);
  5319. let _this1 = this.tmpVertices[this.numTmpVertices++];
  5320. _this1.x = v1.x + (v2.x - v1.x) * t;
  5321. _this1.y = v1.y + (v2.y - v1.y) * t;
  5322. _this1.wx = v1.wx + (v2.wx - v1.wx) * t;
  5323. _this1.wy = v1.wy + (v2.wy - v1.wy) * t;
  5324. _this1.wz = v1.wz + (v2.wz - v1.wz) * t;
  5325. } else if(s1 <= 0 && s2 > 0) {
  5326. let t = s1 / (s1 - s2);
  5327. let _this = this.tmpVertices[this.numTmpVertices++];
  5328. _this.x = v1.x + (v2.x - v1.x) * t;
  5329. _this.y = v1.y + (v2.y - v1.y) * t;
  5330. _this.wx = v1.wx + (v2.wx - v1.wx) * t;
  5331. _this.wy = v1.wy + (v2.wy - v1.wy) * t;
  5332. _this.wz = v1.wz + (v2.wz - v1.wz) * t;
  5333. }
  5334. }
  5335. let tmp3 = this.vertices;
  5336. this.vertices = this.tmpVertices;
  5337. this.tmpVertices = tmp3;
  5338. this.numVertices = this.numTmpVertices;
  5339. this.numTmpVertices = 0;
  5340. }
  5341. reduce() {
  5342. if(this.numVertices < 4) {
  5343. return;
  5344. }
  5345. let max1 = -1e65536;
  5346. let min1 = 1e65536;
  5347. let max2 = -1e65536;
  5348. let min2 = 1e65536;
  5349. let max1V = null;
  5350. let min1V = null;
  5351. let max2V = null;
  5352. let min2V = null;
  5353. let e1x = 1;
  5354. let e1y = 1;
  5355. let e2x = -1;
  5356. let e2y = 1;
  5357. let _g = 0;
  5358. let _g1 = this.numVertices;
  5359. while(_g < _g1) {
  5360. let v = this.vertices[_g++];
  5361. let dot1 = v.x * e1x + v.y * e1y;
  5362. let dot2 = v.x * e2x + v.y * e2y;
  5363. if(dot1 > max1) {
  5364. max1 = dot1;
  5365. max1V = v;
  5366. }
  5367. if(dot1 < min1) {
  5368. min1 = dot1;
  5369. min1V = v;
  5370. }
  5371. if(dot2 > max2) {
  5372. max2 = dot2;
  5373. max2V = v;
  5374. }
  5375. if(dot2 < min2) {
  5376. min2 = dot2;
  5377. min2V = v;
  5378. }
  5379. }
  5380. let _this = this.tmpVertices[this.numTmpVertices++];
  5381. _this.x = max1V.x;
  5382. _this.y = max1V.y;
  5383. _this.wx = max1V.wx;
  5384. _this.wy = max1V.wy;
  5385. _this.wz = max1V.wz;
  5386. let _this1 = this.tmpVertices[this.numTmpVertices++];
  5387. _this1.x = max2V.x;
  5388. _this1.y = max2V.y;
  5389. _this1.wx = max2V.wx;
  5390. _this1.wy = max2V.wy;
  5391. _this1.wz = max2V.wz;
  5392. let _this2 = this.tmpVertices[this.numTmpVertices++];
  5393. _this2.x = min1V.x;
  5394. _this2.y = min1V.y;
  5395. _this2.wx = min1V.wx;
  5396. _this2.wy = min1V.wy;
  5397. _this2.wz = min1V.wz;
  5398. let _this3 = this.tmpVertices[this.numTmpVertices++];
  5399. _this3.x = min2V.x;
  5400. _this3.y = min2V.y;
  5401. _this3.wx = min2V.wx;
  5402. _this3.wy = min2V.wy;
  5403. _this3.wz = min2V.wz;
  5404. let tmp = this.vertices;
  5405. this.vertices = this.tmpVertices;
  5406. this.tmpVertices = tmp;
  5407. this.numVertices = this.numTmpVertices;
  5408. this.numTmpVertices = 0;
  5409. }
  5410. }
  5411. oimo.collision.narrowphase.detector.BoxBoxDetectorMacro = class oimo_collision_narrowphase_detector_BoxBoxDetectorMacro {
  5412. }
  5413. oimo.collision.narrowphase.detector.CachedDetectorData = class oimo_collision_narrowphase_detector_CachedDetectorData {
  5414. constructor() {
  5415. }
  5416. _clear() {
  5417. if(this._gjkCache != null) {
  5418. this._gjkCache.clear();
  5419. }
  5420. }
  5421. }
  5422. oimo.collision.narrowphase.detector.CapsuleCapsuleDetector = class oimo_collision_narrowphase_detector_CapsuleCapsuleDetector extends oimo.collision.narrowphase.detector.Detector {
  5423. constructor() {
  5424. super(false);
  5425. }
  5426. detectImpl(result,geom1,geom2,tf1,tf2,cachedData) {
  5427. let c1 = geom1;
  5428. let c2 = geom2;
  5429. result.incremental = false;
  5430. let axis1X;
  5431. let axis1Y;
  5432. let axis1Z;
  5433. let axis2X;
  5434. let axis2Y;
  5435. let axis2Z;
  5436. axis1X = tf1._rotation01;
  5437. axis1Y = tf1._rotation11;
  5438. axis1Z = tf1._rotation21;
  5439. axis2X = tf2._rotation01;
  5440. axis2Y = tf2._rotation11;
  5441. axis2Z = tf2._rotation21;
  5442. let hh1 = c1._halfHeight;
  5443. let hh2 = c2._halfHeight;
  5444. let r1 = c1._radius;
  5445. let r2 = c2._radius;
  5446. let p1X;
  5447. let p1Y;
  5448. let p1Z;
  5449. let q1X;
  5450. let q1Y;
  5451. let q1Z;
  5452. let p2X;
  5453. let p2Y;
  5454. let p2Z;
  5455. let q2X;
  5456. let q2Y;
  5457. let q2Z;
  5458. p1X = tf1._positionX + axis1X * -hh1;
  5459. p1Y = tf1._positionY + axis1Y * -hh1;
  5460. p1Z = tf1._positionZ + axis1Z * -hh1;
  5461. q1X = tf1._positionX + axis1X * hh1;
  5462. q1Y = tf1._positionY + axis1Y * hh1;
  5463. q1Z = tf1._positionZ + axis1Z * hh1;
  5464. p2X = tf2._positionX + axis2X * -hh2;
  5465. p2Y = tf2._positionY + axis2Y * -hh2;
  5466. p2Z = tf2._positionZ + axis2Z * -hh2;
  5467. q2X = tf2._positionX + axis2X * hh2;
  5468. q2Y = tf2._positionY + axis2Y * hh2;
  5469. q2Z = tf2._positionZ + axis2Z * hh2;
  5470. let p12X;
  5471. let p12Y;
  5472. let p12Z;
  5473. p12X = p1X - p2X;
  5474. p12Y = p1Y - p2Y;
  5475. p12Z = p1Z - p2Z;
  5476. let d1X;
  5477. let d1Y;
  5478. let d1Z;
  5479. let d2X;
  5480. let d2Y;
  5481. let d2Z;
  5482. d1X = q1X - p1X;
  5483. d1Y = q1Y - p1Y;
  5484. d1Z = q1Z - p1Z;
  5485. d2X = q2X - p2X;
  5486. d2Y = q2Y - p2Y;
  5487. d2Z = q2Z - p2Z;
  5488. let p21d1 = -(p12X * d1X + p12Y * d1Y + p12Z * d1Z);
  5489. let p12d2 = p12X * d2X + p12Y * d2Y + p12Z * d2Z;
  5490. let d11 = hh1 * hh1 * 4;
  5491. let d12 = d1X * d2X + d1Y * d2Y + d1Z * d2Z;
  5492. let d22 = hh2 * hh2 * 4;
  5493. let t1;
  5494. let t2;
  5495. if(d11 == 0 && d22 == 0) {
  5496. t1 = 0;
  5497. t2 = 0;
  5498. } else if(d11 == 0) {
  5499. t1 = 0;
  5500. if(p12d2 < 0) {
  5501. t2 = 0;
  5502. } else if(p12d2 > d22) {
  5503. t2 = 1;
  5504. } else {
  5505. t2 = p12d2 / d22;
  5506. }
  5507. } else if(d22 == 0) {
  5508. t2 = 0;
  5509. if(p21d1 < 0) {
  5510. t1 = 0;
  5511. } else if(p21d1 > d11) {
  5512. t1 = 1;
  5513. } else {
  5514. t1 = p21d1 / d11;
  5515. }
  5516. } else {
  5517. let det = d11 * d22 - d12 * d12;
  5518. if(det == 0) {
  5519. t1 = 0;
  5520. } else {
  5521. t1 = d12 * p12d2 + d22 * p21d1;
  5522. if(t1 < 0) {
  5523. t1 = 0;
  5524. } else if(t1 > det) {
  5525. t1 = 1;
  5526. } else {
  5527. t1 /= det;
  5528. }
  5529. }
  5530. t2 = t1 * d12 + p12d2;
  5531. if(t2 < 0) {
  5532. t2 = 0;
  5533. if(p21d1 < 0) {
  5534. t1 = 0;
  5535. } else if(p21d1 > d11) {
  5536. t1 = 1;
  5537. } else {
  5538. t1 = p21d1 / d11;
  5539. }
  5540. } else if(t2 > d22) {
  5541. t2 = 1;
  5542. t1 = d12 + p21d1;
  5543. if(t1 < 0) {
  5544. t1 = 0;
  5545. } else if(t1 > d11) {
  5546. t1 = 1;
  5547. } else {
  5548. t1 /= d11;
  5549. }
  5550. } else {
  5551. t2 /= d22;
  5552. }
  5553. }
  5554. let cp1X;
  5555. let cp1Y;
  5556. let cp1Z;
  5557. let cp2X;
  5558. let cp2Y;
  5559. let cp2Z;
  5560. cp1X = p1X + d1X * t1;
  5561. cp1Y = p1Y + d1Y * t1;
  5562. cp1Z = p1Z + d1Z * t1;
  5563. cp2X = p2X + d2X * t2;
  5564. cp2Y = p2Y + d2Y * t2;
  5565. cp2Z = p2Z + d2Z * t2;
  5566. let dX;
  5567. let dY;
  5568. let dZ;
  5569. dX = cp1X - cp2X;
  5570. dY = cp1Y - cp2Y;
  5571. dZ = cp1Z - cp2Z;
  5572. let len2 = dX * dX + dY * dY + dZ * dZ;
  5573. if(len2 >= (r1 + r2) * (r1 + r2)) {
  5574. return;
  5575. }
  5576. let len = Math.sqrt(len2);
  5577. let nX;
  5578. let nY;
  5579. let nZ;
  5580. if(len > 0) {
  5581. nX = dX * (1 / len);
  5582. nY = dY * (1 / len);
  5583. nZ = dZ * (1 / len);
  5584. } else {
  5585. nX = 1;
  5586. nY = 0;
  5587. nZ = 0;
  5588. }
  5589. this.setNormal(result,nX,nY,nZ);
  5590. let pos1X;
  5591. let pos1Y;
  5592. let pos1Z;
  5593. let pos2X;
  5594. let pos2Y;
  5595. let pos2Z;
  5596. pos1X = cp1X + nX * -r1;
  5597. pos1Y = cp1Y + nY * -r1;
  5598. pos1Z = cp1Z + nZ * -r1;
  5599. pos2X = cp2X + nX * r2;
  5600. pos2Y = cp2Y + nY * r2;
  5601. pos2Z = cp2Z + nZ * r2;
  5602. this.addPoint(result,pos1X,pos1Y,pos1Z,pos2X,pos2Y,pos2Z,r1 + r2 - len,0);
  5603. }
  5604. }
  5605. oimo.collision.narrowphase.detector.GjkEpaDetector = class oimo_collision_narrowphase_detector_GjkEpaDetector extends oimo.collision.narrowphase.detector.Detector {
  5606. constructor() {
  5607. super(false);
  5608. }
  5609. detectImpl(result,geom1,geom2,tf1,tf2,cachedData) {
  5610. let gjkEpa = oimo.collision.narrowphase.detector.gjkepa.GjkEpa.instance;
  5611. let g1 = geom1;
  5612. let g2 = geom2;
  5613. let status = gjkEpa.computeClosestPointsImpl(g1,g2,tf1,tf2,oimo.common.Setting.enableGJKCaching ? cachedData : null,true);
  5614. result.incremental = true;
  5615. if(status != oimo.collision.narrowphase.detector.gjkepa.GjkEpaResultState.SUCCEEDED) {
  5616. console.log("src/oimo/collision/narrowphase/detector/GjkEpaDetector.hx:28:","GJK/EPA failed: status=" + status);
  5617. return;
  5618. }
  5619. if(gjkEpa.distance > g1._gjkMargin + g2._gjkMargin) {
  5620. return;
  5621. }
  5622. let pos1X;
  5623. let pos1Y;
  5624. let pos1Z;
  5625. let pos2X;
  5626. let pos2Y;
  5627. let pos2Z;
  5628. let v = gjkEpa.closestPoint1;
  5629. pos1X = v.x;
  5630. pos1Y = v.y;
  5631. pos1Z = v.z;
  5632. let v1 = gjkEpa.closestPoint2;
  5633. pos2X = v1.x;
  5634. pos2Y = v1.y;
  5635. pos2Z = v1.z;
  5636. let normalX;
  5637. let normalY;
  5638. let normalZ;
  5639. normalX = pos1X - pos2X;
  5640. normalY = pos1Y - pos2Y;
  5641. normalZ = pos1Z - pos2Z;
  5642. if(normalX * normalX + normalY * normalY + normalZ * normalZ == 0) {
  5643. return;
  5644. }
  5645. if(gjkEpa.distance < 0) {
  5646. normalX = -normalX;
  5647. normalY = -normalY;
  5648. normalZ = -normalZ;
  5649. }
  5650. let l = normalX * normalX + normalY * normalY + normalZ * normalZ;
  5651. if(l > 0) {
  5652. l = 1 / Math.sqrt(l);
  5653. }
  5654. normalX *= l;
  5655. normalY *= l;
  5656. normalZ *= l;
  5657. this.setNormal(result,normalX,normalY,normalZ);
  5658. pos1X += normalX * -g1._gjkMargin;
  5659. pos1Y += normalY * -g1._gjkMargin;
  5660. pos1Z += normalZ * -g1._gjkMargin;
  5661. pos2X += normalX * g2._gjkMargin;
  5662. pos2Y += normalY * g2._gjkMargin;
  5663. pos2Z += normalZ * g2._gjkMargin;
  5664. this.addPoint(result,pos1X,pos1Y,pos1Z,pos2X,pos2Y,pos2Z,g1._gjkMargin + g2._gjkMargin - gjkEpa.distance,0);
  5665. }
  5666. }
  5667. oimo.collision.narrowphase.detector.SphereBoxDetector = class oimo_collision_narrowphase_detector_SphereBoxDetector extends oimo.collision.narrowphase.detector.Detector {
  5668. constructor(swapped) {
  5669. super(swapped);
  5670. }
  5671. detectImpl(result,geom1,geom2,tf1,tf2,cachedData) {
  5672. let b = geom2;
  5673. result.incremental = false;
  5674. let halfExtX;
  5675. let halfExtY;
  5676. let halfExtZ;
  5677. let negHalfExtX;
  5678. let negHalfExtY;
  5679. let negHalfExtZ;
  5680. halfExtX = b._halfExtentsX;
  5681. halfExtY = b._halfExtentsY;
  5682. halfExtZ = b._halfExtentsZ;
  5683. negHalfExtX = -halfExtX;
  5684. negHalfExtY = -halfExtY;
  5685. negHalfExtZ = -halfExtZ;
  5686. let r = geom1._radius;
  5687. let boxToSphereX;
  5688. let boxToSphereY;
  5689. let boxToSphereZ;
  5690. boxToSphereX = tf1._positionX - tf2._positionX;
  5691. boxToSphereY = tf1._positionY - tf2._positionY;
  5692. boxToSphereZ = tf1._positionZ - tf2._positionZ;
  5693. let boxToSphereInBoxX;
  5694. let boxToSphereInBoxY;
  5695. let boxToSphereInBoxZ;
  5696. let __tmp__X;
  5697. let __tmp__Y;
  5698. let __tmp__Z;
  5699. __tmp__X = tf2._rotation00 * boxToSphereX + tf2._rotation10 * boxToSphereY + tf2._rotation20 * boxToSphereZ;
  5700. __tmp__Y = tf2._rotation01 * boxToSphereX + tf2._rotation11 * boxToSphereY + tf2._rotation21 * boxToSphereZ;
  5701. __tmp__Z = tf2._rotation02 * boxToSphereX + tf2._rotation12 * boxToSphereY + tf2._rotation22 * boxToSphereZ;
  5702. boxToSphereInBoxX = __tmp__X;
  5703. boxToSphereInBoxY = __tmp__Y;
  5704. boxToSphereInBoxZ = __tmp__Z;
  5705. if(negHalfExtX < boxToSphereInBoxX && halfExtX > boxToSphereInBoxX && negHalfExtY < boxToSphereInBoxY && halfExtY > boxToSphereInBoxY && negHalfExtZ < boxToSphereInBoxZ && halfExtZ > boxToSphereInBoxZ) {
  5706. let sphereToBoxSurfaceX;
  5707. let sphereToBoxSurfaceY;
  5708. let sphereToBoxSurfaceZ;
  5709. sphereToBoxSurfaceX = boxToSphereInBoxX < 0 ? -boxToSphereInBoxX : boxToSphereInBoxX;
  5710. sphereToBoxSurfaceY = boxToSphereInBoxY < 0 ? -boxToSphereInBoxY : boxToSphereInBoxY;
  5711. sphereToBoxSurfaceZ = boxToSphereInBoxZ < 0 ? -boxToSphereInBoxZ : boxToSphereInBoxZ;
  5712. sphereToBoxSurfaceX = halfExtX - sphereToBoxSurfaceX;
  5713. sphereToBoxSurfaceY = halfExtY - sphereToBoxSurfaceY;
  5714. sphereToBoxSurfaceZ = halfExtZ - sphereToBoxSurfaceZ;
  5715. let normalInBoxX;
  5716. let normalInBoxY;
  5717. let normalInBoxZ;
  5718. let distX = sphereToBoxSurfaceX;
  5719. let distY = sphereToBoxSurfaceY;
  5720. let distZ = sphereToBoxSurfaceZ;
  5721. let depth;
  5722. let projectionMaskX;
  5723. let projectionMaskY;
  5724. let projectionMaskZ;
  5725. if(distX < distY) {
  5726. if(distX < distZ) {
  5727. if(boxToSphereInBoxX > 0) {
  5728. normalInBoxX = 1;
  5729. normalInBoxY = 0;
  5730. normalInBoxZ = 0;
  5731. } else {
  5732. normalInBoxX = -1;
  5733. normalInBoxY = 0;
  5734. normalInBoxZ = 0;
  5735. }
  5736. projectionMaskX = 0;
  5737. projectionMaskY = 1;
  5738. projectionMaskZ = 1;
  5739. depth = distX;
  5740. } else {
  5741. if(boxToSphereInBoxZ > 0) {
  5742. normalInBoxX = 0;
  5743. normalInBoxY = 0;
  5744. normalInBoxZ = 1;
  5745. } else {
  5746. normalInBoxX = 0;
  5747. normalInBoxY = 0;
  5748. normalInBoxZ = -1;
  5749. }
  5750. projectionMaskX = 1;
  5751. projectionMaskY = 1;
  5752. projectionMaskZ = 0;
  5753. depth = distZ;
  5754. }
  5755. } else if(distY < distZ) {
  5756. if(boxToSphereInBoxY > 0) {
  5757. normalInBoxX = 0;
  5758. normalInBoxY = 1;
  5759. normalInBoxZ = 0;
  5760. } else {
  5761. normalInBoxX = 0;
  5762. normalInBoxY = -1;
  5763. normalInBoxZ = 0;
  5764. }
  5765. projectionMaskX = 1;
  5766. projectionMaskY = 0;
  5767. projectionMaskZ = 1;
  5768. depth = distY;
  5769. } else {
  5770. if(boxToSphereInBoxZ > 0) {
  5771. normalInBoxX = 0;
  5772. normalInBoxY = 0;
  5773. normalInBoxZ = 1;
  5774. } else {
  5775. normalInBoxX = 0;
  5776. normalInBoxY = 0;
  5777. normalInBoxZ = -1;
  5778. }
  5779. projectionMaskX = 1;
  5780. projectionMaskY = 1;
  5781. projectionMaskZ = 0;
  5782. depth = distZ;
  5783. }
  5784. let baseX;
  5785. let baseY;
  5786. let baseZ;
  5787. baseX = projectionMaskX * boxToSphereInBoxX;
  5788. baseY = projectionMaskY * boxToSphereInBoxY;
  5789. baseZ = projectionMaskZ * boxToSphereInBoxZ;
  5790. let boxToClosestPointInBoxX;
  5791. let boxToClosestPointInBoxY;
  5792. let boxToClosestPointInBoxZ;
  5793. boxToClosestPointInBoxX = normalInBoxX * halfExtX;
  5794. boxToClosestPointInBoxY = normalInBoxY * halfExtY;
  5795. boxToClosestPointInBoxZ = normalInBoxZ * halfExtZ;
  5796. boxToClosestPointInBoxX += baseX;
  5797. boxToClosestPointInBoxY += baseY;
  5798. boxToClosestPointInBoxZ += baseZ;
  5799. let boxToClosestPointX;
  5800. let boxToClosestPointY;
  5801. let boxToClosestPointZ;
  5802. let normalX;
  5803. let normalY;
  5804. let normalZ;
  5805. let __tmp__X;
  5806. let __tmp__Y;
  5807. let __tmp__Z;
  5808. __tmp__X = tf2._rotation00 * boxToClosestPointInBoxX + tf2._rotation01 * boxToClosestPointInBoxY + tf2._rotation02 * boxToClosestPointInBoxZ;
  5809. __tmp__Y = tf2._rotation10 * boxToClosestPointInBoxX + tf2._rotation11 * boxToClosestPointInBoxY + tf2._rotation12 * boxToClosestPointInBoxZ;
  5810. __tmp__Z = tf2._rotation20 * boxToClosestPointInBoxX + tf2._rotation21 * boxToClosestPointInBoxY + tf2._rotation22 * boxToClosestPointInBoxZ;
  5811. boxToClosestPointX = __tmp__X;
  5812. boxToClosestPointY = __tmp__Y;
  5813. boxToClosestPointZ = __tmp__Z;
  5814. let __tmp__X1;
  5815. let __tmp__Y1;
  5816. let __tmp__Z1;
  5817. __tmp__X1 = tf2._rotation00 * normalInBoxX + tf2._rotation01 * normalInBoxY + tf2._rotation02 * normalInBoxZ;
  5818. __tmp__Y1 = tf2._rotation10 * normalInBoxX + tf2._rotation11 * normalInBoxY + tf2._rotation12 * normalInBoxZ;
  5819. __tmp__Z1 = tf2._rotation20 * normalInBoxX + tf2._rotation21 * normalInBoxY + tf2._rotation22 * normalInBoxZ;
  5820. normalX = __tmp__X1;
  5821. normalY = __tmp__Y1;
  5822. normalZ = __tmp__Z1;
  5823. this.setNormal(result,normalX,normalY,normalZ);
  5824. let pos1X;
  5825. let pos1Y;
  5826. let pos1Z;
  5827. let pos2X;
  5828. let pos2Y;
  5829. let pos2Z;
  5830. pos1X = tf1._positionX + normalX * -r;
  5831. pos1Y = tf1._positionY + normalY * -r;
  5832. pos1Z = tf1._positionZ + normalZ * -r;
  5833. pos2X = tf2._positionX + boxToClosestPointX;
  5834. pos2Y = tf2._positionY + boxToClosestPointY;
  5835. pos2Z = tf2._positionZ + boxToClosestPointZ;
  5836. this.addPoint(result,pos1X,pos1Y,pos1Z,pos2X,pos2Y,pos2Z,depth,0);
  5837. return;
  5838. }
  5839. let boxToClosestPointInBoxX;
  5840. let boxToClosestPointInBoxY;
  5841. let boxToClosestPointInBoxZ;
  5842. halfExtX -= 1e-9;
  5843. halfExtY -= 1e-9;
  5844. halfExtZ -= 1e-9;
  5845. negHalfExtX += 1e-9;
  5846. negHalfExtY += 1e-9;
  5847. negHalfExtZ += 1e-9;
  5848. boxToClosestPointInBoxX = boxToSphereInBoxX < halfExtX ? boxToSphereInBoxX : halfExtX;
  5849. boxToClosestPointInBoxY = boxToSphereInBoxY < halfExtY ? boxToSphereInBoxY : halfExtY;
  5850. boxToClosestPointInBoxZ = boxToSphereInBoxZ < halfExtZ ? boxToSphereInBoxZ : halfExtZ;
  5851. if(!(boxToClosestPointInBoxX > negHalfExtX)) {
  5852. boxToClosestPointInBoxX = negHalfExtX;
  5853. }
  5854. if(!(boxToClosestPointInBoxY > negHalfExtY)) {
  5855. boxToClosestPointInBoxY = negHalfExtY;
  5856. }
  5857. if(!(boxToClosestPointInBoxZ > negHalfExtZ)) {
  5858. boxToClosestPointInBoxZ = negHalfExtZ;
  5859. }
  5860. let closestPointToSphereInBoxX;
  5861. let closestPointToSphereInBoxY;
  5862. let closestPointToSphereInBoxZ;
  5863. closestPointToSphereInBoxX = boxToSphereInBoxX - boxToClosestPointInBoxX;
  5864. closestPointToSphereInBoxY = boxToSphereInBoxY - boxToClosestPointInBoxY;
  5865. closestPointToSphereInBoxZ = boxToSphereInBoxZ - boxToClosestPointInBoxZ;
  5866. let dist = closestPointToSphereInBoxX * closestPointToSphereInBoxX + closestPointToSphereInBoxY * closestPointToSphereInBoxY + closestPointToSphereInBoxZ * closestPointToSphereInBoxZ;
  5867. if(dist >= r * r) {
  5868. return;
  5869. }
  5870. dist = Math.sqrt(dist);
  5871. let boxToClosestPointX;
  5872. let boxToClosestPointY;
  5873. let boxToClosestPointZ;
  5874. let closestPointToSphereX;
  5875. let closestPointToSphereY;
  5876. let closestPointToSphereZ;
  5877. let __tmp__X1;
  5878. let __tmp__Y1;
  5879. let __tmp__Z1;
  5880. __tmp__X1 = tf2._rotation00 * boxToClosestPointInBoxX + tf2._rotation01 * boxToClosestPointInBoxY + tf2._rotation02 * boxToClosestPointInBoxZ;
  5881. __tmp__Y1 = tf2._rotation10 * boxToClosestPointInBoxX + tf2._rotation11 * boxToClosestPointInBoxY + tf2._rotation12 * boxToClosestPointInBoxZ;
  5882. __tmp__Z1 = tf2._rotation20 * boxToClosestPointInBoxX + tf2._rotation21 * boxToClosestPointInBoxY + tf2._rotation22 * boxToClosestPointInBoxZ;
  5883. boxToClosestPointX = __tmp__X1;
  5884. boxToClosestPointY = __tmp__Y1;
  5885. boxToClosestPointZ = __tmp__Z1;
  5886. let __tmp__X2;
  5887. let __tmp__Y2;
  5888. let __tmp__Z2;
  5889. __tmp__X2 = tf2._rotation00 * closestPointToSphereInBoxX + tf2._rotation01 * closestPointToSphereInBoxY + tf2._rotation02 * closestPointToSphereInBoxZ;
  5890. __tmp__Y2 = tf2._rotation10 * closestPointToSphereInBoxX + tf2._rotation11 * closestPointToSphereInBoxY + tf2._rotation12 * closestPointToSphereInBoxZ;
  5891. __tmp__Z2 = tf2._rotation20 * closestPointToSphereInBoxX + tf2._rotation21 * closestPointToSphereInBoxY + tf2._rotation22 * closestPointToSphereInBoxZ;
  5892. closestPointToSphereX = __tmp__X2;
  5893. closestPointToSphereY = __tmp__Y2;
  5894. closestPointToSphereZ = __tmp__Z2;
  5895. let normalX;
  5896. let normalY;
  5897. let normalZ;
  5898. let l = closestPointToSphereX * closestPointToSphereX + closestPointToSphereY * closestPointToSphereY + closestPointToSphereZ * closestPointToSphereZ;
  5899. if(l > 0) {
  5900. l = 1 / Math.sqrt(l);
  5901. }
  5902. normalX = closestPointToSphereX * l;
  5903. normalY = closestPointToSphereY * l;
  5904. normalZ = closestPointToSphereZ * l;
  5905. this.setNormal(result,normalX,normalY,normalZ);
  5906. let pos1X;
  5907. let pos1Y;
  5908. let pos1Z;
  5909. let pos2X;
  5910. let pos2Y;
  5911. let pos2Z;
  5912. pos1X = tf1._positionX + normalX * -r;
  5913. pos1Y = tf1._positionY + normalY * -r;
  5914. pos1Z = tf1._positionZ + normalZ * -r;
  5915. pos2X = tf2._positionX + boxToClosestPointX;
  5916. pos2Y = tf2._positionY + boxToClosestPointY;
  5917. pos2Z = tf2._positionZ + boxToClosestPointZ;
  5918. this.addPoint(result,pos1X,pos1Y,pos1Z,pos2X,pos2Y,pos2Z,r - dist,0);
  5919. }
  5920. }
  5921. oimo.collision.narrowphase.detector.SphereCapsuleDetector = class oimo_collision_narrowphase_detector_SphereCapsuleDetector extends oimo.collision.narrowphase.detector.Detector {
  5922. constructor(swapped) {
  5923. super(swapped);
  5924. }
  5925. detectImpl(result,geom1,geom2,tf1,tf2,cachedData) {
  5926. let c2 = geom2;
  5927. result.incremental = false;
  5928. let hh2 = c2._halfHeight;
  5929. let r1 = geom1._radius;
  5930. let r2 = c2._radius;
  5931. let axis2X;
  5932. let axis2Y;
  5933. let axis2Z;
  5934. axis2X = tf2._rotation01;
  5935. axis2Y = tf2._rotation11;
  5936. axis2Z = tf2._rotation21;
  5937. let cp1X;
  5938. let cp1Y;
  5939. let cp1Z;
  5940. cp1X = tf1._positionX;
  5941. cp1Y = tf1._positionY;
  5942. cp1Z = tf1._positionZ;
  5943. let p2X;
  5944. let p2Y;
  5945. let p2Z;
  5946. let q2X;
  5947. let q2Y;
  5948. let q2Z;
  5949. p2X = tf2._positionX + axis2X * -hh2;
  5950. p2Y = tf2._positionY + axis2Y * -hh2;
  5951. p2Z = tf2._positionZ + axis2Z * -hh2;
  5952. q2X = tf2._positionX + axis2X * hh2;
  5953. q2Y = tf2._positionY + axis2Y * hh2;
  5954. q2Z = tf2._positionZ + axis2Z * hh2;
  5955. let p12X;
  5956. let p12Y;
  5957. let p12Z;
  5958. p12X = cp1X - p2X;
  5959. p12Y = cp1Y - p2Y;
  5960. p12Z = cp1Z - p2Z;
  5961. let d2X;
  5962. let d2Y;
  5963. let d2Z;
  5964. d2X = q2X - p2X;
  5965. d2Y = q2Y - p2Y;
  5966. d2Z = q2Z - p2Z;
  5967. let d22 = hh2 * hh2 * 4;
  5968. let t = p12X * d2X + p12Y * d2Y + p12Z * d2Z;
  5969. if(t < 0) {
  5970. t = 0;
  5971. } else if(t > d22) {
  5972. t = 1;
  5973. } else {
  5974. t /= d22;
  5975. }
  5976. let cp2X;
  5977. let cp2Y;
  5978. let cp2Z;
  5979. cp2X = p2X + d2X * t;
  5980. cp2Y = p2Y + d2Y * t;
  5981. cp2Z = p2Z + d2Z * t;
  5982. let dX;
  5983. let dY;
  5984. let dZ;
  5985. dX = cp1X - cp2X;
  5986. dY = cp1Y - cp2Y;
  5987. dZ = cp1Z - cp2Z;
  5988. let len2 = dX * dX + dY * dY + dZ * dZ;
  5989. if(len2 >= (r1 + r2) * (r1 + r2)) {
  5990. return;
  5991. }
  5992. let len = Math.sqrt(len2);
  5993. let nX;
  5994. let nY;
  5995. let nZ;
  5996. if(len > 0) {
  5997. nX = dX * (1 / len);
  5998. nY = dY * (1 / len);
  5999. nZ = dZ * (1 / len);
  6000. } else {
  6001. nX = 1;
  6002. nY = 0;
  6003. nZ = 0;
  6004. }
  6005. this.setNormal(result,nX,nY,nZ);
  6006. let pos1X;
  6007. let pos1Y;
  6008. let pos1Z;
  6009. let pos2X;
  6010. let pos2Y;
  6011. let pos2Z;
  6012. pos1X = cp1X + nX * -r1;
  6013. pos1Y = cp1Y + nY * -r1;
  6014. pos1Z = cp1Z + nZ * -r1;
  6015. pos2X = cp2X + nX * r2;
  6016. pos2Y = cp2Y + nY * r2;
  6017. pos2Z = cp2Z + nZ * r2;
  6018. this.addPoint(result,pos1X,pos1Y,pos1Z,pos2X,pos2Y,pos2Z,r1 + r2 - len,0);
  6019. }
  6020. }
  6021. oimo.collision.narrowphase.detector.SphereSphereDetector = class oimo_collision_narrowphase_detector_SphereSphereDetector extends oimo.collision.narrowphase.detector.Detector {
  6022. constructor() {
  6023. super(false);
  6024. }
  6025. detectImpl(result,geom1,geom2,tf1,tf2,cachedData) {
  6026. result.incremental = false;
  6027. let dX;
  6028. let dY;
  6029. let dZ;
  6030. dX = tf1._positionX - tf2._positionX;
  6031. dY = tf1._positionY - tf2._positionY;
  6032. dZ = tf1._positionZ - tf2._positionZ;
  6033. let r1 = geom1._radius;
  6034. let r2 = geom2._radius;
  6035. let len2 = dX * dX + dY * dY + dZ * dZ;
  6036. if(len2 >= (r1 + r2) * (r1 + r2)) {
  6037. return;
  6038. }
  6039. let len = Math.sqrt(len2);
  6040. let nX;
  6041. let nY;
  6042. let nZ;
  6043. if(len > 0) {
  6044. nX = dX * (1 / len);
  6045. nY = dY * (1 / len);
  6046. nZ = dZ * (1 / len);
  6047. } else {
  6048. nX = 1;
  6049. nY = 0;
  6050. nZ = 0;
  6051. }
  6052. this.setNormal(result,nX,nY,nZ);
  6053. let pos1X;
  6054. let pos1Y;
  6055. let pos1Z;
  6056. let pos2X;
  6057. let pos2Y;
  6058. let pos2Z;
  6059. pos1X = tf1._positionX + nX * -r1;
  6060. pos1Y = tf1._positionY + nY * -r1;
  6061. pos1Z = tf1._positionZ + nZ * -r1;
  6062. pos2X = tf2._positionX + nX * r2;
  6063. pos2Y = tf2._positionY + nY * r2;
  6064. pos2Z = tf2._positionZ + nZ * r2;
  6065. this.addPoint(result,pos1X,pos1Y,pos1Z,pos2X,pos2Y,pos2Z,r1 + r2 - len,0);
  6066. }
  6067. }
  6068. if(!oimo.collision.narrowphase.detector.gjkepa) oimo.collision.narrowphase.detector.gjkepa = {};
  6069. oimo.collision.narrowphase.detector.gjkepa.EpaPolyhedron = class oimo_collision_narrowphase_detector_gjkepa_EpaPolyhedron {
  6070. constructor() {
  6071. this._vertices = new Array(oimo.common.Setting.maxEPAVertices);
  6072. this._center = new oimo.common.Vec3();
  6073. this._numVertices = 0;
  6074. this._triangleList = null;
  6075. this._triangleListLast = null;
  6076. this._numTriangles = 0;
  6077. this._trianglePool = null;
  6078. this._vertexPool = null;
  6079. }
  6080. dumpHoleEdge(first) {
  6081. }
  6082. validate() {
  6083. let t = this._triangleList;
  6084. while(t != null) {
  6085. t._vertices[0]._tmpEdgeLoopOuterTriangle = null;
  6086. t._vertices[0]._tmpEdgeLoopNext = null;
  6087. if(t._adjacentPairIndex[0] == -1) {
  6088. this._status = 2;
  6089. return false;
  6090. }
  6091. if(t._adjacentTriangles[0] == null) {
  6092. this._status = 3;
  6093. return false;
  6094. }
  6095. t._vertices[1]._tmpEdgeLoopOuterTriangle = null;
  6096. t._vertices[1]._tmpEdgeLoopNext = null;
  6097. if(t._adjacentPairIndex[1] == -1) {
  6098. this._status = 2;
  6099. return false;
  6100. }
  6101. if(t._adjacentTriangles[1] == null) {
  6102. this._status = 3;
  6103. return false;
  6104. }
  6105. t._vertices[2]._tmpEdgeLoopOuterTriangle = null;
  6106. t._vertices[2]._tmpEdgeLoopNext = null;
  6107. if(t._adjacentPairIndex[2] == -1) {
  6108. this._status = 2;
  6109. return false;
  6110. }
  6111. if(t._adjacentTriangles[2] == null) {
  6112. this._status = 3;
  6113. return false;
  6114. }
  6115. t = t._next;
  6116. }
  6117. return true;
  6118. }
  6119. findEdgeLoop(id,base,from) {
  6120. if(base._tmpDfsId == id) {
  6121. return;
  6122. }
  6123. base._tmpDfsId = id;
  6124. let _this = base.tmp;
  6125. _this.x = from.x;
  6126. _this.y = from.y;
  6127. _this.z = from.z;
  6128. let v = base._vertices[0].v;
  6129. _this.x -= v.x;
  6130. _this.y -= v.y;
  6131. _this.z -= v.z;
  6132. let _this1 = base.tmp;
  6133. let v1 = base._normal;
  6134. base._tmpDfsVisible = _this1.x * v1.x + _this1.y * v1.y + _this1.z * v1.z > 0;
  6135. if(!base._tmpDfsVisible) {
  6136. this._status = 6;
  6137. return;
  6138. }
  6139. let _g = 0;
  6140. while(_g < 3) {
  6141. let i = _g++;
  6142. let t = base._adjacentTriangles[i];
  6143. if(t == null) {
  6144. continue;
  6145. }
  6146. let _this = t.tmp;
  6147. _this.x = from.x;
  6148. _this.y = from.y;
  6149. _this.z = from.z;
  6150. let v = t._vertices[0].v;
  6151. _this.x -= v.x;
  6152. _this.y -= v.y;
  6153. _this.z -= v.z;
  6154. let _this1 = t.tmp;
  6155. let v1 = t._normal;
  6156. t._tmpDfsVisible = _this1.x * v1.x + _this1.y * v1.y + _this1.z * v1.z > 0;
  6157. if(t._tmpDfsVisible) {
  6158. this.findEdgeLoop(id,t,from);
  6159. } else {
  6160. let v1 = base._vertices[i];
  6161. v1._tmpEdgeLoopNext = base._vertices[base._nextIndex[i]];
  6162. v1._tmpEdgeLoopOuterTriangle = t;
  6163. }
  6164. }
  6165. let triangle = base._adjacentTriangles[0];
  6166. if(triangle != null) {
  6167. let pairIndex = base._adjacentPairIndex[0];
  6168. triangle._adjacentTriangles[pairIndex] = null;
  6169. triangle._adjacentPairIndex[pairIndex] = -1;
  6170. base._adjacentTriangles[0] = null;
  6171. base._adjacentPairIndex[0] = -1;
  6172. }
  6173. let triangle1 = base._adjacentTriangles[1];
  6174. if(triangle1 != null) {
  6175. let pairIndex = base._adjacentPairIndex[1];
  6176. triangle1._adjacentTriangles[pairIndex] = null;
  6177. triangle1._adjacentPairIndex[pairIndex] = -1;
  6178. base._adjacentTriangles[1] = null;
  6179. base._adjacentPairIndex[1] = -1;
  6180. }
  6181. let triangle2 = base._adjacentTriangles[2];
  6182. if(triangle2 != null) {
  6183. let pairIndex = base._adjacentPairIndex[2];
  6184. triangle2._adjacentTriangles[pairIndex] = null;
  6185. triangle2._adjacentPairIndex[pairIndex] = -1;
  6186. base._adjacentTriangles[2] = null;
  6187. base._adjacentPairIndex[2] = -1;
  6188. }
  6189. this._numTriangles--;
  6190. let prev = base._prev;
  6191. let next = base._next;
  6192. if(prev != null) {
  6193. prev._next = next;
  6194. }
  6195. if(next != null) {
  6196. next._prev = prev;
  6197. }
  6198. if(base == this._triangleList) {
  6199. this._triangleList = this._triangleList._next;
  6200. }
  6201. if(base == this._triangleListLast) {
  6202. this._triangleListLast = this._triangleListLast._prev;
  6203. }
  6204. base._next = null;
  6205. base._prev = null;
  6206. base.removeReferences();
  6207. base._next = this._trianglePool;
  6208. this._trianglePool = base;
  6209. }
  6210. _init(v1,v2,v3,v4) {
  6211. this._status = 0;
  6212. this._numVertices = 4;
  6213. this._vertices[0] = v1;
  6214. this._vertices[1] = v2;
  6215. this._vertices[2] = v3;
  6216. this._vertices[3] = v4;
  6217. let _this = this._center;
  6218. let v = v1.v;
  6219. _this.x = v.x;
  6220. _this.y = v.y;
  6221. _this.z = v.z;
  6222. let v5 = v2.v;
  6223. _this.x += v5.x;
  6224. _this.y += v5.y;
  6225. _this.z += v5.z;
  6226. let v6 = v3.v;
  6227. _this.x += v6.x;
  6228. _this.y += v6.y;
  6229. _this.z += v6.z;
  6230. let v7 = v4.v;
  6231. _this.x += v7.x;
  6232. _this.y += v7.y;
  6233. _this.z += v7.z;
  6234. _this.x *= 0.25;
  6235. _this.y *= 0.25;
  6236. _this.z *= 0.25;
  6237. let first = this._trianglePool;
  6238. if(first != null) {
  6239. this._trianglePool = first._next;
  6240. first._next = null;
  6241. } else {
  6242. first = new oimo.collision.narrowphase.detector.gjkepa.EpaTriangle();
  6243. }
  6244. let t1 = first;
  6245. let first1 = this._trianglePool;
  6246. if(first1 != null) {
  6247. this._trianglePool = first1._next;
  6248. first1._next = null;
  6249. } else {
  6250. first1 = new oimo.collision.narrowphase.detector.gjkepa.EpaTriangle();
  6251. }
  6252. let t2 = first1;
  6253. let first2 = this._trianglePool;
  6254. if(first2 != null) {
  6255. this._trianglePool = first2._next;
  6256. first2._next = null;
  6257. } else {
  6258. first2 = new oimo.collision.narrowphase.detector.gjkepa.EpaTriangle();
  6259. }
  6260. let t3 = first2;
  6261. let first3 = this._trianglePool;
  6262. if(first3 != null) {
  6263. this._trianglePool = first3._next;
  6264. first3._next = null;
  6265. } else {
  6266. first3 = new oimo.collision.narrowphase.detector.gjkepa.EpaTriangle();
  6267. }
  6268. let t4 = first3;
  6269. if(!t1.init(v1,v2,v3,this._center,true)) {
  6270. this._status = 1;
  6271. }
  6272. if(!t2.init(v1,v2,v4,this._center,true)) {
  6273. this._status = 1;
  6274. }
  6275. if(!t3.init(v1,v3,v4,this._center,true)) {
  6276. this._status = 1;
  6277. }
  6278. if(!t4.init(v2,v3,v4,this._center,true)) {
  6279. this._status = 1;
  6280. }
  6281. if(!t1.setAdjacentTriangle(t2)) {
  6282. this._status = 1;
  6283. }
  6284. if(!t1.setAdjacentTriangle(t3)) {
  6285. this._status = 1;
  6286. }
  6287. if(!t1.setAdjacentTriangle(t4)) {
  6288. this._status = 1;
  6289. }
  6290. if(!t2.setAdjacentTriangle(t3)) {
  6291. this._status = 1;
  6292. }
  6293. if(!t2.setAdjacentTriangle(t4)) {
  6294. this._status = 1;
  6295. }
  6296. if(!t3.setAdjacentTriangle(t4)) {
  6297. this._status = 1;
  6298. }
  6299. this._numTriangles++;
  6300. if(this._triangleList == null) {
  6301. this._triangleList = t1;
  6302. this._triangleListLast = t1;
  6303. } else {
  6304. this._triangleListLast._next = t1;
  6305. t1._prev = this._triangleListLast;
  6306. this._triangleListLast = t1;
  6307. }
  6308. this._numTriangles++;
  6309. if(this._triangleList == null) {
  6310. this._triangleList = t2;
  6311. this._triangleListLast = t2;
  6312. } else {
  6313. this._triangleListLast._next = t2;
  6314. t2._prev = this._triangleListLast;
  6315. this._triangleListLast = t2;
  6316. }
  6317. this._numTriangles++;
  6318. if(this._triangleList == null) {
  6319. this._triangleList = t3;
  6320. this._triangleListLast = t3;
  6321. } else {
  6322. this._triangleListLast._next = t3;
  6323. t3._prev = this._triangleListLast;
  6324. this._triangleListLast = t3;
  6325. }
  6326. this._numTriangles++;
  6327. if(this._triangleList == null) {
  6328. this._triangleList = t4;
  6329. this._triangleListLast = t4;
  6330. } else {
  6331. this._triangleListLast._next = t4;
  6332. t4._prev = this._triangleListLast;
  6333. this._triangleListLast = t4;
  6334. }
  6335. return this._status == 0;
  6336. }
  6337. _addVertex(vertex,base) {
  6338. this._vertices[this._numVertices++] = vertex;
  6339. let v1 = base._vertices[0];
  6340. this.findEdgeLoop(this._numVertices,base,vertex.v);
  6341. if(this._status != 0) {
  6342. return false;
  6343. }
  6344. let v = v1;
  6345. let prevT = null;
  6346. let firstT = null;
  6347. while(true) {
  6348. if(v._tmpEdgeLoopNext == null) {
  6349. this._dumpAsObjModel();
  6350. this._status = 4;
  6351. return false;
  6352. }
  6353. if(v._tmpEdgeLoopOuterTriangle == null) {
  6354. this._status = 5;
  6355. return false;
  6356. }
  6357. let first = this._trianglePool;
  6358. if(first != null) {
  6359. this._trianglePool = first._next;
  6360. first._next = null;
  6361. } else {
  6362. first = new oimo.collision.narrowphase.detector.gjkepa.EpaTriangle();
  6363. }
  6364. let t = first;
  6365. if(firstT == null) {
  6366. firstT = t;
  6367. }
  6368. if(!t.init(v,v._tmpEdgeLoopNext,vertex,this._center,false)) {
  6369. this._status = 1;
  6370. }
  6371. if(this._status != 0) {
  6372. return false;
  6373. }
  6374. this._numTriangles++;
  6375. if(this._triangleList == null) {
  6376. this._triangleList = t;
  6377. this._triangleListLast = t;
  6378. } else {
  6379. this._triangleListLast._next = t;
  6380. t._prev = this._triangleListLast;
  6381. this._triangleListLast = t;
  6382. }
  6383. if(!t.setAdjacentTriangle(v._tmpEdgeLoopOuterTriangle)) {
  6384. this._status = 1;
  6385. }
  6386. if(prevT != null) {
  6387. if(!t.setAdjacentTriangle(prevT)) {
  6388. this._status = 1;
  6389. }
  6390. }
  6391. prevT = t;
  6392. v = v._tmpEdgeLoopNext;
  6393. if(!(v != v1)) {
  6394. break;
  6395. }
  6396. }
  6397. if(!prevT.setAdjacentTriangle(firstT)) {
  6398. this._status = 1;
  6399. }
  6400. if(this._status == 0) {
  6401. return this.validate();
  6402. } else {
  6403. return false;
  6404. }
  6405. }
  6406. _dumpAsObjModel() {
  6407. }
  6408. }
  6409. oimo.collision.narrowphase.detector.gjkepa.EpaPolyhedronState = class oimo_collision_narrowphase_detector_gjkepa_EpaPolyhedronState {
  6410. }
  6411. oimo.collision.narrowphase.detector.gjkepa.EpaTriangle = class oimo_collision_narrowphase_detector_gjkepa_EpaTriangle {
  6412. constructor() {
  6413. this.id = ++oimo.collision.narrowphase.detector.gjkepa.EpaTriangle.count;
  6414. this._next = null;
  6415. this._prev = null;
  6416. this._normal = new oimo.common.Vec3();
  6417. this._distanceSq = 0;
  6418. this._tmpDfsId = 0;
  6419. this._tmpDfsVisible = false;
  6420. this._vertices = new Array(3);
  6421. this._adjacentTriangles = new Array(3);
  6422. this._adjacentPairIndex = new Array(3);
  6423. this.tmp = new oimo.common.Vec3();
  6424. this._nextIndex = new Array(3);
  6425. this._nextIndex[0] = 1;
  6426. this._nextIndex[1] = 2;
  6427. this._nextIndex[2] = 0;
  6428. }
  6429. init(vertex1,vertex2,vertex3,center,autoCheck) {
  6430. if(autoCheck == null) {
  6431. autoCheck = false;
  6432. }
  6433. let v1X;
  6434. let v1Y;
  6435. let v1Z;
  6436. let v2X;
  6437. let v2Y;
  6438. let v2Z;
  6439. let v3X;
  6440. let v3Y;
  6441. let v3Z;
  6442. let vcX;
  6443. let vcY;
  6444. let vcZ;
  6445. let v = vertex1.v;
  6446. v1X = v.x;
  6447. v1Y = v.y;
  6448. v1Z = v.z;
  6449. let v1 = vertex2.v;
  6450. v2X = v1.x;
  6451. v2Y = v1.y;
  6452. v2Z = v1.z;
  6453. let v2 = vertex3.v;
  6454. v3X = v2.x;
  6455. v3Y = v2.y;
  6456. v3Z = v2.z;
  6457. vcX = center.x;
  6458. vcY = center.y;
  6459. vcZ = center.z;
  6460. let v12X;
  6461. let v12Y;
  6462. let v12Z;
  6463. let v13X;
  6464. let v13Y;
  6465. let v13Z;
  6466. let vc1X;
  6467. let vc1Y;
  6468. let vc1Z;
  6469. v12X = v2X - v1X;
  6470. v12Y = v2Y - v1Y;
  6471. v12Z = v2Z - v1Z;
  6472. v13X = v3X - v1X;
  6473. v13Y = v3Y - v1Y;
  6474. v13Z = v3Z - v1Z;
  6475. vc1X = v1X - vcX;
  6476. vc1Y = v1Y - vcY;
  6477. vc1Z = v1Z - vcZ;
  6478. let inorX;
  6479. let inorY;
  6480. let inorZ;
  6481. inorX = v12Y * v13Z - v12Z * v13Y;
  6482. inorY = v12Z * v13X - v12X * v13Z;
  6483. inorZ = v12X * v13Y - v12Y * v13X;
  6484. let inverted = false;
  6485. if(vc1X * inorX + vc1Y * inorY + vc1Z * inorZ < 0) {
  6486. if(autoCheck) {
  6487. let tmp = vertex2;
  6488. vertex2 = vertex3;
  6489. vertex3 = tmp;
  6490. inorX *= -1;
  6491. inorY *= -1;
  6492. inorZ *= -1;
  6493. } else {
  6494. inverted = true;
  6495. }
  6496. }
  6497. this._vertices[0] = vertex1;
  6498. this._vertices[1] = vertex2;
  6499. this._vertices[2] = vertex3;
  6500. let v3 = this._normal;
  6501. v3.x = inorX;
  6502. v3.y = inorY;
  6503. v3.z = inorZ;
  6504. let vec1 = vertex1.v;
  6505. let vec2 = vertex2.v;
  6506. let vec3 = vertex3.v;
  6507. let out = this.tmp;
  6508. let v1X1;
  6509. let v1Y1;
  6510. let v1Z1;
  6511. let v2X1;
  6512. let v2Y1;
  6513. let v2Z1;
  6514. let v3X1;
  6515. let v3Y1;
  6516. let v3Z1;
  6517. let v12X1;
  6518. let v12Y1;
  6519. let v12Z1;
  6520. let v23X;
  6521. let v23Y;
  6522. let v23Z;
  6523. let v31X;
  6524. let v31Y;
  6525. let v31Z;
  6526. v1X1 = vec1.x;
  6527. v1Y1 = vec1.y;
  6528. v1Z1 = vec1.z;
  6529. v2X1 = vec2.x;
  6530. v2Y1 = vec2.y;
  6531. v2Z1 = vec2.z;
  6532. v3X1 = vec3.x;
  6533. v3Y1 = vec3.y;
  6534. v3Z1 = vec3.z;
  6535. v12X1 = v2X1 - v1X1;
  6536. v12Y1 = v2Y1 - v1Y1;
  6537. v12Z1 = v2Z1 - v1Z1;
  6538. v23X = v3X1 - v2X1;
  6539. v23Y = v3Y1 - v2Y1;
  6540. v23Z = v3Z1 - v2Z1;
  6541. v31X = v1X1 - v3X1;
  6542. v31Y = v1Y1 - v3Y1;
  6543. v31Z = v1Z1 - v3Z1;
  6544. let nX;
  6545. let nY;
  6546. let nZ;
  6547. nX = v12Y1 * v23Z - v12Z1 * v23Y;
  6548. nY = v12Z1 * v23X - v12X1 * v23Z;
  6549. nZ = v12X1 * v23Y - v12Y1 * v23X;
  6550. let n12X;
  6551. let n12Y;
  6552. let n12Z;
  6553. let n23X;
  6554. let n23Y;
  6555. let n23Z;
  6556. let n31X;
  6557. let n31Y;
  6558. let n31Z;
  6559. n12X = v12Y1 * nZ - v12Z1 * nY;
  6560. n12Y = v12Z1 * nX - v12X1 * nZ;
  6561. n12Z = v12X1 * nY - v12Y1 * nX;
  6562. n23X = v23Y * nZ - v23Z * nY;
  6563. n23Y = v23Z * nX - v23X * nZ;
  6564. n23Z = v23X * nY - v23Y * nX;
  6565. n31X = v31Y * nZ - v31Z * nY;
  6566. n31Y = v31Z * nX - v31X * nZ;
  6567. n31Z = v31X * nY - v31Y * nX;
  6568. let mind = -1;
  6569. let minvX;
  6570. let minvY;
  6571. let minvZ;
  6572. minvX = 0;
  6573. minvY = 0;
  6574. minvZ = 0;
  6575. if(v1X1 * n12X + v1Y1 * n12Y + v1Z1 * n12Z < 0) {
  6576. let v1X;
  6577. let v1Y;
  6578. let v1Z;
  6579. let v2X;
  6580. let v2Y;
  6581. let v2Z;
  6582. v1X = vec1.x;
  6583. v1Y = vec1.y;
  6584. v1Z = vec1.z;
  6585. v2X = vec2.x;
  6586. v2Y = vec2.y;
  6587. v2Z = vec2.z;
  6588. let v12X;
  6589. let v12Y;
  6590. let v12Z;
  6591. v12X = v2X - v1X;
  6592. v12Y = v2Y - v1Y;
  6593. v12Z = v2Z - v1Z;
  6594. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  6595. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  6596. if(t < 0) {
  6597. out.x = v1X;
  6598. out.y = v1Y;
  6599. out.z = v1Z;
  6600. } else if(t > 1) {
  6601. out.x = v2X;
  6602. out.y = v2Y;
  6603. out.z = v2Z;
  6604. } else {
  6605. let pX;
  6606. let pY;
  6607. let pZ;
  6608. pX = v1X + v12X * t;
  6609. pY = v1Y + v12Y * t;
  6610. pZ = v1Z + v12Z * t;
  6611. out.x = pX;
  6612. out.y = pY;
  6613. out.z = pZ;
  6614. }
  6615. mind = out.x * out.x + out.y * out.y + out.z * out.z;
  6616. minvX = out.x;
  6617. minvY = out.y;
  6618. minvZ = out.z;
  6619. }
  6620. if(v2X1 * n23X + v2Y1 * n23Y + v2Z1 * n23Z < 0) {
  6621. let v1X;
  6622. let v1Y;
  6623. let v1Z;
  6624. let v2X;
  6625. let v2Y;
  6626. let v2Z;
  6627. v1X = vec2.x;
  6628. v1Y = vec2.y;
  6629. v1Z = vec2.z;
  6630. v2X = vec3.x;
  6631. v2Y = vec3.y;
  6632. v2Z = vec3.z;
  6633. let v12X;
  6634. let v12Y;
  6635. let v12Z;
  6636. v12X = v2X - v1X;
  6637. v12Y = v2Y - v1Y;
  6638. v12Z = v2Z - v1Z;
  6639. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  6640. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  6641. if(t < 0) {
  6642. out.x = v1X;
  6643. out.y = v1Y;
  6644. out.z = v1Z;
  6645. } else if(t > 1) {
  6646. out.x = v2X;
  6647. out.y = v2Y;
  6648. out.z = v2Z;
  6649. } else {
  6650. let pX;
  6651. let pY;
  6652. let pZ;
  6653. pX = v1X + v12X * t;
  6654. pY = v1Y + v12Y * t;
  6655. pZ = v1Z + v12Z * t;
  6656. out.x = pX;
  6657. out.y = pY;
  6658. out.z = pZ;
  6659. }
  6660. let d = out.x * out.x + out.y * out.y + out.z * out.z;
  6661. if(mind < 0 || d < mind) {
  6662. mind = d;
  6663. minvX = out.x;
  6664. minvY = out.y;
  6665. minvZ = out.z;
  6666. }
  6667. }
  6668. if(v3X1 * n31X + v3Y1 * n31Y + v3Z1 * n31Z < 0) {
  6669. let v1X;
  6670. let v1Y;
  6671. let v1Z;
  6672. let v2X;
  6673. let v2Y;
  6674. let v2Z;
  6675. v1X = vec1.x;
  6676. v1Y = vec1.y;
  6677. v1Z = vec1.z;
  6678. v2X = vec3.x;
  6679. v2Y = vec3.y;
  6680. v2Z = vec3.z;
  6681. let v12X;
  6682. let v12Y;
  6683. let v12Z;
  6684. v12X = v2X - v1X;
  6685. v12Y = v2Y - v1Y;
  6686. v12Z = v2Z - v1Z;
  6687. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  6688. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  6689. if(t < 0) {
  6690. out.x = v1X;
  6691. out.y = v1Y;
  6692. out.z = v1Z;
  6693. } else if(t > 1) {
  6694. out.x = v2X;
  6695. out.y = v2Y;
  6696. out.z = v2Z;
  6697. } else {
  6698. let pX;
  6699. let pY;
  6700. let pZ;
  6701. pX = v1X + v12X * t;
  6702. pY = v1Y + v12Y * t;
  6703. pZ = v1Z + v12Z * t;
  6704. out.x = pX;
  6705. out.y = pY;
  6706. out.z = pZ;
  6707. }
  6708. let d = out.x * out.x + out.y * out.y + out.z * out.z;
  6709. if(mind < 0 || d < mind) {
  6710. mind = d;
  6711. minvX = out.x;
  6712. minvY = out.y;
  6713. minvZ = out.z;
  6714. }
  6715. }
  6716. if(mind > 0) {
  6717. out.x = minvX;
  6718. out.y = minvY;
  6719. out.z = minvZ;
  6720. } else {
  6721. let l = nX * nX + nY * nY + nZ * nZ;
  6722. if(l > 0) {
  6723. l = 1 / Math.sqrt(l);
  6724. }
  6725. nX *= l;
  6726. nY *= l;
  6727. nZ *= l;
  6728. let l2 = nX * nX + nY * nY + nZ * nZ;
  6729. l2 = (v1X1 * nX + v1Y1 * nY + v1Z1 * nZ) / l2;
  6730. minvX = nX * l2;
  6731. minvY = nY * l2;
  6732. minvZ = nZ * l2;
  6733. out.x = minvX;
  6734. out.y = minvY;
  6735. out.z = minvZ;
  6736. }
  6737. let _this = this.tmp;
  6738. this._distanceSq = _this.x * _this.x + _this.y * _this.y + _this.z * _this.z;
  6739. this._adjacentTriangles[0] = null;
  6740. this._adjacentTriangles[1] = null;
  6741. this._adjacentTriangles[2] = null;
  6742. this._adjacentPairIndex[0] = -1;
  6743. this._adjacentPairIndex[1] = -1;
  6744. this._adjacentPairIndex[2] = -1;
  6745. return !inverted;
  6746. }
  6747. setAdjacentTriangle(triangle) {
  6748. let count = 0;
  6749. if(this._vertices[0] == triangle._vertices[this._nextIndex[0]] && this._vertices[this._nextIndex[0]] == triangle._vertices[0]) {
  6750. this._adjacentTriangles[0] = triangle;
  6751. this._adjacentPairIndex[0] = 0;
  6752. triangle._adjacentTriangles[0] = this;
  6753. triangle._adjacentPairIndex[0] = 0;
  6754. count = 1;
  6755. }
  6756. if(this._vertices[0] == triangle._vertices[this._nextIndex[1]] && this._vertices[this._nextIndex[0]] == triangle._vertices[1]) {
  6757. this._adjacentTriangles[0] = triangle;
  6758. this._adjacentPairIndex[0] = 1;
  6759. triangle._adjacentTriangles[1] = this;
  6760. triangle._adjacentPairIndex[1] = 0;
  6761. ++count;
  6762. }
  6763. if(this._vertices[0] == triangle._vertices[this._nextIndex[2]] && this._vertices[this._nextIndex[0]] == triangle._vertices[2]) {
  6764. this._adjacentTriangles[0] = triangle;
  6765. this._adjacentPairIndex[0] = 2;
  6766. triangle._adjacentTriangles[2] = this;
  6767. triangle._adjacentPairIndex[2] = 0;
  6768. ++count;
  6769. }
  6770. if(this._vertices[1] == triangle._vertices[this._nextIndex[0]] && this._vertices[this._nextIndex[1]] == triangle._vertices[0]) {
  6771. this._adjacentTriangles[1] = triangle;
  6772. this._adjacentPairIndex[1] = 0;
  6773. triangle._adjacentTriangles[0] = this;
  6774. triangle._adjacentPairIndex[0] = 1;
  6775. ++count;
  6776. }
  6777. if(this._vertices[1] == triangle._vertices[this._nextIndex[1]] && this._vertices[this._nextIndex[1]] == triangle._vertices[1]) {
  6778. this._adjacentTriangles[1] = triangle;
  6779. this._adjacentPairIndex[1] = 1;
  6780. triangle._adjacentTriangles[1] = this;
  6781. triangle._adjacentPairIndex[1] = 1;
  6782. ++count;
  6783. }
  6784. if(this._vertices[1] == triangle._vertices[this._nextIndex[2]] && this._vertices[this._nextIndex[1]] == triangle._vertices[2]) {
  6785. this._adjacentTriangles[1] = triangle;
  6786. this._adjacentPairIndex[1] = 2;
  6787. triangle._adjacentTriangles[2] = this;
  6788. triangle._adjacentPairIndex[2] = 1;
  6789. ++count;
  6790. }
  6791. if(this._vertices[2] == triangle._vertices[this._nextIndex[0]] && this._vertices[this._nextIndex[2]] == triangle._vertices[0]) {
  6792. this._adjacentTriangles[2] = triangle;
  6793. this._adjacentPairIndex[2] = 0;
  6794. triangle._adjacentTriangles[0] = this;
  6795. triangle._adjacentPairIndex[0] = 2;
  6796. ++count;
  6797. }
  6798. if(this._vertices[2] == triangle._vertices[this._nextIndex[1]] && this._vertices[this._nextIndex[2]] == triangle._vertices[1]) {
  6799. this._adjacentTriangles[2] = triangle;
  6800. this._adjacentPairIndex[2] = 1;
  6801. triangle._adjacentTriangles[1] = this;
  6802. triangle._adjacentPairIndex[1] = 2;
  6803. ++count;
  6804. }
  6805. if(this._vertices[2] == triangle._vertices[this._nextIndex[2]] && this._vertices[this._nextIndex[2]] == triangle._vertices[2]) {
  6806. this._adjacentTriangles[2] = triangle;
  6807. this._adjacentPairIndex[2] = 2;
  6808. triangle._adjacentTriangles[2] = this;
  6809. triangle._adjacentPairIndex[2] = 2;
  6810. ++count;
  6811. }
  6812. if(count != 1) {
  6813. return false;
  6814. }
  6815. return true;
  6816. }
  6817. removeAdjacentTriangles() {
  6818. let triangle = this._adjacentTriangles[0];
  6819. if(triangle != null) {
  6820. let pairIndex = this._adjacentPairIndex[0];
  6821. triangle._adjacentTriangles[pairIndex] = null;
  6822. triangle._adjacentPairIndex[pairIndex] = -1;
  6823. this._adjacentTriangles[0] = null;
  6824. this._adjacentPairIndex[0] = -1;
  6825. }
  6826. let triangle1 = this._adjacentTriangles[1];
  6827. if(triangle1 != null) {
  6828. let pairIndex = this._adjacentPairIndex[1];
  6829. triangle1._adjacentTriangles[pairIndex] = null;
  6830. triangle1._adjacentPairIndex[pairIndex] = -1;
  6831. this._adjacentTriangles[1] = null;
  6832. this._adjacentPairIndex[1] = -1;
  6833. }
  6834. let triangle2 = this._adjacentTriangles[2];
  6835. if(triangle2 != null) {
  6836. let pairIndex = this._adjacentPairIndex[2];
  6837. triangle2._adjacentTriangles[pairIndex] = null;
  6838. triangle2._adjacentPairIndex[pairIndex] = -1;
  6839. this._adjacentTriangles[2] = null;
  6840. this._adjacentPairIndex[2] = -1;
  6841. }
  6842. }
  6843. removeReferences() {
  6844. this._next = null;
  6845. this._prev = null;
  6846. this._tmpDfsId = 0;
  6847. this._tmpDfsVisible = false;
  6848. this._distanceSq = 0;
  6849. this._vertices[0] = null;
  6850. this._vertices[1] = null;
  6851. this._vertices[2] = null;
  6852. this._adjacentTriangles[0] = null;
  6853. this._adjacentTriangles[1] = null;
  6854. this._adjacentTriangles[2] = null;
  6855. this._adjacentPairIndex[0] = 0;
  6856. this._adjacentPairIndex[1] = 0;
  6857. this._adjacentPairIndex[2] = 0;
  6858. }
  6859. dump() {
  6860. }
  6861. }
  6862. oimo.collision.narrowphase.detector.gjkepa.EpaVertex = class oimo_collision_narrowphase_detector_gjkepa_EpaVertex {
  6863. constructor() {
  6864. this.randId = Math.random() * 100000 | 0;
  6865. this.v = new oimo.common.Vec3();
  6866. this.w1 = new oimo.common.Vec3();
  6867. this.w2 = new oimo.common.Vec3();
  6868. }
  6869. init(v,w1,w2) {
  6870. let _this = this.v;
  6871. _this.x = v.x;
  6872. _this.y = v.y;
  6873. _this.z = v.z;
  6874. let _this1 = this.w1;
  6875. _this1.x = w1.x;
  6876. _this1.y = w1.y;
  6877. _this1.z = w1.z;
  6878. let _this2 = this.w2;
  6879. _this2.x = w2.x;
  6880. _this2.y = w2.y;
  6881. _this2.z = w2.z;
  6882. this._next = null;
  6883. this._tmpEdgeLoopNext = null;
  6884. this._tmpEdgeLoopOuterTriangle = null;
  6885. return this;
  6886. }
  6887. removeReferences() {
  6888. this._next = null;
  6889. this._tmpEdgeLoopNext = null;
  6890. this._tmpEdgeLoopOuterTriangle = null;
  6891. }
  6892. }
  6893. oimo.collision.narrowphase.detector.gjkepa.GjkCache = class oimo_collision_narrowphase_detector_gjkepa_GjkCache {
  6894. constructor() {
  6895. this.prevClosestDir = new oimo.common.Vec3();
  6896. }
  6897. clear() {
  6898. this.prevClosestDir.zero();
  6899. }
  6900. }
  6901. if(!oimo.common) oimo.common = {};
  6902. oimo.common.Vec3 = class oimo_common_Vec3 {
  6903. constructor(x,y,z) {
  6904. if(z == null) {
  6905. z = 0;
  6906. }
  6907. if(y == null) {
  6908. y = 0;
  6909. }
  6910. if(x == null) {
  6911. x = 0;
  6912. }
  6913. this.x = x;
  6914. this.y = y;
  6915. this.z = z;
  6916. oimo.common.Vec3.numCreations++;
  6917. }
  6918. init(x,y,z) {
  6919. this.x = x;
  6920. this.y = y;
  6921. this.z = z;
  6922. return this;
  6923. }
  6924. zero() {
  6925. this.x = 0;
  6926. this.y = 0;
  6927. this.z = 0;
  6928. return this;
  6929. }
  6930. add(v) {
  6931. return new oimo.common.Vec3(this.x + v.x,this.y + v.y,this.z + v.z);
  6932. }
  6933. add3(vx,vy,vz) {
  6934. return new oimo.common.Vec3(this.x + vx,this.y + vy,this.z + vz);
  6935. }
  6936. addScaled(v,s) {
  6937. return new oimo.common.Vec3(this.x + v.x * s,this.y + v.y * s,this.z + v.z * s);
  6938. }
  6939. sub(v) {
  6940. return new oimo.common.Vec3(this.x - v.x,this.y - v.y,this.z - v.z);
  6941. }
  6942. sub3(vx,vy,vz) {
  6943. return new oimo.common.Vec3(this.x - vx,this.y - vy,this.z - vz);
  6944. }
  6945. scale(s) {
  6946. return new oimo.common.Vec3(this.x * s,this.y * s,this.z * s);
  6947. }
  6948. scale3(sx,sy,sz) {
  6949. return new oimo.common.Vec3(this.x * sx,this.y * sy,this.z * sz);
  6950. }
  6951. dot(v) {
  6952. return this.x * v.x + this.y * v.y + this.z * v.z;
  6953. }
  6954. cross(v) {
  6955. return new oimo.common.Vec3(this.y * v.z - this.z * v.y,this.z * v.x - this.x * v.z,this.x * v.y - this.y * v.x);
  6956. }
  6957. addEq(v) {
  6958. this.x += v.x;
  6959. this.y += v.y;
  6960. this.z += v.z;
  6961. return this;
  6962. }
  6963. add3Eq(vx,vy,vz) {
  6964. this.x += vx;
  6965. this.y += vy;
  6966. this.z += vz;
  6967. return this;
  6968. }
  6969. addScaledEq(v,s) {
  6970. this.x += v.x * s;
  6971. this.y += v.y * s;
  6972. this.z += v.z * s;
  6973. return this;
  6974. }
  6975. subEq(v) {
  6976. this.x -= v.x;
  6977. this.y -= v.y;
  6978. this.z -= v.z;
  6979. return this;
  6980. }
  6981. sub3Eq(vx,vy,vz) {
  6982. this.x -= vx;
  6983. this.y -= vy;
  6984. this.z -= vz;
  6985. return this;
  6986. }
  6987. scaleEq(s) {
  6988. this.x *= s;
  6989. this.y *= s;
  6990. this.z *= s;
  6991. return this;
  6992. }
  6993. scale3Eq(sx,sy,sz) {
  6994. this.x *= sx;
  6995. this.y *= sy;
  6996. this.z *= sz;
  6997. return this;
  6998. }
  6999. crossEq(v) {
  7000. let y = this.z * v.x - this.x * v.z;
  7001. let z = this.x * v.y - this.y * v.x;
  7002. this.x = this.y * v.z - this.z * v.y;
  7003. this.y = y;
  7004. this.z = z;
  7005. return this;
  7006. }
  7007. mulMat3(m) {
  7008. return new oimo.common.Vec3(this.x * m.e00 + this.y * m.e01 + this.z * m.e02,this.x * m.e10 + this.y * m.e11 + this.z * m.e12,this.x * m.e20 + this.y * m.e21 + this.z * m.e22);
  7009. }
  7010. mulMat4(m) {
  7011. return new oimo.common.Vec3(this.x * m.e00 + this.y * m.e01 + this.z * m.e02 + m.e03,this.x * m.e10 + this.y * m.e11 + this.z * m.e12 + m.e13,this.x * m.e20 + this.y * m.e21 + this.z * m.e22 + m.e23);
  7012. }
  7013. mulTransform(tf) {
  7014. let vX;
  7015. let vY;
  7016. let vZ;
  7017. vX = this.x;
  7018. vY = this.y;
  7019. vZ = this.z;
  7020. let __tmp__X;
  7021. let __tmp__Y;
  7022. let __tmp__Z;
  7023. __tmp__X = tf._rotation00 * vX + tf._rotation01 * vY + tf._rotation02 * vZ;
  7024. __tmp__Y = tf._rotation10 * vX + tf._rotation11 * vY + tf._rotation12 * vZ;
  7025. __tmp__Z = tf._rotation20 * vX + tf._rotation21 * vY + tf._rotation22 * vZ;
  7026. vX = __tmp__X;
  7027. vY = __tmp__Y;
  7028. vZ = __tmp__Z;
  7029. vX += tf._positionX;
  7030. vY += tf._positionY;
  7031. vZ += tf._positionZ;
  7032. let res = new oimo.common.Vec3();
  7033. res.x = vX;
  7034. res.y = vY;
  7035. res.z = vZ;
  7036. return res;
  7037. }
  7038. mulMat3Eq(m) {
  7039. let y = this.x * m.e10 + this.y * m.e11 + this.z * m.e12;
  7040. let z = this.x * m.e20 + this.y * m.e21 + this.z * m.e22;
  7041. this.x = this.x * m.e00 + this.y * m.e01 + this.z * m.e02;
  7042. this.y = y;
  7043. this.z = z;
  7044. return this;
  7045. }
  7046. mulMat4Eq(m) {
  7047. let y = this.x * m.e10 + this.y * m.e11 + this.z * m.e12 + m.e13;
  7048. let z = this.x * m.e20 + this.y * m.e21 + this.z * m.e22 + m.e23;
  7049. this.x = this.x * m.e00 + this.y * m.e01 + this.z * m.e02 + m.e03;
  7050. this.y = y;
  7051. this.z = z;
  7052. return this;
  7053. }
  7054. mulTransformEq(tf) {
  7055. let vX;
  7056. let vY;
  7057. let vZ;
  7058. vX = this.x;
  7059. vY = this.y;
  7060. vZ = this.z;
  7061. let __tmp__X;
  7062. let __tmp__Y;
  7063. let __tmp__Z;
  7064. __tmp__X = tf._rotation00 * vX + tf._rotation01 * vY + tf._rotation02 * vZ;
  7065. __tmp__Y = tf._rotation10 * vX + tf._rotation11 * vY + tf._rotation12 * vZ;
  7066. __tmp__Z = tf._rotation20 * vX + tf._rotation21 * vY + tf._rotation22 * vZ;
  7067. vX = __tmp__X;
  7068. vY = __tmp__Y;
  7069. vZ = __tmp__Z;
  7070. vX += tf._positionX;
  7071. vY += tf._positionY;
  7072. vZ += tf._positionZ;
  7073. this.x = vX;
  7074. this.y = vY;
  7075. this.z = vZ;
  7076. return this;
  7077. }
  7078. length() {
  7079. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
  7080. }
  7081. lengthSq() {
  7082. return this.x * this.x + this.y * this.y + this.z * this.z;
  7083. }
  7084. normalized() {
  7085. let invLen = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
  7086. if(invLen > 0) {
  7087. invLen = 1 / invLen;
  7088. }
  7089. return new oimo.common.Vec3(this.x * invLen,this.y * invLen,this.z * invLen);
  7090. }
  7091. normalize() {
  7092. let invLen = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
  7093. if(invLen > 0) {
  7094. invLen = 1 / invLen;
  7095. }
  7096. this.x *= invLen;
  7097. this.y *= invLen;
  7098. this.z *= invLen;
  7099. return this;
  7100. }
  7101. negate() {
  7102. return new oimo.common.Vec3(-this.x,-this.y,-this.z);
  7103. }
  7104. negateEq() {
  7105. this.x = -this.x;
  7106. this.y = -this.y;
  7107. this.z = -this.z;
  7108. return this;
  7109. }
  7110. copyFrom(v) {
  7111. this.x = v.x;
  7112. this.y = v.y;
  7113. this.z = v.z;
  7114. return this;
  7115. }
  7116. clone() {
  7117. return new oimo.common.Vec3(this.x,this.y,this.z);
  7118. }
  7119. toString() {
  7120. return "Vec3[" + (this.x > 0 ? (this.x * 10000000 + 0.5 | 0) / 10000000 : (this.x * 10000000 - 0.5 | 0) / 10000000) + ", " + (this.y > 0 ? (this.y * 10000000 + 0.5 | 0) / 10000000 : (this.y * 10000000 - 0.5 | 0) / 10000000) + ", " + (this.z > 0 ? (this.z * 10000000 + 0.5 | 0) / 10000000 : (this.z * 10000000 - 0.5 | 0) / 10000000) + "]";
  7121. }
  7122. }
  7123. oimo.common.Transform = class oimo_common_Transform {
  7124. constructor() {
  7125. this._positionX = 0;
  7126. this._positionY = 0;
  7127. this._positionZ = 0;
  7128. this._rotation00 = 1;
  7129. this._rotation01 = 0;
  7130. this._rotation02 = 0;
  7131. this._rotation10 = 0;
  7132. this._rotation11 = 1;
  7133. this._rotation12 = 0;
  7134. this._rotation20 = 0;
  7135. this._rotation21 = 0;
  7136. this._rotation22 = 1;
  7137. }
  7138. identity() {
  7139. this._positionX = 0;
  7140. this._positionY = 0;
  7141. this._positionZ = 0;
  7142. this._rotation00 = 1;
  7143. this._rotation01 = 0;
  7144. this._rotation02 = 0;
  7145. this._rotation10 = 0;
  7146. this._rotation11 = 1;
  7147. this._rotation12 = 0;
  7148. this._rotation20 = 0;
  7149. this._rotation21 = 0;
  7150. this._rotation22 = 1;
  7151. return this;
  7152. }
  7153. getPosition() {
  7154. let position = new oimo.common.Vec3();
  7155. position.x = this._positionX;
  7156. position.y = this._positionY;
  7157. position.z = this._positionZ;
  7158. return position;
  7159. }
  7160. getPositionTo(position) {
  7161. position.x = this._positionX;
  7162. position.y = this._positionY;
  7163. position.z = this._positionZ;
  7164. }
  7165. setPosition(position) {
  7166. this._positionX = position.x;
  7167. this._positionY = position.y;
  7168. this._positionZ = position.z;
  7169. return this;
  7170. }
  7171. translate(translation) {
  7172. let diffX;
  7173. let diffY;
  7174. let diffZ;
  7175. diffX = translation.x;
  7176. diffY = translation.y;
  7177. diffZ = translation.z;
  7178. this._positionX += diffX;
  7179. this._positionY += diffY;
  7180. this._positionZ += diffZ;
  7181. }
  7182. getRotation() {
  7183. let rotation = new oimo.common.Mat3();
  7184. rotation.e00 = this._rotation00;
  7185. rotation.e01 = this._rotation01;
  7186. rotation.e02 = this._rotation02;
  7187. rotation.e10 = this._rotation10;
  7188. rotation.e11 = this._rotation11;
  7189. rotation.e12 = this._rotation12;
  7190. rotation.e20 = this._rotation20;
  7191. rotation.e21 = this._rotation21;
  7192. rotation.e22 = this._rotation22;
  7193. return rotation;
  7194. }
  7195. getRotationTo(out) {
  7196. out.e00 = this._rotation00;
  7197. out.e01 = this._rotation01;
  7198. out.e02 = this._rotation02;
  7199. out.e10 = this._rotation10;
  7200. out.e11 = this._rotation11;
  7201. out.e12 = this._rotation12;
  7202. out.e20 = this._rotation20;
  7203. out.e21 = this._rotation21;
  7204. out.e22 = this._rotation22;
  7205. }
  7206. setRotation(rotation) {
  7207. this._rotation00 = rotation.e00;
  7208. this._rotation01 = rotation.e01;
  7209. this._rotation02 = rotation.e02;
  7210. this._rotation10 = rotation.e10;
  7211. this._rotation11 = rotation.e11;
  7212. this._rotation12 = rotation.e12;
  7213. this._rotation20 = rotation.e20;
  7214. this._rotation21 = rotation.e21;
  7215. this._rotation22 = rotation.e22;
  7216. return this;
  7217. }
  7218. setRotationXyz(eulerAngles) {
  7219. let xyzX;
  7220. let xyzY;
  7221. let xyzZ;
  7222. xyzX = eulerAngles.x;
  7223. xyzY = eulerAngles.y;
  7224. xyzZ = eulerAngles.z;
  7225. let sx = Math.sin(xyzX);
  7226. let sy = Math.sin(xyzY);
  7227. let sz = Math.sin(xyzZ);
  7228. let cx = Math.cos(xyzX);
  7229. let cy = Math.cos(xyzY);
  7230. let cz = Math.cos(xyzZ);
  7231. this._rotation00 = cy * cz;
  7232. this._rotation01 = -cy * sz;
  7233. this._rotation02 = sy;
  7234. this._rotation10 = cx * sz + cz * sx * sy;
  7235. this._rotation11 = cx * cz - sx * sy * sz;
  7236. this._rotation12 = -cy * sx;
  7237. this._rotation20 = sx * sz - cx * cz * sy;
  7238. this._rotation21 = cz * sx + cx * sy * sz;
  7239. this._rotation22 = cx * cy;
  7240. }
  7241. rotate(rotation) {
  7242. let rot00;
  7243. let rot01;
  7244. let rot02;
  7245. let rot10;
  7246. let rot11;
  7247. let rot12;
  7248. let rot20;
  7249. let rot21;
  7250. let rot22;
  7251. rot00 = rotation.e00;
  7252. rot01 = rotation.e01;
  7253. rot02 = rotation.e02;
  7254. rot10 = rotation.e10;
  7255. rot11 = rotation.e11;
  7256. rot12 = rotation.e12;
  7257. rot20 = rotation.e20;
  7258. rot21 = rotation.e21;
  7259. rot22 = rotation.e22;
  7260. let __tmp__00;
  7261. let __tmp__01;
  7262. let __tmp__02;
  7263. let __tmp__10;
  7264. let __tmp__11;
  7265. let __tmp__12;
  7266. let __tmp__20;
  7267. let __tmp__21;
  7268. let __tmp__22;
  7269. __tmp__00 = rot00 * this._rotation00 + rot01 * this._rotation10 + rot02 * this._rotation20;
  7270. __tmp__01 = rot00 * this._rotation01 + rot01 * this._rotation11 + rot02 * this._rotation21;
  7271. __tmp__02 = rot00 * this._rotation02 + rot01 * this._rotation12 + rot02 * this._rotation22;
  7272. __tmp__10 = rot10 * this._rotation00 + rot11 * this._rotation10 + rot12 * this._rotation20;
  7273. __tmp__11 = rot10 * this._rotation01 + rot11 * this._rotation11 + rot12 * this._rotation21;
  7274. __tmp__12 = rot10 * this._rotation02 + rot11 * this._rotation12 + rot12 * this._rotation22;
  7275. __tmp__20 = rot20 * this._rotation00 + rot21 * this._rotation10 + rot22 * this._rotation20;
  7276. __tmp__21 = rot20 * this._rotation01 + rot21 * this._rotation11 + rot22 * this._rotation21;
  7277. __tmp__22 = rot20 * this._rotation02 + rot21 * this._rotation12 + rot22 * this._rotation22;
  7278. this._rotation00 = __tmp__00;
  7279. this._rotation01 = __tmp__01;
  7280. this._rotation02 = __tmp__02;
  7281. this._rotation10 = __tmp__10;
  7282. this._rotation11 = __tmp__11;
  7283. this._rotation12 = __tmp__12;
  7284. this._rotation20 = __tmp__20;
  7285. this._rotation21 = __tmp__21;
  7286. this._rotation22 = __tmp__22;
  7287. }
  7288. rotateXyz(eulerAngles) {
  7289. let xyzX;
  7290. let xyzY;
  7291. let xyzZ;
  7292. let rot00;
  7293. let rot01;
  7294. let rot02;
  7295. let rot10;
  7296. let rot11;
  7297. let rot12;
  7298. let rot20;
  7299. let rot21;
  7300. let rot22;
  7301. xyzX = eulerAngles.x;
  7302. xyzY = eulerAngles.y;
  7303. xyzZ = eulerAngles.z;
  7304. let sx = Math.sin(xyzX);
  7305. let sy = Math.sin(xyzY);
  7306. let sz = Math.sin(xyzZ);
  7307. let cx = Math.cos(xyzX);
  7308. let cy = Math.cos(xyzY);
  7309. let cz = Math.cos(xyzZ);
  7310. rot00 = cy * cz;
  7311. rot01 = -cy * sz;
  7312. rot02 = sy;
  7313. rot10 = cx * sz + cz * sx * sy;
  7314. rot11 = cx * cz - sx * sy * sz;
  7315. rot12 = -cy * sx;
  7316. rot20 = sx * sz - cx * cz * sy;
  7317. rot21 = cz * sx + cx * sy * sz;
  7318. rot22 = cx * cy;
  7319. let __tmp__00;
  7320. let __tmp__01;
  7321. let __tmp__02;
  7322. let __tmp__10;
  7323. let __tmp__11;
  7324. let __tmp__12;
  7325. let __tmp__20;
  7326. let __tmp__21;
  7327. let __tmp__22;
  7328. __tmp__00 = rot00 * this._rotation00 + rot01 * this._rotation10 + rot02 * this._rotation20;
  7329. __tmp__01 = rot00 * this._rotation01 + rot01 * this._rotation11 + rot02 * this._rotation21;
  7330. __tmp__02 = rot00 * this._rotation02 + rot01 * this._rotation12 + rot02 * this._rotation22;
  7331. __tmp__10 = rot10 * this._rotation00 + rot11 * this._rotation10 + rot12 * this._rotation20;
  7332. __tmp__11 = rot10 * this._rotation01 + rot11 * this._rotation11 + rot12 * this._rotation21;
  7333. __tmp__12 = rot10 * this._rotation02 + rot11 * this._rotation12 + rot12 * this._rotation22;
  7334. __tmp__20 = rot20 * this._rotation00 + rot21 * this._rotation10 + rot22 * this._rotation20;
  7335. __tmp__21 = rot20 * this._rotation01 + rot21 * this._rotation11 + rot22 * this._rotation21;
  7336. __tmp__22 = rot20 * this._rotation02 + rot21 * this._rotation12 + rot22 * this._rotation22;
  7337. this._rotation00 = __tmp__00;
  7338. this._rotation01 = __tmp__01;
  7339. this._rotation02 = __tmp__02;
  7340. this._rotation10 = __tmp__10;
  7341. this._rotation11 = __tmp__11;
  7342. this._rotation12 = __tmp__12;
  7343. this._rotation20 = __tmp__20;
  7344. this._rotation21 = __tmp__21;
  7345. this._rotation22 = __tmp__22;
  7346. }
  7347. getOrientation() {
  7348. let q = new oimo.common.Quat();
  7349. let iqX;
  7350. let iqY;
  7351. let iqZ;
  7352. let iqW;
  7353. let e00 = this._rotation00;
  7354. let e11 = this._rotation11;
  7355. let e22 = this._rotation22;
  7356. let t = e00 + e11 + e22;
  7357. let s;
  7358. if(t > 0) {
  7359. s = Math.sqrt(t + 1);
  7360. iqW = 0.5 * s;
  7361. s = 0.5 / s;
  7362. iqX = (this._rotation21 - this._rotation12) * s;
  7363. iqY = (this._rotation02 - this._rotation20) * s;
  7364. iqZ = (this._rotation10 - this._rotation01) * s;
  7365. } else if(e00 > e11) {
  7366. if(e00 > e22) {
  7367. s = Math.sqrt(e00 - e11 - e22 + 1);
  7368. iqX = 0.5 * s;
  7369. s = 0.5 / s;
  7370. iqY = (this._rotation01 + this._rotation10) * s;
  7371. iqZ = (this._rotation02 + this._rotation20) * s;
  7372. iqW = (this._rotation21 - this._rotation12) * s;
  7373. } else {
  7374. s = Math.sqrt(e22 - e00 - e11 + 1);
  7375. iqZ = 0.5 * s;
  7376. s = 0.5 / s;
  7377. iqX = (this._rotation02 + this._rotation20) * s;
  7378. iqY = (this._rotation12 + this._rotation21) * s;
  7379. iqW = (this._rotation10 - this._rotation01) * s;
  7380. }
  7381. } else if(e11 > e22) {
  7382. s = Math.sqrt(e11 - e22 - e00 + 1);
  7383. iqY = 0.5 * s;
  7384. s = 0.5 / s;
  7385. iqX = (this._rotation01 + this._rotation10) * s;
  7386. iqZ = (this._rotation12 + this._rotation21) * s;
  7387. iqW = (this._rotation02 - this._rotation20) * s;
  7388. } else {
  7389. s = Math.sqrt(e22 - e00 - e11 + 1);
  7390. iqZ = 0.5 * s;
  7391. s = 0.5 / s;
  7392. iqX = (this._rotation02 + this._rotation20) * s;
  7393. iqY = (this._rotation12 + this._rotation21) * s;
  7394. iqW = (this._rotation10 - this._rotation01) * s;
  7395. }
  7396. q.x = iqX;
  7397. q.y = iqY;
  7398. q.z = iqZ;
  7399. q.w = iqW;
  7400. return q;
  7401. }
  7402. getOrientationTo(orientation) {
  7403. let iqX;
  7404. let iqY;
  7405. let iqZ;
  7406. let iqW;
  7407. let e00 = this._rotation00;
  7408. let e11 = this._rotation11;
  7409. let e22 = this._rotation22;
  7410. let t = e00 + e11 + e22;
  7411. let s;
  7412. if(t > 0) {
  7413. s = Math.sqrt(t + 1);
  7414. iqW = 0.5 * s;
  7415. s = 0.5 / s;
  7416. iqX = (this._rotation21 - this._rotation12) * s;
  7417. iqY = (this._rotation02 - this._rotation20) * s;
  7418. iqZ = (this._rotation10 - this._rotation01) * s;
  7419. } else if(e00 > e11) {
  7420. if(e00 > e22) {
  7421. s = Math.sqrt(e00 - e11 - e22 + 1);
  7422. iqX = 0.5 * s;
  7423. s = 0.5 / s;
  7424. iqY = (this._rotation01 + this._rotation10) * s;
  7425. iqZ = (this._rotation02 + this._rotation20) * s;
  7426. iqW = (this._rotation21 - this._rotation12) * s;
  7427. } else {
  7428. s = Math.sqrt(e22 - e00 - e11 + 1);
  7429. iqZ = 0.5 * s;
  7430. s = 0.5 / s;
  7431. iqX = (this._rotation02 + this._rotation20) * s;
  7432. iqY = (this._rotation12 + this._rotation21) * s;
  7433. iqW = (this._rotation10 - this._rotation01) * s;
  7434. }
  7435. } else if(e11 > e22) {
  7436. s = Math.sqrt(e11 - e22 - e00 + 1);
  7437. iqY = 0.5 * s;
  7438. s = 0.5 / s;
  7439. iqX = (this._rotation01 + this._rotation10) * s;
  7440. iqZ = (this._rotation12 + this._rotation21) * s;
  7441. iqW = (this._rotation02 - this._rotation20) * s;
  7442. } else {
  7443. s = Math.sqrt(e22 - e00 - e11 + 1);
  7444. iqZ = 0.5 * s;
  7445. s = 0.5 / s;
  7446. iqX = (this._rotation02 + this._rotation20) * s;
  7447. iqY = (this._rotation12 + this._rotation21) * s;
  7448. iqW = (this._rotation10 - this._rotation01) * s;
  7449. }
  7450. orientation.x = iqX;
  7451. orientation.y = iqY;
  7452. orientation.z = iqZ;
  7453. orientation.w = iqW;
  7454. }
  7455. setOrientation(quaternion) {
  7456. let qX;
  7457. let qY;
  7458. let qZ;
  7459. let qW;
  7460. qX = quaternion.x;
  7461. qY = quaternion.y;
  7462. qZ = quaternion.z;
  7463. qW = quaternion.w;
  7464. let x = qX;
  7465. let y = qY;
  7466. let z = qZ;
  7467. let w = qW;
  7468. let x2 = 2 * x;
  7469. let y2 = 2 * y;
  7470. let z2 = 2 * z;
  7471. let xx = x * x2;
  7472. let yy = y * y2;
  7473. let zz = z * z2;
  7474. let xy = x * y2;
  7475. let yz = y * z2;
  7476. let xz = x * z2;
  7477. let wx = w * x2;
  7478. let wy = w * y2;
  7479. let wz = w * z2;
  7480. this._rotation00 = 1 - yy - zz;
  7481. this._rotation01 = xy - wz;
  7482. this._rotation02 = xz + wy;
  7483. this._rotation10 = xy + wz;
  7484. this._rotation11 = 1 - xx - zz;
  7485. this._rotation12 = yz - wx;
  7486. this._rotation20 = xz - wy;
  7487. this._rotation21 = yz + wx;
  7488. this._rotation22 = 1 - xx - yy;
  7489. return this;
  7490. }
  7491. clone() {
  7492. let tf = new oimo.common.Transform();
  7493. tf._positionX = this._positionX;
  7494. tf._positionY = this._positionY;
  7495. tf._positionZ = this._positionZ;
  7496. tf._rotation00 = this._rotation00;
  7497. tf._rotation01 = this._rotation01;
  7498. tf._rotation02 = this._rotation02;
  7499. tf._rotation10 = this._rotation10;
  7500. tf._rotation11 = this._rotation11;
  7501. tf._rotation12 = this._rotation12;
  7502. tf._rotation20 = this._rotation20;
  7503. tf._rotation21 = this._rotation21;
  7504. tf._rotation22 = this._rotation22;
  7505. return tf;
  7506. }
  7507. copyFrom(transform) {
  7508. this._positionX = transform._positionX;
  7509. this._positionY = transform._positionY;
  7510. this._positionZ = transform._positionZ;
  7511. this._rotation00 = transform._rotation00;
  7512. this._rotation01 = transform._rotation01;
  7513. this._rotation02 = transform._rotation02;
  7514. this._rotation10 = transform._rotation10;
  7515. this._rotation11 = transform._rotation11;
  7516. this._rotation12 = transform._rotation12;
  7517. this._rotation20 = transform._rotation20;
  7518. this._rotation21 = transform._rotation21;
  7519. this._rotation22 = transform._rotation22;
  7520. return this;
  7521. }
  7522. }
  7523. oimo.common.Setting = class oimo_common_Setting {
  7524. }
  7525. oimo.collision.narrowphase.detector.gjkepa.GjkEpa = class oimo_collision_narrowphase_detector_gjkepa_GjkEpa {
  7526. constructor() {
  7527. this.s = new Array(4);
  7528. this.w1 = new Array(4);
  7529. this.w2 = new Array(4);
  7530. this.baseDirs = new Array(3);
  7531. this.baseDirs[0] = new oimo.common.Vec3(1,0,0);
  7532. this.baseDirs[1] = new oimo.common.Vec3(0,1,0);
  7533. this.baseDirs[2] = new oimo.common.Vec3(0,0,1);
  7534. this.tl1 = new oimo.common.Vec3();
  7535. this.tl2 = new oimo.common.Vec3();
  7536. this.rayX = new oimo.common.Vec3();
  7537. this.rayR = new oimo.common.Vec3();
  7538. this.tempTransform = new oimo.common.Transform();
  7539. this.s[0] = new oimo.common.Vec3();
  7540. this.w1[0] = new oimo.common.Vec3();
  7541. this.w2[0] = new oimo.common.Vec3();
  7542. this.s[1] = new oimo.common.Vec3();
  7543. this.w1[1] = new oimo.common.Vec3();
  7544. this.w2[1] = new oimo.common.Vec3();
  7545. this.s[2] = new oimo.common.Vec3();
  7546. this.w1[2] = new oimo.common.Vec3();
  7547. this.w2[2] = new oimo.common.Vec3();
  7548. this.s[3] = new oimo.common.Vec3();
  7549. this.w1[3] = new oimo.common.Vec3();
  7550. this.w2[3] = new oimo.common.Vec3();
  7551. this.dir = new oimo.common.Vec3();
  7552. this.closest = new oimo.common.Vec3();
  7553. this.closestPoint1 = new oimo.common.Vec3();
  7554. this.closestPoint2 = new oimo.common.Vec3();
  7555. this.polyhedron = new oimo.collision.narrowphase.detector.gjkepa.EpaPolyhedron();
  7556. }
  7557. computeClosestPointsImpl(c1,c2,tf1,tf2,cache,useEpa) {
  7558. this.c1 = c1;
  7559. this.c2 = c2;
  7560. this.tf1 = tf1;
  7561. this.tf2 = tf2;
  7562. let s = this.s;
  7563. let w1 = this.w1;
  7564. let w2 = this.w2;
  7565. let closest = this.closest;
  7566. let dir = this.dir;
  7567. if(cache != null) {
  7568. if(cache._gjkCache == null) {
  7569. cache._gjkCache = new oimo.collision.narrowphase.detector.gjkepa.GjkCache();
  7570. }
  7571. this.loadCache(cache._gjkCache);
  7572. } else {
  7573. dir.zero();
  7574. }
  7575. if(dir.x * dir.x + dir.y * dir.y + dir.z * dir.z == 0) {
  7576. let firstDirX;
  7577. let firstDirY;
  7578. let firstDirZ;
  7579. firstDirX = tf2._positionX - tf1._positionX;
  7580. firstDirY = tf2._positionY - tf1._positionY;
  7581. firstDirZ = tf2._positionZ - tf1._positionZ;
  7582. dir.x = firstDirX;
  7583. dir.y = firstDirY;
  7584. dir.z = firstDirZ;
  7585. if(dir.x * dir.x + dir.y * dir.y + dir.z * dir.z < 1e-6) {
  7586. dir.init(1,0,0);
  7587. }
  7588. }
  7589. this.simplexSize = 0;
  7590. this.computeWitnessPoint1(false);
  7591. this.computeWitnessPoint2(false);
  7592. let _this = this.s[this.simplexSize];
  7593. let v = this.w1[this.simplexSize];
  7594. _this.x = v.x;
  7595. _this.y = v.y;
  7596. _this.z = v.z;
  7597. let v1 = this.w2[this.simplexSize];
  7598. _this.x -= v1.x;
  7599. _this.y -= v1.y;
  7600. _this.z -= v1.z;
  7601. this.simplexSize = 1;
  7602. let count = 0;
  7603. while(count < 40) {
  7604. let v = 0;
  7605. switch(this.simplexSize) {
  7606. case 1:
  7607. let v1 = s[0];
  7608. closest.x = v1.x;
  7609. closest.y = v1.y;
  7610. closest.z = v1.z;
  7611. v = 1;
  7612. break;
  7613. case 2:
  7614. let v1X;
  7615. let v1Y;
  7616. let v1Z;
  7617. let v2X;
  7618. let v2Y;
  7619. let v2Z;
  7620. let v2 = s[0];
  7621. v1X = v2.x;
  7622. v1Y = v2.y;
  7623. v1Z = v2.z;
  7624. let v3 = s[1];
  7625. v2X = v3.x;
  7626. v2Y = v3.y;
  7627. v2Z = v3.z;
  7628. let v12X;
  7629. let v12Y;
  7630. let v12Z;
  7631. v12X = v2X - v1X;
  7632. v12Y = v2Y - v1Y;
  7633. v12Z = v2Z - v1Z;
  7634. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  7635. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  7636. if(t < 0) {
  7637. closest.x = v1X;
  7638. closest.y = v1Y;
  7639. closest.z = v1Z;
  7640. v = 1;
  7641. } else if(t > 1) {
  7642. closest.x = v2X;
  7643. closest.y = v2Y;
  7644. closest.z = v2Z;
  7645. v = 2;
  7646. } else {
  7647. let pX;
  7648. let pY;
  7649. let pZ;
  7650. pX = v1X + v12X * t;
  7651. pY = v1Y + v12Y * t;
  7652. pZ = v1Z + v12Z * t;
  7653. closest.x = pX;
  7654. closest.y = pY;
  7655. closest.z = pZ;
  7656. v = 3;
  7657. }
  7658. break;
  7659. case 3:
  7660. let vec1 = s[0];
  7661. let vec2 = s[1];
  7662. let vec3 = s[2];
  7663. let v1X1;
  7664. let v1Y1;
  7665. let v1Z1;
  7666. let v2X1;
  7667. let v2Y1;
  7668. let v2Z1;
  7669. let v3X;
  7670. let v3Y;
  7671. let v3Z;
  7672. let v12X1;
  7673. let v12Y1;
  7674. let v12Z1;
  7675. let v23X;
  7676. let v23Y;
  7677. let v23Z;
  7678. let v31X;
  7679. let v31Y;
  7680. let v31Z;
  7681. v1X1 = vec1.x;
  7682. v1Y1 = vec1.y;
  7683. v1Z1 = vec1.z;
  7684. v2X1 = vec2.x;
  7685. v2Y1 = vec2.y;
  7686. v2Z1 = vec2.z;
  7687. v3X = vec3.x;
  7688. v3Y = vec3.y;
  7689. v3Z = vec3.z;
  7690. v12X1 = v2X1 - v1X1;
  7691. v12Y1 = v2Y1 - v1Y1;
  7692. v12Z1 = v2Z1 - v1Z1;
  7693. v23X = v3X - v2X1;
  7694. v23Y = v3Y - v2Y1;
  7695. v23Z = v3Z - v2Z1;
  7696. v31X = v1X1 - v3X;
  7697. v31Y = v1Y1 - v3Y;
  7698. v31Z = v1Z1 - v3Z;
  7699. let nX;
  7700. let nY;
  7701. let nZ;
  7702. nX = v12Y1 * v23Z - v12Z1 * v23Y;
  7703. nY = v12Z1 * v23X - v12X1 * v23Z;
  7704. nZ = v12X1 * v23Y - v12Y1 * v23X;
  7705. let n12X;
  7706. let n12Y;
  7707. let n12Z;
  7708. let n23X;
  7709. let n23Y;
  7710. let n23Z;
  7711. let n31X;
  7712. let n31Y;
  7713. let n31Z;
  7714. n12X = v12Y1 * nZ - v12Z1 * nY;
  7715. n12Y = v12Z1 * nX - v12X1 * nZ;
  7716. n12Z = v12X1 * nY - v12Y1 * nX;
  7717. n23X = v23Y * nZ - v23Z * nY;
  7718. n23Y = v23Z * nX - v23X * nZ;
  7719. n23Z = v23X * nY - v23Y * nX;
  7720. n31X = v31Y * nZ - v31Z * nY;
  7721. n31Y = v31Z * nX - v31X * nZ;
  7722. n31Z = v31X * nY - v31Y * nX;
  7723. let mind = -1;
  7724. let minvX;
  7725. let minvY;
  7726. let minvZ;
  7727. let mini = 0;
  7728. minvX = 0;
  7729. minvY = 0;
  7730. minvZ = 0;
  7731. if(v1X1 * n12X + v1Y1 * n12Y + v1Z1 * n12Z < 0) {
  7732. let v1X;
  7733. let v1Y;
  7734. let v1Z;
  7735. let v2X;
  7736. let v2Y;
  7737. let v2Z;
  7738. v1X = vec1.x;
  7739. v1Y = vec1.y;
  7740. v1Z = vec1.z;
  7741. v2X = vec2.x;
  7742. v2Y = vec2.y;
  7743. v2Z = vec2.z;
  7744. let v12X;
  7745. let v12Y;
  7746. let v12Z;
  7747. v12X = v2X - v1X;
  7748. v12Y = v2Y - v1Y;
  7749. v12Z = v2Z - v1Z;
  7750. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  7751. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  7752. let b;
  7753. if(t < 0) {
  7754. closest.x = v1X;
  7755. closest.y = v1Y;
  7756. closest.z = v1Z;
  7757. b = 1;
  7758. } else if(t > 1) {
  7759. closest.x = v2X;
  7760. closest.y = v2Y;
  7761. closest.z = v2Z;
  7762. b = 2;
  7763. } else {
  7764. let pX;
  7765. let pY;
  7766. let pZ;
  7767. pX = v1X + v12X * t;
  7768. pY = v1Y + v12Y * t;
  7769. pZ = v1Z + v12Z * t;
  7770. closest.x = pX;
  7771. closest.y = pY;
  7772. closest.z = pZ;
  7773. b = 3;
  7774. }
  7775. mini = b;
  7776. mind = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  7777. minvX = closest.x;
  7778. minvY = closest.y;
  7779. minvZ = closest.z;
  7780. }
  7781. if(v2X1 * n23X + v2Y1 * n23Y + v2Z1 * n23Z < 0) {
  7782. let v1X;
  7783. let v1Y;
  7784. let v1Z;
  7785. let v2X;
  7786. let v2Y;
  7787. let v2Z;
  7788. v1X = vec2.x;
  7789. v1Y = vec2.y;
  7790. v1Z = vec2.z;
  7791. v2X = vec3.x;
  7792. v2Y = vec3.y;
  7793. v2Z = vec3.z;
  7794. let v12X;
  7795. let v12Y;
  7796. let v12Z;
  7797. v12X = v2X - v1X;
  7798. v12Y = v2Y - v1Y;
  7799. v12Z = v2Z - v1Z;
  7800. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  7801. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  7802. let b;
  7803. if(t < 0) {
  7804. closest.x = v1X;
  7805. closest.y = v1Y;
  7806. closest.z = v1Z;
  7807. b = 1;
  7808. } else if(t > 1) {
  7809. closest.x = v2X;
  7810. closest.y = v2Y;
  7811. closest.z = v2Z;
  7812. b = 2;
  7813. } else {
  7814. let pX;
  7815. let pY;
  7816. let pZ;
  7817. pX = v1X + v12X * t;
  7818. pY = v1Y + v12Y * t;
  7819. pZ = v1Z + v12Z * t;
  7820. closest.x = pX;
  7821. closest.y = pY;
  7822. closest.z = pZ;
  7823. b = 3;
  7824. }
  7825. let d = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  7826. if(mind < 0 || d < mind) {
  7827. mini = b << 1;
  7828. mind = d;
  7829. minvX = closest.x;
  7830. minvY = closest.y;
  7831. minvZ = closest.z;
  7832. }
  7833. }
  7834. if(v3X * n31X + v3Y * n31Y + v3Z * n31Z < 0) {
  7835. let v1X;
  7836. let v1Y;
  7837. let v1Z;
  7838. let v2X;
  7839. let v2Y;
  7840. let v2Z;
  7841. v1X = vec1.x;
  7842. v1Y = vec1.y;
  7843. v1Z = vec1.z;
  7844. v2X = vec3.x;
  7845. v2Y = vec3.y;
  7846. v2Z = vec3.z;
  7847. let v12X;
  7848. let v12Y;
  7849. let v12Z;
  7850. v12X = v2X - v1X;
  7851. v12Y = v2Y - v1Y;
  7852. v12Z = v2Z - v1Z;
  7853. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  7854. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  7855. let b;
  7856. if(t < 0) {
  7857. closest.x = v1X;
  7858. closest.y = v1Y;
  7859. closest.z = v1Z;
  7860. b = 1;
  7861. } else if(t > 1) {
  7862. closest.x = v2X;
  7863. closest.y = v2Y;
  7864. closest.z = v2Z;
  7865. b = 2;
  7866. } else {
  7867. let pX;
  7868. let pY;
  7869. let pZ;
  7870. pX = v1X + v12X * t;
  7871. pY = v1Y + v12Y * t;
  7872. pZ = v1Z + v12Z * t;
  7873. closest.x = pX;
  7874. closest.y = pY;
  7875. closest.z = pZ;
  7876. b = 3;
  7877. }
  7878. let d = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  7879. if(mind < 0 || d < mind) {
  7880. mini = b & 1 | (b & 2) << 1;
  7881. mind = d;
  7882. minvX = closest.x;
  7883. minvY = closest.y;
  7884. minvZ = closest.z;
  7885. }
  7886. }
  7887. if(mind > 0) {
  7888. closest.x = minvX;
  7889. closest.y = minvY;
  7890. closest.z = minvZ;
  7891. v = mini;
  7892. } else {
  7893. let l = nX * nX + nY * nY + nZ * nZ;
  7894. if(l > 0) {
  7895. l = 1 / Math.sqrt(l);
  7896. }
  7897. nX *= l;
  7898. nY *= l;
  7899. nZ *= l;
  7900. let l2 = nX * nX + nY * nY + nZ * nZ;
  7901. l2 = (v1X1 * nX + v1Y1 * nY + v1Z1 * nZ) / l2;
  7902. minvX = nX * l2;
  7903. minvY = nY * l2;
  7904. minvZ = nZ * l2;
  7905. closest.x = minvX;
  7906. closest.y = minvY;
  7907. closest.z = minvZ;
  7908. v = 7;
  7909. }
  7910. break;
  7911. case 4:
  7912. let vec11 = s[0];
  7913. let vec21 = s[1];
  7914. let vec31 = s[2];
  7915. let vec4 = s[3];
  7916. let v1X2;
  7917. let v1Y2;
  7918. let v1Z2;
  7919. let v2X2;
  7920. let v2Y2;
  7921. let v2Z2;
  7922. let v3X1;
  7923. let v3Y1;
  7924. let v3Z1;
  7925. let v4X;
  7926. let v4Y;
  7927. let v4Z;
  7928. let v12X2;
  7929. let v12Y2;
  7930. let v12Z2;
  7931. let v13X;
  7932. let v13Y;
  7933. let v13Z;
  7934. let v14X;
  7935. let v14Y;
  7936. let v14Z;
  7937. let v23X1;
  7938. let v23Y1;
  7939. let v23Z1;
  7940. let v24X;
  7941. let v24Y;
  7942. let v24Z;
  7943. v1X2 = vec11.x;
  7944. v1Y2 = vec11.y;
  7945. v1Z2 = vec11.z;
  7946. v2X2 = vec21.x;
  7947. v2Y2 = vec21.y;
  7948. v2Z2 = vec21.z;
  7949. v3X1 = vec31.x;
  7950. v3Y1 = vec31.y;
  7951. v3Z1 = vec31.z;
  7952. v4X = vec4.x;
  7953. v4Y = vec4.y;
  7954. v4Z = vec4.z;
  7955. v12X2 = v2X2 - v1X2;
  7956. v12Y2 = v2Y2 - v1Y2;
  7957. v12Z2 = v2Z2 - v1Z2;
  7958. v13X = v3X1 - v1X2;
  7959. v13Y = v3Y1 - v1Y2;
  7960. v13Z = v3Z1 - v1Z2;
  7961. v14X = v4X - v1X2;
  7962. v14Y = v4Y - v1Y2;
  7963. v14Z = v4Z - v1Z2;
  7964. v23X1 = v3X1 - v2X2;
  7965. v23Y1 = v3Y1 - v2Y2;
  7966. v23Z1 = v3Z1 - v2Z2;
  7967. v24X = v4X - v2X2;
  7968. v24Y = v4Y - v2Y2;
  7969. v24Z = v4Z - v2Z2;
  7970. let n123X;
  7971. let n123Y;
  7972. let n123Z;
  7973. let n134X;
  7974. let n134Y;
  7975. let n134Z;
  7976. let n142X;
  7977. let n142Y;
  7978. let n142Z;
  7979. let n243X;
  7980. let n243Y;
  7981. let n243Z;
  7982. n123X = v12Y2 * v13Z - v12Z2 * v13Y;
  7983. n123Y = v12Z2 * v13X - v12X2 * v13Z;
  7984. n123Z = v12X2 * v13Y - v12Y2 * v13X;
  7985. n134X = v13Y * v14Z - v13Z * v14Y;
  7986. n134Y = v13Z * v14X - v13X * v14Z;
  7987. n134Z = v13X * v14Y - v13Y * v14X;
  7988. n142X = v14Y * v12Z2 - v14Z * v12Y2;
  7989. n142Y = v14Z * v12X2 - v14X * v12Z2;
  7990. n142Z = v14X * v12Y2 - v14Y * v12X2;
  7991. n243X = v24Y * v23Z1 - v24Z * v23Y1;
  7992. n243Y = v24Z * v23X1 - v24X * v23Z1;
  7993. n243Z = v24X * v23Y1 - v24Y * v23X1;
  7994. let sign = v12X2 * n243X + v12Y2 * n243Y + v12Z2 * n243Z > 0 ? 1 : -1;
  7995. let mind1 = -1;
  7996. let minvX1;
  7997. let minvY1;
  7998. let minvZ1;
  7999. let mini1 = 0;
  8000. minvX1 = 0;
  8001. minvY1 = 0;
  8002. minvZ1 = 0;
  8003. if((v1X2 * n123X + v1Y2 * n123Y + v1Z2 * n123Z) * sign < 0) {
  8004. let v1X;
  8005. let v1Y;
  8006. let v1Z;
  8007. let v2X;
  8008. let v2Y;
  8009. let v2Z;
  8010. let v3X;
  8011. let v3Y;
  8012. let v3Z;
  8013. let v12X;
  8014. let v12Y;
  8015. let v12Z;
  8016. let v23X;
  8017. let v23Y;
  8018. let v23Z;
  8019. let v31X;
  8020. let v31Y;
  8021. let v31Z;
  8022. v1X = vec11.x;
  8023. v1Y = vec11.y;
  8024. v1Z = vec11.z;
  8025. v2X = vec21.x;
  8026. v2Y = vec21.y;
  8027. v2Z = vec21.z;
  8028. v3X = vec31.x;
  8029. v3Y = vec31.y;
  8030. v3Z = vec31.z;
  8031. v12X = v2X - v1X;
  8032. v12Y = v2Y - v1Y;
  8033. v12Z = v2Z - v1Z;
  8034. v23X = v3X - v2X;
  8035. v23Y = v3Y - v2Y;
  8036. v23Z = v3Z - v2Z;
  8037. v31X = v1X - v3X;
  8038. v31Y = v1Y - v3Y;
  8039. v31Z = v1Z - v3Z;
  8040. let nX;
  8041. let nY;
  8042. let nZ;
  8043. nX = v12Y * v23Z - v12Z * v23Y;
  8044. nY = v12Z * v23X - v12X * v23Z;
  8045. nZ = v12X * v23Y - v12Y * v23X;
  8046. let n12X;
  8047. let n12Y;
  8048. let n12Z;
  8049. let n23X;
  8050. let n23Y;
  8051. let n23Z;
  8052. let n31X;
  8053. let n31Y;
  8054. let n31Z;
  8055. n12X = v12Y * nZ - v12Z * nY;
  8056. n12Y = v12Z * nX - v12X * nZ;
  8057. n12Z = v12X * nY - v12Y * nX;
  8058. n23X = v23Y * nZ - v23Z * nY;
  8059. n23Y = v23Z * nX - v23X * nZ;
  8060. n23Z = v23X * nY - v23Y * nX;
  8061. n31X = v31Y * nZ - v31Z * nY;
  8062. n31Y = v31Z * nX - v31X * nZ;
  8063. n31Z = v31X * nY - v31Y * nX;
  8064. let mind = -1;
  8065. let minvX;
  8066. let minvY;
  8067. let minvZ;
  8068. let mini = 0;
  8069. minvX = 0;
  8070. minvY = 0;
  8071. minvZ = 0;
  8072. if(v1X * n12X + v1Y * n12Y + v1Z * n12Z < 0) {
  8073. let v1X;
  8074. let v1Y;
  8075. let v1Z;
  8076. let v2X;
  8077. let v2Y;
  8078. let v2Z;
  8079. v1X = vec11.x;
  8080. v1Y = vec11.y;
  8081. v1Z = vec11.z;
  8082. v2X = vec21.x;
  8083. v2Y = vec21.y;
  8084. v2Z = vec21.z;
  8085. let v12X;
  8086. let v12Y;
  8087. let v12Z;
  8088. v12X = v2X - v1X;
  8089. v12Y = v2Y - v1Y;
  8090. v12Z = v2Z - v1Z;
  8091. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  8092. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  8093. let b;
  8094. if(t < 0) {
  8095. closest.x = v1X;
  8096. closest.y = v1Y;
  8097. closest.z = v1Z;
  8098. b = 1;
  8099. } else if(t > 1) {
  8100. closest.x = v2X;
  8101. closest.y = v2Y;
  8102. closest.z = v2Z;
  8103. b = 2;
  8104. } else {
  8105. let pX;
  8106. let pY;
  8107. let pZ;
  8108. pX = v1X + v12X * t;
  8109. pY = v1Y + v12Y * t;
  8110. pZ = v1Z + v12Z * t;
  8111. closest.x = pX;
  8112. closest.y = pY;
  8113. closest.z = pZ;
  8114. b = 3;
  8115. }
  8116. mini = b;
  8117. mind = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  8118. minvX = closest.x;
  8119. minvY = closest.y;
  8120. minvZ = closest.z;
  8121. }
  8122. if(v2X * n23X + v2Y * n23Y + v2Z * n23Z < 0) {
  8123. let v1X;
  8124. let v1Y;
  8125. let v1Z;
  8126. let v2X;
  8127. let v2Y;
  8128. let v2Z;
  8129. v1X = vec21.x;
  8130. v1Y = vec21.y;
  8131. v1Z = vec21.z;
  8132. v2X = vec31.x;
  8133. v2Y = vec31.y;
  8134. v2Z = vec31.z;
  8135. let v12X;
  8136. let v12Y;
  8137. let v12Z;
  8138. v12X = v2X - v1X;
  8139. v12Y = v2Y - v1Y;
  8140. v12Z = v2Z - v1Z;
  8141. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  8142. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  8143. let b;
  8144. if(t < 0) {
  8145. closest.x = v1X;
  8146. closest.y = v1Y;
  8147. closest.z = v1Z;
  8148. b = 1;
  8149. } else if(t > 1) {
  8150. closest.x = v2X;
  8151. closest.y = v2Y;
  8152. closest.z = v2Z;
  8153. b = 2;
  8154. } else {
  8155. let pX;
  8156. let pY;
  8157. let pZ;
  8158. pX = v1X + v12X * t;
  8159. pY = v1Y + v12Y * t;
  8160. pZ = v1Z + v12Z * t;
  8161. closest.x = pX;
  8162. closest.y = pY;
  8163. closest.z = pZ;
  8164. b = 3;
  8165. }
  8166. let d = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  8167. if(mind < 0 || d < mind) {
  8168. mini = b << 1;
  8169. mind = d;
  8170. minvX = closest.x;
  8171. minvY = closest.y;
  8172. minvZ = closest.z;
  8173. }
  8174. }
  8175. if(v3X * n31X + v3Y * n31Y + v3Z * n31Z < 0) {
  8176. let v1X;
  8177. let v1Y;
  8178. let v1Z;
  8179. let v2X;
  8180. let v2Y;
  8181. let v2Z;
  8182. v1X = vec11.x;
  8183. v1Y = vec11.y;
  8184. v1Z = vec11.z;
  8185. v2X = vec31.x;
  8186. v2Y = vec31.y;
  8187. v2Z = vec31.z;
  8188. let v12X;
  8189. let v12Y;
  8190. let v12Z;
  8191. v12X = v2X - v1X;
  8192. v12Y = v2Y - v1Y;
  8193. v12Z = v2Z - v1Z;
  8194. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  8195. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  8196. let b;
  8197. if(t < 0) {
  8198. closest.x = v1X;
  8199. closest.y = v1Y;
  8200. closest.z = v1Z;
  8201. b = 1;
  8202. } else if(t > 1) {
  8203. closest.x = v2X;
  8204. closest.y = v2Y;
  8205. closest.z = v2Z;
  8206. b = 2;
  8207. } else {
  8208. let pX;
  8209. let pY;
  8210. let pZ;
  8211. pX = v1X + v12X * t;
  8212. pY = v1Y + v12Y * t;
  8213. pZ = v1Z + v12Z * t;
  8214. closest.x = pX;
  8215. closest.y = pY;
  8216. closest.z = pZ;
  8217. b = 3;
  8218. }
  8219. let d = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  8220. if(mind < 0 || d < mind) {
  8221. mini = b & 1 | (b & 2) << 1;
  8222. mind = d;
  8223. minvX = closest.x;
  8224. minvY = closest.y;
  8225. minvZ = closest.z;
  8226. }
  8227. }
  8228. let b;
  8229. if(mind > 0) {
  8230. closest.x = minvX;
  8231. closest.y = minvY;
  8232. closest.z = minvZ;
  8233. b = mini;
  8234. } else {
  8235. let l = nX * nX + nY * nY + nZ * nZ;
  8236. if(l > 0) {
  8237. l = 1 / Math.sqrt(l);
  8238. }
  8239. nX *= l;
  8240. nY *= l;
  8241. nZ *= l;
  8242. let l2 = nX * nX + nY * nY + nZ * nZ;
  8243. l2 = (v1X * nX + v1Y * nY + v1Z * nZ) / l2;
  8244. minvX = nX * l2;
  8245. minvY = nY * l2;
  8246. minvZ = nZ * l2;
  8247. closest.x = minvX;
  8248. closest.y = minvY;
  8249. closest.z = minvZ;
  8250. b = 7;
  8251. }
  8252. mini1 = b;
  8253. mind1 = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  8254. minvX1 = closest.x;
  8255. minvY1 = closest.y;
  8256. minvZ1 = closest.z;
  8257. }
  8258. if((v1X2 * n134X + v1Y2 * n134Y + v1Z2 * n134Z) * sign < 0) {
  8259. let v1X;
  8260. let v1Y;
  8261. let v1Z;
  8262. let v2X;
  8263. let v2Y;
  8264. let v2Z;
  8265. let v3X;
  8266. let v3Y;
  8267. let v3Z;
  8268. let v12X;
  8269. let v12Y;
  8270. let v12Z;
  8271. let v23X;
  8272. let v23Y;
  8273. let v23Z;
  8274. let v31X;
  8275. let v31Y;
  8276. let v31Z;
  8277. v1X = vec11.x;
  8278. v1Y = vec11.y;
  8279. v1Z = vec11.z;
  8280. v2X = vec31.x;
  8281. v2Y = vec31.y;
  8282. v2Z = vec31.z;
  8283. v3X = vec4.x;
  8284. v3Y = vec4.y;
  8285. v3Z = vec4.z;
  8286. v12X = v2X - v1X;
  8287. v12Y = v2Y - v1Y;
  8288. v12Z = v2Z - v1Z;
  8289. v23X = v3X - v2X;
  8290. v23Y = v3Y - v2Y;
  8291. v23Z = v3Z - v2Z;
  8292. v31X = v1X - v3X;
  8293. v31Y = v1Y - v3Y;
  8294. v31Z = v1Z - v3Z;
  8295. let nX;
  8296. let nY;
  8297. let nZ;
  8298. nX = v12Y * v23Z - v12Z * v23Y;
  8299. nY = v12Z * v23X - v12X * v23Z;
  8300. nZ = v12X * v23Y - v12Y * v23X;
  8301. let n12X;
  8302. let n12Y;
  8303. let n12Z;
  8304. let n23X;
  8305. let n23Y;
  8306. let n23Z;
  8307. let n31X;
  8308. let n31Y;
  8309. let n31Z;
  8310. n12X = v12Y * nZ - v12Z * nY;
  8311. n12Y = v12Z * nX - v12X * nZ;
  8312. n12Z = v12X * nY - v12Y * nX;
  8313. n23X = v23Y * nZ - v23Z * nY;
  8314. n23Y = v23Z * nX - v23X * nZ;
  8315. n23Z = v23X * nY - v23Y * nX;
  8316. n31X = v31Y * nZ - v31Z * nY;
  8317. n31Y = v31Z * nX - v31X * nZ;
  8318. n31Z = v31X * nY - v31Y * nX;
  8319. let mind = -1;
  8320. let minvX;
  8321. let minvY;
  8322. let minvZ;
  8323. let mini = 0;
  8324. minvX = 0;
  8325. minvY = 0;
  8326. minvZ = 0;
  8327. if(v1X * n12X + v1Y * n12Y + v1Z * n12Z < 0) {
  8328. let v1X;
  8329. let v1Y;
  8330. let v1Z;
  8331. let v2X;
  8332. let v2Y;
  8333. let v2Z;
  8334. v1X = vec11.x;
  8335. v1Y = vec11.y;
  8336. v1Z = vec11.z;
  8337. v2X = vec31.x;
  8338. v2Y = vec31.y;
  8339. v2Z = vec31.z;
  8340. let v12X;
  8341. let v12Y;
  8342. let v12Z;
  8343. v12X = v2X - v1X;
  8344. v12Y = v2Y - v1Y;
  8345. v12Z = v2Z - v1Z;
  8346. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  8347. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  8348. let b;
  8349. if(t < 0) {
  8350. closest.x = v1X;
  8351. closest.y = v1Y;
  8352. closest.z = v1Z;
  8353. b = 1;
  8354. } else if(t > 1) {
  8355. closest.x = v2X;
  8356. closest.y = v2Y;
  8357. closest.z = v2Z;
  8358. b = 2;
  8359. } else {
  8360. let pX;
  8361. let pY;
  8362. let pZ;
  8363. pX = v1X + v12X * t;
  8364. pY = v1Y + v12Y * t;
  8365. pZ = v1Z + v12Z * t;
  8366. closest.x = pX;
  8367. closest.y = pY;
  8368. closest.z = pZ;
  8369. b = 3;
  8370. }
  8371. mini = b;
  8372. mind = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  8373. minvX = closest.x;
  8374. minvY = closest.y;
  8375. minvZ = closest.z;
  8376. }
  8377. if(v2X * n23X + v2Y * n23Y + v2Z * n23Z < 0) {
  8378. let v1X;
  8379. let v1Y;
  8380. let v1Z;
  8381. let v2X;
  8382. let v2Y;
  8383. let v2Z;
  8384. v1X = vec31.x;
  8385. v1Y = vec31.y;
  8386. v1Z = vec31.z;
  8387. v2X = vec4.x;
  8388. v2Y = vec4.y;
  8389. v2Z = vec4.z;
  8390. let v12X;
  8391. let v12Y;
  8392. let v12Z;
  8393. v12X = v2X - v1X;
  8394. v12Y = v2Y - v1Y;
  8395. v12Z = v2Z - v1Z;
  8396. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  8397. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  8398. let b;
  8399. if(t < 0) {
  8400. closest.x = v1X;
  8401. closest.y = v1Y;
  8402. closest.z = v1Z;
  8403. b = 1;
  8404. } else if(t > 1) {
  8405. closest.x = v2X;
  8406. closest.y = v2Y;
  8407. closest.z = v2Z;
  8408. b = 2;
  8409. } else {
  8410. let pX;
  8411. let pY;
  8412. let pZ;
  8413. pX = v1X + v12X * t;
  8414. pY = v1Y + v12Y * t;
  8415. pZ = v1Z + v12Z * t;
  8416. closest.x = pX;
  8417. closest.y = pY;
  8418. closest.z = pZ;
  8419. b = 3;
  8420. }
  8421. let d = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  8422. if(mind < 0 || d < mind) {
  8423. mini = b << 1;
  8424. mind = d;
  8425. minvX = closest.x;
  8426. minvY = closest.y;
  8427. minvZ = closest.z;
  8428. }
  8429. }
  8430. if(v3X * n31X + v3Y * n31Y + v3Z * n31Z < 0) {
  8431. let v1X;
  8432. let v1Y;
  8433. let v1Z;
  8434. let v2X;
  8435. let v2Y;
  8436. let v2Z;
  8437. v1X = vec11.x;
  8438. v1Y = vec11.y;
  8439. v1Z = vec11.z;
  8440. v2X = vec4.x;
  8441. v2Y = vec4.y;
  8442. v2Z = vec4.z;
  8443. let v12X;
  8444. let v12Y;
  8445. let v12Z;
  8446. v12X = v2X - v1X;
  8447. v12Y = v2Y - v1Y;
  8448. v12Z = v2Z - v1Z;
  8449. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  8450. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  8451. let b;
  8452. if(t < 0) {
  8453. closest.x = v1X;
  8454. closest.y = v1Y;
  8455. closest.z = v1Z;
  8456. b = 1;
  8457. } else if(t > 1) {
  8458. closest.x = v2X;
  8459. closest.y = v2Y;
  8460. closest.z = v2Z;
  8461. b = 2;
  8462. } else {
  8463. let pX;
  8464. let pY;
  8465. let pZ;
  8466. pX = v1X + v12X * t;
  8467. pY = v1Y + v12Y * t;
  8468. pZ = v1Z + v12Z * t;
  8469. closest.x = pX;
  8470. closest.y = pY;
  8471. closest.z = pZ;
  8472. b = 3;
  8473. }
  8474. let d = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  8475. if(mind < 0 || d < mind) {
  8476. mini = b & 1 | (b & 2) << 1;
  8477. mind = d;
  8478. minvX = closest.x;
  8479. minvY = closest.y;
  8480. minvZ = closest.z;
  8481. }
  8482. }
  8483. let b;
  8484. if(mind > 0) {
  8485. closest.x = minvX;
  8486. closest.y = minvY;
  8487. closest.z = minvZ;
  8488. b = mini;
  8489. } else {
  8490. let l = nX * nX + nY * nY + nZ * nZ;
  8491. if(l > 0) {
  8492. l = 1 / Math.sqrt(l);
  8493. }
  8494. nX *= l;
  8495. nY *= l;
  8496. nZ *= l;
  8497. let l2 = nX * nX + nY * nY + nZ * nZ;
  8498. l2 = (v1X * nX + v1Y * nY + v1Z * nZ) / l2;
  8499. minvX = nX * l2;
  8500. minvY = nY * l2;
  8501. minvZ = nZ * l2;
  8502. closest.x = minvX;
  8503. closest.y = minvY;
  8504. closest.z = minvZ;
  8505. b = 7;
  8506. }
  8507. let d = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  8508. if(mind1 < 0 || d < mind1) {
  8509. mini1 = b & 1 | (b & 6) << 1;
  8510. mind1 = d;
  8511. minvX1 = closest.x;
  8512. minvY1 = closest.y;
  8513. minvZ1 = closest.z;
  8514. }
  8515. }
  8516. if((v1X2 * n142X + v1Y2 * n142Y + v1Z2 * n142Z) * sign < 0) {
  8517. let v1X;
  8518. let v1Y;
  8519. let v1Z;
  8520. let v2X;
  8521. let v2Y;
  8522. let v2Z;
  8523. let v3X;
  8524. let v3Y;
  8525. let v3Z;
  8526. let v12X;
  8527. let v12Y;
  8528. let v12Z;
  8529. let v23X;
  8530. let v23Y;
  8531. let v23Z;
  8532. let v31X;
  8533. let v31Y;
  8534. let v31Z;
  8535. v1X = vec11.x;
  8536. v1Y = vec11.y;
  8537. v1Z = vec11.z;
  8538. v2X = vec21.x;
  8539. v2Y = vec21.y;
  8540. v2Z = vec21.z;
  8541. v3X = vec4.x;
  8542. v3Y = vec4.y;
  8543. v3Z = vec4.z;
  8544. v12X = v2X - v1X;
  8545. v12Y = v2Y - v1Y;
  8546. v12Z = v2Z - v1Z;
  8547. v23X = v3X - v2X;
  8548. v23Y = v3Y - v2Y;
  8549. v23Z = v3Z - v2Z;
  8550. v31X = v1X - v3X;
  8551. v31Y = v1Y - v3Y;
  8552. v31Z = v1Z - v3Z;
  8553. let nX;
  8554. let nY;
  8555. let nZ;
  8556. nX = v12Y * v23Z - v12Z * v23Y;
  8557. nY = v12Z * v23X - v12X * v23Z;
  8558. nZ = v12X * v23Y - v12Y * v23X;
  8559. let n12X;
  8560. let n12Y;
  8561. let n12Z;
  8562. let n23X;
  8563. let n23Y;
  8564. let n23Z;
  8565. let n31X;
  8566. let n31Y;
  8567. let n31Z;
  8568. n12X = v12Y * nZ - v12Z * nY;
  8569. n12Y = v12Z * nX - v12X * nZ;
  8570. n12Z = v12X * nY - v12Y * nX;
  8571. n23X = v23Y * nZ - v23Z * nY;
  8572. n23Y = v23Z * nX - v23X * nZ;
  8573. n23Z = v23X * nY - v23Y * nX;
  8574. n31X = v31Y * nZ - v31Z * nY;
  8575. n31Y = v31Z * nX - v31X * nZ;
  8576. n31Z = v31X * nY - v31Y * nX;
  8577. let mind = -1;
  8578. let minvX;
  8579. let minvY;
  8580. let minvZ;
  8581. let mini = 0;
  8582. minvX = 0;
  8583. minvY = 0;
  8584. minvZ = 0;
  8585. if(v1X * n12X + v1Y * n12Y + v1Z * n12Z < 0) {
  8586. let v1X;
  8587. let v1Y;
  8588. let v1Z;
  8589. let v2X;
  8590. let v2Y;
  8591. let v2Z;
  8592. v1X = vec11.x;
  8593. v1Y = vec11.y;
  8594. v1Z = vec11.z;
  8595. v2X = vec21.x;
  8596. v2Y = vec21.y;
  8597. v2Z = vec21.z;
  8598. let v12X;
  8599. let v12Y;
  8600. let v12Z;
  8601. v12X = v2X - v1X;
  8602. v12Y = v2Y - v1Y;
  8603. v12Z = v2Z - v1Z;
  8604. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  8605. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  8606. let b;
  8607. if(t < 0) {
  8608. closest.x = v1X;
  8609. closest.y = v1Y;
  8610. closest.z = v1Z;
  8611. b = 1;
  8612. } else if(t > 1) {
  8613. closest.x = v2X;
  8614. closest.y = v2Y;
  8615. closest.z = v2Z;
  8616. b = 2;
  8617. } else {
  8618. let pX;
  8619. let pY;
  8620. let pZ;
  8621. pX = v1X + v12X * t;
  8622. pY = v1Y + v12Y * t;
  8623. pZ = v1Z + v12Z * t;
  8624. closest.x = pX;
  8625. closest.y = pY;
  8626. closest.z = pZ;
  8627. b = 3;
  8628. }
  8629. mini = b;
  8630. mind = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  8631. minvX = closest.x;
  8632. minvY = closest.y;
  8633. minvZ = closest.z;
  8634. }
  8635. if(v2X * n23X + v2Y * n23Y + v2Z * n23Z < 0) {
  8636. let v1X;
  8637. let v1Y;
  8638. let v1Z;
  8639. let v2X;
  8640. let v2Y;
  8641. let v2Z;
  8642. v1X = vec21.x;
  8643. v1Y = vec21.y;
  8644. v1Z = vec21.z;
  8645. v2X = vec4.x;
  8646. v2Y = vec4.y;
  8647. v2Z = vec4.z;
  8648. let v12X;
  8649. let v12Y;
  8650. let v12Z;
  8651. v12X = v2X - v1X;
  8652. v12Y = v2Y - v1Y;
  8653. v12Z = v2Z - v1Z;
  8654. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  8655. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  8656. let b;
  8657. if(t < 0) {
  8658. closest.x = v1X;
  8659. closest.y = v1Y;
  8660. closest.z = v1Z;
  8661. b = 1;
  8662. } else if(t > 1) {
  8663. closest.x = v2X;
  8664. closest.y = v2Y;
  8665. closest.z = v2Z;
  8666. b = 2;
  8667. } else {
  8668. let pX;
  8669. let pY;
  8670. let pZ;
  8671. pX = v1X + v12X * t;
  8672. pY = v1Y + v12Y * t;
  8673. pZ = v1Z + v12Z * t;
  8674. closest.x = pX;
  8675. closest.y = pY;
  8676. closest.z = pZ;
  8677. b = 3;
  8678. }
  8679. let d = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  8680. if(mind < 0 || d < mind) {
  8681. mini = b << 1;
  8682. mind = d;
  8683. minvX = closest.x;
  8684. minvY = closest.y;
  8685. minvZ = closest.z;
  8686. }
  8687. }
  8688. if(v3X * n31X + v3Y * n31Y + v3Z * n31Z < 0) {
  8689. let v1X;
  8690. let v1Y;
  8691. let v1Z;
  8692. let v2X;
  8693. let v2Y;
  8694. let v2Z;
  8695. v1X = vec11.x;
  8696. v1Y = vec11.y;
  8697. v1Z = vec11.z;
  8698. v2X = vec4.x;
  8699. v2Y = vec4.y;
  8700. v2Z = vec4.z;
  8701. let v12X;
  8702. let v12Y;
  8703. let v12Z;
  8704. v12X = v2X - v1X;
  8705. v12Y = v2Y - v1Y;
  8706. v12Z = v2Z - v1Z;
  8707. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  8708. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  8709. let b;
  8710. if(t < 0) {
  8711. closest.x = v1X;
  8712. closest.y = v1Y;
  8713. closest.z = v1Z;
  8714. b = 1;
  8715. } else if(t > 1) {
  8716. closest.x = v2X;
  8717. closest.y = v2Y;
  8718. closest.z = v2Z;
  8719. b = 2;
  8720. } else {
  8721. let pX;
  8722. let pY;
  8723. let pZ;
  8724. pX = v1X + v12X * t;
  8725. pY = v1Y + v12Y * t;
  8726. pZ = v1Z + v12Z * t;
  8727. closest.x = pX;
  8728. closest.y = pY;
  8729. closest.z = pZ;
  8730. b = 3;
  8731. }
  8732. let d = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  8733. if(mind < 0 || d < mind) {
  8734. mini = b & 1 | (b & 2) << 1;
  8735. mind = d;
  8736. minvX = closest.x;
  8737. minvY = closest.y;
  8738. minvZ = closest.z;
  8739. }
  8740. }
  8741. let b;
  8742. if(mind > 0) {
  8743. closest.x = minvX;
  8744. closest.y = minvY;
  8745. closest.z = minvZ;
  8746. b = mini;
  8747. } else {
  8748. let l = nX * nX + nY * nY + nZ * nZ;
  8749. if(l > 0) {
  8750. l = 1 / Math.sqrt(l);
  8751. }
  8752. nX *= l;
  8753. nY *= l;
  8754. nZ *= l;
  8755. let l2 = nX * nX + nY * nY + nZ * nZ;
  8756. l2 = (v1X * nX + v1Y * nY + v1Z * nZ) / l2;
  8757. minvX = nX * l2;
  8758. minvY = nY * l2;
  8759. minvZ = nZ * l2;
  8760. closest.x = minvX;
  8761. closest.y = minvY;
  8762. closest.z = minvZ;
  8763. b = 7;
  8764. }
  8765. let d = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  8766. if(mind1 < 0 || d < mind1) {
  8767. mini1 = b & 3 | (b & 4) << 1;
  8768. mind1 = d;
  8769. minvX1 = closest.x;
  8770. minvY1 = closest.y;
  8771. minvZ1 = closest.z;
  8772. }
  8773. }
  8774. if((v2X2 * n243X + v2Y2 * n243Y + v2Z2 * n243Z) * sign < 0) {
  8775. let v1X;
  8776. let v1Y;
  8777. let v1Z;
  8778. let v2X;
  8779. let v2Y;
  8780. let v2Z;
  8781. let v3X;
  8782. let v3Y;
  8783. let v3Z;
  8784. let v12X;
  8785. let v12Y;
  8786. let v12Z;
  8787. let v23X;
  8788. let v23Y;
  8789. let v23Z;
  8790. let v31X;
  8791. let v31Y;
  8792. let v31Z;
  8793. v1X = vec21.x;
  8794. v1Y = vec21.y;
  8795. v1Z = vec21.z;
  8796. v2X = vec31.x;
  8797. v2Y = vec31.y;
  8798. v2Z = vec31.z;
  8799. v3X = vec4.x;
  8800. v3Y = vec4.y;
  8801. v3Z = vec4.z;
  8802. v12X = v2X - v1X;
  8803. v12Y = v2Y - v1Y;
  8804. v12Z = v2Z - v1Z;
  8805. v23X = v3X - v2X;
  8806. v23Y = v3Y - v2Y;
  8807. v23Z = v3Z - v2Z;
  8808. v31X = v1X - v3X;
  8809. v31Y = v1Y - v3Y;
  8810. v31Z = v1Z - v3Z;
  8811. let nX;
  8812. let nY;
  8813. let nZ;
  8814. nX = v12Y * v23Z - v12Z * v23Y;
  8815. nY = v12Z * v23X - v12X * v23Z;
  8816. nZ = v12X * v23Y - v12Y * v23X;
  8817. let n12X;
  8818. let n12Y;
  8819. let n12Z;
  8820. let n23X;
  8821. let n23Y;
  8822. let n23Z;
  8823. let n31X;
  8824. let n31Y;
  8825. let n31Z;
  8826. n12X = v12Y * nZ - v12Z * nY;
  8827. n12Y = v12Z * nX - v12X * nZ;
  8828. n12Z = v12X * nY - v12Y * nX;
  8829. n23X = v23Y * nZ - v23Z * nY;
  8830. n23Y = v23Z * nX - v23X * nZ;
  8831. n23Z = v23X * nY - v23Y * nX;
  8832. n31X = v31Y * nZ - v31Z * nY;
  8833. n31Y = v31Z * nX - v31X * nZ;
  8834. n31Z = v31X * nY - v31Y * nX;
  8835. let mind = -1;
  8836. let minvX;
  8837. let minvY;
  8838. let minvZ;
  8839. let mini = 0;
  8840. minvX = 0;
  8841. minvY = 0;
  8842. minvZ = 0;
  8843. if(v1X * n12X + v1Y * n12Y + v1Z * n12Z < 0) {
  8844. let v1X;
  8845. let v1Y;
  8846. let v1Z;
  8847. let v2X;
  8848. let v2Y;
  8849. let v2Z;
  8850. v1X = vec21.x;
  8851. v1Y = vec21.y;
  8852. v1Z = vec21.z;
  8853. v2X = vec31.x;
  8854. v2Y = vec31.y;
  8855. v2Z = vec31.z;
  8856. let v12X;
  8857. let v12Y;
  8858. let v12Z;
  8859. v12X = v2X - v1X;
  8860. v12Y = v2Y - v1Y;
  8861. v12Z = v2Z - v1Z;
  8862. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  8863. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  8864. let b;
  8865. if(t < 0) {
  8866. closest.x = v1X;
  8867. closest.y = v1Y;
  8868. closest.z = v1Z;
  8869. b = 1;
  8870. } else if(t > 1) {
  8871. closest.x = v2X;
  8872. closest.y = v2Y;
  8873. closest.z = v2Z;
  8874. b = 2;
  8875. } else {
  8876. let pX;
  8877. let pY;
  8878. let pZ;
  8879. pX = v1X + v12X * t;
  8880. pY = v1Y + v12Y * t;
  8881. pZ = v1Z + v12Z * t;
  8882. closest.x = pX;
  8883. closest.y = pY;
  8884. closest.z = pZ;
  8885. b = 3;
  8886. }
  8887. mini = b;
  8888. mind = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  8889. minvX = closest.x;
  8890. minvY = closest.y;
  8891. minvZ = closest.z;
  8892. }
  8893. if(v2X * n23X + v2Y * n23Y + v2Z * n23Z < 0) {
  8894. let v1X;
  8895. let v1Y;
  8896. let v1Z;
  8897. let v2X;
  8898. let v2Y;
  8899. let v2Z;
  8900. v1X = vec31.x;
  8901. v1Y = vec31.y;
  8902. v1Z = vec31.z;
  8903. v2X = vec4.x;
  8904. v2Y = vec4.y;
  8905. v2Z = vec4.z;
  8906. let v12X;
  8907. let v12Y;
  8908. let v12Z;
  8909. v12X = v2X - v1X;
  8910. v12Y = v2Y - v1Y;
  8911. v12Z = v2Z - v1Z;
  8912. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  8913. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  8914. let b;
  8915. if(t < 0) {
  8916. closest.x = v1X;
  8917. closest.y = v1Y;
  8918. closest.z = v1Z;
  8919. b = 1;
  8920. } else if(t > 1) {
  8921. closest.x = v2X;
  8922. closest.y = v2Y;
  8923. closest.z = v2Z;
  8924. b = 2;
  8925. } else {
  8926. let pX;
  8927. let pY;
  8928. let pZ;
  8929. pX = v1X + v12X * t;
  8930. pY = v1Y + v12Y * t;
  8931. pZ = v1Z + v12Z * t;
  8932. closest.x = pX;
  8933. closest.y = pY;
  8934. closest.z = pZ;
  8935. b = 3;
  8936. }
  8937. let d = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  8938. if(mind < 0 || d < mind) {
  8939. mini = b << 1;
  8940. mind = d;
  8941. minvX = closest.x;
  8942. minvY = closest.y;
  8943. minvZ = closest.z;
  8944. }
  8945. }
  8946. if(v3X * n31X + v3Y * n31Y + v3Z * n31Z < 0) {
  8947. let v1X;
  8948. let v1Y;
  8949. let v1Z;
  8950. let v2X;
  8951. let v2Y;
  8952. let v2Z;
  8953. v1X = vec21.x;
  8954. v1Y = vec21.y;
  8955. v1Z = vec21.z;
  8956. v2X = vec4.x;
  8957. v2Y = vec4.y;
  8958. v2Z = vec4.z;
  8959. let v12X;
  8960. let v12Y;
  8961. let v12Z;
  8962. v12X = v2X - v1X;
  8963. v12Y = v2Y - v1Y;
  8964. v12Z = v2Z - v1Z;
  8965. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  8966. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  8967. let b;
  8968. if(t < 0) {
  8969. closest.x = v1X;
  8970. closest.y = v1Y;
  8971. closest.z = v1Z;
  8972. b = 1;
  8973. } else if(t > 1) {
  8974. closest.x = v2X;
  8975. closest.y = v2Y;
  8976. closest.z = v2Z;
  8977. b = 2;
  8978. } else {
  8979. let pX;
  8980. let pY;
  8981. let pZ;
  8982. pX = v1X + v12X * t;
  8983. pY = v1Y + v12Y * t;
  8984. pZ = v1Z + v12Z * t;
  8985. closest.x = pX;
  8986. closest.y = pY;
  8987. closest.z = pZ;
  8988. b = 3;
  8989. }
  8990. let d = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  8991. if(mind < 0 || d < mind) {
  8992. mini = b & 1 | (b & 2) << 1;
  8993. mind = d;
  8994. minvX = closest.x;
  8995. minvY = closest.y;
  8996. minvZ = closest.z;
  8997. }
  8998. }
  8999. let b;
  9000. if(mind > 0) {
  9001. closest.x = minvX;
  9002. closest.y = minvY;
  9003. closest.z = minvZ;
  9004. b = mini;
  9005. } else {
  9006. let l = nX * nX + nY * nY + nZ * nZ;
  9007. if(l > 0) {
  9008. l = 1 / Math.sqrt(l);
  9009. }
  9010. nX *= l;
  9011. nY *= l;
  9012. nZ *= l;
  9013. let l2 = nX * nX + nY * nY + nZ * nZ;
  9014. l2 = (v1X * nX + v1Y * nY + v1Z * nZ) / l2;
  9015. minvX = nX * l2;
  9016. minvY = nY * l2;
  9017. minvZ = nZ * l2;
  9018. closest.x = minvX;
  9019. closest.y = minvY;
  9020. closest.z = minvZ;
  9021. b = 7;
  9022. }
  9023. let d = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  9024. if(mind1 < 0 || d < mind1) {
  9025. mini1 = b << 1;
  9026. mind1 = d;
  9027. minvX1 = closest.x;
  9028. minvY1 = closest.y;
  9029. minvZ1 = closest.z;
  9030. }
  9031. }
  9032. if(mind1 > 0) {
  9033. closest.x = minvX1;
  9034. closest.y = minvY1;
  9035. closest.z = minvZ1;
  9036. v = mini1;
  9037. } else {
  9038. closest.zero();
  9039. v = 15;
  9040. }
  9041. break;
  9042. }
  9043. if(closest.x * closest.x + closest.y * closest.y + closest.z * closest.z < 1e-008) {
  9044. if(!useEpa) {
  9045. this.distance = 0;
  9046. return 0;
  9047. }
  9048. switch(this.simplexSize) {
  9049. case 1:
  9050. this.pointToTetrahedron();
  9051. break;
  9052. case 2:
  9053. this.lineToTetrahedron();
  9054. break;
  9055. case 3:
  9056. this.triangleToTetrahedron();
  9057. break;
  9058. }
  9059. if(this.simplexSize == 4) {
  9060. let epaState = this.computeDepth(c1,c2,tf1,tf2,s,w1,w2);
  9061. if(epaState != 0) {
  9062. this.distance = 0;
  9063. return epaState;
  9064. }
  9065. this.distance = -this.depth;
  9066. return 0;
  9067. }
  9068. this.distance = 0;
  9069. return 1;
  9070. }
  9071. this.shrinkSimplex(v);
  9072. dir.x = closest.x;
  9073. dir.y = closest.y;
  9074. dir.z = closest.z;
  9075. dir.x = -dir.x;
  9076. dir.y = -dir.y;
  9077. dir.z = -dir.z;
  9078. this.computeWitnessPoint1(false);
  9079. this.computeWitnessPoint2(false);
  9080. let _this = this.s[this.simplexSize];
  9081. let v4 = this.w1[this.simplexSize];
  9082. _this.x = v4.x;
  9083. _this.y = v4.y;
  9084. _this.z = v4.z;
  9085. let v5 = this.w2[this.simplexSize];
  9086. _this.x -= v5.x;
  9087. _this.y -= v5.y;
  9088. _this.z -= v5.z;
  9089. if(dir.x * dir.x + dir.y * dir.y + dir.z * dir.z < 1e-008) {
  9090. throw new Error("!?");
  9091. }
  9092. let _this1 = s[this.simplexSize];
  9093. if(_this1.x * dir.x + _this1.y * dir.y + _this1.z * dir.z - (closest.x * dir.x + closest.y * dir.y + closest.z * dir.z) < 1e-008) {
  9094. this.interpolateClosestPoints();
  9095. this.distance = Math.sqrt(closest.x * closest.x + closest.y * closest.y + closest.z * closest.z);
  9096. if(cache != null && cache._gjkCache != null) {
  9097. this.saveCache(cache._gjkCache);
  9098. }
  9099. return 0;
  9100. }
  9101. this.simplexSize++;
  9102. ++count;
  9103. }
  9104. return 2;
  9105. }
  9106. convexCastImpl(c1,c2,tf1,tf2,tl1,tl2,hit) {
  9107. this.c1 = c1;
  9108. this.c2 = c2;
  9109. this.tf1 = tf1;
  9110. this.tf2 = tf2;
  9111. let s = this.s;
  9112. let closest = this.closest;
  9113. let dir = this.dir;
  9114. let firstDirX;
  9115. let firstDirY;
  9116. let firstDirZ;
  9117. firstDirX = tf2._positionX - tf1._positionX;
  9118. firstDirY = tf2._positionY - tf1._positionY;
  9119. firstDirZ = tf2._positionZ - tf1._positionZ;
  9120. dir.x = firstDirX;
  9121. dir.y = firstDirY;
  9122. dir.z = firstDirZ;
  9123. if(dir.x * dir.x + dir.y * dir.y + dir.z * dir.z < 1e-6) {
  9124. dir.init(1,0,0);
  9125. }
  9126. this.simplexSize = 0;
  9127. if(this.c1 != null) {
  9128. this.computeWitnessPoint1(true);
  9129. } else {
  9130. let v = this.w1[this.simplexSize];
  9131. v.x = this.tf1._positionX;
  9132. v.y = this.tf1._positionY;
  9133. v.z = this.tf1._positionZ;
  9134. }
  9135. this.computeWitnessPoint2(true);
  9136. let _this = this.s[this.simplexSize];
  9137. let v = this.w1[this.simplexSize];
  9138. _this.x = v.x;
  9139. _this.y = v.y;
  9140. _this.z = v.z;
  9141. let v1 = this.w2[this.simplexSize];
  9142. _this.x -= v1.x;
  9143. _this.y -= v1.y;
  9144. _this.z -= v1.z;
  9145. this.simplexSize = 1;
  9146. let count = 0;
  9147. let lambda = 0.0;
  9148. let rayX = this.rayX;
  9149. let rayR = this.rayR;
  9150. rayX.zero();
  9151. rayR.x = tl2.x;
  9152. rayR.y = tl2.y;
  9153. rayR.z = tl2.z;
  9154. rayR.x -= tl1.x;
  9155. rayR.y -= tl1.y;
  9156. rayR.z -= tl1.z;
  9157. while(count < 40) {
  9158. let v = 0;
  9159. switch(this.simplexSize) {
  9160. case 1:
  9161. let v1 = s[0];
  9162. closest.x = v1.x;
  9163. closest.y = v1.y;
  9164. closest.z = v1.z;
  9165. v = 1;
  9166. break;
  9167. case 2:
  9168. let v1X;
  9169. let v1Y;
  9170. let v1Z;
  9171. let v2X;
  9172. let v2Y;
  9173. let v2Z;
  9174. let v2 = s[0];
  9175. v1X = v2.x;
  9176. v1Y = v2.y;
  9177. v1Z = v2.z;
  9178. let v3 = s[1];
  9179. v2X = v3.x;
  9180. v2Y = v3.y;
  9181. v2Z = v3.z;
  9182. let v12X;
  9183. let v12Y;
  9184. let v12Z;
  9185. v12X = v2X - v1X;
  9186. v12Y = v2Y - v1Y;
  9187. v12Z = v2Z - v1Z;
  9188. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  9189. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  9190. if(t < 0) {
  9191. closest.x = v1X;
  9192. closest.y = v1Y;
  9193. closest.z = v1Z;
  9194. v = 1;
  9195. } else if(t > 1) {
  9196. closest.x = v2X;
  9197. closest.y = v2Y;
  9198. closest.z = v2Z;
  9199. v = 2;
  9200. } else {
  9201. let pX;
  9202. let pY;
  9203. let pZ;
  9204. pX = v1X + v12X * t;
  9205. pY = v1Y + v12Y * t;
  9206. pZ = v1Z + v12Z * t;
  9207. closest.x = pX;
  9208. closest.y = pY;
  9209. closest.z = pZ;
  9210. v = 3;
  9211. }
  9212. break;
  9213. case 3:
  9214. let vec1 = s[0];
  9215. let vec2 = s[1];
  9216. let vec3 = s[2];
  9217. let v1X1;
  9218. let v1Y1;
  9219. let v1Z1;
  9220. let v2X1;
  9221. let v2Y1;
  9222. let v2Z1;
  9223. let v3X;
  9224. let v3Y;
  9225. let v3Z;
  9226. let v12X1;
  9227. let v12Y1;
  9228. let v12Z1;
  9229. let v23X;
  9230. let v23Y;
  9231. let v23Z;
  9232. let v31X;
  9233. let v31Y;
  9234. let v31Z;
  9235. v1X1 = vec1.x;
  9236. v1Y1 = vec1.y;
  9237. v1Z1 = vec1.z;
  9238. v2X1 = vec2.x;
  9239. v2Y1 = vec2.y;
  9240. v2Z1 = vec2.z;
  9241. v3X = vec3.x;
  9242. v3Y = vec3.y;
  9243. v3Z = vec3.z;
  9244. v12X1 = v2X1 - v1X1;
  9245. v12Y1 = v2Y1 - v1Y1;
  9246. v12Z1 = v2Z1 - v1Z1;
  9247. v23X = v3X - v2X1;
  9248. v23Y = v3Y - v2Y1;
  9249. v23Z = v3Z - v2Z1;
  9250. v31X = v1X1 - v3X;
  9251. v31Y = v1Y1 - v3Y;
  9252. v31Z = v1Z1 - v3Z;
  9253. let nX;
  9254. let nY;
  9255. let nZ;
  9256. nX = v12Y1 * v23Z - v12Z1 * v23Y;
  9257. nY = v12Z1 * v23X - v12X1 * v23Z;
  9258. nZ = v12X1 * v23Y - v12Y1 * v23X;
  9259. let n12X;
  9260. let n12Y;
  9261. let n12Z;
  9262. let n23X;
  9263. let n23Y;
  9264. let n23Z;
  9265. let n31X;
  9266. let n31Y;
  9267. let n31Z;
  9268. n12X = v12Y1 * nZ - v12Z1 * nY;
  9269. n12Y = v12Z1 * nX - v12X1 * nZ;
  9270. n12Z = v12X1 * nY - v12Y1 * nX;
  9271. n23X = v23Y * nZ - v23Z * nY;
  9272. n23Y = v23Z * nX - v23X * nZ;
  9273. n23Z = v23X * nY - v23Y * nX;
  9274. n31X = v31Y * nZ - v31Z * nY;
  9275. n31Y = v31Z * nX - v31X * nZ;
  9276. n31Z = v31X * nY - v31Y * nX;
  9277. let mind = -1;
  9278. let minvX;
  9279. let minvY;
  9280. let minvZ;
  9281. let mini = 0;
  9282. minvX = 0;
  9283. minvY = 0;
  9284. minvZ = 0;
  9285. if(v1X1 * n12X + v1Y1 * n12Y + v1Z1 * n12Z < 0) {
  9286. let v1X;
  9287. let v1Y;
  9288. let v1Z;
  9289. let v2X;
  9290. let v2Y;
  9291. let v2Z;
  9292. v1X = vec1.x;
  9293. v1Y = vec1.y;
  9294. v1Z = vec1.z;
  9295. v2X = vec2.x;
  9296. v2Y = vec2.y;
  9297. v2Z = vec2.z;
  9298. let v12X;
  9299. let v12Y;
  9300. let v12Z;
  9301. v12X = v2X - v1X;
  9302. v12Y = v2Y - v1Y;
  9303. v12Z = v2Z - v1Z;
  9304. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  9305. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  9306. let b;
  9307. if(t < 0) {
  9308. closest.x = v1X;
  9309. closest.y = v1Y;
  9310. closest.z = v1Z;
  9311. b = 1;
  9312. } else if(t > 1) {
  9313. closest.x = v2X;
  9314. closest.y = v2Y;
  9315. closest.z = v2Z;
  9316. b = 2;
  9317. } else {
  9318. let pX;
  9319. let pY;
  9320. let pZ;
  9321. pX = v1X + v12X * t;
  9322. pY = v1Y + v12Y * t;
  9323. pZ = v1Z + v12Z * t;
  9324. closest.x = pX;
  9325. closest.y = pY;
  9326. closest.z = pZ;
  9327. b = 3;
  9328. }
  9329. mini = b;
  9330. mind = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  9331. minvX = closest.x;
  9332. minvY = closest.y;
  9333. minvZ = closest.z;
  9334. }
  9335. if(v2X1 * n23X + v2Y1 * n23Y + v2Z1 * n23Z < 0) {
  9336. let v1X;
  9337. let v1Y;
  9338. let v1Z;
  9339. let v2X;
  9340. let v2Y;
  9341. let v2Z;
  9342. v1X = vec2.x;
  9343. v1Y = vec2.y;
  9344. v1Z = vec2.z;
  9345. v2X = vec3.x;
  9346. v2Y = vec3.y;
  9347. v2Z = vec3.z;
  9348. let v12X;
  9349. let v12Y;
  9350. let v12Z;
  9351. v12X = v2X - v1X;
  9352. v12Y = v2Y - v1Y;
  9353. v12Z = v2Z - v1Z;
  9354. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  9355. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  9356. let b;
  9357. if(t < 0) {
  9358. closest.x = v1X;
  9359. closest.y = v1Y;
  9360. closest.z = v1Z;
  9361. b = 1;
  9362. } else if(t > 1) {
  9363. closest.x = v2X;
  9364. closest.y = v2Y;
  9365. closest.z = v2Z;
  9366. b = 2;
  9367. } else {
  9368. let pX;
  9369. let pY;
  9370. let pZ;
  9371. pX = v1X + v12X * t;
  9372. pY = v1Y + v12Y * t;
  9373. pZ = v1Z + v12Z * t;
  9374. closest.x = pX;
  9375. closest.y = pY;
  9376. closest.z = pZ;
  9377. b = 3;
  9378. }
  9379. let d = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  9380. if(mind < 0 || d < mind) {
  9381. mini = b << 1;
  9382. mind = d;
  9383. minvX = closest.x;
  9384. minvY = closest.y;
  9385. minvZ = closest.z;
  9386. }
  9387. }
  9388. if(v3X * n31X + v3Y * n31Y + v3Z * n31Z < 0) {
  9389. let v1X;
  9390. let v1Y;
  9391. let v1Z;
  9392. let v2X;
  9393. let v2Y;
  9394. let v2Z;
  9395. v1X = vec1.x;
  9396. v1Y = vec1.y;
  9397. v1Z = vec1.z;
  9398. v2X = vec3.x;
  9399. v2Y = vec3.y;
  9400. v2Z = vec3.z;
  9401. let v12X;
  9402. let v12Y;
  9403. let v12Z;
  9404. v12X = v2X - v1X;
  9405. v12Y = v2Y - v1Y;
  9406. v12Z = v2Z - v1Z;
  9407. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  9408. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  9409. let b;
  9410. if(t < 0) {
  9411. closest.x = v1X;
  9412. closest.y = v1Y;
  9413. closest.z = v1Z;
  9414. b = 1;
  9415. } else if(t > 1) {
  9416. closest.x = v2X;
  9417. closest.y = v2Y;
  9418. closest.z = v2Z;
  9419. b = 2;
  9420. } else {
  9421. let pX;
  9422. let pY;
  9423. let pZ;
  9424. pX = v1X + v12X * t;
  9425. pY = v1Y + v12Y * t;
  9426. pZ = v1Z + v12Z * t;
  9427. closest.x = pX;
  9428. closest.y = pY;
  9429. closest.z = pZ;
  9430. b = 3;
  9431. }
  9432. let d = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  9433. if(mind < 0 || d < mind) {
  9434. mini = b & 1 | (b & 2) << 1;
  9435. mind = d;
  9436. minvX = closest.x;
  9437. minvY = closest.y;
  9438. minvZ = closest.z;
  9439. }
  9440. }
  9441. if(mind > 0) {
  9442. closest.x = minvX;
  9443. closest.y = minvY;
  9444. closest.z = minvZ;
  9445. v = mini;
  9446. } else {
  9447. let l = nX * nX + nY * nY + nZ * nZ;
  9448. if(l > 0) {
  9449. l = 1 / Math.sqrt(l);
  9450. }
  9451. nX *= l;
  9452. nY *= l;
  9453. nZ *= l;
  9454. let l2 = nX * nX + nY * nY + nZ * nZ;
  9455. l2 = (v1X1 * nX + v1Y1 * nY + v1Z1 * nZ) / l2;
  9456. minvX = nX * l2;
  9457. minvY = nY * l2;
  9458. minvZ = nZ * l2;
  9459. closest.x = minvX;
  9460. closest.y = minvY;
  9461. closest.z = minvZ;
  9462. v = 7;
  9463. }
  9464. break;
  9465. case 4:
  9466. let vec11 = s[0];
  9467. let vec21 = s[1];
  9468. let vec31 = s[2];
  9469. let vec4 = s[3];
  9470. let v1X2;
  9471. let v1Y2;
  9472. let v1Z2;
  9473. let v2X2;
  9474. let v2Y2;
  9475. let v2Z2;
  9476. let v3X1;
  9477. let v3Y1;
  9478. let v3Z1;
  9479. let v4X;
  9480. let v4Y;
  9481. let v4Z;
  9482. let v12X2;
  9483. let v12Y2;
  9484. let v12Z2;
  9485. let v13X;
  9486. let v13Y;
  9487. let v13Z;
  9488. let v14X;
  9489. let v14Y;
  9490. let v14Z;
  9491. let v23X1;
  9492. let v23Y1;
  9493. let v23Z1;
  9494. let v24X;
  9495. let v24Y;
  9496. let v24Z;
  9497. v1X2 = vec11.x;
  9498. v1Y2 = vec11.y;
  9499. v1Z2 = vec11.z;
  9500. v2X2 = vec21.x;
  9501. v2Y2 = vec21.y;
  9502. v2Z2 = vec21.z;
  9503. v3X1 = vec31.x;
  9504. v3Y1 = vec31.y;
  9505. v3Z1 = vec31.z;
  9506. v4X = vec4.x;
  9507. v4Y = vec4.y;
  9508. v4Z = vec4.z;
  9509. v12X2 = v2X2 - v1X2;
  9510. v12Y2 = v2Y2 - v1Y2;
  9511. v12Z2 = v2Z2 - v1Z2;
  9512. v13X = v3X1 - v1X2;
  9513. v13Y = v3Y1 - v1Y2;
  9514. v13Z = v3Z1 - v1Z2;
  9515. v14X = v4X - v1X2;
  9516. v14Y = v4Y - v1Y2;
  9517. v14Z = v4Z - v1Z2;
  9518. v23X1 = v3X1 - v2X2;
  9519. v23Y1 = v3Y1 - v2Y2;
  9520. v23Z1 = v3Z1 - v2Z2;
  9521. v24X = v4X - v2X2;
  9522. v24Y = v4Y - v2Y2;
  9523. v24Z = v4Z - v2Z2;
  9524. let n123X;
  9525. let n123Y;
  9526. let n123Z;
  9527. let n134X;
  9528. let n134Y;
  9529. let n134Z;
  9530. let n142X;
  9531. let n142Y;
  9532. let n142Z;
  9533. let n243X;
  9534. let n243Y;
  9535. let n243Z;
  9536. n123X = v12Y2 * v13Z - v12Z2 * v13Y;
  9537. n123Y = v12Z2 * v13X - v12X2 * v13Z;
  9538. n123Z = v12X2 * v13Y - v12Y2 * v13X;
  9539. n134X = v13Y * v14Z - v13Z * v14Y;
  9540. n134Y = v13Z * v14X - v13X * v14Z;
  9541. n134Z = v13X * v14Y - v13Y * v14X;
  9542. n142X = v14Y * v12Z2 - v14Z * v12Y2;
  9543. n142Y = v14Z * v12X2 - v14X * v12Z2;
  9544. n142Z = v14X * v12Y2 - v14Y * v12X2;
  9545. n243X = v24Y * v23Z1 - v24Z * v23Y1;
  9546. n243Y = v24Z * v23X1 - v24X * v23Z1;
  9547. n243Z = v24X * v23Y1 - v24Y * v23X1;
  9548. let sign = v12X2 * n243X + v12Y2 * n243Y + v12Z2 * n243Z > 0 ? 1 : -1;
  9549. let mind1 = -1;
  9550. let minvX1;
  9551. let minvY1;
  9552. let minvZ1;
  9553. let mini1 = 0;
  9554. minvX1 = 0;
  9555. minvY1 = 0;
  9556. minvZ1 = 0;
  9557. if((v1X2 * n123X + v1Y2 * n123Y + v1Z2 * n123Z) * sign < 0) {
  9558. let v1X;
  9559. let v1Y;
  9560. let v1Z;
  9561. let v2X;
  9562. let v2Y;
  9563. let v2Z;
  9564. let v3X;
  9565. let v3Y;
  9566. let v3Z;
  9567. let v12X;
  9568. let v12Y;
  9569. let v12Z;
  9570. let v23X;
  9571. let v23Y;
  9572. let v23Z;
  9573. let v31X;
  9574. let v31Y;
  9575. let v31Z;
  9576. v1X = vec11.x;
  9577. v1Y = vec11.y;
  9578. v1Z = vec11.z;
  9579. v2X = vec21.x;
  9580. v2Y = vec21.y;
  9581. v2Z = vec21.z;
  9582. v3X = vec31.x;
  9583. v3Y = vec31.y;
  9584. v3Z = vec31.z;
  9585. v12X = v2X - v1X;
  9586. v12Y = v2Y - v1Y;
  9587. v12Z = v2Z - v1Z;
  9588. v23X = v3X - v2X;
  9589. v23Y = v3Y - v2Y;
  9590. v23Z = v3Z - v2Z;
  9591. v31X = v1X - v3X;
  9592. v31Y = v1Y - v3Y;
  9593. v31Z = v1Z - v3Z;
  9594. let nX;
  9595. let nY;
  9596. let nZ;
  9597. nX = v12Y * v23Z - v12Z * v23Y;
  9598. nY = v12Z * v23X - v12X * v23Z;
  9599. nZ = v12X * v23Y - v12Y * v23X;
  9600. let n12X;
  9601. let n12Y;
  9602. let n12Z;
  9603. let n23X;
  9604. let n23Y;
  9605. let n23Z;
  9606. let n31X;
  9607. let n31Y;
  9608. let n31Z;
  9609. n12X = v12Y * nZ - v12Z * nY;
  9610. n12Y = v12Z * nX - v12X * nZ;
  9611. n12Z = v12X * nY - v12Y * nX;
  9612. n23X = v23Y * nZ - v23Z * nY;
  9613. n23Y = v23Z * nX - v23X * nZ;
  9614. n23Z = v23X * nY - v23Y * nX;
  9615. n31X = v31Y * nZ - v31Z * nY;
  9616. n31Y = v31Z * nX - v31X * nZ;
  9617. n31Z = v31X * nY - v31Y * nX;
  9618. let mind = -1;
  9619. let minvX;
  9620. let minvY;
  9621. let minvZ;
  9622. let mini = 0;
  9623. minvX = 0;
  9624. minvY = 0;
  9625. minvZ = 0;
  9626. if(v1X * n12X + v1Y * n12Y + v1Z * n12Z < 0) {
  9627. let v1X;
  9628. let v1Y;
  9629. let v1Z;
  9630. let v2X;
  9631. let v2Y;
  9632. let v2Z;
  9633. v1X = vec11.x;
  9634. v1Y = vec11.y;
  9635. v1Z = vec11.z;
  9636. v2X = vec21.x;
  9637. v2Y = vec21.y;
  9638. v2Z = vec21.z;
  9639. let v12X;
  9640. let v12Y;
  9641. let v12Z;
  9642. v12X = v2X - v1X;
  9643. v12Y = v2Y - v1Y;
  9644. v12Z = v2Z - v1Z;
  9645. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  9646. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  9647. let b;
  9648. if(t < 0) {
  9649. closest.x = v1X;
  9650. closest.y = v1Y;
  9651. closest.z = v1Z;
  9652. b = 1;
  9653. } else if(t > 1) {
  9654. closest.x = v2X;
  9655. closest.y = v2Y;
  9656. closest.z = v2Z;
  9657. b = 2;
  9658. } else {
  9659. let pX;
  9660. let pY;
  9661. let pZ;
  9662. pX = v1X + v12X * t;
  9663. pY = v1Y + v12Y * t;
  9664. pZ = v1Z + v12Z * t;
  9665. closest.x = pX;
  9666. closest.y = pY;
  9667. closest.z = pZ;
  9668. b = 3;
  9669. }
  9670. mini = b;
  9671. mind = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  9672. minvX = closest.x;
  9673. minvY = closest.y;
  9674. minvZ = closest.z;
  9675. }
  9676. if(v2X * n23X + v2Y * n23Y + v2Z * n23Z < 0) {
  9677. let v1X;
  9678. let v1Y;
  9679. let v1Z;
  9680. let v2X;
  9681. let v2Y;
  9682. let v2Z;
  9683. v1X = vec21.x;
  9684. v1Y = vec21.y;
  9685. v1Z = vec21.z;
  9686. v2X = vec31.x;
  9687. v2Y = vec31.y;
  9688. v2Z = vec31.z;
  9689. let v12X;
  9690. let v12Y;
  9691. let v12Z;
  9692. v12X = v2X - v1X;
  9693. v12Y = v2Y - v1Y;
  9694. v12Z = v2Z - v1Z;
  9695. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  9696. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  9697. let b;
  9698. if(t < 0) {
  9699. closest.x = v1X;
  9700. closest.y = v1Y;
  9701. closest.z = v1Z;
  9702. b = 1;
  9703. } else if(t > 1) {
  9704. closest.x = v2X;
  9705. closest.y = v2Y;
  9706. closest.z = v2Z;
  9707. b = 2;
  9708. } else {
  9709. let pX;
  9710. let pY;
  9711. let pZ;
  9712. pX = v1X + v12X * t;
  9713. pY = v1Y + v12Y * t;
  9714. pZ = v1Z + v12Z * t;
  9715. closest.x = pX;
  9716. closest.y = pY;
  9717. closest.z = pZ;
  9718. b = 3;
  9719. }
  9720. let d = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  9721. if(mind < 0 || d < mind) {
  9722. mini = b << 1;
  9723. mind = d;
  9724. minvX = closest.x;
  9725. minvY = closest.y;
  9726. minvZ = closest.z;
  9727. }
  9728. }
  9729. if(v3X * n31X + v3Y * n31Y + v3Z * n31Z < 0) {
  9730. let v1X;
  9731. let v1Y;
  9732. let v1Z;
  9733. let v2X;
  9734. let v2Y;
  9735. let v2Z;
  9736. v1X = vec11.x;
  9737. v1Y = vec11.y;
  9738. v1Z = vec11.z;
  9739. v2X = vec31.x;
  9740. v2Y = vec31.y;
  9741. v2Z = vec31.z;
  9742. let v12X;
  9743. let v12Y;
  9744. let v12Z;
  9745. v12X = v2X - v1X;
  9746. v12Y = v2Y - v1Y;
  9747. v12Z = v2Z - v1Z;
  9748. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  9749. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  9750. let b;
  9751. if(t < 0) {
  9752. closest.x = v1X;
  9753. closest.y = v1Y;
  9754. closest.z = v1Z;
  9755. b = 1;
  9756. } else if(t > 1) {
  9757. closest.x = v2X;
  9758. closest.y = v2Y;
  9759. closest.z = v2Z;
  9760. b = 2;
  9761. } else {
  9762. let pX;
  9763. let pY;
  9764. let pZ;
  9765. pX = v1X + v12X * t;
  9766. pY = v1Y + v12Y * t;
  9767. pZ = v1Z + v12Z * t;
  9768. closest.x = pX;
  9769. closest.y = pY;
  9770. closest.z = pZ;
  9771. b = 3;
  9772. }
  9773. let d = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  9774. if(mind < 0 || d < mind) {
  9775. mini = b & 1 | (b & 2) << 1;
  9776. mind = d;
  9777. minvX = closest.x;
  9778. minvY = closest.y;
  9779. minvZ = closest.z;
  9780. }
  9781. }
  9782. let b;
  9783. if(mind > 0) {
  9784. closest.x = minvX;
  9785. closest.y = minvY;
  9786. closest.z = minvZ;
  9787. b = mini;
  9788. } else {
  9789. let l = nX * nX + nY * nY + nZ * nZ;
  9790. if(l > 0) {
  9791. l = 1 / Math.sqrt(l);
  9792. }
  9793. nX *= l;
  9794. nY *= l;
  9795. nZ *= l;
  9796. let l2 = nX * nX + nY * nY + nZ * nZ;
  9797. l2 = (v1X * nX + v1Y * nY + v1Z * nZ) / l2;
  9798. minvX = nX * l2;
  9799. minvY = nY * l2;
  9800. minvZ = nZ * l2;
  9801. closest.x = minvX;
  9802. closest.y = minvY;
  9803. closest.z = minvZ;
  9804. b = 7;
  9805. }
  9806. mini1 = b;
  9807. mind1 = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  9808. minvX1 = closest.x;
  9809. minvY1 = closest.y;
  9810. minvZ1 = closest.z;
  9811. }
  9812. if((v1X2 * n134X + v1Y2 * n134Y + v1Z2 * n134Z) * sign < 0) {
  9813. let v1X;
  9814. let v1Y;
  9815. let v1Z;
  9816. let v2X;
  9817. let v2Y;
  9818. let v2Z;
  9819. let v3X;
  9820. let v3Y;
  9821. let v3Z;
  9822. let v12X;
  9823. let v12Y;
  9824. let v12Z;
  9825. let v23X;
  9826. let v23Y;
  9827. let v23Z;
  9828. let v31X;
  9829. let v31Y;
  9830. let v31Z;
  9831. v1X = vec11.x;
  9832. v1Y = vec11.y;
  9833. v1Z = vec11.z;
  9834. v2X = vec31.x;
  9835. v2Y = vec31.y;
  9836. v2Z = vec31.z;
  9837. v3X = vec4.x;
  9838. v3Y = vec4.y;
  9839. v3Z = vec4.z;
  9840. v12X = v2X - v1X;
  9841. v12Y = v2Y - v1Y;
  9842. v12Z = v2Z - v1Z;
  9843. v23X = v3X - v2X;
  9844. v23Y = v3Y - v2Y;
  9845. v23Z = v3Z - v2Z;
  9846. v31X = v1X - v3X;
  9847. v31Y = v1Y - v3Y;
  9848. v31Z = v1Z - v3Z;
  9849. let nX;
  9850. let nY;
  9851. let nZ;
  9852. nX = v12Y * v23Z - v12Z * v23Y;
  9853. nY = v12Z * v23X - v12X * v23Z;
  9854. nZ = v12X * v23Y - v12Y * v23X;
  9855. let n12X;
  9856. let n12Y;
  9857. let n12Z;
  9858. let n23X;
  9859. let n23Y;
  9860. let n23Z;
  9861. let n31X;
  9862. let n31Y;
  9863. let n31Z;
  9864. n12X = v12Y * nZ - v12Z * nY;
  9865. n12Y = v12Z * nX - v12X * nZ;
  9866. n12Z = v12X * nY - v12Y * nX;
  9867. n23X = v23Y * nZ - v23Z * nY;
  9868. n23Y = v23Z * nX - v23X * nZ;
  9869. n23Z = v23X * nY - v23Y * nX;
  9870. n31X = v31Y * nZ - v31Z * nY;
  9871. n31Y = v31Z * nX - v31X * nZ;
  9872. n31Z = v31X * nY - v31Y * nX;
  9873. let mind = -1;
  9874. let minvX;
  9875. let minvY;
  9876. let minvZ;
  9877. let mini = 0;
  9878. minvX = 0;
  9879. minvY = 0;
  9880. minvZ = 0;
  9881. if(v1X * n12X + v1Y * n12Y + v1Z * n12Z < 0) {
  9882. let v1X;
  9883. let v1Y;
  9884. let v1Z;
  9885. let v2X;
  9886. let v2Y;
  9887. let v2Z;
  9888. v1X = vec11.x;
  9889. v1Y = vec11.y;
  9890. v1Z = vec11.z;
  9891. v2X = vec31.x;
  9892. v2Y = vec31.y;
  9893. v2Z = vec31.z;
  9894. let v12X;
  9895. let v12Y;
  9896. let v12Z;
  9897. v12X = v2X - v1X;
  9898. v12Y = v2Y - v1Y;
  9899. v12Z = v2Z - v1Z;
  9900. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  9901. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  9902. let b;
  9903. if(t < 0) {
  9904. closest.x = v1X;
  9905. closest.y = v1Y;
  9906. closest.z = v1Z;
  9907. b = 1;
  9908. } else if(t > 1) {
  9909. closest.x = v2X;
  9910. closest.y = v2Y;
  9911. closest.z = v2Z;
  9912. b = 2;
  9913. } else {
  9914. let pX;
  9915. let pY;
  9916. let pZ;
  9917. pX = v1X + v12X * t;
  9918. pY = v1Y + v12Y * t;
  9919. pZ = v1Z + v12Z * t;
  9920. closest.x = pX;
  9921. closest.y = pY;
  9922. closest.z = pZ;
  9923. b = 3;
  9924. }
  9925. mini = b;
  9926. mind = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  9927. minvX = closest.x;
  9928. minvY = closest.y;
  9929. minvZ = closest.z;
  9930. }
  9931. if(v2X * n23X + v2Y * n23Y + v2Z * n23Z < 0) {
  9932. let v1X;
  9933. let v1Y;
  9934. let v1Z;
  9935. let v2X;
  9936. let v2Y;
  9937. let v2Z;
  9938. v1X = vec31.x;
  9939. v1Y = vec31.y;
  9940. v1Z = vec31.z;
  9941. v2X = vec4.x;
  9942. v2Y = vec4.y;
  9943. v2Z = vec4.z;
  9944. let v12X;
  9945. let v12Y;
  9946. let v12Z;
  9947. v12X = v2X - v1X;
  9948. v12Y = v2Y - v1Y;
  9949. v12Z = v2Z - v1Z;
  9950. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  9951. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  9952. let b;
  9953. if(t < 0) {
  9954. closest.x = v1X;
  9955. closest.y = v1Y;
  9956. closest.z = v1Z;
  9957. b = 1;
  9958. } else if(t > 1) {
  9959. closest.x = v2X;
  9960. closest.y = v2Y;
  9961. closest.z = v2Z;
  9962. b = 2;
  9963. } else {
  9964. let pX;
  9965. let pY;
  9966. let pZ;
  9967. pX = v1X + v12X * t;
  9968. pY = v1Y + v12Y * t;
  9969. pZ = v1Z + v12Z * t;
  9970. closest.x = pX;
  9971. closest.y = pY;
  9972. closest.z = pZ;
  9973. b = 3;
  9974. }
  9975. let d = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  9976. if(mind < 0 || d < mind) {
  9977. mini = b << 1;
  9978. mind = d;
  9979. minvX = closest.x;
  9980. minvY = closest.y;
  9981. minvZ = closest.z;
  9982. }
  9983. }
  9984. if(v3X * n31X + v3Y * n31Y + v3Z * n31Z < 0) {
  9985. let v1X;
  9986. let v1Y;
  9987. let v1Z;
  9988. let v2X;
  9989. let v2Y;
  9990. let v2Z;
  9991. v1X = vec11.x;
  9992. v1Y = vec11.y;
  9993. v1Z = vec11.z;
  9994. v2X = vec4.x;
  9995. v2Y = vec4.y;
  9996. v2Z = vec4.z;
  9997. let v12X;
  9998. let v12Y;
  9999. let v12Z;
  10000. v12X = v2X - v1X;
  10001. v12Y = v2Y - v1Y;
  10002. v12Z = v2Z - v1Z;
  10003. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  10004. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  10005. let b;
  10006. if(t < 0) {
  10007. closest.x = v1X;
  10008. closest.y = v1Y;
  10009. closest.z = v1Z;
  10010. b = 1;
  10011. } else if(t > 1) {
  10012. closest.x = v2X;
  10013. closest.y = v2Y;
  10014. closest.z = v2Z;
  10015. b = 2;
  10016. } else {
  10017. let pX;
  10018. let pY;
  10019. let pZ;
  10020. pX = v1X + v12X * t;
  10021. pY = v1Y + v12Y * t;
  10022. pZ = v1Z + v12Z * t;
  10023. closest.x = pX;
  10024. closest.y = pY;
  10025. closest.z = pZ;
  10026. b = 3;
  10027. }
  10028. let d = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  10029. if(mind < 0 || d < mind) {
  10030. mini = b & 1 | (b & 2) << 1;
  10031. mind = d;
  10032. minvX = closest.x;
  10033. minvY = closest.y;
  10034. minvZ = closest.z;
  10035. }
  10036. }
  10037. let b;
  10038. if(mind > 0) {
  10039. closest.x = minvX;
  10040. closest.y = minvY;
  10041. closest.z = minvZ;
  10042. b = mini;
  10043. } else {
  10044. let l = nX * nX + nY * nY + nZ * nZ;
  10045. if(l > 0) {
  10046. l = 1 / Math.sqrt(l);
  10047. }
  10048. nX *= l;
  10049. nY *= l;
  10050. nZ *= l;
  10051. let l2 = nX * nX + nY * nY + nZ * nZ;
  10052. l2 = (v1X * nX + v1Y * nY + v1Z * nZ) / l2;
  10053. minvX = nX * l2;
  10054. minvY = nY * l2;
  10055. minvZ = nZ * l2;
  10056. closest.x = minvX;
  10057. closest.y = minvY;
  10058. closest.z = minvZ;
  10059. b = 7;
  10060. }
  10061. let d = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  10062. if(mind1 < 0 || d < mind1) {
  10063. mini1 = b & 1 | (b & 6) << 1;
  10064. mind1 = d;
  10065. minvX1 = closest.x;
  10066. minvY1 = closest.y;
  10067. minvZ1 = closest.z;
  10068. }
  10069. }
  10070. if((v1X2 * n142X + v1Y2 * n142Y + v1Z2 * n142Z) * sign < 0) {
  10071. let v1X;
  10072. let v1Y;
  10073. let v1Z;
  10074. let v2X;
  10075. let v2Y;
  10076. let v2Z;
  10077. let v3X;
  10078. let v3Y;
  10079. let v3Z;
  10080. let v12X;
  10081. let v12Y;
  10082. let v12Z;
  10083. let v23X;
  10084. let v23Y;
  10085. let v23Z;
  10086. let v31X;
  10087. let v31Y;
  10088. let v31Z;
  10089. v1X = vec11.x;
  10090. v1Y = vec11.y;
  10091. v1Z = vec11.z;
  10092. v2X = vec21.x;
  10093. v2Y = vec21.y;
  10094. v2Z = vec21.z;
  10095. v3X = vec4.x;
  10096. v3Y = vec4.y;
  10097. v3Z = vec4.z;
  10098. v12X = v2X - v1X;
  10099. v12Y = v2Y - v1Y;
  10100. v12Z = v2Z - v1Z;
  10101. v23X = v3X - v2X;
  10102. v23Y = v3Y - v2Y;
  10103. v23Z = v3Z - v2Z;
  10104. v31X = v1X - v3X;
  10105. v31Y = v1Y - v3Y;
  10106. v31Z = v1Z - v3Z;
  10107. let nX;
  10108. let nY;
  10109. let nZ;
  10110. nX = v12Y * v23Z - v12Z * v23Y;
  10111. nY = v12Z * v23X - v12X * v23Z;
  10112. nZ = v12X * v23Y - v12Y * v23X;
  10113. let n12X;
  10114. let n12Y;
  10115. let n12Z;
  10116. let n23X;
  10117. let n23Y;
  10118. let n23Z;
  10119. let n31X;
  10120. let n31Y;
  10121. let n31Z;
  10122. n12X = v12Y * nZ - v12Z * nY;
  10123. n12Y = v12Z * nX - v12X * nZ;
  10124. n12Z = v12X * nY - v12Y * nX;
  10125. n23X = v23Y * nZ - v23Z * nY;
  10126. n23Y = v23Z * nX - v23X * nZ;
  10127. n23Z = v23X * nY - v23Y * nX;
  10128. n31X = v31Y * nZ - v31Z * nY;
  10129. n31Y = v31Z * nX - v31X * nZ;
  10130. n31Z = v31X * nY - v31Y * nX;
  10131. let mind = -1;
  10132. let minvX;
  10133. let minvY;
  10134. let minvZ;
  10135. let mini = 0;
  10136. minvX = 0;
  10137. minvY = 0;
  10138. minvZ = 0;
  10139. if(v1X * n12X + v1Y * n12Y + v1Z * n12Z < 0) {
  10140. let v1X;
  10141. let v1Y;
  10142. let v1Z;
  10143. let v2X;
  10144. let v2Y;
  10145. let v2Z;
  10146. v1X = vec11.x;
  10147. v1Y = vec11.y;
  10148. v1Z = vec11.z;
  10149. v2X = vec21.x;
  10150. v2Y = vec21.y;
  10151. v2Z = vec21.z;
  10152. let v12X;
  10153. let v12Y;
  10154. let v12Z;
  10155. v12X = v2X - v1X;
  10156. v12Y = v2Y - v1Y;
  10157. v12Z = v2Z - v1Z;
  10158. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  10159. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  10160. let b;
  10161. if(t < 0) {
  10162. closest.x = v1X;
  10163. closest.y = v1Y;
  10164. closest.z = v1Z;
  10165. b = 1;
  10166. } else if(t > 1) {
  10167. closest.x = v2X;
  10168. closest.y = v2Y;
  10169. closest.z = v2Z;
  10170. b = 2;
  10171. } else {
  10172. let pX;
  10173. let pY;
  10174. let pZ;
  10175. pX = v1X + v12X * t;
  10176. pY = v1Y + v12Y * t;
  10177. pZ = v1Z + v12Z * t;
  10178. closest.x = pX;
  10179. closest.y = pY;
  10180. closest.z = pZ;
  10181. b = 3;
  10182. }
  10183. mini = b;
  10184. mind = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  10185. minvX = closest.x;
  10186. minvY = closest.y;
  10187. minvZ = closest.z;
  10188. }
  10189. if(v2X * n23X + v2Y * n23Y + v2Z * n23Z < 0) {
  10190. let v1X;
  10191. let v1Y;
  10192. let v1Z;
  10193. let v2X;
  10194. let v2Y;
  10195. let v2Z;
  10196. v1X = vec21.x;
  10197. v1Y = vec21.y;
  10198. v1Z = vec21.z;
  10199. v2X = vec4.x;
  10200. v2Y = vec4.y;
  10201. v2Z = vec4.z;
  10202. let v12X;
  10203. let v12Y;
  10204. let v12Z;
  10205. v12X = v2X - v1X;
  10206. v12Y = v2Y - v1Y;
  10207. v12Z = v2Z - v1Z;
  10208. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  10209. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  10210. let b;
  10211. if(t < 0) {
  10212. closest.x = v1X;
  10213. closest.y = v1Y;
  10214. closest.z = v1Z;
  10215. b = 1;
  10216. } else if(t > 1) {
  10217. closest.x = v2X;
  10218. closest.y = v2Y;
  10219. closest.z = v2Z;
  10220. b = 2;
  10221. } else {
  10222. let pX;
  10223. let pY;
  10224. let pZ;
  10225. pX = v1X + v12X * t;
  10226. pY = v1Y + v12Y * t;
  10227. pZ = v1Z + v12Z * t;
  10228. closest.x = pX;
  10229. closest.y = pY;
  10230. closest.z = pZ;
  10231. b = 3;
  10232. }
  10233. let d = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  10234. if(mind < 0 || d < mind) {
  10235. mini = b << 1;
  10236. mind = d;
  10237. minvX = closest.x;
  10238. minvY = closest.y;
  10239. minvZ = closest.z;
  10240. }
  10241. }
  10242. if(v3X * n31X + v3Y * n31Y + v3Z * n31Z < 0) {
  10243. let v1X;
  10244. let v1Y;
  10245. let v1Z;
  10246. let v2X;
  10247. let v2Y;
  10248. let v2Z;
  10249. v1X = vec11.x;
  10250. v1Y = vec11.y;
  10251. v1Z = vec11.z;
  10252. v2X = vec4.x;
  10253. v2Y = vec4.y;
  10254. v2Z = vec4.z;
  10255. let v12X;
  10256. let v12Y;
  10257. let v12Z;
  10258. v12X = v2X - v1X;
  10259. v12Y = v2Y - v1Y;
  10260. v12Z = v2Z - v1Z;
  10261. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  10262. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  10263. let b;
  10264. if(t < 0) {
  10265. closest.x = v1X;
  10266. closest.y = v1Y;
  10267. closest.z = v1Z;
  10268. b = 1;
  10269. } else if(t > 1) {
  10270. closest.x = v2X;
  10271. closest.y = v2Y;
  10272. closest.z = v2Z;
  10273. b = 2;
  10274. } else {
  10275. let pX;
  10276. let pY;
  10277. let pZ;
  10278. pX = v1X + v12X * t;
  10279. pY = v1Y + v12Y * t;
  10280. pZ = v1Z + v12Z * t;
  10281. closest.x = pX;
  10282. closest.y = pY;
  10283. closest.z = pZ;
  10284. b = 3;
  10285. }
  10286. let d = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  10287. if(mind < 0 || d < mind) {
  10288. mini = b & 1 | (b & 2) << 1;
  10289. mind = d;
  10290. minvX = closest.x;
  10291. minvY = closest.y;
  10292. minvZ = closest.z;
  10293. }
  10294. }
  10295. let b;
  10296. if(mind > 0) {
  10297. closest.x = minvX;
  10298. closest.y = minvY;
  10299. closest.z = minvZ;
  10300. b = mini;
  10301. } else {
  10302. let l = nX * nX + nY * nY + nZ * nZ;
  10303. if(l > 0) {
  10304. l = 1 / Math.sqrt(l);
  10305. }
  10306. nX *= l;
  10307. nY *= l;
  10308. nZ *= l;
  10309. let l2 = nX * nX + nY * nY + nZ * nZ;
  10310. l2 = (v1X * nX + v1Y * nY + v1Z * nZ) / l2;
  10311. minvX = nX * l2;
  10312. minvY = nY * l2;
  10313. minvZ = nZ * l2;
  10314. closest.x = minvX;
  10315. closest.y = minvY;
  10316. closest.z = minvZ;
  10317. b = 7;
  10318. }
  10319. let d = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  10320. if(mind1 < 0 || d < mind1) {
  10321. mini1 = b & 3 | (b & 4) << 1;
  10322. mind1 = d;
  10323. minvX1 = closest.x;
  10324. minvY1 = closest.y;
  10325. minvZ1 = closest.z;
  10326. }
  10327. }
  10328. if((v2X2 * n243X + v2Y2 * n243Y + v2Z2 * n243Z) * sign < 0) {
  10329. let v1X;
  10330. let v1Y;
  10331. let v1Z;
  10332. let v2X;
  10333. let v2Y;
  10334. let v2Z;
  10335. let v3X;
  10336. let v3Y;
  10337. let v3Z;
  10338. let v12X;
  10339. let v12Y;
  10340. let v12Z;
  10341. let v23X;
  10342. let v23Y;
  10343. let v23Z;
  10344. let v31X;
  10345. let v31Y;
  10346. let v31Z;
  10347. v1X = vec21.x;
  10348. v1Y = vec21.y;
  10349. v1Z = vec21.z;
  10350. v2X = vec31.x;
  10351. v2Y = vec31.y;
  10352. v2Z = vec31.z;
  10353. v3X = vec4.x;
  10354. v3Y = vec4.y;
  10355. v3Z = vec4.z;
  10356. v12X = v2X - v1X;
  10357. v12Y = v2Y - v1Y;
  10358. v12Z = v2Z - v1Z;
  10359. v23X = v3X - v2X;
  10360. v23Y = v3Y - v2Y;
  10361. v23Z = v3Z - v2Z;
  10362. v31X = v1X - v3X;
  10363. v31Y = v1Y - v3Y;
  10364. v31Z = v1Z - v3Z;
  10365. let nX;
  10366. let nY;
  10367. let nZ;
  10368. nX = v12Y * v23Z - v12Z * v23Y;
  10369. nY = v12Z * v23X - v12X * v23Z;
  10370. nZ = v12X * v23Y - v12Y * v23X;
  10371. let n12X;
  10372. let n12Y;
  10373. let n12Z;
  10374. let n23X;
  10375. let n23Y;
  10376. let n23Z;
  10377. let n31X;
  10378. let n31Y;
  10379. let n31Z;
  10380. n12X = v12Y * nZ - v12Z * nY;
  10381. n12Y = v12Z * nX - v12X * nZ;
  10382. n12Z = v12X * nY - v12Y * nX;
  10383. n23X = v23Y * nZ - v23Z * nY;
  10384. n23Y = v23Z * nX - v23X * nZ;
  10385. n23Z = v23X * nY - v23Y * nX;
  10386. n31X = v31Y * nZ - v31Z * nY;
  10387. n31Y = v31Z * nX - v31X * nZ;
  10388. n31Z = v31X * nY - v31Y * nX;
  10389. let mind = -1;
  10390. let minvX;
  10391. let minvY;
  10392. let minvZ;
  10393. let mini = 0;
  10394. minvX = 0;
  10395. minvY = 0;
  10396. minvZ = 0;
  10397. if(v1X * n12X + v1Y * n12Y + v1Z * n12Z < 0) {
  10398. let v1X;
  10399. let v1Y;
  10400. let v1Z;
  10401. let v2X;
  10402. let v2Y;
  10403. let v2Z;
  10404. v1X = vec21.x;
  10405. v1Y = vec21.y;
  10406. v1Z = vec21.z;
  10407. v2X = vec31.x;
  10408. v2Y = vec31.y;
  10409. v2Z = vec31.z;
  10410. let v12X;
  10411. let v12Y;
  10412. let v12Z;
  10413. v12X = v2X - v1X;
  10414. v12Y = v2Y - v1Y;
  10415. v12Z = v2Z - v1Z;
  10416. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  10417. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  10418. let b;
  10419. if(t < 0) {
  10420. closest.x = v1X;
  10421. closest.y = v1Y;
  10422. closest.z = v1Z;
  10423. b = 1;
  10424. } else if(t > 1) {
  10425. closest.x = v2X;
  10426. closest.y = v2Y;
  10427. closest.z = v2Z;
  10428. b = 2;
  10429. } else {
  10430. let pX;
  10431. let pY;
  10432. let pZ;
  10433. pX = v1X + v12X * t;
  10434. pY = v1Y + v12Y * t;
  10435. pZ = v1Z + v12Z * t;
  10436. closest.x = pX;
  10437. closest.y = pY;
  10438. closest.z = pZ;
  10439. b = 3;
  10440. }
  10441. mini = b;
  10442. mind = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  10443. minvX = closest.x;
  10444. minvY = closest.y;
  10445. minvZ = closest.z;
  10446. }
  10447. if(v2X * n23X + v2Y * n23Y + v2Z * n23Z < 0) {
  10448. let v1X;
  10449. let v1Y;
  10450. let v1Z;
  10451. let v2X;
  10452. let v2Y;
  10453. let v2Z;
  10454. v1X = vec31.x;
  10455. v1Y = vec31.y;
  10456. v1Z = vec31.z;
  10457. v2X = vec4.x;
  10458. v2Y = vec4.y;
  10459. v2Z = vec4.z;
  10460. let v12X;
  10461. let v12Y;
  10462. let v12Z;
  10463. v12X = v2X - v1X;
  10464. v12Y = v2Y - v1Y;
  10465. v12Z = v2Z - v1Z;
  10466. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  10467. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  10468. let b;
  10469. if(t < 0) {
  10470. closest.x = v1X;
  10471. closest.y = v1Y;
  10472. closest.z = v1Z;
  10473. b = 1;
  10474. } else if(t > 1) {
  10475. closest.x = v2X;
  10476. closest.y = v2Y;
  10477. closest.z = v2Z;
  10478. b = 2;
  10479. } else {
  10480. let pX;
  10481. let pY;
  10482. let pZ;
  10483. pX = v1X + v12X * t;
  10484. pY = v1Y + v12Y * t;
  10485. pZ = v1Z + v12Z * t;
  10486. closest.x = pX;
  10487. closest.y = pY;
  10488. closest.z = pZ;
  10489. b = 3;
  10490. }
  10491. let d = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  10492. if(mind < 0 || d < mind) {
  10493. mini = b << 1;
  10494. mind = d;
  10495. minvX = closest.x;
  10496. minvY = closest.y;
  10497. minvZ = closest.z;
  10498. }
  10499. }
  10500. if(v3X * n31X + v3Y * n31Y + v3Z * n31Z < 0) {
  10501. let v1X;
  10502. let v1Y;
  10503. let v1Z;
  10504. let v2X;
  10505. let v2Y;
  10506. let v2Z;
  10507. v1X = vec21.x;
  10508. v1Y = vec21.y;
  10509. v1Z = vec21.z;
  10510. v2X = vec4.x;
  10511. v2Y = vec4.y;
  10512. v2Z = vec4.z;
  10513. let v12X;
  10514. let v12Y;
  10515. let v12Z;
  10516. v12X = v2X - v1X;
  10517. v12Y = v2Y - v1Y;
  10518. v12Z = v2Z - v1Z;
  10519. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  10520. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  10521. let b;
  10522. if(t < 0) {
  10523. closest.x = v1X;
  10524. closest.y = v1Y;
  10525. closest.z = v1Z;
  10526. b = 1;
  10527. } else if(t > 1) {
  10528. closest.x = v2X;
  10529. closest.y = v2Y;
  10530. closest.z = v2Z;
  10531. b = 2;
  10532. } else {
  10533. let pX;
  10534. let pY;
  10535. let pZ;
  10536. pX = v1X + v12X * t;
  10537. pY = v1Y + v12Y * t;
  10538. pZ = v1Z + v12Z * t;
  10539. closest.x = pX;
  10540. closest.y = pY;
  10541. closest.z = pZ;
  10542. b = 3;
  10543. }
  10544. let d = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  10545. if(mind < 0 || d < mind) {
  10546. mini = b & 1 | (b & 2) << 1;
  10547. mind = d;
  10548. minvX = closest.x;
  10549. minvY = closest.y;
  10550. minvZ = closest.z;
  10551. }
  10552. }
  10553. let b;
  10554. if(mind > 0) {
  10555. closest.x = minvX;
  10556. closest.y = minvY;
  10557. closest.z = minvZ;
  10558. b = mini;
  10559. } else {
  10560. let l = nX * nX + nY * nY + nZ * nZ;
  10561. if(l > 0) {
  10562. l = 1 / Math.sqrt(l);
  10563. }
  10564. nX *= l;
  10565. nY *= l;
  10566. nZ *= l;
  10567. let l2 = nX * nX + nY * nY + nZ * nZ;
  10568. l2 = (v1X * nX + v1Y * nY + v1Z * nZ) / l2;
  10569. minvX = nX * l2;
  10570. minvY = nY * l2;
  10571. minvZ = nZ * l2;
  10572. closest.x = minvX;
  10573. closest.y = minvY;
  10574. closest.z = minvZ;
  10575. b = 7;
  10576. }
  10577. let d = closest.x * closest.x + closest.y * closest.y + closest.z * closest.z;
  10578. if(mind1 < 0 || d < mind1) {
  10579. mini1 = b << 1;
  10580. mind1 = d;
  10581. minvX1 = closest.x;
  10582. minvY1 = closest.y;
  10583. minvZ1 = closest.z;
  10584. }
  10585. }
  10586. if(mind1 > 0) {
  10587. closest.x = minvX1;
  10588. closest.y = minvY1;
  10589. closest.z = minvZ1;
  10590. v = mini1;
  10591. } else {
  10592. closest.zero();
  10593. v = 15;
  10594. }
  10595. break;
  10596. }
  10597. this.shrinkSimplex(v);
  10598. if(closest.x * closest.x + closest.y * closest.y + closest.z * closest.z < 1e-008) {
  10599. if(lambda == 0 || this.simplexSize == 4) {
  10600. hit.fraction = lambda;
  10601. return false;
  10602. }
  10603. this.interpolateClosestPoints();
  10604. hit.fraction = lambda;
  10605. let _this = hit.normal;
  10606. _this.x = dir.x;
  10607. _this.y = dir.y;
  10608. _this.z = dir.z;
  10609. let invLen = Math.sqrt(_this.x * _this.x + _this.y * _this.y + _this.z * _this.z);
  10610. if(invLen > 0) {
  10611. invLen = 1 / invLen;
  10612. }
  10613. _this.x *= invLen;
  10614. _this.y *= invLen;
  10615. _this.z *= invLen;
  10616. let _this1 = hit.position;
  10617. let v = this.closestPoint1;
  10618. _this1.x = v.x;
  10619. _this1.y = v.y;
  10620. _this1.z = v.z;
  10621. _this1.x += tl1.x * lambda;
  10622. _this1.y += tl1.y * lambda;
  10623. _this1.z += tl1.z * lambda;
  10624. return true;
  10625. }
  10626. dir.x = closest.x;
  10627. dir.y = closest.y;
  10628. dir.z = closest.z;
  10629. dir.x = -dir.x;
  10630. dir.y = -dir.y;
  10631. dir.z = -dir.z;
  10632. if(this.c1 != null) {
  10633. this.computeWitnessPoint1(true);
  10634. } else {
  10635. let v = this.w1[this.simplexSize];
  10636. v.x = this.tf1._positionX;
  10637. v.y = this.tf1._positionY;
  10638. v.z = this.tf1._positionZ;
  10639. }
  10640. this.computeWitnessPoint2(true);
  10641. let _this = this.s[this.simplexSize];
  10642. let v4 = this.w1[this.simplexSize];
  10643. _this.x = v4.x;
  10644. _this.y = v4.y;
  10645. _this.z = v4.z;
  10646. let v5 = this.w2[this.simplexSize];
  10647. _this.x -= v5.x;
  10648. _this.y -= v5.y;
  10649. _this.z -= v5.z;
  10650. let _this1 = s[this.simplexSize];
  10651. _this1.x -= rayX.x;
  10652. _this1.y -= rayX.y;
  10653. _this1.z -= rayX.z;
  10654. if(dir.x * dir.x + dir.y * dir.y + dir.z * dir.z < 1e-008) {
  10655. throw new Error("!?");
  10656. }
  10657. let p = s[this.simplexSize];
  10658. let pn = p.x * dir.x + p.y * dir.y + p.z * dir.z;
  10659. if(pn < 0) {
  10660. if(rayR.x * dir.x + rayR.y * dir.y + rayR.z * dir.z >= 0) {
  10661. return false;
  10662. }
  10663. let dLambda = pn / (rayR.x * dir.x + rayR.y * dir.y + rayR.z * dir.z);
  10664. lambda += dLambda;
  10665. if(lambda >= 1) {
  10666. return false;
  10667. }
  10668. rayX.x += rayR.x * dLambda;
  10669. rayX.y += rayR.y * dLambda;
  10670. rayX.z += rayR.z * dLambda;
  10671. let _g = 0;
  10672. let _g1 = this.simplexSize + 1;
  10673. while(_g < _g1) {
  10674. let _this = s[_g++];
  10675. let s1 = -dLambda;
  10676. _this.x += rayR.x * s1;
  10677. _this.y += rayR.y * s1;
  10678. _this.z += rayR.z * s1;
  10679. }
  10680. }
  10681. let duplicate = false;
  10682. let _g = 0;
  10683. let _g1 = this.simplexSize;
  10684. while(_g < _g1) {
  10685. let i = _g++;
  10686. let dx = s[i].x - s[this.simplexSize].x;
  10687. let dy = s[i].y - s[this.simplexSize].y;
  10688. let dz = s[i].z - s[this.simplexSize].z;
  10689. if(dx * dx + dy * dy + dz * dz < 1e-008) {
  10690. duplicate = true;
  10691. break;
  10692. }
  10693. }
  10694. if(!duplicate) {
  10695. this.simplexSize++;
  10696. }
  10697. ++count;
  10698. }
  10699. return false;
  10700. }
  10701. interpolateClosestPoints() {
  10702. switch(this.simplexSize) {
  10703. case 1:
  10704. let _this = this.closestPoint1;
  10705. let v = this.w1[0];
  10706. _this.x = v.x;
  10707. _this.y = v.y;
  10708. _this.z = v.z;
  10709. let _this1 = this.closestPoint2;
  10710. let v1 = this.w2[0];
  10711. _this1.x = v1.x;
  10712. _this1.y = v1.y;
  10713. _this1.z = v1.z;
  10714. break;
  10715. case 2:
  10716. let cX;
  10717. let cY;
  10718. let cZ;
  10719. let v2 = this.closest;
  10720. cX = v2.x;
  10721. cY = v2.y;
  10722. cZ = v2.z;
  10723. let s0X;
  10724. let s0Y;
  10725. let s0Z;
  10726. let w10X;
  10727. let w10Y;
  10728. let w10Z;
  10729. let w20X;
  10730. let w20Y;
  10731. let w20Z;
  10732. let s1X;
  10733. let s1Y;
  10734. let s1Z;
  10735. let w11X;
  10736. let w11Y;
  10737. let w11Z;
  10738. let w21X;
  10739. let w21Y;
  10740. let w21Z;
  10741. let v3 = this.s[0];
  10742. s0X = v3.x;
  10743. s0Y = v3.y;
  10744. s0Z = v3.z;
  10745. let v4 = this.w1[0];
  10746. w10X = v4.x;
  10747. w10Y = v4.y;
  10748. w10Z = v4.z;
  10749. let v5 = this.w2[0];
  10750. w20X = v5.x;
  10751. w20Y = v5.y;
  10752. w20Z = v5.z;
  10753. let v6 = this.s[1];
  10754. s1X = v6.x;
  10755. s1Y = v6.y;
  10756. s1Z = v6.z;
  10757. let v7 = this.w1[1];
  10758. w11X = v7.x;
  10759. w11Y = v7.y;
  10760. w11Z = v7.z;
  10761. let v8 = this.w2[1];
  10762. w21X = v8.x;
  10763. w21Y = v8.y;
  10764. w21Z = v8.z;
  10765. let s01X;
  10766. let s01Y;
  10767. let s01Z;
  10768. s01X = s1X - s0X;
  10769. s01Y = s1Y - s0Y;
  10770. s01Z = s1Z - s0Z;
  10771. let invDet = s01X * s01X + s01Y * s01Y + s01Z * s01Z;
  10772. if(invDet != 0) {
  10773. invDet = 1 / invDet;
  10774. }
  10775. let s0cX;
  10776. let s0cY;
  10777. let s0cZ;
  10778. s0cX = cX - s0X;
  10779. s0cY = cY - s0Y;
  10780. s0cZ = cZ - s0Z;
  10781. let t = (s0cX * s01X + s0cY * s01Y + s0cZ * s01Z) * invDet;
  10782. let diffX;
  10783. let diffY;
  10784. let diffZ;
  10785. let cp1X;
  10786. let cp1Y;
  10787. let cp1Z;
  10788. let cp2X;
  10789. let cp2Y;
  10790. let cp2Z;
  10791. diffX = w11X - w10X;
  10792. diffY = w11Y - w10Y;
  10793. diffZ = w11Z - w10Z;
  10794. cp1X = w10X + diffX * t;
  10795. cp1Y = w10Y + diffY * t;
  10796. cp1Z = w10Z + diffZ * t;
  10797. diffX = w21X - w20X;
  10798. diffY = w21Y - w20Y;
  10799. diffZ = w21Z - w20Z;
  10800. cp2X = w20X + diffX * t;
  10801. cp2Y = w20Y + diffY * t;
  10802. cp2Z = w20Z + diffZ * t;
  10803. let v9 = this.closestPoint1;
  10804. v9.x = cp1X;
  10805. v9.y = cp1Y;
  10806. v9.z = cp1Z;
  10807. let v10 = this.closestPoint2;
  10808. v10.x = cp2X;
  10809. v10.y = cp2Y;
  10810. v10.z = cp2Z;
  10811. break;
  10812. case 3:
  10813. let cX1;
  10814. let cY1;
  10815. let cZ1;
  10816. let v11 = this.closest;
  10817. cX1 = v11.x;
  10818. cY1 = v11.y;
  10819. cZ1 = v11.z;
  10820. let s0X1;
  10821. let s0Y1;
  10822. let s0Z1;
  10823. let w10X1;
  10824. let w10Y1;
  10825. let w10Z1;
  10826. let w20X1;
  10827. let w20Y1;
  10828. let w20Z1;
  10829. let s1X1;
  10830. let s1Y1;
  10831. let s1Z1;
  10832. let w11X1;
  10833. let w11Y1;
  10834. let w11Z1;
  10835. let w21X1;
  10836. let w21Y1;
  10837. let w21Z1;
  10838. let s2X;
  10839. let s2Y;
  10840. let s2Z;
  10841. let w12X;
  10842. let w12Y;
  10843. let w12Z;
  10844. let w22X;
  10845. let w22Y;
  10846. let w22Z;
  10847. let v12 = this.s[0];
  10848. s0X1 = v12.x;
  10849. s0Y1 = v12.y;
  10850. s0Z1 = v12.z;
  10851. let v13 = this.w1[0];
  10852. w10X1 = v13.x;
  10853. w10Y1 = v13.y;
  10854. w10Z1 = v13.z;
  10855. let v14 = this.w2[0];
  10856. w20X1 = v14.x;
  10857. w20Y1 = v14.y;
  10858. w20Z1 = v14.z;
  10859. let v15 = this.s[1];
  10860. s1X1 = v15.x;
  10861. s1Y1 = v15.y;
  10862. s1Z1 = v15.z;
  10863. let v16 = this.w1[1];
  10864. w11X1 = v16.x;
  10865. w11Y1 = v16.y;
  10866. w11Z1 = v16.z;
  10867. let v17 = this.w2[1];
  10868. w21X1 = v17.x;
  10869. w21Y1 = v17.y;
  10870. w21Z1 = v17.z;
  10871. let v18 = this.s[2];
  10872. s2X = v18.x;
  10873. s2Y = v18.y;
  10874. s2Z = v18.z;
  10875. let v19 = this.w1[2];
  10876. w12X = v19.x;
  10877. w12Y = v19.y;
  10878. w12Z = v19.z;
  10879. let v20 = this.w2[2];
  10880. w22X = v20.x;
  10881. w22Y = v20.y;
  10882. w22Z = v20.z;
  10883. let s01X1;
  10884. let s01Y1;
  10885. let s01Z1;
  10886. let s02X;
  10887. let s02Y;
  10888. let s02Z;
  10889. let s0cX1;
  10890. let s0cY1;
  10891. let s0cZ1;
  10892. s01X1 = s1X1 - s0X1;
  10893. s01Y1 = s1Y1 - s0Y1;
  10894. s01Z1 = s1Z1 - s0Z1;
  10895. s02X = s2X - s0X1;
  10896. s02Y = s2Y - s0Y1;
  10897. s02Z = s2Z - s0Z1;
  10898. s0cX1 = cX1 - s0X1;
  10899. s0cY1 = cY1 - s0Y1;
  10900. s0cZ1 = cZ1 - s0Z1;
  10901. let d11 = s01X1 * s01X1 + s01Y1 * s01Y1 + s01Z1 * s01Z1;
  10902. let d12 = s01X1 * s02X + s01Y1 * s02Y + s01Z1 * s02Z;
  10903. let d22 = s02X * s02X + s02Y * s02Y + s02Z * s02Z;
  10904. let d1c = s01X1 * s0cX1 + s01Y1 * s0cY1 + s01Z1 * s0cZ1;
  10905. let d2c = s02X * s0cX1 + s02Y * s0cY1 + s02Z * s0cZ1;
  10906. let invDet1 = d11 * d22 - d12 * d12;
  10907. if(invDet1 != 0) {
  10908. invDet1 = 1 / invDet1;
  10909. }
  10910. let s = (d1c * d22 - d2c * d12) * invDet1;
  10911. let t1 = (-d1c * d12 + d2c * d11) * invDet1;
  10912. let diffX1;
  10913. let diffY1;
  10914. let diffZ1;
  10915. let cp1X1;
  10916. let cp1Y1;
  10917. let cp1Z1;
  10918. let cp2X1;
  10919. let cp2Y1;
  10920. let cp2Z1;
  10921. diffX1 = w11X1 - w10X1;
  10922. diffY1 = w11Y1 - w10Y1;
  10923. diffZ1 = w11Z1 - w10Z1;
  10924. cp1X1 = w10X1 + diffX1 * s;
  10925. cp1Y1 = w10Y1 + diffY1 * s;
  10926. cp1Z1 = w10Z1 + diffZ1 * s;
  10927. diffX1 = w12X - w10X1;
  10928. diffY1 = w12Y - w10Y1;
  10929. diffZ1 = w12Z - w10Z1;
  10930. cp1X1 += diffX1 * t1;
  10931. cp1Y1 += diffY1 * t1;
  10932. cp1Z1 += diffZ1 * t1;
  10933. diffX1 = w21X1 - w20X1;
  10934. diffY1 = w21Y1 - w20Y1;
  10935. diffZ1 = w21Z1 - w20Z1;
  10936. cp2X1 = w20X1 + diffX1 * s;
  10937. cp2Y1 = w20Y1 + diffY1 * s;
  10938. cp2Z1 = w20Z1 + diffZ1 * s;
  10939. diffX1 = w22X - w20X1;
  10940. diffY1 = w22Y - w20Y1;
  10941. diffZ1 = w22Z - w20Z1;
  10942. cp2X1 += diffX1 * t1;
  10943. cp2Y1 += diffY1 * t1;
  10944. cp2Z1 += diffZ1 * t1;
  10945. let v21 = this.closestPoint1;
  10946. v21.x = cp1X1;
  10947. v21.y = cp1Y1;
  10948. v21.z = cp1Z1;
  10949. let v22 = this.closestPoint2;
  10950. v22.x = cp2X1;
  10951. v22.y = cp2Y1;
  10952. v22.z = cp2Z1;
  10953. break;
  10954. default:
  10955. throw new Error("!?");
  10956. }
  10957. }
  10958. loadCache(gjkCache) {
  10959. let _this = this.dir;
  10960. let v = gjkCache.prevClosestDir;
  10961. _this.x = v.x;
  10962. _this.y = v.y;
  10963. _this.z = v.z;
  10964. }
  10965. saveCache(gjkCache) {
  10966. let _this = gjkCache.prevClosestDir;
  10967. let v = this.closest;
  10968. _this.x = v.x;
  10969. _this.y = v.y;
  10970. _this.z = v.z;
  10971. _this.x = -_this.x;
  10972. _this.y = -_this.y;
  10973. _this.z = -_this.z;
  10974. }
  10975. shrinkSimplex(vertexBits) {
  10976. this.simplexSize = vertexBits;
  10977. this.simplexSize = (this.simplexSize & 5) + (this.simplexSize >> 1 & 5);
  10978. this.simplexSize = (this.simplexSize & 3) + (this.simplexSize >> 2 & 3);
  10979. switch(vertexBits) {
  10980. case 2:
  10981. let _this = this.s[0];
  10982. let v = this.s[1];
  10983. _this.x = v.x;
  10984. _this.y = v.y;
  10985. _this.z = v.z;
  10986. let _this1 = this.w1[0];
  10987. let v1 = this.w1[1];
  10988. _this1.x = v1.x;
  10989. _this1.y = v1.y;
  10990. _this1.z = v1.z;
  10991. let _this2 = this.w2[0];
  10992. let v2 = this.w2[1];
  10993. _this2.x = v2.x;
  10994. _this2.y = v2.y;
  10995. _this2.z = v2.z;
  10996. break;
  10997. case 4:
  10998. let _this3 = this.s[0];
  10999. let v3 = this.s[2];
  11000. _this3.x = v3.x;
  11001. _this3.y = v3.y;
  11002. _this3.z = v3.z;
  11003. let _this4 = this.w1[0];
  11004. let v4 = this.w1[2];
  11005. _this4.x = v4.x;
  11006. _this4.y = v4.y;
  11007. _this4.z = v4.z;
  11008. let _this5 = this.w2[0];
  11009. let v5 = this.w2[2];
  11010. _this5.x = v5.x;
  11011. _this5.y = v5.y;
  11012. _this5.z = v5.z;
  11013. break;
  11014. case 5:
  11015. let _this6 = this.s[1];
  11016. let v6 = this.s[2];
  11017. _this6.x = v6.x;
  11018. _this6.y = v6.y;
  11019. _this6.z = v6.z;
  11020. let _this7 = this.w1[1];
  11021. let v7 = this.w1[2];
  11022. _this7.x = v7.x;
  11023. _this7.y = v7.y;
  11024. _this7.z = v7.z;
  11025. let _this8 = this.w2[1];
  11026. let v8 = this.w2[2];
  11027. _this8.x = v8.x;
  11028. _this8.y = v8.y;
  11029. _this8.z = v8.z;
  11030. break;
  11031. case 6:
  11032. let _this9 = this.s[0];
  11033. let v9 = this.s[2];
  11034. _this9.x = v9.x;
  11035. _this9.y = v9.y;
  11036. _this9.z = v9.z;
  11037. let _this10 = this.w1[0];
  11038. let v10 = this.w1[2];
  11039. _this10.x = v10.x;
  11040. _this10.y = v10.y;
  11041. _this10.z = v10.z;
  11042. let _this11 = this.w2[0];
  11043. let v11 = this.w2[2];
  11044. _this11.x = v11.x;
  11045. _this11.y = v11.y;
  11046. _this11.z = v11.z;
  11047. break;
  11048. case 8:
  11049. let _this12 = this.s[0];
  11050. let v12 = this.s[3];
  11051. _this12.x = v12.x;
  11052. _this12.y = v12.y;
  11053. _this12.z = v12.z;
  11054. let _this13 = this.w1[0];
  11055. let v13 = this.w1[3];
  11056. _this13.x = v13.x;
  11057. _this13.y = v13.y;
  11058. _this13.z = v13.z;
  11059. let _this14 = this.w2[0];
  11060. let v14 = this.w2[3];
  11061. _this14.x = v14.x;
  11062. _this14.y = v14.y;
  11063. _this14.z = v14.z;
  11064. break;
  11065. case 9:
  11066. let _this15 = this.s[1];
  11067. let v15 = this.s[3];
  11068. _this15.x = v15.x;
  11069. _this15.y = v15.y;
  11070. _this15.z = v15.z;
  11071. let _this16 = this.w1[1];
  11072. let v16 = this.w1[3];
  11073. _this16.x = v16.x;
  11074. _this16.y = v16.y;
  11075. _this16.z = v16.z;
  11076. let _this17 = this.w2[1];
  11077. let v17 = this.w2[3];
  11078. _this17.x = v17.x;
  11079. _this17.y = v17.y;
  11080. _this17.z = v17.z;
  11081. break;
  11082. case 10:
  11083. let _this18 = this.s[0];
  11084. let v18 = this.s[3];
  11085. _this18.x = v18.x;
  11086. _this18.y = v18.y;
  11087. _this18.z = v18.z;
  11088. let _this19 = this.w1[0];
  11089. let v19 = this.w1[3];
  11090. _this19.x = v19.x;
  11091. _this19.y = v19.y;
  11092. _this19.z = v19.z;
  11093. let _this20 = this.w2[0];
  11094. let v20 = this.w2[3];
  11095. _this20.x = v20.x;
  11096. _this20.y = v20.y;
  11097. _this20.z = v20.z;
  11098. break;
  11099. case 11:
  11100. let _this21 = this.s[2];
  11101. let v21 = this.s[3];
  11102. _this21.x = v21.x;
  11103. _this21.y = v21.y;
  11104. _this21.z = v21.z;
  11105. let _this22 = this.w1[2];
  11106. let v22 = this.w1[3];
  11107. _this22.x = v22.x;
  11108. _this22.y = v22.y;
  11109. _this22.z = v22.z;
  11110. let _this23 = this.w2[2];
  11111. let v23 = this.w2[3];
  11112. _this23.x = v23.x;
  11113. _this23.y = v23.y;
  11114. _this23.z = v23.z;
  11115. break;
  11116. case 12:
  11117. let _this24 = this.s[0];
  11118. let v24 = this.s[2];
  11119. _this24.x = v24.x;
  11120. _this24.y = v24.y;
  11121. _this24.z = v24.z;
  11122. let _this25 = this.w1[0];
  11123. let v25 = this.w1[2];
  11124. _this25.x = v25.x;
  11125. _this25.y = v25.y;
  11126. _this25.z = v25.z;
  11127. let _this26 = this.w2[0];
  11128. let v26 = this.w2[2];
  11129. _this26.x = v26.x;
  11130. _this26.y = v26.y;
  11131. _this26.z = v26.z;
  11132. let _this27 = this.s[1];
  11133. let v27 = this.s[3];
  11134. _this27.x = v27.x;
  11135. _this27.y = v27.y;
  11136. _this27.z = v27.z;
  11137. let _this28 = this.w1[1];
  11138. let v28 = this.w1[3];
  11139. _this28.x = v28.x;
  11140. _this28.y = v28.y;
  11141. _this28.z = v28.z;
  11142. let _this29 = this.w2[1];
  11143. let v29 = this.w2[3];
  11144. _this29.x = v29.x;
  11145. _this29.y = v29.y;
  11146. _this29.z = v29.z;
  11147. break;
  11148. case 13:
  11149. let _this30 = this.s[1];
  11150. let v30 = this.s[3];
  11151. _this30.x = v30.x;
  11152. _this30.y = v30.y;
  11153. _this30.z = v30.z;
  11154. let _this31 = this.w1[1];
  11155. let v31 = this.w1[3];
  11156. _this31.x = v31.x;
  11157. _this31.y = v31.y;
  11158. _this31.z = v31.z;
  11159. let _this32 = this.w2[1];
  11160. let v32 = this.w2[3];
  11161. _this32.x = v32.x;
  11162. _this32.y = v32.y;
  11163. _this32.z = v32.z;
  11164. break;
  11165. case 14:
  11166. let _this33 = this.s[0];
  11167. let v33 = this.s[3];
  11168. _this33.x = v33.x;
  11169. _this33.y = v33.y;
  11170. _this33.z = v33.z;
  11171. let _this34 = this.w1[0];
  11172. let v34 = this.w1[3];
  11173. _this34.x = v34.x;
  11174. _this34.y = v34.y;
  11175. _this34.z = v34.z;
  11176. let _this35 = this.w2[0];
  11177. let v35 = this.w2[3];
  11178. _this35.x = v35.x;
  11179. _this35.y = v35.y;
  11180. _this35.z = v35.z;
  11181. break;
  11182. }
  11183. }
  11184. computeWitnessPoint1(addMargin) {
  11185. let tmpX;
  11186. let tmpY;
  11187. let tmpZ;
  11188. let idirX;
  11189. let idirY;
  11190. let idirZ;
  11191. let v = this.dir;
  11192. idirX = v.x;
  11193. idirY = v.y;
  11194. idirZ = v.z;
  11195. let ldir1X;
  11196. let ldir1Y;
  11197. let ldir1Z;
  11198. let __tmp__X;
  11199. let __tmp__Y;
  11200. let __tmp__Z;
  11201. __tmp__X = this.tf1._rotation00 * idirX + this.tf1._rotation10 * idirY + this.tf1._rotation20 * idirZ;
  11202. __tmp__Y = this.tf1._rotation01 * idirX + this.tf1._rotation11 * idirY + this.tf1._rotation21 * idirZ;
  11203. __tmp__Z = this.tf1._rotation02 * idirX + this.tf1._rotation12 * idirY + this.tf1._rotation22 * idirZ;
  11204. ldir1X = __tmp__X;
  11205. ldir1Y = __tmp__Y;
  11206. ldir1Z = __tmp__Z;
  11207. let iw1X;
  11208. let iw1Y;
  11209. let iw1Z;
  11210. let v1 = this.dir;
  11211. v1.x = ldir1X;
  11212. v1.y = ldir1Y;
  11213. v1.z = ldir1Z;
  11214. this.c1.computeLocalSupportingVertex(this.dir,this.w1[this.simplexSize]);
  11215. if(addMargin) {
  11216. let _this = this.dir;
  11217. let invLen = Math.sqrt(_this.x * _this.x + _this.y * _this.y + _this.z * _this.z);
  11218. if(invLen > 0) {
  11219. invLen = 1 / invLen;
  11220. }
  11221. _this.x *= invLen;
  11222. _this.y *= invLen;
  11223. _this.z *= invLen;
  11224. let _this1 = this.w1[this.simplexSize];
  11225. let v = this.dir;
  11226. let s = this.c1._gjkMargin;
  11227. _this1.x += v.x * s;
  11228. _this1.y += v.y * s;
  11229. _this1.z += v.z * s;
  11230. }
  11231. let v2 = this.w1[this.simplexSize];
  11232. tmpX = v2.x;
  11233. tmpY = v2.y;
  11234. tmpZ = v2.z;
  11235. let __tmp__X1;
  11236. let __tmp__Y1;
  11237. let __tmp__Z1;
  11238. __tmp__X1 = this.tf1._rotation00 * tmpX + this.tf1._rotation01 * tmpY + this.tf1._rotation02 * tmpZ;
  11239. __tmp__Y1 = this.tf1._rotation10 * tmpX + this.tf1._rotation11 * tmpY + this.tf1._rotation12 * tmpZ;
  11240. __tmp__Z1 = this.tf1._rotation20 * tmpX + this.tf1._rotation21 * tmpY + this.tf1._rotation22 * tmpZ;
  11241. iw1X = __tmp__X1;
  11242. iw1Y = __tmp__Y1;
  11243. iw1Z = __tmp__Z1;
  11244. iw1X += this.tf1._positionX;
  11245. iw1Y += this.tf1._positionY;
  11246. iw1Z += this.tf1._positionZ;
  11247. let v3 = this.w1[this.simplexSize];
  11248. v3.x = iw1X;
  11249. v3.y = iw1Y;
  11250. v3.z = iw1Z;
  11251. let v4 = this.dir;
  11252. v4.x = idirX;
  11253. v4.y = idirY;
  11254. v4.z = idirZ;
  11255. }
  11256. computeWitnessPoint2(addMargin) {
  11257. let tmpX;
  11258. let tmpY;
  11259. let tmpZ;
  11260. let idirX;
  11261. let idirY;
  11262. let idirZ;
  11263. let v = this.dir;
  11264. idirX = v.x;
  11265. idirY = v.y;
  11266. idirZ = v.z;
  11267. let ldir2X;
  11268. let ldir2Y;
  11269. let ldir2Z;
  11270. let __tmp__X;
  11271. let __tmp__Y;
  11272. let __tmp__Z;
  11273. __tmp__X = this.tf2._rotation00 * idirX + this.tf2._rotation10 * idirY + this.tf2._rotation20 * idirZ;
  11274. __tmp__Y = this.tf2._rotation01 * idirX + this.tf2._rotation11 * idirY + this.tf2._rotation21 * idirZ;
  11275. __tmp__Z = this.tf2._rotation02 * idirX + this.tf2._rotation12 * idirY + this.tf2._rotation22 * idirZ;
  11276. ldir2X = __tmp__X;
  11277. ldir2Y = __tmp__Y;
  11278. ldir2Z = __tmp__Z;
  11279. ldir2X = -ldir2X;
  11280. ldir2Y = -ldir2Y;
  11281. ldir2Z = -ldir2Z;
  11282. let iw2X;
  11283. let iw2Y;
  11284. let iw2Z;
  11285. let v1 = this.dir;
  11286. v1.x = ldir2X;
  11287. v1.y = ldir2Y;
  11288. v1.z = ldir2Z;
  11289. this.c2.computeLocalSupportingVertex(this.dir,this.w2[this.simplexSize]);
  11290. if(addMargin) {
  11291. let _this = this.dir;
  11292. let invLen = Math.sqrt(_this.x * _this.x + _this.y * _this.y + _this.z * _this.z);
  11293. if(invLen > 0) {
  11294. invLen = 1 / invLen;
  11295. }
  11296. _this.x *= invLen;
  11297. _this.y *= invLen;
  11298. _this.z *= invLen;
  11299. let _this1 = this.w2[this.simplexSize];
  11300. let v = this.dir;
  11301. let s = this.c2._gjkMargin;
  11302. _this1.x += v.x * s;
  11303. _this1.y += v.y * s;
  11304. _this1.z += v.z * s;
  11305. }
  11306. let v2 = this.w2[this.simplexSize];
  11307. tmpX = v2.x;
  11308. tmpY = v2.y;
  11309. tmpZ = v2.z;
  11310. let __tmp__X1;
  11311. let __tmp__Y1;
  11312. let __tmp__Z1;
  11313. __tmp__X1 = this.tf2._rotation00 * tmpX + this.tf2._rotation01 * tmpY + this.tf2._rotation02 * tmpZ;
  11314. __tmp__Y1 = this.tf2._rotation10 * tmpX + this.tf2._rotation11 * tmpY + this.tf2._rotation12 * tmpZ;
  11315. __tmp__Z1 = this.tf2._rotation20 * tmpX + this.tf2._rotation21 * tmpY + this.tf2._rotation22 * tmpZ;
  11316. iw2X = __tmp__X1;
  11317. iw2Y = __tmp__Y1;
  11318. iw2Z = __tmp__Z1;
  11319. iw2X += this.tf2._positionX;
  11320. iw2Y += this.tf2._positionY;
  11321. iw2Z += this.tf2._positionZ;
  11322. let v3 = this.w2[this.simplexSize];
  11323. v3.x = iw2X;
  11324. v3.y = iw2Y;
  11325. v3.z = iw2Z;
  11326. let v4 = this.dir;
  11327. v4.x = idirX;
  11328. v4.y = idirY;
  11329. v4.z = idirZ;
  11330. }
  11331. pointToTetrahedron() {
  11332. let _g = 0;
  11333. while(_g < 3) {
  11334. let _this = this.dir;
  11335. let v = this.baseDirs[_g++];
  11336. _this.x = v.x;
  11337. _this.y = v.y;
  11338. _this.z = v.z;
  11339. this.computeWitnessPoint1(false);
  11340. this.computeWitnessPoint2(false);
  11341. let _this1 = this.s[this.simplexSize];
  11342. let v1 = this.w1[this.simplexSize];
  11343. _this1.x = v1.x;
  11344. _this1.y = v1.y;
  11345. _this1.z = v1.z;
  11346. let v2 = this.w2[this.simplexSize];
  11347. _this1.x -= v2.x;
  11348. _this1.y -= v2.y;
  11349. _this1.z -= v2.z;
  11350. this.simplexSize++;
  11351. this.lineToTetrahedron();
  11352. if(this.simplexSize == 4) {
  11353. break;
  11354. }
  11355. this.simplexSize--;
  11356. let _this2 = this.dir;
  11357. _this2.x = -_this2.x;
  11358. _this2.y = -_this2.y;
  11359. _this2.z = -_this2.z;
  11360. this.computeWitnessPoint1(false);
  11361. this.computeWitnessPoint2(false);
  11362. let _this3 = this.s[this.simplexSize];
  11363. let v3 = this.w1[this.simplexSize];
  11364. _this3.x = v3.x;
  11365. _this3.y = v3.y;
  11366. _this3.z = v3.z;
  11367. let v4 = this.w2[this.simplexSize];
  11368. _this3.x -= v4.x;
  11369. _this3.y -= v4.y;
  11370. _this3.z -= v4.z;
  11371. this.simplexSize++;
  11372. this.lineToTetrahedron();
  11373. if(this.simplexSize == 4) {
  11374. break;
  11375. }
  11376. this.simplexSize--;
  11377. }
  11378. }
  11379. lineToTetrahedron() {
  11380. let oldDirX;
  11381. let oldDirY;
  11382. let oldDirZ;
  11383. let v = this.dir;
  11384. oldDirX = v.x;
  11385. oldDirY = v.y;
  11386. oldDirZ = v.z;
  11387. let s0X;
  11388. let s0Y;
  11389. let s0Z;
  11390. let s1X;
  11391. let s1Y;
  11392. let s1Z;
  11393. let lineDirX;
  11394. let lineDirY;
  11395. let lineDirZ;
  11396. let v1 = this.s[0];
  11397. s0X = v1.x;
  11398. s0Y = v1.y;
  11399. s0Z = v1.z;
  11400. let v2 = this.s[1];
  11401. s1X = v2.x;
  11402. s1Y = v2.y;
  11403. s1Z = v2.z;
  11404. lineDirX = s0X - s1X;
  11405. lineDirY = s0Y - s1Y;
  11406. lineDirZ = s0Z - s1Z;
  11407. let _g = 0;
  11408. while(_g < 3) {
  11409. let baseDirX;
  11410. let baseDirY;
  11411. let baseDirZ;
  11412. let v = this.baseDirs[_g++];
  11413. baseDirX = v.x;
  11414. baseDirY = v.y;
  11415. baseDirZ = v.z;
  11416. let newDirX;
  11417. let newDirY;
  11418. let newDirZ;
  11419. newDirX = lineDirY * baseDirZ - lineDirZ * baseDirY;
  11420. newDirY = lineDirZ * baseDirX - lineDirX * baseDirZ;
  11421. newDirZ = lineDirX * baseDirY - lineDirY * baseDirX;
  11422. let v1 = this.dir;
  11423. v1.x = newDirX;
  11424. v1.y = newDirY;
  11425. v1.z = newDirZ;
  11426. this.computeWitnessPoint1(false);
  11427. this.computeWitnessPoint2(false);
  11428. let _this = this.s[this.simplexSize];
  11429. let v2 = this.w1[this.simplexSize];
  11430. _this.x = v2.x;
  11431. _this.y = v2.y;
  11432. _this.z = v2.z;
  11433. let v3 = this.w2[this.simplexSize];
  11434. _this.x -= v3.x;
  11435. _this.y -= v3.y;
  11436. _this.z -= v3.z;
  11437. this.simplexSize++;
  11438. this.triangleToTetrahedron();
  11439. if(this.simplexSize == 4) {
  11440. break;
  11441. }
  11442. this.simplexSize--;
  11443. let _this1 = this.dir;
  11444. _this1.x = -_this1.x;
  11445. _this1.y = -_this1.y;
  11446. _this1.z = -_this1.z;
  11447. this.computeWitnessPoint1(false);
  11448. this.computeWitnessPoint2(false);
  11449. let _this2 = this.s[this.simplexSize];
  11450. let v4 = this.w1[this.simplexSize];
  11451. _this2.x = v4.x;
  11452. _this2.y = v4.y;
  11453. _this2.z = v4.z;
  11454. let v5 = this.w2[this.simplexSize];
  11455. _this2.x -= v5.x;
  11456. _this2.y -= v5.y;
  11457. _this2.z -= v5.z;
  11458. this.simplexSize++;
  11459. this.triangleToTetrahedron();
  11460. if(this.simplexSize == 4) {
  11461. break;
  11462. }
  11463. this.simplexSize--;
  11464. }
  11465. let v3 = this.dir;
  11466. v3.x = oldDirX;
  11467. v3.y = oldDirY;
  11468. v3.z = oldDirZ;
  11469. }
  11470. triangleToTetrahedron() {
  11471. let oldDirX;
  11472. let oldDirY;
  11473. let oldDirZ;
  11474. let v = this.dir;
  11475. oldDirX = v.x;
  11476. oldDirY = v.y;
  11477. oldDirZ = v.z;
  11478. while(true) {
  11479. let s0X;
  11480. let s0Y;
  11481. let s0Z;
  11482. let s1X;
  11483. let s1Y;
  11484. let s1Z;
  11485. let s2X;
  11486. let s2Y;
  11487. let s2Z;
  11488. let s01X;
  11489. let s01Y;
  11490. let s01Z;
  11491. let s02X;
  11492. let s02Y;
  11493. let s02Z;
  11494. let v = this.s[0];
  11495. s0X = v.x;
  11496. s0Y = v.y;
  11497. s0Z = v.z;
  11498. let v1 = this.s[1];
  11499. s1X = v1.x;
  11500. s1Y = v1.y;
  11501. s1Z = v1.z;
  11502. let v2 = this.s[2];
  11503. s2X = v2.x;
  11504. s2Y = v2.y;
  11505. s2Z = v2.z;
  11506. s01X = s1X - s0X;
  11507. s01Y = s1Y - s0Y;
  11508. s01Z = s1Z - s0Z;
  11509. s02X = s2X - s0X;
  11510. s02Y = s2Y - s0Y;
  11511. s02Z = s2Z - s0Z;
  11512. let nX;
  11513. let nY;
  11514. let nZ;
  11515. nX = s01Y * s02Z - s01Z * s02Y;
  11516. nY = s01Z * s02X - s01X * s02Z;
  11517. nZ = s01X * s02Y - s01Y * s02X;
  11518. let v3 = this.dir;
  11519. v3.x = nX;
  11520. v3.y = nY;
  11521. v3.z = nZ;
  11522. this.computeWitnessPoint1(false);
  11523. this.computeWitnessPoint2(false);
  11524. let _this = this.s[this.simplexSize];
  11525. let v4 = this.w1[this.simplexSize];
  11526. _this.x = v4.x;
  11527. _this.y = v4.y;
  11528. _this.z = v4.z;
  11529. let v5 = this.w2[this.simplexSize];
  11530. _this.x -= v5.x;
  11531. _this.y -= v5.y;
  11532. _this.z -= v5.z;
  11533. this.simplexSize++;
  11534. if(this.isValidTetrahedron()) {
  11535. break;
  11536. }
  11537. this.simplexSize--;
  11538. let _this1 = this.dir;
  11539. _this1.x = -_this1.x;
  11540. _this1.y = -_this1.y;
  11541. _this1.z = -_this1.z;
  11542. this.computeWitnessPoint1(false);
  11543. this.computeWitnessPoint2(false);
  11544. let _this2 = this.s[this.simplexSize];
  11545. let v6 = this.w1[this.simplexSize];
  11546. _this2.x = v6.x;
  11547. _this2.y = v6.y;
  11548. _this2.z = v6.z;
  11549. let v7 = this.w2[this.simplexSize];
  11550. _this2.x -= v7.x;
  11551. _this2.y -= v7.y;
  11552. _this2.z -= v7.z;
  11553. this.simplexSize++;
  11554. if(this.isValidTetrahedron()) {
  11555. break;
  11556. }
  11557. this.simplexSize--;
  11558. break;
  11559. }
  11560. let v1 = this.dir;
  11561. v1.x = oldDirX;
  11562. v1.y = oldDirY;
  11563. v1.z = oldDirZ;
  11564. }
  11565. isValidTetrahedron() {
  11566. let e10 = this.s[2].x - this.s[0].x;
  11567. let e11 = this.s[2].y - this.s[0].y;
  11568. let e12 = this.s[2].z - this.s[0].z;
  11569. let e20 = this.s[3].x - this.s[0].x;
  11570. let e21 = this.s[3].y - this.s[0].y;
  11571. let e22 = this.s[3].z - this.s[0].z;
  11572. let det = (this.s[1].x - this.s[0].x) * (e11 * e22 - e12 * e21) - (this.s[1].y - this.s[0].y) * (e10 * e22 - e12 * e20) + (this.s[1].z - this.s[0].z) * (e10 * e21 - e11 * e20);
  11573. if(!(det > 1e-12)) {
  11574. return det < -1e-12;
  11575. } else {
  11576. return true;
  11577. }
  11578. }
  11579. computeDepth(convex1,convex2,tf1,tf2,initialPolyhedron,initialPolyhedron1,initialPolyhedron2) {
  11580. let _this = this.polyhedron;
  11581. while(_this._numTriangles > 0) {
  11582. let t = _this._triangleList;
  11583. _this._numTriangles--;
  11584. let prev = t._prev;
  11585. let next = t._next;
  11586. if(prev != null) {
  11587. prev._next = next;
  11588. }
  11589. if(next != null) {
  11590. next._prev = prev;
  11591. }
  11592. if(t == _this._triangleList) {
  11593. _this._triangleList = _this._triangleList._next;
  11594. }
  11595. if(t == _this._triangleListLast) {
  11596. _this._triangleListLast = _this._triangleListLast._prev;
  11597. }
  11598. t._next = null;
  11599. t._prev = null;
  11600. t.removeReferences();
  11601. t._next = _this._trianglePool;
  11602. _this._trianglePool = t;
  11603. }
  11604. while(_this._numVertices > 0) {
  11605. let v = _this._vertices[--_this._numVertices];
  11606. v.removeReferences();
  11607. v._next = _this._vertexPool;
  11608. _this._vertexPool = v;
  11609. }
  11610. let tmp = this.polyhedron;
  11611. let _this1 = this.polyhedron;
  11612. let first = _this1._vertexPool;
  11613. if(first != null) {
  11614. _this1._vertexPool = first._next;
  11615. first._next = null;
  11616. } else {
  11617. first = new oimo.collision.narrowphase.detector.gjkepa.EpaVertex();
  11618. }
  11619. let tmp1 = first.init(initialPolyhedron[0],initialPolyhedron1[0],initialPolyhedron2[0]);
  11620. let _this2 = this.polyhedron;
  11621. let first1 = _this2._vertexPool;
  11622. if(first1 != null) {
  11623. _this2._vertexPool = first1._next;
  11624. first1._next = null;
  11625. } else {
  11626. first1 = new oimo.collision.narrowphase.detector.gjkepa.EpaVertex();
  11627. }
  11628. let tmp2 = first1.init(initialPolyhedron[1],initialPolyhedron1[1],initialPolyhedron2[1]);
  11629. let _this3 = this.polyhedron;
  11630. let first2 = _this3._vertexPool;
  11631. if(first2 != null) {
  11632. _this3._vertexPool = first2._next;
  11633. first2._next = null;
  11634. } else {
  11635. first2 = new oimo.collision.narrowphase.detector.gjkepa.EpaVertex();
  11636. }
  11637. let tmp3 = first2.init(initialPolyhedron[2],initialPolyhedron1[2],initialPolyhedron2[2]);
  11638. let _this4 = this.polyhedron;
  11639. let first3 = _this4._vertexPool;
  11640. if(first3 != null) {
  11641. _this4._vertexPool = first3._next;
  11642. first3._next = null;
  11643. } else {
  11644. first3 = new oimo.collision.narrowphase.detector.gjkepa.EpaVertex();
  11645. }
  11646. if(!tmp._init(tmp1,tmp2,tmp3,first3.init(initialPolyhedron[3],initialPolyhedron1[3],initialPolyhedron2[3]))) {
  11647. return oimo.collision.narrowphase.detector.gjkepa.GjkEpaResultState.EPA_FAILED_TO_INIT;
  11648. }
  11649. this.simplexSize = 0;
  11650. let supportingVertex = this.s[0];
  11651. let witness1 = this.w1[0];
  11652. let witness2 = this.w2[0];
  11653. let count = 0;
  11654. while(count < 40) {
  11655. let f = this.polyhedron._triangleList;
  11656. let mind = 1e65536;
  11657. let minf = null;
  11658. while(f != null) {
  11659. if(f._distanceSq < mind) {
  11660. mind = f._distanceSq;
  11661. minf = f;
  11662. }
  11663. f = f._next;
  11664. }
  11665. let face = minf;
  11666. let _this = this.dir;
  11667. let v = face._normal;
  11668. _this.x = v.x;
  11669. _this.y = v.y;
  11670. _this.z = v.z;
  11671. let invLen = Math.sqrt(_this.x * _this.x + _this.y * _this.y + _this.z * _this.z);
  11672. if(invLen > 0) {
  11673. invLen = 1 / invLen;
  11674. }
  11675. _this.x *= invLen;
  11676. _this.y *= invLen;
  11677. _this.z *= invLen;
  11678. this.computeWitnessPoint1(false);
  11679. this.computeWitnessPoint2(false);
  11680. let _this1 = this.s[this.simplexSize];
  11681. let v1 = this.w1[this.simplexSize];
  11682. _this1.x = v1.x;
  11683. _this1.y = v1.y;
  11684. _this1.z = v1.z;
  11685. let v2 = this.w2[this.simplexSize];
  11686. _this1.x -= v2.x;
  11687. _this1.y -= v2.y;
  11688. _this1.z -= v2.z;
  11689. let v0 = face._vertices[0];
  11690. let v11 = face._vertices[1];
  11691. let v21 = face._vertices[2];
  11692. let _this2 = v0.v;
  11693. let v3 = this.dir;
  11694. let v4 = this.dir;
  11695. if(supportingVertex.x * v4.x + supportingVertex.y * v4.y + supportingVertex.z * v4.z - (_this2.x * v3.x + _this2.y * v3.y + _this2.z * v3.z) < 1e-6 || count == 39) {
  11696. let _this = this.closest;
  11697. let v = this.dir;
  11698. _this.x = v.x;
  11699. _this.y = v.y;
  11700. _this.z = v.z;
  11701. let _this1 = this.dir;
  11702. let v1 = v0.v;
  11703. let _this2 = this.dir;
  11704. let s = (_this1.x * v1.x + _this1.y * v1.y + _this1.z * v1.z) / (_this2.x * _this2.x + _this2.y * _this2.y + _this2.z * _this2.z);
  11705. _this.x *= s;
  11706. _this.y *= s;
  11707. _this.z *= s;
  11708. let cX;
  11709. let cY;
  11710. let cZ;
  11711. let v2 = this.closest;
  11712. cX = v2.x;
  11713. cY = v2.y;
  11714. cZ = v2.z;
  11715. let s0X;
  11716. let s0Y;
  11717. let s0Z;
  11718. let w10X;
  11719. let w10Y;
  11720. let w10Z;
  11721. let w20X;
  11722. let w20Y;
  11723. let w20Z;
  11724. let s1X;
  11725. let s1Y;
  11726. let s1Z;
  11727. let w11X;
  11728. let w11Y;
  11729. let w11Z;
  11730. let w21X;
  11731. let w21Y;
  11732. let w21Z;
  11733. let s2X;
  11734. let s2Y;
  11735. let s2Z;
  11736. let w12X;
  11737. let w12Y;
  11738. let w12Z;
  11739. let w22X;
  11740. let w22Y;
  11741. let w22Z;
  11742. let v3 = v0.v;
  11743. s0X = v3.x;
  11744. s0Y = v3.y;
  11745. s0Z = v3.z;
  11746. let v4 = v0.w1;
  11747. w10X = v4.x;
  11748. w10Y = v4.y;
  11749. w10Z = v4.z;
  11750. let v5 = v0.w2;
  11751. w20X = v5.x;
  11752. w20Y = v5.y;
  11753. w20Z = v5.z;
  11754. let v6 = v11.v;
  11755. s1X = v6.x;
  11756. s1Y = v6.y;
  11757. s1Z = v6.z;
  11758. let v7 = v11.w1;
  11759. w11X = v7.x;
  11760. w11Y = v7.y;
  11761. w11Z = v7.z;
  11762. let v8 = v11.w2;
  11763. w21X = v8.x;
  11764. w21Y = v8.y;
  11765. w21Z = v8.z;
  11766. let v9 = v21.v;
  11767. s2X = v9.x;
  11768. s2Y = v9.y;
  11769. s2Z = v9.z;
  11770. let v10 = v21.w1;
  11771. w12X = v10.x;
  11772. w12Y = v10.y;
  11773. w12Z = v10.z;
  11774. let v12 = v21.w2;
  11775. w22X = v12.x;
  11776. w22Y = v12.y;
  11777. w22Z = v12.z;
  11778. let s01X;
  11779. let s01Y;
  11780. let s01Z;
  11781. let s02X;
  11782. let s02Y;
  11783. let s02Z;
  11784. let s0cX;
  11785. let s0cY;
  11786. let s0cZ;
  11787. s01X = s1X - s0X;
  11788. s01Y = s1Y - s0Y;
  11789. s01Z = s1Z - s0Z;
  11790. s02X = s2X - s0X;
  11791. s02Y = s2Y - s0Y;
  11792. s02Z = s2Z - s0Z;
  11793. s0cX = cX - s0X;
  11794. s0cY = cY - s0Y;
  11795. s0cZ = cZ - s0Z;
  11796. let d11 = s01X * s01X + s01Y * s01Y + s01Z * s01Z;
  11797. let d12 = s01X * s02X + s01Y * s02Y + s01Z * s02Z;
  11798. let d22 = s02X * s02X + s02Y * s02Y + s02Z * s02Z;
  11799. let d1c = s01X * s0cX + s01Y * s0cY + s01Z * s0cZ;
  11800. let d2c = s02X * s0cX + s02Y * s0cY + s02Z * s0cZ;
  11801. let invDet = d11 * d22 - d12 * d12;
  11802. if(invDet != 0) {
  11803. invDet = 1 / invDet;
  11804. }
  11805. let s1 = (d1c * d22 - d2c * d12) * invDet;
  11806. let t = (-d1c * d12 + d2c * d11) * invDet;
  11807. let diffX;
  11808. let diffY;
  11809. let diffZ;
  11810. let cp1X;
  11811. let cp1Y;
  11812. let cp1Z;
  11813. let cp2X;
  11814. let cp2Y;
  11815. let cp2Z;
  11816. diffX = w11X - w10X;
  11817. diffY = w11Y - w10Y;
  11818. diffZ = w11Z - w10Z;
  11819. cp1X = w10X + diffX * s1;
  11820. cp1Y = w10Y + diffY * s1;
  11821. cp1Z = w10Z + diffZ * s1;
  11822. diffX = w12X - w10X;
  11823. diffY = w12Y - w10Y;
  11824. diffZ = w12Z - w10Z;
  11825. cp1X += diffX * t;
  11826. cp1Y += diffY * t;
  11827. cp1Z += diffZ * t;
  11828. diffX = w21X - w20X;
  11829. diffY = w21Y - w20Y;
  11830. diffZ = w21Z - w20Z;
  11831. cp2X = w20X + diffX * s1;
  11832. cp2Y = w20Y + diffY * s1;
  11833. cp2Z = w20Z + diffZ * s1;
  11834. diffX = w22X - w20X;
  11835. diffY = w22Y - w20Y;
  11836. diffZ = w22Z - w20Z;
  11837. cp2X += diffX * t;
  11838. cp2Y += diffY * t;
  11839. cp2Z += diffZ * t;
  11840. let v13 = this.closestPoint1;
  11841. v13.x = cp1X;
  11842. v13.y = cp1Y;
  11843. v13.z = cp1Z;
  11844. let v14 = this.closestPoint2;
  11845. v14.x = cp2X;
  11846. v14.y = cp2Y;
  11847. v14.z = cp2Z;
  11848. let _this3 = this.closest;
  11849. this.depth = Math.sqrt(_this3.x * _this3.x + _this3.y * _this3.y + _this3.z * _this3.z);
  11850. return oimo.collision.narrowphase.detector.gjkepa.GjkEpaResultState.SUCCEEDED;
  11851. }
  11852. let _this3 = this.polyhedron;
  11853. let first = _this3._vertexPool;
  11854. if(first != null) {
  11855. _this3._vertexPool = first._next;
  11856. first._next = null;
  11857. } else {
  11858. first = new oimo.collision.narrowphase.detector.gjkepa.EpaVertex();
  11859. }
  11860. let epaVertex = first.init(supportingVertex,witness1,witness2);
  11861. if(!this.polyhedron._addVertex(epaVertex,face)) {
  11862. return oimo.collision.narrowphase.detector.gjkepa.GjkEpaResultState.EPA_FAILED_TO_ADD_VERTEX;
  11863. }
  11864. ++count;
  11865. }
  11866. return oimo.collision.narrowphase.detector.gjkepa.GjkEpaResultState.EPA_DID_NOT_CONVERGE;
  11867. }
  11868. computeClosestPoints(c1,c2,tf1,tf2,cache) {
  11869. return this.computeClosestPointsImpl(c1,c2,tf1,tf2,cache,true);
  11870. }
  11871. computeDistance(c1,c2,tf1,tf2,cache) {
  11872. return this.computeClosestPointsImpl(c1,c2,tf1,tf2,cache,false);
  11873. }
  11874. convexCast(c1,c2,tf1,tf2,tl1,tl2,hit) {
  11875. return this.convexCastImpl(c1,c2,tf1,tf2,tl1,tl2,hit);
  11876. }
  11877. rayCast(c,tf,begin,end,hit) {
  11878. let tf1 = this.tempTransform;
  11879. tf1._positionX = begin.x;
  11880. tf1._positionY = begin.y;
  11881. tf1._positionZ = begin.z;
  11882. let tl1 = this.tl1;
  11883. let tl2 = this.tl2;
  11884. tl1.x = end.x;
  11885. tl1.y = end.y;
  11886. tl1.z = end.z;
  11887. tl1.x -= begin.x;
  11888. tl1.y -= begin.y;
  11889. tl1.z -= begin.z;
  11890. tl2.zero();
  11891. return this.convexCastImpl(null,c,tf1,tf,tl1,tl2,hit);
  11892. }
  11893. static getInstance() {
  11894. return oimo.collision.narrowphase.detector.gjkepa.GjkEpa.instance;
  11895. }
  11896. }
  11897. oimo.collision.narrowphase.detector.gjkepa.GjkEpaLog = class oimo_collision_narrowphase_detector_gjkepa_GjkEpaLog {
  11898. }
  11899. oimo.collision.narrowphase.detector.gjkepa.GjkEpaResultState = class oimo_collision_narrowphase_detector_gjkepa_GjkEpaResultState {
  11900. }
  11901. oimo.collision.narrowphase.detector.gjkepa.SimplexUtil = class oimo_collision_narrowphase_detector_gjkepa_SimplexUtil {
  11902. static projectOrigin2(vec1,vec2,out) {
  11903. let v1X;
  11904. let v1Y;
  11905. let v1Z;
  11906. let v2X;
  11907. let v2Y;
  11908. let v2Z;
  11909. v1X = vec1.x;
  11910. v1Y = vec1.y;
  11911. v1Z = vec1.z;
  11912. v2X = vec2.x;
  11913. v2Y = vec2.y;
  11914. v2Z = vec2.z;
  11915. let v12X;
  11916. let v12Y;
  11917. let v12Z;
  11918. v12X = v2X - v1X;
  11919. v12Y = v2Y - v1Y;
  11920. v12Z = v2Z - v1Z;
  11921. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  11922. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  11923. if(t < 0) {
  11924. out.x = v1X;
  11925. out.y = v1Y;
  11926. out.z = v1Z;
  11927. return 1;
  11928. }
  11929. if(t > 1) {
  11930. out.x = v2X;
  11931. out.y = v2Y;
  11932. out.z = v2Z;
  11933. return 2;
  11934. }
  11935. let pX;
  11936. let pY;
  11937. let pZ;
  11938. pX = v1X + v12X * t;
  11939. pY = v1Y + v12Y * t;
  11940. pZ = v1Z + v12Z * t;
  11941. out.x = pX;
  11942. out.y = pY;
  11943. out.z = pZ;
  11944. return 3;
  11945. }
  11946. static projectOrigin3(vec1,vec2,vec3,out) {
  11947. let v1X;
  11948. let v1Y;
  11949. let v1Z;
  11950. let v2X;
  11951. let v2Y;
  11952. let v2Z;
  11953. let v3X;
  11954. let v3Y;
  11955. let v3Z;
  11956. let v12X;
  11957. let v12Y;
  11958. let v12Z;
  11959. let v23X;
  11960. let v23Y;
  11961. let v23Z;
  11962. let v31X;
  11963. let v31Y;
  11964. let v31Z;
  11965. v1X = vec1.x;
  11966. v1Y = vec1.y;
  11967. v1Z = vec1.z;
  11968. v2X = vec2.x;
  11969. v2Y = vec2.y;
  11970. v2Z = vec2.z;
  11971. v3X = vec3.x;
  11972. v3Y = vec3.y;
  11973. v3Z = vec3.z;
  11974. v12X = v2X - v1X;
  11975. v12Y = v2Y - v1Y;
  11976. v12Z = v2Z - v1Z;
  11977. v23X = v3X - v2X;
  11978. v23Y = v3Y - v2Y;
  11979. v23Z = v3Z - v2Z;
  11980. v31X = v1X - v3X;
  11981. v31Y = v1Y - v3Y;
  11982. v31Z = v1Z - v3Z;
  11983. let nX;
  11984. let nY;
  11985. let nZ;
  11986. nX = v12Y * v23Z - v12Z * v23Y;
  11987. nY = v12Z * v23X - v12X * v23Z;
  11988. nZ = v12X * v23Y - v12Y * v23X;
  11989. let n12X;
  11990. let n12Y;
  11991. let n12Z;
  11992. let n23X;
  11993. let n23Y;
  11994. let n23Z;
  11995. let n31X;
  11996. let n31Y;
  11997. let n31Z;
  11998. n12X = v12Y * nZ - v12Z * nY;
  11999. n12Y = v12Z * nX - v12X * nZ;
  12000. n12Z = v12X * nY - v12Y * nX;
  12001. n23X = v23Y * nZ - v23Z * nY;
  12002. n23Y = v23Z * nX - v23X * nZ;
  12003. n23Z = v23X * nY - v23Y * nX;
  12004. n31X = v31Y * nZ - v31Z * nY;
  12005. n31Y = v31Z * nX - v31X * nZ;
  12006. n31Z = v31X * nY - v31Y * nX;
  12007. let mind = -1;
  12008. let minvX;
  12009. let minvY;
  12010. let minvZ;
  12011. let mini = 0;
  12012. minvX = 0;
  12013. minvY = 0;
  12014. minvZ = 0;
  12015. if(v1X * n12X + v1Y * n12Y + v1Z * n12Z < 0) {
  12016. let v1X;
  12017. let v1Y;
  12018. let v1Z;
  12019. let v2X;
  12020. let v2Y;
  12021. let v2Z;
  12022. v1X = vec1.x;
  12023. v1Y = vec1.y;
  12024. v1Z = vec1.z;
  12025. v2X = vec2.x;
  12026. v2Y = vec2.y;
  12027. v2Z = vec2.z;
  12028. let v12X;
  12029. let v12Y;
  12030. let v12Z;
  12031. v12X = v2X - v1X;
  12032. v12Y = v2Y - v1Y;
  12033. v12Z = v2Z - v1Z;
  12034. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  12035. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  12036. let b;
  12037. if(t < 0) {
  12038. out.x = v1X;
  12039. out.y = v1Y;
  12040. out.z = v1Z;
  12041. b = 1;
  12042. } else if(t > 1) {
  12043. out.x = v2X;
  12044. out.y = v2Y;
  12045. out.z = v2Z;
  12046. b = 2;
  12047. } else {
  12048. let pX;
  12049. let pY;
  12050. let pZ;
  12051. pX = v1X + v12X * t;
  12052. pY = v1Y + v12Y * t;
  12053. pZ = v1Z + v12Z * t;
  12054. out.x = pX;
  12055. out.y = pY;
  12056. out.z = pZ;
  12057. b = 3;
  12058. }
  12059. mini = b;
  12060. mind = out.x * out.x + out.y * out.y + out.z * out.z;
  12061. minvX = out.x;
  12062. minvY = out.y;
  12063. minvZ = out.z;
  12064. }
  12065. if(v2X * n23X + v2Y * n23Y + v2Z * n23Z < 0) {
  12066. let v1X;
  12067. let v1Y;
  12068. let v1Z;
  12069. let v2X;
  12070. let v2Y;
  12071. let v2Z;
  12072. v1X = vec2.x;
  12073. v1Y = vec2.y;
  12074. v1Z = vec2.z;
  12075. v2X = vec3.x;
  12076. v2Y = vec3.y;
  12077. v2Z = vec3.z;
  12078. let v12X;
  12079. let v12Y;
  12080. let v12Z;
  12081. v12X = v2X - v1X;
  12082. v12Y = v2Y - v1Y;
  12083. v12Z = v2Z - v1Z;
  12084. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  12085. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  12086. let b;
  12087. if(t < 0) {
  12088. out.x = v1X;
  12089. out.y = v1Y;
  12090. out.z = v1Z;
  12091. b = 1;
  12092. } else if(t > 1) {
  12093. out.x = v2X;
  12094. out.y = v2Y;
  12095. out.z = v2Z;
  12096. b = 2;
  12097. } else {
  12098. let pX;
  12099. let pY;
  12100. let pZ;
  12101. pX = v1X + v12X * t;
  12102. pY = v1Y + v12Y * t;
  12103. pZ = v1Z + v12Z * t;
  12104. out.x = pX;
  12105. out.y = pY;
  12106. out.z = pZ;
  12107. b = 3;
  12108. }
  12109. let d = out.x * out.x + out.y * out.y + out.z * out.z;
  12110. if(mind < 0 || d < mind) {
  12111. mini = b << 1;
  12112. mind = d;
  12113. minvX = out.x;
  12114. minvY = out.y;
  12115. minvZ = out.z;
  12116. }
  12117. }
  12118. if(v3X * n31X + v3Y * n31Y + v3Z * n31Z < 0) {
  12119. let v1X;
  12120. let v1Y;
  12121. let v1Z;
  12122. let v2X;
  12123. let v2Y;
  12124. let v2Z;
  12125. v1X = vec1.x;
  12126. v1Y = vec1.y;
  12127. v1Z = vec1.z;
  12128. v2X = vec3.x;
  12129. v2Y = vec3.y;
  12130. v2Z = vec3.z;
  12131. let v12X;
  12132. let v12Y;
  12133. let v12Z;
  12134. v12X = v2X - v1X;
  12135. v12Y = v2Y - v1Y;
  12136. v12Z = v2Z - v1Z;
  12137. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  12138. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  12139. let b;
  12140. if(t < 0) {
  12141. out.x = v1X;
  12142. out.y = v1Y;
  12143. out.z = v1Z;
  12144. b = 1;
  12145. } else if(t > 1) {
  12146. out.x = v2X;
  12147. out.y = v2Y;
  12148. out.z = v2Z;
  12149. b = 2;
  12150. } else {
  12151. let pX;
  12152. let pY;
  12153. let pZ;
  12154. pX = v1X + v12X * t;
  12155. pY = v1Y + v12Y * t;
  12156. pZ = v1Z + v12Z * t;
  12157. out.x = pX;
  12158. out.y = pY;
  12159. out.z = pZ;
  12160. b = 3;
  12161. }
  12162. let d = out.x * out.x + out.y * out.y + out.z * out.z;
  12163. if(mind < 0 || d < mind) {
  12164. mini = b & 1 | (b & 2) << 1;
  12165. mind = d;
  12166. minvX = out.x;
  12167. minvY = out.y;
  12168. minvZ = out.z;
  12169. }
  12170. }
  12171. if(mind > 0) {
  12172. out.x = minvX;
  12173. out.y = minvY;
  12174. out.z = minvZ;
  12175. return mini;
  12176. }
  12177. let l = nX * nX + nY * nY + nZ * nZ;
  12178. if(l > 0) {
  12179. l = 1 / Math.sqrt(l);
  12180. }
  12181. nX *= l;
  12182. nY *= l;
  12183. nZ *= l;
  12184. let l2 = nX * nX + nY * nY + nZ * nZ;
  12185. l2 = (v1X * nX + v1Y * nY + v1Z * nZ) / l2;
  12186. minvX = nX * l2;
  12187. minvY = nY * l2;
  12188. minvZ = nZ * l2;
  12189. out.x = minvX;
  12190. out.y = minvY;
  12191. out.z = minvZ;
  12192. return 7;
  12193. }
  12194. static projectOrigin4(vec1,vec2,vec3,vec4,out) {
  12195. let v1X;
  12196. let v1Y;
  12197. let v1Z;
  12198. let v2X;
  12199. let v2Y;
  12200. let v2Z;
  12201. let v3X;
  12202. let v3Y;
  12203. let v3Z;
  12204. let v4X;
  12205. let v4Y;
  12206. let v4Z;
  12207. let v12X;
  12208. let v12Y;
  12209. let v12Z;
  12210. let v13X;
  12211. let v13Y;
  12212. let v13Z;
  12213. let v14X;
  12214. let v14Y;
  12215. let v14Z;
  12216. let v23X;
  12217. let v23Y;
  12218. let v23Z;
  12219. let v24X;
  12220. let v24Y;
  12221. let v24Z;
  12222. v1X = vec1.x;
  12223. v1Y = vec1.y;
  12224. v1Z = vec1.z;
  12225. v2X = vec2.x;
  12226. v2Y = vec2.y;
  12227. v2Z = vec2.z;
  12228. v3X = vec3.x;
  12229. v3Y = vec3.y;
  12230. v3Z = vec3.z;
  12231. v4X = vec4.x;
  12232. v4Y = vec4.y;
  12233. v4Z = vec4.z;
  12234. v12X = v2X - v1X;
  12235. v12Y = v2Y - v1Y;
  12236. v12Z = v2Z - v1Z;
  12237. v13X = v3X - v1X;
  12238. v13Y = v3Y - v1Y;
  12239. v13Z = v3Z - v1Z;
  12240. v14X = v4X - v1X;
  12241. v14Y = v4Y - v1Y;
  12242. v14Z = v4Z - v1Z;
  12243. v23X = v3X - v2X;
  12244. v23Y = v3Y - v2Y;
  12245. v23Z = v3Z - v2Z;
  12246. v24X = v4X - v2X;
  12247. v24Y = v4Y - v2Y;
  12248. v24Z = v4Z - v2Z;
  12249. let n123X;
  12250. let n123Y;
  12251. let n123Z;
  12252. let n134X;
  12253. let n134Y;
  12254. let n134Z;
  12255. let n142X;
  12256. let n142Y;
  12257. let n142Z;
  12258. let n243X;
  12259. let n243Y;
  12260. let n243Z;
  12261. n123X = v12Y * v13Z - v12Z * v13Y;
  12262. n123Y = v12Z * v13X - v12X * v13Z;
  12263. n123Z = v12X * v13Y - v12Y * v13X;
  12264. n134X = v13Y * v14Z - v13Z * v14Y;
  12265. n134Y = v13Z * v14X - v13X * v14Z;
  12266. n134Z = v13X * v14Y - v13Y * v14X;
  12267. n142X = v14Y * v12Z - v14Z * v12Y;
  12268. n142Y = v14Z * v12X - v14X * v12Z;
  12269. n142Z = v14X * v12Y - v14Y * v12X;
  12270. n243X = v24Y * v23Z - v24Z * v23Y;
  12271. n243Y = v24Z * v23X - v24X * v23Z;
  12272. n243Z = v24X * v23Y - v24Y * v23X;
  12273. let sign = v12X * n243X + v12Y * n243Y + v12Z * n243Z > 0 ? 1 : -1;
  12274. let mind = -1;
  12275. let minvX;
  12276. let minvY;
  12277. let minvZ;
  12278. let mini = 0;
  12279. minvX = 0;
  12280. minvY = 0;
  12281. minvZ = 0;
  12282. if((v1X * n123X + v1Y * n123Y + v1Z * n123Z) * sign < 0) {
  12283. let v1X;
  12284. let v1Y;
  12285. let v1Z;
  12286. let v2X;
  12287. let v2Y;
  12288. let v2Z;
  12289. let v3X;
  12290. let v3Y;
  12291. let v3Z;
  12292. let v12X;
  12293. let v12Y;
  12294. let v12Z;
  12295. let v23X;
  12296. let v23Y;
  12297. let v23Z;
  12298. let v31X;
  12299. let v31Y;
  12300. let v31Z;
  12301. v1X = vec1.x;
  12302. v1Y = vec1.y;
  12303. v1Z = vec1.z;
  12304. v2X = vec2.x;
  12305. v2Y = vec2.y;
  12306. v2Z = vec2.z;
  12307. v3X = vec3.x;
  12308. v3Y = vec3.y;
  12309. v3Z = vec3.z;
  12310. v12X = v2X - v1X;
  12311. v12Y = v2Y - v1Y;
  12312. v12Z = v2Z - v1Z;
  12313. v23X = v3X - v2X;
  12314. v23Y = v3Y - v2Y;
  12315. v23Z = v3Z - v2Z;
  12316. v31X = v1X - v3X;
  12317. v31Y = v1Y - v3Y;
  12318. v31Z = v1Z - v3Z;
  12319. let nX;
  12320. let nY;
  12321. let nZ;
  12322. nX = v12Y * v23Z - v12Z * v23Y;
  12323. nY = v12Z * v23X - v12X * v23Z;
  12324. nZ = v12X * v23Y - v12Y * v23X;
  12325. let n12X;
  12326. let n12Y;
  12327. let n12Z;
  12328. let n23X;
  12329. let n23Y;
  12330. let n23Z;
  12331. let n31X;
  12332. let n31Y;
  12333. let n31Z;
  12334. n12X = v12Y * nZ - v12Z * nY;
  12335. n12Y = v12Z * nX - v12X * nZ;
  12336. n12Z = v12X * nY - v12Y * nX;
  12337. n23X = v23Y * nZ - v23Z * nY;
  12338. n23Y = v23Z * nX - v23X * nZ;
  12339. n23Z = v23X * nY - v23Y * nX;
  12340. n31X = v31Y * nZ - v31Z * nY;
  12341. n31Y = v31Z * nX - v31X * nZ;
  12342. n31Z = v31X * nY - v31Y * nX;
  12343. let mind1 = -1;
  12344. let minvX1;
  12345. let minvY1;
  12346. let minvZ1;
  12347. let mini1 = 0;
  12348. minvX1 = 0;
  12349. minvY1 = 0;
  12350. minvZ1 = 0;
  12351. if(v1X * n12X + v1Y * n12Y + v1Z * n12Z < 0) {
  12352. let v1X;
  12353. let v1Y;
  12354. let v1Z;
  12355. let v2X;
  12356. let v2Y;
  12357. let v2Z;
  12358. v1X = vec1.x;
  12359. v1Y = vec1.y;
  12360. v1Z = vec1.z;
  12361. v2X = vec2.x;
  12362. v2Y = vec2.y;
  12363. v2Z = vec2.z;
  12364. let v12X;
  12365. let v12Y;
  12366. let v12Z;
  12367. v12X = v2X - v1X;
  12368. v12Y = v2Y - v1Y;
  12369. v12Z = v2Z - v1Z;
  12370. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  12371. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  12372. let b;
  12373. if(t < 0) {
  12374. out.x = v1X;
  12375. out.y = v1Y;
  12376. out.z = v1Z;
  12377. b = 1;
  12378. } else if(t > 1) {
  12379. out.x = v2X;
  12380. out.y = v2Y;
  12381. out.z = v2Z;
  12382. b = 2;
  12383. } else {
  12384. let pX;
  12385. let pY;
  12386. let pZ;
  12387. pX = v1X + v12X * t;
  12388. pY = v1Y + v12Y * t;
  12389. pZ = v1Z + v12Z * t;
  12390. out.x = pX;
  12391. out.y = pY;
  12392. out.z = pZ;
  12393. b = 3;
  12394. }
  12395. mini1 = b;
  12396. mind1 = out.x * out.x + out.y * out.y + out.z * out.z;
  12397. minvX1 = out.x;
  12398. minvY1 = out.y;
  12399. minvZ1 = out.z;
  12400. }
  12401. if(v2X * n23X + v2Y * n23Y + v2Z * n23Z < 0) {
  12402. let v1X;
  12403. let v1Y;
  12404. let v1Z;
  12405. let v2X;
  12406. let v2Y;
  12407. let v2Z;
  12408. v1X = vec2.x;
  12409. v1Y = vec2.y;
  12410. v1Z = vec2.z;
  12411. v2X = vec3.x;
  12412. v2Y = vec3.y;
  12413. v2Z = vec3.z;
  12414. let v12X;
  12415. let v12Y;
  12416. let v12Z;
  12417. v12X = v2X - v1X;
  12418. v12Y = v2Y - v1Y;
  12419. v12Z = v2Z - v1Z;
  12420. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  12421. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  12422. let b;
  12423. if(t < 0) {
  12424. out.x = v1X;
  12425. out.y = v1Y;
  12426. out.z = v1Z;
  12427. b = 1;
  12428. } else if(t > 1) {
  12429. out.x = v2X;
  12430. out.y = v2Y;
  12431. out.z = v2Z;
  12432. b = 2;
  12433. } else {
  12434. let pX;
  12435. let pY;
  12436. let pZ;
  12437. pX = v1X + v12X * t;
  12438. pY = v1Y + v12Y * t;
  12439. pZ = v1Z + v12Z * t;
  12440. out.x = pX;
  12441. out.y = pY;
  12442. out.z = pZ;
  12443. b = 3;
  12444. }
  12445. let d = out.x * out.x + out.y * out.y + out.z * out.z;
  12446. if(mind1 < 0 || d < mind1) {
  12447. mini1 = b << 1;
  12448. mind1 = d;
  12449. minvX1 = out.x;
  12450. minvY1 = out.y;
  12451. minvZ1 = out.z;
  12452. }
  12453. }
  12454. if(v3X * n31X + v3Y * n31Y + v3Z * n31Z < 0) {
  12455. let v1X;
  12456. let v1Y;
  12457. let v1Z;
  12458. let v2X;
  12459. let v2Y;
  12460. let v2Z;
  12461. v1X = vec1.x;
  12462. v1Y = vec1.y;
  12463. v1Z = vec1.z;
  12464. v2X = vec3.x;
  12465. v2Y = vec3.y;
  12466. v2Z = vec3.z;
  12467. let v12X;
  12468. let v12Y;
  12469. let v12Z;
  12470. v12X = v2X - v1X;
  12471. v12Y = v2Y - v1Y;
  12472. v12Z = v2Z - v1Z;
  12473. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  12474. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  12475. let b;
  12476. if(t < 0) {
  12477. out.x = v1X;
  12478. out.y = v1Y;
  12479. out.z = v1Z;
  12480. b = 1;
  12481. } else if(t > 1) {
  12482. out.x = v2X;
  12483. out.y = v2Y;
  12484. out.z = v2Z;
  12485. b = 2;
  12486. } else {
  12487. let pX;
  12488. let pY;
  12489. let pZ;
  12490. pX = v1X + v12X * t;
  12491. pY = v1Y + v12Y * t;
  12492. pZ = v1Z + v12Z * t;
  12493. out.x = pX;
  12494. out.y = pY;
  12495. out.z = pZ;
  12496. b = 3;
  12497. }
  12498. let d = out.x * out.x + out.y * out.y + out.z * out.z;
  12499. if(mind1 < 0 || d < mind1) {
  12500. mini1 = b & 1 | (b & 2) << 1;
  12501. mind1 = d;
  12502. minvX1 = out.x;
  12503. minvY1 = out.y;
  12504. minvZ1 = out.z;
  12505. }
  12506. }
  12507. let b;
  12508. if(mind1 > 0) {
  12509. out.x = minvX1;
  12510. out.y = minvY1;
  12511. out.z = minvZ1;
  12512. b = mini1;
  12513. } else {
  12514. let l = nX * nX + nY * nY + nZ * nZ;
  12515. if(l > 0) {
  12516. l = 1 / Math.sqrt(l);
  12517. }
  12518. nX *= l;
  12519. nY *= l;
  12520. nZ *= l;
  12521. let l2 = nX * nX + nY * nY + nZ * nZ;
  12522. l2 = (v1X * nX + v1Y * nY + v1Z * nZ) / l2;
  12523. minvX1 = nX * l2;
  12524. minvY1 = nY * l2;
  12525. minvZ1 = nZ * l2;
  12526. out.x = minvX1;
  12527. out.y = minvY1;
  12528. out.z = minvZ1;
  12529. b = 7;
  12530. }
  12531. mini = b;
  12532. mind = out.x * out.x + out.y * out.y + out.z * out.z;
  12533. minvX = out.x;
  12534. minvY = out.y;
  12535. minvZ = out.z;
  12536. }
  12537. if((v1X * n134X + v1Y * n134Y + v1Z * n134Z) * sign < 0) {
  12538. let v1X;
  12539. let v1Y;
  12540. let v1Z;
  12541. let v2X;
  12542. let v2Y;
  12543. let v2Z;
  12544. let v3X;
  12545. let v3Y;
  12546. let v3Z;
  12547. let v12X;
  12548. let v12Y;
  12549. let v12Z;
  12550. let v23X;
  12551. let v23Y;
  12552. let v23Z;
  12553. let v31X;
  12554. let v31Y;
  12555. let v31Z;
  12556. v1X = vec1.x;
  12557. v1Y = vec1.y;
  12558. v1Z = vec1.z;
  12559. v2X = vec3.x;
  12560. v2Y = vec3.y;
  12561. v2Z = vec3.z;
  12562. v3X = vec4.x;
  12563. v3Y = vec4.y;
  12564. v3Z = vec4.z;
  12565. v12X = v2X - v1X;
  12566. v12Y = v2Y - v1Y;
  12567. v12Z = v2Z - v1Z;
  12568. v23X = v3X - v2X;
  12569. v23Y = v3Y - v2Y;
  12570. v23Z = v3Z - v2Z;
  12571. v31X = v1X - v3X;
  12572. v31Y = v1Y - v3Y;
  12573. v31Z = v1Z - v3Z;
  12574. let nX;
  12575. let nY;
  12576. let nZ;
  12577. nX = v12Y * v23Z - v12Z * v23Y;
  12578. nY = v12Z * v23X - v12X * v23Z;
  12579. nZ = v12X * v23Y - v12Y * v23X;
  12580. let n12X;
  12581. let n12Y;
  12582. let n12Z;
  12583. let n23X;
  12584. let n23Y;
  12585. let n23Z;
  12586. let n31X;
  12587. let n31Y;
  12588. let n31Z;
  12589. n12X = v12Y * nZ - v12Z * nY;
  12590. n12Y = v12Z * nX - v12X * nZ;
  12591. n12Z = v12X * nY - v12Y * nX;
  12592. n23X = v23Y * nZ - v23Z * nY;
  12593. n23Y = v23Z * nX - v23X * nZ;
  12594. n23Z = v23X * nY - v23Y * nX;
  12595. n31X = v31Y * nZ - v31Z * nY;
  12596. n31Y = v31Z * nX - v31X * nZ;
  12597. n31Z = v31X * nY - v31Y * nX;
  12598. let mind1 = -1;
  12599. let minvX1;
  12600. let minvY1;
  12601. let minvZ1;
  12602. let mini1 = 0;
  12603. minvX1 = 0;
  12604. minvY1 = 0;
  12605. minvZ1 = 0;
  12606. if(v1X * n12X + v1Y * n12Y + v1Z * n12Z < 0) {
  12607. let v1X;
  12608. let v1Y;
  12609. let v1Z;
  12610. let v2X;
  12611. let v2Y;
  12612. let v2Z;
  12613. v1X = vec1.x;
  12614. v1Y = vec1.y;
  12615. v1Z = vec1.z;
  12616. v2X = vec3.x;
  12617. v2Y = vec3.y;
  12618. v2Z = vec3.z;
  12619. let v12X;
  12620. let v12Y;
  12621. let v12Z;
  12622. v12X = v2X - v1X;
  12623. v12Y = v2Y - v1Y;
  12624. v12Z = v2Z - v1Z;
  12625. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  12626. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  12627. let b;
  12628. if(t < 0) {
  12629. out.x = v1X;
  12630. out.y = v1Y;
  12631. out.z = v1Z;
  12632. b = 1;
  12633. } else if(t > 1) {
  12634. out.x = v2X;
  12635. out.y = v2Y;
  12636. out.z = v2Z;
  12637. b = 2;
  12638. } else {
  12639. let pX;
  12640. let pY;
  12641. let pZ;
  12642. pX = v1X + v12X * t;
  12643. pY = v1Y + v12Y * t;
  12644. pZ = v1Z + v12Z * t;
  12645. out.x = pX;
  12646. out.y = pY;
  12647. out.z = pZ;
  12648. b = 3;
  12649. }
  12650. mini1 = b;
  12651. mind1 = out.x * out.x + out.y * out.y + out.z * out.z;
  12652. minvX1 = out.x;
  12653. minvY1 = out.y;
  12654. minvZ1 = out.z;
  12655. }
  12656. if(v2X * n23X + v2Y * n23Y + v2Z * n23Z < 0) {
  12657. let v1X;
  12658. let v1Y;
  12659. let v1Z;
  12660. let v2X;
  12661. let v2Y;
  12662. let v2Z;
  12663. v1X = vec3.x;
  12664. v1Y = vec3.y;
  12665. v1Z = vec3.z;
  12666. v2X = vec4.x;
  12667. v2Y = vec4.y;
  12668. v2Z = vec4.z;
  12669. let v12X;
  12670. let v12Y;
  12671. let v12Z;
  12672. v12X = v2X - v1X;
  12673. v12Y = v2Y - v1Y;
  12674. v12Z = v2Z - v1Z;
  12675. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  12676. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  12677. let b;
  12678. if(t < 0) {
  12679. out.x = v1X;
  12680. out.y = v1Y;
  12681. out.z = v1Z;
  12682. b = 1;
  12683. } else if(t > 1) {
  12684. out.x = v2X;
  12685. out.y = v2Y;
  12686. out.z = v2Z;
  12687. b = 2;
  12688. } else {
  12689. let pX;
  12690. let pY;
  12691. let pZ;
  12692. pX = v1X + v12X * t;
  12693. pY = v1Y + v12Y * t;
  12694. pZ = v1Z + v12Z * t;
  12695. out.x = pX;
  12696. out.y = pY;
  12697. out.z = pZ;
  12698. b = 3;
  12699. }
  12700. let d = out.x * out.x + out.y * out.y + out.z * out.z;
  12701. if(mind1 < 0 || d < mind1) {
  12702. mini1 = b << 1;
  12703. mind1 = d;
  12704. minvX1 = out.x;
  12705. minvY1 = out.y;
  12706. minvZ1 = out.z;
  12707. }
  12708. }
  12709. if(v3X * n31X + v3Y * n31Y + v3Z * n31Z < 0) {
  12710. let v1X;
  12711. let v1Y;
  12712. let v1Z;
  12713. let v2X;
  12714. let v2Y;
  12715. let v2Z;
  12716. v1X = vec1.x;
  12717. v1Y = vec1.y;
  12718. v1Z = vec1.z;
  12719. v2X = vec4.x;
  12720. v2Y = vec4.y;
  12721. v2Z = vec4.z;
  12722. let v12X;
  12723. let v12Y;
  12724. let v12Z;
  12725. v12X = v2X - v1X;
  12726. v12Y = v2Y - v1Y;
  12727. v12Z = v2Z - v1Z;
  12728. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  12729. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  12730. let b;
  12731. if(t < 0) {
  12732. out.x = v1X;
  12733. out.y = v1Y;
  12734. out.z = v1Z;
  12735. b = 1;
  12736. } else if(t > 1) {
  12737. out.x = v2X;
  12738. out.y = v2Y;
  12739. out.z = v2Z;
  12740. b = 2;
  12741. } else {
  12742. let pX;
  12743. let pY;
  12744. let pZ;
  12745. pX = v1X + v12X * t;
  12746. pY = v1Y + v12Y * t;
  12747. pZ = v1Z + v12Z * t;
  12748. out.x = pX;
  12749. out.y = pY;
  12750. out.z = pZ;
  12751. b = 3;
  12752. }
  12753. let d = out.x * out.x + out.y * out.y + out.z * out.z;
  12754. if(mind1 < 0 || d < mind1) {
  12755. mini1 = b & 1 | (b & 2) << 1;
  12756. mind1 = d;
  12757. minvX1 = out.x;
  12758. minvY1 = out.y;
  12759. minvZ1 = out.z;
  12760. }
  12761. }
  12762. let b;
  12763. if(mind1 > 0) {
  12764. out.x = minvX1;
  12765. out.y = minvY1;
  12766. out.z = minvZ1;
  12767. b = mini1;
  12768. } else {
  12769. let l = nX * nX + nY * nY + nZ * nZ;
  12770. if(l > 0) {
  12771. l = 1 / Math.sqrt(l);
  12772. }
  12773. nX *= l;
  12774. nY *= l;
  12775. nZ *= l;
  12776. let l2 = nX * nX + nY * nY + nZ * nZ;
  12777. l2 = (v1X * nX + v1Y * nY + v1Z * nZ) / l2;
  12778. minvX1 = nX * l2;
  12779. minvY1 = nY * l2;
  12780. minvZ1 = nZ * l2;
  12781. out.x = minvX1;
  12782. out.y = minvY1;
  12783. out.z = minvZ1;
  12784. b = 7;
  12785. }
  12786. let d = out.x * out.x + out.y * out.y + out.z * out.z;
  12787. if(mind < 0 || d < mind) {
  12788. mini = b & 1 | (b & 6) << 1;
  12789. mind = d;
  12790. minvX = out.x;
  12791. minvY = out.y;
  12792. minvZ = out.z;
  12793. }
  12794. }
  12795. if((v1X * n142X + v1Y * n142Y + v1Z * n142Z) * sign < 0) {
  12796. let v1X;
  12797. let v1Y;
  12798. let v1Z;
  12799. let v2X;
  12800. let v2Y;
  12801. let v2Z;
  12802. let v3X;
  12803. let v3Y;
  12804. let v3Z;
  12805. let v12X;
  12806. let v12Y;
  12807. let v12Z;
  12808. let v23X;
  12809. let v23Y;
  12810. let v23Z;
  12811. let v31X;
  12812. let v31Y;
  12813. let v31Z;
  12814. v1X = vec1.x;
  12815. v1Y = vec1.y;
  12816. v1Z = vec1.z;
  12817. v2X = vec2.x;
  12818. v2Y = vec2.y;
  12819. v2Z = vec2.z;
  12820. v3X = vec4.x;
  12821. v3Y = vec4.y;
  12822. v3Z = vec4.z;
  12823. v12X = v2X - v1X;
  12824. v12Y = v2Y - v1Y;
  12825. v12Z = v2Z - v1Z;
  12826. v23X = v3X - v2X;
  12827. v23Y = v3Y - v2Y;
  12828. v23Z = v3Z - v2Z;
  12829. v31X = v1X - v3X;
  12830. v31Y = v1Y - v3Y;
  12831. v31Z = v1Z - v3Z;
  12832. let nX;
  12833. let nY;
  12834. let nZ;
  12835. nX = v12Y * v23Z - v12Z * v23Y;
  12836. nY = v12Z * v23X - v12X * v23Z;
  12837. nZ = v12X * v23Y - v12Y * v23X;
  12838. let n12X;
  12839. let n12Y;
  12840. let n12Z;
  12841. let n23X;
  12842. let n23Y;
  12843. let n23Z;
  12844. let n31X;
  12845. let n31Y;
  12846. let n31Z;
  12847. n12X = v12Y * nZ - v12Z * nY;
  12848. n12Y = v12Z * nX - v12X * nZ;
  12849. n12Z = v12X * nY - v12Y * nX;
  12850. n23X = v23Y * nZ - v23Z * nY;
  12851. n23Y = v23Z * nX - v23X * nZ;
  12852. n23Z = v23X * nY - v23Y * nX;
  12853. n31X = v31Y * nZ - v31Z * nY;
  12854. n31Y = v31Z * nX - v31X * nZ;
  12855. n31Z = v31X * nY - v31Y * nX;
  12856. let mind1 = -1;
  12857. let minvX1;
  12858. let minvY1;
  12859. let minvZ1;
  12860. let mini1 = 0;
  12861. minvX1 = 0;
  12862. minvY1 = 0;
  12863. minvZ1 = 0;
  12864. if(v1X * n12X + v1Y * n12Y + v1Z * n12Z < 0) {
  12865. let v1X;
  12866. let v1Y;
  12867. let v1Z;
  12868. let v2X;
  12869. let v2Y;
  12870. let v2Z;
  12871. v1X = vec1.x;
  12872. v1Y = vec1.y;
  12873. v1Z = vec1.z;
  12874. v2X = vec2.x;
  12875. v2Y = vec2.y;
  12876. v2Z = vec2.z;
  12877. let v12X;
  12878. let v12Y;
  12879. let v12Z;
  12880. v12X = v2X - v1X;
  12881. v12Y = v2Y - v1Y;
  12882. v12Z = v2Z - v1Z;
  12883. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  12884. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  12885. let b;
  12886. if(t < 0) {
  12887. out.x = v1X;
  12888. out.y = v1Y;
  12889. out.z = v1Z;
  12890. b = 1;
  12891. } else if(t > 1) {
  12892. out.x = v2X;
  12893. out.y = v2Y;
  12894. out.z = v2Z;
  12895. b = 2;
  12896. } else {
  12897. let pX;
  12898. let pY;
  12899. let pZ;
  12900. pX = v1X + v12X * t;
  12901. pY = v1Y + v12Y * t;
  12902. pZ = v1Z + v12Z * t;
  12903. out.x = pX;
  12904. out.y = pY;
  12905. out.z = pZ;
  12906. b = 3;
  12907. }
  12908. mini1 = b;
  12909. mind1 = out.x * out.x + out.y * out.y + out.z * out.z;
  12910. minvX1 = out.x;
  12911. minvY1 = out.y;
  12912. minvZ1 = out.z;
  12913. }
  12914. if(v2X * n23X + v2Y * n23Y + v2Z * n23Z < 0) {
  12915. let v1X;
  12916. let v1Y;
  12917. let v1Z;
  12918. let v2X;
  12919. let v2Y;
  12920. let v2Z;
  12921. v1X = vec2.x;
  12922. v1Y = vec2.y;
  12923. v1Z = vec2.z;
  12924. v2X = vec4.x;
  12925. v2Y = vec4.y;
  12926. v2Z = vec4.z;
  12927. let v12X;
  12928. let v12Y;
  12929. let v12Z;
  12930. v12X = v2X - v1X;
  12931. v12Y = v2Y - v1Y;
  12932. v12Z = v2Z - v1Z;
  12933. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  12934. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  12935. let b;
  12936. if(t < 0) {
  12937. out.x = v1X;
  12938. out.y = v1Y;
  12939. out.z = v1Z;
  12940. b = 1;
  12941. } else if(t > 1) {
  12942. out.x = v2X;
  12943. out.y = v2Y;
  12944. out.z = v2Z;
  12945. b = 2;
  12946. } else {
  12947. let pX;
  12948. let pY;
  12949. let pZ;
  12950. pX = v1X + v12X * t;
  12951. pY = v1Y + v12Y * t;
  12952. pZ = v1Z + v12Z * t;
  12953. out.x = pX;
  12954. out.y = pY;
  12955. out.z = pZ;
  12956. b = 3;
  12957. }
  12958. let d = out.x * out.x + out.y * out.y + out.z * out.z;
  12959. if(mind1 < 0 || d < mind1) {
  12960. mini1 = b << 1;
  12961. mind1 = d;
  12962. minvX1 = out.x;
  12963. minvY1 = out.y;
  12964. minvZ1 = out.z;
  12965. }
  12966. }
  12967. if(v3X * n31X + v3Y * n31Y + v3Z * n31Z < 0) {
  12968. let v1X;
  12969. let v1Y;
  12970. let v1Z;
  12971. let v2X;
  12972. let v2Y;
  12973. let v2Z;
  12974. v1X = vec1.x;
  12975. v1Y = vec1.y;
  12976. v1Z = vec1.z;
  12977. v2X = vec4.x;
  12978. v2Y = vec4.y;
  12979. v2Z = vec4.z;
  12980. let v12X;
  12981. let v12Y;
  12982. let v12Z;
  12983. v12X = v2X - v1X;
  12984. v12Y = v2Y - v1Y;
  12985. v12Z = v2Z - v1Z;
  12986. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  12987. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  12988. let b;
  12989. if(t < 0) {
  12990. out.x = v1X;
  12991. out.y = v1Y;
  12992. out.z = v1Z;
  12993. b = 1;
  12994. } else if(t > 1) {
  12995. out.x = v2X;
  12996. out.y = v2Y;
  12997. out.z = v2Z;
  12998. b = 2;
  12999. } else {
  13000. let pX;
  13001. let pY;
  13002. let pZ;
  13003. pX = v1X + v12X * t;
  13004. pY = v1Y + v12Y * t;
  13005. pZ = v1Z + v12Z * t;
  13006. out.x = pX;
  13007. out.y = pY;
  13008. out.z = pZ;
  13009. b = 3;
  13010. }
  13011. let d = out.x * out.x + out.y * out.y + out.z * out.z;
  13012. if(mind1 < 0 || d < mind1) {
  13013. mini1 = b & 1 | (b & 2) << 1;
  13014. mind1 = d;
  13015. minvX1 = out.x;
  13016. minvY1 = out.y;
  13017. minvZ1 = out.z;
  13018. }
  13019. }
  13020. let b;
  13021. if(mind1 > 0) {
  13022. out.x = minvX1;
  13023. out.y = minvY1;
  13024. out.z = minvZ1;
  13025. b = mini1;
  13026. } else {
  13027. let l = nX * nX + nY * nY + nZ * nZ;
  13028. if(l > 0) {
  13029. l = 1 / Math.sqrt(l);
  13030. }
  13031. nX *= l;
  13032. nY *= l;
  13033. nZ *= l;
  13034. let l2 = nX * nX + nY * nY + nZ * nZ;
  13035. l2 = (v1X * nX + v1Y * nY + v1Z * nZ) / l2;
  13036. minvX1 = nX * l2;
  13037. minvY1 = nY * l2;
  13038. minvZ1 = nZ * l2;
  13039. out.x = minvX1;
  13040. out.y = minvY1;
  13041. out.z = minvZ1;
  13042. b = 7;
  13043. }
  13044. let d = out.x * out.x + out.y * out.y + out.z * out.z;
  13045. if(mind < 0 || d < mind) {
  13046. mini = b & 3 | (b & 4) << 1;
  13047. mind = d;
  13048. minvX = out.x;
  13049. minvY = out.y;
  13050. minvZ = out.z;
  13051. }
  13052. }
  13053. if((v2X * n243X + v2Y * n243Y + v2Z * n243Z) * sign < 0) {
  13054. let v1X;
  13055. let v1Y;
  13056. let v1Z;
  13057. let v2X;
  13058. let v2Y;
  13059. let v2Z;
  13060. let v3X;
  13061. let v3Y;
  13062. let v3Z;
  13063. let v12X;
  13064. let v12Y;
  13065. let v12Z;
  13066. let v23X;
  13067. let v23Y;
  13068. let v23Z;
  13069. let v31X;
  13070. let v31Y;
  13071. let v31Z;
  13072. v1X = vec2.x;
  13073. v1Y = vec2.y;
  13074. v1Z = vec2.z;
  13075. v2X = vec3.x;
  13076. v2Y = vec3.y;
  13077. v2Z = vec3.z;
  13078. v3X = vec4.x;
  13079. v3Y = vec4.y;
  13080. v3Z = vec4.z;
  13081. v12X = v2X - v1X;
  13082. v12Y = v2Y - v1Y;
  13083. v12Z = v2Z - v1Z;
  13084. v23X = v3X - v2X;
  13085. v23Y = v3Y - v2Y;
  13086. v23Z = v3Z - v2Z;
  13087. v31X = v1X - v3X;
  13088. v31Y = v1Y - v3Y;
  13089. v31Z = v1Z - v3Z;
  13090. let nX;
  13091. let nY;
  13092. let nZ;
  13093. nX = v12Y * v23Z - v12Z * v23Y;
  13094. nY = v12Z * v23X - v12X * v23Z;
  13095. nZ = v12X * v23Y - v12Y * v23X;
  13096. let n12X;
  13097. let n12Y;
  13098. let n12Z;
  13099. let n23X;
  13100. let n23Y;
  13101. let n23Z;
  13102. let n31X;
  13103. let n31Y;
  13104. let n31Z;
  13105. n12X = v12Y * nZ - v12Z * nY;
  13106. n12Y = v12Z * nX - v12X * nZ;
  13107. n12Z = v12X * nY - v12Y * nX;
  13108. n23X = v23Y * nZ - v23Z * nY;
  13109. n23Y = v23Z * nX - v23X * nZ;
  13110. n23Z = v23X * nY - v23Y * nX;
  13111. n31X = v31Y * nZ - v31Z * nY;
  13112. n31Y = v31Z * nX - v31X * nZ;
  13113. n31Z = v31X * nY - v31Y * nX;
  13114. let mind1 = -1;
  13115. let minvX1;
  13116. let minvY1;
  13117. let minvZ1;
  13118. let mini1 = 0;
  13119. minvX1 = 0;
  13120. minvY1 = 0;
  13121. minvZ1 = 0;
  13122. if(v1X * n12X + v1Y * n12Y + v1Z * n12Z < 0) {
  13123. let v1X;
  13124. let v1Y;
  13125. let v1Z;
  13126. let v2X;
  13127. let v2Y;
  13128. let v2Z;
  13129. v1X = vec2.x;
  13130. v1Y = vec2.y;
  13131. v1Z = vec2.z;
  13132. v2X = vec3.x;
  13133. v2Y = vec3.y;
  13134. v2Z = vec3.z;
  13135. let v12X;
  13136. let v12Y;
  13137. let v12Z;
  13138. v12X = v2X - v1X;
  13139. v12Y = v2Y - v1Y;
  13140. v12Z = v2Z - v1Z;
  13141. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  13142. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  13143. let b;
  13144. if(t < 0) {
  13145. out.x = v1X;
  13146. out.y = v1Y;
  13147. out.z = v1Z;
  13148. b = 1;
  13149. } else if(t > 1) {
  13150. out.x = v2X;
  13151. out.y = v2Y;
  13152. out.z = v2Z;
  13153. b = 2;
  13154. } else {
  13155. let pX;
  13156. let pY;
  13157. let pZ;
  13158. pX = v1X + v12X * t;
  13159. pY = v1Y + v12Y * t;
  13160. pZ = v1Z + v12Z * t;
  13161. out.x = pX;
  13162. out.y = pY;
  13163. out.z = pZ;
  13164. b = 3;
  13165. }
  13166. mini1 = b;
  13167. mind1 = out.x * out.x + out.y * out.y + out.z * out.z;
  13168. minvX1 = out.x;
  13169. minvY1 = out.y;
  13170. minvZ1 = out.z;
  13171. }
  13172. if(v2X * n23X + v2Y * n23Y + v2Z * n23Z < 0) {
  13173. let v1X;
  13174. let v1Y;
  13175. let v1Z;
  13176. let v2X;
  13177. let v2Y;
  13178. let v2Z;
  13179. v1X = vec3.x;
  13180. v1Y = vec3.y;
  13181. v1Z = vec3.z;
  13182. v2X = vec4.x;
  13183. v2Y = vec4.y;
  13184. v2Z = vec4.z;
  13185. let v12X;
  13186. let v12Y;
  13187. let v12Z;
  13188. v12X = v2X - v1X;
  13189. v12Y = v2Y - v1Y;
  13190. v12Z = v2Z - v1Z;
  13191. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  13192. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  13193. let b;
  13194. if(t < 0) {
  13195. out.x = v1X;
  13196. out.y = v1Y;
  13197. out.z = v1Z;
  13198. b = 1;
  13199. } else if(t > 1) {
  13200. out.x = v2X;
  13201. out.y = v2Y;
  13202. out.z = v2Z;
  13203. b = 2;
  13204. } else {
  13205. let pX;
  13206. let pY;
  13207. let pZ;
  13208. pX = v1X + v12X * t;
  13209. pY = v1Y + v12Y * t;
  13210. pZ = v1Z + v12Z * t;
  13211. out.x = pX;
  13212. out.y = pY;
  13213. out.z = pZ;
  13214. b = 3;
  13215. }
  13216. let d = out.x * out.x + out.y * out.y + out.z * out.z;
  13217. if(mind1 < 0 || d < mind1) {
  13218. mini1 = b << 1;
  13219. mind1 = d;
  13220. minvX1 = out.x;
  13221. minvY1 = out.y;
  13222. minvZ1 = out.z;
  13223. }
  13224. }
  13225. if(v3X * n31X + v3Y * n31Y + v3Z * n31Z < 0) {
  13226. let v1X;
  13227. let v1Y;
  13228. let v1Z;
  13229. let v2X;
  13230. let v2Y;
  13231. let v2Z;
  13232. v1X = vec2.x;
  13233. v1Y = vec2.y;
  13234. v1Z = vec2.z;
  13235. v2X = vec4.x;
  13236. v2Y = vec4.y;
  13237. v2Z = vec4.z;
  13238. let v12X;
  13239. let v12Y;
  13240. let v12Z;
  13241. v12X = v2X - v1X;
  13242. v12Y = v2Y - v1Y;
  13243. v12Z = v2Z - v1Z;
  13244. let t = v12X * v1X + v12Y * v1Y + v12Z * v1Z;
  13245. t = -t / (v12X * v12X + v12Y * v12Y + v12Z * v12Z);
  13246. let b;
  13247. if(t < 0) {
  13248. out.x = v1X;
  13249. out.y = v1Y;
  13250. out.z = v1Z;
  13251. b = 1;
  13252. } else if(t > 1) {
  13253. out.x = v2X;
  13254. out.y = v2Y;
  13255. out.z = v2Z;
  13256. b = 2;
  13257. } else {
  13258. let pX;
  13259. let pY;
  13260. let pZ;
  13261. pX = v1X + v12X * t;
  13262. pY = v1Y + v12Y * t;
  13263. pZ = v1Z + v12Z * t;
  13264. out.x = pX;
  13265. out.y = pY;
  13266. out.z = pZ;
  13267. b = 3;
  13268. }
  13269. let d = out.x * out.x + out.y * out.y + out.z * out.z;
  13270. if(mind1 < 0 || d < mind1) {
  13271. mini1 = b & 1 | (b & 2) << 1;
  13272. mind1 = d;
  13273. minvX1 = out.x;
  13274. minvY1 = out.y;
  13275. minvZ1 = out.z;
  13276. }
  13277. }
  13278. let b;
  13279. if(mind1 > 0) {
  13280. out.x = minvX1;
  13281. out.y = minvY1;
  13282. out.z = minvZ1;
  13283. b = mini1;
  13284. } else {
  13285. let l = nX * nX + nY * nY + nZ * nZ;
  13286. if(l > 0) {
  13287. l = 1 / Math.sqrt(l);
  13288. }
  13289. nX *= l;
  13290. nY *= l;
  13291. nZ *= l;
  13292. let l2 = nX * nX + nY * nY + nZ * nZ;
  13293. l2 = (v1X * nX + v1Y * nY + v1Z * nZ) / l2;
  13294. minvX1 = nX * l2;
  13295. minvY1 = nY * l2;
  13296. minvZ1 = nZ * l2;
  13297. out.x = minvX1;
  13298. out.y = minvY1;
  13299. out.z = minvZ1;
  13300. b = 7;
  13301. }
  13302. let d = out.x * out.x + out.y * out.y + out.z * out.z;
  13303. if(mind < 0 || d < mind) {
  13304. mini = b << 1;
  13305. mind = d;
  13306. minvX = out.x;
  13307. minvY = out.y;
  13308. minvZ = out.z;
  13309. }
  13310. }
  13311. if(mind > 0) {
  13312. out.x = minvX;
  13313. out.y = minvY;
  13314. out.z = minvZ;
  13315. return mini;
  13316. }
  13317. out.zero();
  13318. return 15;
  13319. }
  13320. }
  13321. oimo.common.Mat3 = class oimo_common_Mat3 {
  13322. constructor(e00,e01,e02,e10,e11,e12,e20,e21,e22) {
  13323. if(e22 == null) {
  13324. e22 = 1;
  13325. }
  13326. if(e21 == null) {
  13327. e21 = 0;
  13328. }
  13329. if(e20 == null) {
  13330. e20 = 0;
  13331. }
  13332. if(e12 == null) {
  13333. e12 = 0;
  13334. }
  13335. if(e11 == null) {
  13336. e11 = 1;
  13337. }
  13338. if(e10 == null) {
  13339. e10 = 0;
  13340. }
  13341. if(e02 == null) {
  13342. e02 = 0;
  13343. }
  13344. if(e01 == null) {
  13345. e01 = 0;
  13346. }
  13347. if(e00 == null) {
  13348. e00 = 1;
  13349. }
  13350. this.e00 = e00;
  13351. this.e01 = e01;
  13352. this.e02 = e02;
  13353. this.e10 = e10;
  13354. this.e11 = e11;
  13355. this.e12 = e12;
  13356. this.e20 = e20;
  13357. this.e21 = e21;
  13358. this.e22 = e22;
  13359. oimo.common.Mat3.numCreations++;
  13360. }
  13361. init(e00,e01,e02,e10,e11,e12,e20,e21,e22) {
  13362. this.e00 = e00;
  13363. this.e01 = e01;
  13364. this.e02 = e02;
  13365. this.e10 = e10;
  13366. this.e11 = e11;
  13367. this.e12 = e12;
  13368. this.e20 = e20;
  13369. this.e21 = e21;
  13370. this.e22 = e22;
  13371. return this;
  13372. }
  13373. identity() {
  13374. this.e00 = 1;
  13375. this.e01 = 0;
  13376. this.e02 = 0;
  13377. this.e10 = 0;
  13378. this.e11 = 1;
  13379. this.e12 = 0;
  13380. this.e20 = 0;
  13381. this.e21 = 0;
  13382. this.e22 = 1;
  13383. return this;
  13384. }
  13385. add(m) {
  13386. return new oimo.common.Mat3(this.e00 + m.e00,this.e01 + m.e01,this.e02 + m.e02,this.e10 + m.e10,this.e11 + m.e11,this.e12 + m.e12,this.e20 + m.e20,this.e21 + m.e21,this.e22 + m.e22);
  13387. }
  13388. sub(m) {
  13389. return new oimo.common.Mat3(this.e00 - m.e00,this.e01 - m.e01,this.e02 - m.e02,this.e10 - m.e10,this.e11 - m.e11,this.e12 - m.e12,this.e20 - m.e20,this.e21 - m.e21,this.e22 - m.e22);
  13390. }
  13391. scale(s) {
  13392. return new oimo.common.Mat3(this.e00 * s,this.e01 * s,this.e02 * s,this.e10 * s,this.e11 * s,this.e12 * s,this.e20 * s,this.e21 * s,this.e22 * s);
  13393. }
  13394. mul(m) {
  13395. return new oimo.common.Mat3(this.e00 * m.e00 + this.e01 * m.e10 + this.e02 * m.e20,this.e00 * m.e01 + this.e01 * m.e11 + this.e02 * m.e21,this.e00 * m.e02 + this.e01 * m.e12 + this.e02 * m.e22,this.e10 * m.e00 + this.e11 * m.e10 + this.e12 * m.e20,this.e10 * m.e01 + this.e11 * m.e11 + this.e12 * m.e21,this.e10 * m.e02 + this.e11 * m.e12 + this.e12 * m.e22,this.e20 * m.e00 + this.e21 * m.e10 + this.e22 * m.e20,this.e20 * m.e01 + this.e21 * m.e11 + this.e22 * m.e21,this.e20 * m.e02 + this.e21 * m.e12 + this.e22 * m.e22);
  13396. }
  13397. addEq(m) {
  13398. this.e00 += m.e00;
  13399. this.e01 += m.e01;
  13400. this.e02 += m.e02;
  13401. this.e10 += m.e10;
  13402. this.e11 += m.e11;
  13403. this.e12 += m.e12;
  13404. this.e20 += m.e20;
  13405. this.e21 += m.e21;
  13406. this.e22 += m.e22;
  13407. return this;
  13408. }
  13409. subEq(m) {
  13410. this.e00 -= m.e00;
  13411. this.e01 -= m.e01;
  13412. this.e02 -= m.e02;
  13413. this.e10 -= m.e10;
  13414. this.e11 -= m.e11;
  13415. this.e12 -= m.e12;
  13416. this.e20 -= m.e20;
  13417. this.e21 -= m.e21;
  13418. this.e22 -= m.e22;
  13419. return this;
  13420. }
  13421. scaleEq(s) {
  13422. this.e00 *= s;
  13423. this.e01 *= s;
  13424. this.e02 *= s;
  13425. this.e10 *= s;
  13426. this.e11 *= s;
  13427. this.e12 *= s;
  13428. this.e20 *= s;
  13429. this.e21 *= s;
  13430. this.e22 *= s;
  13431. return this;
  13432. }
  13433. mulEq(m) {
  13434. let e01 = this.e00 * m.e01 + this.e01 * m.e11 + this.e02 * m.e21;
  13435. let e02 = this.e00 * m.e02 + this.e01 * m.e12 + this.e02 * m.e22;
  13436. let e10 = this.e10 * m.e00 + this.e11 * m.e10 + this.e12 * m.e20;
  13437. let e11 = this.e10 * m.e01 + this.e11 * m.e11 + this.e12 * m.e21;
  13438. let e12 = this.e10 * m.e02 + this.e11 * m.e12 + this.e12 * m.e22;
  13439. let e20 = this.e20 * m.e00 + this.e21 * m.e10 + this.e22 * m.e20;
  13440. let e21 = this.e20 * m.e01 + this.e21 * m.e11 + this.e22 * m.e21;
  13441. let e22 = this.e20 * m.e02 + this.e21 * m.e12 + this.e22 * m.e22;
  13442. this.e00 = this.e00 * m.e00 + this.e01 * m.e10 + this.e02 * m.e20;
  13443. this.e01 = e01;
  13444. this.e02 = e02;
  13445. this.e10 = e10;
  13446. this.e11 = e11;
  13447. this.e12 = e12;
  13448. this.e20 = e20;
  13449. this.e21 = e21;
  13450. this.e22 = e22;
  13451. return this;
  13452. }
  13453. prependScale(sx,sy,sz) {
  13454. return new oimo.common.Mat3(this.e00 * sx,this.e01 * sx,this.e02 * sx,this.e10 * sy,this.e11 * sy,this.e12 * sy,this.e20 * sz,this.e21 * sz,this.e22 * sz);
  13455. }
  13456. appendScale(sx,sy,sz) {
  13457. return new oimo.common.Mat3(this.e00 * sx,this.e01 * sy,this.e02 * sz,this.e10 * sx,this.e11 * sy,this.e12 * sz,this.e20 * sx,this.e21 * sy,this.e22 * sz);
  13458. }
  13459. prependRotation(rad,axisX,axisY,axisZ) {
  13460. let s = Math.sin(rad);
  13461. let c = Math.cos(rad);
  13462. let c1 = 1 - c;
  13463. let r00 = axisX * axisX * c1 + c;
  13464. let r01 = axisX * axisY * c1 - axisZ * s;
  13465. let r02 = axisX * axisZ * c1 + axisY * s;
  13466. let r10 = axisY * axisX * c1 + axisZ * s;
  13467. let r11 = axisY * axisY * c1 + c;
  13468. let r12 = axisY * axisZ * c1 - axisX * s;
  13469. let r20 = axisZ * axisX * c1 - axisY * s;
  13470. let r21 = axisZ * axisY * c1 + axisX * s;
  13471. let r22 = axisZ * axisZ * c1 + c;
  13472. return new oimo.common.Mat3(r00 * this.e00 + r01 * this.e10 + r02 * this.e20,r00 * this.e01 + r01 * this.e11 + r02 * this.e21,r00 * this.e02 + r01 * this.e12 + r02 * this.e22,r10 * this.e00 + r11 * this.e10 + r12 * this.e20,r10 * this.e01 + r11 * this.e11 + r12 * this.e21,r10 * this.e02 + r11 * this.e12 + r12 * this.e22,r20 * this.e00 + r21 * this.e10 + r22 * this.e20,r20 * this.e01 + r21 * this.e11 + r22 * this.e21,r20 * this.e02 + r21 * this.e12 + r22 * this.e22);
  13473. }
  13474. appendRotation(rad,axisX,axisY,axisZ) {
  13475. let s = Math.sin(rad);
  13476. let c = Math.cos(rad);
  13477. let c1 = 1 - c;
  13478. let r00 = axisX * axisX * c1 + c;
  13479. let r01 = axisX * axisY * c1 - axisZ * s;
  13480. let r02 = axisX * axisZ * c1 + axisY * s;
  13481. let r10 = axisY * axisX * c1 + axisZ * s;
  13482. let r11 = axisY * axisY * c1 + c;
  13483. let r12 = axisY * axisZ * c1 - axisX * s;
  13484. let r20 = axisZ * axisX * c1 - axisY * s;
  13485. let r21 = axisZ * axisY * c1 + axisX * s;
  13486. let r22 = axisZ * axisZ * c1 + c;
  13487. return new oimo.common.Mat3(this.e00 * r00 + this.e01 * r10 + this.e02 * r20,this.e00 * r01 + this.e01 * r11 + this.e02 * r21,this.e00 * r02 + this.e01 * r12 + this.e02 * r22,this.e10 * r00 + this.e11 * r10 + this.e12 * r20,this.e10 * r01 + this.e11 * r11 + this.e12 * r21,this.e10 * r02 + this.e11 * r12 + this.e12 * r22,this.e20 * r00 + this.e21 * r10 + this.e22 * r20,this.e20 * r01 + this.e21 * r11 + this.e22 * r21,this.e20 * r02 + this.e21 * r12 + this.e22 * r22);
  13488. }
  13489. prependScaleEq(sx,sy,sz) {
  13490. this.e00 *= sx;
  13491. this.e01 *= sx;
  13492. this.e02 *= sx;
  13493. this.e10 *= sy;
  13494. this.e11 *= sy;
  13495. this.e12 *= sy;
  13496. this.e20 *= sz;
  13497. this.e21 *= sz;
  13498. this.e22 *= sz;
  13499. return this;
  13500. }
  13501. appendScaleEq(sx,sy,sz) {
  13502. this.e00 *= sx;
  13503. this.e01 *= sy;
  13504. this.e02 *= sz;
  13505. this.e10 *= sx;
  13506. this.e11 *= sy;
  13507. this.e12 *= sz;
  13508. this.e20 *= sx;
  13509. this.e21 *= sy;
  13510. this.e22 *= sz;
  13511. return this;
  13512. }
  13513. prependRotationEq(rad,axisX,axisY,axisZ) {
  13514. let s = Math.sin(rad);
  13515. let c = Math.cos(rad);
  13516. let c1 = 1 - c;
  13517. let r00 = axisX * axisX * c1 + c;
  13518. let r01 = axisX * axisY * c1 - axisZ * s;
  13519. let r02 = axisX * axisZ * c1 + axisY * s;
  13520. let r10 = axisY * axisX * c1 + axisZ * s;
  13521. let r11 = axisY * axisY * c1 + c;
  13522. let r12 = axisY * axisZ * c1 - axisX * s;
  13523. let r20 = axisZ * axisX * c1 - axisY * s;
  13524. let r21 = axisZ * axisY * c1 + axisX * s;
  13525. let r22 = axisZ * axisZ * c1 + c;
  13526. let e10 = r10 * this.e00 + r11 * this.e10 + r12 * this.e20;
  13527. let e11 = r10 * this.e01 + r11 * this.e11 + r12 * this.e21;
  13528. let e12 = r10 * this.e02 + r11 * this.e12 + r12 * this.e22;
  13529. let e20 = r20 * this.e00 + r21 * this.e10 + r22 * this.e20;
  13530. let e21 = r20 * this.e01 + r21 * this.e11 + r22 * this.e21;
  13531. let e22 = r20 * this.e02 + r21 * this.e12 + r22 * this.e22;
  13532. this.e00 = r00 * this.e00 + r01 * this.e10 + r02 * this.e20;
  13533. this.e01 = r00 * this.e01 + r01 * this.e11 + r02 * this.e21;
  13534. this.e02 = r00 * this.e02 + r01 * this.e12 + r02 * this.e22;
  13535. this.e10 = e10;
  13536. this.e11 = e11;
  13537. this.e12 = e12;
  13538. this.e20 = e20;
  13539. this.e21 = e21;
  13540. this.e22 = e22;
  13541. return this;
  13542. }
  13543. appendRotationEq(rad,axisX,axisY,axisZ) {
  13544. let s = Math.sin(rad);
  13545. let c = Math.cos(rad);
  13546. let c1 = 1 - c;
  13547. let r00 = axisX * axisX * c1 + c;
  13548. let r01 = axisX * axisY * c1 - axisZ * s;
  13549. let r02 = axisX * axisZ * c1 + axisY * s;
  13550. let r10 = axisY * axisX * c1 + axisZ * s;
  13551. let r11 = axisY * axisY * c1 + c;
  13552. let r12 = axisY * axisZ * c1 - axisX * s;
  13553. let r20 = axisZ * axisX * c1 - axisY * s;
  13554. let r21 = axisZ * axisY * c1 + axisX * s;
  13555. let r22 = axisZ * axisZ * c1 + c;
  13556. let e01 = this.e00 * r01 + this.e01 * r11 + this.e02 * r21;
  13557. let e02 = this.e00 * r02 + this.e01 * r12 + this.e02 * r22;
  13558. let e11 = this.e10 * r01 + this.e11 * r11 + this.e12 * r21;
  13559. let e12 = this.e10 * r02 + this.e11 * r12 + this.e12 * r22;
  13560. let e21 = this.e20 * r01 + this.e21 * r11 + this.e22 * r21;
  13561. let e22 = this.e20 * r02 + this.e21 * r12 + this.e22 * r22;
  13562. this.e00 = this.e00 * r00 + this.e01 * r10 + this.e02 * r20;
  13563. this.e01 = e01;
  13564. this.e02 = e02;
  13565. this.e10 = this.e10 * r00 + this.e11 * r10 + this.e12 * r20;
  13566. this.e11 = e11;
  13567. this.e12 = e12;
  13568. this.e20 = this.e20 * r00 + this.e21 * r10 + this.e22 * r20;
  13569. this.e21 = e21;
  13570. this.e22 = e22;
  13571. return this;
  13572. }
  13573. transpose() {
  13574. return new oimo.common.Mat3(this.e00,this.e10,this.e20,this.e01,this.e11,this.e21,this.e02,this.e12,this.e22);
  13575. }
  13576. transposeEq() {
  13577. let e10 = this.e01;
  13578. let e20 = this.e02;
  13579. let e21 = this.e12;
  13580. this.e01 = this.e10;
  13581. this.e02 = this.e20;
  13582. this.e10 = e10;
  13583. this.e12 = this.e21;
  13584. this.e20 = e20;
  13585. this.e21 = e21;
  13586. return this;
  13587. }
  13588. determinant() {
  13589. return this.e00 * (this.e11 * this.e22 - this.e12 * this.e21) - this.e01 * (this.e10 * this.e22 - this.e12 * this.e20) + this.e02 * (this.e10 * this.e21 - this.e11 * this.e20);
  13590. }
  13591. trace() {
  13592. return this.e00 + this.e11 + this.e22;
  13593. }
  13594. inverse() {
  13595. let d00 = this.e11 * this.e22 - this.e12 * this.e21;
  13596. let d01 = this.e10 * this.e22 - this.e12 * this.e20;
  13597. let d02 = this.e10 * this.e21 - this.e11 * this.e20;
  13598. let invDet = this.e00 * d00 - this.e01 * d01 + this.e02 * d02;
  13599. if(invDet != 0) {
  13600. invDet = 1 / invDet;
  13601. }
  13602. return new oimo.common.Mat3(d00 * invDet,-(this.e01 * this.e22 - this.e02 * this.e21) * invDet,(this.e01 * this.e12 - this.e02 * this.e11) * invDet,-d01 * invDet,(this.e00 * this.e22 - this.e02 * this.e20) * invDet,-(this.e00 * this.e12 - this.e02 * this.e10) * invDet,d02 * invDet,-(this.e00 * this.e21 - this.e01 * this.e20) * invDet,(this.e00 * this.e11 - this.e01 * this.e10) * invDet);
  13603. }
  13604. inverseEq() {
  13605. let d00 = this.e11 * this.e22 - this.e12 * this.e21;
  13606. let d01 = this.e10 * this.e22 - this.e12 * this.e20;
  13607. let d02 = this.e10 * this.e21 - this.e11 * this.e20;
  13608. let invDet = this.e00 * d00 - this.e01 * d01 + this.e02 * d02;
  13609. if(invDet != 0) {
  13610. invDet = 1 / invDet;
  13611. }
  13612. let t02 = (this.e01 * this.e12 - this.e02 * this.e11) * invDet;
  13613. let t11 = (this.e00 * this.e22 - this.e02 * this.e20) * invDet;
  13614. let t12 = -(this.e00 * this.e12 - this.e02 * this.e10) * invDet;
  13615. let t21 = -(this.e00 * this.e21 - this.e01 * this.e20) * invDet;
  13616. let t22 = (this.e00 * this.e11 - this.e01 * this.e10) * invDet;
  13617. this.e00 = d00 * invDet;
  13618. this.e01 = -(this.e01 * this.e22 - this.e02 * this.e21) * invDet;
  13619. this.e02 = t02;
  13620. this.e10 = -d01 * invDet;
  13621. this.e11 = t11;
  13622. this.e12 = t12;
  13623. this.e20 = d02 * invDet;
  13624. this.e21 = t21;
  13625. this.e22 = t22;
  13626. return this;
  13627. }
  13628. toArray(columnMajor) {
  13629. if(columnMajor == null) {
  13630. columnMajor = false;
  13631. }
  13632. if(columnMajor) {
  13633. return [this.e00,this.e10,this.e20,this.e01,this.e11,this.e21,this.e02,this.e12,this.e22];
  13634. } else {
  13635. return [this.e00,this.e01,this.e02,this.e10,this.e11,this.e12,this.e20,this.e21,this.e22];
  13636. }
  13637. }
  13638. copyFrom(m) {
  13639. this.e00 = m.e00;
  13640. this.e01 = m.e01;
  13641. this.e02 = m.e02;
  13642. this.e10 = m.e10;
  13643. this.e11 = m.e11;
  13644. this.e12 = m.e12;
  13645. this.e20 = m.e20;
  13646. this.e21 = m.e21;
  13647. this.e22 = m.e22;
  13648. return this;
  13649. }
  13650. clone() {
  13651. return new oimo.common.Mat3(this.e00,this.e01,this.e02,this.e10,this.e11,this.e12,this.e20,this.e21,this.e22);
  13652. }
  13653. fromQuat(q) {
  13654. let x = q.x;
  13655. let y = q.y;
  13656. let z = q.z;
  13657. let w = q.w;
  13658. let x2 = 2 * x;
  13659. let y2 = 2 * y;
  13660. let z2 = 2 * z;
  13661. let xx = x * x2;
  13662. let yy = y * y2;
  13663. let zz = z * z2;
  13664. let xy = x * y2;
  13665. let yz = y * z2;
  13666. let xz = x * z2;
  13667. let wx = w * x2;
  13668. let wy = w * y2;
  13669. let wz = w * z2;
  13670. this.e00 = 1 - yy - zz;
  13671. this.e01 = xy - wz;
  13672. this.e02 = xz + wy;
  13673. this.e10 = xy + wz;
  13674. this.e11 = 1 - xx - zz;
  13675. this.e12 = yz - wx;
  13676. this.e20 = xz - wy;
  13677. this.e21 = yz + wx;
  13678. this.e22 = 1 - xx - yy;
  13679. return this;
  13680. }
  13681. toQuat() {
  13682. let _this = new oimo.common.Quat();
  13683. let e00 = this.e00;
  13684. let e11 = this.e11;
  13685. let e22 = this.e22;
  13686. let t = e00 + e11 + e22;
  13687. let s;
  13688. if(t > 0) {
  13689. s = Math.sqrt(t + 1);
  13690. _this.w = 0.5 * s;
  13691. s = 0.5 / s;
  13692. _this.x = (this.e21 - this.e12) * s;
  13693. _this.y = (this.e02 - this.e20) * s;
  13694. _this.z = (this.e10 - this.e01) * s;
  13695. } else if(e00 > e11) {
  13696. if(e00 > e22) {
  13697. s = Math.sqrt(e00 - e11 - e22 + 1);
  13698. _this.x = 0.5 * s;
  13699. s = 0.5 / s;
  13700. _this.y = (this.e01 + this.e10) * s;
  13701. _this.z = (this.e02 + this.e20) * s;
  13702. _this.w = (this.e21 - this.e12) * s;
  13703. } else {
  13704. s = Math.sqrt(e22 - e00 - e11 + 1);
  13705. _this.z = 0.5 * s;
  13706. s = 0.5 / s;
  13707. _this.x = (this.e02 + this.e20) * s;
  13708. _this.y = (this.e12 + this.e21) * s;
  13709. _this.w = (this.e10 - this.e01) * s;
  13710. }
  13711. } else if(e11 > e22) {
  13712. s = Math.sqrt(e11 - e22 - e00 + 1);
  13713. _this.y = 0.5 * s;
  13714. s = 0.5 / s;
  13715. _this.x = (this.e01 + this.e10) * s;
  13716. _this.z = (this.e12 + this.e21) * s;
  13717. _this.w = (this.e02 - this.e20) * s;
  13718. } else {
  13719. s = Math.sqrt(e22 - e00 - e11 + 1);
  13720. _this.z = 0.5 * s;
  13721. s = 0.5 / s;
  13722. _this.x = (this.e02 + this.e20) * s;
  13723. _this.y = (this.e12 + this.e21) * s;
  13724. _this.w = (this.e10 - this.e01) * s;
  13725. }
  13726. return _this;
  13727. }
  13728. fromEulerXyz(eulerAngles) {
  13729. let sx = Math.sin(eulerAngles.x);
  13730. let sy = Math.sin(eulerAngles.y);
  13731. let sz = Math.sin(eulerAngles.z);
  13732. let cx = Math.cos(eulerAngles.x);
  13733. let cy = Math.cos(eulerAngles.y);
  13734. let cz = Math.cos(eulerAngles.z);
  13735. this.e00 = cy * cz;
  13736. this.e01 = -cy * sz;
  13737. this.e02 = sy;
  13738. this.e10 = cx * sz + cz * sx * sy;
  13739. this.e11 = cx * cz - sx * sy * sz;
  13740. this.e12 = -cy * sx;
  13741. this.e20 = sx * sz - cx * cz * sy;
  13742. this.e21 = cz * sx + cx * sy * sz;
  13743. this.e22 = cx * cy;
  13744. return this;
  13745. }
  13746. toEulerXyz() {
  13747. let sy = this.e02;
  13748. if(sy <= -1) {
  13749. let xSubZ = Math.atan2(this.e21,this.e11);
  13750. return new oimo.common.Vec3(xSubZ * 0.5,-1.570796326794895,-xSubZ * 0.5);
  13751. }
  13752. if(sy >= 1) {
  13753. let xAddZ = Math.atan2(this.e21,this.e11);
  13754. return new oimo.common.Vec3(xAddZ * 0.5,1.570796326794895,xAddZ * 0.5);
  13755. }
  13756. return new oimo.common.Vec3(Math.atan2(-this.e12,this.e22),Math.asin(sy),Math.atan2(-this.e01,this.e00));
  13757. }
  13758. getRow(index) {
  13759. if(index == 0) {
  13760. return new oimo.common.Vec3(this.e00,this.e01,this.e02);
  13761. } else if(index == 1) {
  13762. return new oimo.common.Vec3(this.e10,this.e11,this.e12);
  13763. } else if(index == 2) {
  13764. return new oimo.common.Vec3(this.e20,this.e21,this.e22);
  13765. } else {
  13766. return null;
  13767. }
  13768. }
  13769. getCol(index) {
  13770. if(index == 0) {
  13771. return new oimo.common.Vec3(this.e00,this.e10,this.e20);
  13772. } else if(index == 1) {
  13773. return new oimo.common.Vec3(this.e01,this.e11,this.e21);
  13774. } else if(index == 2) {
  13775. return new oimo.common.Vec3(this.e02,this.e12,this.e22);
  13776. } else {
  13777. return null;
  13778. }
  13779. }
  13780. getRowTo(index,dst) {
  13781. if(index == 0) {
  13782. dst.init(this.e00,this.e01,this.e02);
  13783. } else if(index == 1) {
  13784. dst.init(this.e10,this.e11,this.e12);
  13785. } else if(index == 2) {
  13786. dst.init(this.e20,this.e21,this.e22);
  13787. } else {
  13788. dst.zero();
  13789. }
  13790. }
  13791. getColTo(index,dst) {
  13792. if(index == 0) {
  13793. dst.init(this.e00,this.e10,this.e20);
  13794. } else if(index == 1) {
  13795. dst.init(this.e01,this.e11,this.e21);
  13796. } else if(index == 2) {
  13797. dst.init(this.e02,this.e12,this.e22);
  13798. } else {
  13799. dst.zero();
  13800. }
  13801. }
  13802. fromRows(row0,row1,row2) {
  13803. this.e00 = row0.x;
  13804. this.e01 = row0.y;
  13805. this.e02 = row0.z;
  13806. this.e10 = row1.x;
  13807. this.e11 = row1.y;
  13808. this.e12 = row1.z;
  13809. this.e20 = row2.x;
  13810. this.e21 = row2.y;
  13811. this.e22 = row2.z;
  13812. return this;
  13813. }
  13814. fromCols(col0,col1,col2) {
  13815. this.e00 = col0.x;
  13816. this.e01 = col1.x;
  13817. this.e02 = col2.x;
  13818. this.e10 = col0.y;
  13819. this.e11 = col1.y;
  13820. this.e12 = col2.y;
  13821. this.e20 = col0.z;
  13822. this.e21 = col1.z;
  13823. this.e22 = col2.z;
  13824. return this;
  13825. }
  13826. toString() {
  13827. return "Mat3[" + (this.e00 > 0 ? (this.e00 * 10000000 + 0.5 | 0) / 10000000 : (this.e00 * 10000000 - 0.5 | 0) / 10000000) + ", " + (this.e01 > 0 ? (this.e01 * 10000000 + 0.5 | 0) / 10000000 : (this.e01 * 10000000 - 0.5 | 0) / 10000000) + ", " + (this.e02 > 0 ? (this.e02 * 10000000 + 0.5 | 0) / 10000000 : (this.e02 * 10000000 - 0.5 | 0) / 10000000) + ",\n" + " " + (this.e10 > 0 ? (this.e10 * 10000000 + 0.5 | 0) / 10000000 : (this.e10 * 10000000 - 0.5 | 0) / 10000000) + ", " + (this.e11 > 0 ? (this.e11 * 10000000 + 0.5 | 0) / 10000000 : (this.e11 * 10000000 - 0.5 | 0) / 10000000) + ", " + (this.e12 > 0 ? (this.e12 * 10000000 + 0.5 | 0) / 10000000 : (this.e12 * 10000000 - 0.5 | 0) / 10000000) + ",\n" + " " + (this.e20 > 0 ? (this.e20 * 10000000 + 0.5 | 0) / 10000000 : (this.e20 * 10000000 - 0.5 | 0) / 10000000) + ", " + (this.e21 > 0 ? (this.e21 * 10000000 + 0.5 | 0) / 10000000 : (this.e21 * 10000000 - 0.5 | 0) / 10000000) + ", " + (this.e22 > 0 ? (this.e22 * 10000000 + 0.5 | 0) / 10000000 : (this.e22 * 10000000 - 0.5 | 0) / 10000000) + "]";
  13828. }
  13829. }
  13830. oimo.common.Mat4 = class oimo_common_Mat4 {
  13831. constructor(e00,e01,e02,e03,e10,e11,e12,e13,e20,e21,e22,e23,e30,e31,e32,e33) {
  13832. if(e33 == null) {
  13833. e33 = 1;
  13834. }
  13835. if(e32 == null) {
  13836. e32 = 0;
  13837. }
  13838. if(e31 == null) {
  13839. e31 = 0;
  13840. }
  13841. if(e30 == null) {
  13842. e30 = 0;
  13843. }
  13844. if(e23 == null) {
  13845. e23 = 0;
  13846. }
  13847. if(e22 == null) {
  13848. e22 = 1;
  13849. }
  13850. if(e21 == null) {
  13851. e21 = 0;
  13852. }
  13853. if(e20 == null) {
  13854. e20 = 0;
  13855. }
  13856. if(e13 == null) {
  13857. e13 = 0;
  13858. }
  13859. if(e12 == null) {
  13860. e12 = 0;
  13861. }
  13862. if(e11 == null) {
  13863. e11 = 1;
  13864. }
  13865. if(e10 == null) {
  13866. e10 = 0;
  13867. }
  13868. if(e03 == null) {
  13869. e03 = 0;
  13870. }
  13871. if(e02 == null) {
  13872. e02 = 0;
  13873. }
  13874. if(e01 == null) {
  13875. e01 = 0;
  13876. }
  13877. if(e00 == null) {
  13878. e00 = 1;
  13879. }
  13880. this.e00 = e00;
  13881. this.e01 = e01;
  13882. this.e02 = e02;
  13883. this.e03 = e03;
  13884. this.e10 = e10;
  13885. this.e11 = e11;
  13886. this.e12 = e12;
  13887. this.e13 = e13;
  13888. this.e20 = e20;
  13889. this.e21 = e21;
  13890. this.e22 = e22;
  13891. this.e23 = e23;
  13892. this.e30 = e30;
  13893. this.e31 = e31;
  13894. this.e32 = e32;
  13895. this.e33 = e33;
  13896. oimo.common.Mat4.numCreations++;
  13897. }
  13898. init(e00,e01,e02,e03,e10,e11,e12,e13,e20,e21,e22,e23,e30,e31,e32,e33) {
  13899. this.e00 = e00;
  13900. this.e01 = e01;
  13901. this.e02 = e02;
  13902. this.e03 = e03;
  13903. this.e10 = e10;
  13904. this.e11 = e11;
  13905. this.e12 = e12;
  13906. this.e13 = e13;
  13907. this.e20 = e20;
  13908. this.e21 = e21;
  13909. this.e22 = e22;
  13910. this.e23 = e23;
  13911. this.e30 = e30;
  13912. this.e31 = e31;
  13913. this.e32 = e32;
  13914. this.e33 = e33;
  13915. return this;
  13916. }
  13917. identity() {
  13918. this.e00 = 1;
  13919. this.e01 = 0;
  13920. this.e02 = 0;
  13921. this.e03 = 0;
  13922. this.e10 = 0;
  13923. this.e11 = 1;
  13924. this.e12 = 0;
  13925. this.e13 = 0;
  13926. this.e20 = 0;
  13927. this.e21 = 0;
  13928. this.e22 = 1;
  13929. this.e23 = 0;
  13930. this.e30 = 0;
  13931. this.e31 = 0;
  13932. this.e32 = 0;
  13933. this.e33 = 1;
  13934. return this;
  13935. }
  13936. add(m) {
  13937. return new oimo.common.Mat4(this.e00 + m.e00,this.e01 + m.e01,this.e02 + m.e02,this.e03 + m.e03,this.e10 + m.e10,this.e11 + m.e11,this.e12 + m.e12,this.e13 + m.e13,this.e20 + m.e20,this.e21 + m.e21,this.e22 + m.e22,this.e23 + m.e23,this.e30 + m.e30,this.e31 + m.e31,this.e32 + m.e32,this.e33 + m.e33);
  13938. }
  13939. sub(m) {
  13940. return new oimo.common.Mat4(this.e00 - m.e00,this.e01 - m.e01,this.e02 - m.e02,this.e03 - m.e03,this.e10 - m.e10,this.e11 - m.e11,this.e12 - m.e12,this.e13 - m.e13,this.e20 - m.e20,this.e21 - m.e21,this.e22 - m.e22,this.e23 - m.e23,this.e30 - m.e30,this.e31 - m.e31,this.e32 - m.e32,this.e33 - m.e33);
  13941. }
  13942. scale(s) {
  13943. return new oimo.common.Mat4(this.e00 * s,this.e01 * s,this.e02 * s,this.e03 * s,this.e10 * s,this.e11 * s,this.e12 * s,this.e13 * s,this.e20 * s,this.e21 * s,this.e22 * s,this.e23 * s,this.e30 * s,this.e31 * s,this.e32 * s,this.e33 * s);
  13944. }
  13945. mul(m) {
  13946. return new oimo.common.Mat4(this.e00 * m.e00 + this.e01 * m.e10 + this.e02 * m.e20 + this.e03 * m.e30,this.e00 * m.e01 + this.e01 * m.e11 + this.e02 * m.e21 + this.e03 * m.e31,this.e00 * m.e02 + this.e01 * m.e12 + this.e02 * m.e22 + this.e03 * m.e32,this.e00 * m.e03 + this.e01 * m.e13 + this.e02 * m.e23 + this.e03 * m.e33,this.e10 * m.e00 + this.e11 * m.e10 + this.e12 * m.e20 + this.e13 * m.e30,this.e10 * m.e01 + this.e11 * m.e11 + this.e12 * m.e21 + this.e13 * m.e31,this.e10 * m.e02 + this.e11 * m.e12 + this.e12 * m.e22 + this.e13 * m.e32,this.e10 * m.e03 + this.e11 * m.e13 + this.e12 * m.e23 + this.e13 * m.e33,this.e20 * m.e00 + this.e21 * m.e10 + this.e22 * m.e20 + this.e23 * m.e30,this.e20 * m.e01 + this.e21 * m.e11 + this.e22 * m.e21 + this.e23 * m.e31,this.e20 * m.e02 + this.e21 * m.e12 + this.e22 * m.e22 + this.e23 * m.e32,this.e20 * m.e03 + this.e21 * m.e13 + this.e22 * m.e23 + this.e23 * m.e33,this.e30 * m.e00 + this.e31 * m.e10 + this.e32 * m.e20 + this.e33 * m.e30,this.e30 * m.e01 + this.e31 * m.e11 + this.e32 * m.e21 + this.e33 * m.e31,this.e30 * m.e02 + this.e31 * m.e12 + this.e32 * m.e22 + this.e33 * m.e32,this.e30 * m.e03 + this.e31 * m.e13 + this.e32 * m.e23 + this.e33 * m.e33);
  13947. }
  13948. addEq(m) {
  13949. this.e00 += m.e00;
  13950. this.e01 += m.e01;
  13951. this.e02 += m.e02;
  13952. this.e03 += m.e03;
  13953. this.e10 += m.e10;
  13954. this.e11 += m.e11;
  13955. this.e12 += m.e12;
  13956. this.e13 += m.e13;
  13957. this.e20 += m.e20;
  13958. this.e21 += m.e21;
  13959. this.e22 += m.e22;
  13960. this.e23 += m.e23;
  13961. this.e30 += m.e30;
  13962. this.e31 += m.e31;
  13963. this.e32 += m.e32;
  13964. this.e33 += m.e33;
  13965. return this;
  13966. }
  13967. subEq(m) {
  13968. this.e00 -= m.e00;
  13969. this.e01 -= m.e01;
  13970. this.e02 -= m.e02;
  13971. this.e03 -= m.e03;
  13972. this.e10 -= m.e10;
  13973. this.e11 -= m.e11;
  13974. this.e12 -= m.e12;
  13975. this.e13 -= m.e13;
  13976. this.e20 -= m.e20;
  13977. this.e21 -= m.e21;
  13978. this.e22 -= m.e22;
  13979. this.e23 -= m.e23;
  13980. this.e30 -= m.e30;
  13981. this.e31 -= m.e31;
  13982. this.e32 -= m.e32;
  13983. this.e33 -= m.e33;
  13984. return this;
  13985. }
  13986. scaleEq(s) {
  13987. this.e00 *= s;
  13988. this.e01 *= s;
  13989. this.e02 *= s;
  13990. this.e03 *= s;
  13991. this.e10 *= s;
  13992. this.e11 *= s;
  13993. this.e12 *= s;
  13994. this.e13 *= s;
  13995. this.e20 *= s;
  13996. this.e21 *= s;
  13997. this.e22 *= s;
  13998. this.e23 *= s;
  13999. this.e30 *= s;
  14000. this.e31 *= s;
  14001. this.e32 *= s;
  14002. this.e33 *= s;
  14003. return this;
  14004. }
  14005. mulEq(m) {
  14006. let e01 = this.e00 * m.e01 + this.e01 * m.e11 + this.e02 * m.e21 + this.e03 * m.e31;
  14007. let e02 = this.e00 * m.e02 + this.e01 * m.e12 + this.e02 * m.e22 + this.e03 * m.e32;
  14008. let e03 = this.e00 * m.e03 + this.e01 * m.e13 + this.e02 * m.e23 + this.e03 * m.e33;
  14009. let e10 = this.e10 * m.e00 + this.e11 * m.e10 + this.e12 * m.e20 + this.e13 * m.e30;
  14010. let e11 = this.e10 * m.e01 + this.e11 * m.e11 + this.e12 * m.e21 + this.e13 * m.e31;
  14011. let e12 = this.e10 * m.e02 + this.e11 * m.e12 + this.e12 * m.e22 + this.e13 * m.e32;
  14012. let e13 = this.e10 * m.e03 + this.e11 * m.e13 + this.e12 * m.e23 + this.e13 * m.e33;
  14013. let e20 = this.e20 * m.e00 + this.e21 * m.e10 + this.e22 * m.e20 + this.e23 * m.e30;
  14014. let e21 = this.e20 * m.e01 + this.e21 * m.e11 + this.e22 * m.e21 + this.e23 * m.e31;
  14015. let e22 = this.e20 * m.e02 + this.e21 * m.e12 + this.e22 * m.e22 + this.e23 * m.e32;
  14016. let e23 = this.e20 * m.e03 + this.e21 * m.e13 + this.e22 * m.e23 + this.e23 * m.e33;
  14017. let e30 = this.e30 * m.e00 + this.e31 * m.e10 + this.e32 * m.e20 + this.e33 * m.e30;
  14018. let e31 = this.e30 * m.e01 + this.e31 * m.e11 + this.e32 * m.e21 + this.e33 * m.e31;
  14019. let e32 = this.e30 * m.e02 + this.e31 * m.e12 + this.e32 * m.e22 + this.e33 * m.e32;
  14020. let e33 = this.e30 * m.e03 + this.e31 * m.e13 + this.e32 * m.e23 + this.e33 * m.e33;
  14021. this.e00 = this.e00 * m.e00 + this.e01 * m.e10 + this.e02 * m.e20 + this.e03 * m.e30;
  14022. this.e01 = e01;
  14023. this.e02 = e02;
  14024. this.e03 = e03;
  14025. this.e10 = e10;
  14026. this.e11 = e11;
  14027. this.e12 = e12;
  14028. this.e13 = e13;
  14029. this.e20 = e20;
  14030. this.e21 = e21;
  14031. this.e22 = e22;
  14032. this.e23 = e23;
  14033. this.e30 = e30;
  14034. this.e31 = e31;
  14035. this.e32 = e32;
  14036. this.e33 = e33;
  14037. return this;
  14038. }
  14039. prependScale(sx,sy,sz) {
  14040. return new oimo.common.Mat4(this.e00 * sx,this.e01 * sx,this.e02 * sx,this.e03 * sx,this.e10 * sy,this.e11 * sy,this.e12 * sy,this.e13 * sy,this.e20 * sz,this.e21 * sz,this.e22 * sz,this.e23 * sz,this.e30,this.e31,this.e32,this.e33);
  14041. }
  14042. appendScale(sx,sy,sz) {
  14043. return new oimo.common.Mat4(this.e00 * sx,this.e01 * sy,this.e02 * sz,this.e03,this.e10 * sx,this.e11 * sy,this.e12 * sz,this.e13,this.e20 * sx,this.e21 * sy,this.e22 * sz,this.e23,this.e30 * sx,this.e31 * sy,this.e32 * sz,this.e33);
  14044. }
  14045. prependRotation(rad,axisX,axisY,axisZ) {
  14046. let s = Math.sin(rad);
  14047. let c = Math.cos(rad);
  14048. let c1 = 1 - c;
  14049. let r00 = axisX * axisX * c1 + c;
  14050. let r01 = axisX * axisY * c1 - axisZ * s;
  14051. let r02 = axisX * axisZ * c1 + axisY * s;
  14052. let r10 = axisY * axisX * c1 + axisZ * s;
  14053. let r11 = axisY * axisY * c1 + c;
  14054. let r12 = axisY * axisZ * c1 - axisX * s;
  14055. let r20 = axisZ * axisX * c1 - axisY * s;
  14056. let r21 = axisZ * axisY * c1 + axisX * s;
  14057. let r22 = axisZ * axisZ * c1 + c;
  14058. return new oimo.common.Mat4(r00 * this.e00 + r01 * this.e10 + r02 * this.e20,r00 * this.e01 + r01 * this.e11 + r02 * this.e21,r00 * this.e02 + r01 * this.e12 + r02 * this.e22,r00 * this.e03 + r01 * this.e13 + r02 * this.e23,r10 * this.e00 + r11 * this.e10 + r12 * this.e20,r10 * this.e01 + r11 * this.e11 + r12 * this.e21,r10 * this.e02 + r11 * this.e12 + r12 * this.e22,r10 * this.e03 + r11 * this.e13 + r12 * this.e23,r20 * this.e00 + r21 * this.e10 + r22 * this.e20,r20 * this.e01 + r21 * this.e11 + r22 * this.e21,r20 * this.e02 + r21 * this.e12 + r22 * this.e22,r20 * this.e03 + r21 * this.e13 + r22 * this.e23,this.e30,this.e31,this.e32,this.e33);
  14059. }
  14060. appendRotation(rad,axisX,axisY,axisZ) {
  14061. let s = Math.sin(rad);
  14062. let c = Math.cos(rad);
  14063. let c1 = 1 - c;
  14064. let r00 = axisX * axisX * c1 + c;
  14065. let r01 = axisX * axisY * c1 - axisZ * s;
  14066. let r02 = axisX * axisZ * c1 + axisY * s;
  14067. let r10 = axisY * axisX * c1 + axisZ * s;
  14068. let r11 = axisY * axisY * c1 + c;
  14069. let r12 = axisY * axisZ * c1 - axisX * s;
  14070. let r20 = axisZ * axisX * c1 - axisY * s;
  14071. let r21 = axisZ * axisY * c1 + axisX * s;
  14072. let r22 = axisZ * axisZ * c1 + c;
  14073. return new oimo.common.Mat4(this.e00 * r00 + this.e01 * r10 + this.e02 * r20,this.e00 * r01 + this.e01 * r11 + this.e02 * r21,this.e00 * r02 + this.e01 * r12 + this.e02 * r22,this.e03,this.e10 * r00 + this.e11 * r10 + this.e12 * r20,this.e10 * r01 + this.e11 * r11 + this.e12 * r21,this.e10 * r02 + this.e11 * r12 + this.e12 * r22,this.e13,this.e20 * r00 + this.e21 * r10 + this.e22 * r20,this.e20 * r01 + this.e21 * r11 + this.e22 * r21,this.e20 * r02 + this.e21 * r12 + this.e22 * r22,this.e23,this.e30 * r00 + this.e31 * r10 + this.e32 * r20,this.e30 * r01 + this.e31 * r11 + this.e32 * r21,this.e30 * r02 + this.e31 * r12 + this.e32 * r22,this.e33);
  14074. }
  14075. prependTranslation(tx,ty,tz) {
  14076. return new oimo.common.Mat4(this.e00 + tx * this.e30,this.e01 + tx * this.e31,this.e02 + tx * this.e32,this.e03 + tx * this.e33,this.e10 + ty * this.e30,this.e11 + ty * this.e31,this.e12 + ty * this.e32,this.e13 + ty * this.e33,this.e20 + tz * this.e30,this.e21 + tz * this.e31,this.e22 + tz * this.e32,this.e23 + tz * this.e33,this.e30,this.e31,this.e32,this.e33);
  14077. }
  14078. appendTranslation(tx,ty,tz) {
  14079. return new oimo.common.Mat4(this.e00,this.e01,this.e02,this.e00 * tx + this.e01 * ty + this.e02 * tz + this.e03,this.e10,this.e11,this.e12,this.e10 * tx + this.e11 * ty + this.e12 * tz + this.e13,this.e20,this.e21,this.e22,this.e20 * tx + this.e21 * ty + this.e22 * tz + this.e23,this.e30,this.e31,this.e32,this.e30 * tx + this.e31 * ty + this.e32 * tz + this.e33);
  14080. }
  14081. prependScaleEq(sx,sy,sz) {
  14082. this.e00 *= sx;
  14083. this.e01 *= sx;
  14084. this.e02 *= sx;
  14085. this.e03 *= sx;
  14086. this.e10 *= sy;
  14087. this.e11 *= sy;
  14088. this.e12 *= sy;
  14089. this.e13 *= sy;
  14090. this.e20 *= sz;
  14091. this.e21 *= sz;
  14092. this.e22 *= sz;
  14093. this.e23 *= sz;
  14094. return this;
  14095. }
  14096. appendScaleEq(sx,sy,sz) {
  14097. this.e00 *= sx;
  14098. this.e01 *= sy;
  14099. this.e02 *= sz;
  14100. this.e10 *= sx;
  14101. this.e11 *= sy;
  14102. this.e12 *= sz;
  14103. this.e20 *= sx;
  14104. this.e21 *= sy;
  14105. this.e22 *= sz;
  14106. this.e30 *= sx;
  14107. this.e31 *= sy;
  14108. this.e32 *= sz;
  14109. return this;
  14110. }
  14111. prependRotationEq(rad,axisX,axisY,axisZ) {
  14112. let s = Math.sin(rad);
  14113. let c = Math.cos(rad);
  14114. let c1 = 1 - c;
  14115. let r00 = axisX * axisX * c1 + c;
  14116. let r01 = axisX * axisY * c1 - axisZ * s;
  14117. let r02 = axisX * axisZ * c1 + axisY * s;
  14118. let r10 = axisY * axisX * c1 + axisZ * s;
  14119. let r11 = axisY * axisY * c1 + c;
  14120. let r12 = axisY * axisZ * c1 - axisX * s;
  14121. let r20 = axisZ * axisX * c1 - axisY * s;
  14122. let r21 = axisZ * axisY * c1 + axisX * s;
  14123. let r22 = axisZ * axisZ * c1 + c;
  14124. let e10 = r10 * this.e00 + r11 * this.e10 + r12 * this.e20;
  14125. let e11 = r10 * this.e01 + r11 * this.e11 + r12 * this.e21;
  14126. let e12 = r10 * this.e02 + r11 * this.e12 + r12 * this.e22;
  14127. let e13 = r10 * this.e03 + r11 * this.e13 + r12 * this.e23;
  14128. let e20 = r20 * this.e00 + r21 * this.e10 + r22 * this.e20;
  14129. let e21 = r20 * this.e01 + r21 * this.e11 + r22 * this.e21;
  14130. let e22 = r20 * this.e02 + r21 * this.e12 + r22 * this.e22;
  14131. let e23 = r20 * this.e03 + r21 * this.e13 + r22 * this.e23;
  14132. this.e00 = r00 * this.e00 + r01 * this.e10 + r02 * this.e20;
  14133. this.e01 = r00 * this.e01 + r01 * this.e11 + r02 * this.e21;
  14134. this.e02 = r00 * this.e02 + r01 * this.e12 + r02 * this.e22;
  14135. this.e03 = r00 * this.e03 + r01 * this.e13 + r02 * this.e23;
  14136. this.e10 = e10;
  14137. this.e11 = e11;
  14138. this.e12 = e12;
  14139. this.e13 = e13;
  14140. this.e20 = e20;
  14141. this.e21 = e21;
  14142. this.e22 = e22;
  14143. this.e23 = e23;
  14144. return this;
  14145. }
  14146. appendRotationEq(rad,axisX,axisY,axisZ) {
  14147. let s = Math.sin(rad);
  14148. let c = Math.cos(rad);
  14149. let c1 = 1 - c;
  14150. let r00 = axisX * axisX * c1 + c;
  14151. let r01 = axisX * axisY * c1 - axisZ * s;
  14152. let r02 = axisX * axisZ * c1 + axisY * s;
  14153. let r10 = axisY * axisX * c1 + axisZ * s;
  14154. let r11 = axisY * axisY * c1 + c;
  14155. let r12 = axisY * axisZ * c1 - axisX * s;
  14156. let r20 = axisZ * axisX * c1 - axisY * s;
  14157. let r21 = axisZ * axisY * c1 + axisX * s;
  14158. let r22 = axisZ * axisZ * c1 + c;
  14159. let e01 = this.e00 * r01 + this.e01 * r11 + this.e02 * r21;
  14160. let e02 = this.e00 * r02 + this.e01 * r12 + this.e02 * r22;
  14161. let e11 = this.e10 * r01 + this.e11 * r11 + this.e12 * r21;
  14162. let e12 = this.e10 * r02 + this.e11 * r12 + this.e12 * r22;
  14163. let e21 = this.e20 * r01 + this.e21 * r11 + this.e22 * r21;
  14164. let e22 = this.e20 * r02 + this.e21 * r12 + this.e22 * r22;
  14165. let e31 = this.e30 * r01 + this.e31 * r11 + this.e32 * r21;
  14166. let e32 = this.e30 * r02 + this.e31 * r12 + this.e32 * r22;
  14167. this.e00 = this.e00 * r00 + this.e01 * r10 + this.e02 * r20;
  14168. this.e01 = e01;
  14169. this.e02 = e02;
  14170. this.e10 = this.e10 * r00 + this.e11 * r10 + this.e12 * r20;
  14171. this.e11 = e11;
  14172. this.e12 = e12;
  14173. this.e20 = this.e20 * r00 + this.e21 * r10 + this.e22 * r20;
  14174. this.e21 = e21;
  14175. this.e22 = e22;
  14176. this.e30 = this.e30 * r00 + this.e31 * r10 + this.e32 * r20;
  14177. this.e31 = e31;
  14178. this.e32 = e32;
  14179. return this;
  14180. }
  14181. prependTranslationEq(tx,ty,tz) {
  14182. this.e00 += tx * this.e30;
  14183. this.e01 += tx * this.e31;
  14184. this.e02 += tx * this.e32;
  14185. this.e03 += tx * this.e33;
  14186. this.e10 += ty * this.e30;
  14187. this.e11 += ty * this.e31;
  14188. this.e12 += ty * this.e32;
  14189. this.e13 += ty * this.e33;
  14190. this.e20 += tz * this.e30;
  14191. this.e21 += tz * this.e31;
  14192. this.e22 += tz * this.e32;
  14193. this.e23 += tz * this.e33;
  14194. return this;
  14195. }
  14196. appendTranslationEq(tx,ty,tz) {
  14197. let e03 = this.e00 * tx + this.e01 * ty + this.e02 * tz + this.e03;
  14198. let e13 = this.e10 * tx + this.e11 * ty + this.e12 * tz + this.e13;
  14199. let e23 = this.e20 * tx + this.e21 * ty + this.e22 * tz + this.e23;
  14200. let e33 = this.e30 * tx + this.e31 * ty + this.e32 * tz + this.e33;
  14201. this.e03 = e03;
  14202. this.e13 = e13;
  14203. this.e23 = e23;
  14204. this.e33 = e33;
  14205. return this;
  14206. }
  14207. transpose() {
  14208. return new oimo.common.Mat4(this.e00,this.e10,this.e20,this.e30,this.e01,this.e11,this.e21,this.e31,this.e02,this.e12,this.e22,this.e32,this.e03,this.e13,this.e23,this.e33);
  14209. }
  14210. transposeEq() {
  14211. let e10 = this.e01;
  14212. let e20 = this.e02;
  14213. let e21 = this.e12;
  14214. let e30 = this.e03;
  14215. let e31 = this.e13;
  14216. let e32 = this.e23;
  14217. this.e01 = this.e10;
  14218. this.e02 = this.e20;
  14219. this.e03 = this.e30;
  14220. this.e10 = e10;
  14221. this.e12 = this.e21;
  14222. this.e13 = this.e31;
  14223. this.e20 = e20;
  14224. this.e21 = e21;
  14225. this.e23 = this.e32;
  14226. this.e30 = e30;
  14227. this.e31 = e31;
  14228. this.e32 = e32;
  14229. return this;
  14230. }
  14231. determinant() {
  14232. let d23_01 = this.e20 * this.e31 - this.e21 * this.e30;
  14233. let d23_02 = this.e20 * this.e32 - this.e22 * this.e30;
  14234. let d23_03 = this.e20 * this.e33 - this.e23 * this.e30;
  14235. let d23_12 = this.e21 * this.e32 - this.e22 * this.e31;
  14236. let d23_13 = this.e21 * this.e33 - this.e23 * this.e31;
  14237. let d23_23 = this.e22 * this.e33 - this.e23 * this.e32;
  14238. return this.e00 * (this.e11 * d23_23 - this.e12 * d23_13 + this.e13 * d23_12) - this.e01 * (this.e10 * d23_23 - this.e12 * d23_03 + this.e13 * d23_02) + this.e02 * (this.e10 * d23_13 - this.e11 * d23_03 + this.e13 * d23_01) - this.e03 * (this.e10 * d23_12 - this.e11 * d23_02 + this.e12 * d23_01);
  14239. }
  14240. trace() {
  14241. return this.e00 + this.e11 + this.e22 + this.e33;
  14242. }
  14243. inverse() {
  14244. let d01_01 = this.e00 * this.e11 - this.e01 * this.e10;
  14245. let d01_02 = this.e00 * this.e12 - this.e02 * this.e10;
  14246. let d01_03 = this.e00 * this.e13 - this.e03 * this.e10;
  14247. let d01_12 = this.e01 * this.e12 - this.e02 * this.e11;
  14248. let d01_13 = this.e01 * this.e13 - this.e03 * this.e11;
  14249. let d01_23 = this.e02 * this.e13 - this.e03 * this.e12;
  14250. let d23_01 = this.e20 * this.e31 - this.e21 * this.e30;
  14251. let d23_02 = this.e20 * this.e32 - this.e22 * this.e30;
  14252. let d23_03 = this.e20 * this.e33 - this.e23 * this.e30;
  14253. let d23_12 = this.e21 * this.e32 - this.e22 * this.e31;
  14254. let d23_13 = this.e21 * this.e33 - this.e23 * this.e31;
  14255. let d23_23 = this.e22 * this.e33 - this.e23 * this.e32;
  14256. let d00 = this.e11 * d23_23 - this.e12 * d23_13 + this.e13 * d23_12;
  14257. let d01 = this.e10 * d23_23 - this.e12 * d23_03 + this.e13 * d23_02;
  14258. let d02 = this.e10 * d23_13 - this.e11 * d23_03 + this.e13 * d23_01;
  14259. let d03 = this.e10 * d23_12 - this.e11 * d23_02 + this.e12 * d23_01;
  14260. let invDet = this.e00 * d00 - this.e01 * d01 + this.e02 * d02 - this.e03 * d03;
  14261. if(invDet != 0) {
  14262. invDet = 1 / invDet;
  14263. }
  14264. return new oimo.common.Mat4(d00 * invDet,-(this.e01 * d23_23 - this.e02 * d23_13 + this.e03 * d23_12) * invDet,(this.e31 * d01_23 - this.e32 * d01_13 + this.e33 * d01_12) * invDet,-(this.e21 * d01_23 - this.e22 * d01_13 + this.e23 * d01_12) * invDet,-d01 * invDet,(this.e00 * d23_23 - this.e02 * d23_03 + this.e03 * d23_02) * invDet,-(this.e30 * d01_23 - this.e32 * d01_03 + this.e33 * d01_02) * invDet,(this.e20 * d01_23 - this.e22 * d01_03 + this.e23 * d01_02) * invDet,d02 * invDet,-(this.e00 * d23_13 - this.e01 * d23_03 + this.e03 * d23_01) * invDet,(this.e30 * d01_13 - this.e31 * d01_03 + this.e33 * d01_01) * invDet,-(this.e20 * d01_13 - this.e21 * d01_03 + this.e23 * d01_01) * invDet,-d03 * invDet,(this.e00 * d23_12 - this.e01 * d23_02 + this.e02 * d23_01) * invDet,-(this.e30 * d01_12 - this.e31 * d01_02 + this.e32 * d01_01) * invDet,(this.e20 * d01_12 - this.e21 * d01_02 + this.e22 * d01_01) * invDet);
  14265. }
  14266. inverseEq() {
  14267. let d01_01 = this.e00 * this.e11 - this.e01 * this.e10;
  14268. let d01_02 = this.e00 * this.e12 - this.e02 * this.e10;
  14269. let d01_03 = this.e00 * this.e13 - this.e03 * this.e10;
  14270. let d01_12 = this.e01 * this.e12 - this.e02 * this.e11;
  14271. let d01_13 = this.e01 * this.e13 - this.e03 * this.e11;
  14272. let d01_23 = this.e02 * this.e13 - this.e03 * this.e12;
  14273. let d23_01 = this.e20 * this.e31 - this.e21 * this.e30;
  14274. let d23_02 = this.e20 * this.e32 - this.e22 * this.e30;
  14275. let d23_03 = this.e20 * this.e33 - this.e23 * this.e30;
  14276. let d23_12 = this.e21 * this.e32 - this.e22 * this.e31;
  14277. let d23_13 = this.e21 * this.e33 - this.e23 * this.e31;
  14278. let d23_23 = this.e22 * this.e33 - this.e23 * this.e32;
  14279. let d00 = this.e11 * d23_23 - this.e12 * d23_13 + this.e13 * d23_12;
  14280. let d01 = this.e10 * d23_23 - this.e12 * d23_03 + this.e13 * d23_02;
  14281. let d02 = this.e10 * d23_13 - this.e11 * d23_03 + this.e13 * d23_01;
  14282. let d03 = this.e10 * d23_12 - this.e11 * d23_02 + this.e12 * d23_01;
  14283. let invDet = this.e00 * d00 - this.e01 * d01 + this.e02 * d02 - this.e03 * d03;
  14284. if(invDet != 0) {
  14285. invDet = 1 / invDet;
  14286. }
  14287. let t11 = (this.e00 * d23_23 - this.e02 * d23_03 + this.e03 * d23_02) * invDet;
  14288. let t21 = -(this.e00 * d23_13 - this.e01 * d23_03 + this.e03 * d23_01) * invDet;
  14289. let t23 = -(this.e20 * d01_13 - this.e21 * d01_03 + this.e23 * d01_01) * invDet;
  14290. let t31 = (this.e00 * d23_12 - this.e01 * d23_02 + this.e02 * d23_01) * invDet;
  14291. let t32 = -(this.e30 * d01_12 - this.e31 * d01_02 + this.e32 * d01_01) * invDet;
  14292. let t33 = (this.e20 * d01_12 - this.e21 * d01_02 + this.e22 * d01_01) * invDet;
  14293. this.e00 = d00 * invDet;
  14294. this.e01 = -(this.e01 * d23_23 - this.e02 * d23_13 + this.e03 * d23_12) * invDet;
  14295. this.e02 = (this.e31 * d01_23 - this.e32 * d01_13 + this.e33 * d01_12) * invDet;
  14296. this.e03 = -(this.e21 * d01_23 - this.e22 * d01_13 + this.e23 * d01_12) * invDet;
  14297. this.e10 = -d01 * invDet;
  14298. this.e11 = t11;
  14299. this.e12 = -(this.e30 * d01_23 - this.e32 * d01_03 + this.e33 * d01_02) * invDet;
  14300. this.e13 = (this.e20 * d01_23 - this.e22 * d01_03 + this.e23 * d01_02) * invDet;
  14301. this.e20 = d02 * invDet;
  14302. this.e21 = t21;
  14303. this.e22 = (this.e30 * d01_13 - this.e31 * d01_03 + this.e33 * d01_01) * invDet;
  14304. this.e23 = t23;
  14305. this.e30 = -d03 * invDet;
  14306. this.e31 = t31;
  14307. this.e32 = t32;
  14308. this.e33 = t33;
  14309. return this;
  14310. }
  14311. lookAt(eyeX,eyeY,eyeZ,atX,atY,atZ,upX,upY,upZ) {
  14312. let zx = eyeX - atX;
  14313. let zy = eyeY - atY;
  14314. let zz = eyeZ - atZ;
  14315. let tmp = 1 / Math.sqrt(zx * zx + zy * zy + zz * zz);
  14316. zx *= tmp;
  14317. zy *= tmp;
  14318. zz *= tmp;
  14319. let xx = upY * zz - upZ * zy;
  14320. let xy = upZ * zx - upX * zz;
  14321. let xz = upX * zy - upY * zx;
  14322. tmp = 1 / Math.sqrt(xx * xx + xy * xy + xz * xz);
  14323. xx *= tmp;
  14324. xy *= tmp;
  14325. xz *= tmp;
  14326. let yx = zy * xz - zz * xy;
  14327. let yy = zz * xx - zx * xz;
  14328. let yz = zx * xy - zy * xx;
  14329. this.e00 = xx;
  14330. this.e01 = xy;
  14331. this.e02 = xz;
  14332. this.e03 = -(xx * eyeX + xy * eyeY + xz * eyeZ);
  14333. this.e10 = yx;
  14334. this.e11 = yy;
  14335. this.e12 = yz;
  14336. this.e13 = -(yx * eyeX + yy * eyeY + yz * eyeZ);
  14337. this.e20 = zx;
  14338. this.e21 = zy;
  14339. this.e22 = zz;
  14340. this.e23 = -(zx * eyeX + zy * eyeY + zz * eyeZ);
  14341. this.e30 = 0;
  14342. this.e31 = 0;
  14343. this.e32 = 0;
  14344. this.e33 = 1;
  14345. return this;
  14346. }
  14347. perspective(fovY,aspect,near,far) {
  14348. let h = 1 / Math.tan(fovY * 0.5);
  14349. let fnf = far / (near - far);
  14350. this.e00 = h / aspect;
  14351. this.e01 = 0;
  14352. this.e02 = 0;
  14353. this.e03 = 0;
  14354. this.e10 = 0;
  14355. this.e11 = h;
  14356. this.e12 = 0;
  14357. this.e13 = 0;
  14358. this.e20 = 0;
  14359. this.e21 = 0;
  14360. this.e22 = fnf;
  14361. this.e23 = near * fnf;
  14362. this.e30 = 0;
  14363. this.e31 = 0;
  14364. this.e32 = -1;
  14365. this.e33 = 0;
  14366. return this;
  14367. }
  14368. ortho(width,height,near,far) {
  14369. let nf = 1 / (near - far);
  14370. this.e00 = 2 / width;
  14371. this.e01 = 0;
  14372. this.e02 = 0;
  14373. this.e03 = 0;
  14374. this.e10 = 0;
  14375. this.e11 = 2 / height;
  14376. this.e12 = 0;
  14377. this.e13 = 0;
  14378. this.e20 = 0;
  14379. this.e21 = 0;
  14380. this.e22 = nf;
  14381. this.e23 = near * nf;
  14382. this.e30 = 0;
  14383. this.e31 = 0;
  14384. this.e32 = 0;
  14385. this.e33 = 1;
  14386. return this;
  14387. }
  14388. toArray(columnMajor) {
  14389. if(columnMajor == null) {
  14390. columnMajor = false;
  14391. }
  14392. if(columnMajor) {
  14393. return [this.e00,this.e10,this.e20,this.e30,this.e01,this.e11,this.e21,this.e31,this.e02,this.e12,this.e22,this.e32,this.e03,this.e13,this.e23,this.e33];
  14394. } else {
  14395. return [this.e00,this.e01,this.e02,this.e03,this.e10,this.e11,this.e12,this.e13,this.e20,this.e21,this.e22,this.e23,this.e30,this.e31,this.e32,this.e33];
  14396. }
  14397. }
  14398. copyFrom(m) {
  14399. this.e00 = m.e00;
  14400. this.e01 = m.e01;
  14401. this.e02 = m.e02;
  14402. this.e03 = m.e03;
  14403. this.e10 = m.e10;
  14404. this.e11 = m.e11;
  14405. this.e12 = m.e12;
  14406. this.e13 = m.e13;
  14407. this.e20 = m.e20;
  14408. this.e21 = m.e21;
  14409. this.e22 = m.e22;
  14410. this.e23 = m.e23;
  14411. this.e30 = m.e30;
  14412. this.e31 = m.e31;
  14413. this.e32 = m.e32;
  14414. this.e33 = m.e33;
  14415. return this;
  14416. }
  14417. fromMat3(m) {
  14418. this.e00 = m.e00;
  14419. this.e01 = m.e01;
  14420. this.e02 = m.e02;
  14421. this.e03 = 0;
  14422. this.e10 = m.e10;
  14423. this.e11 = m.e11;
  14424. this.e12 = m.e12;
  14425. this.e13 = 0;
  14426. this.e20 = m.e20;
  14427. this.e21 = m.e21;
  14428. this.e22 = m.e22;
  14429. this.e23 = 0;
  14430. this.e30 = 0;
  14431. this.e31 = 0;
  14432. this.e32 = 0;
  14433. this.e33 = 1;
  14434. return this;
  14435. }
  14436. fromTransform(transform) {
  14437. this.e00 = transform._rotation00;
  14438. this.e01 = transform._rotation01;
  14439. this.e02 = transform._rotation02;
  14440. this.e10 = transform._rotation10;
  14441. this.e11 = transform._rotation11;
  14442. this.e12 = transform._rotation12;
  14443. this.e20 = transform._rotation20;
  14444. this.e21 = transform._rotation21;
  14445. this.e22 = transform._rotation22;
  14446. this.e03 = transform._positionX;
  14447. this.e13 = transform._positionY;
  14448. this.e23 = transform._positionZ;
  14449. this.e30 = 0;
  14450. this.e31 = 0;
  14451. this.e32 = 0;
  14452. this.e33 = 1;
  14453. return this;
  14454. }
  14455. clone() {
  14456. return new oimo.common.Mat4(this.e00,this.e01,this.e02,this.e03,this.e10,this.e11,this.e12,this.e13,this.e20,this.e21,this.e22,this.e23,this.e30,this.e31,this.e32,this.e33);
  14457. }
  14458. toString() {
  14459. return "Mat4[" + (this.e00 > 0 ? (this.e00 * 10000000 + 0.5 | 0) / 10000000 : (this.e00 * 10000000 - 0.5 | 0) / 10000000) + ", " + (this.e01 > 0 ? (this.e01 * 10000000 + 0.5 | 0) / 10000000 : (this.e01 * 10000000 - 0.5 | 0) / 10000000) + ", " + (this.e02 > 0 ? (this.e02 * 10000000 + 0.5 | 0) / 10000000 : (this.e02 * 10000000 - 0.5 | 0) / 10000000) + ", " + (this.e03 > 0 ? (this.e03 * 10000000 + 0.5 | 0) / 10000000 : (this.e03 * 10000000 - 0.5 | 0) / 10000000) + ",\n" + " " + (this.e10 > 0 ? (this.e10 * 10000000 + 0.5 | 0) / 10000000 : (this.e10 * 10000000 - 0.5 | 0) / 10000000) + ", " + (this.e11 > 0 ? (this.e11 * 10000000 + 0.5 | 0) / 10000000 : (this.e11 * 10000000 - 0.5 | 0) / 10000000) + ", " + (this.e12 > 0 ? (this.e12 * 10000000 + 0.5 | 0) / 10000000 : (this.e12 * 10000000 - 0.5 | 0) / 10000000) + ", " + (this.e13 > 0 ? (this.e13 * 10000000 + 0.5 | 0) / 10000000 : (this.e13 * 10000000 - 0.5 | 0) / 10000000) + ",\n" + " " + (this.e20 > 0 ? (this.e20 * 10000000 + 0.5 | 0) / 10000000 : (this.e20 * 10000000 - 0.5 | 0) / 10000000) + ", " + (this.e21 > 0 ? (this.e21 * 10000000 + 0.5 | 0) / 10000000 : (this.e21 * 10000000 - 0.5 | 0) / 10000000) + ", " + (this.e22 > 0 ? (this.e22 * 10000000 + 0.5 | 0) / 10000000 : (this.e22 * 10000000 - 0.5 | 0) / 10000000) + ", " + (this.e23 > 0 ? (this.e23 * 10000000 + 0.5 | 0) / 10000000 : (this.e23 * 10000000 - 0.5 | 0) / 10000000) + ",\n" + " " + (this.e30 > 0 ? (this.e30 * 10000000 + 0.5 | 0) / 10000000 : (this.e30 * 10000000 - 0.5 | 0) / 10000000) + ", " + (this.e31 > 0 ? (this.e31 * 10000000 + 0.5 | 0) / 10000000 : (this.e31 * 10000000 - 0.5 | 0) / 10000000) + ", " + (this.e32 > 0 ? (this.e32 * 10000000 + 0.5 | 0) / 10000000 : (this.e32 * 10000000 - 0.5 | 0) / 10000000) + ", " + (this.e33 > 0 ? (this.e33 * 10000000 + 0.5 | 0) / 10000000 : (this.e33 * 10000000 - 0.5 | 0) / 10000000) + "]";
  14460. }
  14461. }
  14462. oimo.common.MathUtil = class oimo_common_MathUtil {
  14463. static abs(x) {
  14464. if(x > 0) {
  14465. return x;
  14466. } else {
  14467. return -x;
  14468. }
  14469. }
  14470. static sin(x) {
  14471. return Math.sin(x);
  14472. }
  14473. static cos(x) {
  14474. return Math.cos(x);
  14475. }
  14476. static tan(x) {
  14477. return Math.tan(x);
  14478. }
  14479. static asin(x) {
  14480. return Math.asin(x);
  14481. }
  14482. static acos(x) {
  14483. return Math.acos(x);
  14484. }
  14485. static atan(x) {
  14486. return Math.atan(x);
  14487. }
  14488. static safeAsin(x) {
  14489. if(x <= -1) {
  14490. return -1.570796326794895;
  14491. }
  14492. if(x >= 1) {
  14493. return 1.570796326794895;
  14494. }
  14495. return Math.asin(x);
  14496. }
  14497. static safeAcos(x) {
  14498. if(x <= -1) {
  14499. return 3.14159265358979;
  14500. }
  14501. if(x >= 1) {
  14502. return 0;
  14503. }
  14504. return Math.acos(x);
  14505. }
  14506. static atan2(y,x) {
  14507. return Math.atan2(y,x);
  14508. }
  14509. static sqrt(x) {
  14510. return Math.sqrt(x);
  14511. }
  14512. static clamp(x,min,max) {
  14513. if(x < min) {
  14514. return min;
  14515. } else if(x > max) {
  14516. return max;
  14517. } else {
  14518. return x;
  14519. }
  14520. }
  14521. static rand() {
  14522. return Math.random();
  14523. }
  14524. static randIn(min,max) {
  14525. return min + Math.random() * (max - min);
  14526. }
  14527. static randVec3In(min,max) {
  14528. return new oimo.common.Vec3(min + Math.random() * (max - min),min + Math.random() * (max - min),min + Math.random() * (max - min));
  14529. }
  14530. static randVec3() {
  14531. return new oimo.common.Vec3(-1 + Math.random() * 2,-1 + Math.random() * 2,-1 + Math.random() * 2);
  14532. }
  14533. }
  14534. oimo.common.Pool = class oimo_common_Pool {
  14535. constructor() {
  14536. this.stackVec3 = new Array(256);
  14537. this.sizeVec3 = 0;
  14538. this.stackMat3 = new Array(256);
  14539. this.sizeMat3 = 0;
  14540. this.stackMat4 = new Array(256);
  14541. this.sizeMat4 = 0;
  14542. this.stackQuat = new Array(256);
  14543. this.sizeQuat = 0;
  14544. }
  14545. vec3() {
  14546. if(this.sizeVec3 == 0) {
  14547. return new oimo.common.Vec3();
  14548. } else {
  14549. return this.stackVec3[--this.sizeVec3];
  14550. }
  14551. }
  14552. mat3() {
  14553. if(this.sizeMat3 == 0) {
  14554. return new oimo.common.Mat3();
  14555. } else {
  14556. return this.stackMat3[--this.sizeMat3];
  14557. }
  14558. }
  14559. mat4() {
  14560. if(this.sizeMat4 == 0) {
  14561. return new oimo.common.Mat4();
  14562. } else {
  14563. return this.stackMat4[--this.sizeMat4];
  14564. }
  14565. }
  14566. quat() {
  14567. if(this.sizeQuat == 0) {
  14568. return new oimo.common.Quat();
  14569. } else {
  14570. return this.stackQuat[--this.sizeQuat];
  14571. }
  14572. }
  14573. dispose(vec3,mat3,mat4,quat) {
  14574. if(vec3 != null) {
  14575. vec3.zero();
  14576. if(this.sizeVec3 == this.stackVec3.length) {
  14577. let newArray = new Array(this.sizeVec3 << 1);
  14578. let _g = 0;
  14579. let _g1 = this.sizeVec3;
  14580. while(_g < _g1) {
  14581. let i = _g++;
  14582. newArray[i] = this.stackVec3[i];
  14583. this.stackVec3[i] = null;
  14584. }
  14585. this.stackVec3 = newArray;
  14586. }
  14587. this.stackVec3[this.sizeVec3++] = vec3;
  14588. }
  14589. if(mat3 != null) {
  14590. mat3.e00 = 1;
  14591. mat3.e01 = 0;
  14592. mat3.e02 = 0;
  14593. mat3.e10 = 0;
  14594. mat3.e11 = 1;
  14595. mat3.e12 = 0;
  14596. mat3.e20 = 0;
  14597. mat3.e21 = 0;
  14598. mat3.e22 = 1;
  14599. if(this.sizeMat3 == this.stackMat3.length) {
  14600. let newArray = new Array(this.sizeMat3 << 1);
  14601. let _g = 0;
  14602. let _g1 = this.sizeMat3;
  14603. while(_g < _g1) {
  14604. let i = _g++;
  14605. newArray[i] = this.stackMat3[i];
  14606. this.stackMat3[i] = null;
  14607. }
  14608. this.stackMat3 = newArray;
  14609. }
  14610. this.stackMat3[this.sizeMat3++] = mat3;
  14611. }
  14612. if(mat4 != null) {
  14613. mat4.e00 = 1;
  14614. mat4.e01 = 0;
  14615. mat4.e02 = 0;
  14616. mat4.e03 = 0;
  14617. mat4.e10 = 0;
  14618. mat4.e11 = 1;
  14619. mat4.e12 = 0;
  14620. mat4.e13 = 0;
  14621. mat4.e20 = 0;
  14622. mat4.e21 = 0;
  14623. mat4.e22 = 1;
  14624. mat4.e23 = 0;
  14625. mat4.e30 = 0;
  14626. mat4.e31 = 0;
  14627. mat4.e32 = 0;
  14628. mat4.e33 = 1;
  14629. if(this.sizeMat4 == this.stackMat4.length) {
  14630. let newArray = new Array(this.sizeMat4 << 1);
  14631. let _g = 0;
  14632. let _g1 = this.sizeMat4;
  14633. while(_g < _g1) {
  14634. let i = _g++;
  14635. newArray[i] = this.stackMat4[i];
  14636. this.stackMat4[i] = null;
  14637. }
  14638. this.stackMat4 = newArray;
  14639. }
  14640. this.stackMat4[this.sizeMat4++] = mat4;
  14641. }
  14642. if(quat != null) {
  14643. quat.x = 0;
  14644. quat.y = 0;
  14645. quat.z = 0;
  14646. quat.w = 1;
  14647. if(this.sizeQuat == this.stackQuat.length) {
  14648. let newArray = new Array(this.sizeQuat << 1);
  14649. let _g = 0;
  14650. let _g1 = this.sizeQuat;
  14651. while(_g < _g1) {
  14652. let i = _g++;
  14653. newArray[i] = this.stackQuat[i];
  14654. this.stackQuat[i] = null;
  14655. }
  14656. this.stackQuat = newArray;
  14657. }
  14658. this.stackQuat[this.sizeQuat++] = quat;
  14659. }
  14660. }
  14661. disposeVec3(v) {
  14662. v.zero();
  14663. if(this.sizeVec3 == this.stackVec3.length) {
  14664. let newArray = new Array(this.sizeVec3 << 1);
  14665. let _g = 0;
  14666. let _g1 = this.sizeVec3;
  14667. while(_g < _g1) {
  14668. let i = _g++;
  14669. newArray[i] = this.stackVec3[i];
  14670. this.stackVec3[i] = null;
  14671. }
  14672. this.stackVec3 = newArray;
  14673. }
  14674. this.stackVec3[this.sizeVec3++] = v;
  14675. }
  14676. disposeMat3(m) {
  14677. m.e00 = 1;
  14678. m.e01 = 0;
  14679. m.e02 = 0;
  14680. m.e10 = 0;
  14681. m.e11 = 1;
  14682. m.e12 = 0;
  14683. m.e20 = 0;
  14684. m.e21 = 0;
  14685. m.e22 = 1;
  14686. if(this.sizeMat3 == this.stackMat3.length) {
  14687. let newArray = new Array(this.sizeMat3 << 1);
  14688. let _g = 0;
  14689. let _g1 = this.sizeMat3;
  14690. while(_g < _g1) {
  14691. let i = _g++;
  14692. newArray[i] = this.stackMat3[i];
  14693. this.stackMat3[i] = null;
  14694. }
  14695. this.stackMat3 = newArray;
  14696. }
  14697. this.stackMat3[this.sizeMat3++] = m;
  14698. }
  14699. disposeMat4(m) {
  14700. m.e00 = 1;
  14701. m.e01 = 0;
  14702. m.e02 = 0;
  14703. m.e03 = 0;
  14704. m.e10 = 0;
  14705. m.e11 = 1;
  14706. m.e12 = 0;
  14707. m.e13 = 0;
  14708. m.e20 = 0;
  14709. m.e21 = 0;
  14710. m.e22 = 1;
  14711. m.e23 = 0;
  14712. m.e30 = 0;
  14713. m.e31 = 0;
  14714. m.e32 = 0;
  14715. m.e33 = 1;
  14716. if(this.sizeMat4 == this.stackMat4.length) {
  14717. let newArray = new Array(this.sizeMat4 << 1);
  14718. let _g = 0;
  14719. let _g1 = this.sizeMat4;
  14720. while(_g < _g1) {
  14721. let i = _g++;
  14722. newArray[i] = this.stackMat4[i];
  14723. this.stackMat4[i] = null;
  14724. }
  14725. this.stackMat4 = newArray;
  14726. }
  14727. this.stackMat4[this.sizeMat4++] = m;
  14728. }
  14729. disposeQuat(q) {
  14730. q.x = 0;
  14731. q.y = 0;
  14732. q.z = 0;
  14733. q.w = 1;
  14734. if(this.sizeQuat == this.stackQuat.length) {
  14735. let newArray = new Array(this.sizeQuat << 1);
  14736. let _g = 0;
  14737. let _g1 = this.sizeQuat;
  14738. while(_g < _g1) {
  14739. let i = _g++;
  14740. newArray[i] = this.stackQuat[i];
  14741. this.stackQuat[i] = null;
  14742. }
  14743. this.stackQuat = newArray;
  14744. }
  14745. this.stackQuat[this.sizeQuat++] = q;
  14746. }
  14747. }
  14748. oimo.common.Quat = class oimo_common_Quat {
  14749. constructor(x,y,z,w) {
  14750. if(w == null) {
  14751. w = 1;
  14752. }
  14753. if(z == null) {
  14754. z = 0;
  14755. }
  14756. if(y == null) {
  14757. y = 0;
  14758. }
  14759. if(x == null) {
  14760. x = 0;
  14761. }
  14762. this.x = x;
  14763. this.y = y;
  14764. this.z = z;
  14765. this.w = w;
  14766. oimo.common.Quat.numCreations++;
  14767. }
  14768. identity() {
  14769. this.x = 0;
  14770. this.y = 0;
  14771. this.z = 0;
  14772. this.w = 1;
  14773. return this;
  14774. }
  14775. init(x,y,z,w) {
  14776. this.x = x;
  14777. this.y = y;
  14778. this.z = z;
  14779. this.w = w;
  14780. return this;
  14781. }
  14782. add(q) {
  14783. return new oimo.common.Quat(this.x + q.x,this.y + q.y,this.z + q.z,this.w + q.w);
  14784. }
  14785. sub(q) {
  14786. return new oimo.common.Quat(this.x - q.x,this.y - q.y,this.z - q.z,this.w - q.w);
  14787. }
  14788. scale(s) {
  14789. return new oimo.common.Quat(this.x * s,this.y * s,this.z * s,this.w * s);
  14790. }
  14791. addEq(q) {
  14792. this.x += q.x;
  14793. this.y += q.y;
  14794. this.z += q.z;
  14795. this.w += q.w;
  14796. return this;
  14797. }
  14798. subEq(q) {
  14799. this.x -= q.x;
  14800. this.y -= q.y;
  14801. this.z -= q.z;
  14802. this.w -= q.w;
  14803. return this;
  14804. }
  14805. scaleEq(s) {
  14806. this.x *= s;
  14807. this.y *= s;
  14808. this.z *= s;
  14809. this.w *= s;
  14810. return this;
  14811. }
  14812. length() {
  14813. return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
  14814. }
  14815. lengthSq() {
  14816. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  14817. }
  14818. dot(q) {
  14819. return this.x * q.x + this.y * q.y + this.z * q.z + this.w * q.w;
  14820. }
  14821. normalized() {
  14822. let invLen = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
  14823. if(invLen > 0) {
  14824. invLen = 1 / invLen;
  14825. }
  14826. return new oimo.common.Quat(this.x * invLen,this.y * invLen,this.z * invLen,this.w * invLen);
  14827. }
  14828. normalize() {
  14829. let invLen = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
  14830. if(invLen > 0) {
  14831. invLen = 1 / invLen;
  14832. }
  14833. this.x *= invLen;
  14834. this.y *= invLen;
  14835. this.z *= invLen;
  14836. this.w *= invLen;
  14837. return this;
  14838. }
  14839. setArc(v1,v2) {
  14840. let x1 = v1.x;
  14841. let y1 = v1.y;
  14842. let z1 = v1.z;
  14843. let x2 = v2.x;
  14844. let y2 = v2.y;
  14845. let z2 = v2.z;
  14846. let d = x1 * x2 + y1 * y2 + z1 * z2;
  14847. this.w = Math.sqrt((1 + d) * 0.5);
  14848. if(this.w == 0) {
  14849. x2 = x1 * x1;
  14850. y2 = y1 * y1;
  14851. z2 = z1 * z1;
  14852. if(x2 < y2) {
  14853. if(x2 < z2) {
  14854. d = 1 / Math.sqrt(y2 + z2);
  14855. this.x = 0;
  14856. this.y = z1 * d;
  14857. this.z = -y1 * d;
  14858. } else {
  14859. d = 1 / Math.sqrt(x2 + y2);
  14860. this.z = 0;
  14861. this.x = y1 * d;
  14862. this.y = -x1 * d;
  14863. }
  14864. } else if(y2 < z2) {
  14865. d = 1 / Math.sqrt(z2 + x2);
  14866. this.y = 0;
  14867. this.z = x1 * d;
  14868. this.x = -z1 * d;
  14869. } else {
  14870. d = 1 / Math.sqrt(x2 + y2);
  14871. this.z = 0;
  14872. this.x = y1 * d;
  14873. this.y = -x1 * d;
  14874. }
  14875. return this;
  14876. }
  14877. d = 0.5 / this.w;
  14878. this.x = (y1 * z2 - z1 * y2) * d;
  14879. this.y = (z1 * x2 - x1 * z2) * d;
  14880. this.z = (x1 * y2 - y1 * x2) * d;
  14881. return this;
  14882. }
  14883. slerp(q,t) {
  14884. let qx;
  14885. let qy;
  14886. let qz;
  14887. let qw;
  14888. let d = this.x * q.x + this.y * q.y + this.z * q.z + this.w * q.w;
  14889. if(d < 0) {
  14890. d = -d;
  14891. qx = -q.x;
  14892. qy = -q.y;
  14893. qz = -q.z;
  14894. qw = -q.w;
  14895. } else {
  14896. qx = q.x;
  14897. qy = q.y;
  14898. qz = q.z;
  14899. qw = q.w;
  14900. }
  14901. if(d > 0.999999) {
  14902. let _this = new oimo.common.Quat(this.x + (qx - this.x) * t,this.y + (qy - this.y) * t,this.z + (qz - this.z) * t,this.w + (qw - this.w) * t);
  14903. let invLen = Math.sqrt(_this.x * _this.x + _this.y * _this.y + _this.z * _this.z + _this.w * _this.w);
  14904. if(invLen > 0) {
  14905. invLen = 1 / invLen;
  14906. }
  14907. _this.x *= invLen;
  14908. _this.y *= invLen;
  14909. _this.z *= invLen;
  14910. _this.w *= invLen;
  14911. return _this;
  14912. }
  14913. let theta = t * Math.acos(d);
  14914. qx -= this.x * d;
  14915. qy -= this.y * d;
  14916. qz -= this.z * d;
  14917. qw -= this.w * d;
  14918. let invLen = 1 / Math.sqrt(qx * qx + qy * qy + qz * qz + qw * qw);
  14919. qx *= invLen;
  14920. qy *= invLen;
  14921. qz *= invLen;
  14922. qw *= invLen;
  14923. let sin = Math.sin(theta);
  14924. let cos = Math.cos(theta);
  14925. return new oimo.common.Quat(this.x * cos + qx * sin,this.y * cos + qy * sin,this.z * cos + qz * sin,this.w * cos + qw * sin);
  14926. }
  14927. copyFrom(q) {
  14928. this.x = q.x;
  14929. this.y = q.y;
  14930. this.z = q.z;
  14931. this.w = q.w;
  14932. return this;
  14933. }
  14934. clone() {
  14935. return new oimo.common.Quat(this.x,this.y,this.z,this.w);
  14936. }
  14937. fromMat3(m) {
  14938. let e00 = m.e00;
  14939. let e11 = m.e11;
  14940. let e22 = m.e22;
  14941. let t = e00 + e11 + e22;
  14942. let s;
  14943. if(t > 0) {
  14944. s = Math.sqrt(t + 1);
  14945. this.w = 0.5 * s;
  14946. s = 0.5 / s;
  14947. this.x = (m.e21 - m.e12) * s;
  14948. this.y = (m.e02 - m.e20) * s;
  14949. this.z = (m.e10 - m.e01) * s;
  14950. } else if(e00 > e11) {
  14951. if(e00 > e22) {
  14952. s = Math.sqrt(e00 - e11 - e22 + 1);
  14953. this.x = 0.5 * s;
  14954. s = 0.5 / s;
  14955. this.y = (m.e01 + m.e10) * s;
  14956. this.z = (m.e02 + m.e20) * s;
  14957. this.w = (m.e21 - m.e12) * s;
  14958. } else {
  14959. s = Math.sqrt(e22 - e00 - e11 + 1);
  14960. this.z = 0.5 * s;
  14961. s = 0.5 / s;
  14962. this.x = (m.e02 + m.e20) * s;
  14963. this.y = (m.e12 + m.e21) * s;
  14964. this.w = (m.e10 - m.e01) * s;
  14965. }
  14966. } else if(e11 > e22) {
  14967. s = Math.sqrt(e11 - e22 - e00 + 1);
  14968. this.y = 0.5 * s;
  14969. s = 0.5 / s;
  14970. this.x = (m.e01 + m.e10) * s;
  14971. this.z = (m.e12 + m.e21) * s;
  14972. this.w = (m.e02 - m.e20) * s;
  14973. } else {
  14974. s = Math.sqrt(e22 - e00 - e11 + 1);
  14975. this.z = 0.5 * s;
  14976. s = 0.5 / s;
  14977. this.x = (m.e02 + m.e20) * s;
  14978. this.y = (m.e12 + m.e21) * s;
  14979. this.w = (m.e10 - m.e01) * s;
  14980. }
  14981. return this;
  14982. }
  14983. toMat3() {
  14984. let _this = new oimo.common.Mat3();
  14985. let x = this.x;
  14986. let y = this.y;
  14987. let z = this.z;
  14988. let w = this.w;
  14989. let x2 = 2 * x;
  14990. let y2 = 2 * y;
  14991. let z2 = 2 * z;
  14992. let xx = x * x2;
  14993. let yy = y * y2;
  14994. let zz = z * z2;
  14995. let xy = x * y2;
  14996. let yz = y * z2;
  14997. let xz = x * z2;
  14998. let wx = w * x2;
  14999. let wy = w * y2;
  15000. let wz = w * z2;
  15001. _this.e00 = 1 - yy - zz;
  15002. _this.e01 = xy - wz;
  15003. _this.e02 = xz + wy;
  15004. _this.e10 = xy + wz;
  15005. _this.e11 = 1 - xx - zz;
  15006. _this.e12 = yz - wx;
  15007. _this.e20 = xz - wy;
  15008. _this.e21 = yz + wx;
  15009. _this.e22 = 1 - xx - yy;
  15010. return _this;
  15011. }
  15012. toString() {
  15013. return "Quat[" + (this.x > 0 ? (this.x * 10000000 + 0.5 | 0) / 10000000 : (this.x * 10000000 - 0.5 | 0) / 10000000) + " i,\n" + " " + (this.y > 0 ? (this.y * 10000000 + 0.5 | 0) / 10000000 : (this.y * 10000000 - 0.5 | 0) / 10000000) + " j,\n" + " " + (this.z > 0 ? (this.z * 10000000 + 0.5 | 0) / 10000000 : (this.z * 10000000 - 0.5 | 0) / 10000000) + " k,\n" + " " + (this.w > 0 ? (this.w * 10000000 + 0.5 | 0) / 10000000 : (this.w * 10000000 - 0.5 | 0) / 10000000) + "]";
  15014. }
  15015. }
  15016. if(!oimo.dynamics) oimo.dynamics = {};
  15017. oimo.dynamics.Contact = class oimo_dynamics_Contact {
  15018. constructor() {
  15019. this._next = null;
  15020. this._prev = null;
  15021. this._link1 = new oimo.dynamics.ContactLink();
  15022. this._link2 = new oimo.dynamics.ContactLink();
  15023. this._s1 = null;
  15024. this._s2 = null;
  15025. this._b1 = null;
  15026. this._b2 = null;
  15027. this._detector = null;
  15028. this._cachedDetectorData = new oimo.collision.narrowphase.detector.CachedDetectorData();
  15029. this._detectorResult = new oimo.collision.narrowphase.DetectorResult();
  15030. this._latest = false;
  15031. this._shouldBeSkipped = false;
  15032. this._manifold = new oimo.dynamics.constraint.contact.Manifold();
  15033. this._updater = new oimo.dynamics.constraint.contact.ManifoldUpdater(this._manifold);
  15034. this._contactConstraint = new oimo.dynamics.constraint.contact.ContactConstraint(this._manifold);
  15035. this._touching = false;
  15036. }
  15037. _updateManifold() {
  15038. if(this._detector == null) {
  15039. return;
  15040. }
  15041. let ptouching = this._touching;
  15042. let result = this._detectorResult;
  15043. this._detector.detect(result,this._s1._geom,this._s2._geom,this._s1._transform,this._s2._transform,this._cachedDetectorData);
  15044. this._touching = result.numPoints > 0;
  15045. if(this._touching) {
  15046. this._manifold._buildBasis(result.normal);
  15047. if(result.getMaxDepth() > oimo.common.Setting.contactUseAlternativePositionCorrectionAlgorithmDepthThreshold) {
  15048. this._contactConstraint._positionCorrectionAlgorithm = oimo.common.Setting.alternativeContactPositionCorrectionAlgorithm;
  15049. } else {
  15050. this._contactConstraint._positionCorrectionAlgorithm = oimo.common.Setting.defaultContactPositionCorrectionAlgorithm;
  15051. }
  15052. if(result.incremental) {
  15053. this._updater.incrementalUpdate(result,this._b1._transform,this._b2._transform);
  15054. } else {
  15055. this._updater.totalUpdate(result,this._b1._transform,this._b2._transform);
  15056. }
  15057. } else {
  15058. this._manifold._clear();
  15059. }
  15060. if(this._touching && !ptouching) {
  15061. let cc1 = this._s1._contactCallback;
  15062. let cc2 = this._s2._contactCallback;
  15063. if(cc1 == cc2) {
  15064. cc2 = null;
  15065. }
  15066. if(cc1 != null) {
  15067. cc1.beginContact(this);
  15068. }
  15069. if(cc2 != null) {
  15070. cc2.beginContact(this);
  15071. }
  15072. }
  15073. if(!this._touching && ptouching) {
  15074. let cc1 = this._s1._contactCallback;
  15075. let cc2 = this._s2._contactCallback;
  15076. if(cc1 == cc2) {
  15077. cc2 = null;
  15078. }
  15079. if(cc1 != null) {
  15080. cc1.endContact(this);
  15081. }
  15082. if(cc2 != null) {
  15083. cc2.endContact(this);
  15084. }
  15085. }
  15086. if(this._touching) {
  15087. let cc1 = this._s1._contactCallback;
  15088. let cc2 = this._s2._contactCallback;
  15089. if(cc1 == cc2) {
  15090. cc2 = null;
  15091. }
  15092. if(cc1 != null) {
  15093. cc1.preSolve(this);
  15094. }
  15095. if(cc2 != null) {
  15096. cc2.preSolve(this);
  15097. }
  15098. }
  15099. }
  15100. _postSolve() {
  15101. let cc1 = this._s1._contactCallback;
  15102. let cc2 = this._s2._contactCallback;
  15103. if(cc1 == cc2) {
  15104. cc2 = null;
  15105. }
  15106. if(cc1 != null) {
  15107. cc1.postSolve(this);
  15108. }
  15109. if(cc2 != null) {
  15110. cc2.postSolve(this);
  15111. }
  15112. }
  15113. getShape1() {
  15114. return this._s1;
  15115. }
  15116. getShape2() {
  15117. return this._s2;
  15118. }
  15119. isTouching() {
  15120. return this._touching;
  15121. }
  15122. getManifold() {
  15123. return this._manifold;
  15124. }
  15125. getContactConstraint() {
  15126. return this._contactConstraint;
  15127. }
  15128. getPrev() {
  15129. return this._prev;
  15130. }
  15131. getNext() {
  15132. return this._next;
  15133. }
  15134. }
  15135. oimo.dynamics.ContactLink = class oimo_dynamics_ContactLink {
  15136. constructor() {
  15137. this._prev = null;
  15138. this._next = null;
  15139. this._contact = null;
  15140. this._other = null;
  15141. }
  15142. getContact() {
  15143. return this._contact;
  15144. }
  15145. getOther() {
  15146. return this._other;
  15147. }
  15148. getPrev() {
  15149. return this._prev;
  15150. }
  15151. getNext() {
  15152. return this._next;
  15153. }
  15154. }
  15155. oimo.dynamics.ContactManager = class oimo_dynamics_ContactManager {
  15156. constructor(broadPhase) {
  15157. this._broadPhase = broadPhase;
  15158. this._collisionMatrix = new oimo.collision.narrowphase.CollisionMatrix();
  15159. this._numContacts = 0;
  15160. }
  15161. createContacts() {
  15162. let pp = this._broadPhase._proxyPairList;
  15163. while(pp != null) {
  15164. let n = pp._next;
  15165. while(true) {
  15166. let s1;
  15167. let s2;
  15168. if(pp._p1._id < pp._p2._id) {
  15169. s1 = pp._p1.userData;
  15170. s2 = pp._p2.userData;
  15171. } else {
  15172. s1 = pp._p2.userData;
  15173. s2 = pp._p1.userData;
  15174. }
  15175. if(!this.shouldCollide(s1,s2)) {
  15176. break;
  15177. }
  15178. let b1 = s1._rigidBody;
  15179. let b2 = s2._rigidBody;
  15180. let l;
  15181. if(b1._numContactLinks < b2._numContactLinks) {
  15182. l = b1._contactLinkList;
  15183. } else {
  15184. l = b2._contactLinkList;
  15185. }
  15186. let id1 = s1._id;
  15187. let id2 = s2._id;
  15188. let found = false;
  15189. while(l != null) {
  15190. let c = l._contact;
  15191. if(c._s1._id == id1 && c._s2._id == id2) {
  15192. c._latest = true;
  15193. found = true;
  15194. break;
  15195. }
  15196. l = l._next;
  15197. }
  15198. if(!found) {
  15199. let first = this._contactPool;
  15200. if(first != null) {
  15201. this._contactPool = first._next;
  15202. first._next = null;
  15203. } else {
  15204. first = new oimo.dynamics.Contact();
  15205. }
  15206. let c = first;
  15207. if(this._contactList == null) {
  15208. this._contactList = c;
  15209. this._contactListLast = c;
  15210. } else {
  15211. this._contactListLast._next = c;
  15212. c._prev = this._contactListLast;
  15213. this._contactListLast = c;
  15214. }
  15215. c._latest = true;
  15216. let detector = this._collisionMatrix.detectors[s1._geom._type][s2._geom._type];
  15217. c._s1 = s1;
  15218. c._s2 = s2;
  15219. c._b1 = s1._rigidBody;
  15220. c._b2 = s2._rigidBody;
  15221. c._touching = false;
  15222. if(c._b1._contactLinkList == null) {
  15223. c._b1._contactLinkList = c._link1;
  15224. c._b1._contactLinkListLast = c._link1;
  15225. } else {
  15226. c._b1._contactLinkListLast._next = c._link1;
  15227. c._link1._prev = c._b1._contactLinkListLast;
  15228. c._b1._contactLinkListLast = c._link1;
  15229. }
  15230. if(c._b2._contactLinkList == null) {
  15231. c._b2._contactLinkList = c._link2;
  15232. c._b2._contactLinkListLast = c._link2;
  15233. } else {
  15234. c._b2._contactLinkListLast._next = c._link2;
  15235. c._link2._prev = c._b2._contactLinkListLast;
  15236. c._b2._contactLinkListLast = c._link2;
  15237. }
  15238. c._b1._numContactLinks++;
  15239. c._b2._numContactLinks++;
  15240. c._link1._other = c._b2;
  15241. c._link2._other = c._b1;
  15242. c._link1._contact = c;
  15243. c._link2._contact = c;
  15244. c._detector = detector;
  15245. let _this = c._contactConstraint;
  15246. _this._s1 = s1;
  15247. _this._s2 = s2;
  15248. _this._b1 = _this._s1._rigidBody;
  15249. _this._b2 = _this._s2._rigidBody;
  15250. _this._tf1 = _this._b1._transform;
  15251. _this._tf2 = _this._b2._transform;
  15252. this._numContacts++;
  15253. }
  15254. break;
  15255. }
  15256. pp = n;
  15257. }
  15258. }
  15259. destroyOutdatedContacts() {
  15260. let incremental = this._broadPhase._incremental;
  15261. let c = this._contactList;
  15262. while(c != null) {
  15263. let n = c._next;
  15264. while(true) {
  15265. if(c._latest) {
  15266. c._latest = false;
  15267. c._shouldBeSkipped = false;
  15268. break;
  15269. }
  15270. if(!incremental) {
  15271. let prev = c._prev;
  15272. let next = c._next;
  15273. if(prev != null) {
  15274. prev._next = next;
  15275. }
  15276. if(next != null) {
  15277. next._prev = prev;
  15278. }
  15279. if(c == this._contactList) {
  15280. this._contactList = this._contactList._next;
  15281. }
  15282. if(c == this._contactListLast) {
  15283. this._contactListLast = this._contactListLast._prev;
  15284. }
  15285. c._next = null;
  15286. c._prev = null;
  15287. if(c._touching) {
  15288. let cc1 = c._s1._contactCallback;
  15289. let cc2 = c._s2._contactCallback;
  15290. if(cc1 == cc2) {
  15291. cc2 = null;
  15292. }
  15293. if(cc1 != null) {
  15294. cc1.endContact(c);
  15295. }
  15296. if(cc2 != null) {
  15297. cc2.endContact(c);
  15298. }
  15299. }
  15300. let prev1 = c._link1._prev;
  15301. let next1 = c._link1._next;
  15302. if(prev1 != null) {
  15303. prev1._next = next1;
  15304. }
  15305. if(next1 != null) {
  15306. next1._prev = prev1;
  15307. }
  15308. if(c._link1 == c._b1._contactLinkList) {
  15309. c._b1._contactLinkList = c._b1._contactLinkList._next;
  15310. }
  15311. if(c._link1 == c._b1._contactLinkListLast) {
  15312. c._b1._contactLinkListLast = c._b1._contactLinkListLast._prev;
  15313. }
  15314. c._link1._next = null;
  15315. c._link1._prev = null;
  15316. let prev2 = c._link2._prev;
  15317. let next2 = c._link2._next;
  15318. if(prev2 != null) {
  15319. prev2._next = next2;
  15320. }
  15321. if(next2 != null) {
  15322. next2._prev = prev2;
  15323. }
  15324. if(c._link2 == c._b2._contactLinkList) {
  15325. c._b2._contactLinkList = c._b2._contactLinkList._next;
  15326. }
  15327. if(c._link2 == c._b2._contactLinkListLast) {
  15328. c._b2._contactLinkListLast = c._b2._contactLinkListLast._prev;
  15329. }
  15330. c._link2._next = null;
  15331. c._link2._prev = null;
  15332. c._b1._numContactLinks--;
  15333. c._b2._numContactLinks--;
  15334. c._link1._other = null;
  15335. c._link2._other = null;
  15336. c._link1._contact = null;
  15337. c._link2._contact = null;
  15338. c._s1 = null;
  15339. c._s2 = null;
  15340. c._b1 = null;
  15341. c._b2 = null;
  15342. c._touching = false;
  15343. c._cachedDetectorData._clear();
  15344. c._manifold._clear();
  15345. c._detector = null;
  15346. let _this = c._contactConstraint;
  15347. _this._s1 = null;
  15348. _this._s2 = null;
  15349. _this._b1 = null;
  15350. _this._b2 = null;
  15351. _this._tf1 = null;
  15352. _this._tf2 = null;
  15353. c._next = this._contactPool;
  15354. this._contactPool = c;
  15355. this._numContacts--;
  15356. break;
  15357. }
  15358. let s1 = c._s1;
  15359. let s2 = c._s2;
  15360. let r1 = s1._rigidBody;
  15361. let r2 = s2._rigidBody;
  15362. if(!(!r1._sleeping && r1._type != 1) && !(!r2._sleeping && r2._type != 1)) {
  15363. c._shouldBeSkipped = true;
  15364. break;
  15365. }
  15366. let aabb1 = s1._aabb;
  15367. let aabb2 = s2._aabb;
  15368. let proxy1 = s1._proxy;
  15369. let proxy2 = s2._proxy;
  15370. if(!(proxy1._aabbMinX < proxy2._aabbMaxX && proxy1._aabbMaxX > proxy2._aabbMinX && proxy1._aabbMinY < proxy2._aabbMaxY && proxy1._aabbMaxY > proxy2._aabbMinY && proxy1._aabbMinZ < proxy2._aabbMaxZ && proxy1._aabbMaxZ > proxy2._aabbMinZ) || !this.shouldCollide(s1,s2)) {
  15371. let prev = c._prev;
  15372. let next = c._next;
  15373. if(prev != null) {
  15374. prev._next = next;
  15375. }
  15376. if(next != null) {
  15377. next._prev = prev;
  15378. }
  15379. if(c == this._contactList) {
  15380. this._contactList = this._contactList._next;
  15381. }
  15382. if(c == this._contactListLast) {
  15383. this._contactListLast = this._contactListLast._prev;
  15384. }
  15385. c._next = null;
  15386. c._prev = null;
  15387. if(c._touching) {
  15388. let cc1 = c._s1._contactCallback;
  15389. let cc2 = c._s2._contactCallback;
  15390. if(cc1 == cc2) {
  15391. cc2 = null;
  15392. }
  15393. if(cc1 != null) {
  15394. cc1.endContact(c);
  15395. }
  15396. if(cc2 != null) {
  15397. cc2.endContact(c);
  15398. }
  15399. }
  15400. let prev1 = c._link1._prev;
  15401. let next1 = c._link1._next;
  15402. if(prev1 != null) {
  15403. prev1._next = next1;
  15404. }
  15405. if(next1 != null) {
  15406. next1._prev = prev1;
  15407. }
  15408. if(c._link1 == c._b1._contactLinkList) {
  15409. c._b1._contactLinkList = c._b1._contactLinkList._next;
  15410. }
  15411. if(c._link1 == c._b1._contactLinkListLast) {
  15412. c._b1._contactLinkListLast = c._b1._contactLinkListLast._prev;
  15413. }
  15414. c._link1._next = null;
  15415. c._link1._prev = null;
  15416. let prev2 = c._link2._prev;
  15417. let next2 = c._link2._next;
  15418. if(prev2 != null) {
  15419. prev2._next = next2;
  15420. }
  15421. if(next2 != null) {
  15422. next2._prev = prev2;
  15423. }
  15424. if(c._link2 == c._b2._contactLinkList) {
  15425. c._b2._contactLinkList = c._b2._contactLinkList._next;
  15426. }
  15427. if(c._link2 == c._b2._contactLinkListLast) {
  15428. c._b2._contactLinkListLast = c._b2._contactLinkListLast._prev;
  15429. }
  15430. c._link2._next = null;
  15431. c._link2._prev = null;
  15432. c._b1._numContactLinks--;
  15433. c._b2._numContactLinks--;
  15434. c._link1._other = null;
  15435. c._link2._other = null;
  15436. c._link1._contact = null;
  15437. c._link2._contact = null;
  15438. c._s1 = null;
  15439. c._s2 = null;
  15440. c._b1 = null;
  15441. c._b2 = null;
  15442. c._touching = false;
  15443. c._cachedDetectorData._clear();
  15444. c._manifold._clear();
  15445. c._detector = null;
  15446. let _this = c._contactConstraint;
  15447. _this._s1 = null;
  15448. _this._s2 = null;
  15449. _this._b1 = null;
  15450. _this._b2 = null;
  15451. _this._tf1 = null;
  15452. _this._tf2 = null;
  15453. c._next = this._contactPool;
  15454. this._contactPool = c;
  15455. this._numContacts--;
  15456. break;
  15457. }
  15458. c._shouldBeSkipped = !(aabb1._minX < aabb2._maxX && aabb1._maxX > aabb2._minX && aabb1._minY < aabb2._maxY && aabb1._maxY > aabb2._minY && aabb1._minZ < aabb2._maxZ && aabb1._maxZ > aabb2._minZ);
  15459. break;
  15460. }
  15461. c = n;
  15462. }
  15463. }
  15464. shouldCollide(s1,s2) {
  15465. let r1 = s1._rigidBody;
  15466. let r2 = s2._rigidBody;
  15467. if(r1 == r2) {
  15468. return false;
  15469. }
  15470. if(r1._type != 0 && r2._type != 0) {
  15471. return false;
  15472. }
  15473. if((s1._collisionGroup & s2._collisionMask) == 0 || (s2._collisionGroup & s1._collisionMask) == 0) {
  15474. return false;
  15475. }
  15476. let jl;
  15477. let other;
  15478. if(r1._numJointLinks < r2._numJointLinks) {
  15479. jl = r1._jointLinkList;
  15480. other = r2;
  15481. } else {
  15482. jl = r2._jointLinkList;
  15483. other = r1;
  15484. }
  15485. while(jl != null) {
  15486. if(jl._other == other && !jl._joint._allowCollision) {
  15487. return false;
  15488. }
  15489. jl = jl._next;
  15490. }
  15491. return true;
  15492. }
  15493. _updateContacts() {
  15494. this._broadPhase.collectPairs();
  15495. this.createContacts();
  15496. this.destroyOutdatedContacts();
  15497. }
  15498. _postSolve() {
  15499. let c = this._contactList;
  15500. while(c != null) {
  15501. let n = c._next;
  15502. if(c._touching) {
  15503. c._postSolve();
  15504. }
  15505. c = n;
  15506. }
  15507. }
  15508. getNumContacts() {
  15509. return this._numContacts;
  15510. }
  15511. getContactList() {
  15512. return this._contactList;
  15513. }
  15514. }
  15515. oimo.dynamics.Island = class oimo_dynamics_Island {
  15516. constructor() {
  15517. this.rigidBodies = new Array(oimo.common.Setting.islandInitialRigidBodyArraySize);
  15518. this.solvers = new Array(oimo.common.Setting.islandInitialConstraintArraySize);
  15519. this.solversSi = new Array(oimo.common.Setting.islandInitialConstraintArraySize);
  15520. this.solversNgs = new Array(oimo.common.Setting.islandInitialConstraintArraySize);
  15521. this.numRigidBodies = 0;
  15522. this.numSolvers = 0;
  15523. this.numSolversSi = 0;
  15524. this.numSolversNgs = 0;
  15525. }
  15526. _clear() {
  15527. while(this.numRigidBodies > 0) this.rigidBodies[--this.numRigidBodies] = null;
  15528. while(this.numSolvers > 0) this.solvers[--this.numSolvers] = null;
  15529. while(this.numSolversSi > 0) this.solversSi[--this.numSolversSi] = null;
  15530. while(this.numSolversNgs > 0) this.solversNgs[--this.numSolversNgs] = null;
  15531. }
  15532. _addRigidBody(rigidBody) {
  15533. if(this.numRigidBodies == this.rigidBodies.length) {
  15534. let newArray = new Array(this.numRigidBodies << 1);
  15535. let _g = 0;
  15536. let _g1 = this.numRigidBodies;
  15537. while(_g < _g1) {
  15538. let i = _g++;
  15539. newArray[i] = this.rigidBodies[i];
  15540. this.rigidBodies[i] = null;
  15541. }
  15542. this.rigidBodies = newArray;
  15543. }
  15544. rigidBody._addedToIsland = true;
  15545. this.rigidBodies[this.numRigidBodies++] = rigidBody;
  15546. }
  15547. _addConstraintSolver(solver,positionCorrection) {
  15548. if(this.numSolvers == this.solvers.length) {
  15549. let newArray = new Array(this.numSolvers << 1);
  15550. let _g = 0;
  15551. let _g1 = this.numSolvers;
  15552. while(_g < _g1) {
  15553. let i = _g++;
  15554. newArray[i] = this.solvers[i];
  15555. this.solvers[i] = null;
  15556. }
  15557. this.solvers = newArray;
  15558. }
  15559. solver._addedToIsland = true;
  15560. this.solvers[this.numSolvers++] = solver;
  15561. if(positionCorrection == oimo.dynamics.constraint.PositionCorrectionAlgorithm.SPLIT_IMPULSE) {
  15562. if(this.numSolversSi == this.solversSi.length) {
  15563. let newArray = new Array(this.numSolversSi << 1);
  15564. let _g = 0;
  15565. let _g1 = this.numSolversSi;
  15566. while(_g < _g1) {
  15567. let i = _g++;
  15568. newArray[i] = this.solversSi[i];
  15569. this.solversSi[i] = null;
  15570. }
  15571. this.solversSi = newArray;
  15572. }
  15573. this.solversSi[this.numSolversSi++] = solver;
  15574. }
  15575. if(positionCorrection == oimo.dynamics.constraint.PositionCorrectionAlgorithm.NGS) {
  15576. if(this.numSolversNgs == this.solversNgs.length) {
  15577. let newArray = new Array(this.numSolversNgs << 1);
  15578. let _g = 0;
  15579. let _g1 = this.numSolversNgs;
  15580. while(_g < _g1) {
  15581. let i = _g++;
  15582. newArray[i] = this.solversNgs[i];
  15583. this.solversNgs[i] = null;
  15584. }
  15585. this.solversNgs = newArray;
  15586. }
  15587. this.solversNgs[this.numSolversNgs++] = solver;
  15588. }
  15589. }
  15590. _stepSingleRigidBody(timeStep,rb) {
  15591. let dt = timeStep.dt;
  15592. let dst = rb._ptransform;
  15593. let src = rb._transform;
  15594. dst._positionX = src._positionX;
  15595. dst._positionY = src._positionY;
  15596. dst._positionZ = src._positionZ;
  15597. dst._rotation00 = src._rotation00;
  15598. dst._rotation01 = src._rotation01;
  15599. dst._rotation02 = src._rotation02;
  15600. dst._rotation10 = src._rotation10;
  15601. dst._rotation11 = src._rotation11;
  15602. dst._rotation12 = src._rotation12;
  15603. dst._rotation20 = src._rotation20;
  15604. dst._rotation21 = src._rotation21;
  15605. dst._rotation22 = src._rotation22;
  15606. rb._linearContactImpulseX = 0;
  15607. rb._linearContactImpulseY = 0;
  15608. rb._linearContactImpulseZ = 0;
  15609. rb._angularContactImpulseX = 0;
  15610. rb._angularContactImpulseY = 0;
  15611. rb._angularContactImpulseZ = 0;
  15612. if(rb._autoSleep && rb._velX * rb._velX + rb._velY * rb._velY + rb._velZ * rb._velZ < oimo.common.Setting.sleepingVelocityThreshold * oimo.common.Setting.sleepingVelocityThreshold && rb._angVelX * rb._angVelX + rb._angVelY * rb._angVelY + rb._angVelZ * rb._angVelZ < oimo.common.Setting.sleepingAngularVelocityThreshold * oimo.common.Setting.sleepingAngularVelocityThreshold) {
  15613. rb._sleepTime += dt;
  15614. if(rb._sleepTime > oimo.common.Setting.sleepingTimeThreshold) {
  15615. rb._sleeping = true;
  15616. rb._sleepTime = 0;
  15617. }
  15618. } else {
  15619. rb._sleepTime = 0;
  15620. }
  15621. if(!rb._sleeping) {
  15622. if(rb._type == 0) {
  15623. let x = dt * rb._linearDamping;
  15624. let x2 = x * x;
  15625. let linScale = 1 / (1 + x + x2 * (0.5 + x * 0.16666666666666666 + x2 * 0.041666666666666664));
  15626. let x1 = dt * rb._angularDamping;
  15627. let x21 = x1 * x1;
  15628. let angScale = 1 / (1 + x1 + x21 * (0.5 + x1 * 0.16666666666666666 + x21 * 0.041666666666666664));
  15629. let linAccX;
  15630. let linAccY;
  15631. let linAccZ;
  15632. let angAccX;
  15633. let angAccY;
  15634. let angAccZ;
  15635. linAccX = this.gravityX * rb._gravityScale;
  15636. linAccY = this.gravityY * rb._gravityScale;
  15637. linAccZ = this.gravityZ * rb._gravityScale;
  15638. linAccX += rb._forceX * rb._invMass;
  15639. linAccY += rb._forceY * rb._invMass;
  15640. linAccZ += rb._forceZ * rb._invMass;
  15641. let __tmp__X;
  15642. let __tmp__Y;
  15643. let __tmp__Z;
  15644. __tmp__X = rb._invInertia00 * rb._torqueX + rb._invInertia01 * rb._torqueY + rb._invInertia02 * rb._torqueZ;
  15645. __tmp__Y = rb._invInertia10 * rb._torqueX + rb._invInertia11 * rb._torqueY + rb._invInertia12 * rb._torqueZ;
  15646. __tmp__Z = rb._invInertia20 * rb._torqueX + rb._invInertia21 * rb._torqueY + rb._invInertia22 * rb._torqueZ;
  15647. angAccX = __tmp__X;
  15648. angAccY = __tmp__Y;
  15649. angAccZ = __tmp__Z;
  15650. rb._velX += linAccX * dt;
  15651. rb._velY += linAccY * dt;
  15652. rb._velZ += linAccZ * dt;
  15653. rb._velX *= linScale;
  15654. rb._velY *= linScale;
  15655. rb._velZ *= linScale;
  15656. rb._angVelX += angAccX * dt;
  15657. rb._angVelY += angAccY * dt;
  15658. rb._angVelZ += angAccZ * dt;
  15659. rb._angVelX *= angScale;
  15660. rb._angVelY *= angScale;
  15661. rb._angVelZ *= angScale;
  15662. }
  15663. rb._integrate(dt);
  15664. let s = rb._shapeList;
  15665. while(s != null) {
  15666. let n = s._next;
  15667. let tf1 = rb._ptransform;
  15668. let tf2 = rb._transform;
  15669. let dst = s._ptransform;
  15670. let src1 = s._localTransform;
  15671. let __tmp__00;
  15672. let __tmp__01;
  15673. let __tmp__02;
  15674. let __tmp__10;
  15675. let __tmp__11;
  15676. let __tmp__12;
  15677. let __tmp__20;
  15678. let __tmp__21;
  15679. let __tmp__22;
  15680. __tmp__00 = tf1._rotation00 * src1._rotation00 + tf1._rotation01 * src1._rotation10 + tf1._rotation02 * src1._rotation20;
  15681. __tmp__01 = tf1._rotation00 * src1._rotation01 + tf1._rotation01 * src1._rotation11 + tf1._rotation02 * src1._rotation21;
  15682. __tmp__02 = tf1._rotation00 * src1._rotation02 + tf1._rotation01 * src1._rotation12 + tf1._rotation02 * src1._rotation22;
  15683. __tmp__10 = tf1._rotation10 * src1._rotation00 + tf1._rotation11 * src1._rotation10 + tf1._rotation12 * src1._rotation20;
  15684. __tmp__11 = tf1._rotation10 * src1._rotation01 + tf1._rotation11 * src1._rotation11 + tf1._rotation12 * src1._rotation21;
  15685. __tmp__12 = tf1._rotation10 * src1._rotation02 + tf1._rotation11 * src1._rotation12 + tf1._rotation12 * src1._rotation22;
  15686. __tmp__20 = tf1._rotation20 * src1._rotation00 + tf1._rotation21 * src1._rotation10 + tf1._rotation22 * src1._rotation20;
  15687. __tmp__21 = tf1._rotation20 * src1._rotation01 + tf1._rotation21 * src1._rotation11 + tf1._rotation22 * src1._rotation21;
  15688. __tmp__22 = tf1._rotation20 * src1._rotation02 + tf1._rotation21 * src1._rotation12 + tf1._rotation22 * src1._rotation22;
  15689. dst._rotation00 = __tmp__00;
  15690. dst._rotation01 = __tmp__01;
  15691. dst._rotation02 = __tmp__02;
  15692. dst._rotation10 = __tmp__10;
  15693. dst._rotation11 = __tmp__11;
  15694. dst._rotation12 = __tmp__12;
  15695. dst._rotation20 = __tmp__20;
  15696. dst._rotation21 = __tmp__21;
  15697. dst._rotation22 = __tmp__22;
  15698. let __tmp__X;
  15699. let __tmp__Y;
  15700. let __tmp__Z;
  15701. __tmp__X = tf1._rotation00 * src1._positionX + tf1._rotation01 * src1._positionY + tf1._rotation02 * src1._positionZ;
  15702. __tmp__Y = tf1._rotation10 * src1._positionX + tf1._rotation11 * src1._positionY + tf1._rotation12 * src1._positionZ;
  15703. __tmp__Z = tf1._rotation20 * src1._positionX + tf1._rotation21 * src1._positionY + tf1._rotation22 * src1._positionZ;
  15704. dst._positionX = __tmp__X;
  15705. dst._positionY = __tmp__Y;
  15706. dst._positionZ = __tmp__Z;
  15707. dst._positionX += tf1._positionX;
  15708. dst._positionY += tf1._positionY;
  15709. dst._positionZ += tf1._positionZ;
  15710. let dst1 = s._transform;
  15711. let src11 = s._localTransform;
  15712. let __tmp__001;
  15713. let __tmp__011;
  15714. let __tmp__021;
  15715. let __tmp__101;
  15716. let __tmp__111;
  15717. let __tmp__121;
  15718. let __tmp__201;
  15719. let __tmp__211;
  15720. let __tmp__221;
  15721. __tmp__001 = tf2._rotation00 * src11._rotation00 + tf2._rotation01 * src11._rotation10 + tf2._rotation02 * src11._rotation20;
  15722. __tmp__011 = tf2._rotation00 * src11._rotation01 + tf2._rotation01 * src11._rotation11 + tf2._rotation02 * src11._rotation21;
  15723. __tmp__021 = tf2._rotation00 * src11._rotation02 + tf2._rotation01 * src11._rotation12 + tf2._rotation02 * src11._rotation22;
  15724. __tmp__101 = tf2._rotation10 * src11._rotation00 + tf2._rotation11 * src11._rotation10 + tf2._rotation12 * src11._rotation20;
  15725. __tmp__111 = tf2._rotation10 * src11._rotation01 + tf2._rotation11 * src11._rotation11 + tf2._rotation12 * src11._rotation21;
  15726. __tmp__121 = tf2._rotation10 * src11._rotation02 + tf2._rotation11 * src11._rotation12 + tf2._rotation12 * src11._rotation22;
  15727. __tmp__201 = tf2._rotation20 * src11._rotation00 + tf2._rotation21 * src11._rotation10 + tf2._rotation22 * src11._rotation20;
  15728. __tmp__211 = tf2._rotation20 * src11._rotation01 + tf2._rotation21 * src11._rotation11 + tf2._rotation22 * src11._rotation21;
  15729. __tmp__221 = tf2._rotation20 * src11._rotation02 + tf2._rotation21 * src11._rotation12 + tf2._rotation22 * src11._rotation22;
  15730. dst1._rotation00 = __tmp__001;
  15731. dst1._rotation01 = __tmp__011;
  15732. dst1._rotation02 = __tmp__021;
  15733. dst1._rotation10 = __tmp__101;
  15734. dst1._rotation11 = __tmp__111;
  15735. dst1._rotation12 = __tmp__121;
  15736. dst1._rotation20 = __tmp__201;
  15737. dst1._rotation21 = __tmp__211;
  15738. dst1._rotation22 = __tmp__221;
  15739. let __tmp__X1;
  15740. let __tmp__Y1;
  15741. let __tmp__Z1;
  15742. __tmp__X1 = tf2._rotation00 * src11._positionX + tf2._rotation01 * src11._positionY + tf2._rotation02 * src11._positionZ;
  15743. __tmp__Y1 = tf2._rotation10 * src11._positionX + tf2._rotation11 * src11._positionY + tf2._rotation12 * src11._positionZ;
  15744. __tmp__Z1 = tf2._rotation20 * src11._positionX + tf2._rotation21 * src11._positionY + tf2._rotation22 * src11._positionZ;
  15745. dst1._positionX = __tmp__X1;
  15746. dst1._positionY = __tmp__Y1;
  15747. dst1._positionZ = __tmp__Z1;
  15748. dst1._positionX += tf2._positionX;
  15749. dst1._positionY += tf2._positionY;
  15750. dst1._positionZ += tf2._positionZ;
  15751. let minX;
  15752. let minY;
  15753. let minZ;
  15754. let maxX;
  15755. let maxY;
  15756. let maxZ;
  15757. s._geom._computeAabb(s._aabb,s._ptransform);
  15758. minX = s._aabb._minX;
  15759. minY = s._aabb._minY;
  15760. minZ = s._aabb._minZ;
  15761. maxX = s._aabb._maxX;
  15762. maxY = s._aabb._maxY;
  15763. maxZ = s._aabb._maxZ;
  15764. s._geom._computeAabb(s._aabb,s._transform);
  15765. s._aabb._minX = minX < s._aabb._minX ? minX : s._aabb._minX;
  15766. s._aabb._minY = minY < s._aabb._minY ? minY : s._aabb._minY;
  15767. s._aabb._minZ = minZ < s._aabb._minZ ? minZ : s._aabb._minZ;
  15768. s._aabb._maxX = maxX > s._aabb._maxX ? maxX : s._aabb._maxX;
  15769. s._aabb._maxY = maxY > s._aabb._maxY ? maxY : s._aabb._maxY;
  15770. s._aabb._maxZ = maxZ > s._aabb._maxZ ? maxZ : s._aabb._maxZ;
  15771. if(s._proxy != null) {
  15772. let dX;
  15773. let dY;
  15774. let dZ;
  15775. dX = s._transform._positionX - s._ptransform._positionX;
  15776. dY = s._transform._positionY - s._ptransform._positionY;
  15777. dZ = s._transform._positionZ - s._ptransform._positionZ;
  15778. let v = s.displacement;
  15779. v.x = dX;
  15780. v.y = dY;
  15781. v.z = dZ;
  15782. s._rigidBody._world._broadPhase.moveProxy(s._proxy,s._aabb,s.displacement);
  15783. }
  15784. s = n;
  15785. }
  15786. }
  15787. }
  15788. _step(timeStep,numVelocityIterations,numPositionIterations) {
  15789. let dt = timeStep.dt;
  15790. let sleepIsland = true;
  15791. let _g = 0;
  15792. let _g1 = this.numRigidBodies;
  15793. while(_g < _g1) {
  15794. let rb = this.rigidBodies[_g++];
  15795. let dst = rb._ptransform;
  15796. let src = rb._transform;
  15797. dst._positionX = src._positionX;
  15798. dst._positionY = src._positionY;
  15799. dst._positionZ = src._positionZ;
  15800. dst._rotation00 = src._rotation00;
  15801. dst._rotation01 = src._rotation01;
  15802. dst._rotation02 = src._rotation02;
  15803. dst._rotation10 = src._rotation10;
  15804. dst._rotation11 = src._rotation11;
  15805. dst._rotation12 = src._rotation12;
  15806. dst._rotation20 = src._rotation20;
  15807. dst._rotation21 = src._rotation21;
  15808. dst._rotation22 = src._rotation22;
  15809. rb._linearContactImpulseX = 0;
  15810. rb._linearContactImpulseY = 0;
  15811. rb._linearContactImpulseZ = 0;
  15812. rb._angularContactImpulseX = 0;
  15813. rb._angularContactImpulseY = 0;
  15814. rb._angularContactImpulseZ = 0;
  15815. rb._sleeping = false;
  15816. if(rb._autoSleep && rb._velX * rb._velX + rb._velY * rb._velY + rb._velZ * rb._velZ < oimo.common.Setting.sleepingVelocityThreshold * oimo.common.Setting.sleepingVelocityThreshold && rb._angVelX * rb._angVelX + rb._angVelY * rb._angVelY + rb._angVelZ * rb._angVelZ < oimo.common.Setting.sleepingAngularVelocityThreshold * oimo.common.Setting.sleepingAngularVelocityThreshold) {
  15817. rb._sleepTime += dt;
  15818. } else {
  15819. rb._sleepTime = 0;
  15820. }
  15821. if(rb._sleepTime < oimo.common.Setting.sleepingTimeThreshold) {
  15822. sleepIsland = false;
  15823. }
  15824. if(rb._type == 0) {
  15825. let x = dt * rb._linearDamping;
  15826. let x2 = x * x;
  15827. let linScale = 1 / (1 + x + x2 * (0.5 + x * 0.16666666666666666 + x2 * 0.041666666666666664));
  15828. let x1 = dt * rb._angularDamping;
  15829. let x21 = x1 * x1;
  15830. let angScale = 1 / (1 + x1 + x21 * (0.5 + x1 * 0.16666666666666666 + x21 * 0.041666666666666664));
  15831. let linAccX;
  15832. let linAccY;
  15833. let linAccZ;
  15834. let angAccX;
  15835. let angAccY;
  15836. let angAccZ;
  15837. linAccX = this.gravityX * rb._gravityScale;
  15838. linAccY = this.gravityY * rb._gravityScale;
  15839. linAccZ = this.gravityZ * rb._gravityScale;
  15840. linAccX += rb._forceX * rb._invMass;
  15841. linAccY += rb._forceY * rb._invMass;
  15842. linAccZ += rb._forceZ * rb._invMass;
  15843. let __tmp__X;
  15844. let __tmp__Y;
  15845. let __tmp__Z;
  15846. __tmp__X = rb._invInertia00 * rb._torqueX + rb._invInertia01 * rb._torqueY + rb._invInertia02 * rb._torqueZ;
  15847. __tmp__Y = rb._invInertia10 * rb._torqueX + rb._invInertia11 * rb._torqueY + rb._invInertia12 * rb._torqueZ;
  15848. __tmp__Z = rb._invInertia20 * rb._torqueX + rb._invInertia21 * rb._torqueY + rb._invInertia22 * rb._torqueZ;
  15849. angAccX = __tmp__X;
  15850. angAccY = __tmp__Y;
  15851. angAccZ = __tmp__Z;
  15852. rb._velX += linAccX * dt;
  15853. rb._velY += linAccY * dt;
  15854. rb._velZ += linAccZ * dt;
  15855. rb._velX *= linScale;
  15856. rb._velY *= linScale;
  15857. rb._velZ *= linScale;
  15858. rb._angVelX += angAccX * dt;
  15859. rb._angVelY += angAccY * dt;
  15860. rb._angVelZ += angAccZ * dt;
  15861. rb._angVelX *= angScale;
  15862. rb._angVelY *= angScale;
  15863. rb._angVelZ *= angScale;
  15864. }
  15865. }
  15866. if(sleepIsland) {
  15867. let _g = 0;
  15868. let _g1 = this.numRigidBodies;
  15869. while(_g < _g1) {
  15870. let rb = this.rigidBodies[_g++];
  15871. rb._sleeping = true;
  15872. rb._sleepTime = 0;
  15873. }
  15874. return;
  15875. }
  15876. let _g2 = 0;
  15877. let _g3 = this.numSolvers;
  15878. while(_g2 < _g3) this.solvers[_g2++].preSolveVelocity(timeStep);
  15879. let _g4 = 0;
  15880. let _g5 = this.numSolvers;
  15881. while(_g4 < _g5) this.solvers[_g4++].warmStart(timeStep);
  15882. let _g6 = 0;
  15883. while(_g6 < numVelocityIterations) {
  15884. ++_g6;
  15885. let _g = 0;
  15886. let _g1 = this.numSolvers;
  15887. while(_g < _g1) this.solvers[_g++].solveVelocity();
  15888. }
  15889. let _g7 = 0;
  15890. let _g8 = this.numSolvers;
  15891. while(_g7 < _g8) this.solvers[_g7++].postSolveVelocity(timeStep);
  15892. let _g9 = 0;
  15893. let _g10 = this.numRigidBodies;
  15894. while(_g9 < _g10) this.rigidBodies[_g9++]._integrate(dt);
  15895. let _g11 = 0;
  15896. let _g12 = this.numSolversSi;
  15897. while(_g11 < _g12) this.solversSi[_g11++].preSolvePosition(timeStep);
  15898. let _g13 = 0;
  15899. while(_g13 < numPositionIterations) {
  15900. ++_g13;
  15901. let _g = 0;
  15902. let _g1 = this.numSolversSi;
  15903. while(_g < _g1) this.solversSi[_g++].solvePositionSplitImpulse();
  15904. }
  15905. let _g14 = 0;
  15906. let _g15 = this.numRigidBodies;
  15907. while(_g14 < _g15) this.rigidBodies[_g14++]._integratePseudoVelocity();
  15908. let _g16 = 0;
  15909. let _g17 = this.numSolversNgs;
  15910. while(_g16 < _g17) this.solversNgs[_g16++].preSolvePosition(timeStep);
  15911. let _g18 = 0;
  15912. while(_g18 < numPositionIterations) {
  15913. ++_g18;
  15914. let _g = 0;
  15915. let _g1 = this.numSolversNgs;
  15916. while(_g < _g1) this.solversNgs[_g++].solvePositionNgs(timeStep);
  15917. }
  15918. let _g19 = 0;
  15919. let _g20 = this.numSolvers;
  15920. while(_g19 < _g20) this.solvers[_g19++].postSolve();
  15921. let _g21 = 0;
  15922. let _g22 = this.numRigidBodies;
  15923. while(_g21 < _g22) {
  15924. let rb = this.rigidBodies[_g21++];
  15925. let s = rb._shapeList;
  15926. while(s != null) {
  15927. let n = s._next;
  15928. let tf1 = rb._ptransform;
  15929. let tf2 = rb._transform;
  15930. let dst = s._ptransform;
  15931. let src1 = s._localTransform;
  15932. let __tmp__00;
  15933. let __tmp__01;
  15934. let __tmp__02;
  15935. let __tmp__10;
  15936. let __tmp__11;
  15937. let __tmp__12;
  15938. let __tmp__20;
  15939. let __tmp__21;
  15940. let __tmp__22;
  15941. __tmp__00 = tf1._rotation00 * src1._rotation00 + tf1._rotation01 * src1._rotation10 + tf1._rotation02 * src1._rotation20;
  15942. __tmp__01 = tf1._rotation00 * src1._rotation01 + tf1._rotation01 * src1._rotation11 + tf1._rotation02 * src1._rotation21;
  15943. __tmp__02 = tf1._rotation00 * src1._rotation02 + tf1._rotation01 * src1._rotation12 + tf1._rotation02 * src1._rotation22;
  15944. __tmp__10 = tf1._rotation10 * src1._rotation00 + tf1._rotation11 * src1._rotation10 + tf1._rotation12 * src1._rotation20;
  15945. __tmp__11 = tf1._rotation10 * src1._rotation01 + tf1._rotation11 * src1._rotation11 + tf1._rotation12 * src1._rotation21;
  15946. __tmp__12 = tf1._rotation10 * src1._rotation02 + tf1._rotation11 * src1._rotation12 + tf1._rotation12 * src1._rotation22;
  15947. __tmp__20 = tf1._rotation20 * src1._rotation00 + tf1._rotation21 * src1._rotation10 + tf1._rotation22 * src1._rotation20;
  15948. __tmp__21 = tf1._rotation20 * src1._rotation01 + tf1._rotation21 * src1._rotation11 + tf1._rotation22 * src1._rotation21;
  15949. __tmp__22 = tf1._rotation20 * src1._rotation02 + tf1._rotation21 * src1._rotation12 + tf1._rotation22 * src1._rotation22;
  15950. dst._rotation00 = __tmp__00;
  15951. dst._rotation01 = __tmp__01;
  15952. dst._rotation02 = __tmp__02;
  15953. dst._rotation10 = __tmp__10;
  15954. dst._rotation11 = __tmp__11;
  15955. dst._rotation12 = __tmp__12;
  15956. dst._rotation20 = __tmp__20;
  15957. dst._rotation21 = __tmp__21;
  15958. dst._rotation22 = __tmp__22;
  15959. let __tmp__X;
  15960. let __tmp__Y;
  15961. let __tmp__Z;
  15962. __tmp__X = tf1._rotation00 * src1._positionX + tf1._rotation01 * src1._positionY + tf1._rotation02 * src1._positionZ;
  15963. __tmp__Y = tf1._rotation10 * src1._positionX + tf1._rotation11 * src1._positionY + tf1._rotation12 * src1._positionZ;
  15964. __tmp__Z = tf1._rotation20 * src1._positionX + tf1._rotation21 * src1._positionY + tf1._rotation22 * src1._positionZ;
  15965. dst._positionX = __tmp__X;
  15966. dst._positionY = __tmp__Y;
  15967. dst._positionZ = __tmp__Z;
  15968. dst._positionX += tf1._positionX;
  15969. dst._positionY += tf1._positionY;
  15970. dst._positionZ += tf1._positionZ;
  15971. let dst1 = s._transform;
  15972. let src11 = s._localTransform;
  15973. let __tmp__001;
  15974. let __tmp__011;
  15975. let __tmp__021;
  15976. let __tmp__101;
  15977. let __tmp__111;
  15978. let __tmp__121;
  15979. let __tmp__201;
  15980. let __tmp__211;
  15981. let __tmp__221;
  15982. __tmp__001 = tf2._rotation00 * src11._rotation00 + tf2._rotation01 * src11._rotation10 + tf2._rotation02 * src11._rotation20;
  15983. __tmp__011 = tf2._rotation00 * src11._rotation01 + tf2._rotation01 * src11._rotation11 + tf2._rotation02 * src11._rotation21;
  15984. __tmp__021 = tf2._rotation00 * src11._rotation02 + tf2._rotation01 * src11._rotation12 + tf2._rotation02 * src11._rotation22;
  15985. __tmp__101 = tf2._rotation10 * src11._rotation00 + tf2._rotation11 * src11._rotation10 + tf2._rotation12 * src11._rotation20;
  15986. __tmp__111 = tf2._rotation10 * src11._rotation01 + tf2._rotation11 * src11._rotation11 + tf2._rotation12 * src11._rotation21;
  15987. __tmp__121 = tf2._rotation10 * src11._rotation02 + tf2._rotation11 * src11._rotation12 + tf2._rotation12 * src11._rotation22;
  15988. __tmp__201 = tf2._rotation20 * src11._rotation00 + tf2._rotation21 * src11._rotation10 + tf2._rotation22 * src11._rotation20;
  15989. __tmp__211 = tf2._rotation20 * src11._rotation01 + tf2._rotation21 * src11._rotation11 + tf2._rotation22 * src11._rotation21;
  15990. __tmp__221 = tf2._rotation20 * src11._rotation02 + tf2._rotation21 * src11._rotation12 + tf2._rotation22 * src11._rotation22;
  15991. dst1._rotation00 = __tmp__001;
  15992. dst1._rotation01 = __tmp__011;
  15993. dst1._rotation02 = __tmp__021;
  15994. dst1._rotation10 = __tmp__101;
  15995. dst1._rotation11 = __tmp__111;
  15996. dst1._rotation12 = __tmp__121;
  15997. dst1._rotation20 = __tmp__201;
  15998. dst1._rotation21 = __tmp__211;
  15999. dst1._rotation22 = __tmp__221;
  16000. let __tmp__X1;
  16001. let __tmp__Y1;
  16002. let __tmp__Z1;
  16003. __tmp__X1 = tf2._rotation00 * src11._positionX + tf2._rotation01 * src11._positionY + tf2._rotation02 * src11._positionZ;
  16004. __tmp__Y1 = tf2._rotation10 * src11._positionX + tf2._rotation11 * src11._positionY + tf2._rotation12 * src11._positionZ;
  16005. __tmp__Z1 = tf2._rotation20 * src11._positionX + tf2._rotation21 * src11._positionY + tf2._rotation22 * src11._positionZ;
  16006. dst1._positionX = __tmp__X1;
  16007. dst1._positionY = __tmp__Y1;
  16008. dst1._positionZ = __tmp__Z1;
  16009. dst1._positionX += tf2._positionX;
  16010. dst1._positionY += tf2._positionY;
  16011. dst1._positionZ += tf2._positionZ;
  16012. let minX;
  16013. let minY;
  16014. let minZ;
  16015. let maxX;
  16016. let maxY;
  16017. let maxZ;
  16018. s._geom._computeAabb(s._aabb,s._ptransform);
  16019. minX = s._aabb._minX;
  16020. minY = s._aabb._minY;
  16021. minZ = s._aabb._minZ;
  16022. maxX = s._aabb._maxX;
  16023. maxY = s._aabb._maxY;
  16024. maxZ = s._aabb._maxZ;
  16025. s._geom._computeAabb(s._aabb,s._transform);
  16026. s._aabb._minX = minX < s._aabb._minX ? minX : s._aabb._minX;
  16027. s._aabb._minY = minY < s._aabb._minY ? minY : s._aabb._minY;
  16028. s._aabb._minZ = minZ < s._aabb._minZ ? minZ : s._aabb._minZ;
  16029. s._aabb._maxX = maxX > s._aabb._maxX ? maxX : s._aabb._maxX;
  16030. s._aabb._maxY = maxY > s._aabb._maxY ? maxY : s._aabb._maxY;
  16031. s._aabb._maxZ = maxZ > s._aabb._maxZ ? maxZ : s._aabb._maxZ;
  16032. if(s._proxy != null) {
  16033. let dX;
  16034. let dY;
  16035. let dZ;
  16036. dX = s._transform._positionX - s._ptransform._positionX;
  16037. dY = s._transform._positionY - s._ptransform._positionY;
  16038. dZ = s._transform._positionZ - s._ptransform._positionZ;
  16039. let v = s.displacement;
  16040. v.x = dX;
  16041. v.y = dY;
  16042. v.z = dZ;
  16043. s._rigidBody._world._broadPhase.moveProxy(s._proxy,s._aabb,s.displacement);
  16044. }
  16045. s = n;
  16046. }
  16047. }
  16048. }
  16049. }
  16050. oimo.dynamics.TimeStep = class oimo_dynamics_TimeStep {
  16051. constructor() {
  16052. this.dt = 0;
  16053. this.invDt = 0;
  16054. this.dtRatio = 1;
  16055. }
  16056. }
  16057. oimo.dynamics.World = class oimo_dynamics_World {
  16058. constructor(broadPhaseType,gravity) {
  16059. if(broadPhaseType == null) {
  16060. broadPhaseType = 2;
  16061. }
  16062. switch(broadPhaseType) {
  16063. case 1:
  16064. this._broadPhase = new oimo.collision.broadphase.bruteforce.BruteForceBroadPhase();
  16065. break;
  16066. case 2:
  16067. this._broadPhase = new oimo.collision.broadphase.bvh.BvhBroadPhase();
  16068. break;
  16069. }
  16070. this._contactManager = new oimo.dynamics.ContactManager(this._broadPhase);
  16071. if(gravity == null) {
  16072. gravity = new oimo.common.Vec3(0,-9.80665,0);
  16073. }
  16074. this._gravity = new oimo.common.Vec3(gravity.x,gravity.y,gravity.z);
  16075. this._rigidBodyList = null;
  16076. this._rigidBodyListLast = null;
  16077. this._jointList = null;
  16078. this._jointListLast = null;
  16079. this._numRigidBodies = 0;
  16080. this._numShapes = 0;
  16081. this._numJoints = 0;
  16082. this._numIslands = 0;
  16083. this._numVelocityIterations = 10;
  16084. this._numPositionIterations = 5;
  16085. this._rayCastWrapper = new oimo.dynamics._World.RayCastWrapper();
  16086. this._convexCastWrapper = new oimo.dynamics._World.ConvexCastWrapper();
  16087. this._aabbTestWrapper = new oimo.dynamics._World.AabbTestWrapper();
  16088. this._island = new oimo.dynamics.Island();
  16089. this._solversInIslands = new Array(oimo.common.Setting.islandInitialConstraintArraySize);
  16090. this._rigidBodyStack = new Array(oimo.common.Setting.islandInitialRigidBodyArraySize);
  16091. this._timeStep = new oimo.dynamics.TimeStep();
  16092. this._pool = new oimo.common.Pool();
  16093. this._shapeIdCount = 0;
  16094. }
  16095. _updateContacts() {
  16096. let st = Date.now() / 1000;
  16097. this._contactManager._updateContacts();
  16098. oimo.dynamics.common.Performance.broadPhaseCollisionTime = (Date.now() / 1000 - st) * 1000;
  16099. let st1 = Date.now() / 1000;
  16100. let c = this._contactManager._contactList;
  16101. while(c != null) {
  16102. let n = c._next;
  16103. if(!c._shouldBeSkipped) {
  16104. c._updateManifold();
  16105. }
  16106. c = n;
  16107. }
  16108. oimo.dynamics.common.Performance.narrowPhaseCollisionTime = (Date.now() / 1000 - st1) * 1000;
  16109. }
  16110. _solveIslands() {
  16111. let st = Date.now() / 1000;
  16112. if(oimo.common.Setting.disableSleeping) {
  16113. let b = this._rigidBodyList;
  16114. while(b != null) {
  16115. b._sleeping = false;
  16116. b._sleepTime = 0;
  16117. b = b._next;
  16118. }
  16119. }
  16120. if(this._rigidBodyStack.length < this._numRigidBodies) {
  16121. let newStackSize = this._rigidBodyStack.length << 1;
  16122. while(newStackSize < this._numRigidBodies) newStackSize <<= 1;
  16123. this._rigidBodyStack = new Array(newStackSize);
  16124. }
  16125. this._numIslands = 0;
  16126. let _this = this._island;
  16127. let gravity = this._gravity;
  16128. _this.gravityX = gravity.x;
  16129. _this.gravityY = gravity.y;
  16130. _this.gravityZ = gravity.z;
  16131. let b = this._rigidBodyList;
  16132. this._numSolversInIslands = 0;
  16133. while(b != null) {
  16134. let n = b._next;
  16135. while(!(b._addedToIsland || b._sleeping || b._type == 1)) {
  16136. if(b._numContactLinks == 0 && b._numJointLinks == 0) {
  16137. this._island._stepSingleRigidBody(this._timeStep,b);
  16138. this._numIslands++;
  16139. break;
  16140. }
  16141. this.buildIsland(b);
  16142. this._island._step(this._timeStep,this._numVelocityIterations,this._numPositionIterations);
  16143. this._island._clear();
  16144. this._numIslands++;
  16145. break;
  16146. }
  16147. b = n;
  16148. }
  16149. this._contactManager._postSolve();
  16150. b = this._rigidBodyList;
  16151. while(b != null) {
  16152. b._addedToIsland = false;
  16153. b = b._next;
  16154. }
  16155. b = this._rigidBodyList;
  16156. while(b != null) {
  16157. b._forceX = 0;
  16158. b._forceY = 0;
  16159. b._forceZ = 0;
  16160. b._torqueX = 0;
  16161. b._torqueY = 0;
  16162. b._torqueZ = 0;
  16163. b = b._next;
  16164. }
  16165. while(this._numSolversInIslands > 0) {
  16166. this._solversInIslands[--this._numSolversInIslands]._addedToIsland = false;
  16167. this._solversInIslands[this._numSolversInIslands] = null;
  16168. }
  16169. oimo.dynamics.common.Performance.dynamicsTime = (Date.now() / 1000 - st) * 1000;
  16170. }
  16171. buildIsland(base) {
  16172. let stackCount = 1;
  16173. this._island._addRigidBody(base);
  16174. this._rigidBodyStack[0] = base;
  16175. while(stackCount > 0) {
  16176. let rb = this._rigidBodyStack[--stackCount];
  16177. this._rigidBodyStack[stackCount] = null;
  16178. if(rb._type == 1) {
  16179. continue;
  16180. }
  16181. let cl = rb._contactLinkList;
  16182. while(cl != null) {
  16183. let n = cl._next;
  16184. let cc = cl._contact._contactConstraint;
  16185. let ccs = cl._contact._contactConstraint._solver;
  16186. if(cc.isTouching() && !ccs._addedToIsland) {
  16187. if(this._solversInIslands.length == this._numSolversInIslands) {
  16188. let newArray = new Array(this._numSolversInIslands << 1);
  16189. let _g = 0;
  16190. let _g1 = this._numSolversInIslands;
  16191. while(_g < _g1) {
  16192. let i = _g++;
  16193. newArray[i] = this._solversInIslands[i];
  16194. this._solversInIslands[i] = null;
  16195. }
  16196. this._solversInIslands = newArray;
  16197. }
  16198. this._solversInIslands[this._numSolversInIslands++] = ccs;
  16199. this._island._addConstraintSolver(ccs,cc._positionCorrectionAlgorithm);
  16200. let other = cl._other;
  16201. if(!other._addedToIsland) {
  16202. this._island._addRigidBody(other);
  16203. this._rigidBodyStack[stackCount++] = other;
  16204. }
  16205. }
  16206. cl = n;
  16207. }
  16208. let jl = rb._jointLinkList;
  16209. while(jl != null) {
  16210. let n = jl._next;
  16211. let j = jl._joint;
  16212. let js1 = j._solver;
  16213. if(!js1._addedToIsland) {
  16214. if(this._solversInIslands.length == this._numSolversInIslands) {
  16215. let newArray = new Array(this._numSolversInIslands << 1);
  16216. let _g = 0;
  16217. let _g1 = this._numSolversInIslands;
  16218. while(_g < _g1) {
  16219. let i = _g++;
  16220. newArray[i] = this._solversInIslands[i];
  16221. this._solversInIslands[i] = null;
  16222. }
  16223. this._solversInIslands = newArray;
  16224. }
  16225. this._solversInIslands[this._numSolversInIslands++] = js1;
  16226. this._island._addConstraintSolver(js1,j._positionCorrectionAlgorithm);
  16227. let other = jl._other;
  16228. if(!other._addedToIsland) {
  16229. this._island._addRigidBody(other);
  16230. this._rigidBodyStack[stackCount++] = other;
  16231. }
  16232. }
  16233. jl = n;
  16234. }
  16235. }
  16236. }
  16237. _drawBvh(d,tree) {
  16238. if(d.drawBvh) {
  16239. this._drawBvhNode(d,tree._root,0,d.style.bvhNodeColor);
  16240. }
  16241. }
  16242. _drawBvhNode(d,node,level,color) {
  16243. if(node == null) {
  16244. return;
  16245. }
  16246. if(level >= d.drawBvhMinLevel && level <= d.drawBvhMaxLevel) {
  16247. let _this = this._pool;
  16248. let min = _this.sizeVec3 == 0 ? new oimo.common.Vec3() : _this.stackVec3[--_this.sizeVec3];
  16249. let _this1 = this._pool;
  16250. let max = _this1.sizeVec3 == 0 ? new oimo.common.Vec3() : _this1.stackVec3[--_this1.sizeVec3];
  16251. let v = min;
  16252. v.x = node._aabbMinX;
  16253. v.y = node._aabbMinY;
  16254. v.z = node._aabbMinZ;
  16255. let v1 = max;
  16256. v1.x = node._aabbMaxX;
  16257. v1.y = node._aabbMaxY;
  16258. v1.z = node._aabbMaxZ;
  16259. d.aabb(min,max,color);
  16260. let _this2 = this._pool;
  16261. if(min != null) {
  16262. min.zero();
  16263. if(_this2.sizeVec3 == _this2.stackVec3.length) {
  16264. let newArray = new Array(_this2.sizeVec3 << 1);
  16265. let _g = 0;
  16266. let _g1 = _this2.sizeVec3;
  16267. while(_g < _g1) {
  16268. let i = _g++;
  16269. newArray[i] = _this2.stackVec3[i];
  16270. _this2.stackVec3[i] = null;
  16271. }
  16272. _this2.stackVec3 = newArray;
  16273. }
  16274. _this2.stackVec3[_this2.sizeVec3++] = min;
  16275. }
  16276. let _this3 = this._pool;
  16277. if(max != null) {
  16278. max.zero();
  16279. if(_this3.sizeVec3 == _this3.stackVec3.length) {
  16280. let newArray = new Array(_this3.sizeVec3 << 1);
  16281. let _g = 0;
  16282. let _g1 = _this3.sizeVec3;
  16283. while(_g < _g1) {
  16284. let i = _g++;
  16285. newArray[i] = _this3.stackVec3[i];
  16286. _this3.stackVec3[i] = null;
  16287. }
  16288. _this3.stackVec3 = newArray;
  16289. }
  16290. _this3.stackVec3[_this3.sizeVec3++] = max;
  16291. }
  16292. }
  16293. this._drawBvhNode(d,node._children[0],level + 1,color);
  16294. this._drawBvhNode(d,node._children[1],level + 1,color);
  16295. }
  16296. _drawRigidBodies(d) {
  16297. let style = d.style;
  16298. let r = this._rigidBodyList;
  16299. while(r != null) {
  16300. let n = r._next;
  16301. if(d.drawBases) {
  16302. let style = d.style;
  16303. d.basis(r._transform,style.basisLength,style.basisColorX,style.basisColorY,style.basisColorZ);
  16304. }
  16305. let shapeColor = null;
  16306. let isDynamic = r._type == 0;
  16307. if(!isDynamic) {
  16308. shapeColor = r._type == 2 ? style.kinematicShapeColor : style.staticShapeColor;
  16309. }
  16310. let s = r._shapeList;
  16311. while(s != null) {
  16312. let n = s._next;
  16313. if(isDynamic) {
  16314. if((s._id & 1) == 0) {
  16315. shapeColor = r._sleeping ? style.sleepingShapeColor1 : r._sleepTime > oimo.common.Setting.sleepingTimeThreshold ? style.sleepyShapeColor1 : style.shapeColor1;
  16316. } else {
  16317. shapeColor = r._sleeping ? style.sleepingShapeColor2 : r._sleepTime > oimo.common.Setting.sleepingTimeThreshold ? style.sleepyShapeColor2 : style.shapeColor2;
  16318. }
  16319. }
  16320. if(d.drawShapes) {
  16321. let geom = s._geom;
  16322. let tf = s._transform;
  16323. switch(geom._type) {
  16324. case 0:
  16325. d.sphere(tf,geom._radius,shapeColor);
  16326. break;
  16327. case 1:
  16328. let g = geom;
  16329. let _this = this._pool;
  16330. let hx = _this.sizeVec3 == 0 ? new oimo.common.Vec3() : _this.stackVec3[--_this.sizeVec3];
  16331. let v = hx;
  16332. v.x = g._halfExtentsX;
  16333. v.y = g._halfExtentsY;
  16334. v.z = g._halfExtentsZ;
  16335. d.box(tf,hx,shapeColor);
  16336. let _this1 = this._pool;
  16337. if(hx != null) {
  16338. hx.zero();
  16339. if(_this1.sizeVec3 == _this1.stackVec3.length) {
  16340. let newArray = new Array(_this1.sizeVec3 << 1);
  16341. let _g = 0;
  16342. let _g1 = _this1.sizeVec3;
  16343. while(_g < _g1) {
  16344. let i = _g++;
  16345. newArray[i] = _this1.stackVec3[i];
  16346. _this1.stackVec3[i] = null;
  16347. }
  16348. _this1.stackVec3 = newArray;
  16349. }
  16350. _this1.stackVec3[_this1.sizeVec3++] = hx;
  16351. }
  16352. break;
  16353. case 2:
  16354. let g1 = geom;
  16355. d.cylinder(tf,g1._radius,g1._halfHeight,shapeColor);
  16356. break;
  16357. case 3:
  16358. let g2 = geom;
  16359. d.cone(tf,g2._radius,g2._halfHeight,shapeColor);
  16360. break;
  16361. case 4:
  16362. let g3 = geom;
  16363. d.capsule(tf,g3._radius,g3._halfHeight,shapeColor);
  16364. break;
  16365. case 5:
  16366. let g4 = geom;
  16367. let n = g4._numVertices;
  16368. let _this2 = this._pool;
  16369. let v1 = _this2.sizeVec3 == 0 ? new oimo.common.Vec3() : _this2.stackVec3[--_this2.sizeVec3];
  16370. let _this3 = this._pool;
  16371. let v2 = _this3.sizeVec3 == 0 ? new oimo.common.Vec3() : _this3.stackVec3[--_this3.sizeVec3];
  16372. let _this4 = this._pool;
  16373. let v3 = _this4.sizeVec3 == 0 ? new oimo.common.Vec3() : _this4.stackVec3[--_this4.sizeVec3];
  16374. let _this5 = this._pool;
  16375. let v12 = _this5.sizeVec3 == 0 ? new oimo.common.Vec3() : _this5.stackVec3[--_this5.sizeVec3];
  16376. let _this6 = this._pool;
  16377. let v13 = _this6.sizeVec3 == 0 ? new oimo.common.Vec3() : _this6.stackVec3[--_this6.sizeVec3];
  16378. let _this7 = this._pool;
  16379. let normal = _this7.sizeVec3 == 0 ? new oimo.common.Vec3() : _this7.stackVec3[--_this7.sizeVec3];
  16380. let _this8 = this._pool;
  16381. let m = _this8.sizeMat3 == 0 ? new oimo.common.Mat3() : _this8.stackMat3[--_this8.sizeMat3];
  16382. let _this9 = this._pool;
  16383. let o = _this9.sizeVec3 == 0 ? new oimo.common.Vec3() : _this9.stackVec3[--_this9.sizeVec3];
  16384. let m1 = m;
  16385. m1.e00 = tf._rotation00;
  16386. m1.e01 = tf._rotation01;
  16387. m1.e02 = tf._rotation02;
  16388. m1.e10 = tf._rotation10;
  16389. m1.e11 = tf._rotation11;
  16390. m1.e12 = tf._rotation12;
  16391. m1.e20 = tf._rotation20;
  16392. m1.e21 = tf._rotation21;
  16393. m1.e22 = tf._rotation22;
  16394. let v4 = o;
  16395. v4.x = tf._positionX;
  16396. v4.y = tf._positionY;
  16397. v4.z = tf._positionZ;
  16398. let _g = 0;
  16399. while(_g < n) {
  16400. let i = _g++;
  16401. let _this = g4._tmpVertices[i];
  16402. let v = g4._vertices[i];
  16403. _this.x = v.x;
  16404. _this.y = v.y;
  16405. _this.z = v.z;
  16406. let y = _this.x * m.e10 + _this.y * m.e11 + _this.z * m.e12;
  16407. let z = _this.x * m.e20 + _this.y * m.e21 + _this.z * m.e22;
  16408. _this.x = _this.x * m.e00 + _this.y * m.e01 + _this.z * m.e02;
  16409. _this.y = y;
  16410. _this.z = z;
  16411. _this.x += o.x;
  16412. _this.y += o.y;
  16413. _this.z += o.z;
  16414. }
  16415. if(n > 30) {
  16416. let _g = 0;
  16417. while(_g < n) {
  16418. let i = _g++;
  16419. let v = g4._tmpVertices[i];
  16420. v1.x = v.x;
  16421. v1.y = v.y;
  16422. v1.z = v.z;
  16423. let v3 = g4._tmpVertices[(i + 1) % n];
  16424. v2.x = v3.x;
  16425. v2.y = v3.y;
  16426. v2.z = v3.z;
  16427. d.line(v1,v2,shapeColor);
  16428. }
  16429. } else if(this._debugDraw.wireframe || n > 10) {
  16430. let _g = 0;
  16431. while(_g < n) {
  16432. let i = _g++;
  16433. let v = g4._tmpVertices[i];
  16434. v1.x = v.x;
  16435. v1.y = v.y;
  16436. v1.z = v.z;
  16437. let _g1 = 0;
  16438. while(_g1 < i) {
  16439. let v = g4._tmpVertices[_g1++];
  16440. v2.x = v.x;
  16441. v2.y = v.y;
  16442. v2.z = v.z;
  16443. d.line(v1,v2,shapeColor);
  16444. }
  16445. }
  16446. } else {
  16447. let _g = 0;
  16448. while(_g < n) {
  16449. let i = _g++;
  16450. let v = g4._tmpVertices[i];
  16451. v1.x = v.x;
  16452. v1.y = v.y;
  16453. v1.z = v.z;
  16454. let _g1 = 0;
  16455. while(_g1 < i) {
  16456. let j = _g1++;
  16457. let v = g4._tmpVertices[j];
  16458. v2.x = v.x;
  16459. v2.y = v.y;
  16460. v2.z = v.z;
  16461. let _g = 0;
  16462. while(_g < j) {
  16463. let v = g4._tmpVertices[_g++];
  16464. v3.x = v.x;
  16465. v3.y = v.y;
  16466. v3.z = v.z;
  16467. v12.x = v2.x;
  16468. v12.y = v2.y;
  16469. v12.z = v2.z;
  16470. let _this = v12;
  16471. _this.x -= v1.x;
  16472. _this.y -= v1.y;
  16473. _this.z -= v1.z;
  16474. v13.x = v3.x;
  16475. v13.y = v3.y;
  16476. v13.z = v3.z;
  16477. let _this1 = v13;
  16478. _this1.x -= v1.x;
  16479. _this1.y -= v1.y;
  16480. _this1.z -= v1.z;
  16481. normal.x = v12.x;
  16482. normal.y = v12.y;
  16483. normal.z = v12.z;
  16484. let _this2 = normal;
  16485. let y = _this2.z * v13.x - _this2.x * v13.z;
  16486. let z = _this2.x * v13.y - _this2.y * v13.x;
  16487. _this2.x = _this2.y * v13.z - _this2.z * v13.y;
  16488. _this2.y = y;
  16489. _this2.z = z;
  16490. let invLen = Math.sqrt(_this2.x * _this2.x + _this2.y * _this2.y + _this2.z * _this2.z);
  16491. if(invLen > 0) {
  16492. invLen = 1 / invLen;
  16493. }
  16494. _this2.x *= invLen;
  16495. _this2.y *= invLen;
  16496. _this2.z *= invLen;
  16497. d.triangle(v1,v2,v3,normal,normal,normal,shapeColor);
  16498. normal.x = -normal.x;
  16499. normal.y = -normal.y;
  16500. normal.z = -normal.z;
  16501. d.triangle(v1,v3,v2,normal,normal,normal,shapeColor);
  16502. }
  16503. }
  16504. }
  16505. }
  16506. let _this10 = this._pool;
  16507. if(v1 != null) {
  16508. v1.zero();
  16509. if(_this10.sizeVec3 == _this10.stackVec3.length) {
  16510. let newArray = new Array(_this10.sizeVec3 << 1);
  16511. let _g = 0;
  16512. let _g1 = _this10.sizeVec3;
  16513. while(_g < _g1) {
  16514. let i = _g++;
  16515. newArray[i] = _this10.stackVec3[i];
  16516. _this10.stackVec3[i] = null;
  16517. }
  16518. _this10.stackVec3 = newArray;
  16519. }
  16520. _this10.stackVec3[_this10.sizeVec3++] = v1;
  16521. }
  16522. let _this11 = this._pool;
  16523. if(v2 != null) {
  16524. v2.zero();
  16525. if(_this11.sizeVec3 == _this11.stackVec3.length) {
  16526. let newArray = new Array(_this11.sizeVec3 << 1);
  16527. let _g = 0;
  16528. let _g1 = _this11.sizeVec3;
  16529. while(_g < _g1) {
  16530. let i = _g++;
  16531. newArray[i] = _this11.stackVec3[i];
  16532. _this11.stackVec3[i] = null;
  16533. }
  16534. _this11.stackVec3 = newArray;
  16535. }
  16536. _this11.stackVec3[_this11.sizeVec3++] = v2;
  16537. }
  16538. let _this12 = this._pool;
  16539. if(v3 != null) {
  16540. v3.zero();
  16541. if(_this12.sizeVec3 == _this12.stackVec3.length) {
  16542. let newArray = new Array(_this12.sizeVec3 << 1);
  16543. let _g = 0;
  16544. let _g1 = _this12.sizeVec3;
  16545. while(_g < _g1) {
  16546. let i = _g++;
  16547. newArray[i] = _this12.stackVec3[i];
  16548. _this12.stackVec3[i] = null;
  16549. }
  16550. _this12.stackVec3 = newArray;
  16551. }
  16552. _this12.stackVec3[_this12.sizeVec3++] = v3;
  16553. }
  16554. let _this13 = this._pool;
  16555. if(v12 != null) {
  16556. v12.zero();
  16557. if(_this13.sizeVec3 == _this13.stackVec3.length) {
  16558. let newArray = new Array(_this13.sizeVec3 << 1);
  16559. let _g = 0;
  16560. let _g1 = _this13.sizeVec3;
  16561. while(_g < _g1) {
  16562. let i = _g++;
  16563. newArray[i] = _this13.stackVec3[i];
  16564. _this13.stackVec3[i] = null;
  16565. }
  16566. _this13.stackVec3 = newArray;
  16567. }
  16568. _this13.stackVec3[_this13.sizeVec3++] = v12;
  16569. }
  16570. let _this14 = this._pool;
  16571. if(v13 != null) {
  16572. v13.zero();
  16573. if(_this14.sizeVec3 == _this14.stackVec3.length) {
  16574. let newArray = new Array(_this14.sizeVec3 << 1);
  16575. let _g = 0;
  16576. let _g1 = _this14.sizeVec3;
  16577. while(_g < _g1) {
  16578. let i = _g++;
  16579. newArray[i] = _this14.stackVec3[i];
  16580. _this14.stackVec3[i] = null;
  16581. }
  16582. _this14.stackVec3 = newArray;
  16583. }
  16584. _this14.stackVec3[_this14.sizeVec3++] = v13;
  16585. }
  16586. let _this15 = this._pool;
  16587. if(normal != null) {
  16588. normal.zero();
  16589. if(_this15.sizeVec3 == _this15.stackVec3.length) {
  16590. let newArray = new Array(_this15.sizeVec3 << 1);
  16591. let _g = 0;
  16592. let _g1 = _this15.sizeVec3;
  16593. while(_g < _g1) {
  16594. let i = _g++;
  16595. newArray[i] = _this15.stackVec3[i];
  16596. _this15.stackVec3[i] = null;
  16597. }
  16598. _this15.stackVec3 = newArray;
  16599. }
  16600. _this15.stackVec3[_this15.sizeVec3++] = normal;
  16601. }
  16602. let _this16 = this._pool;
  16603. if(m != null) {
  16604. m.e00 = 1;
  16605. m.e01 = 0;
  16606. m.e02 = 0;
  16607. m.e10 = 0;
  16608. m.e11 = 1;
  16609. m.e12 = 0;
  16610. m.e20 = 0;
  16611. m.e21 = 0;
  16612. m.e22 = 1;
  16613. if(_this16.sizeMat3 == _this16.stackMat3.length) {
  16614. let newArray = new Array(_this16.sizeMat3 << 1);
  16615. let _g = 0;
  16616. let _g1 = _this16.sizeMat3;
  16617. while(_g < _g1) {
  16618. let i = _g++;
  16619. newArray[i] = _this16.stackMat3[i];
  16620. _this16.stackMat3[i] = null;
  16621. }
  16622. _this16.stackMat3 = newArray;
  16623. }
  16624. _this16.stackMat3[_this16.sizeMat3++] = m;
  16625. }
  16626. let _this17 = this._pool;
  16627. if(o != null) {
  16628. o.zero();
  16629. if(_this17.sizeVec3 == _this17.stackVec3.length) {
  16630. let newArray = new Array(_this17.sizeVec3 << 1);
  16631. let _g = 0;
  16632. let _g1 = _this17.sizeVec3;
  16633. while(_g < _g1) {
  16634. let i = _g++;
  16635. newArray[i] = _this17.stackVec3[i];
  16636. _this17.stackVec3[i] = null;
  16637. }
  16638. _this17.stackVec3 = newArray;
  16639. }
  16640. _this17.stackVec3[_this17.sizeVec3++] = o;
  16641. }
  16642. break;
  16643. }
  16644. }
  16645. if(d.drawAabbs) {
  16646. let aabb = s._aabb;
  16647. let color = style.aabbColor;
  16648. let _this = this._pool;
  16649. let min = _this.sizeVec3 == 0 ? new oimo.common.Vec3() : _this.stackVec3[--_this.sizeVec3];
  16650. let _this1 = this._pool;
  16651. let max = _this1.sizeVec3 == 0 ? new oimo.common.Vec3() : _this1.stackVec3[--_this1.sizeVec3];
  16652. let v = min;
  16653. v.x = aabb._minX;
  16654. v.y = aabb._minY;
  16655. v.z = aabb._minZ;
  16656. let v1 = max;
  16657. v1.x = aabb._maxX;
  16658. v1.y = aabb._maxY;
  16659. v1.z = aabb._maxZ;
  16660. d.aabb(min,max,color);
  16661. let _this2 = this._pool;
  16662. if(min != null) {
  16663. min.zero();
  16664. if(_this2.sizeVec3 == _this2.stackVec3.length) {
  16665. let newArray = new Array(_this2.sizeVec3 << 1);
  16666. let _g = 0;
  16667. let _g1 = _this2.sizeVec3;
  16668. while(_g < _g1) {
  16669. let i = _g++;
  16670. newArray[i] = _this2.stackVec3[i];
  16671. _this2.stackVec3[i] = null;
  16672. }
  16673. _this2.stackVec3 = newArray;
  16674. }
  16675. _this2.stackVec3[_this2.sizeVec3++] = min;
  16676. }
  16677. let _this3 = this._pool;
  16678. if(max != null) {
  16679. max.zero();
  16680. if(_this3.sizeVec3 == _this3.stackVec3.length) {
  16681. let newArray = new Array(_this3.sizeVec3 << 1);
  16682. let _g = 0;
  16683. let _g1 = _this3.sizeVec3;
  16684. while(_g < _g1) {
  16685. let i = _g++;
  16686. newArray[i] = _this3.stackVec3[i];
  16687. _this3.stackVec3[i] = null;
  16688. }
  16689. _this3.stackVec3 = newArray;
  16690. }
  16691. _this3.stackVec3[_this3.sizeVec3++] = max;
  16692. }
  16693. }
  16694. s = n;
  16695. }
  16696. r = n;
  16697. }
  16698. }
  16699. _drawConstraints(d) {
  16700. let style = d.style;
  16701. if(d.drawPairs || d.drawContacts) {
  16702. let c = this._contactManager._contactList;
  16703. while(c != null) {
  16704. let n = c._next;
  16705. if(d.drawPairs) {
  16706. let color = style.pairColor;
  16707. let _this = this._pool;
  16708. let v1 = _this.sizeVec3 == 0 ? new oimo.common.Vec3() : _this.stackVec3[--_this.sizeVec3];
  16709. let _this1 = this._pool;
  16710. let v2 = _this1.sizeVec3 == 0 ? new oimo.common.Vec3() : _this1.stackVec3[--_this1.sizeVec3];
  16711. let v = v1;
  16712. v.x = c._s1._transform._positionX;
  16713. v.y = c._s1._transform._positionY;
  16714. v.z = c._s1._transform._positionZ;
  16715. let v3 = v2;
  16716. v3.x = c._s2._transform._positionX;
  16717. v3.y = c._s2._transform._positionY;
  16718. v3.z = c._s2._transform._positionZ;
  16719. d.line(v1,v2,color);
  16720. let _this2 = this._pool;
  16721. if(v1 != null) {
  16722. v1.zero();
  16723. if(_this2.sizeVec3 == _this2.stackVec3.length) {
  16724. let newArray = new Array(_this2.sizeVec3 << 1);
  16725. let _g = 0;
  16726. let _g1 = _this2.sizeVec3;
  16727. while(_g < _g1) {
  16728. let i = _g++;
  16729. newArray[i] = _this2.stackVec3[i];
  16730. _this2.stackVec3[i] = null;
  16731. }
  16732. _this2.stackVec3 = newArray;
  16733. }
  16734. _this2.stackVec3[_this2.sizeVec3++] = v1;
  16735. }
  16736. let _this3 = this._pool;
  16737. if(v2 != null) {
  16738. v2.zero();
  16739. if(_this3.sizeVec3 == _this3.stackVec3.length) {
  16740. let newArray = new Array(_this3.sizeVec3 << 1);
  16741. let _g = 0;
  16742. let _g1 = _this3.sizeVec3;
  16743. while(_g < _g1) {
  16744. let i = _g++;
  16745. newArray[i] = _this3.stackVec3[i];
  16746. _this3.stackVec3[i] = null;
  16747. }
  16748. _this3.stackVec3 = newArray;
  16749. }
  16750. _this3.stackVec3[_this3.sizeVec3++] = v2;
  16751. }
  16752. }
  16753. if(d.drawContacts) {
  16754. let cc = c._contactConstraint;
  16755. let ps = c._contactConstraint._manifold._points;
  16756. let _g = 0;
  16757. let _g1 = c._contactConstraint._manifold._numPoints;
  16758. while(_g < _g1) {
  16759. let p = ps[_g++];
  16760. let style = d.style;
  16761. let _this = this._pool;
  16762. let pos1 = _this.sizeVec3 == 0 ? new oimo.common.Vec3() : _this.stackVec3[--_this.sizeVec3];
  16763. let _this1 = this._pool;
  16764. let pos2 = _this1.sizeVec3 == 0 ? new oimo.common.Vec3() : _this1.stackVec3[--_this1.sizeVec3];
  16765. let _this2 = this._pool;
  16766. let normal = _this2.sizeVec3 == 0 ? new oimo.common.Vec3() : _this2.stackVec3[--_this2.sizeVec3];
  16767. let _this3 = this._pool;
  16768. let tangent = _this3.sizeVec3 == 0 ? new oimo.common.Vec3() : _this3.stackVec3[--_this3.sizeVec3];
  16769. let _this4 = this._pool;
  16770. let binormal = _this4.sizeVec3 == 0 ? new oimo.common.Vec3() : _this4.stackVec3[--_this4.sizeVec3];
  16771. let v = pos1;
  16772. v.x = p._pos1X;
  16773. v.y = p._pos1Y;
  16774. v.z = p._pos1Z;
  16775. let v1 = pos2;
  16776. v1.x = p._pos2X;
  16777. v1.y = p._pos2Y;
  16778. v1.z = p._pos2Z;
  16779. let v2 = normal;
  16780. v2.x = cc._manifold._normalX;
  16781. v2.y = cc._manifold._normalY;
  16782. v2.z = cc._manifold._normalZ;
  16783. let v3 = tangent;
  16784. v3.x = cc._manifold._tangentX;
  16785. v3.y = cc._manifold._tangentY;
  16786. v3.z = cc._manifold._tangentZ;
  16787. let v4 = binormal;
  16788. v4.x = cc._manifold._binormalX;
  16789. v4.y = cc._manifold._binormalY;
  16790. v4.z = cc._manifold._binormalZ;
  16791. if(p._disabled) {
  16792. d.point(pos1,style.disabledContactColor);
  16793. d.point(pos2,style.disabledContactColor);
  16794. d.line(pos1,pos2,style.disabledContactColor);
  16795. } else if(p._warmStarted) {
  16796. let color;
  16797. switch(p._id & 3) {
  16798. case 0:
  16799. color = style.contactColor;
  16800. break;
  16801. case 1:
  16802. color = style.contactColor2;
  16803. break;
  16804. case 2:
  16805. color = style.contactColor3;
  16806. break;
  16807. default:
  16808. color = style.contactColor4;
  16809. }
  16810. d.point(pos1,color);
  16811. d.point(pos2,color);
  16812. d.line(pos1,pos2,style.contactColor);
  16813. } else {
  16814. d.point(pos1,style.newContactColor);
  16815. d.point(pos2,style.newContactColor);
  16816. d.line(pos1,pos2,style.newContactColor);
  16817. }
  16818. pos2.x = pos1.x;
  16819. pos2.y = pos1.y;
  16820. pos2.z = pos1.z;
  16821. let _this5 = pos2;
  16822. let s = style.contactNormalLength;
  16823. _this5.x += normal.x * s;
  16824. _this5.y += normal.y * s;
  16825. _this5.z += normal.z * s;
  16826. d.line(pos1,pos2,style.contactNormalColor);
  16827. if(d.drawContactBases) {
  16828. pos2.x = pos1.x;
  16829. pos2.y = pos1.y;
  16830. pos2.z = pos1.z;
  16831. let _this = pos2;
  16832. let s = style.contactTangentLength;
  16833. _this.x += tangent.x * s;
  16834. _this.y += tangent.y * s;
  16835. _this.z += tangent.z * s;
  16836. d.line(pos1,pos2,style.contactTangentColor);
  16837. pos2.x = pos1.x;
  16838. pos2.y = pos1.y;
  16839. pos2.z = pos1.z;
  16840. let _this1 = pos2;
  16841. let s1 = style.contactBinormalLength;
  16842. _this1.x += binormal.x * s1;
  16843. _this1.y += binormal.y * s1;
  16844. _this1.z += binormal.z * s1;
  16845. d.line(pos1,pos2,style.contactBinormalColor);
  16846. }
  16847. let _this6 = this._pool;
  16848. if(pos1 != null) {
  16849. pos1.zero();
  16850. if(_this6.sizeVec3 == _this6.stackVec3.length) {
  16851. let newArray = new Array(_this6.sizeVec3 << 1);
  16852. let _g = 0;
  16853. let _g1 = _this6.sizeVec3;
  16854. while(_g < _g1) {
  16855. let i = _g++;
  16856. newArray[i] = _this6.stackVec3[i];
  16857. _this6.stackVec3[i] = null;
  16858. }
  16859. _this6.stackVec3 = newArray;
  16860. }
  16861. _this6.stackVec3[_this6.sizeVec3++] = pos1;
  16862. }
  16863. let _this7 = this._pool;
  16864. if(pos2 != null) {
  16865. pos2.zero();
  16866. if(_this7.sizeVec3 == _this7.stackVec3.length) {
  16867. let newArray = new Array(_this7.sizeVec3 << 1);
  16868. let _g = 0;
  16869. let _g1 = _this7.sizeVec3;
  16870. while(_g < _g1) {
  16871. let i = _g++;
  16872. newArray[i] = _this7.stackVec3[i];
  16873. _this7.stackVec3[i] = null;
  16874. }
  16875. _this7.stackVec3 = newArray;
  16876. }
  16877. _this7.stackVec3[_this7.sizeVec3++] = pos2;
  16878. }
  16879. let _this8 = this._pool;
  16880. if(normal != null) {
  16881. normal.zero();
  16882. if(_this8.sizeVec3 == _this8.stackVec3.length) {
  16883. let newArray = new Array(_this8.sizeVec3 << 1);
  16884. let _g = 0;
  16885. let _g1 = _this8.sizeVec3;
  16886. while(_g < _g1) {
  16887. let i = _g++;
  16888. newArray[i] = _this8.stackVec3[i];
  16889. _this8.stackVec3[i] = null;
  16890. }
  16891. _this8.stackVec3 = newArray;
  16892. }
  16893. _this8.stackVec3[_this8.sizeVec3++] = normal;
  16894. }
  16895. let _this9 = this._pool;
  16896. if(tangent != null) {
  16897. tangent.zero();
  16898. if(_this9.sizeVec3 == _this9.stackVec3.length) {
  16899. let newArray = new Array(_this9.sizeVec3 << 1);
  16900. let _g = 0;
  16901. let _g1 = _this9.sizeVec3;
  16902. while(_g < _g1) {
  16903. let i = _g++;
  16904. newArray[i] = _this9.stackVec3[i];
  16905. _this9.stackVec3[i] = null;
  16906. }
  16907. _this9.stackVec3 = newArray;
  16908. }
  16909. _this9.stackVec3[_this9.sizeVec3++] = tangent;
  16910. }
  16911. let _this10 = this._pool;
  16912. if(binormal != null) {
  16913. binormal.zero();
  16914. if(_this10.sizeVec3 == _this10.stackVec3.length) {
  16915. let newArray = new Array(_this10.sizeVec3 << 1);
  16916. let _g = 0;
  16917. let _g1 = _this10.sizeVec3;
  16918. while(_g < _g1) {
  16919. let i = _g++;
  16920. newArray[i] = _this10.stackVec3[i];
  16921. _this10.stackVec3[i] = null;
  16922. }
  16923. _this10.stackVec3 = newArray;
  16924. }
  16925. _this10.stackVec3[_this10.sizeVec3++] = binormal;
  16926. }
  16927. }
  16928. }
  16929. c = n;
  16930. }
  16931. }
  16932. if(d.drawJoints) {
  16933. let j = this._jointList;
  16934. while(j != null) {
  16935. let n = j._next;
  16936. let _this = this._pool;
  16937. let p1 = _this.sizeVec3 == 0 ? new oimo.common.Vec3() : _this.stackVec3[--_this.sizeVec3];
  16938. let _this1 = this._pool;
  16939. let p2 = _this1.sizeVec3 == 0 ? new oimo.common.Vec3() : _this1.stackVec3[--_this1.sizeVec3];
  16940. let v = p1;
  16941. v.x = j._b1._transform._positionX;
  16942. v.y = j._b1._transform._positionY;
  16943. v.z = j._b1._transform._positionZ;
  16944. let v1 = p2;
  16945. v1.x = j._b2._transform._positionX;
  16946. v1.y = j._b2._transform._positionY;
  16947. v1.z = j._b2._transform._positionZ;
  16948. let _this2 = this._pool;
  16949. let anchor1 = _this2.sizeVec3 == 0 ? new oimo.common.Vec3() : _this2.stackVec3[--_this2.sizeVec3];
  16950. let _this3 = this._pool;
  16951. let anchor2 = _this3.sizeVec3 == 0 ? new oimo.common.Vec3() : _this3.stackVec3[--_this3.sizeVec3];
  16952. let _this4 = this._pool;
  16953. let basisX1 = _this4.sizeVec3 == 0 ? new oimo.common.Vec3() : _this4.stackVec3[--_this4.sizeVec3];
  16954. let _this5 = this._pool;
  16955. let basisY1 = _this5.sizeVec3 == 0 ? new oimo.common.Vec3() : _this5.stackVec3[--_this5.sizeVec3];
  16956. let _this6 = this._pool;
  16957. let basisZ1 = _this6.sizeVec3 == 0 ? new oimo.common.Vec3() : _this6.stackVec3[--_this6.sizeVec3];
  16958. let _this7 = this._pool;
  16959. let basisX2 = _this7.sizeVec3 == 0 ? new oimo.common.Vec3() : _this7.stackVec3[--_this7.sizeVec3];
  16960. let _this8 = this._pool;
  16961. let basisY2 = _this8.sizeVec3 == 0 ? new oimo.common.Vec3() : _this8.stackVec3[--_this8.sizeVec3];
  16962. let _this9 = this._pool;
  16963. let basisZ2 = _this9.sizeVec3 == 0 ? new oimo.common.Vec3() : _this9.stackVec3[--_this9.sizeVec3];
  16964. let v2 = anchor1;
  16965. v2.x = j._anchor1X;
  16966. v2.y = j._anchor1Y;
  16967. v2.z = j._anchor1Z;
  16968. let v3 = anchor2;
  16969. v3.x = j._anchor2X;
  16970. v3.y = j._anchor2Y;
  16971. v3.z = j._anchor2Z;
  16972. let v4 = basisX1;
  16973. v4.x = j._basisX1X;
  16974. v4.y = j._basisX1Y;
  16975. v4.z = j._basisX1Z;
  16976. let v5 = basisY1;
  16977. v5.x = j._basisY1X;
  16978. v5.y = j._basisY1Y;
  16979. v5.z = j._basisY1Z;
  16980. let v6 = basisZ1;
  16981. v6.x = j._basisZ1X;
  16982. v6.y = j._basisZ1Y;
  16983. v6.z = j._basisZ1Z;
  16984. let v7 = basisX2;
  16985. v7.x = j._basisX2X;
  16986. v7.y = j._basisX2Y;
  16987. v7.z = j._basisX2Z;
  16988. let v8 = basisY2;
  16989. v8.x = j._basisY2X;
  16990. v8.y = j._basisY2Y;
  16991. v8.z = j._basisY2Z;
  16992. let v9 = basisZ2;
  16993. v9.x = j._basisZ2X;
  16994. v9.y = j._basisZ2Y;
  16995. v9.z = j._basisZ2Z;
  16996. d.line(p1,anchor1,d.style.jointLineColor);
  16997. d.line(p2,anchor2,d.style.jointLineColor);
  16998. if(d.drawJointLimits) {
  16999. switch(j._type) {
  17000. case 0:
  17001. break;
  17002. case 1:
  17003. let lm = j._lm;
  17004. this._drawRotationalLimit(d,anchor1,basisY1,basisZ1,basisY2,d.style.jointRotationalConstraintRadius,lm.lowerLimit,lm.upperLimit,d.style.jointLineColor);
  17005. break;
  17006. case 2:
  17007. let j1 = j;
  17008. let color = d.style.jointLineColor;
  17009. let rlm = j1._rotLm;
  17010. let tlm = j1._translLm;
  17011. this._drawRotationalLimit(d,anchor2,basisY1,basisZ1,basisY2,d.style.jointRotationalConstraintRadius,rlm.lowerLimit,rlm.upperLimit,color);
  17012. this._drawTranslationalLimit(d,anchor1,basisX1,tlm.lowerLimit,tlm.upperLimit,color);
  17013. break;
  17014. case 3:
  17015. let lm1 = j._lm;
  17016. this._drawTranslationalLimit(d,anchor1,basisX1,lm1.lowerLimit,lm1.upperLimit,d.style.jointLineColor);
  17017. break;
  17018. case 4:
  17019. let j2 = j;
  17020. let radius = d.style.jointRotationalConstraintRadius;
  17021. let color1 = d.style.jointLineColor;
  17022. let lm11 = j2._lm1;
  17023. let lm2 = j2._lm2;
  17024. this._drawRotationalLimit(d,anchor1,basisY1,basisZ1,basisY1,radius,j2._angleX - lm11.upperLimit,j2._angleX - lm11.lowerLimit,color1);
  17025. this._drawRotationalLimit(d,anchor2,basisX2,basisY2,basisX2,radius,lm2.lowerLimit - j2._angleZ,lm2.upperLimit - j2._angleZ,color1);
  17026. break;
  17027. case 5:
  17028. let j3 = j;
  17029. let radius1 = d.style.jointRotationalConstraintRadius;
  17030. let color2 = d.style.jointLineColor;
  17031. let lm3 = j3._twistLm;
  17032. this._drawRotationalLimit(d,anchor2,basisY2,basisZ2,basisY2,radius1,lm3.lowerLimit - j3._twistAngle,lm3.upperLimit - j3._twistAngle,color2);
  17033. this._drawEllipseOnSphere(d,anchor1,basisX1,basisY1,basisZ1,j3._maxSwingAngle1,j3._maxSwingAngle2,radius1,color2);
  17034. let _this10 = this._pool;
  17035. let _this11 = _this10.sizeVec3 == 0 ? new oimo.common.Vec3() : _this10.stackVec3[--_this10.sizeVec3];
  17036. _this11.x = anchor2.x;
  17037. _this11.y = anchor2.y;
  17038. _this11.z = anchor2.z;
  17039. let _this12 = _this11;
  17040. _this12.x += basisX2.x * radius1;
  17041. _this12.y += basisX2.y * radius1;
  17042. _this12.z += basisX2.z * radius1;
  17043. d.line(anchor2,_this12,color2);
  17044. let _this13 = this._pool;
  17045. if(_this12 != null) {
  17046. _this12.zero();
  17047. if(_this13.sizeVec3 == _this13.stackVec3.length) {
  17048. let newArray = new Array(_this13.sizeVec3 << 1);
  17049. let _g = 0;
  17050. let _g1 = _this13.sizeVec3;
  17051. while(_g < _g1) {
  17052. let i = _g++;
  17053. newArray[i] = _this13.stackVec3[i];
  17054. _this13.stackVec3[i] = null;
  17055. }
  17056. _this13.stackVec3 = newArray;
  17057. }
  17058. _this13.stackVec3[_this13.sizeVec3++] = _this12;
  17059. }
  17060. break;
  17061. case 6:
  17062. let j4 = j;
  17063. let radius2 = d.style.jointRotationalConstraintRadius;
  17064. let color3 = d.style.jointLineColor;
  17065. let rxlm = j4._rotLms[0];
  17066. let rylm = j4._rotLms[1];
  17067. let rzlm = j4._rotLms[2];
  17068. this._drawTranslationalLimit3D(d,anchor1,basisX1,basisY1,basisZ1,j4._translLms[0],j4._translLms[1],j4._translLms[2],color3);
  17069. let _this14 = this._pool;
  17070. let rotYAxis = _this14.sizeVec3 == 0 ? new oimo.common.Vec3() : _this14.stackVec3[--_this14.sizeVec3];
  17071. let v10 = rotYAxis;
  17072. v10.x = j4._axisYX;
  17073. v10.y = j4._axisYY;
  17074. v10.z = j4._axisYZ;
  17075. let _this15 = this._pool;
  17076. let _this16 = _this15.sizeVec3 == 0 ? new oimo.common.Vec3() : _this15.stackVec3[--_this15.sizeVec3];
  17077. _this16.x = basisX1.x;
  17078. _this16.y = basisX1.y;
  17079. _this16.z = basisX1.z;
  17080. let rotYBasisX = _this16;
  17081. let _this17 = this._pool;
  17082. let _this18 = _this17.sizeVec3 == 0 ? new oimo.common.Vec3() : _this17.stackVec3[--_this17.sizeVec3];
  17083. _this18.x = basisX1.x;
  17084. _this18.y = basisX1.y;
  17085. _this18.z = basisX1.z;
  17086. let _this19 = _this18;
  17087. let y = _this19.z * rotYAxis.x - _this19.x * rotYAxis.z;
  17088. let z = _this19.x * rotYAxis.y - _this19.y * rotYAxis.x;
  17089. _this19.x = _this19.y * rotYAxis.z - _this19.z * rotYAxis.y;
  17090. _this19.y = y;
  17091. _this19.z = z;
  17092. this._drawRotationalLimit(d,anchor2,basisY1,basisZ1,basisY1,radius2,j4._angleX - rxlm.upperLimit,j4._angleX - rxlm.lowerLimit,color3);
  17093. this._drawRotationalLimit(d,anchor2,rotYBasisX,_this19,rotYBasisX,radius2,rylm.lowerLimit - j4._angleY,rylm.upperLimit - j4._angleY,color3);
  17094. this._drawRotationalLimit(d,anchor2,basisX2,basisY2,basisX2,radius2,rzlm.lowerLimit - j4._angleZ,rzlm.upperLimit - j4._angleZ,color3);
  17095. break;
  17096. }
  17097. }
  17098. d.line(anchor1,anchor2,d.style.jointErrorColor);
  17099. let _this20 = this._pool;
  17100. if(p1 != null) {
  17101. p1.zero();
  17102. if(_this20.sizeVec3 == _this20.stackVec3.length) {
  17103. let newArray = new Array(_this20.sizeVec3 << 1);
  17104. let _g = 0;
  17105. let _g1 = _this20.sizeVec3;
  17106. while(_g < _g1) {
  17107. let i = _g++;
  17108. newArray[i] = _this20.stackVec3[i];
  17109. _this20.stackVec3[i] = null;
  17110. }
  17111. _this20.stackVec3 = newArray;
  17112. }
  17113. _this20.stackVec3[_this20.sizeVec3++] = p1;
  17114. }
  17115. let _this21 = this._pool;
  17116. if(p2 != null) {
  17117. p2.zero();
  17118. if(_this21.sizeVec3 == _this21.stackVec3.length) {
  17119. let newArray = new Array(_this21.sizeVec3 << 1);
  17120. let _g = 0;
  17121. let _g1 = _this21.sizeVec3;
  17122. while(_g < _g1) {
  17123. let i = _g++;
  17124. newArray[i] = _this21.stackVec3[i];
  17125. _this21.stackVec3[i] = null;
  17126. }
  17127. _this21.stackVec3 = newArray;
  17128. }
  17129. _this21.stackVec3[_this21.sizeVec3++] = p2;
  17130. }
  17131. let _this22 = this._pool;
  17132. if(anchor1 != null) {
  17133. anchor1.zero();
  17134. if(_this22.sizeVec3 == _this22.stackVec3.length) {
  17135. let newArray = new Array(_this22.sizeVec3 << 1);
  17136. let _g = 0;
  17137. let _g1 = _this22.sizeVec3;
  17138. while(_g < _g1) {
  17139. let i = _g++;
  17140. newArray[i] = _this22.stackVec3[i];
  17141. _this22.stackVec3[i] = null;
  17142. }
  17143. _this22.stackVec3 = newArray;
  17144. }
  17145. _this22.stackVec3[_this22.sizeVec3++] = anchor1;
  17146. }
  17147. let _this23 = this._pool;
  17148. if(anchor2 != null) {
  17149. anchor2.zero();
  17150. if(_this23.sizeVec3 == _this23.stackVec3.length) {
  17151. let newArray = new Array(_this23.sizeVec3 << 1);
  17152. let _g = 0;
  17153. let _g1 = _this23.sizeVec3;
  17154. while(_g < _g1) {
  17155. let i = _g++;
  17156. newArray[i] = _this23.stackVec3[i];
  17157. _this23.stackVec3[i] = null;
  17158. }
  17159. _this23.stackVec3 = newArray;
  17160. }
  17161. _this23.stackVec3[_this23.sizeVec3++] = anchor2;
  17162. }
  17163. let _this24 = this._pool;
  17164. if(basisX1 != null) {
  17165. basisX1.zero();
  17166. if(_this24.sizeVec3 == _this24.stackVec3.length) {
  17167. let newArray = new Array(_this24.sizeVec3 << 1);
  17168. let _g = 0;
  17169. let _g1 = _this24.sizeVec3;
  17170. while(_g < _g1) {
  17171. let i = _g++;
  17172. newArray[i] = _this24.stackVec3[i];
  17173. _this24.stackVec3[i] = null;
  17174. }
  17175. _this24.stackVec3 = newArray;
  17176. }
  17177. _this24.stackVec3[_this24.sizeVec3++] = basisX1;
  17178. }
  17179. let _this25 = this._pool;
  17180. if(basisY1 != null) {
  17181. basisY1.zero();
  17182. if(_this25.sizeVec3 == _this25.stackVec3.length) {
  17183. let newArray = new Array(_this25.sizeVec3 << 1);
  17184. let _g = 0;
  17185. let _g1 = _this25.sizeVec3;
  17186. while(_g < _g1) {
  17187. let i = _g++;
  17188. newArray[i] = _this25.stackVec3[i];
  17189. _this25.stackVec3[i] = null;
  17190. }
  17191. _this25.stackVec3 = newArray;
  17192. }
  17193. _this25.stackVec3[_this25.sizeVec3++] = basisY1;
  17194. }
  17195. let _this26 = this._pool;
  17196. if(basisZ1 != null) {
  17197. basisZ1.zero();
  17198. if(_this26.sizeVec3 == _this26.stackVec3.length) {
  17199. let newArray = new Array(_this26.sizeVec3 << 1);
  17200. let _g = 0;
  17201. let _g1 = _this26.sizeVec3;
  17202. while(_g < _g1) {
  17203. let i = _g++;
  17204. newArray[i] = _this26.stackVec3[i];
  17205. _this26.stackVec3[i] = null;
  17206. }
  17207. _this26.stackVec3 = newArray;
  17208. }
  17209. _this26.stackVec3[_this26.sizeVec3++] = basisZ1;
  17210. }
  17211. let _this27 = this._pool;
  17212. if(basisX2 != null) {
  17213. basisX2.zero();
  17214. if(_this27.sizeVec3 == _this27.stackVec3.length) {
  17215. let newArray = new Array(_this27.sizeVec3 << 1);
  17216. let _g = 0;
  17217. let _g1 = _this27.sizeVec3;
  17218. while(_g < _g1) {
  17219. let i = _g++;
  17220. newArray[i] = _this27.stackVec3[i];
  17221. _this27.stackVec3[i] = null;
  17222. }
  17223. _this27.stackVec3 = newArray;
  17224. }
  17225. _this27.stackVec3[_this27.sizeVec3++] = basisX2;
  17226. }
  17227. let _this28 = this._pool;
  17228. if(basisY2 != null) {
  17229. basisY2.zero();
  17230. if(_this28.sizeVec3 == _this28.stackVec3.length) {
  17231. let newArray = new Array(_this28.sizeVec3 << 1);
  17232. let _g = 0;
  17233. let _g1 = _this28.sizeVec3;
  17234. while(_g < _g1) {
  17235. let i = _g++;
  17236. newArray[i] = _this28.stackVec3[i];
  17237. _this28.stackVec3[i] = null;
  17238. }
  17239. _this28.stackVec3 = newArray;
  17240. }
  17241. _this28.stackVec3[_this28.sizeVec3++] = basisY2;
  17242. }
  17243. let _this29 = this._pool;
  17244. if(basisZ2 != null) {
  17245. basisZ2.zero();
  17246. if(_this29.sizeVec3 == _this29.stackVec3.length) {
  17247. let newArray = new Array(_this29.sizeVec3 << 1);
  17248. let _g = 0;
  17249. let _g1 = _this29.sizeVec3;
  17250. while(_g < _g1) {
  17251. let i = _g++;
  17252. newArray[i] = _this29.stackVec3[i];
  17253. _this29.stackVec3[i] = null;
  17254. }
  17255. _this29.stackVec3 = newArray;
  17256. }
  17257. _this29.stackVec3[_this29.sizeVec3++] = basisZ2;
  17258. }
  17259. j = n;
  17260. }
  17261. }
  17262. }
  17263. _drawRotationalLimit(d,center,ex,ey,needle,radius,min,max,color) {
  17264. if(min != max) {
  17265. let _this = this._pool;
  17266. let _this1 = _this.sizeVec3 == 0 ? new oimo.common.Vec3() : _this.stackVec3[--_this.sizeVec3];
  17267. _this1.x = center.x;
  17268. _this1.y = center.y;
  17269. _this1.z = center.z;
  17270. let _this2 = _this1;
  17271. _this2.x += needle.x * radius;
  17272. _this2.y += needle.y * radius;
  17273. _this2.z += needle.z * radius;
  17274. d.line(center,_this2,color);
  17275. let _this3 = this._pool;
  17276. if(_this2 != null) {
  17277. _this2.zero();
  17278. if(_this3.sizeVec3 == _this3.stackVec3.length) {
  17279. let newArray = new Array(_this3.sizeVec3 << 1);
  17280. let _g = 0;
  17281. let _g1 = _this3.sizeVec3;
  17282. while(_g < _g1) {
  17283. let i = _g++;
  17284. newArray[i] = _this3.stackVec3[i];
  17285. _this3.stackVec3[i] = null;
  17286. }
  17287. _this3.stackVec3 = newArray;
  17288. }
  17289. _this3.stackVec3[_this3.sizeVec3++] = _this2;
  17290. }
  17291. if(min > max) {
  17292. d.ellipse(center,ex,ey,radius,radius,color);
  17293. } else {
  17294. d.arc(center,ex,ey,radius,radius,min,max,true,color);
  17295. }
  17296. }
  17297. }
  17298. _drawTranslationalLimit(d,center,ex,min,max,color) {
  17299. if(min < max) {
  17300. let _this = this._pool;
  17301. let _this1 = _this.sizeVec3 == 0 ? new oimo.common.Vec3() : _this.stackVec3[--_this.sizeVec3];
  17302. _this1.x = center.x;
  17303. _this1.y = center.y;
  17304. _this1.z = center.z;
  17305. let _this2 = _this1;
  17306. _this2.x += ex.x * min;
  17307. _this2.y += ex.y * min;
  17308. _this2.z += ex.z * min;
  17309. let _this3 = this._pool;
  17310. let _this4 = _this3.sizeVec3 == 0 ? new oimo.common.Vec3() : _this3.stackVec3[--_this3.sizeVec3];
  17311. _this4.x = center.x;
  17312. _this4.y = center.y;
  17313. _this4.z = center.z;
  17314. let _this5 = _this4;
  17315. _this5.x += ex.x * max;
  17316. _this5.y += ex.y * max;
  17317. _this5.z += ex.z * max;
  17318. d.line(_this2,_this5,color);
  17319. let _this6 = this._pool;
  17320. if(_this2 != null) {
  17321. _this2.zero();
  17322. if(_this6.sizeVec3 == _this6.stackVec3.length) {
  17323. let newArray = new Array(_this6.sizeVec3 << 1);
  17324. let _g = 0;
  17325. let _g1 = _this6.sizeVec3;
  17326. while(_g < _g1) {
  17327. let i = _g++;
  17328. newArray[i] = _this6.stackVec3[i];
  17329. _this6.stackVec3[i] = null;
  17330. }
  17331. _this6.stackVec3 = newArray;
  17332. }
  17333. _this6.stackVec3[_this6.sizeVec3++] = _this2;
  17334. }
  17335. let _this7 = this._pool;
  17336. if(_this5 != null) {
  17337. _this5.zero();
  17338. if(_this7.sizeVec3 == _this7.stackVec3.length) {
  17339. let newArray = new Array(_this7.sizeVec3 << 1);
  17340. let _g = 0;
  17341. let _g1 = _this7.sizeVec3;
  17342. while(_g < _g1) {
  17343. let i = _g++;
  17344. newArray[i] = _this7.stackVec3[i];
  17345. _this7.stackVec3[i] = null;
  17346. }
  17347. _this7.stackVec3 = newArray;
  17348. }
  17349. _this7.stackVec3[_this7.sizeVec3++] = _this5;
  17350. }
  17351. }
  17352. }
  17353. _drawTranslationalLimit3D(d,center,ex,ey,ez,xlm,ylm,zlm,color) {
  17354. let minx = xlm.lowerLimit;
  17355. let maxx = xlm.upperLimit;
  17356. let miny = ylm.lowerLimit;
  17357. let maxy = ylm.upperLimit;
  17358. let minz = zlm.lowerLimit;
  17359. let maxz = zlm.upperLimit;
  17360. let _this = this._pool;
  17361. if(_this.sizeVec3 == 0) {
  17362. new oimo.common.Vec3();
  17363. } else {
  17364. --_this.sizeVec3;
  17365. }
  17366. let _this1 = this._pool;
  17367. if(_this1.sizeVec3 == 0) {
  17368. new oimo.common.Vec3();
  17369. } else {
  17370. --_this1.sizeVec3;
  17371. }
  17372. let _this2 = this._pool;
  17373. let _this3 = _this2.sizeVec3 == 0 ? new oimo.common.Vec3() : _this2.stackVec3[--_this2.sizeVec3];
  17374. _this3.x = center.x;
  17375. _this3.y = center.y;
  17376. _this3.z = center.z;
  17377. let _this4 = _this3;
  17378. _this4.x += ex.x * minx;
  17379. _this4.y += ex.y * minx;
  17380. _this4.z += ex.z * minx;
  17381. _this4.x += ey.x * miny;
  17382. _this4.y += ey.y * miny;
  17383. _this4.z += ey.z * miny;
  17384. _this4.x += ez.x * minz;
  17385. _this4.y += ez.y * minz;
  17386. _this4.z += ez.z * minz;
  17387. let _this5 = this._pool;
  17388. let _this6 = _this5.sizeVec3 == 0 ? new oimo.common.Vec3() : _this5.stackVec3[--_this5.sizeVec3];
  17389. _this6.x = center.x;
  17390. _this6.y = center.y;
  17391. _this6.z = center.z;
  17392. let _this7 = _this6;
  17393. _this7.x += ex.x * minx;
  17394. _this7.y += ex.y * minx;
  17395. _this7.z += ex.z * minx;
  17396. _this7.x += ey.x * miny;
  17397. _this7.y += ey.y * miny;
  17398. _this7.z += ey.z * miny;
  17399. _this7.x += ez.x * maxz;
  17400. _this7.y += ez.y * maxz;
  17401. _this7.z += ez.z * maxz;
  17402. let _this8 = this._pool;
  17403. let _this9 = _this8.sizeVec3 == 0 ? new oimo.common.Vec3() : _this8.stackVec3[--_this8.sizeVec3];
  17404. _this9.x = center.x;
  17405. _this9.y = center.y;
  17406. _this9.z = center.z;
  17407. let _this10 = _this9;
  17408. _this10.x += ex.x * minx;
  17409. _this10.y += ex.y * minx;
  17410. _this10.z += ex.z * minx;
  17411. _this10.x += ey.x * maxy;
  17412. _this10.y += ey.y * maxy;
  17413. _this10.z += ey.z * maxy;
  17414. _this10.x += ez.x * minz;
  17415. _this10.y += ez.y * minz;
  17416. _this10.z += ez.z * minz;
  17417. let _this11 = this._pool;
  17418. let _this12 = _this11.sizeVec3 == 0 ? new oimo.common.Vec3() : _this11.stackVec3[--_this11.sizeVec3];
  17419. _this12.x = center.x;
  17420. _this12.y = center.y;
  17421. _this12.z = center.z;
  17422. let _this13 = _this12;
  17423. _this13.x += ex.x * minx;
  17424. _this13.y += ex.y * minx;
  17425. _this13.z += ex.z * minx;
  17426. _this13.x += ey.x * maxy;
  17427. _this13.y += ey.y * maxy;
  17428. _this13.z += ey.z * maxy;
  17429. _this13.x += ez.x * maxz;
  17430. _this13.y += ez.y * maxz;
  17431. _this13.z += ez.z * maxz;
  17432. let _this14 = this._pool;
  17433. let _this15 = _this14.sizeVec3 == 0 ? new oimo.common.Vec3() : _this14.stackVec3[--_this14.sizeVec3];
  17434. _this15.x = center.x;
  17435. _this15.y = center.y;
  17436. _this15.z = center.z;
  17437. let _this16 = _this15;
  17438. _this16.x += ex.x * maxx;
  17439. _this16.y += ex.y * maxx;
  17440. _this16.z += ex.z * maxx;
  17441. _this16.x += ey.x * miny;
  17442. _this16.y += ey.y * miny;
  17443. _this16.z += ey.z * miny;
  17444. _this16.x += ez.x * minz;
  17445. _this16.y += ez.y * minz;
  17446. _this16.z += ez.z * minz;
  17447. let _this17 = this._pool;
  17448. let _this18 = _this17.sizeVec3 == 0 ? new oimo.common.Vec3() : _this17.stackVec3[--_this17.sizeVec3];
  17449. _this18.x = center.x;
  17450. _this18.y = center.y;
  17451. _this18.z = center.z;
  17452. let _this19 = _this18;
  17453. _this19.x += ex.x * maxx;
  17454. _this19.y += ex.y * maxx;
  17455. _this19.z += ex.z * maxx;
  17456. _this19.x += ey.x * miny;
  17457. _this19.y += ey.y * miny;
  17458. _this19.z += ey.z * miny;
  17459. _this19.x += ez.x * maxz;
  17460. _this19.y += ez.y * maxz;
  17461. _this19.z += ez.z * maxz;
  17462. let _this20 = this._pool;
  17463. let _this21 = _this20.sizeVec3 == 0 ? new oimo.common.Vec3() : _this20.stackVec3[--_this20.sizeVec3];
  17464. _this21.x = center.x;
  17465. _this21.y = center.y;
  17466. _this21.z = center.z;
  17467. let _this22 = _this21;
  17468. _this22.x += ex.x * maxx;
  17469. _this22.y += ex.y * maxx;
  17470. _this22.z += ex.z * maxx;
  17471. _this22.x += ey.x * maxy;
  17472. _this22.y += ey.y * maxy;
  17473. _this22.z += ey.z * maxy;
  17474. _this22.x += ez.x * minz;
  17475. _this22.y += ez.y * minz;
  17476. _this22.z += ez.z * minz;
  17477. let _this23 = this._pool;
  17478. let _this24 = _this23.sizeVec3 == 0 ? new oimo.common.Vec3() : _this23.stackVec3[--_this23.sizeVec3];
  17479. _this24.x = center.x;
  17480. _this24.y = center.y;
  17481. _this24.z = center.z;
  17482. let _this25 = _this24;
  17483. _this25.x += ex.x * maxx;
  17484. _this25.y += ex.y * maxx;
  17485. _this25.z += ex.z * maxx;
  17486. _this25.x += ey.x * maxy;
  17487. _this25.y += ey.y * maxy;
  17488. _this25.z += ey.z * maxy;
  17489. _this25.x += ez.x * maxz;
  17490. _this25.y += ez.y * maxz;
  17491. _this25.z += ez.z * maxz;
  17492. d.line(_this4,_this16,color);
  17493. d.line(_this10,_this22,color);
  17494. d.line(_this7,_this19,color);
  17495. d.line(_this13,_this25,color);
  17496. d.line(_this4,_this10,color);
  17497. d.line(_this16,_this22,color);
  17498. d.line(_this7,_this13,color);
  17499. d.line(_this19,_this25,color);
  17500. d.line(_this4,_this7,color);
  17501. d.line(_this16,_this19,color);
  17502. d.line(_this10,_this13,color);
  17503. d.line(_this22,_this25,color);
  17504. let _this26 = this._pool;
  17505. if(_this4 != null) {
  17506. _this4.zero();
  17507. if(_this26.sizeVec3 == _this26.stackVec3.length) {
  17508. let newArray = new Array(_this26.sizeVec3 << 1);
  17509. let _g = 0;
  17510. let _g1 = _this26.sizeVec3;
  17511. while(_g < _g1) {
  17512. let i = _g++;
  17513. newArray[i] = _this26.stackVec3[i];
  17514. _this26.stackVec3[i] = null;
  17515. }
  17516. _this26.stackVec3 = newArray;
  17517. }
  17518. _this26.stackVec3[_this26.sizeVec3++] = _this4;
  17519. }
  17520. let _this27 = this._pool;
  17521. if(_this7 != null) {
  17522. _this7.zero();
  17523. if(_this27.sizeVec3 == _this27.stackVec3.length) {
  17524. let newArray = new Array(_this27.sizeVec3 << 1);
  17525. let _g = 0;
  17526. let _g1 = _this27.sizeVec3;
  17527. while(_g < _g1) {
  17528. let i = _g++;
  17529. newArray[i] = _this27.stackVec3[i];
  17530. _this27.stackVec3[i] = null;
  17531. }
  17532. _this27.stackVec3 = newArray;
  17533. }
  17534. _this27.stackVec3[_this27.sizeVec3++] = _this7;
  17535. }
  17536. let _this28 = this._pool;
  17537. if(_this10 != null) {
  17538. _this10.zero();
  17539. if(_this28.sizeVec3 == _this28.stackVec3.length) {
  17540. let newArray = new Array(_this28.sizeVec3 << 1);
  17541. let _g = 0;
  17542. let _g1 = _this28.sizeVec3;
  17543. while(_g < _g1) {
  17544. let i = _g++;
  17545. newArray[i] = _this28.stackVec3[i];
  17546. _this28.stackVec3[i] = null;
  17547. }
  17548. _this28.stackVec3 = newArray;
  17549. }
  17550. _this28.stackVec3[_this28.sizeVec3++] = _this10;
  17551. }
  17552. let _this29 = this._pool;
  17553. if(_this13 != null) {
  17554. _this13.zero();
  17555. if(_this29.sizeVec3 == _this29.stackVec3.length) {
  17556. let newArray = new Array(_this29.sizeVec3 << 1);
  17557. let _g = 0;
  17558. let _g1 = _this29.sizeVec3;
  17559. while(_g < _g1) {
  17560. let i = _g++;
  17561. newArray[i] = _this29.stackVec3[i];
  17562. _this29.stackVec3[i] = null;
  17563. }
  17564. _this29.stackVec3 = newArray;
  17565. }
  17566. _this29.stackVec3[_this29.sizeVec3++] = _this13;
  17567. }
  17568. let _this30 = this._pool;
  17569. if(_this16 != null) {
  17570. _this16.zero();
  17571. if(_this30.sizeVec3 == _this30.stackVec3.length) {
  17572. let newArray = new Array(_this30.sizeVec3 << 1);
  17573. let _g = 0;
  17574. let _g1 = _this30.sizeVec3;
  17575. while(_g < _g1) {
  17576. let i = _g++;
  17577. newArray[i] = _this30.stackVec3[i];
  17578. _this30.stackVec3[i] = null;
  17579. }
  17580. _this30.stackVec3 = newArray;
  17581. }
  17582. _this30.stackVec3[_this30.sizeVec3++] = _this16;
  17583. }
  17584. let _this31 = this._pool;
  17585. if(_this19 != null) {
  17586. _this19.zero();
  17587. if(_this31.sizeVec3 == _this31.stackVec3.length) {
  17588. let newArray = new Array(_this31.sizeVec3 << 1);
  17589. let _g = 0;
  17590. let _g1 = _this31.sizeVec3;
  17591. while(_g < _g1) {
  17592. let i = _g++;
  17593. newArray[i] = _this31.stackVec3[i];
  17594. _this31.stackVec3[i] = null;
  17595. }
  17596. _this31.stackVec3 = newArray;
  17597. }
  17598. _this31.stackVec3[_this31.sizeVec3++] = _this19;
  17599. }
  17600. let _this32 = this._pool;
  17601. if(_this22 != null) {
  17602. _this22.zero();
  17603. if(_this32.sizeVec3 == _this32.stackVec3.length) {
  17604. let newArray = new Array(_this32.sizeVec3 << 1);
  17605. let _g = 0;
  17606. let _g1 = _this32.sizeVec3;
  17607. while(_g < _g1) {
  17608. let i = _g++;
  17609. newArray[i] = _this32.stackVec3[i];
  17610. _this32.stackVec3[i] = null;
  17611. }
  17612. _this32.stackVec3 = newArray;
  17613. }
  17614. _this32.stackVec3[_this32.sizeVec3++] = _this22;
  17615. }
  17616. let _this33 = this._pool;
  17617. if(_this25 != null) {
  17618. _this25.zero();
  17619. if(_this33.sizeVec3 == _this33.stackVec3.length) {
  17620. let newArray = new Array(_this33.sizeVec3 << 1);
  17621. let _g = 0;
  17622. let _g1 = _this33.sizeVec3;
  17623. while(_g < _g1) {
  17624. let i = _g++;
  17625. newArray[i] = _this33.stackVec3[i];
  17626. _this33.stackVec3[i] = null;
  17627. }
  17628. _this33.stackVec3 = newArray;
  17629. }
  17630. _this33.stackVec3[_this33.sizeVec3++] = _this25;
  17631. }
  17632. }
  17633. _drawEllipseOnSphere(d,center,normal,x,y,radiansX,radiansY,radius,color) {
  17634. let theta = 0;
  17635. let _this = this._pool;
  17636. let rotVec = _this.sizeVec3 == 0 ? new oimo.common.Vec3() : _this.stackVec3[--_this.sizeVec3];
  17637. let _this1 = this._pool;
  17638. let rotQ = _this1.sizeQuat == 0 ? new oimo.common.Quat() : _this1.stackQuat[--_this1.sizeQuat];
  17639. let _this2 = this._pool;
  17640. let rotM = _this2.sizeMat3 == 0 ? new oimo.common.Mat3() : _this2.stackMat3[--_this2.sizeMat3];
  17641. let _this3 = this._pool;
  17642. let prevV = _this3.sizeVec3 == 0 ? new oimo.common.Vec3() : _this3.stackVec3[--_this3.sizeVec3];
  17643. let _g = 0;
  17644. while(_g < 17) {
  17645. let i = _g++;
  17646. let rx = Math.cos(theta) * radiansX;
  17647. let ry = Math.sin(theta) * radiansY;
  17648. let halfRotAng = Math.sqrt(rx * rx + ry * ry);
  17649. let rotSin = Math.sin(halfRotAng * 0.5);
  17650. let rotCos = Math.cos(halfRotAng * 0.5);
  17651. let _this = rotVec.zero();
  17652. _this.x += x.x * rx;
  17653. _this.y += x.y * rx;
  17654. _this.z += x.z * rx;
  17655. _this.x += y.x * ry;
  17656. _this.y += y.y * ry;
  17657. _this.z += y.z * ry;
  17658. let s = 1 / halfRotAng * rotSin;
  17659. rotVec.x *= s;
  17660. rotVec.y *= s;
  17661. rotVec.z *= s;
  17662. rotQ.x = rotVec.x;
  17663. rotQ.y = rotVec.y;
  17664. rotQ.z = rotVec.z;
  17665. rotQ.w = rotCos;
  17666. let x1 = rotQ.x;
  17667. let y1 = rotQ.y;
  17668. let z = rotQ.z;
  17669. let w = rotQ.w;
  17670. let x2 = 2 * x1;
  17671. let y2 = 2 * y1;
  17672. let z2 = 2 * z;
  17673. let xx = x1 * x2;
  17674. let yy = y1 * y2;
  17675. let zz = z * z2;
  17676. let xy = x1 * y2;
  17677. let yz = y1 * z2;
  17678. let xz = x1 * z2;
  17679. let wx = w * x2;
  17680. let wy = w * y2;
  17681. let wz = w * z2;
  17682. rotM.e00 = 1 - yy - zz;
  17683. rotM.e01 = xy - wz;
  17684. rotM.e02 = xz + wy;
  17685. rotM.e10 = xy + wz;
  17686. rotM.e11 = 1 - xx - zz;
  17687. rotM.e12 = yz - wx;
  17688. rotM.e20 = xz - wy;
  17689. rotM.e21 = yz + wx;
  17690. rotM.e22 = 1 - xx - yy;
  17691. let _this1 = this._pool;
  17692. let _this2 = _this1.sizeVec3 == 0 ? new oimo.common.Vec3() : _this1.stackVec3[--_this1.sizeVec3];
  17693. _this2.x += normal.x * radius;
  17694. _this2.y += normal.y * radius;
  17695. _this2.z += normal.z * radius;
  17696. let v = _this2;
  17697. let y3 = v.x * rotM.e10 + v.y * rotM.e11 + v.z * rotM.e12;
  17698. let z1 = v.x * rotM.e20 + v.y * rotM.e21 + v.z * rotM.e22;
  17699. v.x = v.x * rotM.e00 + v.y * rotM.e01 + v.z * rotM.e02;
  17700. v.y = y3;
  17701. v.z = z1;
  17702. v.x += center.x;
  17703. v.y += center.y;
  17704. v.z += center.z;
  17705. if(i >= 1) {
  17706. d.line(prevV,v,color);
  17707. }
  17708. let _this3 = this._pool;
  17709. if(prevV != null) {
  17710. prevV.zero();
  17711. if(_this3.sizeVec3 == _this3.stackVec3.length) {
  17712. let newArray = new Array(_this3.sizeVec3 << 1);
  17713. let _g = 0;
  17714. let _g1 = _this3.sizeVec3;
  17715. while(_g < _g1) {
  17716. let i = _g++;
  17717. newArray[i] = _this3.stackVec3[i];
  17718. _this3.stackVec3[i] = null;
  17719. }
  17720. _this3.stackVec3 = newArray;
  17721. }
  17722. _this3.stackVec3[_this3.sizeVec3++] = prevV;
  17723. }
  17724. prevV = v;
  17725. theta += 0.39269908169872375;
  17726. }
  17727. let _this4 = this._pool;
  17728. if(rotVec != null) {
  17729. rotVec.zero();
  17730. if(_this4.sizeVec3 == _this4.stackVec3.length) {
  17731. let newArray = new Array(_this4.sizeVec3 << 1);
  17732. let _g = 0;
  17733. let _g1 = _this4.sizeVec3;
  17734. while(_g < _g1) {
  17735. let i = _g++;
  17736. newArray[i] = _this4.stackVec3[i];
  17737. _this4.stackVec3[i] = null;
  17738. }
  17739. _this4.stackVec3 = newArray;
  17740. }
  17741. _this4.stackVec3[_this4.sizeVec3++] = rotVec;
  17742. }
  17743. let _this5 = this._pool;
  17744. if(rotQ != null) {
  17745. rotQ.x = 0;
  17746. rotQ.y = 0;
  17747. rotQ.z = 0;
  17748. rotQ.w = 1;
  17749. if(_this5.sizeQuat == _this5.stackQuat.length) {
  17750. let newArray = new Array(_this5.sizeQuat << 1);
  17751. let _g = 0;
  17752. let _g1 = _this5.sizeQuat;
  17753. while(_g < _g1) {
  17754. let i = _g++;
  17755. newArray[i] = _this5.stackQuat[i];
  17756. _this5.stackQuat[i] = null;
  17757. }
  17758. _this5.stackQuat = newArray;
  17759. }
  17760. _this5.stackQuat[_this5.sizeQuat++] = rotQ;
  17761. }
  17762. let _this6 = this._pool;
  17763. if(rotM != null) {
  17764. rotM.e00 = 1;
  17765. rotM.e01 = 0;
  17766. rotM.e02 = 0;
  17767. rotM.e10 = 0;
  17768. rotM.e11 = 1;
  17769. rotM.e12 = 0;
  17770. rotM.e20 = 0;
  17771. rotM.e21 = 0;
  17772. rotM.e22 = 1;
  17773. if(_this6.sizeMat3 == _this6.stackMat3.length) {
  17774. let newArray = new Array(_this6.sizeMat3 << 1);
  17775. let _g = 0;
  17776. let _g1 = _this6.sizeMat3;
  17777. while(_g < _g1) {
  17778. let i = _g++;
  17779. newArray[i] = _this6.stackMat3[i];
  17780. _this6.stackMat3[i] = null;
  17781. }
  17782. _this6.stackMat3 = newArray;
  17783. }
  17784. _this6.stackMat3[_this6.sizeMat3++] = rotM;
  17785. }
  17786. let _this7 = this._pool;
  17787. if(prevV != null) {
  17788. prevV.zero();
  17789. if(_this7.sizeVec3 == _this7.stackVec3.length) {
  17790. let newArray = new Array(_this7.sizeVec3 << 1);
  17791. let _g = 0;
  17792. let _g1 = _this7.sizeVec3;
  17793. while(_g < _g1) {
  17794. let i = _g++;
  17795. newArray[i] = _this7.stackVec3[i];
  17796. _this7.stackVec3[i] = null;
  17797. }
  17798. _this7.stackVec3 = newArray;
  17799. }
  17800. _this7.stackVec3[_this7.sizeVec3++] = prevV;
  17801. }
  17802. }
  17803. step(timeStep) {
  17804. if(this._timeStep.dt > 0) {
  17805. this._timeStep.dtRatio = timeStep / this._timeStep.dt;
  17806. }
  17807. this._timeStep.dt = timeStep;
  17808. this._timeStep.invDt = 1 / timeStep;
  17809. let st = Date.now() / 1000;
  17810. this._updateContacts();
  17811. this._solveIslands();
  17812. oimo.dynamics.common.Performance.totalTime = (Date.now() / 1000 - st) * 1000;
  17813. }
  17814. addRigidBody(rigidBody) {
  17815. if(rigidBody._world != null) {
  17816. throw new Error("A rigid body cannot belong to multiple worlds.");
  17817. }
  17818. if(this._rigidBodyList == null) {
  17819. this._rigidBodyList = rigidBody;
  17820. this._rigidBodyListLast = rigidBody;
  17821. } else {
  17822. this._rigidBodyListLast._next = rigidBody;
  17823. rigidBody._prev = this._rigidBodyListLast;
  17824. this._rigidBodyListLast = rigidBody;
  17825. }
  17826. rigidBody._world = this;
  17827. let s = rigidBody._shapeList;
  17828. while(s != null) {
  17829. let n = s._next;
  17830. s._proxy = this._broadPhase.createProxy(s,s._aabb);
  17831. s._id = this._shapeIdCount++;
  17832. this._numShapes++;
  17833. s = n;
  17834. }
  17835. this._numRigidBodies++;
  17836. }
  17837. removeRigidBody(rigidBody) {
  17838. if(rigidBody._world != this) {
  17839. throw new Error("The rigid body doesn't belong to the world.");
  17840. }
  17841. let prev = rigidBody._prev;
  17842. let next = rigidBody._next;
  17843. if(prev != null) {
  17844. prev._next = next;
  17845. }
  17846. if(next != null) {
  17847. next._prev = prev;
  17848. }
  17849. if(rigidBody == this._rigidBodyList) {
  17850. this._rigidBodyList = this._rigidBodyList._next;
  17851. }
  17852. if(rigidBody == this._rigidBodyListLast) {
  17853. this._rigidBodyListLast = this._rigidBodyListLast._prev;
  17854. }
  17855. rigidBody._next = null;
  17856. rigidBody._prev = null;
  17857. rigidBody._world = null;
  17858. let s = rigidBody._shapeList;
  17859. while(s != null) {
  17860. let n = s._next;
  17861. this._broadPhase.destroyProxy(s._proxy);
  17862. s._proxy = null;
  17863. s._id = -1;
  17864. let cl = s._rigidBody._contactLinkList;
  17865. while(cl != null) {
  17866. let n = cl._next;
  17867. let c = cl._contact;
  17868. if(c._s1 == s || c._s2 == s) {
  17869. let _this = cl._other;
  17870. _this._sleeping = false;
  17871. _this._sleepTime = 0;
  17872. let _this1 = this._contactManager;
  17873. let prev = c._prev;
  17874. let next = c._next;
  17875. if(prev != null) {
  17876. prev._next = next;
  17877. }
  17878. if(next != null) {
  17879. next._prev = prev;
  17880. }
  17881. if(c == _this1._contactList) {
  17882. _this1._contactList = _this1._contactList._next;
  17883. }
  17884. if(c == _this1._contactListLast) {
  17885. _this1._contactListLast = _this1._contactListLast._prev;
  17886. }
  17887. c._next = null;
  17888. c._prev = null;
  17889. if(c._touching) {
  17890. let cc1 = c._s1._contactCallback;
  17891. let cc2 = c._s2._contactCallback;
  17892. if(cc1 == cc2) {
  17893. cc2 = null;
  17894. }
  17895. if(cc1 != null) {
  17896. cc1.endContact(c);
  17897. }
  17898. if(cc2 != null) {
  17899. cc2.endContact(c);
  17900. }
  17901. }
  17902. let prev1 = c._link1._prev;
  17903. let next1 = c._link1._next;
  17904. if(prev1 != null) {
  17905. prev1._next = next1;
  17906. }
  17907. if(next1 != null) {
  17908. next1._prev = prev1;
  17909. }
  17910. if(c._link1 == c._b1._contactLinkList) {
  17911. c._b1._contactLinkList = c._b1._contactLinkList._next;
  17912. }
  17913. if(c._link1 == c._b1._contactLinkListLast) {
  17914. c._b1._contactLinkListLast = c._b1._contactLinkListLast._prev;
  17915. }
  17916. c._link1._next = null;
  17917. c._link1._prev = null;
  17918. let prev2 = c._link2._prev;
  17919. let next2 = c._link2._next;
  17920. if(prev2 != null) {
  17921. prev2._next = next2;
  17922. }
  17923. if(next2 != null) {
  17924. next2._prev = prev2;
  17925. }
  17926. if(c._link2 == c._b2._contactLinkList) {
  17927. c._b2._contactLinkList = c._b2._contactLinkList._next;
  17928. }
  17929. if(c._link2 == c._b2._contactLinkListLast) {
  17930. c._b2._contactLinkListLast = c._b2._contactLinkListLast._prev;
  17931. }
  17932. c._link2._next = null;
  17933. c._link2._prev = null;
  17934. c._b1._numContactLinks--;
  17935. c._b2._numContactLinks--;
  17936. c._link1._other = null;
  17937. c._link2._other = null;
  17938. c._link1._contact = null;
  17939. c._link2._contact = null;
  17940. c._s1 = null;
  17941. c._s2 = null;
  17942. c._b1 = null;
  17943. c._b2 = null;
  17944. c._touching = false;
  17945. c._cachedDetectorData._clear();
  17946. c._manifold._clear();
  17947. c._detector = null;
  17948. let _this2 = c._contactConstraint;
  17949. _this2._s1 = null;
  17950. _this2._s2 = null;
  17951. _this2._b1 = null;
  17952. _this2._b2 = null;
  17953. _this2._tf1 = null;
  17954. _this2._tf2 = null;
  17955. c._next = _this1._contactPool;
  17956. _this1._contactPool = c;
  17957. _this1._numContacts--;
  17958. }
  17959. cl = n;
  17960. }
  17961. this._numShapes--;
  17962. s = n;
  17963. }
  17964. this._numRigidBodies--;
  17965. }
  17966. addJoint(joint) {
  17967. if(joint._world != null) {
  17968. throw new Error("A joint cannot belong to multiple worlds.");
  17969. }
  17970. if(this._jointList == null) {
  17971. this._jointList = joint;
  17972. this._jointListLast = joint;
  17973. } else {
  17974. this._jointListLast._next = joint;
  17975. joint._prev = this._jointListLast;
  17976. this._jointListLast = joint;
  17977. }
  17978. joint._world = this;
  17979. joint._link1._other = joint._b2;
  17980. joint._link2._other = joint._b1;
  17981. if(joint._b1._jointLinkList == null) {
  17982. joint._b1._jointLinkList = joint._link1;
  17983. joint._b1._jointLinkListLast = joint._link1;
  17984. } else {
  17985. joint._b1._jointLinkListLast._next = joint._link1;
  17986. joint._link1._prev = joint._b1._jointLinkListLast;
  17987. joint._b1._jointLinkListLast = joint._link1;
  17988. }
  17989. if(joint._b2._jointLinkList == null) {
  17990. joint._b2._jointLinkList = joint._link2;
  17991. joint._b2._jointLinkListLast = joint._link2;
  17992. } else {
  17993. joint._b2._jointLinkListLast._next = joint._link2;
  17994. joint._link2._prev = joint._b2._jointLinkListLast;
  17995. joint._b2._jointLinkListLast = joint._link2;
  17996. }
  17997. joint._b1._numJointLinks++;
  17998. joint._b2._numJointLinks++;
  17999. let _this = joint._b1;
  18000. _this._sleeping = false;
  18001. _this._sleepTime = 0;
  18002. let _this1 = joint._b2;
  18003. _this1._sleeping = false;
  18004. _this1._sleepTime = 0;
  18005. joint._syncAnchors();
  18006. this._numJoints++;
  18007. }
  18008. removeJoint(joint) {
  18009. if(joint._world != this) {
  18010. throw new Error("The joint doesn't belong to the world.");
  18011. }
  18012. let prev = joint._prev;
  18013. let next = joint._next;
  18014. if(prev != null) {
  18015. prev._next = next;
  18016. }
  18017. if(next != null) {
  18018. next._prev = prev;
  18019. }
  18020. if(joint == this._jointList) {
  18021. this._jointList = this._jointList._next;
  18022. }
  18023. if(joint == this._jointListLast) {
  18024. this._jointListLast = this._jointListLast._prev;
  18025. }
  18026. joint._next = null;
  18027. joint._prev = null;
  18028. joint._world = null;
  18029. let prev1 = joint._link1._prev;
  18030. let next1 = joint._link1._next;
  18031. if(prev1 != null) {
  18032. prev1._next = next1;
  18033. }
  18034. if(next1 != null) {
  18035. next1._prev = prev1;
  18036. }
  18037. if(joint._link1 == joint._b1._jointLinkList) {
  18038. joint._b1._jointLinkList = joint._b1._jointLinkList._next;
  18039. }
  18040. if(joint._link1 == joint._b1._jointLinkListLast) {
  18041. joint._b1._jointLinkListLast = joint._b1._jointLinkListLast._prev;
  18042. }
  18043. joint._link1._next = null;
  18044. joint._link1._prev = null;
  18045. let prev2 = joint._link2._prev;
  18046. let next2 = joint._link2._next;
  18047. if(prev2 != null) {
  18048. prev2._next = next2;
  18049. }
  18050. if(next2 != null) {
  18051. next2._prev = prev2;
  18052. }
  18053. if(joint._link2 == joint._b2._jointLinkList) {
  18054. joint._b2._jointLinkList = joint._b2._jointLinkList._next;
  18055. }
  18056. if(joint._link2 == joint._b2._jointLinkListLast) {
  18057. joint._b2._jointLinkListLast = joint._b2._jointLinkListLast._prev;
  18058. }
  18059. joint._link2._next = null;
  18060. joint._link2._prev = null;
  18061. joint._link1._other = null;
  18062. joint._link2._other = null;
  18063. joint._b1._numJointLinks--;
  18064. joint._b2._numJointLinks--;
  18065. let _this = joint._b1;
  18066. _this._sleeping = false;
  18067. _this._sleepTime = 0;
  18068. let _this1 = joint._b2;
  18069. _this1._sleeping = false;
  18070. _this1._sleepTime = 0;
  18071. this._numJoints--;
  18072. }
  18073. setDebugDraw(debugDraw) {
  18074. this._debugDraw = debugDraw;
  18075. }
  18076. getDebugDraw() {
  18077. return this._debugDraw;
  18078. }
  18079. debugDraw() {
  18080. if(this._debugDraw != null) {
  18081. if(this._broadPhase._type == 2) {
  18082. this._drawBvh(this._debugDraw,this._broadPhase._tree);
  18083. }
  18084. this._drawRigidBodies(this._debugDraw);
  18085. this._drawConstraints(this._debugDraw);
  18086. }
  18087. }
  18088. rayCast(begin,end,callback) {
  18089. let _this = this._rayCastWrapper.begin;
  18090. _this.x = begin.x;
  18091. _this.y = begin.y;
  18092. _this.z = begin.z;
  18093. let _this1 = this._rayCastWrapper.end;
  18094. _this1.x = end.x;
  18095. _this1.y = end.y;
  18096. _this1.z = end.z;
  18097. this._rayCastWrapper.callback = callback;
  18098. this._broadPhase.rayCast(begin,end,this._rayCastWrapper);
  18099. }
  18100. convexCast(convex,begin,translation,callback) {
  18101. this._convexCastWrapper.convex = convex;
  18102. let _this = this._convexCastWrapper.begin;
  18103. _this._positionX = begin._positionX;
  18104. _this._positionY = begin._positionY;
  18105. _this._positionZ = begin._positionZ;
  18106. _this._rotation00 = begin._rotation00;
  18107. _this._rotation01 = begin._rotation01;
  18108. _this._rotation02 = begin._rotation02;
  18109. _this._rotation10 = begin._rotation10;
  18110. _this._rotation11 = begin._rotation11;
  18111. _this._rotation12 = begin._rotation12;
  18112. _this._rotation20 = begin._rotation20;
  18113. _this._rotation21 = begin._rotation21;
  18114. _this._rotation22 = begin._rotation22;
  18115. let _this1 = this._convexCastWrapper.translation;
  18116. _this1.x = translation.x;
  18117. _this1.y = translation.y;
  18118. _this1.z = translation.z;
  18119. this._convexCastWrapper.callback = callback;
  18120. this._broadPhase.convexCast(convex,begin,translation,this._convexCastWrapper);
  18121. }
  18122. aabbTest(aabb,callback) {
  18123. this._aabbTestWrapper._aabb.copyFrom(aabb);
  18124. this._aabbTestWrapper._callback = callback;
  18125. this._broadPhase.aabbTest(aabb,this._aabbTestWrapper);
  18126. }
  18127. getRigidBodyList() {
  18128. return this._rigidBodyList;
  18129. }
  18130. getJointList() {
  18131. return this._jointList;
  18132. }
  18133. getBroadPhase() {
  18134. return this._broadPhase;
  18135. }
  18136. getContactManager() {
  18137. return this._contactManager;
  18138. }
  18139. getNumRigidBodies() {
  18140. return this._numRigidBodies;
  18141. }
  18142. getNumJoints() {
  18143. return this._numJoints;
  18144. }
  18145. getNumShapes() {
  18146. return this._numShapes;
  18147. }
  18148. getNumIslands() {
  18149. return this._numIslands;
  18150. }
  18151. getNumVelocityIterations() {
  18152. return this._numVelocityIterations;
  18153. }
  18154. setNumVelocityIterations(numVelocityIterations) {
  18155. this._numVelocityIterations = numVelocityIterations;
  18156. }
  18157. getNumPositionIterations() {
  18158. return this._numPositionIterations;
  18159. }
  18160. setNumPositionIterations(numPositionIterations) {
  18161. this._numPositionIterations = numPositionIterations;
  18162. }
  18163. getGravity() {
  18164. return this._gravity;
  18165. }
  18166. setGravity(gravity) {
  18167. let _this = this._gravity;
  18168. _this.x = gravity.x;
  18169. _this.y = gravity.y;
  18170. _this.z = gravity.z;
  18171. }
  18172. }
  18173. if(!oimo.dynamics._World) oimo.dynamics._World = {};
  18174. oimo.dynamics._World.RayCastWrapper = class oimo_dynamics__$World_RayCastWrapper extends oimo.collision.broadphase.BroadPhaseProxyCallback {
  18175. constructor() {
  18176. super();
  18177. this.rayCastHit = new oimo.collision.geometry.RayCastHit();
  18178. this.begin = new oimo.common.Vec3();
  18179. this.end = new oimo.common.Vec3();
  18180. this.callback = null;
  18181. }
  18182. process(proxy) {
  18183. let shape = proxy.userData;
  18184. if(shape._geom.rayCast(this.begin,this.end,shape._transform,this.rayCastHit)) {
  18185. this.callback.process(shape,this.rayCastHit);
  18186. }
  18187. }
  18188. }
  18189. oimo.dynamics._World.ConvexCastWrapper = class oimo_dynamics__$World_ConvexCastWrapper extends oimo.collision.broadphase.BroadPhaseProxyCallback {
  18190. constructor() {
  18191. super();
  18192. this.rayCastHit = new oimo.collision.geometry.RayCastHit();
  18193. this.begin = new oimo.common.Transform();
  18194. this.translation = new oimo.common.Vec3();
  18195. this.zero = new oimo.common.Vec3();
  18196. this.callback = null;
  18197. this.convex = null;
  18198. }
  18199. process(proxy) {
  18200. let shape = proxy.userData;
  18201. let type = shape._geom._type;
  18202. if(type < 0 || type > 5) {
  18203. return;
  18204. }
  18205. if(oimo.collision.narrowphase.detector.gjkepa.GjkEpa.instance.convexCast(this.convex,shape._geom,this.begin,shape._transform,this.translation,this.zero,this.rayCastHit)) {
  18206. this.callback.process(shape,this.rayCastHit);
  18207. }
  18208. }
  18209. }
  18210. oimo.dynamics._World.AabbTestWrapper = class oimo_dynamics__$World_AabbTestWrapper extends oimo.collision.broadphase.BroadPhaseProxyCallback {
  18211. constructor() {
  18212. super();
  18213. this._aabb = new oimo.collision.geometry.Aabb();
  18214. this._callback = null;
  18215. }
  18216. process(proxy) {
  18217. let shape = proxy.userData;
  18218. let shapeAabb = shape._aabb;
  18219. if(shapeAabb._minX < this._aabb._maxX && shapeAabb._maxX > this._aabb._minX && shapeAabb._minY < this._aabb._maxY && shapeAabb._maxY > this._aabb._minY && shapeAabb._minZ < this._aabb._maxZ && shapeAabb._maxZ > this._aabb._minZ) {
  18220. this._callback.process(shape);
  18221. }
  18222. }
  18223. }
  18224. if(!oimo.dynamics.callback) oimo.dynamics.callback = {};
  18225. oimo.dynamics.callback.AabbTestCallback = class oimo_dynamics_callback_AabbTestCallback {
  18226. constructor() {
  18227. }
  18228. process(shape) {
  18229. }
  18230. }
  18231. oimo.dynamics.callback.ContactCallback = class oimo_dynamics_callback_ContactCallback {
  18232. constructor() {
  18233. }
  18234. beginContact(c) {
  18235. }
  18236. preSolve(c) {
  18237. }
  18238. postSolve(c) {
  18239. }
  18240. endContact(c) {
  18241. }
  18242. }
  18243. oimo.dynamics.callback.RayCastCallback = class oimo_dynamics_callback_RayCastCallback {
  18244. constructor() {
  18245. }
  18246. process(shape,hit) {
  18247. }
  18248. }
  18249. oimo.dynamics.callback.RayCastClosest = class oimo_dynamics_callback_RayCastClosest extends oimo.dynamics.callback.RayCastCallback {
  18250. constructor() {
  18251. super();
  18252. this.position = new oimo.common.Vec3();
  18253. this.normal = new oimo.common.Vec3();
  18254. this.shape = null;
  18255. this.fraction = 1;
  18256. this.position.zero();
  18257. this.normal.zero();
  18258. this.hit = false;
  18259. }
  18260. clear() {
  18261. this.shape = null;
  18262. this.fraction = 1;
  18263. this.position.zero();
  18264. this.normal.zero();
  18265. this.hit = false;
  18266. }
  18267. process(shape,hit) {
  18268. if(hit.fraction < this.fraction) {
  18269. this.shape = shape;
  18270. this.hit = true;
  18271. this.fraction = hit.fraction;
  18272. let _this = this.position;
  18273. let v = hit.position;
  18274. _this.x = v.x;
  18275. _this.y = v.y;
  18276. _this.z = v.z;
  18277. let _this1 = this.normal;
  18278. let v1 = hit.normal;
  18279. _this1.x = v1.x;
  18280. _this1.y = v1.y;
  18281. _this1.z = v1.z;
  18282. }
  18283. }
  18284. }
  18285. if(!oimo.dynamics.common) oimo.dynamics.common = {};
  18286. oimo.dynamics.common.DebugDraw = class oimo_dynamics_common_DebugDraw {
  18287. constructor() {
  18288. this.p = new oimo.common.Pool();
  18289. this.wireframe = false;
  18290. this.drawShapes = true;
  18291. this.drawBvh = false;
  18292. this.drawBvhMinLevel = 0;
  18293. this.drawBvhMaxLevel = 65536;
  18294. this.drawAabbs = false;
  18295. this.drawBases = false;
  18296. this.drawPairs = false;
  18297. this.drawContacts = false;
  18298. this.drawJoints = true;
  18299. this.drawJointLimits = false;
  18300. this.sphereCoords = new Array(5);
  18301. this.tmpSphereVerts = new Array(5);
  18302. this.tmpSphereNorms = new Array(5);
  18303. let _g = 0;
  18304. while(_g < 5) {
  18305. let i = _g++;
  18306. let num = i == 0 || i == 4 ? 1 : 8;
  18307. this.sphereCoords[i] = new Array(num);
  18308. this.tmpSphereVerts[i] = new Array(num);
  18309. this.tmpSphereNorms[i] = new Array(num);
  18310. let _g1 = 0;
  18311. while(_g1 < 8) {
  18312. let j = _g1++;
  18313. let theta = i * 0.7853981633974475;
  18314. let phi = j * 0.7853981633974475;
  18315. this.sphereCoords[i][j] = new oimo.common.Vec3(Math.sin(theta) * Math.cos(phi),Math.cos(theta),-Math.sin(theta) * Math.sin(phi));
  18316. this.tmpSphereVerts[i][j] = new oimo.common.Vec3();
  18317. this.tmpSphereNorms[i][j] = new oimo.common.Vec3();
  18318. }
  18319. }
  18320. this.circleCoords = new Array(8);
  18321. this.circleCoordsShift = new Array(8);
  18322. this.tmpCircleVerts1 = new Array(8);
  18323. this.tmpCircleVerts2 = new Array(8);
  18324. this.tmpCircleNorms = new Array(8);
  18325. let _g1 = 0;
  18326. while(_g1 < 8) {
  18327. let i = _g1++;
  18328. this.circleCoords[i] = new oimo.common.Vec3(Math.cos(i * 0.7853981633974475),0,-Math.sin(i * 0.7853981633974475));
  18329. this.circleCoordsShift[i] = new oimo.common.Vec3(Math.cos((i + 0.5) * 0.7853981633974475),0,-Math.sin((i + 0.5) * 0.7853981633974475));
  18330. this.tmpCircleVerts1[i] = new oimo.common.Vec3();
  18331. this.tmpCircleVerts2[i] = new oimo.common.Vec3();
  18332. this.tmpCircleNorms[i] = new oimo.common.Vec3();
  18333. }
  18334. this.style = new oimo.dynamics.common.DebugDrawStyle();
  18335. }
  18336. aabb(min,max,color) {
  18337. let _this = this.p;
  18338. let v1 = (_this.sizeVec3 == 0 ? new oimo.common.Vec3() : _this.stackVec3[--_this.sizeVec3]).init(min.x,min.y,min.z);
  18339. let _this1 = this.p;
  18340. let v2 = (_this1.sizeVec3 == 0 ? new oimo.common.Vec3() : _this1.stackVec3[--_this1.sizeVec3]).init(min.x,min.y,max.z);
  18341. let _this2 = this.p;
  18342. let v3 = (_this2.sizeVec3 == 0 ? new oimo.common.Vec3() : _this2.stackVec3[--_this2.sizeVec3]).init(min.x,max.y,min.z);
  18343. let _this3 = this.p;
  18344. let v4 = (_this3.sizeVec3 == 0 ? new oimo.common.Vec3() : _this3.stackVec3[--_this3.sizeVec3]).init(min.x,max.y,max.z);
  18345. let _this4 = this.p;
  18346. let v5 = (_this4.sizeVec3 == 0 ? new oimo.common.Vec3() : _this4.stackVec3[--_this4.sizeVec3]).init(max.x,min.y,min.z);
  18347. let _this5 = this.p;
  18348. let v6 = (_this5.sizeVec3 == 0 ? new oimo.common.Vec3() : _this5.stackVec3[--_this5.sizeVec3]).init(max.x,min.y,max.z);
  18349. let _this6 = this.p;
  18350. let v7 = (_this6.sizeVec3 == 0 ? new oimo.common.Vec3() : _this6.stackVec3[--_this6.sizeVec3]).init(max.x,max.y,min.z);
  18351. let _this7 = this.p;
  18352. let v8 = (_this7.sizeVec3 == 0 ? new oimo.common.Vec3() : _this7.stackVec3[--_this7.sizeVec3]).init(max.x,max.y,max.z);
  18353. this.line(v1,v2,color);
  18354. this.line(v3,v4,color);
  18355. this.line(v5,v6,color);
  18356. this.line(v7,v8,color);
  18357. this.line(v1,v3,color);
  18358. this.line(v2,v4,color);
  18359. this.line(v5,v7,color);
  18360. this.line(v6,v8,color);
  18361. this.line(v1,v5,color);
  18362. this.line(v2,v6,color);
  18363. this.line(v3,v7,color);
  18364. this.line(v4,v8,color);
  18365. let _this8 = this.p;
  18366. if(v1 != null) {
  18367. v1.zero();
  18368. if(_this8.sizeVec3 == _this8.stackVec3.length) {
  18369. let newArray = new Array(_this8.sizeVec3 << 1);
  18370. let _g = 0;
  18371. let _g1 = _this8.sizeVec3;
  18372. while(_g < _g1) {
  18373. let i = _g++;
  18374. newArray[i] = _this8.stackVec3[i];
  18375. _this8.stackVec3[i] = null;
  18376. }
  18377. _this8.stackVec3 = newArray;
  18378. }
  18379. _this8.stackVec3[_this8.sizeVec3++] = v1;
  18380. }
  18381. let _this9 = this.p;
  18382. if(v2 != null) {
  18383. v2.zero();
  18384. if(_this9.sizeVec3 == _this9.stackVec3.length) {
  18385. let newArray = new Array(_this9.sizeVec3 << 1);
  18386. let _g = 0;
  18387. let _g1 = _this9.sizeVec3;
  18388. while(_g < _g1) {
  18389. let i = _g++;
  18390. newArray[i] = _this9.stackVec3[i];
  18391. _this9.stackVec3[i] = null;
  18392. }
  18393. _this9.stackVec3 = newArray;
  18394. }
  18395. _this9.stackVec3[_this9.sizeVec3++] = v2;
  18396. }
  18397. let _this10 = this.p;
  18398. if(v3 != null) {
  18399. v3.zero();
  18400. if(_this10.sizeVec3 == _this10.stackVec3.length) {
  18401. let newArray = new Array(_this10.sizeVec3 << 1);
  18402. let _g = 0;
  18403. let _g1 = _this10.sizeVec3;
  18404. while(_g < _g1) {
  18405. let i = _g++;
  18406. newArray[i] = _this10.stackVec3[i];
  18407. _this10.stackVec3[i] = null;
  18408. }
  18409. _this10.stackVec3 = newArray;
  18410. }
  18411. _this10.stackVec3[_this10.sizeVec3++] = v3;
  18412. }
  18413. let _this11 = this.p;
  18414. if(v4 != null) {
  18415. v4.zero();
  18416. if(_this11.sizeVec3 == _this11.stackVec3.length) {
  18417. let newArray = new Array(_this11.sizeVec3 << 1);
  18418. let _g = 0;
  18419. let _g1 = _this11.sizeVec3;
  18420. while(_g < _g1) {
  18421. let i = _g++;
  18422. newArray[i] = _this11.stackVec3[i];
  18423. _this11.stackVec3[i] = null;
  18424. }
  18425. _this11.stackVec3 = newArray;
  18426. }
  18427. _this11.stackVec3[_this11.sizeVec3++] = v4;
  18428. }
  18429. let _this12 = this.p;
  18430. if(v5 != null) {
  18431. v5.zero();
  18432. if(_this12.sizeVec3 == _this12.stackVec3.length) {
  18433. let newArray = new Array(_this12.sizeVec3 << 1);
  18434. let _g = 0;
  18435. let _g1 = _this12.sizeVec3;
  18436. while(_g < _g1) {
  18437. let i = _g++;
  18438. newArray[i] = _this12.stackVec3[i];
  18439. _this12.stackVec3[i] = null;
  18440. }
  18441. _this12.stackVec3 = newArray;
  18442. }
  18443. _this12.stackVec3[_this12.sizeVec3++] = v5;
  18444. }
  18445. let _this13 = this.p;
  18446. if(v6 != null) {
  18447. v6.zero();
  18448. if(_this13.sizeVec3 == _this13.stackVec3.length) {
  18449. let newArray = new Array(_this13.sizeVec3 << 1);
  18450. let _g = 0;
  18451. let _g1 = _this13.sizeVec3;
  18452. while(_g < _g1) {
  18453. let i = _g++;
  18454. newArray[i] = _this13.stackVec3[i];
  18455. _this13.stackVec3[i] = null;
  18456. }
  18457. _this13.stackVec3 = newArray;
  18458. }
  18459. _this13.stackVec3[_this13.sizeVec3++] = v6;
  18460. }
  18461. let _this14 = this.p;
  18462. if(v7 != null) {
  18463. v7.zero();
  18464. if(_this14.sizeVec3 == _this14.stackVec3.length) {
  18465. let newArray = new Array(_this14.sizeVec3 << 1);
  18466. let _g = 0;
  18467. let _g1 = _this14.sizeVec3;
  18468. while(_g < _g1) {
  18469. let i = _g++;
  18470. newArray[i] = _this14.stackVec3[i];
  18471. _this14.stackVec3[i] = null;
  18472. }
  18473. _this14.stackVec3 = newArray;
  18474. }
  18475. _this14.stackVec3[_this14.sizeVec3++] = v7;
  18476. }
  18477. let _this15 = this.p;
  18478. if(v8 != null) {
  18479. v8.zero();
  18480. if(_this15.sizeVec3 == _this15.stackVec3.length) {
  18481. let newArray = new Array(_this15.sizeVec3 << 1);
  18482. let _g = 0;
  18483. let _g1 = _this15.sizeVec3;
  18484. while(_g < _g1) {
  18485. let i = _g++;
  18486. newArray[i] = _this15.stackVec3[i];
  18487. _this15.stackVec3[i] = null;
  18488. }
  18489. _this15.stackVec3 = newArray;
  18490. }
  18491. _this15.stackVec3[_this15.sizeVec3++] = v8;
  18492. }
  18493. }
  18494. basis(transform,length,colorX,colorY,colorZ) {
  18495. let _this = this.p;
  18496. let pos = _this.sizeVec3 == 0 ? new oimo.common.Vec3() : _this.stackVec3[--_this.sizeVec3];
  18497. let _this1 = this.p;
  18498. let rot = _this1.sizeMat3 == 0 ? new oimo.common.Mat3() : _this1.stackMat3[--_this1.sizeMat3];
  18499. let _this2 = this.p;
  18500. let ex = _this2.sizeVec3 == 0 ? new oimo.common.Vec3() : _this2.stackVec3[--_this2.sizeVec3];
  18501. let _this3 = this.p;
  18502. let ey = _this3.sizeVec3 == 0 ? new oimo.common.Vec3() : _this3.stackVec3[--_this3.sizeVec3];
  18503. let _this4 = this.p;
  18504. let ez = _this4.sizeVec3 == 0 ? new oimo.common.Vec3() : _this4.stackVec3[--_this4.sizeVec3];
  18505. let v = pos;
  18506. v.x = transform._positionX;
  18507. v.y = transform._positionY;
  18508. v.z = transform._positionZ;
  18509. let m = rot;
  18510. m.e00 = transform._rotation00;
  18511. m.e01 = transform._rotation01;
  18512. m.e02 = transform._rotation02;
  18513. m.e10 = transform._rotation10;
  18514. m.e11 = transform._rotation11;
  18515. m.e12 = transform._rotation12;
  18516. m.e20 = transform._rotation20;
  18517. m.e21 = transform._rotation21;
  18518. m.e22 = transform._rotation22;
  18519. ex.init(rot.e00,rot.e10,rot.e20);
  18520. ey.init(rot.e01,rot.e11,rot.e21);
  18521. ez.init(rot.e02,rot.e12,rot.e22);
  18522. ex.x *= length;
  18523. ex.y *= length;
  18524. ex.z *= length;
  18525. let _this5 = ex;
  18526. _this5.x += pos.x;
  18527. _this5.y += pos.y;
  18528. _this5.z += pos.z;
  18529. ey.x *= length;
  18530. ey.y *= length;
  18531. ey.z *= length;
  18532. let _this6 = ey;
  18533. _this6.x += pos.x;
  18534. _this6.y += pos.y;
  18535. _this6.z += pos.z;
  18536. ez.x *= length;
  18537. ez.y *= length;
  18538. ez.z *= length;
  18539. let _this7 = ez;
  18540. _this7.x += pos.x;
  18541. _this7.y += pos.y;
  18542. _this7.z += pos.z;
  18543. this.line(pos,ex,colorX);
  18544. this.line(pos,ey,colorY);
  18545. this.line(pos,ez,colorZ);
  18546. let _this8 = this.p;
  18547. if(pos != null) {
  18548. pos.zero();
  18549. if(_this8.sizeVec3 == _this8.stackVec3.length) {
  18550. let newArray = new Array(_this8.sizeVec3 << 1);
  18551. let _g = 0;
  18552. let _g1 = _this8.sizeVec3;
  18553. while(_g < _g1) {
  18554. let i = _g++;
  18555. newArray[i] = _this8.stackVec3[i];
  18556. _this8.stackVec3[i] = null;
  18557. }
  18558. _this8.stackVec3 = newArray;
  18559. }
  18560. _this8.stackVec3[_this8.sizeVec3++] = pos;
  18561. }
  18562. let _this9 = this.p;
  18563. if(rot != null) {
  18564. rot.e00 = 1;
  18565. rot.e01 = 0;
  18566. rot.e02 = 0;
  18567. rot.e10 = 0;
  18568. rot.e11 = 1;
  18569. rot.e12 = 0;
  18570. rot.e20 = 0;
  18571. rot.e21 = 0;
  18572. rot.e22 = 1;
  18573. if(_this9.sizeMat3 == _this9.stackMat3.length) {
  18574. let newArray = new Array(_this9.sizeMat3 << 1);
  18575. let _g = 0;
  18576. let _g1 = _this9.sizeMat3;
  18577. while(_g < _g1) {
  18578. let i = _g++;
  18579. newArray[i] = _this9.stackMat3[i];
  18580. _this9.stackMat3[i] = null;
  18581. }
  18582. _this9.stackMat3 = newArray;
  18583. }
  18584. _this9.stackMat3[_this9.sizeMat3++] = rot;
  18585. }
  18586. let _this10 = this.p;
  18587. if(ex != null) {
  18588. ex.zero();
  18589. if(_this10.sizeVec3 == _this10.stackVec3.length) {
  18590. let newArray = new Array(_this10.sizeVec3 << 1);
  18591. let _g = 0;
  18592. let _g1 = _this10.sizeVec3;
  18593. while(_g < _g1) {
  18594. let i = _g++;
  18595. newArray[i] = _this10.stackVec3[i];
  18596. _this10.stackVec3[i] = null;
  18597. }
  18598. _this10.stackVec3 = newArray;
  18599. }
  18600. _this10.stackVec3[_this10.sizeVec3++] = ex;
  18601. }
  18602. let _this11 = this.p;
  18603. if(ey != null) {
  18604. ey.zero();
  18605. if(_this11.sizeVec3 == _this11.stackVec3.length) {
  18606. let newArray = new Array(_this11.sizeVec3 << 1);
  18607. let _g = 0;
  18608. let _g1 = _this11.sizeVec3;
  18609. while(_g < _g1) {
  18610. let i = _g++;
  18611. newArray[i] = _this11.stackVec3[i];
  18612. _this11.stackVec3[i] = null;
  18613. }
  18614. _this11.stackVec3 = newArray;
  18615. }
  18616. _this11.stackVec3[_this11.sizeVec3++] = ey;
  18617. }
  18618. let _this12 = this.p;
  18619. if(ez != null) {
  18620. ez.zero();
  18621. if(_this12.sizeVec3 == _this12.stackVec3.length) {
  18622. let newArray = new Array(_this12.sizeVec3 << 1);
  18623. let _g = 0;
  18624. let _g1 = _this12.sizeVec3;
  18625. while(_g < _g1) {
  18626. let i = _g++;
  18627. newArray[i] = _this12.stackVec3[i];
  18628. _this12.stackVec3[i] = null;
  18629. }
  18630. _this12.stackVec3 = newArray;
  18631. }
  18632. _this12.stackVec3[_this12.sizeVec3++] = ez;
  18633. }
  18634. }
  18635. ellipse(center,ex,ey,radiusX,radiusY,color) {
  18636. this.arc(center,ex,ey,radiusX,radiusY,0,6.28318530717958,false,color);
  18637. }
  18638. arc(center,ex,ey,radiusX,radiusY,startAngle,endAngle,drawSector,color) {
  18639. let _this = this.p;
  18640. let _this1 = _this.sizeVec3 == 0 ? new oimo.common.Vec3() : _this.stackVec3[--_this.sizeVec3];
  18641. _this1.x = ex.x;
  18642. _this1.y = ex.y;
  18643. _this1.z = ex.z;
  18644. let _this2 = _this1;
  18645. _this2.x *= radiusX;
  18646. _this2.y *= radiusX;
  18647. _this2.z *= radiusX;
  18648. let _this3 = this.p;
  18649. let _this4 = _this3.sizeVec3 == 0 ? new oimo.common.Vec3() : _this3.stackVec3[--_this3.sizeVec3];
  18650. _this4.x = ey.x;
  18651. _this4.y = ey.y;
  18652. _this4.z = ey.z;
  18653. let _this5 = _this4;
  18654. _this5.x *= radiusY;
  18655. _this5.y *= radiusY;
  18656. _this5.z *= radiusY;
  18657. let angDiff = endAngle - startAngle;
  18658. if(angDiff < 0) {
  18659. angDiff = -angDiff;
  18660. }
  18661. let n = angDiff / 0.52359877559829837 + 0.5 | 0;
  18662. if(n == 0) {
  18663. n = 1;
  18664. }
  18665. let theta = startAngle;
  18666. let dt = (endAngle - startAngle) / n;
  18667. let _this6 = this.p;
  18668. let _this7 = _this6.sizeVec3 == 0 ? new oimo.common.Vec3() : _this6.stackVec3[--_this6.sizeVec3];
  18669. _this7.x = center.x;
  18670. _this7.y = center.y;
  18671. _this7.z = center.z;
  18672. let _this8 = _this7;
  18673. let s = Math.cos(startAngle);
  18674. _this8.x += _this2.x * s;
  18675. _this8.y += _this2.y * s;
  18676. _this8.z += _this2.z * s;
  18677. let s1 = Math.sin(startAngle);
  18678. _this8.x += _this5.x * s1;
  18679. _this8.y += _this5.y * s1;
  18680. _this8.z += _this5.z * s1;
  18681. let prevV = _this8;
  18682. if(drawSector) {
  18683. this.line(center,_this8,color);
  18684. }
  18685. let _g = 0;
  18686. let _g1 = n;
  18687. while(_g < _g1) {
  18688. ++_g;
  18689. theta += dt;
  18690. let _this = this.p;
  18691. let _this1 = _this.sizeVec3 == 0 ? new oimo.common.Vec3() : _this.stackVec3[--_this.sizeVec3];
  18692. _this1.x = center.x;
  18693. _this1.y = center.y;
  18694. _this1.z = center.z;
  18695. let _this3 = _this1;
  18696. let s = Math.cos(theta);
  18697. _this3.x += _this2.x * s;
  18698. _this3.y += _this2.y * s;
  18699. _this3.z += _this2.z * s;
  18700. let s1 = Math.sin(theta);
  18701. _this3.x += _this5.x * s1;
  18702. _this3.y += _this5.y * s1;
  18703. _this3.z += _this5.z * s1;
  18704. this.line(prevV,_this3,color);
  18705. let _this4 = this.p;
  18706. if(prevV != null) {
  18707. prevV.zero();
  18708. if(_this4.sizeVec3 == _this4.stackVec3.length) {
  18709. let newArray = new Array(_this4.sizeVec3 << 1);
  18710. let _g = 0;
  18711. let _g1 = _this4.sizeVec3;
  18712. while(_g < _g1) {
  18713. let i = _g++;
  18714. newArray[i] = _this4.stackVec3[i];
  18715. _this4.stackVec3[i] = null;
  18716. }
  18717. _this4.stackVec3 = newArray;
  18718. }
  18719. _this4.stackVec3[_this4.sizeVec3++] = prevV;
  18720. }
  18721. prevV = _this3;
  18722. }
  18723. if(drawSector) {
  18724. this.line(center,prevV,color);
  18725. }
  18726. let _this9 = this.p;
  18727. if(prevV != null) {
  18728. prevV.zero();
  18729. if(_this9.sizeVec3 == _this9.stackVec3.length) {
  18730. let newArray = new Array(_this9.sizeVec3 << 1);
  18731. let _g = 0;
  18732. let _g1 = _this9.sizeVec3;
  18733. while(_g < _g1) {
  18734. let i = _g++;
  18735. newArray[i] = _this9.stackVec3[i];
  18736. _this9.stackVec3[i] = null;
  18737. }
  18738. _this9.stackVec3 = newArray;
  18739. }
  18740. _this9.stackVec3[_this9.sizeVec3++] = prevV;
  18741. }
  18742. let _this10 = this.p;
  18743. if(_this2 != null) {
  18744. _this2.zero();
  18745. if(_this10.sizeVec3 == _this10.stackVec3.length) {
  18746. let newArray = new Array(_this10.sizeVec3 << 1);
  18747. let _g = 0;
  18748. let _g1 = _this10.sizeVec3;
  18749. while(_g < _g1) {
  18750. let i = _g++;
  18751. newArray[i] = _this10.stackVec3[i];
  18752. _this10.stackVec3[i] = null;
  18753. }
  18754. _this10.stackVec3 = newArray;
  18755. }
  18756. _this10.stackVec3[_this10.sizeVec3++] = _this2;
  18757. }
  18758. let _this11 = this.p;
  18759. if(_this5 != null) {
  18760. _this5.zero();
  18761. if(_this11.sizeVec3 == _this11.stackVec3.length) {
  18762. let newArray = new Array(_this11.sizeVec3 << 1);
  18763. let _g = 0;
  18764. let _g1 = _this11.sizeVec3;
  18765. while(_g < _g1) {
  18766. let i = _g++;
  18767. newArray[i] = _this11.stackVec3[i];
  18768. _this11.stackVec3[i] = null;
  18769. }
  18770. _this11.stackVec3 = newArray;
  18771. }
  18772. _this11.stackVec3[_this11.sizeVec3++] = _this5;
  18773. }
  18774. }
  18775. cone(tf,radius,halfHeight,color) {
  18776. let _this = this.p;
  18777. let ex = _this.sizeVec3 == 0 ? new oimo.common.Vec3() : _this.stackVec3[--_this.sizeVec3];
  18778. let _this1 = this.p;
  18779. let ey = _this1.sizeVec3 == 0 ? new oimo.common.Vec3() : _this1.stackVec3[--_this1.sizeVec3];
  18780. let _this2 = this.p;
  18781. let ez = _this2.sizeVec3 == 0 ? new oimo.common.Vec3() : _this2.stackVec3[--_this2.sizeVec3];
  18782. let _this3 = this.p;
  18783. let o = _this3.sizeVec3 == 0 ? new oimo.common.Vec3() : _this3.stackVec3[--_this3.sizeVec3];
  18784. let _this4 = this.p;
  18785. let m = _this4.sizeMat3 == 0 ? new oimo.common.Mat3() : _this4.stackMat3[--_this4.sizeMat3];
  18786. let v = o;
  18787. v.x = tf._positionX;
  18788. v.y = tf._positionY;
  18789. v.z = tf._positionZ;
  18790. let m1 = m;
  18791. m1.e00 = tf._rotation00;
  18792. m1.e01 = tf._rotation01;
  18793. m1.e02 = tf._rotation02;
  18794. m1.e10 = tf._rotation10;
  18795. m1.e11 = tf._rotation11;
  18796. m1.e12 = tf._rotation12;
  18797. m1.e20 = tf._rotation20;
  18798. m1.e21 = tf._rotation21;
  18799. m1.e22 = tf._rotation22;
  18800. ex.init(m.e00,m.e10,m.e20);
  18801. ey.init(m.e01,m.e11,m.e21);
  18802. ez.init(m.e02,m.e12,m.e22);
  18803. let _this5 = this.p;
  18804. let _this6 = _this5.sizeVec3 == 0 ? new oimo.common.Vec3() : _this5.stackVec3[--_this5.sizeVec3];
  18805. _this6.x = o.x;
  18806. _this6.y = o.y;
  18807. _this6.z = o.z;
  18808. let _this7 = _this6;
  18809. _this7.x += ey.x * halfHeight;
  18810. _this7.y += ey.y * halfHeight;
  18811. _this7.z += ey.z * halfHeight;
  18812. let _this8 = this.p;
  18813. let _this9 = _this8.sizeVec3 == 0 ? new oimo.common.Vec3() : _this8.stackVec3[--_this8.sizeVec3];
  18814. _this9.x = o.x;
  18815. _this9.y = o.y;
  18816. _this9.z = o.z;
  18817. let _this10 = _this9;
  18818. let s = -halfHeight;
  18819. _this10.x += ey.x * s;
  18820. _this10.y += ey.y * s;
  18821. _this10.z += ey.z * s;
  18822. if(this.wireframe) {
  18823. let _this = this.p;
  18824. let _this1 = _this.sizeVec3 == 0 ? new oimo.common.Vec3() : _this.stackVec3[--_this.sizeVec3];
  18825. _this1.x = _this10.x;
  18826. _this1.y = _this10.y;
  18827. _this1.z = _this10.z;
  18828. let _this2 = _this1;
  18829. let s = -radius;
  18830. _this2.x += ex.x * s;
  18831. _this2.y += ex.y * s;
  18832. _this2.z += ex.z * s;
  18833. _this2.x += ez.x * 0;
  18834. _this2.y += ez.y * 0;
  18835. _this2.z += ez.z * 0;
  18836. let _this3 = this.p;
  18837. let _this4 = _this3.sizeVec3 == 0 ? new oimo.common.Vec3() : _this3.stackVec3[--_this3.sizeVec3];
  18838. _this4.x = _this10.x;
  18839. _this4.y = _this10.y;
  18840. _this4.z = _this10.z;
  18841. let _this5 = _this4;
  18842. _this5.x += ex.x * radius;
  18843. _this5.y += ex.y * radius;
  18844. _this5.z += ex.z * radius;
  18845. _this5.x += ez.x * 0;
  18846. _this5.y += ez.y * 0;
  18847. _this5.z += ez.z * 0;
  18848. let _this6 = this.p;
  18849. let _this8 = _this6.sizeVec3 == 0 ? new oimo.common.Vec3() : _this6.stackVec3[--_this6.sizeVec3];
  18850. _this8.x = _this10.x;
  18851. _this8.y = _this10.y;
  18852. _this8.z = _this10.z;
  18853. let _this9 = _this8;
  18854. _this9.x += ex.x * 0;
  18855. _this9.y += ex.y * 0;
  18856. _this9.z += ex.z * 0;
  18857. let s1 = -radius;
  18858. _this9.x += ez.x * s1;
  18859. _this9.y += ez.y * s1;
  18860. _this9.z += ez.z * s1;
  18861. let _this11 = this.p;
  18862. let _this12 = _this11.sizeVec3 == 0 ? new oimo.common.Vec3() : _this11.stackVec3[--_this11.sizeVec3];
  18863. _this12.x = _this10.x;
  18864. _this12.y = _this10.y;
  18865. _this12.z = _this10.z;
  18866. let _this13 = _this12;
  18867. _this13.x += ex.x * 0;
  18868. _this13.y += ex.y * 0;
  18869. _this13.z += ex.z * 0;
  18870. _this13.x += ez.x * radius;
  18871. _this13.y += ez.y * radius;
  18872. _this13.z += ez.z * radius;
  18873. this.ellipse(_this10,ex,ez,radius,radius,color);
  18874. this.line(_this7,_this2,color);
  18875. this.line(_this7,_this5,color);
  18876. this.line(_this7,_this9,color);
  18877. this.line(_this7,_this13,color);
  18878. let _this14 = this.p;
  18879. if(_this2 != null) {
  18880. _this2.zero();
  18881. if(_this14.sizeVec3 == _this14.stackVec3.length) {
  18882. let newArray = new Array(_this14.sizeVec3 << 1);
  18883. let _g = 0;
  18884. let _g1 = _this14.sizeVec3;
  18885. while(_g < _g1) {
  18886. let i = _g++;
  18887. newArray[i] = _this14.stackVec3[i];
  18888. _this14.stackVec3[i] = null;
  18889. }
  18890. _this14.stackVec3 = newArray;
  18891. }
  18892. _this14.stackVec3[_this14.sizeVec3++] = _this2;
  18893. }
  18894. let _this15 = this.p;
  18895. if(_this5 != null) {
  18896. _this5.zero();
  18897. if(_this15.sizeVec3 == _this15.stackVec3.length) {
  18898. let newArray = new Array(_this15.sizeVec3 << 1);
  18899. let _g = 0;
  18900. let _g1 = _this15.sizeVec3;
  18901. while(_g < _g1) {
  18902. let i = _g++;
  18903. newArray[i] = _this15.stackVec3[i];
  18904. _this15.stackVec3[i] = null;
  18905. }
  18906. _this15.stackVec3 = newArray;
  18907. }
  18908. _this15.stackVec3[_this15.sizeVec3++] = _this5;
  18909. }
  18910. let _this16 = this.p;
  18911. if(_this9 != null) {
  18912. _this9.zero();
  18913. if(_this16.sizeVec3 == _this16.stackVec3.length) {
  18914. let newArray = new Array(_this16.sizeVec3 << 1);
  18915. let _g = 0;
  18916. let _g1 = _this16.sizeVec3;
  18917. while(_g < _g1) {
  18918. let i = _g++;
  18919. newArray[i] = _this16.stackVec3[i];
  18920. _this16.stackVec3[i] = null;
  18921. }
  18922. _this16.stackVec3 = newArray;
  18923. }
  18924. _this16.stackVec3[_this16.sizeVec3++] = _this9;
  18925. }
  18926. let _this17 = this.p;
  18927. if(_this13 != null) {
  18928. _this13.zero();
  18929. if(_this17.sizeVec3 == _this17.stackVec3.length) {
  18930. let newArray = new Array(_this17.sizeVec3 << 1);
  18931. let _g = 0;
  18932. let _g1 = _this17.sizeVec3;
  18933. while(_g < _g1) {
  18934. let i = _g++;
  18935. newArray[i] = _this17.stackVec3[i];
  18936. _this17.stackVec3[i] = null;
  18937. }
  18938. _this17.stackVec3 = newArray;
  18939. }
  18940. _this17.stackVec3[_this17.sizeVec3++] = _this13;
  18941. }
  18942. } else {
  18943. let invDenom = 1 / Math.sqrt(radius * radius + 4 * halfHeight * halfHeight);
  18944. let cos = 2 * halfHeight * invDenom;
  18945. let sin = radius * invDenom;
  18946. let _g = 0;
  18947. while(_g < 8) {
  18948. let i = _g++;
  18949. let _this = this.tmpCircleNorms[i];
  18950. let v = this.circleCoords[i];
  18951. _this.x = v.x;
  18952. _this.y = v.y;
  18953. _this.z = v.z;
  18954. _this.x *= cos;
  18955. _this.y *= cos;
  18956. _this.z *= cos;
  18957. _this.y += sin;
  18958. let _this1 = this.tmpCircleNorms[i];
  18959. let y = _this1.x * m.e10 + _this1.y * m.e11 + _this1.z * m.e12;
  18960. let z = _this1.x * m.e20 + _this1.y * m.e21 + _this1.z * m.e22;
  18961. _this1.x = _this1.x * m.e00 + _this1.y * m.e01 + _this1.z * m.e02;
  18962. _this1.y = y;
  18963. _this1.z = z;
  18964. let _this2 = this.tmpCircleVerts1[i];
  18965. let v1 = this.circleCoordsShift[i];
  18966. _this2.x = v1.x;
  18967. _this2.y = v1.y;
  18968. _this2.z = v1.z;
  18969. _this2.x *= cos;
  18970. _this2.y *= cos;
  18971. _this2.z *= cos;
  18972. _this2.y += sin;
  18973. let _this3 = this.tmpCircleVerts1[i];
  18974. let y1 = _this3.x * m.e10 + _this3.y * m.e11 + _this3.z * m.e12;
  18975. let z1 = _this3.x * m.e20 + _this3.y * m.e21 + _this3.z * m.e22;
  18976. _this3.x = _this3.x * m.e00 + _this3.y * m.e01 + _this3.z * m.e02;
  18977. _this3.y = y1;
  18978. _this3.z = z1;
  18979. let _this4 = this.tmpCircleVerts2[i];
  18980. let v2 = this.circleCoords[i];
  18981. _this4.x = v2.x;
  18982. _this4.y = v2.y;
  18983. _this4.z = v2.z;
  18984. let y2 = _this4.x * m.e10 + _this4.y * m.e11 + _this4.z * m.e12;
  18985. let z2 = _this4.x * m.e20 + _this4.y * m.e21 + _this4.z * m.e22;
  18986. _this4.x = _this4.x * m.e00 + _this4.y * m.e01 + _this4.z * m.e02;
  18987. _this4.y = y2;
  18988. _this4.z = z2;
  18989. _this4.x *= radius;
  18990. _this4.y *= radius;
  18991. _this4.z *= radius;
  18992. _this4.x += o.x;
  18993. _this4.y += o.y;
  18994. _this4.z += o.z;
  18995. let _this5 = this.tmpCircleVerts2[i];
  18996. let s = -halfHeight;
  18997. _this5.x += ey.x * s;
  18998. _this5.y += ey.y * s;
  18999. _this5.z += ey.z * s;
  19000. }
  19001. let _g1 = 0;
  19002. while(_g1 < 8) {
  19003. let i = _g1++;
  19004. let v2 = this.tmpCircleVerts2[i];
  19005. let v3 = this.tmpCircleVerts2[(i + 1) % 8];
  19006. let n1 = this.tmpCircleVerts1[i];
  19007. this.triangle(_this7,v2,v3,n1,this.tmpCircleNorms[i],this.tmpCircleNorms[(i + 1) % 8],color);
  19008. v2 = this.tmpCircleVerts2[(i + 1) % 8];
  19009. v3 = this.tmpCircleVerts2[i];
  19010. let _this = this.p;
  19011. let _this1 = _this.sizeVec3 == 0 ? new oimo.common.Vec3() : _this.stackVec3[--_this.sizeVec3];
  19012. _this1.x = ey.x;
  19013. _this1.y = ey.y;
  19014. _this1.z = ey.z;
  19015. let _this2 = _this1;
  19016. _this2.x = -_this2.x;
  19017. _this2.y = -_this2.y;
  19018. _this2.z = -_this2.z;
  19019. this.triangle(_this10,v2,v3,_this2,_this2,_this2,color);
  19020. let _this3 = this.p;
  19021. if(_this2 != null) {
  19022. _this2.zero();
  19023. if(_this3.sizeVec3 == _this3.stackVec3.length) {
  19024. let newArray = new Array(_this3.sizeVec3 << 1);
  19025. let _g = 0;
  19026. let _g1 = _this3.sizeVec3;
  19027. while(_g < _g1) {
  19028. let i = _g++;
  19029. newArray[i] = _this3.stackVec3[i];
  19030. _this3.stackVec3[i] = null;
  19031. }
  19032. _this3.stackVec3 = newArray;
  19033. }
  19034. _this3.stackVec3[_this3.sizeVec3++] = _this2;
  19035. }
  19036. }
  19037. }
  19038. let _this11 = this.p;
  19039. if(_this7 != null) {
  19040. _this7.zero();
  19041. if(_this11.sizeVec3 == _this11.stackVec3.length) {
  19042. let newArray = new Array(_this11.sizeVec3 << 1);
  19043. let _g = 0;
  19044. let _g1 = _this11.sizeVec3;
  19045. while(_g < _g1) {
  19046. let i = _g++;
  19047. newArray[i] = _this11.stackVec3[i];
  19048. _this11.stackVec3[i] = null;
  19049. }
  19050. _this11.stackVec3 = newArray;
  19051. }
  19052. _this11.stackVec3[_this11.sizeVec3++] = _this7;
  19053. }
  19054. let _this12 = this.p;
  19055. if(_this10 != null) {
  19056. _this10.zero();
  19057. if(_this12.sizeVec3 == _this12.stackVec3.length) {
  19058. let newArray = new Array(_this12.sizeVec3 << 1);
  19059. let _g = 0;
  19060. let _g1 = _this12.sizeVec3;
  19061. while(_g < _g1) {
  19062. let i = _g++;
  19063. newArray[i] = _this12.stackVec3[i];
  19064. _this12.stackVec3[i] = null;
  19065. }
  19066. _this12.stackVec3 = newArray;
  19067. }
  19068. _this12.stackVec3[_this12.sizeVec3++] = _this10;
  19069. }
  19070. let _this13 = this.p;
  19071. if(o != null) {
  19072. o.zero();
  19073. if(_this13.sizeVec3 == _this13.stackVec3.length) {
  19074. let newArray = new Array(_this13.sizeVec3 << 1);
  19075. let _g = 0;
  19076. let _g1 = _this13.sizeVec3;
  19077. while(_g < _g1) {
  19078. let i = _g++;
  19079. newArray[i] = _this13.stackVec3[i];
  19080. _this13.stackVec3[i] = null;
  19081. }
  19082. _this13.stackVec3 = newArray;
  19083. }
  19084. _this13.stackVec3[_this13.sizeVec3++] = o;
  19085. }
  19086. let _this14 = this.p;
  19087. if(m != null) {
  19088. m.e00 = 1;
  19089. m.e01 = 0;
  19090. m.e02 = 0;
  19091. m.e10 = 0;
  19092. m.e11 = 1;
  19093. m.e12 = 0;
  19094. m.e20 = 0;
  19095. m.e21 = 0;
  19096. m.e22 = 1;
  19097. if(_this14.sizeMat3 == _this14.stackMat3.length) {
  19098. let newArray = new Array(_this14.sizeMat3 << 1);
  19099. let _g = 0;
  19100. let _g1 = _this14.sizeMat3;
  19101. while(_g < _g1) {
  19102. let i = _g++;
  19103. newArray[i] = _this14.stackMat3[i];
  19104. _this14.stackMat3[i] = null;
  19105. }
  19106. _this14.stackMat3 = newArray;
  19107. }
  19108. _this14.stackMat3[_this14.sizeMat3++] = m;
  19109. }
  19110. let _this15 = this.p;
  19111. if(ex != null) {
  19112. ex.zero();
  19113. if(_this15.sizeVec3 == _this15.stackVec3.length) {
  19114. let newArray = new Array(_this15.sizeVec3 << 1);
  19115. let _g = 0;
  19116. let _g1 = _this15.sizeVec3;
  19117. while(_g < _g1) {
  19118. let i = _g++;
  19119. newArray[i] = _this15.stackVec3[i];
  19120. _this15.stackVec3[i] = null;
  19121. }
  19122. _this15.stackVec3 = newArray;
  19123. }
  19124. _this15.stackVec3[_this15.sizeVec3++] = ex;
  19125. }
  19126. let _this16 = this.p;
  19127. if(ey != null) {
  19128. ey.zero();
  19129. if(_this16.sizeVec3 == _this16.stackVec3.length) {
  19130. let newArray = new Array(_this16.sizeVec3 << 1);
  19131. let _g = 0;
  19132. let _g1 = _this16.sizeVec3;
  19133. while(_g < _g1) {
  19134. let i = _g++;
  19135. newArray[i] = _this16.stackVec3[i];
  19136. _this16.stackVec3[i] = null;
  19137. }
  19138. _this16.stackVec3 = newArray;
  19139. }
  19140. _this16.stackVec3[_this16.sizeVec3++] = ey;
  19141. }
  19142. let _this17 = this.p;
  19143. if(ez != null) {
  19144. ez.zero();
  19145. if(_this17.sizeVec3 == _this17.stackVec3.length) {
  19146. let newArray = new Array(_this17.sizeVec3 << 1);
  19147. let _g = 0;
  19148. let _g1 = _this17.sizeVec3;
  19149. while(_g < _g1) {
  19150. let i = _g++;
  19151. newArray[i] = _this17.stackVec3[i];
  19152. _this17.stackVec3[i] = null;
  19153. }
  19154. _this17.stackVec3 = newArray;
  19155. }
  19156. _this17.stackVec3[_this17.sizeVec3++] = ez;
  19157. }
  19158. }
  19159. cylinder(tf,radius,halfHeight,color) {
  19160. let _this = this.p;
  19161. let ex = _this.sizeVec3 == 0 ? new oimo.common.Vec3() : _this.stackVec3[--_this.sizeVec3];
  19162. let _this1 = this.p;
  19163. let ey = _this1.sizeVec3 == 0 ? new oimo.common.Vec3() : _this1.stackVec3[--_this1.sizeVec3];
  19164. let _this2 = this.p;
  19165. let ez = _this2.sizeVec3 == 0 ? new oimo.common.Vec3() : _this2.stackVec3[--_this2.sizeVec3];
  19166. let _this3 = this.p;
  19167. let o = _this3.sizeVec3 == 0 ? new oimo.common.Vec3() : _this3.stackVec3[--_this3.sizeVec3];
  19168. let _this4 = this.p;
  19169. let m = _this4.sizeMat3 == 0 ? new oimo.common.Mat3() : _this4.stackMat3[--_this4.sizeMat3];
  19170. let v = o;
  19171. v.x = tf._positionX;
  19172. v.y = tf._positionY;
  19173. v.z = tf._positionZ;
  19174. let m1 = m;
  19175. m1.e00 = tf._rotation00;
  19176. m1.e01 = tf._rotation01;
  19177. m1.e02 = tf._rotation02;
  19178. m1.e10 = tf._rotation10;
  19179. m1.e11 = tf._rotation11;
  19180. m1.e12 = tf._rotation12;
  19181. m1.e20 = tf._rotation20;
  19182. m1.e21 = tf._rotation21;
  19183. m1.e22 = tf._rotation22;
  19184. ex.init(m.e00,m.e10,m.e20);
  19185. ey.init(m.e01,m.e11,m.e21);
  19186. ez.init(m.e02,m.e12,m.e22);
  19187. let _this5 = this.p;
  19188. let _this6 = _this5.sizeVec3 == 0 ? new oimo.common.Vec3() : _this5.stackVec3[--_this5.sizeVec3];
  19189. _this6.x = o.x;
  19190. _this6.y = o.y;
  19191. _this6.z = o.z;
  19192. let _this7 = _this6;
  19193. _this7.x += ey.x * halfHeight;
  19194. _this7.y += ey.y * halfHeight;
  19195. _this7.z += ey.z * halfHeight;
  19196. let _this8 = this.p;
  19197. let _this9 = _this8.sizeVec3 == 0 ? new oimo.common.Vec3() : _this8.stackVec3[--_this8.sizeVec3];
  19198. _this9.x = o.x;
  19199. _this9.y = o.y;
  19200. _this9.z = o.z;
  19201. let _this10 = _this9;
  19202. let s = -halfHeight;
  19203. _this10.x += ey.x * s;
  19204. _this10.y += ey.y * s;
  19205. _this10.z += ey.z * s;
  19206. if(this.wireframe) {
  19207. let _this = this.p;
  19208. let _this1 = _this.sizeVec3 == 0 ? new oimo.common.Vec3() : _this.stackVec3[--_this.sizeVec3];
  19209. _this1.x = _this7.x;
  19210. _this1.y = _this7.y;
  19211. _this1.z = _this7.z;
  19212. let _this2 = _this1;
  19213. let s = -radius;
  19214. _this2.x += ex.x * s;
  19215. _this2.y += ex.y * s;
  19216. _this2.z += ex.z * s;
  19217. _this2.x += ez.x * 0;
  19218. _this2.y += ez.y * 0;
  19219. _this2.z += ez.z * 0;
  19220. let _this3 = this.p;
  19221. let _this4 = _this3.sizeVec3 == 0 ? new oimo.common.Vec3() : _this3.stackVec3[--_this3.sizeVec3];
  19222. _this4.x = _this7.x;
  19223. _this4.y = _this7.y;
  19224. _this4.z = _this7.z;
  19225. let _this5 = _this4;
  19226. _this5.x += ex.x * radius;
  19227. _this5.y += ex.y * radius;
  19228. _this5.z += ex.z * radius;
  19229. _this5.x += ez.x * 0;
  19230. _this5.y += ez.y * 0;
  19231. _this5.z += ez.z * 0;
  19232. let _this6 = this.p;
  19233. let _this8 = _this6.sizeVec3 == 0 ? new oimo.common.Vec3() : _this6.stackVec3[--_this6.sizeVec3];
  19234. _this8.x = _this7.x;
  19235. _this8.y = _this7.y;
  19236. _this8.z = _this7.z;
  19237. let _this9 = _this8;
  19238. _this9.x += ex.x * 0;
  19239. _this9.y += ex.y * 0;
  19240. _this9.z += ex.z * 0;
  19241. let s1 = -radius;
  19242. _this9.x += ez.x * s1;
  19243. _this9.y += ez.y * s1;
  19244. _this9.z += ez.z * s1;
  19245. let _this11 = this.p;
  19246. let _this12 = _this11.sizeVec3 == 0 ? new oimo.common.Vec3() : _this11.stackVec3[--_this11.sizeVec3];
  19247. _this12.x = _this7.x;
  19248. _this12.y = _this7.y;
  19249. _this12.z = _this7.z;
  19250. let _this13 = _this12;
  19251. _this13.x += ex.x * 0;
  19252. _this13.y += ex.y * 0;
  19253. _this13.z += ex.z * 0;
  19254. _this13.x += ez.x * radius;
  19255. _this13.y += ez.y * radius;
  19256. _this13.z += ez.z * radius;
  19257. let _this14 = this.p;
  19258. let _this15 = _this14.sizeVec3 == 0 ? new oimo.common.Vec3() : _this14.stackVec3[--_this14.sizeVec3];
  19259. _this15.x = _this10.x;
  19260. _this15.y = _this10.y;
  19261. _this15.z = _this10.z;
  19262. let _this16 = _this15;
  19263. let s2 = -radius;
  19264. _this16.x += ex.x * s2;
  19265. _this16.y += ex.y * s2;
  19266. _this16.z += ex.z * s2;
  19267. _this16.x += ez.x * 0;
  19268. _this16.y += ez.y * 0;
  19269. _this16.z += ez.z * 0;
  19270. let _this17 = this.p;
  19271. let _this18 = _this17.sizeVec3 == 0 ? new oimo.common.Vec3() : _this17.stackVec3[--_this17.sizeVec3];
  19272. _this18.x = _this10.x;
  19273. _this18.y = _this10.y;
  19274. _this18.z = _this10.z;
  19275. let _this19 = _this18;
  19276. _this19.x += ex.x * radius;
  19277. _this19.y += ex.y * radius;
  19278. _this19.z += ex.z * radius;
  19279. _this19.x += ez.x * 0;
  19280. _this19.y += ez.y * 0;
  19281. _this19.z += ez.z * 0;
  19282. let _this20 = this.p;
  19283. let _this21 = _this20.sizeVec3 == 0 ? new oimo.common.Vec3() : _this20.stackVec3[--_this20.sizeVec3];
  19284. _this21.x = _this10.x;
  19285. _this21.y = _this10.y;
  19286. _this21.z = _this10.z;
  19287. let _this22 = _this21;
  19288. _this22.x += ex.x * 0;
  19289. _this22.y += ex.y * 0;
  19290. _this22.z += ex.z * 0;
  19291. let s3 = -radius;
  19292. _this22.x += ez.x * s3;
  19293. _this22.y += ez.y * s3;
  19294. _this22.z += ez.z * s3;
  19295. let _this23 = this.p;
  19296. let _this24 = _this23.sizeVec3 == 0 ? new oimo.common.Vec3() : _this23.stackVec3[--_this23.sizeVec3];
  19297. _this24.x = _this10.x;
  19298. _this24.y = _this10.y;
  19299. _this24.z = _this10.z;
  19300. let _this25 = _this24;
  19301. _this25.x += ex.x * 0;
  19302. _this25.y += ex.y * 0;
  19303. _this25.z += ex.z * 0;
  19304. _this25.x += ez.x * radius;
  19305. _this25.y += ez.y * radius;
  19306. _this25.z += ez.z * radius;
  19307. this.ellipse(_this7,ex,ez,radius,radius,color);
  19308. this.ellipse(_this10,ex,ez,radius,radius,color);
  19309. this.line(_this2,_this16,color);
  19310. this.line(_this5,_this19,color);
  19311. this.line(_this9,_this22,color);
  19312. this.line(_this13,_this25,color);
  19313. let _this26 = this.p;
  19314. if(_this2 != null) {
  19315. _this2.zero();
  19316. if(_this26.sizeVec3 == _this26.stackVec3.length) {
  19317. let newArray = new Array(_this26.sizeVec3 << 1);
  19318. let _g = 0;
  19319. let _g1 = _this26.sizeVec3;
  19320. while(_g < _g1) {
  19321. let i = _g++;
  19322. newArray[i] = _this26.stackVec3[i];
  19323. _this26.stackVec3[i] = null;
  19324. }
  19325. _this26.stackVec3 = newArray;
  19326. }
  19327. _this26.stackVec3[_this26.sizeVec3++] = _this2;
  19328. }
  19329. let _this27 = this.p;
  19330. if(_this5 != null) {
  19331. _this5.zero();
  19332. if(_this27.sizeVec3 == _this27.stackVec3.length) {
  19333. let newArray = new Array(_this27.sizeVec3 << 1);
  19334. let _g = 0;
  19335. let _g1 = _this27.sizeVec3;
  19336. while(_g < _g1) {
  19337. let i = _g++;
  19338. newArray[i] = _this27.stackVec3[i];
  19339. _this27.stackVec3[i] = null;
  19340. }
  19341. _this27.stackVec3 = newArray;
  19342. }
  19343. _this27.stackVec3[_this27.sizeVec3++] = _this5;
  19344. }
  19345. let _this28 = this.p;
  19346. if(_this9 != null) {
  19347. _this9.zero();
  19348. if(_this28.sizeVec3 == _this28.stackVec3.length) {
  19349. let newArray = new Array(_this28.sizeVec3 << 1);
  19350. let _g = 0;
  19351. let _g1 = _this28.sizeVec3;
  19352. while(_g < _g1) {
  19353. let i = _g++;
  19354. newArray[i] = _this28.stackVec3[i];
  19355. _this28.stackVec3[i] = null;
  19356. }
  19357. _this28.stackVec3 = newArray;
  19358. }
  19359. _this28.stackVec3[_this28.sizeVec3++] = _this9;
  19360. }
  19361. let _this29 = this.p;
  19362. if(_this13 != null) {
  19363. _this13.zero();
  19364. if(_this29.sizeVec3 == _this29.stackVec3.length) {
  19365. let newArray = new Array(_this29.sizeVec3 << 1);
  19366. let _g = 0;
  19367. let _g1 = _this29.sizeVec3;
  19368. while(_g < _g1) {
  19369. let i = _g++;
  19370. newArray[i] = _this29.stackVec3[i];
  19371. _this29.stackVec3[i] = null;
  19372. }
  19373. _this29.stackVec3 = newArray;
  19374. }
  19375. _this29.stackVec3[_this29.sizeVec3++] = _this13;
  19376. }
  19377. let _this30 = this.p;
  19378. if(_this16 != null) {
  19379. _this16.zero();
  19380. if(_this30.sizeVec3 == _this30.stackVec3.length) {
  19381. let newArray = new Array(_this30.sizeVec3 << 1);
  19382. let _g = 0;
  19383. let _g1 = _this30.sizeVec3;
  19384. while(_g < _g1) {
  19385. let i = _g++;
  19386. newArray[i] = _this30.stackVec3[i];
  19387. _this30.stackVec3[i] = null;
  19388. }
  19389. _this30.stackVec3 = newArray;
  19390. }
  19391. _this30.stackVec3[_this30.sizeVec3++] = _this16;
  19392. }
  19393. let _this31 = this.p;
  19394. if(_this19 != null) {
  19395. _this19.zero();
  19396. if(_this31.sizeVec3 == _this31.stackVec3.length) {
  19397. let newArray = new Array(_this31.sizeVec3 << 1);
  19398. let _g = 0;
  19399. let _g1 = _this31.sizeVec3;
  19400. while(_g < _g1) {
  19401. let i = _g++;
  19402. newArray[i] = _this31.stackVec3[i];
  19403. _this31.stackVec3[i] = null;
  19404. }
  19405. _this31.stackVec3 = newArray;
  19406. }
  19407. _this31.stackVec3[_this31.sizeVec3++] = _this19;
  19408. }
  19409. let _this32 = this.p;
  19410. if(_this22 != null) {
  19411. _this22.zero();
  19412. if(_this32.sizeVec3 == _this32.stackVec3.length) {
  19413. let newArray = new Array(_this32.sizeVec3 << 1);
  19414. let _g = 0;
  19415. let _g1 = _this32.sizeVec3;
  19416. while(_g < _g1) {
  19417. let i = _g++;
  19418. newArray[i] = _this32.stackVec3[i];
  19419. _this32.stackVec3[i] = null;
  19420. }
  19421. _this32.stackVec3 = newArray;
  19422. }
  19423. _this32.stackVec3[_this32.sizeVec3++] = _this22;
  19424. }
  19425. let _this33 = this.p;
  19426. if(_this25 != null) {
  19427. _this25.zero();
  19428. if(_this33.sizeVec3 == _this33.stackVec3.length) {
  19429. let newArray = new Array(_this33.sizeVec3 << 1);
  19430. let _g = 0;
  19431. let _g1 = _this33.sizeVec3;
  19432. while(_g < _g1) {
  19433. let i = _g++;
  19434. newArray[i] = _this33.stackVec3[i];
  19435. _this33.stackVec3[i] = null;
  19436. }
  19437. _this33.stackVec3 = newArray;
  19438. }
  19439. _this33.stackVec3[_this33.sizeVec3++] = _this25;
  19440. }
  19441. } else {
  19442. let _g = 0;
  19443. while(_g < 8) {
  19444. let i = _g++;
  19445. let _this = this.tmpCircleNorms[i];
  19446. let v = this.circleCoords[i];
  19447. _this.x = v.x;
  19448. _this.y = v.y;
  19449. _this.z = v.z;
  19450. let y = _this.x * m.e10 + _this.y * m.e11 + _this.z * m.e12;
  19451. let z = _this.x * m.e20 + _this.y * m.e21 + _this.z * m.e22;
  19452. _this.x = _this.x * m.e00 + _this.y * m.e01 + _this.z * m.e02;
  19453. _this.y = y;
  19454. _this.z = z;
  19455. let _this1 = this.tmpCircleVerts1[i];
  19456. let v1 = this.tmpCircleNorms[i];
  19457. _this1.x = v1.x;
  19458. _this1.y = v1.y;
  19459. _this1.z = v1.z;
  19460. _this1.x *= radius;
  19461. _this1.y *= radius;
  19462. _this1.z *= radius;
  19463. _this1.x += o.x;
  19464. _this1.y += o.y;
  19465. _this1.z += o.z;
  19466. let _this2 = this.tmpCircleVerts2[i];
  19467. let v2 = this.tmpCircleVerts1[i];
  19468. _this2.x = v2.x;
  19469. _this2.y = v2.y;
  19470. _this2.z = v2.z;
  19471. let _this3 = this.tmpCircleVerts1[i];
  19472. _this3.x += ey.x * halfHeight;
  19473. _this3.y += ey.y * halfHeight;
  19474. _this3.z += ey.z * halfHeight;
  19475. let _this4 = this.tmpCircleVerts2[i];
  19476. let s = -halfHeight;
  19477. _this4.x += ey.x * s;
  19478. _this4.y += ey.y * s;
  19479. _this4.z += ey.z * s;
  19480. }
  19481. let _g1 = 0;
  19482. while(_g1 < 8) {
  19483. let i = _g1++;
  19484. let v1;
  19485. let v2 = this.tmpCircleVerts1[i];
  19486. let v3 = this.tmpCircleVerts1[(i + 1) % 8];
  19487. let n1 = ey;
  19488. this.triangle(_this7,v2,v3,n1,n1,n1,color);
  19489. v2 = this.tmpCircleVerts2[(i + 1) % 8];
  19490. v3 = this.tmpCircleVerts2[i];
  19491. let _this = this.p;
  19492. let _this1 = _this.sizeVec3 == 0 ? new oimo.common.Vec3() : _this.stackVec3[--_this.sizeVec3];
  19493. _this1.x = ey.x;
  19494. _this1.y = ey.y;
  19495. _this1.z = ey.z;
  19496. let _this2 = _this1;
  19497. _this2.x = -_this2.x;
  19498. _this2.y = -_this2.y;
  19499. _this2.z = -_this2.z;
  19500. this.triangle(_this10,v2,v3,_this2,_this2,_this2,color);
  19501. let _this3 = this.p;
  19502. if(_this2 != null) {
  19503. _this2.zero();
  19504. if(_this3.sizeVec3 == _this3.stackVec3.length) {
  19505. let newArray = new Array(_this3.sizeVec3 << 1);
  19506. let _g = 0;
  19507. let _g1 = _this3.sizeVec3;
  19508. while(_g < _g1) {
  19509. let i = _g++;
  19510. newArray[i] = _this3.stackVec3[i];
  19511. _this3.stackVec3[i] = null;
  19512. }
  19513. _this3.stackVec3 = newArray;
  19514. }
  19515. _this3.stackVec3[_this3.sizeVec3++] = _this2;
  19516. }
  19517. v1 = this.tmpCircleVerts1[i];
  19518. v2 = this.tmpCircleVerts2[i];
  19519. v3 = this.tmpCircleVerts2[(i + 1) % 8];
  19520. n1 = this.tmpCircleNorms[i];
  19521. let n2 = this.tmpCircleNorms[(i + 1) % 8];
  19522. this.rect(v1,v2,v3,this.tmpCircleVerts1[(i + 1) % 8],n1,n1,n2,n2,color);
  19523. }
  19524. }
  19525. let _this11 = this.p;
  19526. if(_this7 != null) {
  19527. _this7.zero();
  19528. if(_this11.sizeVec3 == _this11.stackVec3.length) {
  19529. let newArray = new Array(_this11.sizeVec3 << 1);
  19530. let _g = 0;
  19531. let _g1 = _this11.sizeVec3;
  19532. while(_g < _g1) {
  19533. let i = _g++;
  19534. newArray[i] = _this11.stackVec3[i];
  19535. _this11.stackVec3[i] = null;
  19536. }
  19537. _this11.stackVec3 = newArray;
  19538. }
  19539. _this11.stackVec3[_this11.sizeVec3++] = _this7;
  19540. }
  19541. let _this12 = this.p;
  19542. if(_this10 != null) {
  19543. _this10.zero();
  19544. if(_this12.sizeVec3 == _this12.stackVec3.length) {
  19545. let newArray = new Array(_this12.sizeVec3 << 1);
  19546. let _g = 0;
  19547. let _g1 = _this12.sizeVec3;
  19548. while(_g < _g1) {
  19549. let i = _g++;
  19550. newArray[i] = _this12.stackVec3[i];
  19551. _this12.stackVec3[i] = null;
  19552. }
  19553. _this12.stackVec3 = newArray;
  19554. }
  19555. _this12.stackVec3[_this12.sizeVec3++] = _this10;
  19556. }
  19557. let _this13 = this.p;
  19558. if(o != null) {
  19559. o.zero();
  19560. if(_this13.sizeVec3 == _this13.stackVec3.length) {
  19561. let newArray = new Array(_this13.sizeVec3 << 1);
  19562. let _g = 0;
  19563. let _g1 = _this13.sizeVec3;
  19564. while(_g < _g1) {
  19565. let i = _g++;
  19566. newArray[i] = _this13.stackVec3[i];
  19567. _this13.stackVec3[i] = null;
  19568. }
  19569. _this13.stackVec3 = newArray;
  19570. }
  19571. _this13.stackVec3[_this13.sizeVec3++] = o;
  19572. }
  19573. let _this14 = this.p;
  19574. if(m != null) {
  19575. m.e00 = 1;
  19576. m.e01 = 0;
  19577. m.e02 = 0;
  19578. m.e10 = 0;
  19579. m.e11 = 1;
  19580. m.e12 = 0;
  19581. m.e20 = 0;
  19582. m.e21 = 0;
  19583. m.e22 = 1;
  19584. if(_this14.sizeMat3 == _this14.stackMat3.length) {
  19585. let newArray = new Array(_this14.sizeMat3 << 1);
  19586. let _g = 0;
  19587. let _g1 = _this14.sizeMat3;
  19588. while(_g < _g1) {
  19589. let i = _g++;
  19590. newArray[i] = _this14.stackMat3[i];
  19591. _this14.stackMat3[i] = null;
  19592. }
  19593. _this14.stackMat3 = newArray;
  19594. }
  19595. _this14.stackMat3[_this14.sizeMat3++] = m;
  19596. }
  19597. let _this15 = this.p;
  19598. if(ex != null) {
  19599. ex.zero();
  19600. if(_this15.sizeVec3 == _this15.stackVec3.length) {
  19601. let newArray = new Array(_this15.sizeVec3 << 1);
  19602. let _g = 0;
  19603. let _g1 = _this15.sizeVec3;
  19604. while(_g < _g1) {
  19605. let i = _g++;
  19606. newArray[i] = _this15.stackVec3[i];
  19607. _this15.stackVec3[i] = null;
  19608. }
  19609. _this15.stackVec3 = newArray;
  19610. }
  19611. _this15.stackVec3[_this15.sizeVec3++] = ex;
  19612. }
  19613. let _this16 = this.p;
  19614. if(ey != null) {
  19615. ey.zero();
  19616. if(_this16.sizeVec3 == _this16.stackVec3.length) {
  19617. let newArray = new Array(_this16.sizeVec3 << 1);
  19618. let _g = 0;
  19619. let _g1 = _this16.sizeVec3;
  19620. while(_g < _g1) {
  19621. let i = _g++;
  19622. newArray[i] = _this16.stackVec3[i];
  19623. _this16.stackVec3[i] = null;
  19624. }
  19625. _this16.stackVec3 = newArray;
  19626. }
  19627. _this16.stackVec3[_this16.sizeVec3++] = ey;
  19628. }
  19629. let _this17 = this.p;
  19630. if(ez != null) {
  19631. ez.zero();
  19632. if(_this17.sizeVec3 == _this17.stackVec3.length) {
  19633. let newArray = new Array(_this17.sizeVec3 << 1);
  19634. let _g = 0;
  19635. let _g1 = _this17.sizeVec3;
  19636. while(_g < _g1) {
  19637. let i = _g++;
  19638. newArray[i] = _this17.stackVec3[i];
  19639. _this17.stackVec3[i] = null;
  19640. }
  19641. _this17.stackVec3 = newArray;
  19642. }
  19643. _this17.stackVec3[_this17.sizeVec3++] = ez;
  19644. }
  19645. }
  19646. capsule(tf,radius,halfHeight,color) {
  19647. let _this = this.p;
  19648. let ex = _this.sizeVec3 == 0 ? new oimo.common.Vec3() : _this.stackVec3[--_this.sizeVec3];
  19649. let _this1 = this.p;
  19650. let ey = _this1.sizeVec3 == 0 ? new oimo.common.Vec3() : _this1.stackVec3[--_this1.sizeVec3];
  19651. let _this2 = this.p;
  19652. let ez = _this2.sizeVec3 == 0 ? new oimo.common.Vec3() : _this2.stackVec3[--_this2.sizeVec3];
  19653. let _this3 = this.p;
  19654. let o = _this3.sizeVec3 == 0 ? new oimo.common.Vec3() : _this3.stackVec3[--_this3.sizeVec3];
  19655. let _this4 = this.p;
  19656. let m = _this4.sizeMat3 == 0 ? new oimo.common.Mat3() : _this4.stackMat3[--_this4.sizeMat3];
  19657. let v = o;
  19658. v.x = tf._positionX;
  19659. v.y = tf._positionY;
  19660. v.z = tf._positionZ;
  19661. let m1 = m;
  19662. m1.e00 = tf._rotation00;
  19663. m1.e01 = tf._rotation01;
  19664. m1.e02 = tf._rotation02;
  19665. m1.e10 = tf._rotation10;
  19666. m1.e11 = tf._rotation11;
  19667. m1.e12 = tf._rotation12;
  19668. m1.e20 = tf._rotation20;
  19669. m1.e21 = tf._rotation21;
  19670. m1.e22 = tf._rotation22;
  19671. ex.init(m.e00,m.e10,m.e20);
  19672. ey.init(m.e01,m.e11,m.e21);
  19673. ez.init(m.e02,m.e12,m.e22);
  19674. let vs = this.tmpSphereVerts;
  19675. let ns = this.tmpSphereNorms;
  19676. let _g = 0;
  19677. while(_g < 5) {
  19678. let i2 = _g++;
  19679. let n = this.tmpSphereVerts[i2].length;
  19680. let _g1 = 0;
  19681. while(_g1 < n) {
  19682. let j2 = _g1++;
  19683. let _this = ns[i2][j2];
  19684. let v = this.sphereCoords[i2][j2];
  19685. _this.x = v.x;
  19686. _this.y = v.y;
  19687. _this.z = v.z;
  19688. let y = _this.x * m.e10 + _this.y * m.e11 + _this.z * m.e12;
  19689. let z = _this.x * m.e20 + _this.y * m.e21 + _this.z * m.e22;
  19690. _this.x = _this.x * m.e00 + _this.y * m.e01 + _this.z * m.e02;
  19691. _this.y = y;
  19692. _this.z = z;
  19693. }
  19694. }
  19695. let _g1 = 0;
  19696. while(_g1 < 4) {
  19697. let i = _g1++;
  19698. if(i == 0) {
  19699. let _g = 0;
  19700. while(_g < 3) {
  19701. let i2 = _g++;
  19702. let n = this.tmpSphereVerts[i2].length;
  19703. let _g1 = 0;
  19704. while(_g1 < n) {
  19705. let j2 = _g1++;
  19706. let _this = vs[i2][j2];
  19707. let v = ns[i2][j2];
  19708. _this.x = v.x;
  19709. _this.y = v.y;
  19710. _this.z = v.z;
  19711. _this.x *= radius;
  19712. _this.y *= radius;
  19713. _this.z *= radius;
  19714. _this.x += o.x;
  19715. _this.y += o.y;
  19716. _this.z += o.z;
  19717. _this.x += ey.x * halfHeight;
  19718. _this.y += ey.y * halfHeight;
  19719. _this.z += ey.z * halfHeight;
  19720. }
  19721. }
  19722. }
  19723. if(i == 2) {
  19724. let _g = 2;
  19725. while(_g < 5) {
  19726. let i2 = _g++;
  19727. let n = this.tmpSphereVerts[i2].length;
  19728. let _g1 = 0;
  19729. while(_g1 < n) {
  19730. let j2 = _g1++;
  19731. let _this = vs[i2][j2];
  19732. let v = ns[i2][j2];
  19733. _this.x = v.x;
  19734. _this.y = v.y;
  19735. _this.z = v.z;
  19736. _this.x *= radius;
  19737. _this.y *= radius;
  19738. _this.z *= radius;
  19739. _this.x += o.x;
  19740. _this.y += o.y;
  19741. _this.z += o.z;
  19742. let s = -halfHeight;
  19743. _this.x += ey.x * s;
  19744. _this.y += ey.y * s;
  19745. _this.z += ey.z * s;
  19746. }
  19747. }
  19748. }
  19749. let _g = 0;
  19750. while(_g < 8) {
  19751. let j = _g++;
  19752. let v1;
  19753. let v2;
  19754. let v3;
  19755. let v4;
  19756. let n1;
  19757. let n2;
  19758. let n3;
  19759. let n4;
  19760. if(i == 0) {
  19761. if(this.wireframe) {
  19762. v1 = vs[0][0];
  19763. v2 = vs[1][j];
  19764. this.line(v1,v2,color);
  19765. } else {
  19766. v1 = vs[0][0];
  19767. v2 = vs[1][j];
  19768. v3 = vs[1][(j + 1) % 8];
  19769. n1 = ns[0][0];
  19770. n2 = ns[1][j];
  19771. n3 = ns[1][(j + 1) % 8];
  19772. this.triangle(v1,v2,v3,n1,n2,n3,color);
  19773. }
  19774. } else if(i == 3) {
  19775. if(this.wireframe) {
  19776. v1 = vs[4][0];
  19777. v2 = vs[i][(j + 1) % 8];
  19778. v3 = vs[i][j];
  19779. this.line(v1,v2,color);
  19780. this.line(v2,v3,color);
  19781. } else {
  19782. v1 = vs[4][0];
  19783. v2 = vs[i][(j + 1) % 8];
  19784. v3 = vs[i][j];
  19785. n1 = ns[4][0];
  19786. n2 = ns[i][(j + 1) % 8];
  19787. n3 = ns[i][j];
  19788. this.triangle(v1,v2,v3,n1,n2,n3,color);
  19789. }
  19790. } else if(this.wireframe) {
  19791. v1 = vs[i][j];
  19792. v2 = vs[i][(j + 1) % 8];
  19793. v3 = vs[i + 1][j];
  19794. this.line(v1,v2,color);
  19795. this.line(v1,v3,color);
  19796. } else {
  19797. v1 = vs[i][j];
  19798. v2 = vs[i][(j + 1) % 8];
  19799. v3 = vs[i + 1][j];
  19800. v4 = vs[i + 1][(j + 1) % 8];
  19801. n1 = ns[i][j];
  19802. n2 = ns[i][(j + 1) % 8];
  19803. n3 = ns[i + 1][j];
  19804. n4 = ns[i + 1][(j + 1) % 8];
  19805. this.rect(v1,v3,v4,v2,n1,n3,n4,n2,color);
  19806. }
  19807. }
  19808. }
  19809. let _this5 = this.p;
  19810. let _this6 = _this5.sizeVec3 == 0 ? new oimo.common.Vec3() : _this5.stackVec3[--_this5.sizeVec3];
  19811. _this6.x = o.x;
  19812. _this6.y = o.y;
  19813. _this6.z = o.z;
  19814. let _this7 = _this6;
  19815. _this7.x += ey.x * halfHeight;
  19816. _this7.y += ey.y * halfHeight;
  19817. _this7.z += ey.z * halfHeight;
  19818. let _this8 = this.p;
  19819. let _this9 = _this8.sizeVec3 == 0 ? new oimo.common.Vec3() : _this8.stackVec3[--_this8.sizeVec3];
  19820. _this9.x = o.x;
  19821. _this9.y = o.y;
  19822. _this9.z = o.z;
  19823. let _this10 = _this9;
  19824. let s = -halfHeight;
  19825. _this10.x += ey.x * s;
  19826. _this10.y += ey.y * s;
  19827. _this10.z += ey.z * s;
  19828. if(this.wireframe) {
  19829. let _this = this.p;
  19830. let _this1 = _this.sizeVec3 == 0 ? new oimo.common.Vec3() : _this.stackVec3[--_this.sizeVec3];
  19831. _this1.x = _this7.x;
  19832. _this1.y = _this7.y;
  19833. _this1.z = _this7.z;
  19834. let _this2 = _this1;
  19835. let s = -radius;
  19836. _this2.x += ex.x * s;
  19837. _this2.y += ex.y * s;
  19838. _this2.z += ex.z * s;
  19839. _this2.x += ez.x * 0;
  19840. _this2.y += ez.y * 0;
  19841. _this2.z += ez.z * 0;
  19842. let _this3 = this.p;
  19843. let _this4 = _this3.sizeVec3 == 0 ? new oimo.common.Vec3() : _this3.stackVec3[--_this3.sizeVec3];
  19844. _this4.x = _this7.x;
  19845. _this4.y = _this7.y;
  19846. _this4.z = _this7.z;
  19847. let _this5 = _this4;
  19848. _this5.x += ex.x * radius;
  19849. _this5.y += ex.y * radius;
  19850. _this5.z += ex.z * radius;
  19851. _this5.x += ez.x * 0;
  19852. _this5.y += ez.y * 0;
  19853. _this5.z += ez.z * 0;
  19854. let _this6 = this.p;
  19855. let _this8 = _this6.sizeVec3 == 0 ? new oimo.common.Vec3() : _this6.stackVec3[--_this6.sizeVec3];
  19856. _this8.x = _this7.x;
  19857. _this8.y = _this7.y;
  19858. _this8.z = _this7.z;
  19859. let _this9 = _this8;
  19860. _this9.x += ex.x * 0;
  19861. _this9.y += ex.y * 0;
  19862. _this9.z += ex.z * 0;
  19863. let s1 = -radius;
  19864. _this9.x += ez.x * s1;
  19865. _this9.y += ez.y * s1;
  19866. _this9.z += ez.z * s1;
  19867. let _this11 = this.p;
  19868. let _this12 = _this11.sizeVec3 == 0 ? new oimo.common.Vec3() : _this11.stackVec3[--_this11.sizeVec3];
  19869. _this12.x = _this7.x;
  19870. _this12.y = _this7.y;
  19871. _this12.z = _this7.z;
  19872. let _this13 = _this12;
  19873. _this13.x += ex.x * 0;
  19874. _this13.y += ex.y * 0;
  19875. _this13.z += ex.z * 0;
  19876. _this13.x += ez.x * radius;
  19877. _this13.y += ez.y * radius;
  19878. _this13.z += ez.z * radius;
  19879. let _this14 = this.p;
  19880. let _this15 = _this14.sizeVec3 == 0 ? new oimo.common.Vec3() : _this14.stackVec3[--_this14.sizeVec3];
  19881. _this15.x = _this10.x;
  19882. _this15.y = _this10.y;
  19883. _this15.z = _this10.z;
  19884. let _this16 = _this15;
  19885. let s2 = -radius;
  19886. _this16.x += ex.x * s2;
  19887. _this16.y += ex.y * s2;
  19888. _this16.z += ex.z * s2;
  19889. _this16.x += ez.x * 0;
  19890. _this16.y += ez.y * 0;
  19891. _this16.z += ez.z * 0;
  19892. let _this17 = this.p;
  19893. let _this18 = _this17.sizeVec3 == 0 ? new oimo.common.Vec3() : _this17.stackVec3[--_this17.sizeVec3];
  19894. _this18.x = _this10.x;
  19895. _this18.y = _this10.y;
  19896. _this18.z = _this10.z;
  19897. let _this19 = _this18;
  19898. _this19.x += ex.x * radius;
  19899. _this19.y += ex.y * radius;
  19900. _this19.z += ex.z * radius;
  19901. _this19.x += ez.x * 0;
  19902. _this19.y += ez.y * 0;
  19903. _this19.z += ez.z * 0;
  19904. let _this20 = this.p;
  19905. let _this21 = _this20.sizeVec3 == 0 ? new oimo.common.Vec3() : _this20.stackVec3[--_this20.sizeVec3];
  19906. _this21.x = _this10.x;
  19907. _this21.y = _this10.y;
  19908. _this21.z = _this10.z;
  19909. let _this22 = _this21;
  19910. _this22.x += ex.x * 0;
  19911. _this22.y += ex.y * 0;
  19912. _this22.z += ex.z * 0;
  19913. let s3 = -radius;
  19914. _this22.x += ez.x * s3;
  19915. _this22.y += ez.y * s3;
  19916. _this22.z += ez.z * s3;
  19917. let _this23 = this.p;
  19918. let _this24 = _this23.sizeVec3 == 0 ? new oimo.common.Vec3() : _this23.stackVec3[--_this23.sizeVec3];
  19919. _this24.x = _this10.x;
  19920. _this24.y = _this10.y;
  19921. _this24.z = _this10.z;
  19922. let _this25 = _this24;
  19923. _this25.x += ex.x * 0;
  19924. _this25.y += ex.y * 0;
  19925. _this25.z += ex.z * 0;
  19926. _this25.x += ez.x * radius;
  19927. _this25.y += ez.y * radius;
  19928. _this25.z += ez.z * radius;
  19929. this.ellipse(_this7,ex,ez,radius,radius,color);
  19930. this.ellipse(_this10,ex,ez,radius,radius,color);
  19931. this.line(_this2,_this16,color);
  19932. this.line(_this5,_this19,color);
  19933. this.line(_this9,_this22,color);
  19934. this.line(_this13,_this25,color);
  19935. let _this26 = this.p;
  19936. if(_this2 != null) {
  19937. _this2.zero();
  19938. if(_this26.sizeVec3 == _this26.stackVec3.length) {
  19939. let newArray = new Array(_this26.sizeVec3 << 1);
  19940. let _g = 0;
  19941. let _g1 = _this26.sizeVec3;
  19942. while(_g < _g1) {
  19943. let i = _g++;
  19944. newArray[i] = _this26.stackVec3[i];
  19945. _this26.stackVec3[i] = null;
  19946. }
  19947. _this26.stackVec3 = newArray;
  19948. }
  19949. _this26.stackVec3[_this26.sizeVec3++] = _this2;
  19950. }
  19951. let _this27 = this.p;
  19952. if(_this5 != null) {
  19953. _this5.zero();
  19954. if(_this27.sizeVec3 == _this27.stackVec3.length) {
  19955. let newArray = new Array(_this27.sizeVec3 << 1);
  19956. let _g = 0;
  19957. let _g1 = _this27.sizeVec3;
  19958. while(_g < _g1) {
  19959. let i = _g++;
  19960. newArray[i] = _this27.stackVec3[i];
  19961. _this27.stackVec3[i] = null;
  19962. }
  19963. _this27.stackVec3 = newArray;
  19964. }
  19965. _this27.stackVec3[_this27.sizeVec3++] = _this5;
  19966. }
  19967. let _this28 = this.p;
  19968. if(_this9 != null) {
  19969. _this9.zero();
  19970. if(_this28.sizeVec3 == _this28.stackVec3.length) {
  19971. let newArray = new Array(_this28.sizeVec3 << 1);
  19972. let _g = 0;
  19973. let _g1 = _this28.sizeVec3;
  19974. while(_g < _g1) {
  19975. let i = _g++;
  19976. newArray[i] = _this28.stackVec3[i];
  19977. _this28.stackVec3[i] = null;
  19978. }
  19979. _this28.stackVec3 = newArray;
  19980. }
  19981. _this28.stackVec3[_this28.sizeVec3++] = _this9;
  19982. }
  19983. let _this29 = this.p;
  19984. if(_this13 != null) {
  19985. _this13.zero();
  19986. if(_this29.sizeVec3 == _this29.stackVec3.length) {
  19987. let newArray = new Array(_this29.sizeVec3 << 1);
  19988. let _g = 0;
  19989. let _g1 = _this29.sizeVec3;
  19990. while(_g < _g1) {
  19991. let i = _g++;
  19992. newArray[i] = _this29.stackVec3[i];
  19993. _this29.stackVec3[i] = null;
  19994. }
  19995. _this29.stackVec3 = newArray;
  19996. }
  19997. _this29.stackVec3[_this29.sizeVec3++] = _this13;
  19998. }
  19999. let _this30 = this.p;
  20000. if(_this16 != null) {
  20001. _this16.zero();
  20002. if(_this30.sizeVec3 == _this30.stackVec3.length) {
  20003. let newArray = new Array(_this30.sizeVec3 << 1);
  20004. let _g = 0;
  20005. let _g1 = _this30.sizeVec3;
  20006. while(_g < _g1) {
  20007. let i = _g++;
  20008. newArray[i] = _this30.stackVec3[i];
  20009. _this30.stackVec3[i] = null;
  20010. }
  20011. _this30.stackVec3 = newArray;
  20012. }
  20013. _this30.stackVec3[_this30.sizeVec3++] = _this16;
  20014. }
  20015. let _this31 = this.p;
  20016. if(_this19 != null) {
  20017. _this19.zero();
  20018. if(_this31.sizeVec3 == _this31.stackVec3.length) {
  20019. let newArray = new Array(_this31.sizeVec3 << 1);
  20020. let _g = 0;
  20021. let _g1 = _this31.sizeVec3;
  20022. while(_g < _g1) {
  20023. let i = _g++;
  20024. newArray[i] = _this31.stackVec3[i];
  20025. _this31.stackVec3[i] = null;
  20026. }
  20027. _this31.stackVec3 = newArray;
  20028. }
  20029. _this31.stackVec3[_this31.sizeVec3++] = _this19;
  20030. }
  20031. let _this32 = this.p;
  20032. if(_this22 != null) {
  20033. _this22.zero();
  20034. if(_this32.sizeVec3 == _this32.stackVec3.length) {
  20035. let newArray = new Array(_this32.sizeVec3 << 1);
  20036. let _g = 0;
  20037. let _g1 = _this32.sizeVec3;
  20038. while(_g < _g1) {
  20039. let i = _g++;
  20040. newArray[i] = _this32.stackVec3[i];
  20041. _this32.stackVec3[i] = null;
  20042. }
  20043. _this32.stackVec3 = newArray;
  20044. }
  20045. _this32.stackVec3[_this32.sizeVec3++] = _this22;
  20046. }
  20047. let _this33 = this.p;
  20048. if(_this25 != null) {
  20049. _this25.zero();
  20050. if(_this33.sizeVec3 == _this33.stackVec3.length) {
  20051. let newArray = new Array(_this33.sizeVec3 << 1);
  20052. let _g = 0;
  20053. let _g1 = _this33.sizeVec3;
  20054. while(_g < _g1) {
  20055. let i = _g++;
  20056. newArray[i] = _this33.stackVec3[i];
  20057. _this33.stackVec3[i] = null;
  20058. }
  20059. _this33.stackVec3 = newArray;
  20060. }
  20061. _this33.stackVec3[_this33.sizeVec3++] = _this25;
  20062. }
  20063. } else {
  20064. let _g = 0;
  20065. while(_g < 8) {
  20066. let i = _g++;
  20067. let _this = this.tmpCircleNorms[i];
  20068. let v = this.circleCoords[i];
  20069. _this.x = v.x;
  20070. _this.y = v.y;
  20071. _this.z = v.z;
  20072. let y = _this.x * m.e10 + _this.y * m.e11 + _this.z * m.e12;
  20073. let z = _this.x * m.e20 + _this.y * m.e21 + _this.z * m.e22;
  20074. _this.x = _this.x * m.e00 + _this.y * m.e01 + _this.z * m.e02;
  20075. _this.y = y;
  20076. _this.z = z;
  20077. let _this1 = this.tmpCircleVerts1[i];
  20078. let v1 = this.tmpCircleNorms[i];
  20079. _this1.x = v1.x;
  20080. _this1.y = v1.y;
  20081. _this1.z = v1.z;
  20082. _this1.x *= radius;
  20083. _this1.y *= radius;
  20084. _this1.z *= radius;
  20085. _this1.x += o.x;
  20086. _this1.y += o.y;
  20087. _this1.z += o.z;
  20088. let _this2 = this.tmpCircleVerts2[i];
  20089. let v2 = this.tmpCircleVerts1[i];
  20090. _this2.x = v2.x;
  20091. _this2.y = v2.y;
  20092. _this2.z = v2.z;
  20093. let _this3 = this.tmpCircleVerts1[i];
  20094. _this3.x += ey.x * halfHeight;
  20095. _this3.y += ey.y * halfHeight;
  20096. _this3.z += ey.z * halfHeight;
  20097. let _this4 = this.tmpCircleVerts2[i];
  20098. let s = -halfHeight;
  20099. _this4.x += ey.x * s;
  20100. _this4.y += ey.y * s;
  20101. _this4.z += ey.z * s;
  20102. }
  20103. let _g1 = 0;
  20104. while(_g1 < 8) {
  20105. let i = _g1++;
  20106. let n1 = this.tmpCircleNorms[i];
  20107. let n2 = this.tmpCircleNorms[(i + 1) % 8];
  20108. this.rect(this.tmpCircleVerts1[i],this.tmpCircleVerts2[i],this.tmpCircleVerts2[(i + 1) % 8],this.tmpCircleVerts1[(i + 1) % 8],n1,n1,n2,n2,color);
  20109. }
  20110. }
  20111. let _this11 = this.p;
  20112. if(_this7 != null) {
  20113. _this7.zero();
  20114. if(_this11.sizeVec3 == _this11.stackVec3.length) {
  20115. let newArray = new Array(_this11.sizeVec3 << 1);
  20116. let _g = 0;
  20117. let _g1 = _this11.sizeVec3;
  20118. while(_g < _g1) {
  20119. let i = _g++;
  20120. newArray[i] = _this11.stackVec3[i];
  20121. _this11.stackVec3[i] = null;
  20122. }
  20123. _this11.stackVec3 = newArray;
  20124. }
  20125. _this11.stackVec3[_this11.sizeVec3++] = _this7;
  20126. }
  20127. let _this12 = this.p;
  20128. if(_this10 != null) {
  20129. _this10.zero();
  20130. if(_this12.sizeVec3 == _this12.stackVec3.length) {
  20131. let newArray = new Array(_this12.sizeVec3 << 1);
  20132. let _g = 0;
  20133. let _g1 = _this12.sizeVec3;
  20134. while(_g < _g1) {
  20135. let i = _g++;
  20136. newArray[i] = _this12.stackVec3[i];
  20137. _this12.stackVec3[i] = null;
  20138. }
  20139. _this12.stackVec3 = newArray;
  20140. }
  20141. _this12.stackVec3[_this12.sizeVec3++] = _this10;
  20142. }
  20143. let _this13 = this.p;
  20144. if(o != null) {
  20145. o.zero();
  20146. if(_this13.sizeVec3 == _this13.stackVec3.length) {
  20147. let newArray = new Array(_this13.sizeVec3 << 1);
  20148. let _g = 0;
  20149. let _g1 = _this13.sizeVec3;
  20150. while(_g < _g1) {
  20151. let i = _g++;
  20152. newArray[i] = _this13.stackVec3[i];
  20153. _this13.stackVec3[i] = null;
  20154. }
  20155. _this13.stackVec3 = newArray;
  20156. }
  20157. _this13.stackVec3[_this13.sizeVec3++] = o;
  20158. }
  20159. let _this14 = this.p;
  20160. if(m != null) {
  20161. m.e00 = 1;
  20162. m.e01 = 0;
  20163. m.e02 = 0;
  20164. m.e10 = 0;
  20165. m.e11 = 1;
  20166. m.e12 = 0;
  20167. m.e20 = 0;
  20168. m.e21 = 0;
  20169. m.e22 = 1;
  20170. if(_this14.sizeMat3 == _this14.stackMat3.length) {
  20171. let newArray = new Array(_this14.sizeMat3 << 1);
  20172. let _g = 0;
  20173. let _g1 = _this14.sizeMat3;
  20174. while(_g < _g1) {
  20175. let i = _g++;
  20176. newArray[i] = _this14.stackMat3[i];
  20177. _this14.stackMat3[i] = null;
  20178. }
  20179. _this14.stackMat3 = newArray;
  20180. }
  20181. _this14.stackMat3[_this14.sizeMat3++] = m;
  20182. }
  20183. let _this15 = this.p;
  20184. if(ex != null) {
  20185. ex.zero();
  20186. if(_this15.sizeVec3 == _this15.stackVec3.length) {
  20187. let newArray = new Array(_this15.sizeVec3 << 1);
  20188. let _g = 0;
  20189. let _g1 = _this15.sizeVec3;
  20190. while(_g < _g1) {
  20191. let i = _g++;
  20192. newArray[i] = _this15.stackVec3[i];
  20193. _this15.stackVec3[i] = null;
  20194. }
  20195. _this15.stackVec3 = newArray;
  20196. }
  20197. _this15.stackVec3[_this15.sizeVec3++] = ex;
  20198. }
  20199. let _this16 = this.p;
  20200. if(ey != null) {
  20201. ey.zero();
  20202. if(_this16.sizeVec3 == _this16.stackVec3.length) {
  20203. let newArray = new Array(_this16.sizeVec3 << 1);
  20204. let _g = 0;
  20205. let _g1 = _this16.sizeVec3;
  20206. while(_g < _g1) {
  20207. let i = _g++;
  20208. newArray[i] = _this16.stackVec3[i];
  20209. _this16.stackVec3[i] = null;
  20210. }
  20211. _this16.stackVec3 = newArray;
  20212. }
  20213. _this16.stackVec3[_this16.sizeVec3++] = ey;
  20214. }
  20215. let _this17 = this.p;
  20216. if(ez != null) {
  20217. ez.zero();
  20218. if(_this17.sizeVec3 == _this17.stackVec3.length) {
  20219. let newArray = new Array(_this17.sizeVec3 << 1);
  20220. let _g = 0;
  20221. let _g1 = _this17.sizeVec3;
  20222. while(_g < _g1) {
  20223. let i = _g++;
  20224. newArray[i] = _this17.stackVec3[i];
  20225. _this17.stackVec3[i] = null;
  20226. }
  20227. _this17.stackVec3 = newArray;
  20228. }
  20229. _this17.stackVec3[_this17.sizeVec3++] = ez;
  20230. }
  20231. }
  20232. sphere(tf,radius,color) {
  20233. let _this = this.p;
  20234. let o = _this.sizeVec3 == 0 ? new oimo.common.Vec3() : _this.stackVec3[--_this.sizeVec3];
  20235. let _this1 = this.p;
  20236. let m = _this1.sizeMat3 == 0 ? new oimo.common.Mat3() : _this1.stackMat3[--_this1.sizeMat3];
  20237. let v = o;
  20238. v.x = tf._positionX;
  20239. v.y = tf._positionY;
  20240. v.z = tf._positionZ;
  20241. let m1 = m;
  20242. m1.e00 = tf._rotation00;
  20243. m1.e01 = tf._rotation01;
  20244. m1.e02 = tf._rotation02;
  20245. m1.e10 = tf._rotation10;
  20246. m1.e11 = tf._rotation11;
  20247. m1.e12 = tf._rotation12;
  20248. m1.e20 = tf._rotation20;
  20249. m1.e21 = tf._rotation21;
  20250. m1.e22 = tf._rotation22;
  20251. let vs = this.tmpSphereVerts;
  20252. let ns = this.tmpSphereNorms;
  20253. let _g = 0;
  20254. while(_g < 5) {
  20255. let i = _g++;
  20256. let n = this.tmpSphereVerts[i].length;
  20257. let _g1 = 0;
  20258. while(_g1 < n) {
  20259. let j = _g1++;
  20260. let _this = ns[i][j];
  20261. let v = this.sphereCoords[i][j];
  20262. _this.x = v.x;
  20263. _this.y = v.y;
  20264. _this.z = v.z;
  20265. let y = _this.x * m.e10 + _this.y * m.e11 + _this.z * m.e12;
  20266. let z = _this.x * m.e20 + _this.y * m.e21 + _this.z * m.e22;
  20267. _this.x = _this.x * m.e00 + _this.y * m.e01 + _this.z * m.e02;
  20268. _this.y = y;
  20269. _this.z = z;
  20270. let _this1 = vs[i][j];
  20271. let v1 = ns[i][j];
  20272. _this1.x = v1.x;
  20273. _this1.y = v1.y;
  20274. _this1.z = v1.z;
  20275. _this1.x *= radius;
  20276. _this1.y *= radius;
  20277. _this1.z *= radius;
  20278. _this1.x += o.x;
  20279. _this1.y += o.y;
  20280. _this1.z += o.z;
  20281. }
  20282. }
  20283. let _g1 = 0;
  20284. while(_g1 < 4) {
  20285. let i = _g1++;
  20286. let _g = 0;
  20287. while(_g < 8) {
  20288. let j = _g++;
  20289. let v1;
  20290. let v2;
  20291. let v3;
  20292. let v4;
  20293. let n1;
  20294. let n2;
  20295. let n3;
  20296. let n4;
  20297. if(i == 0) {
  20298. if(this.wireframe) {
  20299. v1 = vs[0][0];
  20300. v2 = vs[1][j];
  20301. this.line(v1,v2,color);
  20302. } else {
  20303. v1 = vs[0][0];
  20304. v2 = vs[1][j];
  20305. v3 = vs[1][(j + 1) % 8];
  20306. n1 = ns[0][0];
  20307. n2 = ns[1][j];
  20308. n3 = ns[1][(j + 1) % 8];
  20309. this.triangle(v1,v2,v3,n1,n2,n3,color);
  20310. }
  20311. } else if(i == 3) {
  20312. if(this.wireframe) {
  20313. v1 = vs[4][0];
  20314. v2 = vs[i][(j + 1) % 8];
  20315. v3 = vs[i][j];
  20316. this.line(v1,v2,color);
  20317. this.line(v2,v3,color);
  20318. } else {
  20319. v1 = vs[4][0];
  20320. v2 = vs[i][(j + 1) % 8];
  20321. v3 = vs[i][j];
  20322. n1 = ns[4][0];
  20323. n2 = ns[i][(j + 1) % 8];
  20324. n3 = ns[i][j];
  20325. this.triangle(v1,v2,v3,n1,n2,n3,color);
  20326. }
  20327. } else if(this.wireframe) {
  20328. v1 = vs[i][j];
  20329. v2 = vs[i][(j + 1) % 8];
  20330. v3 = vs[i + 1][j];
  20331. this.line(v1,v2,color);
  20332. this.line(v1,v3,color);
  20333. } else {
  20334. v1 = vs[i][j];
  20335. v2 = vs[i][(j + 1) % 8];
  20336. v3 = vs[i + 1][j];
  20337. v4 = vs[i + 1][(j + 1) % 8];
  20338. n1 = ns[i][j];
  20339. n2 = ns[i][(j + 1) % 8];
  20340. n3 = ns[i + 1][j];
  20341. n4 = ns[i + 1][(j + 1) % 8];
  20342. this.rect(v1,v3,v4,v2,n1,n3,n4,n2,color);
  20343. }
  20344. }
  20345. }
  20346. let _this2 = this.p;
  20347. if(o != null) {
  20348. o.zero();
  20349. if(_this2.sizeVec3 == _this2.stackVec3.length) {
  20350. let newArray = new Array(_this2.sizeVec3 << 1);
  20351. let _g = 0;
  20352. let _g1 = _this2.sizeVec3;
  20353. while(_g < _g1) {
  20354. let i = _g++;
  20355. newArray[i] = _this2.stackVec3[i];
  20356. _this2.stackVec3[i] = null;
  20357. }
  20358. _this2.stackVec3 = newArray;
  20359. }
  20360. _this2.stackVec3[_this2.sizeVec3++] = o;
  20361. }
  20362. let _this3 = this.p;
  20363. if(m != null) {
  20364. m.e00 = 1;
  20365. m.e01 = 0;
  20366. m.e02 = 0;
  20367. m.e10 = 0;
  20368. m.e11 = 1;
  20369. m.e12 = 0;
  20370. m.e20 = 0;
  20371. m.e21 = 0;
  20372. m.e22 = 1;
  20373. if(_this3.sizeMat3 == _this3.stackMat3.length) {
  20374. let newArray = new Array(_this3.sizeMat3 << 1);
  20375. let _g = 0;
  20376. let _g1 = _this3.sizeMat3;
  20377. while(_g < _g1) {
  20378. let i = _g++;
  20379. newArray[i] = _this3.stackMat3[i];
  20380. _this3.stackMat3[i] = null;
  20381. }
  20382. _this3.stackMat3 = newArray;
  20383. }
  20384. _this3.stackMat3[_this3.sizeMat3++] = m;
  20385. }
  20386. }
  20387. box(tf,halfExtents,color) {
  20388. let _this = this.p;
  20389. let ex = _this.sizeVec3 == 0 ? new oimo.common.Vec3() : _this.stackVec3[--_this.sizeVec3];
  20390. let _this1 = this.p;
  20391. let ey = _this1.sizeVec3 == 0 ? new oimo.common.Vec3() : _this1.stackVec3[--_this1.sizeVec3];
  20392. let _this2 = this.p;
  20393. let ez = _this2.sizeVec3 == 0 ? new oimo.common.Vec3() : _this2.stackVec3[--_this2.sizeVec3];
  20394. let _this3 = this.p;
  20395. let o = _this3.sizeVec3 == 0 ? new oimo.common.Vec3() : _this3.stackVec3[--_this3.sizeVec3];
  20396. let _this4 = this.p;
  20397. let m = _this4.sizeMat3 == 0 ? new oimo.common.Mat3() : _this4.stackMat3[--_this4.sizeMat3];
  20398. let v = o;
  20399. v.x = tf._positionX;
  20400. v.y = tf._positionY;
  20401. v.z = tf._positionZ;
  20402. let m1 = m;
  20403. m1.e00 = tf._rotation00;
  20404. m1.e01 = tf._rotation01;
  20405. m1.e02 = tf._rotation02;
  20406. m1.e10 = tf._rotation10;
  20407. m1.e11 = tf._rotation11;
  20408. m1.e12 = tf._rotation12;
  20409. m1.e20 = tf._rotation20;
  20410. m1.e21 = tf._rotation21;
  20411. m1.e22 = tf._rotation22;
  20412. ex.init(m.e00,m.e10,m.e20);
  20413. ey.init(m.e01,m.e11,m.e21);
  20414. ez.init(m.e02,m.e12,m.e22);
  20415. let hx = halfExtents.x;
  20416. let hy = halfExtents.y;
  20417. let hz = halfExtents.z;
  20418. let _this5 = this.p;
  20419. let _this6 = _this5.sizeVec3 == 0 ? new oimo.common.Vec3() : _this5.stackVec3[--_this5.sizeVec3];
  20420. _this6.x = o.x;
  20421. _this6.y = o.y;
  20422. _this6.z = o.z;
  20423. let _this7 = _this6;
  20424. let s = -hx;
  20425. _this7.x += ex.x * s;
  20426. _this7.y += ex.y * s;
  20427. _this7.z += ex.z * s;
  20428. let s1 = -hy;
  20429. _this7.x += ey.x * s1;
  20430. _this7.y += ey.y * s1;
  20431. _this7.z += ey.z * s1;
  20432. let s2 = -hz;
  20433. _this7.x += ez.x * s2;
  20434. _this7.y += ez.y * s2;
  20435. _this7.z += ez.z * s2;
  20436. let _this8 = this.p;
  20437. let _this9 = _this8.sizeVec3 == 0 ? new oimo.common.Vec3() : _this8.stackVec3[--_this8.sizeVec3];
  20438. _this9.x = o.x;
  20439. _this9.y = o.y;
  20440. _this9.z = o.z;
  20441. let _this10 = _this9;
  20442. let s3 = -hx;
  20443. _this10.x += ex.x * s3;
  20444. _this10.y += ex.y * s3;
  20445. _this10.z += ex.z * s3;
  20446. let s4 = -hy;
  20447. _this10.x += ey.x * s4;
  20448. _this10.y += ey.y * s4;
  20449. _this10.z += ey.z * s4;
  20450. _this10.x += ez.x * hz;
  20451. _this10.y += ez.y * hz;
  20452. _this10.z += ez.z * hz;
  20453. let _this11 = this.p;
  20454. let _this12 = _this11.sizeVec3 == 0 ? new oimo.common.Vec3() : _this11.stackVec3[--_this11.sizeVec3];
  20455. _this12.x = o.x;
  20456. _this12.y = o.y;
  20457. _this12.z = o.z;
  20458. let _this13 = _this12;
  20459. let s5 = -hx;
  20460. _this13.x += ex.x * s5;
  20461. _this13.y += ex.y * s5;
  20462. _this13.z += ex.z * s5;
  20463. _this13.x += ey.x * hy;
  20464. _this13.y += ey.y * hy;
  20465. _this13.z += ey.z * hy;
  20466. let s6 = -hz;
  20467. _this13.x += ez.x * s6;
  20468. _this13.y += ez.y * s6;
  20469. _this13.z += ez.z * s6;
  20470. let _this14 = this.p;
  20471. let _this15 = _this14.sizeVec3 == 0 ? new oimo.common.Vec3() : _this14.stackVec3[--_this14.sizeVec3];
  20472. _this15.x = o.x;
  20473. _this15.y = o.y;
  20474. _this15.z = o.z;
  20475. let _this16 = _this15;
  20476. let s7 = -hx;
  20477. _this16.x += ex.x * s7;
  20478. _this16.y += ex.y * s7;
  20479. _this16.z += ex.z * s7;
  20480. _this16.x += ey.x * hy;
  20481. _this16.y += ey.y * hy;
  20482. _this16.z += ey.z * hy;
  20483. _this16.x += ez.x * hz;
  20484. _this16.y += ez.y * hz;
  20485. _this16.z += ez.z * hz;
  20486. let _this17 = this.p;
  20487. let _this18 = _this17.sizeVec3 == 0 ? new oimo.common.Vec3() : _this17.stackVec3[--_this17.sizeVec3];
  20488. _this18.x = o.x;
  20489. _this18.y = o.y;
  20490. _this18.z = o.z;
  20491. let _this19 = _this18;
  20492. _this19.x += ex.x * hx;
  20493. _this19.y += ex.y * hx;
  20494. _this19.z += ex.z * hx;
  20495. let s8 = -hy;
  20496. _this19.x += ey.x * s8;
  20497. _this19.y += ey.y * s8;
  20498. _this19.z += ey.z * s8;
  20499. let s9 = -hz;
  20500. _this19.x += ez.x * s9;
  20501. _this19.y += ez.y * s9;
  20502. _this19.z += ez.z * s9;
  20503. let _this20 = this.p;
  20504. let _this21 = _this20.sizeVec3 == 0 ? new oimo.common.Vec3() : _this20.stackVec3[--_this20.sizeVec3];
  20505. _this21.x = o.x;
  20506. _this21.y = o.y;
  20507. _this21.z = o.z;
  20508. let _this22 = _this21;
  20509. _this22.x += ex.x * hx;
  20510. _this22.y += ex.y * hx;
  20511. _this22.z += ex.z * hx;
  20512. let s10 = -hy;
  20513. _this22.x += ey.x * s10;
  20514. _this22.y += ey.y * s10;
  20515. _this22.z += ey.z * s10;
  20516. _this22.x += ez.x * hz;
  20517. _this22.y += ez.y * hz;
  20518. _this22.z += ez.z * hz;
  20519. let _this23 = this.p;
  20520. let _this24 = _this23.sizeVec3 == 0 ? new oimo.common.Vec3() : _this23.stackVec3[--_this23.sizeVec3];
  20521. _this24.x = o.x;
  20522. _this24.y = o.y;
  20523. _this24.z = o.z;
  20524. let _this25 = _this24;
  20525. _this25.x += ex.x * hx;
  20526. _this25.y += ex.y * hx;
  20527. _this25.z += ex.z * hx;
  20528. _this25.x += ey.x * hy;
  20529. _this25.y += ey.y * hy;
  20530. _this25.z += ey.z * hy;
  20531. let s11 = -hz;
  20532. _this25.x += ez.x * s11;
  20533. _this25.y += ez.y * s11;
  20534. _this25.z += ez.z * s11;
  20535. let _this26 = this.p;
  20536. let _this27 = _this26.sizeVec3 == 0 ? new oimo.common.Vec3() : _this26.stackVec3[--_this26.sizeVec3];
  20537. _this27.x = o.x;
  20538. _this27.y = o.y;
  20539. _this27.z = o.z;
  20540. let _this28 = _this27;
  20541. _this28.x += ex.x * hx;
  20542. _this28.y += ex.y * hx;
  20543. _this28.z += ex.z * hx;
  20544. _this28.x += ey.x * hy;
  20545. _this28.y += ey.y * hy;
  20546. _this28.z += ey.z * hy;
  20547. _this28.x += ez.x * hz;
  20548. _this28.y += ez.y * hz;
  20549. _this28.z += ez.z * hz;
  20550. if(this.wireframe) {
  20551. this.line(_this7,_this10,color);
  20552. this.line(_this13,_this16,color);
  20553. this.line(_this19,_this22,color);
  20554. this.line(_this25,_this28,color);
  20555. this.line(_this7,_this13,color);
  20556. this.line(_this10,_this16,color);
  20557. this.line(_this19,_this25,color);
  20558. this.line(_this22,_this28,color);
  20559. this.line(_this7,_this19,color);
  20560. this.line(_this10,_this22,color);
  20561. this.line(_this13,_this25,color);
  20562. this.line(_this16,_this28,color);
  20563. } else {
  20564. let _this = this.p;
  20565. let _this1 = _this.sizeVec3 == 0 ? new oimo.common.Vec3() : _this.stackVec3[--_this.sizeVec3];
  20566. _this1.x = ex.x;
  20567. _this1.y = ex.y;
  20568. _this1.z = ex.z;
  20569. let _this2 = _this1;
  20570. _this2.x = -_this2.x;
  20571. _this2.y = -_this2.y;
  20572. _this2.z = -_this2.z;
  20573. let _this3 = this.p;
  20574. let _this4 = _this3.sizeVec3 == 0 ? new oimo.common.Vec3() : _this3.stackVec3[--_this3.sizeVec3];
  20575. _this4.x = ey.x;
  20576. _this4.y = ey.y;
  20577. _this4.z = ey.z;
  20578. let _this5 = _this4;
  20579. _this5.x = -_this5.x;
  20580. _this5.y = -_this5.y;
  20581. _this5.z = -_this5.z;
  20582. let _this6 = this.p;
  20583. let _this8 = _this6.sizeVec3 == 0 ? new oimo.common.Vec3() : _this6.stackVec3[--_this6.sizeVec3];
  20584. _this8.x = ez.x;
  20585. _this8.y = ez.y;
  20586. _this8.z = ez.z;
  20587. let _this9 = _this8;
  20588. _this9.x = -_this9.x;
  20589. _this9.y = -_this9.y;
  20590. _this9.z = -_this9.z;
  20591. this.rect(_this7,_this10,_this16,_this13,_this2,_this2,_this2,_this2,color);
  20592. this.rect(_this19,_this25,_this28,_this22,ex,ex,ex,ex,color);
  20593. this.rect(_this7,_this19,_this22,_this10,_this5,_this5,_this5,_this5,color);
  20594. this.rect(_this13,_this16,_this28,_this25,ey,ey,ey,ey,color);
  20595. this.rect(_this7,_this13,_this25,_this19,_this9,_this9,_this9,_this9,color);
  20596. this.rect(_this10,_this22,_this28,_this16,ez,ez,ez,ez,color);
  20597. let _this11 = this.p;
  20598. if(_this2 != null) {
  20599. _this2.zero();
  20600. if(_this11.sizeVec3 == _this11.stackVec3.length) {
  20601. let newArray = new Array(_this11.sizeVec3 << 1);
  20602. let _g = 0;
  20603. let _g1 = _this11.sizeVec3;
  20604. while(_g < _g1) {
  20605. let i = _g++;
  20606. newArray[i] = _this11.stackVec3[i];
  20607. _this11.stackVec3[i] = null;
  20608. }
  20609. _this11.stackVec3 = newArray;
  20610. }
  20611. _this11.stackVec3[_this11.sizeVec3++] = _this2;
  20612. }
  20613. let _this12 = this.p;
  20614. if(_this5 != null) {
  20615. _this5.zero();
  20616. if(_this12.sizeVec3 == _this12.stackVec3.length) {
  20617. let newArray = new Array(_this12.sizeVec3 << 1);
  20618. let _g = 0;
  20619. let _g1 = _this12.sizeVec3;
  20620. while(_g < _g1) {
  20621. let i = _g++;
  20622. newArray[i] = _this12.stackVec3[i];
  20623. _this12.stackVec3[i] = null;
  20624. }
  20625. _this12.stackVec3 = newArray;
  20626. }
  20627. _this12.stackVec3[_this12.sizeVec3++] = _this5;
  20628. }
  20629. let _this14 = this.p;
  20630. if(_this9 != null) {
  20631. _this9.zero();
  20632. if(_this14.sizeVec3 == _this14.stackVec3.length) {
  20633. let newArray = new Array(_this14.sizeVec3 << 1);
  20634. let _g = 0;
  20635. let _g1 = _this14.sizeVec3;
  20636. while(_g < _g1) {
  20637. let i = _g++;
  20638. newArray[i] = _this14.stackVec3[i];
  20639. _this14.stackVec3[i] = null;
  20640. }
  20641. _this14.stackVec3 = newArray;
  20642. }
  20643. _this14.stackVec3[_this14.sizeVec3++] = _this9;
  20644. }
  20645. }
  20646. let _this29 = this.p;
  20647. if(_this7 != null) {
  20648. _this7.zero();
  20649. if(_this29.sizeVec3 == _this29.stackVec3.length) {
  20650. let newArray = new Array(_this29.sizeVec3 << 1);
  20651. let _g = 0;
  20652. let _g1 = _this29.sizeVec3;
  20653. while(_g < _g1) {
  20654. let i = _g++;
  20655. newArray[i] = _this29.stackVec3[i];
  20656. _this29.stackVec3[i] = null;
  20657. }
  20658. _this29.stackVec3 = newArray;
  20659. }
  20660. _this29.stackVec3[_this29.sizeVec3++] = _this7;
  20661. }
  20662. let _this30 = this.p;
  20663. if(_this10 != null) {
  20664. _this10.zero();
  20665. if(_this30.sizeVec3 == _this30.stackVec3.length) {
  20666. let newArray = new Array(_this30.sizeVec3 << 1);
  20667. let _g = 0;
  20668. let _g1 = _this30.sizeVec3;
  20669. while(_g < _g1) {
  20670. let i = _g++;
  20671. newArray[i] = _this30.stackVec3[i];
  20672. _this30.stackVec3[i] = null;
  20673. }
  20674. _this30.stackVec3 = newArray;
  20675. }
  20676. _this30.stackVec3[_this30.sizeVec3++] = _this10;
  20677. }
  20678. let _this31 = this.p;
  20679. if(_this13 != null) {
  20680. _this13.zero();
  20681. if(_this31.sizeVec3 == _this31.stackVec3.length) {
  20682. let newArray = new Array(_this31.sizeVec3 << 1);
  20683. let _g = 0;
  20684. let _g1 = _this31.sizeVec3;
  20685. while(_g < _g1) {
  20686. let i = _g++;
  20687. newArray[i] = _this31.stackVec3[i];
  20688. _this31.stackVec3[i] = null;
  20689. }
  20690. _this31.stackVec3 = newArray;
  20691. }
  20692. _this31.stackVec3[_this31.sizeVec3++] = _this13;
  20693. }
  20694. let _this32 = this.p;
  20695. if(_this16 != null) {
  20696. _this16.zero();
  20697. if(_this32.sizeVec3 == _this32.stackVec3.length) {
  20698. let newArray = new Array(_this32.sizeVec3 << 1);
  20699. let _g = 0;
  20700. let _g1 = _this32.sizeVec3;
  20701. while(_g < _g1) {
  20702. let i = _g++;
  20703. newArray[i] = _this32.stackVec3[i];
  20704. _this32.stackVec3[i] = null;
  20705. }
  20706. _this32.stackVec3 = newArray;
  20707. }
  20708. _this32.stackVec3[_this32.sizeVec3++] = _this16;
  20709. }
  20710. let _this33 = this.p;
  20711. if(_this19 != null) {
  20712. _this19.zero();
  20713. if(_this33.sizeVec3 == _this33.stackVec3.length) {
  20714. let newArray = new Array(_this33.sizeVec3 << 1);
  20715. let _g = 0;
  20716. let _g1 = _this33.sizeVec3;
  20717. while(_g < _g1) {
  20718. let i = _g++;
  20719. newArray[i] = _this33.stackVec3[i];
  20720. _this33.stackVec3[i] = null;
  20721. }
  20722. _this33.stackVec3 = newArray;
  20723. }
  20724. _this33.stackVec3[_this33.sizeVec3++] = _this19;
  20725. }
  20726. let _this34 = this.p;
  20727. if(_this22 != null) {
  20728. _this22.zero();
  20729. if(_this34.sizeVec3 == _this34.stackVec3.length) {
  20730. let newArray = new Array(_this34.sizeVec3 << 1);
  20731. let _g = 0;
  20732. let _g1 = _this34.sizeVec3;
  20733. while(_g < _g1) {
  20734. let i = _g++;
  20735. newArray[i] = _this34.stackVec3[i];
  20736. _this34.stackVec3[i] = null;
  20737. }
  20738. _this34.stackVec3 = newArray;
  20739. }
  20740. _this34.stackVec3[_this34.sizeVec3++] = _this22;
  20741. }
  20742. let _this35 = this.p;
  20743. if(_this25 != null) {
  20744. _this25.zero();
  20745. if(_this35.sizeVec3 == _this35.stackVec3.length) {
  20746. let newArray = new Array(_this35.sizeVec3 << 1);
  20747. let _g = 0;
  20748. let _g1 = _this35.sizeVec3;
  20749. while(_g < _g1) {
  20750. let i = _g++;
  20751. newArray[i] = _this35.stackVec3[i];
  20752. _this35.stackVec3[i] = null;
  20753. }
  20754. _this35.stackVec3 = newArray;
  20755. }
  20756. _this35.stackVec3[_this35.sizeVec3++] = _this25;
  20757. }
  20758. let _this36 = this.p;
  20759. if(_this28 != null) {
  20760. _this28.zero();
  20761. if(_this36.sizeVec3 == _this36.stackVec3.length) {
  20762. let newArray = new Array(_this36.sizeVec3 << 1);
  20763. let _g = 0;
  20764. let _g1 = _this36.sizeVec3;
  20765. while(_g < _g1) {
  20766. let i = _g++;
  20767. newArray[i] = _this36.stackVec3[i];
  20768. _this36.stackVec3[i] = null;
  20769. }
  20770. _this36.stackVec3 = newArray;
  20771. }
  20772. _this36.stackVec3[_this36.sizeVec3++] = _this28;
  20773. }
  20774. let _this37 = this.p;
  20775. if(o != null) {
  20776. o.zero();
  20777. if(_this37.sizeVec3 == _this37.stackVec3.length) {
  20778. let newArray = new Array(_this37.sizeVec3 << 1);
  20779. let _g = 0;
  20780. let _g1 = _this37.sizeVec3;
  20781. while(_g < _g1) {
  20782. let i = _g++;
  20783. newArray[i] = _this37.stackVec3[i];
  20784. _this37.stackVec3[i] = null;
  20785. }
  20786. _this37.stackVec3 = newArray;
  20787. }
  20788. _this37.stackVec3[_this37.sizeVec3++] = o;
  20789. }
  20790. let _this38 = this.p;
  20791. if(m != null) {
  20792. m.e00 = 1;
  20793. m.e01 = 0;
  20794. m.e02 = 0;
  20795. m.e10 = 0;
  20796. m.e11 = 1;
  20797. m.e12 = 0;
  20798. m.e20 = 0;
  20799. m.e21 = 0;
  20800. m.e22 = 1;
  20801. if(_this38.sizeMat3 == _this38.stackMat3.length) {
  20802. let newArray = new Array(_this38.sizeMat3 << 1);
  20803. let _g = 0;
  20804. let _g1 = _this38.sizeMat3;
  20805. while(_g < _g1) {
  20806. let i = _g++;
  20807. newArray[i] = _this38.stackMat3[i];
  20808. _this38.stackMat3[i] = null;
  20809. }
  20810. _this38.stackMat3 = newArray;
  20811. }
  20812. _this38.stackMat3[_this38.sizeMat3++] = m;
  20813. }
  20814. let _this39 = this.p;
  20815. if(ex != null) {
  20816. ex.zero();
  20817. if(_this39.sizeVec3 == _this39.stackVec3.length) {
  20818. let newArray = new Array(_this39.sizeVec3 << 1);
  20819. let _g = 0;
  20820. let _g1 = _this39.sizeVec3;
  20821. while(_g < _g1) {
  20822. let i = _g++;
  20823. newArray[i] = _this39.stackVec3[i];
  20824. _this39.stackVec3[i] = null;
  20825. }
  20826. _this39.stackVec3 = newArray;
  20827. }
  20828. _this39.stackVec3[_this39.sizeVec3++] = ex;
  20829. }
  20830. let _this40 = this.p;
  20831. if(ey != null) {
  20832. ey.zero();
  20833. if(_this40.sizeVec3 == _this40.stackVec3.length) {
  20834. let newArray = new Array(_this40.sizeVec3 << 1);
  20835. let _g = 0;
  20836. let _g1 = _this40.sizeVec3;
  20837. while(_g < _g1) {
  20838. let i = _g++;
  20839. newArray[i] = _this40.stackVec3[i];
  20840. _this40.stackVec3[i] = null;
  20841. }
  20842. _this40.stackVec3 = newArray;
  20843. }
  20844. _this40.stackVec3[_this40.sizeVec3++] = ey;
  20845. }
  20846. let _this41 = this.p;
  20847. if(ez != null) {
  20848. ez.zero();
  20849. if(_this41.sizeVec3 == _this41.stackVec3.length) {
  20850. let newArray = new Array(_this41.sizeVec3 << 1);
  20851. let _g = 0;
  20852. let _g1 = _this41.sizeVec3;
  20853. while(_g < _g1) {
  20854. let i = _g++;
  20855. newArray[i] = _this41.stackVec3[i];
  20856. _this41.stackVec3[i] = null;
  20857. }
  20858. _this41.stackVec3 = newArray;
  20859. }
  20860. _this41.stackVec3[_this41.sizeVec3++] = ez;
  20861. }
  20862. }
  20863. rect(v1,v2,v3,v4,n1,n2,n3,n4,color) {
  20864. this.triangle(v1,v2,v3,n1,n2,n3,color);
  20865. this.triangle(v1,v3,v4,n1,n3,n4,color);
  20866. }
  20867. point(v,color) {
  20868. }
  20869. triangle(v1,v2,v3,n1,n2,n3,color) {
  20870. }
  20871. line(v1,v2,color) {
  20872. }
  20873. }
  20874. oimo.dynamics.common.DebugDrawStyle = class oimo_dynamics_common_DebugDrawStyle {
  20875. constructor() {
  20876. this.basisColorZ = new oimo.common.Vec3(0.0,0.0,1.0);
  20877. this.basisColorY = new oimo.common.Vec3(0.0,1.0,0.0);
  20878. this.basisColorX = new oimo.common.Vec3(1.0,0.0,0.0);
  20879. this.basisLength = 0.5;
  20880. this.jointRotationalConstraintRadius = 0.3;
  20881. this.jointErrorColor = new oimo.common.Vec3(1.0,0.1,0.1);
  20882. this.jointLineColor = new oimo.common.Vec3(0.8,0.8,0.8);
  20883. this.contactBinormalLength = 0.5;
  20884. this.contactTangentLength = 0.5;
  20885. this.contactNormalLength = 0.5;
  20886. this.contactBinormalColor = new oimo.common.Vec3(0.2,0.2,1.0);
  20887. this.contactTangentColor = new oimo.common.Vec3(0.1,0.8,0.1);
  20888. this.contactNormalColor = new oimo.common.Vec3(1.0,0.1,0.1);
  20889. this.disabledContactColor = new oimo.common.Vec3(0.5,0.1,0.1);
  20890. this.newContactColor = new oimo.common.Vec3(1.0,1.0,0.1);
  20891. this.contactColor4 = new oimo.common.Vec3(0.8,0.1,1.0);
  20892. this.contactColor3 = new oimo.common.Vec3(0.1,0.8,0.6);
  20893. this.contactColor2 = new oimo.common.Vec3(1.0,0.6,0.1);
  20894. this.contactColor = new oimo.common.Vec3(1.0,0.1,0.1);
  20895. this.pairColor = new oimo.common.Vec3(1.0,1.0,0.1);
  20896. this.bvhNodeColor = new oimo.common.Vec3(0.4,0.4,0.4);
  20897. this.aabbColor = new oimo.common.Vec3(1.0,0.1,0.1);
  20898. this.kinematicShapeColor = new oimo.common.Vec3(1.0,0.5,0.1);
  20899. this.staticShapeColor = new oimo.common.Vec3(0.7,0.7,0.7);
  20900. this.sleepingShapeColor2 = new oimo.common.Vec3(0.2,0.8,0.5);
  20901. this.sleepingShapeColor1 = new oimo.common.Vec3(0.3,0.3,0.8);
  20902. this.sleepyShapeColor2 = new oimo.common.Vec3(0.6,0.8,0.3);
  20903. this.sleepyShapeColor1 = new oimo.common.Vec3(0.5,0.25,0.6);
  20904. this.shapeColor2 = new oimo.common.Vec3(1.0,0.8,0.1);
  20905. this.shapeColor1 = new oimo.common.Vec3(0.7,0.2,0.4);
  20906. }
  20907. }
  20908. oimo.dynamics.common.Performance = class oimo_dynamics_common_Performance {
  20909. }
  20910. if(!oimo.dynamics.constraint) oimo.dynamics.constraint = {};
  20911. oimo.dynamics.constraint.ConstraintSolver = class oimo_dynamics_constraint_ConstraintSolver {
  20912. constructor() {
  20913. this._b1 = null;
  20914. this._b2 = null;
  20915. this._addedToIsland = false;
  20916. }
  20917. preSolveVelocity(timeStep) {
  20918. }
  20919. warmStart(timeStep) {
  20920. }
  20921. solveVelocity() {
  20922. }
  20923. postSolveVelocity(timeStep) {
  20924. }
  20925. preSolvePosition(timeStep) {
  20926. }
  20927. solvePositionSplitImpulse() {
  20928. }
  20929. solvePositionNgs(timeStep) {
  20930. }
  20931. postSolve() {
  20932. }
  20933. }
  20934. oimo.dynamics.constraint.PositionCorrectionAlgorithm = class oimo_dynamics_constraint_PositionCorrectionAlgorithm {
  20935. }
  20936. if(!oimo.dynamics.constraint.contact) oimo.dynamics.constraint.contact = {};
  20937. oimo.dynamics.constraint.contact.ContactConstraint = class oimo_dynamics_constraint_contact_ContactConstraint {
  20938. constructor(manifold) {
  20939. this._solver = new oimo.dynamics.constraint.solver.pgs.PgsContactConstraintSolver(this);
  20940. this._manifold = manifold;
  20941. }
  20942. _getVelocitySolverInfo(timeStep,info) {
  20943. info.b1 = this._b1;
  20944. info.b2 = this._b2;
  20945. let normalX;
  20946. let normalY;
  20947. let normalZ;
  20948. let tangentX;
  20949. let tangentY;
  20950. let tangentZ;
  20951. let binormalX;
  20952. let binormalY;
  20953. let binormalZ;
  20954. normalX = this._manifold._normalX;
  20955. normalY = this._manifold._normalY;
  20956. normalZ = this._manifold._normalZ;
  20957. tangentX = this._manifold._tangentX;
  20958. tangentY = this._manifold._tangentY;
  20959. tangentZ = this._manifold._tangentZ;
  20960. binormalX = this._manifold._binormalX;
  20961. binormalY = this._manifold._binormalY;
  20962. binormalZ = this._manifold._binormalZ;
  20963. let friction = Math.sqrt(this._s1._friction * this._s2._friction);
  20964. let restitution = Math.sqrt(this._s1._restitution * this._s2._restitution);
  20965. let num = this._manifold._numPoints;
  20966. info.numRows = 0;
  20967. let _g = 0;
  20968. while(_g < num) {
  20969. let p = this._manifold._points[_g++];
  20970. if(p._depth < 0) {
  20971. p._disabled = true;
  20972. let _this = p._impulse;
  20973. _this.impulseN = 0;
  20974. _this.impulseT = 0;
  20975. _this.impulseB = 0;
  20976. _this.impulseP = 0;
  20977. _this.impulseLX = 0;
  20978. _this.impulseLY = 0;
  20979. _this.impulseLZ = 0;
  20980. continue;
  20981. } else {
  20982. p._disabled = false;
  20983. }
  20984. let row = info.rows[info.numRows++];
  20985. row.friction = friction;
  20986. row.cfm = 0;
  20987. let j = row.jacobianN;
  20988. j.lin1X = normalX;
  20989. j.lin1Y = normalY;
  20990. j.lin1Z = normalZ;
  20991. j.lin2X = normalX;
  20992. j.lin2Y = normalY;
  20993. j.lin2Z = normalZ;
  20994. j.ang1X = p._relPos1Y * normalZ - p._relPos1Z * normalY;
  20995. j.ang1Y = p._relPos1Z * normalX - p._relPos1X * normalZ;
  20996. j.ang1Z = p._relPos1X * normalY - p._relPos1Y * normalX;
  20997. j.ang2X = p._relPos2Y * normalZ - p._relPos2Z * normalY;
  20998. j.ang2Y = p._relPos2Z * normalX - p._relPos2X * normalZ;
  20999. j.ang2Z = p._relPos2X * normalY - p._relPos2Y * normalX;
  21000. j = row.jacobianT;
  21001. j.lin1X = tangentX;
  21002. j.lin1Y = tangentY;
  21003. j.lin1Z = tangentZ;
  21004. j.lin2X = tangentX;
  21005. j.lin2Y = tangentY;
  21006. j.lin2Z = tangentZ;
  21007. j.ang1X = p._relPos1Y * tangentZ - p._relPos1Z * tangentY;
  21008. j.ang1Y = p._relPos1Z * tangentX - p._relPos1X * tangentZ;
  21009. j.ang1Z = p._relPos1X * tangentY - p._relPos1Y * tangentX;
  21010. j.ang2X = p._relPos2Y * tangentZ - p._relPos2Z * tangentY;
  21011. j.ang2Y = p._relPos2Z * tangentX - p._relPos2X * tangentZ;
  21012. j.ang2Z = p._relPos2X * tangentY - p._relPos2Y * tangentX;
  21013. j = row.jacobianB;
  21014. j.lin1X = binormalX;
  21015. j.lin1Y = binormalY;
  21016. j.lin1Z = binormalZ;
  21017. j.lin2X = binormalX;
  21018. j.lin2Y = binormalY;
  21019. j.lin2Z = binormalZ;
  21020. j.ang1X = p._relPos1Y * binormalZ - p._relPos1Z * binormalY;
  21021. j.ang1Y = p._relPos1Z * binormalX - p._relPos1X * binormalZ;
  21022. j.ang1Z = p._relPos1X * binormalY - p._relPos1Y * binormalX;
  21023. j.ang2X = p._relPos2Y * binormalZ - p._relPos2Z * binormalY;
  21024. j.ang2Y = p._relPos2Z * binormalX - p._relPos2X * binormalZ;
  21025. j.ang2Z = p._relPos2X * binormalY - p._relPos2Y * binormalX;
  21026. j = row.jacobianN;
  21027. let rvn = j.lin1X * this._b1._velX + j.lin1Y * this._b1._velY + j.lin1Z * this._b1._velZ + (j.ang1X * this._b1._angVelX + j.ang1Y * this._b1._angVelY + j.ang1Z * this._b1._angVelZ) - (j.lin2X * this._b2._velX + j.lin2Y * this._b2._velY + j.lin2Z * this._b2._velZ + (j.ang2X * this._b2._angVelX + j.ang2Y * this._b2._angVelY + j.ang2Z * this._b2._angVelZ));
  21028. if(rvn < -oimo.common.Setting.contactEnableBounceThreshold && !p._warmStarted) {
  21029. row.rhs = -rvn * restitution;
  21030. } else {
  21031. row.rhs = 0;
  21032. }
  21033. if(this._positionCorrectionAlgorithm == oimo.dynamics.constraint.PositionCorrectionAlgorithm.BAUMGARTE) {
  21034. if(p._depth > oimo.common.Setting.linearSlop) {
  21035. let minRhs = (p._depth - oimo.common.Setting.linearSlop) * oimo.common.Setting.velocityBaumgarte * timeStep.invDt;
  21036. if(row.rhs < minRhs) {
  21037. row.rhs = minRhs;
  21038. }
  21039. }
  21040. }
  21041. if(!p._warmStarted) {
  21042. let _this = p._impulse;
  21043. _this.impulseN = 0;
  21044. _this.impulseT = 0;
  21045. _this.impulseB = 0;
  21046. _this.impulseP = 0;
  21047. _this.impulseLX = 0;
  21048. _this.impulseLY = 0;
  21049. _this.impulseLZ = 0;
  21050. }
  21051. row.impulse = p._impulse;
  21052. }
  21053. }
  21054. _getPositionSolverInfo(info) {
  21055. info.b1 = this._b1;
  21056. info.b2 = this._b2;
  21057. let normalX;
  21058. let normalY;
  21059. let normalZ;
  21060. normalX = this._manifold._normalX;
  21061. normalY = this._manifold._normalY;
  21062. normalZ = this._manifold._normalZ;
  21063. let num = this._manifold._numPoints;
  21064. info.numRows = 0;
  21065. let _g = 0;
  21066. while(_g < num) {
  21067. let p = this._manifold._points[_g++];
  21068. if(p._disabled) {
  21069. continue;
  21070. }
  21071. let row = info.rows[info.numRows++];
  21072. let j = row.jacobianN;
  21073. j.lin1X = normalX;
  21074. j.lin1Y = normalY;
  21075. j.lin1Z = normalZ;
  21076. j.lin2X = normalX;
  21077. j.lin2Y = normalY;
  21078. j.lin2Z = normalZ;
  21079. j.ang1X = p._relPos1Y * normalZ - p._relPos1Z * normalY;
  21080. j.ang1Y = p._relPos1Z * normalX - p._relPos1X * normalZ;
  21081. j.ang1Z = p._relPos1X * normalY - p._relPos1Y * normalX;
  21082. j.ang2X = p._relPos2Y * normalZ - p._relPos2Z * normalY;
  21083. j.ang2Y = p._relPos2Z * normalX - p._relPos2X * normalZ;
  21084. j.ang2Z = p._relPos2X * normalY - p._relPos2Y * normalX;
  21085. row.rhs = p._depth - oimo.common.Setting.linearSlop;
  21086. if(row.rhs < 0) {
  21087. row.rhs = 0;
  21088. }
  21089. row.impulse = p._impulse;
  21090. }
  21091. }
  21092. _syncManifold() {
  21093. this._manifold._updateDepthsAndPositions(this._tf1,this._tf2);
  21094. }
  21095. getShape1() {
  21096. return this._s1;
  21097. }
  21098. getShape2() {
  21099. return this._s2;
  21100. }
  21101. getManifold() {
  21102. return this._manifold;
  21103. }
  21104. isTouching() {
  21105. let _g = 0;
  21106. let _g1 = this._manifold._numPoints;
  21107. while(_g < _g1) if(this._manifold._points[_g++]._depth >= 0) {
  21108. return true;
  21109. }
  21110. return false;
  21111. }
  21112. }
  21113. oimo.dynamics.constraint.contact.ContactImpulse = class oimo_dynamics_constraint_contact_ContactImpulse {
  21114. constructor() {
  21115. this.impulseN = 0;
  21116. this.impulseT = 0;
  21117. this.impulseB = 0;
  21118. this.impulseP = 0;
  21119. this.impulseLX = 0;
  21120. this.impulseLY = 0;
  21121. this.impulseLZ = 0;
  21122. }
  21123. copyFrom(imp) {
  21124. this.impulseN = imp.impulseN;
  21125. this.impulseT = imp.impulseT;
  21126. this.impulseB = imp.impulseB;
  21127. this.impulseLX = imp.impulseLX;
  21128. this.impulseLY = imp.impulseLY;
  21129. this.impulseLZ = imp.impulseLZ;
  21130. }
  21131. }
  21132. oimo.dynamics.constraint.contact.Manifold = class oimo_dynamics_constraint_contact_Manifold {
  21133. constructor() {
  21134. this._normalX = 0;
  21135. this._normalY = 0;
  21136. this._normalZ = 0;
  21137. this._tangentX = 0;
  21138. this._tangentY = 0;
  21139. this._tangentZ = 0;
  21140. this._binormalX = 0;
  21141. this._binormalY = 0;
  21142. this._binormalZ = 0;
  21143. this._numPoints = 0;
  21144. this._points = new Array(oimo.common.Setting.maxManifoldPoints);
  21145. let _g = 0;
  21146. let _g1 = oimo.common.Setting.maxManifoldPoints;
  21147. while(_g < _g1) this._points[_g++] = new oimo.dynamics.constraint.contact.ManifoldPoint();
  21148. }
  21149. _clear() {
  21150. let _g = 0;
  21151. let _g1 = this._numPoints;
  21152. while(_g < _g1) {
  21153. let _this = this._points[_g++];
  21154. _this._localPos1X = 0;
  21155. _this._localPos1Y = 0;
  21156. _this._localPos1Z = 0;
  21157. _this._localPos2X = 0;
  21158. _this._localPos2Y = 0;
  21159. _this._localPos2Z = 0;
  21160. _this._relPos1X = 0;
  21161. _this._relPos1Y = 0;
  21162. _this._relPos1Z = 0;
  21163. _this._relPos2X = 0;
  21164. _this._relPos2Y = 0;
  21165. _this._relPos2Z = 0;
  21166. _this._pos1X = 0;
  21167. _this._pos1Y = 0;
  21168. _this._pos1Z = 0;
  21169. _this._pos2X = 0;
  21170. _this._pos2Y = 0;
  21171. _this._pos2Z = 0;
  21172. _this._depth = 0;
  21173. let _this1 = _this._impulse;
  21174. _this1.impulseN = 0;
  21175. _this1.impulseT = 0;
  21176. _this1.impulseB = 0;
  21177. _this1.impulseP = 0;
  21178. _this1.impulseLX = 0;
  21179. _this1.impulseLY = 0;
  21180. _this1.impulseLZ = 0;
  21181. _this._warmStarted = false;
  21182. _this._disabled = false;
  21183. _this._id = -1;
  21184. }
  21185. this._numPoints = 0;
  21186. }
  21187. _buildBasis(normal) {
  21188. this._normalX = normal.x;
  21189. this._normalY = normal.y;
  21190. this._normalZ = normal.z;
  21191. let nx = normal.x;
  21192. let ny = normal.y;
  21193. let nz = normal.z;
  21194. let nx2 = nx * nx;
  21195. let ny2 = ny * ny;
  21196. let nz2 = nz * nz;
  21197. let tx;
  21198. let ty;
  21199. let tz;
  21200. let bx;
  21201. let by;
  21202. let bz;
  21203. if(nx2 < ny2) {
  21204. if(nx2 < nz2) {
  21205. let invL = 1 / Math.sqrt(ny2 + nz2);
  21206. tx = 0;
  21207. ty = -nz * invL;
  21208. tz = ny * invL;
  21209. bx = ny * tz - nz * ty;
  21210. by = -nx * tz;
  21211. bz = nx * ty;
  21212. } else {
  21213. let invL = 1 / Math.sqrt(nx2 + ny2);
  21214. tx = -ny * invL;
  21215. ty = nx * invL;
  21216. tz = 0;
  21217. bx = -nz * ty;
  21218. by = nz * tx;
  21219. bz = nx * ty - ny * tx;
  21220. }
  21221. } else if(ny2 < nz2) {
  21222. let invL = 1 / Math.sqrt(nx2 + nz2);
  21223. tx = nz * invL;
  21224. ty = 0;
  21225. tz = -nx * invL;
  21226. bx = ny * tz;
  21227. by = nz * tx - nx * tz;
  21228. bz = -ny * tx;
  21229. } else {
  21230. let invL = 1 / Math.sqrt(nx2 + ny2);
  21231. tx = -ny * invL;
  21232. ty = nx * invL;
  21233. tz = 0;
  21234. bx = -nz * ty;
  21235. by = nz * tx;
  21236. bz = nx * ty - ny * tx;
  21237. }
  21238. this._tangentX = tx;
  21239. this._tangentY = ty;
  21240. this._tangentZ = tz;
  21241. this._binormalX = bx;
  21242. this._binormalY = by;
  21243. this._binormalZ = bz;
  21244. }
  21245. _updateDepthsAndPositions(tf1,tf2) {
  21246. let _g = 0;
  21247. let _g1 = this._numPoints;
  21248. while(_g < _g1) {
  21249. let p = this._points[_g++];
  21250. let __tmp__X;
  21251. let __tmp__Y;
  21252. let __tmp__Z;
  21253. __tmp__X = tf1._rotation00 * p._localPos1X + tf1._rotation01 * p._localPos1Y + tf1._rotation02 * p._localPos1Z;
  21254. __tmp__Y = tf1._rotation10 * p._localPos1X + tf1._rotation11 * p._localPos1Y + tf1._rotation12 * p._localPos1Z;
  21255. __tmp__Z = tf1._rotation20 * p._localPos1X + tf1._rotation21 * p._localPos1Y + tf1._rotation22 * p._localPos1Z;
  21256. p._relPos1X = __tmp__X;
  21257. p._relPos1Y = __tmp__Y;
  21258. p._relPos1Z = __tmp__Z;
  21259. let __tmp__X1;
  21260. let __tmp__Y1;
  21261. let __tmp__Z1;
  21262. __tmp__X1 = tf2._rotation00 * p._localPos2X + tf2._rotation01 * p._localPos2Y + tf2._rotation02 * p._localPos2Z;
  21263. __tmp__Y1 = tf2._rotation10 * p._localPos2X + tf2._rotation11 * p._localPos2Y + tf2._rotation12 * p._localPos2Z;
  21264. __tmp__Z1 = tf2._rotation20 * p._localPos2X + tf2._rotation21 * p._localPos2Y + tf2._rotation22 * p._localPos2Z;
  21265. p._relPos2X = __tmp__X1;
  21266. p._relPos2Y = __tmp__Y1;
  21267. p._relPos2Z = __tmp__Z1;
  21268. p._pos1X = p._relPos1X + tf1._positionX;
  21269. p._pos1Y = p._relPos1Y + tf1._positionY;
  21270. p._pos1Z = p._relPos1Z + tf1._positionZ;
  21271. p._pos2X = p._relPos2X + tf2._positionX;
  21272. p._pos2Y = p._relPos2Y + tf2._positionY;
  21273. p._pos2Z = p._relPos2Z + tf2._positionZ;
  21274. let diffX;
  21275. let diffY;
  21276. let diffZ;
  21277. diffX = p._pos1X - p._pos2X;
  21278. diffY = p._pos1Y - p._pos2Y;
  21279. diffZ = p._pos1Z - p._pos2Z;
  21280. p._depth = -(diffX * this._normalX + diffY * this._normalY + diffZ * this._normalZ);
  21281. }
  21282. }
  21283. getNormal() {
  21284. let v = new oimo.common.Vec3();
  21285. v.x = this._normalX;
  21286. v.y = this._normalY;
  21287. v.z = this._normalZ;
  21288. return v;
  21289. }
  21290. getNormalTo(normal) {
  21291. normal.x = this._normalX;
  21292. normal.y = this._normalY;
  21293. normal.z = this._normalZ;
  21294. }
  21295. getTangent() {
  21296. let v = new oimo.common.Vec3();
  21297. v.x = this._tangentX;
  21298. v.y = this._tangentY;
  21299. v.z = this._tangentZ;
  21300. return v;
  21301. }
  21302. getTangentTo(tangent) {
  21303. tangent.x = this._tangentX;
  21304. tangent.y = this._tangentY;
  21305. tangent.z = this._tangentZ;
  21306. }
  21307. getBinormal() {
  21308. let v = new oimo.common.Vec3();
  21309. v.x = this._binormalX;
  21310. v.y = this._binormalY;
  21311. v.z = this._binormalZ;
  21312. return v;
  21313. }
  21314. getBinormalTo(binormal) {
  21315. binormal.x = this._binormalX;
  21316. binormal.y = this._binormalY;
  21317. binormal.z = this._binormalZ;
  21318. }
  21319. getPoints() {
  21320. return this._points;
  21321. }
  21322. getNumPoints() {
  21323. return this._numPoints;
  21324. }
  21325. }
  21326. oimo.dynamics.constraint.contact.ManifoldPoint = class oimo_dynamics_constraint_contact_ManifoldPoint {
  21327. constructor() {
  21328. this._localPos1X = 0;
  21329. this._localPos1Y = 0;
  21330. this._localPos1Z = 0;
  21331. this._localPos2X = 0;
  21332. this._localPos2Y = 0;
  21333. this._localPos2Z = 0;
  21334. this._relPos1X = 0;
  21335. this._relPos1Y = 0;
  21336. this._relPos1Z = 0;
  21337. this._relPos2X = 0;
  21338. this._relPos2Y = 0;
  21339. this._relPos2Z = 0;
  21340. this._pos1X = 0;
  21341. this._pos1Y = 0;
  21342. this._pos1Z = 0;
  21343. this._pos2X = 0;
  21344. this._pos2Y = 0;
  21345. this._pos2Z = 0;
  21346. this._depth = 0;
  21347. this._impulse = new oimo.dynamics.constraint.contact.ContactImpulse();
  21348. this._warmStarted = false;
  21349. this._disabled = false;
  21350. this._id = -1;
  21351. }
  21352. getPosition1() {
  21353. let v = new oimo.common.Vec3();
  21354. v.x = this._pos1X;
  21355. v.y = this._pos1Y;
  21356. v.z = this._pos1Z;
  21357. return v;
  21358. }
  21359. getPosition1To(position) {
  21360. position.x = this._pos1X;
  21361. position.y = this._pos1Y;
  21362. position.z = this._pos1Z;
  21363. }
  21364. getPosition2() {
  21365. let v = new oimo.common.Vec3();
  21366. v.x = this._pos2X;
  21367. v.y = this._pos2Y;
  21368. v.z = this._pos2Z;
  21369. return v;
  21370. }
  21371. getPosition2To(position) {
  21372. position.x = this._pos2X;
  21373. position.y = this._pos2Y;
  21374. position.z = this._pos2Z;
  21375. }
  21376. getDepth() {
  21377. return this._depth;
  21378. }
  21379. isWarmStarted() {
  21380. return this._warmStarted;
  21381. }
  21382. getNormalImpulse() {
  21383. return this._impulse.impulseN;
  21384. }
  21385. getTangentImpulse() {
  21386. return this._impulse.impulseT;
  21387. }
  21388. getBinormalImpulse() {
  21389. return this._impulse.impulseB;
  21390. }
  21391. isEnabled() {
  21392. return !this._disabled;
  21393. }
  21394. }
  21395. oimo.dynamics.constraint.contact.ManifoldUpdater = class oimo_dynamics_constraint_contact_ManifoldUpdater {
  21396. constructor(manifold) {
  21397. this._manifold = manifold;
  21398. this.numOldPoints = 0;
  21399. this.oldPoints = new Array(oimo.common.Setting.maxManifoldPoints);
  21400. let _g = 0;
  21401. let _g1 = oimo.common.Setting.maxManifoldPoints;
  21402. while(_g < _g1) this.oldPoints[_g++] = new oimo.dynamics.constraint.contact.ManifoldPoint();
  21403. }
  21404. removeOutdatedPoints() {
  21405. let index = this._manifold._numPoints;
  21406. while(--index >= 0) {
  21407. let p = this._manifold._points[index];
  21408. let diffX;
  21409. let diffY;
  21410. let diffZ;
  21411. diffX = p._pos1X - p._pos2X;
  21412. diffY = p._pos1Y - p._pos2Y;
  21413. diffZ = p._pos1Z - p._pos2Z;
  21414. let dotN = this._manifold._normalX * diffX + this._manifold._normalY * diffY + this._manifold._normalZ * diffZ;
  21415. if(dotN > oimo.common.Setting.contactPersistenceThreshold) {
  21416. this.removeManifoldPoint(index);
  21417. continue;
  21418. }
  21419. diffX += this._manifold._normalX * -dotN;
  21420. diffY += this._manifold._normalY * -dotN;
  21421. diffZ += this._manifold._normalZ * -dotN;
  21422. if(diffX * diffX + diffY * diffY + diffZ * diffZ > oimo.common.Setting.contactPersistenceThreshold * oimo.common.Setting.contactPersistenceThreshold) {
  21423. this.removeManifoldPoint(index);
  21424. continue;
  21425. }
  21426. }
  21427. }
  21428. removeManifoldPoint(index) {
  21429. let lastIndex = --this._manifold._numPoints;
  21430. if(index != lastIndex) {
  21431. let tmp = this._manifold._points[index];
  21432. this._manifold._points[index] = this._manifold._points[lastIndex];
  21433. this._manifold._points[lastIndex] = tmp;
  21434. }
  21435. let _this = this._manifold._points[lastIndex];
  21436. _this._localPos1X = 0;
  21437. _this._localPos1Y = 0;
  21438. _this._localPos1Z = 0;
  21439. _this._localPos2X = 0;
  21440. _this._localPos2Y = 0;
  21441. _this._localPos2Z = 0;
  21442. _this._relPos1X = 0;
  21443. _this._relPos1Y = 0;
  21444. _this._relPos1Z = 0;
  21445. _this._relPos2X = 0;
  21446. _this._relPos2Y = 0;
  21447. _this._relPos2Z = 0;
  21448. _this._pos1X = 0;
  21449. _this._pos1Y = 0;
  21450. _this._pos1Z = 0;
  21451. _this._pos2X = 0;
  21452. _this._pos2Y = 0;
  21453. _this._pos2Z = 0;
  21454. _this._depth = 0;
  21455. let _this1 = _this._impulse;
  21456. _this1.impulseN = 0;
  21457. _this1.impulseT = 0;
  21458. _this1.impulseB = 0;
  21459. _this1.impulseP = 0;
  21460. _this1.impulseLX = 0;
  21461. _this1.impulseLY = 0;
  21462. _this1.impulseLZ = 0;
  21463. _this._warmStarted = false;
  21464. _this._disabled = false;
  21465. _this._id = -1;
  21466. }
  21467. addManifoldPoint(point,tf1,tf2) {
  21468. let num = this._manifold._numPoints;
  21469. if(num == oimo.common.Setting.maxManifoldPoints) {
  21470. let targetIndex = this.computeTargetIndex(point,tf1,tf2);
  21471. let _this = this._manifold._points[targetIndex];
  21472. let v = point.position1;
  21473. _this._pos1X = v.x;
  21474. _this._pos1Y = v.y;
  21475. _this._pos1Z = v.z;
  21476. let v1 = point.position2;
  21477. _this._pos2X = v1.x;
  21478. _this._pos2Y = v1.y;
  21479. _this._pos2Z = v1.z;
  21480. _this._relPos1X = _this._pos1X - tf1._positionX;
  21481. _this._relPos1Y = _this._pos1Y - tf1._positionY;
  21482. _this._relPos1Z = _this._pos1Z - tf1._positionZ;
  21483. _this._relPos2X = _this._pos2X - tf2._positionX;
  21484. _this._relPos2Y = _this._pos2Y - tf2._positionY;
  21485. _this._relPos2Z = _this._pos2Z - tf2._positionZ;
  21486. let __tmp__X;
  21487. let __tmp__Y;
  21488. let __tmp__Z;
  21489. __tmp__X = tf1._rotation00 * _this._relPos1X + tf1._rotation10 * _this._relPos1Y + tf1._rotation20 * _this._relPos1Z;
  21490. __tmp__Y = tf1._rotation01 * _this._relPos1X + tf1._rotation11 * _this._relPos1Y + tf1._rotation21 * _this._relPos1Z;
  21491. __tmp__Z = tf1._rotation02 * _this._relPos1X + tf1._rotation12 * _this._relPos1Y + tf1._rotation22 * _this._relPos1Z;
  21492. _this._localPos1X = __tmp__X;
  21493. _this._localPos1Y = __tmp__Y;
  21494. _this._localPos1Z = __tmp__Z;
  21495. let __tmp__X1;
  21496. let __tmp__Y1;
  21497. let __tmp__Z1;
  21498. __tmp__X1 = tf2._rotation00 * _this._relPos2X + tf2._rotation10 * _this._relPos2Y + tf2._rotation20 * _this._relPos2Z;
  21499. __tmp__Y1 = tf2._rotation01 * _this._relPos2X + tf2._rotation11 * _this._relPos2Y + tf2._rotation21 * _this._relPos2Z;
  21500. __tmp__Z1 = tf2._rotation02 * _this._relPos2X + tf2._rotation12 * _this._relPos2Y + tf2._rotation22 * _this._relPos2Z;
  21501. _this._localPos2X = __tmp__X1;
  21502. _this._localPos2Y = __tmp__Y1;
  21503. _this._localPos2Z = __tmp__Z1;
  21504. _this._depth = point.depth;
  21505. let _this1 = _this._impulse;
  21506. _this1.impulseN = 0;
  21507. _this1.impulseT = 0;
  21508. _this1.impulseB = 0;
  21509. _this1.impulseP = 0;
  21510. _this1.impulseLX = 0;
  21511. _this1.impulseLY = 0;
  21512. _this1.impulseLZ = 0;
  21513. _this._id = point.id;
  21514. _this._warmStarted = false;
  21515. _this._disabled = false;
  21516. return;
  21517. }
  21518. let _this = this._manifold._points[num];
  21519. let v = point.position1;
  21520. _this._pos1X = v.x;
  21521. _this._pos1Y = v.y;
  21522. _this._pos1Z = v.z;
  21523. let v1 = point.position2;
  21524. _this._pos2X = v1.x;
  21525. _this._pos2Y = v1.y;
  21526. _this._pos2Z = v1.z;
  21527. _this._relPos1X = _this._pos1X - tf1._positionX;
  21528. _this._relPos1Y = _this._pos1Y - tf1._positionY;
  21529. _this._relPos1Z = _this._pos1Z - tf1._positionZ;
  21530. _this._relPos2X = _this._pos2X - tf2._positionX;
  21531. _this._relPos2Y = _this._pos2Y - tf2._positionY;
  21532. _this._relPos2Z = _this._pos2Z - tf2._positionZ;
  21533. let __tmp__X;
  21534. let __tmp__Y;
  21535. let __tmp__Z;
  21536. __tmp__X = tf1._rotation00 * _this._relPos1X + tf1._rotation10 * _this._relPos1Y + tf1._rotation20 * _this._relPos1Z;
  21537. __tmp__Y = tf1._rotation01 * _this._relPos1X + tf1._rotation11 * _this._relPos1Y + tf1._rotation21 * _this._relPos1Z;
  21538. __tmp__Z = tf1._rotation02 * _this._relPos1X + tf1._rotation12 * _this._relPos1Y + tf1._rotation22 * _this._relPos1Z;
  21539. _this._localPos1X = __tmp__X;
  21540. _this._localPos1Y = __tmp__Y;
  21541. _this._localPos1Z = __tmp__Z;
  21542. let __tmp__X1;
  21543. let __tmp__Y1;
  21544. let __tmp__Z1;
  21545. __tmp__X1 = tf2._rotation00 * _this._relPos2X + tf2._rotation10 * _this._relPos2Y + tf2._rotation20 * _this._relPos2Z;
  21546. __tmp__Y1 = tf2._rotation01 * _this._relPos2X + tf2._rotation11 * _this._relPos2Y + tf2._rotation21 * _this._relPos2Z;
  21547. __tmp__Z1 = tf2._rotation02 * _this._relPos2X + tf2._rotation12 * _this._relPos2Y + tf2._rotation22 * _this._relPos2Z;
  21548. _this._localPos2X = __tmp__X1;
  21549. _this._localPos2Y = __tmp__Y1;
  21550. _this._localPos2Z = __tmp__Z1;
  21551. _this._depth = point.depth;
  21552. let _this1 = _this._impulse;
  21553. _this1.impulseN = 0;
  21554. _this1.impulseT = 0;
  21555. _this1.impulseB = 0;
  21556. _this1.impulseP = 0;
  21557. _this1.impulseLX = 0;
  21558. _this1.impulseLY = 0;
  21559. _this1.impulseLZ = 0;
  21560. _this._id = point.id;
  21561. _this._warmStarted = false;
  21562. _this._disabled = false;
  21563. this._manifold._numPoints++;
  21564. }
  21565. computeTargetIndex(newPoint,tf1,tf2) {
  21566. let p1 = this._manifold._points[0];
  21567. let p2 = this._manifold._points[1];
  21568. let p3 = this._manifold._points[2];
  21569. let p4 = this._manifold._points[3];
  21570. let maxDepth = p1._depth;
  21571. let maxDepthIndex = 0;
  21572. if(p2._depth > maxDepth) {
  21573. maxDepth = p2._depth;
  21574. maxDepthIndex = 1;
  21575. }
  21576. if(p3._depth > maxDepth) {
  21577. maxDepth = p3._depth;
  21578. maxDepthIndex = 2;
  21579. }
  21580. if(p4._depth > maxDepth) {
  21581. maxDepthIndex = 3;
  21582. }
  21583. let rp1X;
  21584. let rp1Y;
  21585. let rp1Z;
  21586. let v = newPoint.position1;
  21587. rp1X = v.x;
  21588. rp1Y = v.y;
  21589. rp1Z = v.z;
  21590. rp1X -= tf1._positionX;
  21591. rp1Y -= tf1._positionY;
  21592. rp1Z -= tf1._positionZ;
  21593. let p1X = p2._relPos1X;
  21594. let p1Y = p2._relPos1Y;
  21595. let p1Z = p2._relPos1Z;
  21596. let p2X = p3._relPos1X;
  21597. let p2Y = p3._relPos1Y;
  21598. let p2Z = p3._relPos1Z;
  21599. let p3X = p4._relPos1X;
  21600. let p3Y = p4._relPos1Y;
  21601. let p3Z = p4._relPos1Z;
  21602. let v12X;
  21603. let v12Y;
  21604. let v12Z;
  21605. let v34X;
  21606. let v34Y;
  21607. let v34Z;
  21608. let v13X;
  21609. let v13Y;
  21610. let v13Z;
  21611. let v24X;
  21612. let v24Y;
  21613. let v24Z;
  21614. let v14X;
  21615. let v14Y;
  21616. let v14Z;
  21617. let v23X;
  21618. let v23Y;
  21619. let v23Z;
  21620. v12X = p2X - p1X;
  21621. v12Y = p2Y - p1Y;
  21622. v12Z = p2Z - p1Z;
  21623. v34X = rp1X - p3X;
  21624. v34Y = rp1Y - p3Y;
  21625. v34Z = rp1Z - p3Z;
  21626. v13X = p3X - p1X;
  21627. v13Y = p3Y - p1Y;
  21628. v13Z = p3Z - p1Z;
  21629. v24X = rp1X - p2X;
  21630. v24Y = rp1Y - p2Y;
  21631. v24Z = rp1Z - p2Z;
  21632. v14X = rp1X - p1X;
  21633. v14Y = rp1Y - p1Y;
  21634. v14Z = rp1Z - p1Z;
  21635. v23X = p3X - p2X;
  21636. v23Y = p3Y - p2Y;
  21637. v23Z = p3Z - p2Z;
  21638. let cross1X;
  21639. let cross1Y;
  21640. let cross1Z;
  21641. let cross2X;
  21642. let cross2Y;
  21643. let cross2Z;
  21644. let cross3X;
  21645. let cross3Y;
  21646. let cross3Z;
  21647. cross1X = v12Y * v34Z - v12Z * v34Y;
  21648. cross1Y = v12Z * v34X - v12X * v34Z;
  21649. cross1Z = v12X * v34Y - v12Y * v34X;
  21650. cross2X = v13Y * v24Z - v13Z * v24Y;
  21651. cross2Y = v13Z * v24X - v13X * v24Z;
  21652. cross2Z = v13X * v24Y - v13Y * v24X;
  21653. cross3X = v14Y * v23Z - v14Z * v23Y;
  21654. cross3Y = v14Z * v23X - v14X * v23Z;
  21655. cross3Z = v14X * v23Y - v14Y * v23X;
  21656. let a1 = cross1X * cross1X + cross1Y * cross1Y + cross1Z * cross1Z;
  21657. let a2 = cross2X * cross2X + cross2Y * cross2Y + cross2Z * cross2Z;
  21658. let a3 = cross3X * cross3X + cross3Y * cross3Y + cross3Z * cross3Z;
  21659. let p1X1 = p1._relPos1X;
  21660. let p1Y1 = p1._relPos1Y;
  21661. let p1Z1 = p1._relPos1Z;
  21662. let p2X1 = p3._relPos1X;
  21663. let p2Y1 = p3._relPos1Y;
  21664. let p2Z1 = p3._relPos1Z;
  21665. let p3X1 = p4._relPos1X;
  21666. let p3Y1 = p4._relPos1Y;
  21667. let p3Z1 = p4._relPos1Z;
  21668. let v12X1;
  21669. let v12Y1;
  21670. let v12Z1;
  21671. let v34X1;
  21672. let v34Y1;
  21673. let v34Z1;
  21674. let v13X1;
  21675. let v13Y1;
  21676. let v13Z1;
  21677. let v24X1;
  21678. let v24Y1;
  21679. let v24Z1;
  21680. let v14X1;
  21681. let v14Y1;
  21682. let v14Z1;
  21683. let v23X1;
  21684. let v23Y1;
  21685. let v23Z1;
  21686. v12X1 = p2X1 - p1X1;
  21687. v12Y1 = p2Y1 - p1Y1;
  21688. v12Z1 = p2Z1 - p1Z1;
  21689. v34X1 = rp1X - p3X1;
  21690. v34Y1 = rp1Y - p3Y1;
  21691. v34Z1 = rp1Z - p3Z1;
  21692. v13X1 = p3X1 - p1X1;
  21693. v13Y1 = p3Y1 - p1Y1;
  21694. v13Z1 = p3Z1 - p1Z1;
  21695. v24X1 = rp1X - p2X1;
  21696. v24Y1 = rp1Y - p2Y1;
  21697. v24Z1 = rp1Z - p2Z1;
  21698. v14X1 = rp1X - p1X1;
  21699. v14Y1 = rp1Y - p1Y1;
  21700. v14Z1 = rp1Z - p1Z1;
  21701. v23X1 = p3X1 - p2X1;
  21702. v23Y1 = p3Y1 - p2Y1;
  21703. v23Z1 = p3Z1 - p2Z1;
  21704. let cross1X1;
  21705. let cross1Y1;
  21706. let cross1Z1;
  21707. let cross2X1;
  21708. let cross2Y1;
  21709. let cross2Z1;
  21710. let cross3X1;
  21711. let cross3Y1;
  21712. let cross3Z1;
  21713. cross1X1 = v12Y1 * v34Z1 - v12Z1 * v34Y1;
  21714. cross1Y1 = v12Z1 * v34X1 - v12X1 * v34Z1;
  21715. cross1Z1 = v12X1 * v34Y1 - v12Y1 * v34X1;
  21716. cross2X1 = v13Y1 * v24Z1 - v13Z1 * v24Y1;
  21717. cross2Y1 = v13Z1 * v24X1 - v13X1 * v24Z1;
  21718. cross2Z1 = v13X1 * v24Y1 - v13Y1 * v24X1;
  21719. cross3X1 = v14Y1 * v23Z1 - v14Z1 * v23Y1;
  21720. cross3Y1 = v14Z1 * v23X1 - v14X1 * v23Z1;
  21721. cross3Z1 = v14X1 * v23Y1 - v14Y1 * v23X1;
  21722. let a11 = cross1X1 * cross1X1 + cross1Y1 * cross1Y1 + cross1Z1 * cross1Z1;
  21723. let a21 = cross2X1 * cross2X1 + cross2Y1 * cross2Y1 + cross2Z1 * cross2Z1;
  21724. let a31 = cross3X1 * cross3X1 + cross3Y1 * cross3Y1 + cross3Z1 * cross3Z1;
  21725. let a22 = a11 > a21 ? a11 > a31 ? a11 : a31 : a21 > a31 ? a21 : a31;
  21726. let p1X2 = p1._relPos1X;
  21727. let p1Y2 = p1._relPos1Y;
  21728. let p1Z2 = p1._relPos1Z;
  21729. let p2X2 = p2._relPos1X;
  21730. let p2Y2 = p2._relPos1Y;
  21731. let p2Z2 = p2._relPos1Z;
  21732. let p3X2 = p4._relPos1X;
  21733. let p3Y2 = p4._relPos1Y;
  21734. let p3Z2 = p4._relPos1Z;
  21735. let v12X2;
  21736. let v12Y2;
  21737. let v12Z2;
  21738. let v34X2;
  21739. let v34Y2;
  21740. let v34Z2;
  21741. let v13X2;
  21742. let v13Y2;
  21743. let v13Z2;
  21744. let v24X2;
  21745. let v24Y2;
  21746. let v24Z2;
  21747. let v14X2;
  21748. let v14Y2;
  21749. let v14Z2;
  21750. let v23X2;
  21751. let v23Y2;
  21752. let v23Z2;
  21753. v12X2 = p2X2 - p1X2;
  21754. v12Y2 = p2Y2 - p1Y2;
  21755. v12Z2 = p2Z2 - p1Z2;
  21756. v34X2 = rp1X - p3X2;
  21757. v34Y2 = rp1Y - p3Y2;
  21758. v34Z2 = rp1Z - p3Z2;
  21759. v13X2 = p3X2 - p1X2;
  21760. v13Y2 = p3Y2 - p1Y2;
  21761. v13Z2 = p3Z2 - p1Z2;
  21762. v24X2 = rp1X - p2X2;
  21763. v24Y2 = rp1Y - p2Y2;
  21764. v24Z2 = rp1Z - p2Z2;
  21765. v14X2 = rp1X - p1X2;
  21766. v14Y2 = rp1Y - p1Y2;
  21767. v14Z2 = rp1Z - p1Z2;
  21768. v23X2 = p3X2 - p2X2;
  21769. v23Y2 = p3Y2 - p2Y2;
  21770. v23Z2 = p3Z2 - p2Z2;
  21771. let cross1X2;
  21772. let cross1Y2;
  21773. let cross1Z2;
  21774. let cross2X2;
  21775. let cross2Y2;
  21776. let cross2Z2;
  21777. let cross3X2;
  21778. let cross3Y2;
  21779. let cross3Z2;
  21780. cross1X2 = v12Y2 * v34Z2 - v12Z2 * v34Y2;
  21781. cross1Y2 = v12Z2 * v34X2 - v12X2 * v34Z2;
  21782. cross1Z2 = v12X2 * v34Y2 - v12Y2 * v34X2;
  21783. cross2X2 = v13Y2 * v24Z2 - v13Z2 * v24Y2;
  21784. cross2Y2 = v13Z2 * v24X2 - v13X2 * v24Z2;
  21785. cross2Z2 = v13X2 * v24Y2 - v13Y2 * v24X2;
  21786. cross3X2 = v14Y2 * v23Z2 - v14Z2 * v23Y2;
  21787. cross3Y2 = v14Z2 * v23X2 - v14X2 * v23Z2;
  21788. cross3Z2 = v14X2 * v23Y2 - v14Y2 * v23X2;
  21789. let a12 = cross1X2 * cross1X2 + cross1Y2 * cross1Y2 + cross1Z2 * cross1Z2;
  21790. let a23 = cross2X2 * cross2X2 + cross2Y2 * cross2Y2 + cross2Z2 * cross2Z2;
  21791. let a32 = cross3X2 * cross3X2 + cross3Y2 * cross3Y2 + cross3Z2 * cross3Z2;
  21792. let a33 = a12 > a23 ? a12 > a32 ? a12 : a32 : a23 > a32 ? a23 : a32;
  21793. let p1X3 = p1._relPos1X;
  21794. let p1Y3 = p1._relPos1Y;
  21795. let p1Z3 = p1._relPos1Z;
  21796. let p2X3 = p2._relPos1X;
  21797. let p2Y3 = p2._relPos1Y;
  21798. let p2Z3 = p2._relPos1Z;
  21799. let p3X3 = p3._relPos1X;
  21800. let p3Y3 = p3._relPos1Y;
  21801. let p3Z3 = p3._relPos1Z;
  21802. let v12X3;
  21803. let v12Y3;
  21804. let v12Z3;
  21805. let v34X3;
  21806. let v34Y3;
  21807. let v34Z3;
  21808. let v13X3;
  21809. let v13Y3;
  21810. let v13Z3;
  21811. let v24X3;
  21812. let v24Y3;
  21813. let v24Z3;
  21814. let v14X3;
  21815. let v14Y3;
  21816. let v14Z3;
  21817. let v23X3;
  21818. let v23Y3;
  21819. let v23Z3;
  21820. v12X3 = p2X3 - p1X3;
  21821. v12Y3 = p2Y3 - p1Y3;
  21822. v12Z3 = p2Z3 - p1Z3;
  21823. v34X3 = rp1X - p3X3;
  21824. v34Y3 = rp1Y - p3Y3;
  21825. v34Z3 = rp1Z - p3Z3;
  21826. v13X3 = p3X3 - p1X3;
  21827. v13Y3 = p3Y3 - p1Y3;
  21828. v13Z3 = p3Z3 - p1Z3;
  21829. v24X3 = rp1X - p2X3;
  21830. v24Y3 = rp1Y - p2Y3;
  21831. v24Z3 = rp1Z - p2Z3;
  21832. v14X3 = rp1X - p1X3;
  21833. v14Y3 = rp1Y - p1Y3;
  21834. v14Z3 = rp1Z - p1Z3;
  21835. v23X3 = p3X3 - p2X3;
  21836. v23Y3 = p3Y3 - p2Y3;
  21837. v23Z3 = p3Z3 - p2Z3;
  21838. let cross1X3;
  21839. let cross1Y3;
  21840. let cross1Z3;
  21841. let cross2X3;
  21842. let cross2Y3;
  21843. let cross2Z3;
  21844. let cross3X3;
  21845. let cross3Y3;
  21846. let cross3Z3;
  21847. cross1X3 = v12Y3 * v34Z3 - v12Z3 * v34Y3;
  21848. cross1Y3 = v12Z3 * v34X3 - v12X3 * v34Z3;
  21849. cross1Z3 = v12X3 * v34Y3 - v12Y3 * v34X3;
  21850. cross2X3 = v13Y3 * v24Z3 - v13Z3 * v24Y3;
  21851. cross2Y3 = v13Z3 * v24X3 - v13X3 * v24Z3;
  21852. cross2Z3 = v13X3 * v24Y3 - v13Y3 * v24X3;
  21853. cross3X3 = v14Y3 * v23Z3 - v14Z3 * v23Y3;
  21854. cross3Y3 = v14Z3 * v23X3 - v14X3 * v23Z3;
  21855. cross3Z3 = v14X3 * v23Y3 - v14Y3 * v23X3;
  21856. let a13 = cross1X3 * cross1X3 + cross1Y3 * cross1Y3 + cross1Z3 * cross1Z3;
  21857. let a24 = cross2X3 * cross2X3 + cross2Y3 * cross2Y3 + cross2Z3 * cross2Z3;
  21858. let a34 = cross3X3 * cross3X3 + cross3Y3 * cross3Y3 + cross3Z3 * cross3Z3;
  21859. let a4 = a13 > a24 ? a13 > a34 ? a13 : a34 : a24 > a34 ? a24 : a34;
  21860. let max = a1 > a2 ? a1 > a3 ? a1 : a3 : a2 > a3 ? a2 : a3;
  21861. let target = 0;
  21862. if(a22 > max && maxDepthIndex != 1 || maxDepthIndex == 0) {
  21863. max = a22;
  21864. target = 1;
  21865. }
  21866. if(a33 > max && maxDepthIndex != 2) {
  21867. max = a33;
  21868. target = 2;
  21869. }
  21870. if(a4 > max && maxDepthIndex != 3) {
  21871. target = 3;
  21872. }
  21873. return target;
  21874. }
  21875. computeRelativePositions(tf1,tf2) {
  21876. let num = this._manifold._numPoints;
  21877. let _g = 0;
  21878. while(_g < num) {
  21879. let p = this._manifold._points[_g++];
  21880. let __tmp__X;
  21881. let __tmp__Y;
  21882. let __tmp__Z;
  21883. __tmp__X = tf1._rotation00 * p._localPos1X + tf1._rotation01 * p._localPos1Y + tf1._rotation02 * p._localPos1Z;
  21884. __tmp__Y = tf1._rotation10 * p._localPos1X + tf1._rotation11 * p._localPos1Y + tf1._rotation12 * p._localPos1Z;
  21885. __tmp__Z = tf1._rotation20 * p._localPos1X + tf1._rotation21 * p._localPos1Y + tf1._rotation22 * p._localPos1Z;
  21886. p._relPos1X = __tmp__X;
  21887. p._relPos1Y = __tmp__Y;
  21888. p._relPos1Z = __tmp__Z;
  21889. let __tmp__X1;
  21890. let __tmp__Y1;
  21891. let __tmp__Z1;
  21892. __tmp__X1 = tf2._rotation00 * p._localPos2X + tf2._rotation01 * p._localPos2Y + tf2._rotation02 * p._localPos2Z;
  21893. __tmp__Y1 = tf2._rotation10 * p._localPos2X + tf2._rotation11 * p._localPos2Y + tf2._rotation12 * p._localPos2Z;
  21894. __tmp__Z1 = tf2._rotation20 * p._localPos2X + tf2._rotation21 * p._localPos2Y + tf2._rotation22 * p._localPos2Z;
  21895. p._relPos2X = __tmp__X1;
  21896. p._relPos2Y = __tmp__Y1;
  21897. p._relPos2Z = __tmp__Z1;
  21898. p._warmStarted = true;
  21899. }
  21900. }
  21901. findNearestContactPointIndex(target,tf1,tf2) {
  21902. let nearestSq = oimo.common.Setting.contactPersistenceThreshold * oimo.common.Setting.contactPersistenceThreshold;
  21903. let idx = -1;
  21904. let _g = 0;
  21905. let _g1 = this._manifold._numPoints;
  21906. while(_g < _g1) {
  21907. let i = _g++;
  21908. let mp = this._manifold._points[i];
  21909. let rp1X;
  21910. let rp1Y;
  21911. let rp1Z;
  21912. let rp2X;
  21913. let rp2Y;
  21914. let rp2Z;
  21915. let v = target.position1;
  21916. rp1X = v.x;
  21917. rp1Y = v.y;
  21918. rp1Z = v.z;
  21919. let v1 = target.position2;
  21920. rp2X = v1.x;
  21921. rp2Y = v1.y;
  21922. rp2Z = v1.z;
  21923. rp1X -= tf1._positionX;
  21924. rp1Y -= tf1._positionY;
  21925. rp1Z -= tf1._positionZ;
  21926. rp2X -= tf2._positionX;
  21927. rp2Y -= tf2._positionY;
  21928. rp2Z -= tf2._positionZ;
  21929. let diff1X;
  21930. let diff1Y;
  21931. let diff1Z;
  21932. let diff2X;
  21933. let diff2Y;
  21934. let diff2Z;
  21935. diff1X = mp._relPos1X - rp1X;
  21936. diff1Y = mp._relPos1Y - rp1Y;
  21937. diff1Z = mp._relPos1Z - rp1Z;
  21938. diff2X = mp._relPos2X - rp2X;
  21939. diff2Y = mp._relPos2Y - rp2Y;
  21940. diff2Z = mp._relPos2Z - rp2Z;
  21941. let sq1 = diff1X * diff1X + diff1Y * diff1Y + diff1Z * diff1Z;
  21942. let sq2 = diff2X * diff2X + diff2Y * diff2Y + diff2Z * diff2Z;
  21943. let d = sq1 < sq2 ? sq1 : sq2;
  21944. if(d < nearestSq) {
  21945. nearestSq = d;
  21946. idx = i;
  21947. }
  21948. }
  21949. return idx;
  21950. }
  21951. totalUpdate(result,tf1,tf2) {
  21952. this.numOldPoints = this._manifold._numPoints;
  21953. let _g = 0;
  21954. let _g1 = this.numOldPoints;
  21955. while(_g < _g1) {
  21956. let i = _g++;
  21957. let _this = this.oldPoints[i];
  21958. let cp = this._manifold._points[i];
  21959. _this._localPos1X = cp._localPos1X;
  21960. _this._localPos1Y = cp._localPos1Y;
  21961. _this._localPos1Z = cp._localPos1Z;
  21962. _this._localPos2X = cp._localPos2X;
  21963. _this._localPos2Y = cp._localPos2Y;
  21964. _this._localPos2Z = cp._localPos2Z;
  21965. _this._relPos1X = cp._relPos1X;
  21966. _this._relPos1Y = cp._relPos1Y;
  21967. _this._relPos1Z = cp._relPos1Z;
  21968. _this._relPos2X = cp._relPos2X;
  21969. _this._relPos2Y = cp._relPos2Y;
  21970. _this._relPos2Z = cp._relPos2Z;
  21971. _this._pos1X = cp._pos1X;
  21972. _this._pos1Y = cp._pos1Y;
  21973. _this._pos1Z = cp._pos1Z;
  21974. _this._pos2X = cp._pos2X;
  21975. _this._pos2Y = cp._pos2Y;
  21976. _this._pos2Z = cp._pos2Z;
  21977. _this._depth = cp._depth;
  21978. _this._impulse.copyFrom(cp._impulse);
  21979. _this._id = cp._id;
  21980. _this._warmStarted = cp._warmStarted;
  21981. _this._disabled = false;
  21982. }
  21983. let num = result.numPoints;
  21984. this._manifold._numPoints = num;
  21985. let _g2 = 0;
  21986. while(_g2 < num) {
  21987. let i = _g2++;
  21988. let p = this._manifold._points[i];
  21989. let ref = result.points[i];
  21990. let v = ref.position1;
  21991. p._pos1X = v.x;
  21992. p._pos1Y = v.y;
  21993. p._pos1Z = v.z;
  21994. let v1 = ref.position2;
  21995. p._pos2X = v1.x;
  21996. p._pos2Y = v1.y;
  21997. p._pos2Z = v1.z;
  21998. p._relPos1X = p._pos1X - tf1._positionX;
  21999. p._relPos1Y = p._pos1Y - tf1._positionY;
  22000. p._relPos1Z = p._pos1Z - tf1._positionZ;
  22001. p._relPos2X = p._pos2X - tf2._positionX;
  22002. p._relPos2Y = p._pos2Y - tf2._positionY;
  22003. p._relPos2Z = p._pos2Z - tf2._positionZ;
  22004. let __tmp__X;
  22005. let __tmp__Y;
  22006. let __tmp__Z;
  22007. __tmp__X = tf1._rotation00 * p._relPos1X + tf1._rotation10 * p._relPos1Y + tf1._rotation20 * p._relPos1Z;
  22008. __tmp__Y = tf1._rotation01 * p._relPos1X + tf1._rotation11 * p._relPos1Y + tf1._rotation21 * p._relPos1Z;
  22009. __tmp__Z = tf1._rotation02 * p._relPos1X + tf1._rotation12 * p._relPos1Y + tf1._rotation22 * p._relPos1Z;
  22010. p._localPos1X = __tmp__X;
  22011. p._localPos1Y = __tmp__Y;
  22012. p._localPos1Z = __tmp__Z;
  22013. let __tmp__X1;
  22014. let __tmp__Y1;
  22015. let __tmp__Z1;
  22016. __tmp__X1 = tf2._rotation00 * p._relPos2X + tf2._rotation10 * p._relPos2Y + tf2._rotation20 * p._relPos2Z;
  22017. __tmp__Y1 = tf2._rotation01 * p._relPos2X + tf2._rotation11 * p._relPos2Y + tf2._rotation21 * p._relPos2Z;
  22018. __tmp__Z1 = tf2._rotation02 * p._relPos2X + tf2._rotation12 * p._relPos2Y + tf2._rotation22 * p._relPos2Z;
  22019. p._localPos2X = __tmp__X1;
  22020. p._localPos2Y = __tmp__Y1;
  22021. p._localPos2Z = __tmp__Z1;
  22022. p._depth = ref.depth;
  22023. let _this = p._impulse;
  22024. _this.impulseN = 0;
  22025. _this.impulseT = 0;
  22026. _this.impulseB = 0;
  22027. _this.impulseP = 0;
  22028. _this.impulseLX = 0;
  22029. _this.impulseLY = 0;
  22030. _this.impulseLZ = 0;
  22031. p._id = ref.id;
  22032. p._warmStarted = false;
  22033. p._disabled = false;
  22034. let _g = 0;
  22035. let _g1 = this.numOldPoints;
  22036. while(_g < _g1) {
  22037. let ocp = this.oldPoints[_g++];
  22038. if(p._id == ocp._id) {
  22039. p._impulse.copyFrom(ocp._impulse);
  22040. p._warmStarted = true;
  22041. break;
  22042. }
  22043. }
  22044. }
  22045. }
  22046. incrementalUpdate(result,tf1,tf2) {
  22047. this._manifold._updateDepthsAndPositions(tf1,tf2);
  22048. let _g = 0;
  22049. let _g1 = this._manifold._numPoints;
  22050. while(_g < _g1) this._manifold._points[_g++]._warmStarted = true;
  22051. let newPoint = result.points[0];
  22052. let index = this.findNearestContactPointIndex(newPoint,tf1,tf2);
  22053. if(index == -1) {
  22054. this.addManifoldPoint(newPoint,tf1,tf2);
  22055. } else {
  22056. let cp = this._manifold._points[index];
  22057. let v = newPoint.position1;
  22058. cp._pos1X = v.x;
  22059. cp._pos1Y = v.y;
  22060. cp._pos1Z = v.z;
  22061. let v1 = newPoint.position2;
  22062. cp._pos2X = v1.x;
  22063. cp._pos2Y = v1.y;
  22064. cp._pos2Z = v1.z;
  22065. cp._relPos1X = cp._pos1X - tf1._positionX;
  22066. cp._relPos1Y = cp._pos1Y - tf1._positionY;
  22067. cp._relPos1Z = cp._pos1Z - tf1._positionZ;
  22068. cp._relPos2X = cp._pos2X - tf2._positionX;
  22069. cp._relPos2Y = cp._pos2Y - tf2._positionY;
  22070. cp._relPos2Z = cp._pos2Z - tf2._positionZ;
  22071. let __tmp__X;
  22072. let __tmp__Y;
  22073. let __tmp__Z;
  22074. __tmp__X = tf1._rotation00 * cp._relPos1X + tf1._rotation10 * cp._relPos1Y + tf1._rotation20 * cp._relPos1Z;
  22075. __tmp__Y = tf1._rotation01 * cp._relPos1X + tf1._rotation11 * cp._relPos1Y + tf1._rotation21 * cp._relPos1Z;
  22076. __tmp__Z = tf1._rotation02 * cp._relPos1X + tf1._rotation12 * cp._relPos1Y + tf1._rotation22 * cp._relPos1Z;
  22077. cp._localPos1X = __tmp__X;
  22078. cp._localPos1Y = __tmp__Y;
  22079. cp._localPos1Z = __tmp__Z;
  22080. let __tmp__X1;
  22081. let __tmp__Y1;
  22082. let __tmp__Z1;
  22083. __tmp__X1 = tf2._rotation00 * cp._relPos2X + tf2._rotation10 * cp._relPos2Y + tf2._rotation20 * cp._relPos2Z;
  22084. __tmp__Y1 = tf2._rotation01 * cp._relPos2X + tf2._rotation11 * cp._relPos2Y + tf2._rotation21 * cp._relPos2Z;
  22085. __tmp__Z1 = tf2._rotation02 * cp._relPos2X + tf2._rotation12 * cp._relPos2Y + tf2._rotation22 * cp._relPos2Z;
  22086. cp._localPos2X = __tmp__X1;
  22087. cp._localPos2Y = __tmp__Y1;
  22088. cp._localPos2Z = __tmp__Z1;
  22089. cp._depth = newPoint.depth;
  22090. }
  22091. this.removeOutdatedPoints();
  22092. }
  22093. }
  22094. if(!oimo.dynamics.constraint.info) oimo.dynamics.constraint.info = {};
  22095. oimo.dynamics.constraint.info.JacobianRow = class oimo_dynamics_constraint_info_JacobianRow {
  22096. constructor() {
  22097. this.lin1X = 0;
  22098. this.lin1Y = 0;
  22099. this.lin1Z = 0;
  22100. this.lin2X = 0;
  22101. this.lin2Y = 0;
  22102. this.lin2Z = 0;
  22103. this.ang1X = 0;
  22104. this.ang1Y = 0;
  22105. this.ang1Z = 0;
  22106. this.ang2X = 0;
  22107. this.ang2Y = 0;
  22108. this.ang2Z = 0;
  22109. this.flag = 0;
  22110. }
  22111. updateSparsity() {
  22112. this.flag = 0;
  22113. if(!(this.lin1X == 0 && this.lin1Y == 0 && this.lin1Z == 0) || !(this.lin2X == 0 && this.lin2Y == 0 && this.lin2Z == 0)) {
  22114. this.flag |= 1;
  22115. }
  22116. if(!(this.ang1X == 0 && this.ang1Y == 0 && this.ang1Z == 0) || !(this.ang2X == 0 && this.ang2Y == 0 && this.ang2Z == 0)) {
  22117. this.flag |= 2;
  22118. }
  22119. }
  22120. }
  22121. if(!oimo.dynamics.constraint.info.contact) oimo.dynamics.constraint.info.contact = {};
  22122. oimo.dynamics.constraint.info.contact.ContactSolverInfo = class oimo_dynamics_constraint_info_contact_ContactSolverInfo {
  22123. constructor() {
  22124. this.b1 = null;
  22125. this.b2 = null;
  22126. this.numRows = 0;
  22127. this.rows = new Array(oimo.common.Setting.maxManifoldPoints);
  22128. let _g = 0;
  22129. let _g1 = this.rows.length;
  22130. while(_g < _g1) this.rows[_g++] = new oimo.dynamics.constraint.info.contact.ContactSolverInfoRow();
  22131. }
  22132. }
  22133. oimo.dynamics.constraint.info.contact.ContactSolverInfoRow = class oimo_dynamics_constraint_info_contact_ContactSolverInfoRow {
  22134. constructor() {
  22135. this.jacobianN = new oimo.dynamics.constraint.info.JacobianRow();
  22136. this.jacobianT = new oimo.dynamics.constraint.info.JacobianRow();
  22137. this.jacobianB = new oimo.dynamics.constraint.info.JacobianRow();
  22138. this.rhs = 0;
  22139. this.cfm = 0;
  22140. this.friction = 0;
  22141. this.impulse = null;
  22142. }
  22143. }
  22144. if(!oimo.dynamics.constraint.info.joint) oimo.dynamics.constraint.info.joint = {};
  22145. oimo.dynamics.constraint.info.joint.JointSolverInfo = class oimo_dynamics_constraint_info_joint_JointSolverInfo {
  22146. constructor() {
  22147. this.b1 = null;
  22148. this.b2 = null;
  22149. this.numRows = 0;
  22150. this.rows = new Array(oimo.common.Setting.maxJacobianRows);
  22151. let _g = 0;
  22152. let _g1 = this.rows.length;
  22153. while(_g < _g1) this.rows[_g++] = new oimo.dynamics.constraint.info.joint.JointSolverInfoRow();
  22154. }
  22155. }
  22156. oimo.dynamics.constraint.info.joint.JointSolverInfoRow = class oimo_dynamics_constraint_info_joint_JointSolverInfoRow {
  22157. constructor() {
  22158. this.jacobian = new oimo.dynamics.constraint.info.JacobianRow();
  22159. this.rhs = 0;
  22160. this.cfm = 0;
  22161. this.minImpulse = 0;
  22162. this.maxImpulse = 0;
  22163. this.motorSpeed = 0;
  22164. this.motorMaxImpulse = 0;
  22165. this.impulse = null;
  22166. }
  22167. }
  22168. if(!oimo.dynamics.constraint.joint) oimo.dynamics.constraint.joint = {};
  22169. oimo.dynamics.constraint.joint.BasisTracker = class oimo_dynamics_constraint_joint_BasisTracker {
  22170. constructor(joint) {
  22171. this.joint = joint;
  22172. this.xX = 0;
  22173. this.xY = 0;
  22174. this.xZ = 0;
  22175. this.yX = 0;
  22176. this.yY = 0;
  22177. this.yZ = 0;
  22178. this.zX = 0;
  22179. this.zY = 0;
  22180. this.zZ = 0;
  22181. }
  22182. }
  22183. oimo.dynamics.constraint.joint.Joint = class oimo_dynamics_constraint_joint_Joint {
  22184. constructor(config,type) {
  22185. this._link1 = new oimo.dynamics.constraint.joint.JointLink(this);
  22186. this._link2 = new oimo.dynamics.constraint.joint.JointLink(this);
  22187. this._positionCorrectionAlgorithm = oimo.common.Setting.defaultJointPositionCorrectionAlgorithm;
  22188. this._type = type;
  22189. this._world = null;
  22190. this._b1 = config.rigidBody1;
  22191. this._b2 = config.rigidBody2;
  22192. this._allowCollision = config.allowCollision;
  22193. this._breakForce = config.breakForce;
  22194. this._breakTorque = config.breakTorque;
  22195. switch(config.solverType) {
  22196. case 0:
  22197. this._solver = new oimo.dynamics.constraint.solver.pgs.PgsJointConstraintSolver(this);
  22198. break;
  22199. case 1:
  22200. this._solver = new oimo.dynamics.constraint.solver.direct.DirectJointConstraintSolver(this);
  22201. break;
  22202. }
  22203. let v = config.localAnchor1;
  22204. this._localAnchor1X = v.x;
  22205. this._localAnchor1Y = v.y;
  22206. this._localAnchor1Z = v.z;
  22207. let v1 = config.localAnchor2;
  22208. this._localAnchor2X = v1.x;
  22209. this._localAnchor2Y = v1.y;
  22210. this._localAnchor2Z = v1.z;
  22211. this._relativeAnchor1X = 0;
  22212. this._relativeAnchor1Y = 0;
  22213. this._relativeAnchor1Z = 0;
  22214. this._relativeAnchor2X = 0;
  22215. this._relativeAnchor2Y = 0;
  22216. this._relativeAnchor2Z = 0;
  22217. this._anchor1X = 0;
  22218. this._anchor1Y = 0;
  22219. this._anchor1Z = 0;
  22220. this._anchor2X = 0;
  22221. this._anchor2Y = 0;
  22222. this._anchor2Z = 0;
  22223. this._localBasisX1X = 0;
  22224. this._localBasisX1Y = 0;
  22225. this._localBasisX1Z = 0;
  22226. this._localBasisY1X = 0;
  22227. this._localBasisY1Y = 0;
  22228. this._localBasisY1Z = 0;
  22229. this._localBasisZ1X = 0;
  22230. this._localBasisZ1Y = 0;
  22231. this._localBasisZ1Z = 0;
  22232. this._localBasisX2X = 0;
  22233. this._localBasisX2Y = 0;
  22234. this._localBasisX2Z = 0;
  22235. this._localBasisY2X = 0;
  22236. this._localBasisY2Y = 0;
  22237. this._localBasisY2Z = 0;
  22238. this._localBasisZ2X = 0;
  22239. this._localBasisZ2Y = 0;
  22240. this._localBasisZ2Z = 0;
  22241. this._impulses = new Array(oimo.common.Setting.maxJacobianRows);
  22242. let _g = 0;
  22243. let _g1 = oimo.common.Setting.maxJacobianRows;
  22244. while(_g < _g1) this._impulses[_g++] = new oimo.dynamics.constraint.joint.JointImpulse();
  22245. }
  22246. buildLocalBasesFromX() {
  22247. if(this._localBasisX1X * this._localBasisX1X + this._localBasisX1Y * this._localBasisX1Y + this._localBasisX1Z * this._localBasisX1Z == 0) {
  22248. this._localBasisX1X = 1;
  22249. this._localBasisX1Y = 0;
  22250. this._localBasisX1Z = 0;
  22251. } else {
  22252. let l = this._localBasisX1X * this._localBasisX1X + this._localBasisX1Y * this._localBasisX1Y + this._localBasisX1Z * this._localBasisX1Z;
  22253. if(l > 0) {
  22254. l = 1 / Math.sqrt(l);
  22255. }
  22256. this._localBasisX1X *= l;
  22257. this._localBasisX1Y *= l;
  22258. this._localBasisX1Z *= l;
  22259. }
  22260. if(this._localBasisX2X * this._localBasisX2X + this._localBasisX2Y * this._localBasisX2Y + this._localBasisX2Z * this._localBasisX2Z == 0) {
  22261. this._localBasisX2X = 1;
  22262. this._localBasisX2Y = 0;
  22263. this._localBasisX2Z = 0;
  22264. } else {
  22265. let l = this._localBasisX2X * this._localBasisX2X + this._localBasisX2Y * this._localBasisX2Y + this._localBasisX2Z * this._localBasisX2Z;
  22266. if(l > 0) {
  22267. l = 1 / Math.sqrt(l);
  22268. }
  22269. this._localBasisX2X *= l;
  22270. this._localBasisX2Y *= l;
  22271. this._localBasisX2Z *= l;
  22272. }
  22273. let slerpQX;
  22274. let slerpQY;
  22275. let slerpQZ;
  22276. let slerpQW;
  22277. let slerpM00;
  22278. let slerpM01;
  22279. let slerpM02;
  22280. let slerpM10;
  22281. let slerpM11;
  22282. let slerpM12;
  22283. let slerpM20;
  22284. let slerpM21;
  22285. let slerpM22;
  22286. let d = this._localBasisX1X * this._localBasisX2X + this._localBasisX1Y * this._localBasisX2Y + this._localBasisX1Z * this._localBasisX2Z;
  22287. if(d < -0.999999999) {
  22288. let vX;
  22289. let vY;
  22290. let vZ;
  22291. let x1 = this._localBasisX1X;
  22292. let y1 = this._localBasisX1Y;
  22293. let z1 = this._localBasisX1Z;
  22294. let x2 = x1 * x1;
  22295. let y2 = y1 * y1;
  22296. let z2 = z1 * z1;
  22297. let d;
  22298. if(x2 < y2) {
  22299. if(x2 < z2) {
  22300. d = 1 / Math.sqrt(y2 + z2);
  22301. vX = 0;
  22302. vY = z1 * d;
  22303. vZ = -y1 * d;
  22304. } else {
  22305. d = 1 / Math.sqrt(x2 + y2);
  22306. vX = y1 * d;
  22307. vY = -x1 * d;
  22308. vZ = 0;
  22309. }
  22310. } else if(y2 < z2) {
  22311. d = 1 / Math.sqrt(z2 + x2);
  22312. vX = -z1 * d;
  22313. vY = 0;
  22314. vZ = x1 * d;
  22315. } else {
  22316. d = 1 / Math.sqrt(x2 + y2);
  22317. vX = y1 * d;
  22318. vY = -x1 * d;
  22319. vZ = 0;
  22320. }
  22321. slerpQX = vX;
  22322. slerpQY = vY;
  22323. slerpQZ = vZ;
  22324. slerpQW = 0;
  22325. } else {
  22326. let cX;
  22327. let cY;
  22328. let cZ;
  22329. cX = this._localBasisX1Y * this._localBasisX2Z - this._localBasisX1Z * this._localBasisX2Y;
  22330. cY = this._localBasisX1Z * this._localBasisX2X - this._localBasisX1X * this._localBasisX2Z;
  22331. cZ = this._localBasisX1X * this._localBasisX2Y - this._localBasisX1Y * this._localBasisX2X;
  22332. let w = Math.sqrt((1 + d) * 0.5);
  22333. d = 0.5 / w;
  22334. cX *= d;
  22335. cY *= d;
  22336. cZ *= d;
  22337. slerpQX = cX;
  22338. slerpQY = cY;
  22339. slerpQZ = cZ;
  22340. slerpQW = w;
  22341. }
  22342. let x = slerpQX;
  22343. let y = slerpQY;
  22344. let z = slerpQZ;
  22345. let w = slerpQW;
  22346. let x2 = 2 * x;
  22347. let y2 = 2 * y;
  22348. let z2 = 2 * z;
  22349. let xx = x * x2;
  22350. let yy = y * y2;
  22351. let zz = z * z2;
  22352. let xy = x * y2;
  22353. let yz = y * z2;
  22354. let xz = x * z2;
  22355. let wx = w * x2;
  22356. let wy = w * y2;
  22357. let wz = w * z2;
  22358. slerpM00 = 1 - yy - zz;
  22359. slerpM01 = xy - wz;
  22360. slerpM02 = xz + wy;
  22361. slerpM10 = xy + wz;
  22362. slerpM11 = 1 - xx - zz;
  22363. slerpM12 = yz - wx;
  22364. slerpM20 = xz - wy;
  22365. slerpM21 = yz + wx;
  22366. slerpM22 = 1 - xx - yy;
  22367. let x1 = this._localBasisX1X;
  22368. let y1 = this._localBasisX1Y;
  22369. let z1 = this._localBasisX1Z;
  22370. let x21 = x1 * x1;
  22371. let y21 = y1 * y1;
  22372. let z21 = z1 * z1;
  22373. let d1;
  22374. if(x21 < y21) {
  22375. if(x21 < z21) {
  22376. d1 = 1 / Math.sqrt(y21 + z21);
  22377. this._localBasisY1X = 0;
  22378. this._localBasisY1Y = z1 * d1;
  22379. this._localBasisY1Z = -y1 * d1;
  22380. } else {
  22381. d1 = 1 / Math.sqrt(x21 + y21);
  22382. this._localBasisY1X = y1 * d1;
  22383. this._localBasisY1Y = -x1 * d1;
  22384. this._localBasisY1Z = 0;
  22385. }
  22386. } else if(y21 < z21) {
  22387. d1 = 1 / Math.sqrt(z21 + x21);
  22388. this._localBasisY1X = -z1 * d1;
  22389. this._localBasisY1Y = 0;
  22390. this._localBasisY1Z = x1 * d1;
  22391. } else {
  22392. d1 = 1 / Math.sqrt(x21 + y21);
  22393. this._localBasisY1X = y1 * d1;
  22394. this._localBasisY1Y = -x1 * d1;
  22395. this._localBasisY1Z = 0;
  22396. }
  22397. this._localBasisZ1X = this._localBasisX1Y * this._localBasisY1Z - this._localBasisX1Z * this._localBasisY1Y;
  22398. this._localBasisZ1Y = this._localBasisX1Z * this._localBasisY1X - this._localBasisX1X * this._localBasisY1Z;
  22399. this._localBasisZ1Z = this._localBasisX1X * this._localBasisY1Y - this._localBasisX1Y * this._localBasisY1X;
  22400. let __tmp__X;
  22401. let __tmp__Y;
  22402. let __tmp__Z;
  22403. __tmp__X = slerpM00 * this._localBasisX1X + slerpM01 * this._localBasisX1Y + slerpM02 * this._localBasisX1Z;
  22404. __tmp__Y = slerpM10 * this._localBasisX1X + slerpM11 * this._localBasisX1Y + slerpM12 * this._localBasisX1Z;
  22405. __tmp__Z = slerpM20 * this._localBasisX1X + slerpM21 * this._localBasisX1Y + slerpM22 * this._localBasisX1Z;
  22406. this._localBasisX2X = __tmp__X;
  22407. this._localBasisX2Y = __tmp__Y;
  22408. this._localBasisX2Z = __tmp__Z;
  22409. let __tmp__X1;
  22410. let __tmp__Y1;
  22411. let __tmp__Z1;
  22412. __tmp__X1 = slerpM00 * this._localBasisY1X + slerpM01 * this._localBasisY1Y + slerpM02 * this._localBasisY1Z;
  22413. __tmp__Y1 = slerpM10 * this._localBasisY1X + slerpM11 * this._localBasisY1Y + slerpM12 * this._localBasisY1Z;
  22414. __tmp__Z1 = slerpM20 * this._localBasisY1X + slerpM21 * this._localBasisY1Y + slerpM22 * this._localBasisY1Z;
  22415. this._localBasisY2X = __tmp__X1;
  22416. this._localBasisY2Y = __tmp__Y1;
  22417. this._localBasisY2Z = __tmp__Z1;
  22418. let __tmp__X2;
  22419. let __tmp__Y2;
  22420. let __tmp__Z2;
  22421. __tmp__X2 = slerpM00 * this._localBasisZ1X + slerpM01 * this._localBasisZ1Y + slerpM02 * this._localBasisZ1Z;
  22422. __tmp__Y2 = slerpM10 * this._localBasisZ1X + slerpM11 * this._localBasisZ1Y + slerpM12 * this._localBasisZ1Z;
  22423. __tmp__Z2 = slerpM20 * this._localBasisZ1X + slerpM21 * this._localBasisZ1Y + slerpM22 * this._localBasisZ1Z;
  22424. this._localBasisZ2X = __tmp__X2;
  22425. this._localBasisZ2Y = __tmp__Y2;
  22426. this._localBasisZ2Z = __tmp__Z2;
  22427. }
  22428. buildLocalBasesFromXY() {
  22429. if(this._localBasisX1X * this._localBasisX1X + this._localBasisX1Y * this._localBasisX1Y + this._localBasisX1Z * this._localBasisX1Z == 0) {
  22430. this._localBasisX1X = 1;
  22431. this._localBasisX1Y = 0;
  22432. this._localBasisX1Z = 0;
  22433. } else {
  22434. let l = this._localBasisX1X * this._localBasisX1X + this._localBasisX1Y * this._localBasisX1Y + this._localBasisX1Z * this._localBasisX1Z;
  22435. if(l > 0) {
  22436. l = 1 / Math.sqrt(l);
  22437. }
  22438. this._localBasisX1X *= l;
  22439. this._localBasisX1Y *= l;
  22440. this._localBasisX1Z *= l;
  22441. }
  22442. if(this._localBasisX2X * this._localBasisX2X + this._localBasisX2Y * this._localBasisX2Y + this._localBasisX2Z * this._localBasisX2Z == 0) {
  22443. this._localBasisX2X = 1;
  22444. this._localBasisX2Y = 0;
  22445. this._localBasisX2Z = 0;
  22446. } else {
  22447. let l = this._localBasisX2X * this._localBasisX2X + this._localBasisX2Y * this._localBasisX2Y + this._localBasisX2Z * this._localBasisX2Z;
  22448. if(l > 0) {
  22449. l = 1 / Math.sqrt(l);
  22450. }
  22451. this._localBasisX2X *= l;
  22452. this._localBasisX2Y *= l;
  22453. this._localBasisX2Z *= l;
  22454. }
  22455. this._localBasisZ1X = this._localBasisX1Y * this._localBasisY1Z - this._localBasisX1Z * this._localBasisY1Y;
  22456. this._localBasisZ1Y = this._localBasisX1Z * this._localBasisY1X - this._localBasisX1X * this._localBasisY1Z;
  22457. this._localBasisZ1Z = this._localBasisX1X * this._localBasisY1Y - this._localBasisX1Y * this._localBasisY1X;
  22458. this._localBasisZ2X = this._localBasisX2Y * this._localBasisY2Z - this._localBasisX2Z * this._localBasisY2Y;
  22459. this._localBasisZ2Y = this._localBasisX2Z * this._localBasisY2X - this._localBasisX2X * this._localBasisY2Z;
  22460. this._localBasisZ2Z = this._localBasisX2X * this._localBasisY2Y - this._localBasisX2Y * this._localBasisY2X;
  22461. if(this._localBasisZ1X * this._localBasisZ1X + this._localBasisZ1Y * this._localBasisZ1Y + this._localBasisZ1Z * this._localBasisZ1Z == 0) {
  22462. let x1 = this._localBasisX1X;
  22463. let y1 = this._localBasisX1Y;
  22464. let z1 = this._localBasisX1Z;
  22465. let x2 = x1 * x1;
  22466. let y2 = y1 * y1;
  22467. let z2 = z1 * z1;
  22468. let d;
  22469. if(x2 < y2) {
  22470. if(x2 < z2) {
  22471. d = 1 / Math.sqrt(y2 + z2);
  22472. this._localBasisY1X = 0;
  22473. this._localBasisY1Y = z1 * d;
  22474. this._localBasisY1Z = -y1 * d;
  22475. } else {
  22476. d = 1 / Math.sqrt(x2 + y2);
  22477. this._localBasisY1X = y1 * d;
  22478. this._localBasisY1Y = -x1 * d;
  22479. this._localBasisY1Z = 0;
  22480. }
  22481. } else if(y2 < z2) {
  22482. d = 1 / Math.sqrt(z2 + x2);
  22483. this._localBasisY1X = -z1 * d;
  22484. this._localBasisY1Y = 0;
  22485. this._localBasisY1Z = x1 * d;
  22486. } else {
  22487. d = 1 / Math.sqrt(x2 + y2);
  22488. this._localBasisY1X = y1 * d;
  22489. this._localBasisY1Y = -x1 * d;
  22490. this._localBasisY1Z = 0;
  22491. }
  22492. this._localBasisZ1X = this._localBasisX1Y * this._localBasisY1Z - this._localBasisX1Z * this._localBasisY1Y;
  22493. this._localBasisZ1Y = this._localBasisX1Z * this._localBasisY1X - this._localBasisX1X * this._localBasisY1Z;
  22494. this._localBasisZ1Z = this._localBasisX1X * this._localBasisY1Y - this._localBasisX1Y * this._localBasisY1X;
  22495. } else {
  22496. let l = this._localBasisZ1X * this._localBasisZ1X + this._localBasisZ1Y * this._localBasisZ1Y + this._localBasisZ1Z * this._localBasisZ1Z;
  22497. if(l > 0) {
  22498. l = 1 / Math.sqrt(l);
  22499. }
  22500. this._localBasisZ1X *= l;
  22501. this._localBasisZ1Y *= l;
  22502. this._localBasisZ1Z *= l;
  22503. this._localBasisY1X = this._localBasisZ1Y * this._localBasisX1Z - this._localBasisZ1Z * this._localBasisX1Y;
  22504. this._localBasisY1Y = this._localBasisZ1Z * this._localBasisX1X - this._localBasisZ1X * this._localBasisX1Z;
  22505. this._localBasisY1Z = this._localBasisZ1X * this._localBasisX1Y - this._localBasisZ1Y * this._localBasisX1X;
  22506. }
  22507. if(this._localBasisZ2X * this._localBasisZ2X + this._localBasisZ2Y * this._localBasisZ2Y + this._localBasisZ2Z * this._localBasisZ2Z == 0) {
  22508. let x1 = this._localBasisX2X;
  22509. let y1 = this._localBasisX2Y;
  22510. let z1 = this._localBasisX2Z;
  22511. let x2 = x1 * x1;
  22512. let y2 = y1 * y1;
  22513. let z2 = z1 * z1;
  22514. let d;
  22515. if(x2 < y2) {
  22516. if(x2 < z2) {
  22517. d = 1 / Math.sqrt(y2 + z2);
  22518. this._localBasisY2X = 0;
  22519. this._localBasisY2Y = z1 * d;
  22520. this._localBasisY2Z = -y1 * d;
  22521. } else {
  22522. d = 1 / Math.sqrt(x2 + y2);
  22523. this._localBasisY2X = y1 * d;
  22524. this._localBasisY2Y = -x1 * d;
  22525. this._localBasisY2Z = 0;
  22526. }
  22527. } else if(y2 < z2) {
  22528. d = 1 / Math.sqrt(z2 + x2);
  22529. this._localBasisY2X = -z1 * d;
  22530. this._localBasisY2Y = 0;
  22531. this._localBasisY2Z = x1 * d;
  22532. } else {
  22533. d = 1 / Math.sqrt(x2 + y2);
  22534. this._localBasisY2X = y1 * d;
  22535. this._localBasisY2Y = -x1 * d;
  22536. this._localBasisY2Z = 0;
  22537. }
  22538. this._localBasisZ2X = this._localBasisX2Y * this._localBasisY2Z - this._localBasisX2Z * this._localBasisY2Y;
  22539. this._localBasisZ2Y = this._localBasisX2Z * this._localBasisY2X - this._localBasisX2X * this._localBasisY2Z;
  22540. this._localBasisZ2Z = this._localBasisX2X * this._localBasisY2Y - this._localBasisX2Y * this._localBasisY2X;
  22541. } else {
  22542. let l = this._localBasisZ2X * this._localBasisZ2X + this._localBasisZ2Y * this._localBasisZ2Y + this._localBasisZ2Z * this._localBasisZ2Z;
  22543. if(l > 0) {
  22544. l = 1 / Math.sqrt(l);
  22545. }
  22546. this._localBasisZ2X *= l;
  22547. this._localBasisZ2Y *= l;
  22548. this._localBasisZ2Z *= l;
  22549. this._localBasisY2X = this._localBasisZ2Y * this._localBasisX2Z - this._localBasisZ2Z * this._localBasisX2Y;
  22550. this._localBasisY2Y = this._localBasisZ2Z * this._localBasisX2X - this._localBasisZ2X * this._localBasisX2Z;
  22551. this._localBasisY2Z = this._localBasisZ2X * this._localBasisX2Y - this._localBasisZ2Y * this._localBasisX2X;
  22552. }
  22553. }
  22554. buildLocalBasesFromX1Z2() {
  22555. if(this._localBasisX1X * this._localBasisX1X + this._localBasisX1Y * this._localBasisX1Y + this._localBasisX1Z * this._localBasisX1Z == 0) {
  22556. this._localBasisX1X = 1;
  22557. this._localBasisX1Y = 0;
  22558. this._localBasisX1Z = 0;
  22559. } else {
  22560. let l = this._localBasisX1X * this._localBasisX1X + this._localBasisX1Y * this._localBasisX1Y + this._localBasisX1Z * this._localBasisX1Z;
  22561. if(l > 0) {
  22562. l = 1 / Math.sqrt(l);
  22563. }
  22564. this._localBasisX1X *= l;
  22565. this._localBasisX1Y *= l;
  22566. this._localBasisX1Z *= l;
  22567. }
  22568. if(this._localBasisZ2X * this._localBasisZ2X + this._localBasisZ2Y * this._localBasisZ2Y + this._localBasisZ2Z * this._localBasisZ2Z == 0) {
  22569. this._localBasisZ2X = 0;
  22570. this._localBasisZ2Y = 0;
  22571. this._localBasisZ2Z = 1;
  22572. } else {
  22573. let l = this._localBasisZ2X * this._localBasisZ2X + this._localBasisZ2Y * this._localBasisZ2Y + this._localBasisZ2Z * this._localBasisZ2Z;
  22574. if(l > 0) {
  22575. l = 1 / Math.sqrt(l);
  22576. }
  22577. this._localBasisZ2X *= l;
  22578. this._localBasisZ2Y *= l;
  22579. this._localBasisZ2Z *= l;
  22580. }
  22581. let tf1 = this._b1._transform;
  22582. let tf2 = this._b2._transform;
  22583. let worldX1X;
  22584. let worldX1Y;
  22585. let worldX1Z;
  22586. let worldZ1X;
  22587. let worldZ1Y;
  22588. let worldZ1Z;
  22589. let worldYX;
  22590. let worldYY;
  22591. let worldYZ;
  22592. let worldX2X;
  22593. let worldX2Y;
  22594. let worldX2Z;
  22595. let worldZ2X;
  22596. let worldZ2Y;
  22597. let worldZ2Z;
  22598. let __tmp__X;
  22599. let __tmp__Y;
  22600. let __tmp__Z;
  22601. __tmp__X = tf1._rotation00 * this._localBasisX1X + tf1._rotation01 * this._localBasisX1Y + tf1._rotation02 * this._localBasisX1Z;
  22602. __tmp__Y = tf1._rotation10 * this._localBasisX1X + tf1._rotation11 * this._localBasisX1Y + tf1._rotation12 * this._localBasisX1Z;
  22603. __tmp__Z = tf1._rotation20 * this._localBasisX1X + tf1._rotation21 * this._localBasisX1Y + tf1._rotation22 * this._localBasisX1Z;
  22604. worldX1X = __tmp__X;
  22605. worldX1Y = __tmp__Y;
  22606. worldX1Z = __tmp__Z;
  22607. let __tmp__X1;
  22608. let __tmp__Y1;
  22609. let __tmp__Z1;
  22610. __tmp__X1 = tf2._rotation00 * this._localBasisZ2X + tf2._rotation01 * this._localBasisZ2Y + tf2._rotation02 * this._localBasisZ2Z;
  22611. __tmp__Y1 = tf2._rotation10 * this._localBasisZ2X + tf2._rotation11 * this._localBasisZ2Y + tf2._rotation12 * this._localBasisZ2Z;
  22612. __tmp__Z1 = tf2._rotation20 * this._localBasisZ2X + tf2._rotation21 * this._localBasisZ2Y + tf2._rotation22 * this._localBasisZ2Z;
  22613. worldZ2X = __tmp__X1;
  22614. worldZ2Y = __tmp__Y1;
  22615. worldZ2Z = __tmp__Z1;
  22616. worldYX = worldZ2Y * worldX1Z - worldZ2Z * worldX1Y;
  22617. worldYY = worldZ2Z * worldX1X - worldZ2X * worldX1Z;
  22618. worldYZ = worldZ2X * worldX1Y - worldZ2Y * worldX1X;
  22619. if(worldYX * worldYX + worldYY * worldYY + worldYZ * worldYZ == 0) {
  22620. let x1 = worldX1X;
  22621. let y1 = worldX1Y;
  22622. let z1 = worldX1Z;
  22623. let x2 = x1 * x1;
  22624. let y2 = y1 * y1;
  22625. let z2 = z1 * z1;
  22626. let d;
  22627. if(x2 < y2) {
  22628. if(x2 < z2) {
  22629. d = 1 / Math.sqrt(y2 + z2);
  22630. worldYX = 0;
  22631. worldYY = z1 * d;
  22632. worldYZ = -y1 * d;
  22633. } else {
  22634. d = 1 / Math.sqrt(x2 + y2);
  22635. worldYX = y1 * d;
  22636. worldYY = -x1 * d;
  22637. worldYZ = 0;
  22638. }
  22639. } else if(y2 < z2) {
  22640. d = 1 / Math.sqrt(z2 + x2);
  22641. worldYX = -z1 * d;
  22642. worldYY = 0;
  22643. worldYZ = x1 * d;
  22644. } else {
  22645. d = 1 / Math.sqrt(x2 + y2);
  22646. worldYX = y1 * d;
  22647. worldYY = -x1 * d;
  22648. worldYZ = 0;
  22649. }
  22650. }
  22651. worldZ1X = worldX1Y * worldYZ - worldX1Z * worldYY;
  22652. worldZ1Y = worldX1Z * worldYX - worldX1X * worldYZ;
  22653. worldZ1Z = worldX1X * worldYY - worldX1Y * worldYX;
  22654. worldX2X = worldYY * worldZ2Z - worldYZ * worldZ2Y;
  22655. worldX2Y = worldYZ * worldZ2X - worldYX * worldZ2Z;
  22656. worldX2Z = worldYX * worldZ2Y - worldYY * worldZ2X;
  22657. let __tmp__X2;
  22658. let __tmp__Y2;
  22659. let __tmp__Z2;
  22660. __tmp__X2 = tf1._rotation00 * worldX1X + tf1._rotation10 * worldX1Y + tf1._rotation20 * worldX1Z;
  22661. __tmp__Y2 = tf1._rotation01 * worldX1X + tf1._rotation11 * worldX1Y + tf1._rotation21 * worldX1Z;
  22662. __tmp__Z2 = tf1._rotation02 * worldX1X + tf1._rotation12 * worldX1Y + tf1._rotation22 * worldX1Z;
  22663. this._localBasisX1X = __tmp__X2;
  22664. this._localBasisX1Y = __tmp__Y2;
  22665. this._localBasisX1Z = __tmp__Z2;
  22666. let __tmp__X3;
  22667. let __tmp__Y3;
  22668. let __tmp__Z3;
  22669. __tmp__X3 = tf1._rotation00 * worldYX + tf1._rotation10 * worldYY + tf1._rotation20 * worldYZ;
  22670. __tmp__Y3 = tf1._rotation01 * worldYX + tf1._rotation11 * worldYY + tf1._rotation21 * worldYZ;
  22671. __tmp__Z3 = tf1._rotation02 * worldYX + tf1._rotation12 * worldYY + tf1._rotation22 * worldYZ;
  22672. this._localBasisY1X = __tmp__X3;
  22673. this._localBasisY1Y = __tmp__Y3;
  22674. this._localBasisY1Z = __tmp__Z3;
  22675. let __tmp__X4;
  22676. let __tmp__Y4;
  22677. let __tmp__Z4;
  22678. __tmp__X4 = tf1._rotation00 * worldZ1X + tf1._rotation10 * worldZ1Y + tf1._rotation20 * worldZ1Z;
  22679. __tmp__Y4 = tf1._rotation01 * worldZ1X + tf1._rotation11 * worldZ1Y + tf1._rotation21 * worldZ1Z;
  22680. __tmp__Z4 = tf1._rotation02 * worldZ1X + tf1._rotation12 * worldZ1Y + tf1._rotation22 * worldZ1Z;
  22681. this._localBasisZ1X = __tmp__X4;
  22682. this._localBasisZ1Y = __tmp__Y4;
  22683. this._localBasisZ1Z = __tmp__Z4;
  22684. let __tmp__X5;
  22685. let __tmp__Y5;
  22686. let __tmp__Z5;
  22687. __tmp__X5 = tf2._rotation00 * worldX2X + tf2._rotation10 * worldX2Y + tf2._rotation20 * worldX2Z;
  22688. __tmp__Y5 = tf2._rotation01 * worldX2X + tf2._rotation11 * worldX2Y + tf2._rotation21 * worldX2Z;
  22689. __tmp__Z5 = tf2._rotation02 * worldX2X + tf2._rotation12 * worldX2Y + tf2._rotation22 * worldX2Z;
  22690. this._localBasisX2X = __tmp__X5;
  22691. this._localBasisX2Y = __tmp__Y5;
  22692. this._localBasisX2Z = __tmp__Z5;
  22693. let __tmp__X6;
  22694. let __tmp__Y6;
  22695. let __tmp__Z6;
  22696. __tmp__X6 = tf2._rotation00 * worldYX + tf2._rotation10 * worldYY + tf2._rotation20 * worldYZ;
  22697. __tmp__Y6 = tf2._rotation01 * worldYX + tf2._rotation11 * worldYY + tf2._rotation21 * worldYZ;
  22698. __tmp__Z6 = tf2._rotation02 * worldYX + tf2._rotation12 * worldYY + tf2._rotation22 * worldYZ;
  22699. this._localBasisY2X = __tmp__X6;
  22700. this._localBasisY2Y = __tmp__Y6;
  22701. this._localBasisY2Z = __tmp__Z6;
  22702. let __tmp__X7;
  22703. let __tmp__Y7;
  22704. let __tmp__Z7;
  22705. __tmp__X7 = tf2._rotation00 * worldZ2X + tf2._rotation10 * worldZ2Y + tf2._rotation20 * worldZ2Z;
  22706. __tmp__Y7 = tf2._rotation01 * worldZ2X + tf2._rotation11 * worldZ2Y + tf2._rotation21 * worldZ2Z;
  22707. __tmp__Z7 = tf2._rotation02 * worldZ2X + tf2._rotation12 * worldZ2Y + tf2._rotation22 * worldZ2Z;
  22708. this._localBasisZ2X = __tmp__X7;
  22709. this._localBasisZ2Y = __tmp__Y7;
  22710. this._localBasisZ2Z = __tmp__Z7;
  22711. }
  22712. buildLocalBasesFromXY1X2() {
  22713. if(this._localBasisX1X * this._localBasisX1X + this._localBasisX1Y * this._localBasisX1Y + this._localBasisX1Z * this._localBasisX1Z == 0) {
  22714. this._localBasisX1X = 1;
  22715. this._localBasisX1Y = 0;
  22716. this._localBasisX1Z = 0;
  22717. } else {
  22718. let l = this._localBasisX1X * this._localBasisX1X + this._localBasisX1Y * this._localBasisX1Y + this._localBasisX1Z * this._localBasisX1Z;
  22719. if(l > 0) {
  22720. l = 1 / Math.sqrt(l);
  22721. }
  22722. this._localBasisX1X *= l;
  22723. this._localBasisX1Y *= l;
  22724. this._localBasisX1Z *= l;
  22725. }
  22726. this._localBasisZ1X = this._localBasisX1Y * this._localBasisY1Z - this._localBasisX1Z * this._localBasisY1Y;
  22727. this._localBasisZ1Y = this._localBasisX1Z * this._localBasisY1X - this._localBasisX1X * this._localBasisY1Z;
  22728. this._localBasisZ1Z = this._localBasisX1X * this._localBasisY1Y - this._localBasisX1Y * this._localBasisY1X;
  22729. if(this._localBasisZ1X * this._localBasisZ1X + this._localBasisZ1Y * this._localBasisZ1Y + this._localBasisZ1Z * this._localBasisZ1Z == 0) {
  22730. let x1 = this._localBasisX1X;
  22731. let y1 = this._localBasisX1Y;
  22732. let z1 = this._localBasisX1Z;
  22733. let x2 = x1 * x1;
  22734. let y2 = y1 * y1;
  22735. let z2 = z1 * z1;
  22736. let d;
  22737. if(x2 < y2) {
  22738. if(x2 < z2) {
  22739. d = 1 / Math.sqrt(y2 + z2);
  22740. this._localBasisY1X = 0;
  22741. this._localBasisY1Y = z1 * d;
  22742. this._localBasisY1Z = -y1 * d;
  22743. } else {
  22744. d = 1 / Math.sqrt(x2 + y2);
  22745. this._localBasisY1X = y1 * d;
  22746. this._localBasisY1Y = -x1 * d;
  22747. this._localBasisY1Z = 0;
  22748. }
  22749. } else if(y2 < z2) {
  22750. d = 1 / Math.sqrt(z2 + x2);
  22751. this._localBasisY1X = -z1 * d;
  22752. this._localBasisY1Y = 0;
  22753. this._localBasisY1Z = x1 * d;
  22754. } else {
  22755. d = 1 / Math.sqrt(x2 + y2);
  22756. this._localBasisY1X = y1 * d;
  22757. this._localBasisY1Y = -x1 * d;
  22758. this._localBasisY1Z = 0;
  22759. }
  22760. this._localBasisZ1X = this._localBasisX1Y * this._localBasisY1Z - this._localBasisX1Z * this._localBasisY1Y;
  22761. this._localBasisZ1Y = this._localBasisX1Z * this._localBasisY1X - this._localBasisX1X * this._localBasisY1Z;
  22762. this._localBasisZ1Z = this._localBasisX1X * this._localBasisY1Y - this._localBasisX1Y * this._localBasisY1X;
  22763. } else {
  22764. let l = this._localBasisZ1X * this._localBasisZ1X + this._localBasisZ1Y * this._localBasisZ1Y + this._localBasisZ1Z * this._localBasisZ1Z;
  22765. if(l > 0) {
  22766. l = 1 / Math.sqrt(l);
  22767. }
  22768. this._localBasisZ1X *= l;
  22769. this._localBasisZ1Y *= l;
  22770. this._localBasisZ1Z *= l;
  22771. this._localBasisY1X = this._localBasisZ1Y * this._localBasisX1Z - this._localBasisZ1Z * this._localBasisX1Y;
  22772. this._localBasisY1Y = this._localBasisZ1Z * this._localBasisX1X - this._localBasisZ1X * this._localBasisX1Z;
  22773. this._localBasisY1Z = this._localBasisZ1X * this._localBasisX1Y - this._localBasisZ1Y * this._localBasisX1X;
  22774. }
  22775. let slerpQX;
  22776. let slerpQY;
  22777. let slerpQZ;
  22778. let slerpQW;
  22779. let slerpM00;
  22780. let slerpM01;
  22781. let slerpM02;
  22782. let slerpM10;
  22783. let slerpM11;
  22784. let slerpM12;
  22785. let slerpM20;
  22786. let slerpM21;
  22787. let slerpM22;
  22788. let d = this._localBasisX1X * this._localBasisX2X + this._localBasisX1Y * this._localBasisX2Y + this._localBasisX1Z * this._localBasisX2Z;
  22789. if(d < -0.999999999) {
  22790. let vX;
  22791. let vY;
  22792. let vZ;
  22793. let x1 = this._localBasisX1X;
  22794. let y1 = this._localBasisX1Y;
  22795. let z1 = this._localBasisX1Z;
  22796. let x2 = x1 * x1;
  22797. let y2 = y1 * y1;
  22798. let z2 = z1 * z1;
  22799. let d;
  22800. if(x2 < y2) {
  22801. if(x2 < z2) {
  22802. d = 1 / Math.sqrt(y2 + z2);
  22803. vX = 0;
  22804. vY = z1 * d;
  22805. vZ = -y1 * d;
  22806. } else {
  22807. d = 1 / Math.sqrt(x2 + y2);
  22808. vX = y1 * d;
  22809. vY = -x1 * d;
  22810. vZ = 0;
  22811. }
  22812. } else if(y2 < z2) {
  22813. d = 1 / Math.sqrt(z2 + x2);
  22814. vX = -z1 * d;
  22815. vY = 0;
  22816. vZ = x1 * d;
  22817. } else {
  22818. d = 1 / Math.sqrt(x2 + y2);
  22819. vX = y1 * d;
  22820. vY = -x1 * d;
  22821. vZ = 0;
  22822. }
  22823. slerpQX = vX;
  22824. slerpQY = vY;
  22825. slerpQZ = vZ;
  22826. slerpQW = 0;
  22827. } else {
  22828. let cX;
  22829. let cY;
  22830. let cZ;
  22831. cX = this._localBasisX1Y * this._localBasisX2Z - this._localBasisX1Z * this._localBasisX2Y;
  22832. cY = this._localBasisX1Z * this._localBasisX2X - this._localBasisX1X * this._localBasisX2Z;
  22833. cZ = this._localBasisX1X * this._localBasisX2Y - this._localBasisX1Y * this._localBasisX2X;
  22834. let w = Math.sqrt((1 + d) * 0.5);
  22835. d = 0.5 / w;
  22836. cX *= d;
  22837. cY *= d;
  22838. cZ *= d;
  22839. slerpQX = cX;
  22840. slerpQY = cY;
  22841. slerpQZ = cZ;
  22842. slerpQW = w;
  22843. }
  22844. let x = slerpQX;
  22845. let y = slerpQY;
  22846. let z = slerpQZ;
  22847. let w = slerpQW;
  22848. let x2 = 2 * x;
  22849. let y2 = 2 * y;
  22850. let z2 = 2 * z;
  22851. let xx = x * x2;
  22852. let yy = y * y2;
  22853. let zz = z * z2;
  22854. let xy = x * y2;
  22855. let yz = y * z2;
  22856. let xz = x * z2;
  22857. let wx = w * x2;
  22858. let wy = w * y2;
  22859. let wz = w * z2;
  22860. slerpM00 = 1 - yy - zz;
  22861. slerpM01 = xy - wz;
  22862. slerpM02 = xz + wy;
  22863. slerpM10 = xy + wz;
  22864. slerpM11 = 1 - xx - zz;
  22865. slerpM12 = yz - wx;
  22866. slerpM20 = xz - wy;
  22867. slerpM21 = yz + wx;
  22868. slerpM22 = 1 - xx - yy;
  22869. let __tmp__X;
  22870. let __tmp__Y;
  22871. let __tmp__Z;
  22872. __tmp__X = slerpM00 * this._localBasisX1X + slerpM01 * this._localBasisX1Y + slerpM02 * this._localBasisX1Z;
  22873. __tmp__Y = slerpM10 * this._localBasisX1X + slerpM11 * this._localBasisX1Y + slerpM12 * this._localBasisX1Z;
  22874. __tmp__Z = slerpM20 * this._localBasisX1X + slerpM21 * this._localBasisX1Y + slerpM22 * this._localBasisX1Z;
  22875. this._localBasisX2X = __tmp__X;
  22876. this._localBasisX2Y = __tmp__Y;
  22877. this._localBasisX2Z = __tmp__Z;
  22878. let __tmp__X1;
  22879. let __tmp__Y1;
  22880. let __tmp__Z1;
  22881. __tmp__X1 = slerpM00 * this._localBasisY1X + slerpM01 * this._localBasisY1Y + slerpM02 * this._localBasisY1Z;
  22882. __tmp__Y1 = slerpM10 * this._localBasisY1X + slerpM11 * this._localBasisY1Y + slerpM12 * this._localBasisY1Z;
  22883. __tmp__Z1 = slerpM20 * this._localBasisY1X + slerpM21 * this._localBasisY1Y + slerpM22 * this._localBasisY1Z;
  22884. this._localBasisY2X = __tmp__X1;
  22885. this._localBasisY2Y = __tmp__Y1;
  22886. this._localBasisY2Z = __tmp__Z1;
  22887. let __tmp__X2;
  22888. let __tmp__Y2;
  22889. let __tmp__Z2;
  22890. __tmp__X2 = slerpM00 * this._localBasisZ1X + slerpM01 * this._localBasisZ1Y + slerpM02 * this._localBasisZ1Z;
  22891. __tmp__Y2 = slerpM10 * this._localBasisZ1X + slerpM11 * this._localBasisZ1Y + slerpM12 * this._localBasisZ1Z;
  22892. __tmp__Z2 = slerpM20 * this._localBasisZ1X + slerpM21 * this._localBasisZ1Y + slerpM22 * this._localBasisZ1Z;
  22893. this._localBasisZ2X = __tmp__X2;
  22894. this._localBasisZ2Y = __tmp__Y2;
  22895. this._localBasisZ2Z = __tmp__Z2;
  22896. }
  22897. setSolverInfoRowLinear(row,diff,lm,mass,sd,timeStep,isPositionPart) {
  22898. let cfmFactor;
  22899. let erp;
  22900. let slop = oimo.common.Setting.linearSlop;
  22901. if(isPositionPart) {
  22902. cfmFactor = 0;
  22903. erp = 1;
  22904. } else {
  22905. if(sd.frequency > 0) {
  22906. slop = 0;
  22907. let omega = 6.28318530717958 * sd.frequency;
  22908. let zeta = sd.dampingRatio;
  22909. if(zeta < oimo.common.Setting.minSpringDamperDampingRatio) {
  22910. zeta = oimo.common.Setting.minSpringDamperDampingRatio;
  22911. }
  22912. let h = timeStep.dt;
  22913. let c = 2 * zeta * omega;
  22914. let k = omega * omega;
  22915. if(sd.useSymplecticEuler) {
  22916. cfmFactor = 1 / (h * c);
  22917. erp = k / c;
  22918. } else {
  22919. cfmFactor = 1 / (h * (h * k + c));
  22920. erp = k / (h * k + c);
  22921. }
  22922. } else {
  22923. cfmFactor = 0;
  22924. erp = this.getErp(timeStep,false);
  22925. }
  22926. if(lm.motorForce > 0) {
  22927. row.motorSpeed = lm.motorSpeed;
  22928. row.motorMaxImpulse = lm.motorForce * timeStep.dt;
  22929. } else {
  22930. row.motorSpeed = 0;
  22931. row.motorMaxImpulse = 0;
  22932. }
  22933. }
  22934. let lower = lm.lowerLimit;
  22935. let upper = lm.upperLimit;
  22936. let minImp;
  22937. let maxImp;
  22938. let error;
  22939. if(lower > upper) {
  22940. minImp = 0;
  22941. maxImp = 0;
  22942. error = 0;
  22943. } else if(lower == upper) {
  22944. minImp = -1e65536;
  22945. maxImp = 1e65536;
  22946. error = diff - lower;
  22947. } else if(diff < lower) {
  22948. minImp = -1e65536;
  22949. maxImp = 0;
  22950. error = diff - lower + slop;
  22951. if(error > 0) {
  22952. error = 0;
  22953. }
  22954. } else if(diff > upper) {
  22955. minImp = 0;
  22956. maxImp = 1e65536;
  22957. error = diff - upper - slop;
  22958. if(error < 0) {
  22959. error = 0;
  22960. }
  22961. } else {
  22962. minImp = 0;
  22963. maxImp = 0;
  22964. error = 0;
  22965. }
  22966. row.minImpulse = minImp;
  22967. row.maxImpulse = maxImp;
  22968. row.cfm = cfmFactor * (mass == 0 ? 0 : 1 / mass);
  22969. row.rhs = error * erp;
  22970. }
  22971. setSolverInfoRowAngular(row,diff,lm,mass,sd,timeStep,isPositionPart) {
  22972. let cfmFactor;
  22973. let erp;
  22974. let slop = oimo.common.Setting.angularSlop;
  22975. if(isPositionPart) {
  22976. cfmFactor = 0;
  22977. erp = 1;
  22978. } else {
  22979. if(sd.frequency > 0) {
  22980. slop = 0;
  22981. let omega = 6.28318530717958 * sd.frequency;
  22982. let zeta = sd.dampingRatio;
  22983. if(zeta < oimo.common.Setting.minSpringDamperDampingRatio) {
  22984. zeta = oimo.common.Setting.minSpringDamperDampingRatio;
  22985. }
  22986. let h = timeStep.dt;
  22987. let c = 2 * zeta * omega;
  22988. let k = omega * omega;
  22989. if(sd.useSymplecticEuler) {
  22990. cfmFactor = 1 / (h * c);
  22991. erp = k / c;
  22992. } else {
  22993. cfmFactor = 1 / (h * (h * k + c));
  22994. erp = k / (h * k + c);
  22995. }
  22996. } else {
  22997. cfmFactor = 0;
  22998. erp = this.getErp(timeStep,false);
  22999. }
  23000. if(lm.motorTorque > 0) {
  23001. row.motorSpeed = lm.motorSpeed;
  23002. row.motorMaxImpulse = lm.motorTorque * timeStep.dt;
  23003. } else {
  23004. row.motorSpeed = 0;
  23005. row.motorMaxImpulse = 0;
  23006. }
  23007. }
  23008. let lower = lm.lowerLimit;
  23009. let upper = lm.upperLimit;
  23010. let mid = (lower + upper) * 0.5;
  23011. diff -= mid;
  23012. diff = ((diff + 3.14159265358979) % 6.28318530717958 + 6.28318530717958) % 6.28318530717958 - 3.14159265358979;
  23013. diff += mid;
  23014. let minImp;
  23015. let maxImp;
  23016. let error;
  23017. if(lower > upper) {
  23018. minImp = 0;
  23019. maxImp = 0;
  23020. error = 0;
  23021. } else if(lower == upper) {
  23022. minImp = -1e65536;
  23023. maxImp = 1e65536;
  23024. error = diff - lower;
  23025. } else if(diff < lower) {
  23026. minImp = -1e65536;
  23027. maxImp = 0;
  23028. error = diff - lower + slop;
  23029. if(error > 0) {
  23030. error = 0;
  23031. }
  23032. } else if(diff > upper) {
  23033. minImp = 0;
  23034. maxImp = 1e65536;
  23035. error = diff - upper - slop;
  23036. if(error < 0) {
  23037. error = 0;
  23038. }
  23039. } else {
  23040. minImp = 0;
  23041. maxImp = 0;
  23042. error = 0;
  23043. }
  23044. row.minImpulse = minImp;
  23045. row.maxImpulse = maxImp;
  23046. row.cfm = cfmFactor * (mass == 0 ? 0 : 1 / mass);
  23047. row.rhs = error * erp;
  23048. }
  23049. getErp(timeStep,isPositionPart) {
  23050. if(isPositionPart) {
  23051. return 1;
  23052. } else if(this._positionCorrectionAlgorithm == oimo.dynamics.constraint.PositionCorrectionAlgorithm.BAUMGARTE) {
  23053. return timeStep.invDt * oimo.common.Setting.velocityBaumgarte;
  23054. } else {
  23055. return 0;
  23056. }
  23057. }
  23058. computeEffectiveInertiaMoment(axisX,axisY,axisZ) {
  23059. let ia1X;
  23060. let ia1Y;
  23061. let ia1Z;
  23062. let ia2X;
  23063. let ia2Y;
  23064. let ia2Z;
  23065. let __tmp__X;
  23066. let __tmp__Y;
  23067. let __tmp__Z;
  23068. __tmp__X = this._b1._invInertia00 * axisX + this._b1._invInertia01 * axisY + this._b1._invInertia02 * axisZ;
  23069. __tmp__Y = this._b1._invInertia10 * axisX + this._b1._invInertia11 * axisY + this._b1._invInertia12 * axisZ;
  23070. __tmp__Z = this._b1._invInertia20 * axisX + this._b1._invInertia21 * axisY + this._b1._invInertia22 * axisZ;
  23071. ia1X = __tmp__X;
  23072. ia1Y = __tmp__Y;
  23073. ia1Z = __tmp__Z;
  23074. let __tmp__X1;
  23075. let __tmp__Y1;
  23076. let __tmp__Z1;
  23077. __tmp__X1 = this._b2._invInertia00 * axisX + this._b2._invInertia01 * axisY + this._b2._invInertia02 * axisZ;
  23078. __tmp__Y1 = this._b2._invInertia10 * axisX + this._b2._invInertia11 * axisY + this._b2._invInertia12 * axisZ;
  23079. __tmp__Z1 = this._b2._invInertia20 * axisX + this._b2._invInertia21 * axisY + this._b2._invInertia22 * axisZ;
  23080. ia2X = __tmp__X1;
  23081. ia2Y = __tmp__Y1;
  23082. ia2Z = __tmp__Z1;
  23083. let invI1 = ia1X * axisX + ia1Y * axisY + ia1Z * axisZ;
  23084. let invI2 = ia2X * axisX + ia2Y * axisY + ia2Z * axisZ;
  23085. if(invI1 > 0) {
  23086. let dot = axisX * this._relativeAnchor1X + axisY * this._relativeAnchor1Y + axisZ * this._relativeAnchor1Z;
  23087. let projsq = this._relativeAnchor1X * this._relativeAnchor1X + this._relativeAnchor1Y * this._relativeAnchor1Y + this._relativeAnchor1Z * this._relativeAnchor1Z - dot * dot;
  23088. if(projsq > 0) {
  23089. if(this._b1._invMass > 0) {
  23090. invI1 = 1 / (1 / invI1 + this._b1._mass * projsq);
  23091. } else {
  23092. invI1 = 0;
  23093. }
  23094. }
  23095. }
  23096. if(invI2 > 0) {
  23097. let dot = axisX * this._relativeAnchor2X + axisY * this._relativeAnchor2Y + axisZ * this._relativeAnchor2Z;
  23098. let projsq = this._relativeAnchor2X * this._relativeAnchor2X + this._relativeAnchor2Y * this._relativeAnchor2Y + this._relativeAnchor2Z * this._relativeAnchor2Z - dot * dot;
  23099. if(projsq > 0) {
  23100. if(this._b2._invMass > 0) {
  23101. invI2 = 1 / (1 / invI2 + this._b2._mass * projsq);
  23102. } else {
  23103. invI2 = 0;
  23104. }
  23105. }
  23106. }
  23107. if(invI1 + invI2 == 0) {
  23108. return 0;
  23109. } else {
  23110. return 1 / (invI1 + invI2);
  23111. }
  23112. }
  23113. computeEffectiveInertiaMoment2(axis1X,axis1Y,axis1Z,axis2X,axis2Y,axis2Z) {
  23114. let ia1X;
  23115. let ia1Y;
  23116. let ia1Z;
  23117. let ia2X;
  23118. let ia2Y;
  23119. let ia2Z;
  23120. let __tmp__X;
  23121. let __tmp__Y;
  23122. let __tmp__Z;
  23123. __tmp__X = this._b1._invInertia00 * axis1X + this._b1._invInertia01 * axis1Y + this._b1._invInertia02 * axis1Z;
  23124. __tmp__Y = this._b1._invInertia10 * axis1X + this._b1._invInertia11 * axis1Y + this._b1._invInertia12 * axis1Z;
  23125. __tmp__Z = this._b1._invInertia20 * axis1X + this._b1._invInertia21 * axis1Y + this._b1._invInertia22 * axis1Z;
  23126. ia1X = __tmp__X;
  23127. ia1Y = __tmp__Y;
  23128. ia1Z = __tmp__Z;
  23129. let __tmp__X1;
  23130. let __tmp__Y1;
  23131. let __tmp__Z1;
  23132. __tmp__X1 = this._b2._invInertia00 * axis2X + this._b2._invInertia01 * axis2Y + this._b2._invInertia02 * axis2Z;
  23133. __tmp__Y1 = this._b2._invInertia10 * axis2X + this._b2._invInertia11 * axis2Y + this._b2._invInertia12 * axis2Z;
  23134. __tmp__Z1 = this._b2._invInertia20 * axis2X + this._b2._invInertia21 * axis2Y + this._b2._invInertia22 * axis2Z;
  23135. ia2X = __tmp__X1;
  23136. ia2Y = __tmp__Y1;
  23137. ia2Z = __tmp__Z1;
  23138. let invI1 = ia1X * axis1X + ia1Y * axis1Y + ia1Z * axis1Z;
  23139. let invI2 = ia2X * axis2X + ia2Y * axis2Y + ia2Z * axis2Z;
  23140. if(invI1 > 0) {
  23141. let rsq = this._relativeAnchor1X * this._relativeAnchor1X + this._relativeAnchor1Y * this._relativeAnchor1Y + this._relativeAnchor1Z * this._relativeAnchor1Z;
  23142. let dot = axis1X * this._relativeAnchor1X + axis1Y * this._relativeAnchor1Y + axis1Z * this._relativeAnchor1Z;
  23143. let projsq = rsq * rsq - dot * dot;
  23144. if(projsq > 0) {
  23145. if(this._b1._invMass > 0) {
  23146. invI1 = 1 / (1 / invI1 + this._b1._mass * projsq);
  23147. } else {
  23148. invI1 = 0;
  23149. }
  23150. }
  23151. }
  23152. if(invI2 > 0) {
  23153. let rsq = this._relativeAnchor2X * this._relativeAnchor2X + this._relativeAnchor2Y * this._relativeAnchor2Y + this._relativeAnchor2Z * this._relativeAnchor2Z;
  23154. let dot = axis2X * this._relativeAnchor2X + axis2Y * this._relativeAnchor2Y + axis2Z * this._relativeAnchor2Z;
  23155. let projsq = rsq * rsq - dot * dot;
  23156. if(projsq > 0) {
  23157. if(this._b2._invMass > 0) {
  23158. invI2 = 1 / (1 / invI2 + this._b2._mass * projsq);
  23159. } else {
  23160. invI2 = 0;
  23161. }
  23162. }
  23163. }
  23164. if(invI1 + invI2 == 0) {
  23165. return 0;
  23166. } else {
  23167. return 1 / (invI1 + invI2);
  23168. }
  23169. }
  23170. _syncAnchors() {
  23171. let tf1 = this._b1._transform;
  23172. let tf2 = this._b2._transform;
  23173. let __tmp__X;
  23174. let __tmp__Y;
  23175. let __tmp__Z;
  23176. __tmp__X = tf1._rotation00 * this._localAnchor1X + tf1._rotation01 * this._localAnchor1Y + tf1._rotation02 * this._localAnchor1Z;
  23177. __tmp__Y = tf1._rotation10 * this._localAnchor1X + tf1._rotation11 * this._localAnchor1Y + tf1._rotation12 * this._localAnchor1Z;
  23178. __tmp__Z = tf1._rotation20 * this._localAnchor1X + tf1._rotation21 * this._localAnchor1Y + tf1._rotation22 * this._localAnchor1Z;
  23179. this._relativeAnchor1X = __tmp__X;
  23180. this._relativeAnchor1Y = __tmp__Y;
  23181. this._relativeAnchor1Z = __tmp__Z;
  23182. let __tmp__X1;
  23183. let __tmp__Y1;
  23184. let __tmp__Z1;
  23185. __tmp__X1 = tf2._rotation00 * this._localAnchor2X + tf2._rotation01 * this._localAnchor2Y + tf2._rotation02 * this._localAnchor2Z;
  23186. __tmp__Y1 = tf2._rotation10 * this._localAnchor2X + tf2._rotation11 * this._localAnchor2Y + tf2._rotation12 * this._localAnchor2Z;
  23187. __tmp__Z1 = tf2._rotation20 * this._localAnchor2X + tf2._rotation21 * this._localAnchor2Y + tf2._rotation22 * this._localAnchor2Z;
  23188. this._relativeAnchor2X = __tmp__X1;
  23189. this._relativeAnchor2Y = __tmp__Y1;
  23190. this._relativeAnchor2Z = __tmp__Z1;
  23191. this._anchor1X = this._relativeAnchor1X + tf1._positionX;
  23192. this._anchor1Y = this._relativeAnchor1Y + tf1._positionY;
  23193. this._anchor1Z = this._relativeAnchor1Z + tf1._positionZ;
  23194. this._anchor2X = this._relativeAnchor2X + tf2._positionX;
  23195. this._anchor2Y = this._relativeAnchor2Y + tf2._positionY;
  23196. this._anchor2Z = this._relativeAnchor2Z + tf2._positionZ;
  23197. let __tmp__X2;
  23198. let __tmp__Y2;
  23199. let __tmp__Z2;
  23200. __tmp__X2 = tf1._rotation00 * this._localBasisX1X + tf1._rotation01 * this._localBasisX1Y + tf1._rotation02 * this._localBasisX1Z;
  23201. __tmp__Y2 = tf1._rotation10 * this._localBasisX1X + tf1._rotation11 * this._localBasisX1Y + tf1._rotation12 * this._localBasisX1Z;
  23202. __tmp__Z2 = tf1._rotation20 * this._localBasisX1X + tf1._rotation21 * this._localBasisX1Y + tf1._rotation22 * this._localBasisX1Z;
  23203. this._basisX1X = __tmp__X2;
  23204. this._basisX1Y = __tmp__Y2;
  23205. this._basisX1Z = __tmp__Z2;
  23206. let __tmp__X3;
  23207. let __tmp__Y3;
  23208. let __tmp__Z3;
  23209. __tmp__X3 = tf1._rotation00 * this._localBasisY1X + tf1._rotation01 * this._localBasisY1Y + tf1._rotation02 * this._localBasisY1Z;
  23210. __tmp__Y3 = tf1._rotation10 * this._localBasisY1X + tf1._rotation11 * this._localBasisY1Y + tf1._rotation12 * this._localBasisY1Z;
  23211. __tmp__Z3 = tf1._rotation20 * this._localBasisY1X + tf1._rotation21 * this._localBasisY1Y + tf1._rotation22 * this._localBasisY1Z;
  23212. this._basisY1X = __tmp__X3;
  23213. this._basisY1Y = __tmp__Y3;
  23214. this._basisY1Z = __tmp__Z3;
  23215. let __tmp__X4;
  23216. let __tmp__Y4;
  23217. let __tmp__Z4;
  23218. __tmp__X4 = tf1._rotation00 * this._localBasisZ1X + tf1._rotation01 * this._localBasisZ1Y + tf1._rotation02 * this._localBasisZ1Z;
  23219. __tmp__Y4 = tf1._rotation10 * this._localBasisZ1X + tf1._rotation11 * this._localBasisZ1Y + tf1._rotation12 * this._localBasisZ1Z;
  23220. __tmp__Z4 = tf1._rotation20 * this._localBasisZ1X + tf1._rotation21 * this._localBasisZ1Y + tf1._rotation22 * this._localBasisZ1Z;
  23221. this._basisZ1X = __tmp__X4;
  23222. this._basisZ1Y = __tmp__Y4;
  23223. this._basisZ1Z = __tmp__Z4;
  23224. let __tmp__X5;
  23225. let __tmp__Y5;
  23226. let __tmp__Z5;
  23227. __tmp__X5 = tf2._rotation00 * this._localBasisX2X + tf2._rotation01 * this._localBasisX2Y + tf2._rotation02 * this._localBasisX2Z;
  23228. __tmp__Y5 = tf2._rotation10 * this._localBasisX2X + tf2._rotation11 * this._localBasisX2Y + tf2._rotation12 * this._localBasisX2Z;
  23229. __tmp__Z5 = tf2._rotation20 * this._localBasisX2X + tf2._rotation21 * this._localBasisX2Y + tf2._rotation22 * this._localBasisX2Z;
  23230. this._basisX2X = __tmp__X5;
  23231. this._basisX2Y = __tmp__Y5;
  23232. this._basisX2Z = __tmp__Z5;
  23233. let __tmp__X6;
  23234. let __tmp__Y6;
  23235. let __tmp__Z6;
  23236. __tmp__X6 = tf2._rotation00 * this._localBasisY2X + tf2._rotation01 * this._localBasisY2Y + tf2._rotation02 * this._localBasisY2Z;
  23237. __tmp__Y6 = tf2._rotation10 * this._localBasisY2X + tf2._rotation11 * this._localBasisY2Y + tf2._rotation12 * this._localBasisY2Z;
  23238. __tmp__Z6 = tf2._rotation20 * this._localBasisY2X + tf2._rotation21 * this._localBasisY2Y + tf2._rotation22 * this._localBasisY2Z;
  23239. this._basisY2X = __tmp__X6;
  23240. this._basisY2Y = __tmp__Y6;
  23241. this._basisY2Z = __tmp__Z6;
  23242. let __tmp__X7;
  23243. let __tmp__Y7;
  23244. let __tmp__Z7;
  23245. __tmp__X7 = tf2._rotation00 * this._localBasisZ2X + tf2._rotation01 * this._localBasisZ2Y + tf2._rotation02 * this._localBasisZ2Z;
  23246. __tmp__Y7 = tf2._rotation10 * this._localBasisZ2X + tf2._rotation11 * this._localBasisZ2Y + tf2._rotation12 * this._localBasisZ2Z;
  23247. __tmp__Z7 = tf2._rotation20 * this._localBasisZ2X + tf2._rotation21 * this._localBasisZ2Y + tf2._rotation22 * this._localBasisZ2Z;
  23248. this._basisZ2X = __tmp__X7;
  23249. this._basisZ2Y = __tmp__Y7;
  23250. this._basisZ2Z = __tmp__Z7;
  23251. }
  23252. _getVelocitySolverInfo(timeStep,info) {
  23253. info.b1 = this._b1;
  23254. info.b2 = this._b2;
  23255. info.numRows = 0;
  23256. }
  23257. _getPositionSolverInfo(info) {
  23258. info.b1 = this._b1;
  23259. info.b2 = this._b2;
  23260. info.numRows = 0;
  23261. }
  23262. _checkDestruction() {
  23263. let torqueSq = this._appliedTorqueX * this._appliedTorqueX + this._appliedTorqueY * this._appliedTorqueY + this._appliedTorqueZ * this._appliedTorqueZ;
  23264. if(this._breakForce > 0 && this._appliedForceX * this._appliedForceX + this._appliedForceY * this._appliedForceY + this._appliedForceZ * this._appliedForceZ > this._breakForce * this._breakForce) {
  23265. this._world.removeJoint(this);
  23266. return;
  23267. }
  23268. if(this._breakTorque > 0 && torqueSq > this._breakTorque * this._breakTorque) {
  23269. this._world.removeJoint(this);
  23270. return;
  23271. }
  23272. }
  23273. getRigidBody1() {
  23274. return this._b1;
  23275. }
  23276. getRigidBody2() {
  23277. return this._b2;
  23278. }
  23279. getType() {
  23280. return this._type;
  23281. }
  23282. getAnchor1() {
  23283. let v = new oimo.common.Vec3();
  23284. v.x = this._anchor1X;
  23285. v.y = this._anchor1Y;
  23286. v.z = this._anchor1Z;
  23287. return v;
  23288. }
  23289. getAnchor2() {
  23290. let v = new oimo.common.Vec3();
  23291. v.x = this._anchor2X;
  23292. v.y = this._anchor2Y;
  23293. v.z = this._anchor2Z;
  23294. return v;
  23295. }
  23296. getAnchor1To(anchor) {
  23297. anchor.x = this._anchor1X;
  23298. anchor.y = this._anchor1Y;
  23299. anchor.z = this._anchor1Z;
  23300. }
  23301. getAnchor2To(anchor) {
  23302. anchor.x = this._anchor2X;
  23303. anchor.y = this._anchor2Y;
  23304. anchor.z = this._anchor2Z;
  23305. }
  23306. getLocalAnchor1() {
  23307. let v = new oimo.common.Vec3();
  23308. v.x = this._localAnchor1X;
  23309. v.y = this._localAnchor1Y;
  23310. v.z = this._localAnchor1Z;
  23311. return v;
  23312. }
  23313. getLocalAnchor2() {
  23314. let v = new oimo.common.Vec3();
  23315. v.x = this._localAnchor2X;
  23316. v.y = this._localAnchor2Y;
  23317. v.z = this._localAnchor2Z;
  23318. return v;
  23319. }
  23320. getLocalAnchor1To(localAnchor) {
  23321. localAnchor.x = this._localAnchor1X;
  23322. localAnchor.y = this._localAnchor1Y;
  23323. localAnchor.z = this._localAnchor1Z;
  23324. }
  23325. getLocalAnchor2To(localAnchor) {
  23326. localAnchor.x = this._localAnchor2X;
  23327. localAnchor.y = this._localAnchor2Y;
  23328. localAnchor.z = this._localAnchor2Z;
  23329. }
  23330. getBasis1() {
  23331. let m = new oimo.common.Mat3();
  23332. let b00;
  23333. let b01;
  23334. let b02;
  23335. let b10;
  23336. let b11;
  23337. let b12;
  23338. let b20;
  23339. let b21;
  23340. let b22;
  23341. b00 = this._basisX1X;
  23342. b01 = this._basisY1X;
  23343. b02 = this._basisZ1X;
  23344. b10 = this._basisX1Y;
  23345. b11 = this._basisY1Y;
  23346. b12 = this._basisZ1Y;
  23347. b20 = this._basisX1Z;
  23348. b21 = this._basisY1Z;
  23349. b22 = this._basisZ1Z;
  23350. m.e00 = b00;
  23351. m.e01 = b01;
  23352. m.e02 = b02;
  23353. m.e10 = b10;
  23354. m.e11 = b11;
  23355. m.e12 = b12;
  23356. m.e20 = b20;
  23357. m.e21 = b21;
  23358. m.e22 = b22;
  23359. return m;
  23360. }
  23361. getBasis2() {
  23362. let m = new oimo.common.Mat3();
  23363. let b00;
  23364. let b01;
  23365. let b02;
  23366. let b10;
  23367. let b11;
  23368. let b12;
  23369. let b20;
  23370. let b21;
  23371. let b22;
  23372. b00 = this._basisX2X;
  23373. b01 = this._basisY2X;
  23374. b02 = this._basisZ2X;
  23375. b10 = this._basisX2Y;
  23376. b11 = this._basisY2Y;
  23377. b12 = this._basisZ2Y;
  23378. b20 = this._basisX2Z;
  23379. b21 = this._basisY2Z;
  23380. b22 = this._basisZ2Z;
  23381. m.e00 = b00;
  23382. m.e01 = b01;
  23383. m.e02 = b02;
  23384. m.e10 = b10;
  23385. m.e11 = b11;
  23386. m.e12 = b12;
  23387. m.e20 = b20;
  23388. m.e21 = b21;
  23389. m.e22 = b22;
  23390. return m;
  23391. }
  23392. getBasis1To(basis) {
  23393. let b00;
  23394. let b01;
  23395. let b02;
  23396. let b10;
  23397. let b11;
  23398. let b12;
  23399. let b20;
  23400. let b21;
  23401. let b22;
  23402. b00 = this._basisX1X;
  23403. b01 = this._basisY1X;
  23404. b02 = this._basisZ1X;
  23405. b10 = this._basisX1Y;
  23406. b11 = this._basisY1Y;
  23407. b12 = this._basisZ1Y;
  23408. b20 = this._basisX1Z;
  23409. b21 = this._basisY1Z;
  23410. b22 = this._basisZ1Z;
  23411. basis.e00 = b00;
  23412. basis.e01 = b01;
  23413. basis.e02 = b02;
  23414. basis.e10 = b10;
  23415. basis.e11 = b11;
  23416. basis.e12 = b12;
  23417. basis.e20 = b20;
  23418. basis.e21 = b21;
  23419. basis.e22 = b22;
  23420. }
  23421. getBasis2To(basis) {
  23422. let b00;
  23423. let b01;
  23424. let b02;
  23425. let b10;
  23426. let b11;
  23427. let b12;
  23428. let b20;
  23429. let b21;
  23430. let b22;
  23431. b00 = this._basisX2X;
  23432. b01 = this._basisY2X;
  23433. b02 = this._basisZ2X;
  23434. b10 = this._basisX2Y;
  23435. b11 = this._basisY2Y;
  23436. b12 = this._basisZ2Y;
  23437. b20 = this._basisX2Z;
  23438. b21 = this._basisY2Z;
  23439. b22 = this._basisZ2Z;
  23440. basis.e00 = b00;
  23441. basis.e01 = b01;
  23442. basis.e02 = b02;
  23443. basis.e10 = b10;
  23444. basis.e11 = b11;
  23445. basis.e12 = b12;
  23446. basis.e20 = b20;
  23447. basis.e21 = b21;
  23448. basis.e22 = b22;
  23449. }
  23450. getAllowCollision() {
  23451. return this._allowCollision;
  23452. }
  23453. setAllowCollision(allowCollision) {
  23454. this._allowCollision = allowCollision;
  23455. }
  23456. getBreakForce() {
  23457. return this._breakForce;
  23458. }
  23459. setBreakForce(breakForce) {
  23460. this._breakForce = breakForce;
  23461. }
  23462. getBreakTorque() {
  23463. return this._breakTorque;
  23464. }
  23465. setBreakTorque(breakTorque) {
  23466. this._breakTorque = breakTorque;
  23467. }
  23468. getPositionCorrectionAlgorithm() {
  23469. return this._positionCorrectionAlgorithm;
  23470. }
  23471. setPositionCorrectionAlgorithm(positionCorrectionAlgorithm) {
  23472. switch(positionCorrectionAlgorithm) {
  23473. case 0:case 1:case 2:
  23474. break;
  23475. default:
  23476. throw new Error("invalid position correction algorithm id: " + positionCorrectionAlgorithm);
  23477. }
  23478. this._positionCorrectionAlgorithm = positionCorrectionAlgorithm;
  23479. }
  23480. getAppliedForce() {
  23481. let v = new oimo.common.Vec3();
  23482. v.x = this._appliedForceX;
  23483. v.y = this._appliedForceY;
  23484. v.z = this._appliedForceZ;
  23485. return v;
  23486. }
  23487. getAppliedForceTo(appliedForce) {
  23488. appliedForce.x = this._appliedForceX;
  23489. appliedForce.y = this._appliedForceY;
  23490. appliedForce.z = this._appliedForceZ;
  23491. }
  23492. getAppliedTorque() {
  23493. let v = new oimo.common.Vec3();
  23494. v.x = this._appliedTorqueX;
  23495. v.y = this._appliedTorqueY;
  23496. v.z = this._appliedTorqueZ;
  23497. return v;
  23498. }
  23499. getAppliedTorqueTo(appliedTorque) {
  23500. appliedTorque.x = this._appliedTorqueX;
  23501. appliedTorque.y = this._appliedTorqueY;
  23502. appliedTorque.z = this._appliedTorqueZ;
  23503. }
  23504. getPrev() {
  23505. return this._prev;
  23506. }
  23507. getNext() {
  23508. return this._next;
  23509. }
  23510. }
  23511. oimo.dynamics.constraint.joint.CylindricalJoint = class oimo_dynamics_constraint_joint_CylindricalJoint extends oimo.dynamics.constraint.joint.Joint {
  23512. constructor(config) {
  23513. super(config,2);
  23514. let v = config.localAxis1;
  23515. this._localBasisX1X = v.x;
  23516. this._localBasisX1Y = v.y;
  23517. this._localBasisX1Z = v.z;
  23518. let v1 = config.localAxis2;
  23519. this._localBasisX2X = v1.x;
  23520. this._localBasisX2Y = v1.y;
  23521. this._localBasisX2Z = v1.z;
  23522. this.buildLocalBasesFromX();
  23523. this.angle = 0;
  23524. this.angularErrorY = 0;
  23525. this.angularErrorZ = 0;
  23526. this.translation = 0;
  23527. this.linearErrorY = 0;
  23528. this.linearErrorZ = 0;
  23529. this._basis = new oimo.dynamics.constraint.joint.BasisTracker(this);
  23530. this._translSd = config.translationalSpringDamper.clone();
  23531. this._translLm = config.translationalLimitMotor.clone();
  23532. this._rotSd = config.rotationalSpringDamper.clone();
  23533. this._rotLm = config.rotationalLimitMotor.clone();
  23534. }
  23535. getInfo(info,timeStep,isPositionPart) {
  23536. let erp = this.getErp(timeStep,isPositionPart);
  23537. let linRhsY = this.linearErrorY * erp;
  23538. let linRhsZ = this.linearErrorZ * erp;
  23539. let angRhsY = this.angularErrorY * erp;
  23540. let angRhsZ = this.angularErrorZ * erp;
  23541. let j;
  23542. let translationalMotorMass = 1 / (this._b1._invMass + this._b2._invMass);
  23543. let rotationalMotorMass = this.computeEffectiveInertiaMoment(this._basis.xX,this._basis.xY,this._basis.xZ);
  23544. if(this._translSd.frequency <= 0 || !isPositionPart) {
  23545. let impulse = this._impulses[0];
  23546. let row = info.rows[info.numRows++];
  23547. let _this = row.jacobian;
  23548. _this.lin1X = 0;
  23549. _this.lin1Y = 0;
  23550. _this.lin1Z = 0;
  23551. _this.lin2X = 0;
  23552. _this.lin2Y = 0;
  23553. _this.lin2Z = 0;
  23554. _this.ang1X = 0;
  23555. _this.ang1Y = 0;
  23556. _this.ang1Z = 0;
  23557. _this.ang2X = 0;
  23558. _this.ang2Y = 0;
  23559. _this.ang2Z = 0;
  23560. row.rhs = 0;
  23561. row.cfm = 0;
  23562. row.minImpulse = 0;
  23563. row.maxImpulse = 0;
  23564. row.motorSpeed = 0;
  23565. row.motorMaxImpulse = 0;
  23566. row.impulse = null;
  23567. row.impulse = impulse;
  23568. this.setSolverInfoRowLinear(row,this.translation,this._translLm,translationalMotorMass,this._translSd,timeStep,isPositionPart);
  23569. j = row.jacobian;
  23570. j.lin1X = this._basis.xX;
  23571. j.lin1Y = this._basis.xY;
  23572. j.lin1Z = this._basis.xZ;
  23573. j.lin2X = this._basis.xX;
  23574. j.lin2Y = this._basis.xY;
  23575. j.lin2Z = this._basis.xZ;
  23576. j.ang1X = this._relativeAnchor1Y * this._basis.xZ - this._relativeAnchor1Z * this._basis.xY;
  23577. j.ang1Y = this._relativeAnchor1Z * this._basis.xX - this._relativeAnchor1X * this._basis.xZ;
  23578. j.ang1Z = this._relativeAnchor1X * this._basis.xY - this._relativeAnchor1Y * this._basis.xX;
  23579. j.ang2X = this._relativeAnchor2Y * this._basis.xZ - this._relativeAnchor2Z * this._basis.xY;
  23580. j.ang2Y = this._relativeAnchor2Z * this._basis.xX - this._relativeAnchor2X * this._basis.xZ;
  23581. j.ang2Z = this._relativeAnchor2X * this._basis.xY - this._relativeAnchor2Y * this._basis.xX;
  23582. }
  23583. let impulse = this._impulses[1];
  23584. let row = info.rows[info.numRows++];
  23585. let _this = row.jacobian;
  23586. _this.lin1X = 0;
  23587. _this.lin1Y = 0;
  23588. _this.lin1Z = 0;
  23589. _this.lin2X = 0;
  23590. _this.lin2Y = 0;
  23591. _this.lin2Z = 0;
  23592. _this.ang1X = 0;
  23593. _this.ang1Y = 0;
  23594. _this.ang1Z = 0;
  23595. _this.ang2X = 0;
  23596. _this.ang2Y = 0;
  23597. _this.ang2Z = 0;
  23598. row.rhs = 0;
  23599. row.cfm = 0;
  23600. row.minImpulse = 0;
  23601. row.maxImpulse = 0;
  23602. row.motorSpeed = 0;
  23603. row.motorMaxImpulse = 0;
  23604. row.impulse = null;
  23605. row.impulse = impulse;
  23606. row.rhs = linRhsY;
  23607. row.cfm = 0;
  23608. row.minImpulse = -1e65536;
  23609. row.maxImpulse = 1e65536;
  23610. j = row.jacobian;
  23611. j.lin1X = this._basis.yX;
  23612. j.lin1Y = this._basis.yY;
  23613. j.lin1Z = this._basis.yZ;
  23614. j.lin2X = this._basis.yX;
  23615. j.lin2Y = this._basis.yY;
  23616. j.lin2Z = this._basis.yZ;
  23617. j.ang1X = this._relativeAnchor1Y * this._basis.yZ - this._relativeAnchor1Z * this._basis.yY;
  23618. j.ang1Y = this._relativeAnchor1Z * this._basis.yX - this._relativeAnchor1X * this._basis.yZ;
  23619. j.ang1Z = this._relativeAnchor1X * this._basis.yY - this._relativeAnchor1Y * this._basis.yX;
  23620. j.ang2X = this._relativeAnchor2Y * this._basis.yZ - this._relativeAnchor2Z * this._basis.yY;
  23621. j.ang2Y = this._relativeAnchor2Z * this._basis.yX - this._relativeAnchor2X * this._basis.yZ;
  23622. j.ang2Z = this._relativeAnchor2X * this._basis.yY - this._relativeAnchor2Y * this._basis.yX;
  23623. let impulse1 = this._impulses[2];
  23624. let row1 = info.rows[info.numRows++];
  23625. let _this1 = row1.jacobian;
  23626. _this1.lin1X = 0;
  23627. _this1.lin1Y = 0;
  23628. _this1.lin1Z = 0;
  23629. _this1.lin2X = 0;
  23630. _this1.lin2Y = 0;
  23631. _this1.lin2Z = 0;
  23632. _this1.ang1X = 0;
  23633. _this1.ang1Y = 0;
  23634. _this1.ang1Z = 0;
  23635. _this1.ang2X = 0;
  23636. _this1.ang2Y = 0;
  23637. _this1.ang2Z = 0;
  23638. row1.rhs = 0;
  23639. row1.cfm = 0;
  23640. row1.minImpulse = 0;
  23641. row1.maxImpulse = 0;
  23642. row1.motorSpeed = 0;
  23643. row1.motorMaxImpulse = 0;
  23644. row1.impulse = null;
  23645. row1.impulse = impulse1;
  23646. row1.rhs = linRhsZ;
  23647. row1.cfm = 0;
  23648. row1.minImpulse = -1e65536;
  23649. row1.maxImpulse = 1e65536;
  23650. j = row1.jacobian;
  23651. j.lin1X = this._basis.zX;
  23652. j.lin1Y = this._basis.zY;
  23653. j.lin1Z = this._basis.zZ;
  23654. j.lin2X = this._basis.zX;
  23655. j.lin2Y = this._basis.zY;
  23656. j.lin2Z = this._basis.zZ;
  23657. j.ang1X = this._relativeAnchor1Y * this._basis.zZ - this._relativeAnchor1Z * this._basis.zY;
  23658. j.ang1Y = this._relativeAnchor1Z * this._basis.zX - this._relativeAnchor1X * this._basis.zZ;
  23659. j.ang1Z = this._relativeAnchor1X * this._basis.zY - this._relativeAnchor1Y * this._basis.zX;
  23660. j.ang2X = this._relativeAnchor2Y * this._basis.zZ - this._relativeAnchor2Z * this._basis.zY;
  23661. j.ang2Y = this._relativeAnchor2Z * this._basis.zX - this._relativeAnchor2X * this._basis.zZ;
  23662. j.ang2Z = this._relativeAnchor2X * this._basis.zY - this._relativeAnchor2Y * this._basis.zX;
  23663. if(this._rotSd.frequency <= 0 || !isPositionPart) {
  23664. let impulse = this._impulses[3];
  23665. let row = info.rows[info.numRows++];
  23666. let _this = row.jacobian;
  23667. _this.lin1X = 0;
  23668. _this.lin1Y = 0;
  23669. _this.lin1Z = 0;
  23670. _this.lin2X = 0;
  23671. _this.lin2Y = 0;
  23672. _this.lin2Z = 0;
  23673. _this.ang1X = 0;
  23674. _this.ang1Y = 0;
  23675. _this.ang1Z = 0;
  23676. _this.ang2X = 0;
  23677. _this.ang2Y = 0;
  23678. _this.ang2Z = 0;
  23679. row.rhs = 0;
  23680. row.cfm = 0;
  23681. row.minImpulse = 0;
  23682. row.maxImpulse = 0;
  23683. row.motorSpeed = 0;
  23684. row.motorMaxImpulse = 0;
  23685. row.impulse = null;
  23686. row.impulse = impulse;
  23687. this.setSolverInfoRowAngular(row,this.angle,this._rotLm,rotationalMotorMass,this._rotSd,timeStep,isPositionPart);
  23688. j = row.jacobian;
  23689. j.ang1X = this._basis.xX;
  23690. j.ang1Y = this._basis.xY;
  23691. j.ang1Z = this._basis.xZ;
  23692. j.ang2X = this._basis.xX;
  23693. j.ang2Y = this._basis.xY;
  23694. j.ang2Z = this._basis.xZ;
  23695. }
  23696. let impulse2 = this._impulses[4];
  23697. let row2 = info.rows[info.numRows++];
  23698. let _this2 = row2.jacobian;
  23699. _this2.lin1X = 0;
  23700. _this2.lin1Y = 0;
  23701. _this2.lin1Z = 0;
  23702. _this2.lin2X = 0;
  23703. _this2.lin2Y = 0;
  23704. _this2.lin2Z = 0;
  23705. _this2.ang1X = 0;
  23706. _this2.ang1Y = 0;
  23707. _this2.ang1Z = 0;
  23708. _this2.ang2X = 0;
  23709. _this2.ang2Y = 0;
  23710. _this2.ang2Z = 0;
  23711. row2.rhs = 0;
  23712. row2.cfm = 0;
  23713. row2.minImpulse = 0;
  23714. row2.maxImpulse = 0;
  23715. row2.motorSpeed = 0;
  23716. row2.motorMaxImpulse = 0;
  23717. row2.impulse = null;
  23718. row2.impulse = impulse2;
  23719. row2.rhs = angRhsY;
  23720. row2.cfm = 0;
  23721. row2.minImpulse = -1e65536;
  23722. row2.maxImpulse = 1e65536;
  23723. j = row2.jacobian;
  23724. j.ang1X = this._basis.yX;
  23725. j.ang1Y = this._basis.yY;
  23726. j.ang1Z = this._basis.yZ;
  23727. j.ang2X = this._basis.yX;
  23728. j.ang2Y = this._basis.yY;
  23729. j.ang2Z = this._basis.yZ;
  23730. let impulse3 = this._impulses[5];
  23731. let row3 = info.rows[info.numRows++];
  23732. let _this3 = row3.jacobian;
  23733. _this3.lin1X = 0;
  23734. _this3.lin1Y = 0;
  23735. _this3.lin1Z = 0;
  23736. _this3.lin2X = 0;
  23737. _this3.lin2Y = 0;
  23738. _this3.lin2Z = 0;
  23739. _this3.ang1X = 0;
  23740. _this3.ang1Y = 0;
  23741. _this3.ang1Z = 0;
  23742. _this3.ang2X = 0;
  23743. _this3.ang2Y = 0;
  23744. _this3.ang2Z = 0;
  23745. row3.rhs = 0;
  23746. row3.cfm = 0;
  23747. row3.minImpulse = 0;
  23748. row3.maxImpulse = 0;
  23749. row3.motorSpeed = 0;
  23750. row3.motorMaxImpulse = 0;
  23751. row3.impulse = null;
  23752. row3.impulse = impulse3;
  23753. row3.rhs = angRhsZ;
  23754. row3.cfm = 0;
  23755. row3.minImpulse = -1e65536;
  23756. row3.maxImpulse = 1e65536;
  23757. j = row3.jacobian;
  23758. j.ang1X = this._basis.zX;
  23759. j.ang1Y = this._basis.zY;
  23760. j.ang1Z = this._basis.zZ;
  23761. j.ang2X = this._basis.zX;
  23762. j.ang2Y = this._basis.zY;
  23763. j.ang2Z = this._basis.zZ;
  23764. }
  23765. _syncAnchors() {
  23766. super._syncAnchors();
  23767. let _this = this._basis;
  23768. let invM1 = _this.joint._b1._invMass;
  23769. let invM2 = _this.joint._b2._invMass;
  23770. let qX;
  23771. let qY;
  23772. let qZ;
  23773. let qW;
  23774. let idQX;
  23775. let idQY;
  23776. let idQZ;
  23777. let idQW;
  23778. let slerpQX;
  23779. let slerpQY;
  23780. let slerpQZ;
  23781. let slerpQW;
  23782. let slerpM00;
  23783. let slerpM01;
  23784. let slerpM02;
  23785. let slerpM10;
  23786. let slerpM11;
  23787. let slerpM12;
  23788. let slerpM20;
  23789. let slerpM21;
  23790. let slerpM22;
  23791. let newXX;
  23792. let newXY;
  23793. let newXZ;
  23794. let newYX;
  23795. let newYY;
  23796. let newYZ;
  23797. let newZX;
  23798. let newZY;
  23799. let newZZ;
  23800. let prevXX;
  23801. let prevXY;
  23802. let prevXZ;
  23803. let prevYX;
  23804. let prevYY;
  23805. let prevYZ;
  23806. let d = _this.joint._basisX1X * _this.joint._basisX2X + _this.joint._basisX1Y * _this.joint._basisX2Y + _this.joint._basisX1Z * _this.joint._basisX2Z;
  23807. if(d < -0.999999999) {
  23808. let vX;
  23809. let vY;
  23810. let vZ;
  23811. let x1 = _this.joint._basisX1X;
  23812. let y1 = _this.joint._basisX1Y;
  23813. let z1 = _this.joint._basisX1Z;
  23814. let x2 = x1 * x1;
  23815. let y2 = y1 * y1;
  23816. let z2 = z1 * z1;
  23817. let d;
  23818. if(x2 < y2) {
  23819. if(x2 < z2) {
  23820. d = 1 / Math.sqrt(y2 + z2);
  23821. vX = 0;
  23822. vY = z1 * d;
  23823. vZ = -y1 * d;
  23824. } else {
  23825. d = 1 / Math.sqrt(x2 + y2);
  23826. vX = y1 * d;
  23827. vY = -x1 * d;
  23828. vZ = 0;
  23829. }
  23830. } else if(y2 < z2) {
  23831. d = 1 / Math.sqrt(z2 + x2);
  23832. vX = -z1 * d;
  23833. vY = 0;
  23834. vZ = x1 * d;
  23835. } else {
  23836. d = 1 / Math.sqrt(x2 + y2);
  23837. vX = y1 * d;
  23838. vY = -x1 * d;
  23839. vZ = 0;
  23840. }
  23841. qX = vX;
  23842. qY = vY;
  23843. qZ = vZ;
  23844. qW = 0;
  23845. } else {
  23846. let cX;
  23847. let cY;
  23848. let cZ;
  23849. cX = _this.joint._basisX1Y * _this.joint._basisX2Z - _this.joint._basisX1Z * _this.joint._basisX2Y;
  23850. cY = _this.joint._basisX1Z * _this.joint._basisX2X - _this.joint._basisX1X * _this.joint._basisX2Z;
  23851. cZ = _this.joint._basisX1X * _this.joint._basisX2Y - _this.joint._basisX1Y * _this.joint._basisX2X;
  23852. let w = Math.sqrt((1 + d) * 0.5);
  23853. d = 0.5 / w;
  23854. cX *= d;
  23855. cY *= d;
  23856. cZ *= d;
  23857. qX = cX;
  23858. qY = cY;
  23859. qZ = cZ;
  23860. qW = w;
  23861. }
  23862. idQX = 0;
  23863. idQY = 0;
  23864. idQZ = 0;
  23865. idQW = 1;
  23866. let q1X;
  23867. let q1Y;
  23868. let q1Z;
  23869. let q1W;
  23870. let q2X;
  23871. let q2Y;
  23872. let q2Z;
  23873. let q2W;
  23874. q1X = idQX;
  23875. q1Y = idQY;
  23876. q1Z = idQZ;
  23877. q1W = idQW;
  23878. q2X = qX;
  23879. q2Y = qY;
  23880. q2Z = qZ;
  23881. q2W = qW;
  23882. let d1 = q1X * q2X + q1Y * q2Y + q1Z * q2Z + q1W * q2W;
  23883. if(d1 < 0) {
  23884. d1 = -d1;
  23885. q2X = -q2X;
  23886. q2Y = -q2Y;
  23887. q2Z = -q2Z;
  23888. q2W = -q2W;
  23889. }
  23890. if(d1 > 0.999999) {
  23891. let dqX;
  23892. let dqY;
  23893. let dqZ;
  23894. let dqW;
  23895. dqX = q2X - q1X;
  23896. dqY = q2Y - q1Y;
  23897. dqZ = q2Z - q1Z;
  23898. dqW = q2W - q1W;
  23899. q2X = q1X + dqX * (invM1 / (invM1 + invM2));
  23900. q2Y = q1Y + dqY * (invM1 / (invM1 + invM2));
  23901. q2Z = q1Z + dqZ * (invM1 / (invM1 + invM2));
  23902. q2W = q1W + dqW * (invM1 / (invM1 + invM2));
  23903. let l = q2X * q2X + q2Y * q2Y + q2Z * q2Z + q2W * q2W;
  23904. if(l > 1e-32) {
  23905. l = 1 / Math.sqrt(l);
  23906. }
  23907. slerpQX = q2X * l;
  23908. slerpQY = q2Y * l;
  23909. slerpQZ = q2Z * l;
  23910. slerpQW = q2W * l;
  23911. } else {
  23912. let theta = invM1 / (invM1 + invM2) * Math.acos(d1);
  23913. q2X += q1X * -d1;
  23914. q2Y += q1Y * -d1;
  23915. q2Z += q1Z * -d1;
  23916. q2W += q1W * -d1;
  23917. let l = q2X * q2X + q2Y * q2Y + q2Z * q2Z + q2W * q2W;
  23918. if(l > 1e-32) {
  23919. l = 1 / Math.sqrt(l);
  23920. }
  23921. q2X *= l;
  23922. q2Y *= l;
  23923. q2Z *= l;
  23924. q2W *= l;
  23925. let sin = Math.sin(theta);
  23926. let cos = Math.cos(theta);
  23927. q1X *= cos;
  23928. q1Y *= cos;
  23929. q1Z *= cos;
  23930. q1W *= cos;
  23931. slerpQX = q1X + q2X * sin;
  23932. slerpQY = q1Y + q2Y * sin;
  23933. slerpQZ = q1Z + q2Z * sin;
  23934. slerpQW = q1W + q2W * sin;
  23935. }
  23936. let x = slerpQX;
  23937. let y = slerpQY;
  23938. let z = slerpQZ;
  23939. let w = slerpQW;
  23940. let x2 = 2 * x;
  23941. let y2 = 2 * y;
  23942. let z2 = 2 * z;
  23943. let xx = x * x2;
  23944. let yy = y * y2;
  23945. let zz = z * z2;
  23946. let xy = x * y2;
  23947. let yz = y * z2;
  23948. let xz = x * z2;
  23949. let wx = w * x2;
  23950. let wy = w * y2;
  23951. let wz = w * z2;
  23952. slerpM00 = 1 - yy - zz;
  23953. slerpM01 = xy - wz;
  23954. slerpM02 = xz + wy;
  23955. slerpM10 = xy + wz;
  23956. slerpM11 = 1 - xx - zz;
  23957. slerpM12 = yz - wx;
  23958. slerpM20 = xz - wy;
  23959. slerpM21 = yz + wx;
  23960. slerpM22 = 1 - xx - yy;
  23961. let __tmp__X;
  23962. let __tmp__Y;
  23963. let __tmp__Z;
  23964. __tmp__X = slerpM00 * _this.joint._basisX1X + slerpM01 * _this.joint._basisX1Y + slerpM02 * _this.joint._basisX1Z;
  23965. __tmp__Y = slerpM10 * _this.joint._basisX1X + slerpM11 * _this.joint._basisX1Y + slerpM12 * _this.joint._basisX1Z;
  23966. __tmp__Z = slerpM20 * _this.joint._basisX1X + slerpM21 * _this.joint._basisX1Y + slerpM22 * _this.joint._basisX1Z;
  23967. newXX = __tmp__X;
  23968. newXY = __tmp__Y;
  23969. newXZ = __tmp__Z;
  23970. prevXX = _this.xX;
  23971. prevXY = _this.xY;
  23972. prevXZ = _this.xZ;
  23973. prevYX = _this.yX;
  23974. prevYY = _this.yY;
  23975. prevYZ = _this.yZ;
  23976. let d2 = prevXX * newXX + prevXY * newXY + prevXZ * newXZ;
  23977. if(d2 < -0.999999999) {
  23978. let vX;
  23979. let vY;
  23980. let vZ;
  23981. let x1 = prevXX;
  23982. let y1 = prevXY;
  23983. let z1 = prevXZ;
  23984. let x2 = x1 * x1;
  23985. let y2 = y1 * y1;
  23986. let z2 = z1 * z1;
  23987. let d;
  23988. if(x2 < y2) {
  23989. if(x2 < z2) {
  23990. d = 1 / Math.sqrt(y2 + z2);
  23991. vX = 0;
  23992. vY = z1 * d;
  23993. vZ = -y1 * d;
  23994. } else {
  23995. d = 1 / Math.sqrt(x2 + y2);
  23996. vX = y1 * d;
  23997. vY = -x1 * d;
  23998. vZ = 0;
  23999. }
  24000. } else if(y2 < z2) {
  24001. d = 1 / Math.sqrt(z2 + x2);
  24002. vX = -z1 * d;
  24003. vY = 0;
  24004. vZ = x1 * d;
  24005. } else {
  24006. d = 1 / Math.sqrt(x2 + y2);
  24007. vX = y1 * d;
  24008. vY = -x1 * d;
  24009. vZ = 0;
  24010. }
  24011. slerpQX = vX;
  24012. slerpQY = vY;
  24013. slerpQZ = vZ;
  24014. slerpQW = 0;
  24015. } else {
  24016. let cX;
  24017. let cY;
  24018. let cZ;
  24019. cX = prevXY * newXZ - prevXZ * newXY;
  24020. cY = prevXZ * newXX - prevXX * newXZ;
  24021. cZ = prevXX * newXY - prevXY * newXX;
  24022. let w = Math.sqrt((1 + d2) * 0.5);
  24023. d2 = 0.5 / w;
  24024. cX *= d2;
  24025. cY *= d2;
  24026. cZ *= d2;
  24027. slerpQX = cX;
  24028. slerpQY = cY;
  24029. slerpQZ = cZ;
  24030. slerpQW = w;
  24031. }
  24032. let x1 = slerpQX;
  24033. let y1 = slerpQY;
  24034. let z1 = slerpQZ;
  24035. let w1 = slerpQW;
  24036. let x21 = 2 * x1;
  24037. let y21 = 2 * y1;
  24038. let z21 = 2 * z1;
  24039. let xx1 = x1 * x21;
  24040. let yy1 = y1 * y21;
  24041. let zz1 = z1 * z21;
  24042. let xy1 = x1 * y21;
  24043. let yz1 = y1 * z21;
  24044. let xz1 = x1 * z21;
  24045. let wx1 = w1 * x21;
  24046. let wy1 = w1 * y21;
  24047. let wz1 = w1 * z21;
  24048. slerpM00 = 1 - yy1 - zz1;
  24049. slerpM01 = xy1 - wz1;
  24050. slerpM02 = xz1 + wy1;
  24051. slerpM10 = xy1 + wz1;
  24052. slerpM11 = 1 - xx1 - zz1;
  24053. slerpM12 = yz1 - wx1;
  24054. slerpM20 = xz1 - wy1;
  24055. slerpM21 = yz1 + wx1;
  24056. slerpM22 = 1 - xx1 - yy1;
  24057. let __tmp__X1;
  24058. let __tmp__Y1;
  24059. let __tmp__Z1;
  24060. __tmp__X1 = slerpM00 * prevYX + slerpM01 * prevYY + slerpM02 * prevYZ;
  24061. __tmp__Y1 = slerpM10 * prevYX + slerpM11 * prevYY + slerpM12 * prevYZ;
  24062. __tmp__Z1 = slerpM20 * prevYX + slerpM21 * prevYY + slerpM22 * prevYZ;
  24063. newYX = __tmp__X1;
  24064. newYY = __tmp__Y1;
  24065. newYZ = __tmp__Z1;
  24066. newZX = newXY * newYZ - newXZ * newYY;
  24067. newZY = newXZ * newYX - newXX * newYZ;
  24068. newZZ = newXX * newYY - newXY * newYX;
  24069. if(newZX * newZX + newZY * newZY + newZZ * newZZ > 1e-6) {
  24070. let l = newZX * newZX + newZY * newZY + newZZ * newZZ;
  24071. if(l > 0) {
  24072. l = 1 / Math.sqrt(l);
  24073. }
  24074. newZX *= l;
  24075. newZY *= l;
  24076. newZZ *= l;
  24077. } else {
  24078. let x1 = newXX;
  24079. let y1 = newXY;
  24080. let z1 = newXZ;
  24081. let x2 = x1 * x1;
  24082. let y2 = y1 * y1;
  24083. let z2 = z1 * z1;
  24084. let d;
  24085. if(x2 < y2) {
  24086. if(x2 < z2) {
  24087. d = 1 / Math.sqrt(y2 + z2);
  24088. newZX = 0;
  24089. newZY = z1 * d;
  24090. newZZ = -y1 * d;
  24091. } else {
  24092. d = 1 / Math.sqrt(x2 + y2);
  24093. newZX = y1 * d;
  24094. newZY = -x1 * d;
  24095. newZZ = 0;
  24096. }
  24097. } else if(y2 < z2) {
  24098. d = 1 / Math.sqrt(z2 + x2);
  24099. newZX = -z1 * d;
  24100. newZY = 0;
  24101. newZZ = x1 * d;
  24102. } else {
  24103. d = 1 / Math.sqrt(x2 + y2);
  24104. newZX = y1 * d;
  24105. newZY = -x1 * d;
  24106. newZZ = 0;
  24107. }
  24108. }
  24109. newYX = newZY * newXZ - newZZ * newXY;
  24110. newYY = newZZ * newXX - newZX * newXZ;
  24111. newYZ = newZX * newXY - newZY * newXX;
  24112. _this.xX = newXX;
  24113. _this.xY = newXY;
  24114. _this.xZ = newXZ;
  24115. _this.yX = newYX;
  24116. _this.yY = newYY;
  24117. _this.yZ = newYZ;
  24118. _this.zX = newZX;
  24119. _this.zY = newZY;
  24120. _this.zZ = newZZ;
  24121. let angErrorX;
  24122. let angErrorY;
  24123. let angErrorZ;
  24124. angErrorX = this._basisX1Y * this._basisX2Z - this._basisX1Z * this._basisX2Y;
  24125. angErrorY = this._basisX1Z * this._basisX2X - this._basisX1X * this._basisX2Z;
  24126. angErrorZ = this._basisX1X * this._basisX2Y - this._basisX1Y * this._basisX2X;
  24127. let cos = this._basisX1X * this._basisX2X + this._basisX1Y * this._basisX2Y + this._basisX1Z * this._basisX2Z;
  24128. let theta = cos <= -1 ? 3.14159265358979 : cos >= 1 ? 0 : Math.acos(cos);
  24129. let l = angErrorX * angErrorX + angErrorY * angErrorY + angErrorZ * angErrorZ;
  24130. if(l > 0) {
  24131. l = 1 / Math.sqrt(l);
  24132. }
  24133. angErrorX *= l;
  24134. angErrorY *= l;
  24135. angErrorZ *= l;
  24136. angErrorX *= theta;
  24137. angErrorY *= theta;
  24138. angErrorZ *= theta;
  24139. this.angularErrorY = angErrorX * this._basis.yX + angErrorY * this._basis.yY + angErrorZ * this._basis.yZ;
  24140. this.angularErrorZ = angErrorX * this._basis.zX + angErrorY * this._basis.zY + angErrorZ * this._basis.zZ;
  24141. let perpCrossX;
  24142. let perpCrossY;
  24143. let perpCrossZ;
  24144. perpCrossX = this._basisY1Y * this._basisY2Z - this._basisY1Z * this._basisY2Y;
  24145. perpCrossY = this._basisY1Z * this._basisY2X - this._basisY1X * this._basisY2Z;
  24146. perpCrossZ = this._basisY1X * this._basisY2Y - this._basisY1Y * this._basisY2X;
  24147. cos = this._basisY1X * this._basisY2X + this._basisY1Y * this._basisY2Y + this._basisY1Z * this._basisY2Z;
  24148. this.angle = cos <= -1 ? 3.14159265358979 : cos >= 1 ? 0 : Math.acos(cos);
  24149. if(perpCrossX * this._basis.xX + perpCrossY * this._basis.xY + perpCrossZ * this._basis.xZ < 0) {
  24150. this.angle = -this.angle;
  24151. }
  24152. let anchorDiffX;
  24153. let anchorDiffY;
  24154. let anchorDiffZ;
  24155. anchorDiffX = this._anchor2X - this._anchor1X;
  24156. anchorDiffY = this._anchor2Y - this._anchor1Y;
  24157. anchorDiffZ = this._anchor2Z - this._anchor1Z;
  24158. this.translation = anchorDiffX * this._basis.xX + anchorDiffY * this._basis.xY + anchorDiffZ * this._basis.xZ;
  24159. this.linearErrorY = anchorDiffX * this._basis.yX + anchorDiffY * this._basis.yY + anchorDiffZ * this._basis.yZ;
  24160. this.linearErrorZ = anchorDiffX * this._basis.zX + anchorDiffY * this._basis.zY + anchorDiffZ * this._basis.zZ;
  24161. }
  24162. _getVelocitySolverInfo(timeStep,info) {
  24163. super._getVelocitySolverInfo(timeStep,info);
  24164. this.getInfo(info,timeStep,false);
  24165. }
  24166. _getPositionSolverInfo(info) {
  24167. super._getPositionSolverInfo(info);
  24168. this.getInfo(info,null,true);
  24169. }
  24170. getAxis1() {
  24171. let v = new oimo.common.Vec3();
  24172. v.x = this._basisX1X;
  24173. v.y = this._basisX1Y;
  24174. v.z = this._basisX1Z;
  24175. return v;
  24176. }
  24177. getAxis2() {
  24178. let v = new oimo.common.Vec3();
  24179. v.x = this._basisX2X;
  24180. v.y = this._basisX2Y;
  24181. v.z = this._basisX2Z;
  24182. return v;
  24183. }
  24184. getAxis1To(axis) {
  24185. axis.x = this._basisX1X;
  24186. axis.y = this._basisX1Y;
  24187. axis.z = this._basisX1Z;
  24188. }
  24189. getAxis2To(axis) {
  24190. axis.x = this._basisX2X;
  24191. axis.y = this._basisX2Y;
  24192. axis.z = this._basisX2Z;
  24193. }
  24194. getLocalAxis1() {
  24195. let v = new oimo.common.Vec3();
  24196. v.x = this._localBasisX1X;
  24197. v.y = this._localBasisX1Y;
  24198. v.z = this._localBasisX1Z;
  24199. return v;
  24200. }
  24201. getLocalAxis2() {
  24202. let v = new oimo.common.Vec3();
  24203. v.x = this._localBasisX2X;
  24204. v.y = this._localBasisX2Y;
  24205. v.z = this._localBasisX2Z;
  24206. return v;
  24207. }
  24208. getLocalAxis1To(axis) {
  24209. axis.x = this._localBasisX1X;
  24210. axis.y = this._localBasisX1Y;
  24211. axis.z = this._localBasisX1Z;
  24212. }
  24213. getLocalAxis2To(axis) {
  24214. axis.x = this._localBasisX2X;
  24215. axis.y = this._localBasisX2Y;
  24216. axis.z = this._localBasisX2Z;
  24217. }
  24218. getTranslationalSpringDamper() {
  24219. return this._translSd;
  24220. }
  24221. getRotationalSpringDamper() {
  24222. return this._rotSd;
  24223. }
  24224. getTranslationalLimitMotor() {
  24225. return this._translLm;
  24226. }
  24227. getRotationalLimitMotor() {
  24228. return this._rotLm;
  24229. }
  24230. getAngle() {
  24231. return this.angle;
  24232. }
  24233. getTranslation() {
  24234. return this.translation;
  24235. }
  24236. }
  24237. oimo.dynamics.constraint.joint.JointConfig = class oimo_dynamics_constraint_joint_JointConfig {
  24238. constructor() {
  24239. this.rigidBody1 = null;
  24240. this.rigidBody2 = null;
  24241. this.localAnchor1 = new oimo.common.Vec3();
  24242. this.localAnchor2 = new oimo.common.Vec3();
  24243. this.allowCollision = false;
  24244. this.solverType = oimo.common.Setting.defaultJointConstraintSolverType;
  24245. this.positionCorrectionAlgorithm = oimo.common.Setting.defaultJointPositionCorrectionAlgorithm;
  24246. this.breakForce = 0;
  24247. this.breakTorque = 0;
  24248. }
  24249. _init(rb1,rb2,worldAnchor) {
  24250. this.rigidBody1 = rb1;
  24251. this.rigidBody2 = rb2;
  24252. let _this = this.rigidBody1;
  24253. let localPoint = this.localAnchor1;
  24254. let vX;
  24255. let vY;
  24256. let vZ;
  24257. vX = worldAnchor.x;
  24258. vY = worldAnchor.y;
  24259. vZ = worldAnchor.z;
  24260. vX -= _this._transform._positionX;
  24261. vY -= _this._transform._positionY;
  24262. vZ -= _this._transform._positionZ;
  24263. let __tmp__X;
  24264. let __tmp__Y;
  24265. let __tmp__Z;
  24266. __tmp__X = _this._transform._rotation00 * vX + _this._transform._rotation10 * vY + _this._transform._rotation20 * vZ;
  24267. __tmp__Y = _this._transform._rotation01 * vX + _this._transform._rotation11 * vY + _this._transform._rotation21 * vZ;
  24268. __tmp__Z = _this._transform._rotation02 * vX + _this._transform._rotation12 * vY + _this._transform._rotation22 * vZ;
  24269. vX = __tmp__X;
  24270. vY = __tmp__Y;
  24271. vZ = __tmp__Z;
  24272. localPoint.x = vX;
  24273. localPoint.y = vY;
  24274. localPoint.z = vZ;
  24275. let _this1 = this.rigidBody2;
  24276. let localPoint1 = this.localAnchor2;
  24277. let vX1;
  24278. let vY1;
  24279. let vZ1;
  24280. vX1 = worldAnchor.x;
  24281. vY1 = worldAnchor.y;
  24282. vZ1 = worldAnchor.z;
  24283. vX1 -= _this1._transform._positionX;
  24284. vY1 -= _this1._transform._positionY;
  24285. vZ1 -= _this1._transform._positionZ;
  24286. let __tmp__X1;
  24287. let __tmp__Y1;
  24288. let __tmp__Z1;
  24289. __tmp__X1 = _this1._transform._rotation00 * vX1 + _this1._transform._rotation10 * vY1 + _this1._transform._rotation20 * vZ1;
  24290. __tmp__Y1 = _this1._transform._rotation01 * vX1 + _this1._transform._rotation11 * vY1 + _this1._transform._rotation21 * vZ1;
  24291. __tmp__Z1 = _this1._transform._rotation02 * vX1 + _this1._transform._rotation12 * vY1 + _this1._transform._rotation22 * vZ1;
  24292. vX1 = __tmp__X1;
  24293. vY1 = __tmp__Y1;
  24294. vZ1 = __tmp__Z1;
  24295. localPoint1.x = vX1;
  24296. localPoint1.y = vY1;
  24297. localPoint1.z = vZ1;
  24298. }
  24299. }
  24300. oimo.dynamics.constraint.joint.CylindricalJointConfig = class oimo_dynamics_constraint_joint_CylindricalJointConfig extends oimo.dynamics.constraint.joint.JointConfig {
  24301. constructor() {
  24302. super();
  24303. this.localAxis1 = new oimo.common.Vec3(1,0,0);
  24304. this.localAxis2 = new oimo.common.Vec3(1,0,0);
  24305. this.translationalLimitMotor = new oimo.dynamics.constraint.joint.TranslationalLimitMotor();
  24306. this.translationalSpringDamper = new oimo.dynamics.constraint.joint.SpringDamper();
  24307. this.rotationalLimitMotor = new oimo.dynamics.constraint.joint.RotationalLimitMotor();
  24308. this.rotationalSpringDamper = new oimo.dynamics.constraint.joint.SpringDamper();
  24309. }
  24310. init(rigidBody1,rigidBody2,worldAnchor,worldAxis) {
  24311. this._init(rigidBody1,rigidBody2,worldAnchor);
  24312. let localVector = this.localAxis1;
  24313. let vX;
  24314. let vY;
  24315. let vZ;
  24316. vX = worldAxis.x;
  24317. vY = worldAxis.y;
  24318. vZ = worldAxis.z;
  24319. let __tmp__X;
  24320. let __tmp__Y;
  24321. let __tmp__Z;
  24322. __tmp__X = rigidBody1._transform._rotation00 * vX + rigidBody1._transform._rotation10 * vY + rigidBody1._transform._rotation20 * vZ;
  24323. __tmp__Y = rigidBody1._transform._rotation01 * vX + rigidBody1._transform._rotation11 * vY + rigidBody1._transform._rotation21 * vZ;
  24324. __tmp__Z = rigidBody1._transform._rotation02 * vX + rigidBody1._transform._rotation12 * vY + rigidBody1._transform._rotation22 * vZ;
  24325. vX = __tmp__X;
  24326. vY = __tmp__Y;
  24327. vZ = __tmp__Z;
  24328. localVector.x = vX;
  24329. localVector.y = vY;
  24330. localVector.z = vZ;
  24331. let localVector1 = this.localAxis2;
  24332. let vX1;
  24333. let vY1;
  24334. let vZ1;
  24335. vX1 = worldAxis.x;
  24336. vY1 = worldAxis.y;
  24337. vZ1 = worldAxis.z;
  24338. let __tmp__X1;
  24339. let __tmp__Y1;
  24340. let __tmp__Z1;
  24341. __tmp__X1 = rigidBody2._transform._rotation00 * vX1 + rigidBody2._transform._rotation10 * vY1 + rigidBody2._transform._rotation20 * vZ1;
  24342. __tmp__Y1 = rigidBody2._transform._rotation01 * vX1 + rigidBody2._transform._rotation11 * vY1 + rigidBody2._transform._rotation21 * vZ1;
  24343. __tmp__Z1 = rigidBody2._transform._rotation02 * vX1 + rigidBody2._transform._rotation12 * vY1 + rigidBody2._transform._rotation22 * vZ1;
  24344. vX1 = __tmp__X1;
  24345. vY1 = __tmp__Y1;
  24346. vZ1 = __tmp__Z1;
  24347. localVector1.x = vX1;
  24348. localVector1.y = vY1;
  24349. localVector1.z = vZ1;
  24350. return this;
  24351. }
  24352. }
  24353. oimo.dynamics.constraint.joint.GenericJoint = class oimo_dynamics_constraint_joint_GenericJoint extends oimo.dynamics.constraint.joint.Joint {
  24354. constructor(config) {
  24355. super(config,oimo.dynamics.constraint.joint.JointType.GENERIC);
  24356. let tmp;
  24357. let _this = config.localBasis1;
  24358. if(!(_this.e00 * (_this.e11 * _this.e22 - _this.e12 * _this.e21) - _this.e01 * (_this.e10 * _this.e22 - _this.e12 * _this.e20) + _this.e02 * (_this.e10 * _this.e21 - _this.e11 * _this.e20) < 0)) {
  24359. let _this = config.localBasis2;
  24360. tmp = _this.e00 * (_this.e11 * _this.e22 - _this.e12 * _this.e21) - _this.e01 * (_this.e10 * _this.e22 - _this.e12 * _this.e20) + _this.e02 * (_this.e10 * _this.e21 - _this.e11 * _this.e20) < 0;
  24361. } else {
  24362. tmp = true;
  24363. }
  24364. if(tmp) {
  24365. console.log("src/oimo/dynamics/constraint/joint/GenericJoint.hx:50:","[warning] joint basis must be right handed");
  24366. }
  24367. let lb100;
  24368. let lb101;
  24369. let lb102;
  24370. let lb110;
  24371. let lb111;
  24372. let lb112;
  24373. let lb120;
  24374. let lb121;
  24375. let lb122;
  24376. let lb200;
  24377. let lb201;
  24378. let lb202;
  24379. let lb210;
  24380. let lb211;
  24381. let lb212;
  24382. let lb220;
  24383. let lb221;
  24384. let lb222;
  24385. let m = config.localBasis1;
  24386. lb100 = m.e00;
  24387. lb101 = m.e01;
  24388. lb102 = m.e02;
  24389. lb110 = m.e10;
  24390. lb111 = m.e11;
  24391. lb112 = m.e12;
  24392. lb120 = m.e20;
  24393. lb121 = m.e21;
  24394. lb122 = m.e22;
  24395. let m1 = config.localBasis2;
  24396. lb200 = m1.e00;
  24397. lb201 = m1.e01;
  24398. lb202 = m1.e02;
  24399. lb210 = m1.e10;
  24400. lb211 = m1.e11;
  24401. lb212 = m1.e12;
  24402. lb220 = m1.e20;
  24403. lb221 = m1.e21;
  24404. lb222 = m1.e22;
  24405. this._localBasisX1X = lb100;
  24406. this._localBasisX1Y = lb110;
  24407. this._localBasisX1Z = lb120;
  24408. this._localBasisY1X = lb101;
  24409. this._localBasisY1Y = lb111;
  24410. this._localBasisY1Z = lb121;
  24411. this._localBasisZ1X = lb102;
  24412. this._localBasisZ1Y = lb112;
  24413. this._localBasisZ1Z = lb122;
  24414. this._localBasisX2X = lb200;
  24415. this._localBasisX2Y = lb210;
  24416. this._localBasisX2Z = lb220;
  24417. this._localBasisY2X = lb201;
  24418. this._localBasisY2Y = lb211;
  24419. this._localBasisY2Z = lb221;
  24420. this._localBasisZ2X = lb202;
  24421. this._localBasisZ2Y = lb212;
  24422. this._localBasisZ2Z = lb222;
  24423. this._angleX = 0;
  24424. this._angleY = 0;
  24425. this._angleZ = 0;
  24426. this.translationX = 0;
  24427. this.translationY = 0;
  24428. this.translationZ = 0;
  24429. this.xSingular = false;
  24430. this.ySingular = false;
  24431. this.zSingular = false;
  24432. this._translLms = new Array(3);
  24433. this._translSds = new Array(3);
  24434. this._rotLms = new Array(3);
  24435. this._rotSds = new Array(3);
  24436. this._translLms[0] = config.translationalLimitMotors[0].clone();
  24437. this._translLms[1] = config.translationalLimitMotors[1].clone();
  24438. this._translLms[2] = config.translationalLimitMotors[2].clone();
  24439. this._translSds[0] = config.translationalSpringDampers[0].clone();
  24440. this._translSds[1] = config.translationalSpringDampers[1].clone();
  24441. this._translSds[2] = config.translationalSpringDampers[2].clone();
  24442. this._rotLms[0] = config.rotationalLimitMotors[0].clone();
  24443. this._rotLms[1] = config.rotationalLimitMotors[1].clone();
  24444. this._rotLms[2] = config.rotationalLimitMotors[2].clone();
  24445. this._rotSds[0] = config.rotationalSpringDampers[0].clone();
  24446. this._rotSds[1] = config.rotationalSpringDampers[1].clone();
  24447. this._rotSds[2] = config.rotationalSpringDampers[2].clone();
  24448. }
  24449. getInfo(info,timeStep,isPositionPart) {
  24450. let j;
  24451. let translMotorMass = 1 / (this._b1._invMass + this._b2._invMass);
  24452. let motorMassX = this.computeEffectiveInertiaMoment(this._axisXX,this._axisXY,this._axisXZ);
  24453. let motorMassY = this.computeEffectiveInertiaMoment(this._axisYX,this._axisYY,this._axisYZ);
  24454. let motorMassZ = this.computeEffectiveInertiaMoment(this._axisZX,this._axisZY,this._axisZZ);
  24455. if(this._translSds[0].frequency <= 0 || !isPositionPart) {
  24456. let impulse = this._impulses[0];
  24457. let row = info.rows[info.numRows++];
  24458. let _this = row.jacobian;
  24459. _this.lin1X = 0;
  24460. _this.lin1Y = 0;
  24461. _this.lin1Z = 0;
  24462. _this.lin2X = 0;
  24463. _this.lin2Y = 0;
  24464. _this.lin2Z = 0;
  24465. _this.ang1X = 0;
  24466. _this.ang1Y = 0;
  24467. _this.ang1Z = 0;
  24468. _this.ang2X = 0;
  24469. _this.ang2Y = 0;
  24470. _this.ang2Z = 0;
  24471. row.rhs = 0;
  24472. row.cfm = 0;
  24473. row.minImpulse = 0;
  24474. row.maxImpulse = 0;
  24475. row.motorSpeed = 0;
  24476. row.motorMaxImpulse = 0;
  24477. row.impulse = null;
  24478. row.impulse = impulse;
  24479. this.setSolverInfoRowLinear(row,this.translationX,this._translLms[0],translMotorMass,this._translSds[0],timeStep,isPositionPart);
  24480. j = row.jacobian;
  24481. j.lin1X = this._basisX1X;
  24482. j.lin1Y = this._basisX1Y;
  24483. j.lin1Z = this._basisX1Z;
  24484. j.lin2X = this._basisX1X;
  24485. j.lin2Y = this._basisX1Y;
  24486. j.lin2Z = this._basisX1Z;
  24487. j.ang1X = this._relativeAnchor1Y * this._basisX1Z - this._relativeAnchor1Z * this._basisX1Y;
  24488. j.ang1Y = this._relativeAnchor1Z * this._basisX1X - this._relativeAnchor1X * this._basisX1Z;
  24489. j.ang1Z = this._relativeAnchor1X * this._basisX1Y - this._relativeAnchor1Y * this._basisX1X;
  24490. j.ang2X = this._relativeAnchor2Y * this._basisX1Z - this._relativeAnchor2Z * this._basisX1Y;
  24491. j.ang2Y = this._relativeAnchor2Z * this._basisX1X - this._relativeAnchor2X * this._basisX1Z;
  24492. j.ang2Z = this._relativeAnchor2X * this._basisX1Y - this._relativeAnchor2Y * this._basisX1X;
  24493. }
  24494. if(this._translSds[1].frequency <= 0 || !isPositionPart) {
  24495. let impulse = this._impulses[1];
  24496. let row = info.rows[info.numRows++];
  24497. let _this = row.jacobian;
  24498. _this.lin1X = 0;
  24499. _this.lin1Y = 0;
  24500. _this.lin1Z = 0;
  24501. _this.lin2X = 0;
  24502. _this.lin2Y = 0;
  24503. _this.lin2Z = 0;
  24504. _this.ang1X = 0;
  24505. _this.ang1Y = 0;
  24506. _this.ang1Z = 0;
  24507. _this.ang2X = 0;
  24508. _this.ang2Y = 0;
  24509. _this.ang2Z = 0;
  24510. row.rhs = 0;
  24511. row.cfm = 0;
  24512. row.minImpulse = 0;
  24513. row.maxImpulse = 0;
  24514. row.motorSpeed = 0;
  24515. row.motorMaxImpulse = 0;
  24516. row.impulse = null;
  24517. row.impulse = impulse;
  24518. this.setSolverInfoRowLinear(row,this.translationY,this._translLms[1],translMotorMass,this._translSds[1],timeStep,isPositionPart);
  24519. j = row.jacobian;
  24520. j.lin1X = this._basisY1X;
  24521. j.lin1Y = this._basisY1Y;
  24522. j.lin1Z = this._basisY1Z;
  24523. j.lin2X = this._basisY1X;
  24524. j.lin2Y = this._basisY1Y;
  24525. j.lin2Z = this._basisY1Z;
  24526. j.ang1X = this._relativeAnchor1Y * this._basisY1Z - this._relativeAnchor1Z * this._basisY1Y;
  24527. j.ang1Y = this._relativeAnchor1Z * this._basisY1X - this._relativeAnchor1X * this._basisY1Z;
  24528. j.ang1Z = this._relativeAnchor1X * this._basisY1Y - this._relativeAnchor1Y * this._basisY1X;
  24529. j.ang2X = this._relativeAnchor2Y * this._basisY1Z - this._relativeAnchor2Z * this._basisY1Y;
  24530. j.ang2Y = this._relativeAnchor2Z * this._basisY1X - this._relativeAnchor2X * this._basisY1Z;
  24531. j.ang2Z = this._relativeAnchor2X * this._basisY1Y - this._relativeAnchor2Y * this._basisY1X;
  24532. }
  24533. if(this._translSds[2].frequency <= 0 || !isPositionPart) {
  24534. let impulse = this._impulses[2];
  24535. let row = info.rows[info.numRows++];
  24536. let _this = row.jacobian;
  24537. _this.lin1X = 0;
  24538. _this.lin1Y = 0;
  24539. _this.lin1Z = 0;
  24540. _this.lin2X = 0;
  24541. _this.lin2Y = 0;
  24542. _this.lin2Z = 0;
  24543. _this.ang1X = 0;
  24544. _this.ang1Y = 0;
  24545. _this.ang1Z = 0;
  24546. _this.ang2X = 0;
  24547. _this.ang2Y = 0;
  24548. _this.ang2Z = 0;
  24549. row.rhs = 0;
  24550. row.cfm = 0;
  24551. row.minImpulse = 0;
  24552. row.maxImpulse = 0;
  24553. row.motorSpeed = 0;
  24554. row.motorMaxImpulse = 0;
  24555. row.impulse = null;
  24556. row.impulse = impulse;
  24557. this.setSolverInfoRowLinear(row,this.translationZ,this._translLms[2],translMotorMass,this._translSds[2],timeStep,isPositionPart);
  24558. j = row.jacobian;
  24559. j.lin1X = this._basisZ1X;
  24560. j.lin1Y = this._basisZ1Y;
  24561. j.lin1Z = this._basisZ1Z;
  24562. j.lin2X = this._basisZ1X;
  24563. j.lin2Y = this._basisZ1Y;
  24564. j.lin2Z = this._basisZ1Z;
  24565. j.ang1X = this._relativeAnchor1Y * this._basisZ1Z - this._relativeAnchor1Z * this._basisZ1Y;
  24566. j.ang1Y = this._relativeAnchor1Z * this._basisZ1X - this._relativeAnchor1X * this._basisZ1Z;
  24567. j.ang1Z = this._relativeAnchor1X * this._basisZ1Y - this._relativeAnchor1Y * this._basisZ1X;
  24568. j.ang2X = this._relativeAnchor2Y * this._basisZ1Z - this._relativeAnchor2Z * this._basisZ1Y;
  24569. j.ang2Y = this._relativeAnchor2Z * this._basisZ1X - this._relativeAnchor2X * this._basisZ1Z;
  24570. j.ang2Z = this._relativeAnchor2X * this._basisZ1Y - this._relativeAnchor2Y * this._basisZ1X;
  24571. }
  24572. if(!this.xSingular && (this._rotSds[0].frequency <= 0 || !isPositionPart)) {
  24573. let impulse = this._impulses[3];
  24574. let row = info.rows[info.numRows++];
  24575. let _this = row.jacobian;
  24576. _this.lin1X = 0;
  24577. _this.lin1Y = 0;
  24578. _this.lin1Z = 0;
  24579. _this.lin2X = 0;
  24580. _this.lin2Y = 0;
  24581. _this.lin2Z = 0;
  24582. _this.ang1X = 0;
  24583. _this.ang1Y = 0;
  24584. _this.ang1Z = 0;
  24585. _this.ang2X = 0;
  24586. _this.ang2Y = 0;
  24587. _this.ang2Z = 0;
  24588. row.rhs = 0;
  24589. row.cfm = 0;
  24590. row.minImpulse = 0;
  24591. row.maxImpulse = 0;
  24592. row.motorSpeed = 0;
  24593. row.motorMaxImpulse = 0;
  24594. row.impulse = null;
  24595. row.impulse = impulse;
  24596. this.setSolverInfoRowAngular(row,this._angleX,this._rotLms[0],motorMassX,this._rotSds[0],timeStep,isPositionPart);
  24597. j = row.jacobian;
  24598. j.ang1X = this._axisXX;
  24599. j.ang1Y = this._axisXY;
  24600. j.ang1Z = this._axisXZ;
  24601. j.ang2X = this._axisXX;
  24602. j.ang2Y = this._axisXY;
  24603. j.ang2Z = this._axisXZ;
  24604. }
  24605. if(!this.ySingular && (this._rotSds[1].frequency <= 0 || !isPositionPart)) {
  24606. let impulse = this._impulses[4];
  24607. let row = info.rows[info.numRows++];
  24608. let _this = row.jacobian;
  24609. _this.lin1X = 0;
  24610. _this.lin1Y = 0;
  24611. _this.lin1Z = 0;
  24612. _this.lin2X = 0;
  24613. _this.lin2Y = 0;
  24614. _this.lin2Z = 0;
  24615. _this.ang1X = 0;
  24616. _this.ang1Y = 0;
  24617. _this.ang1Z = 0;
  24618. _this.ang2X = 0;
  24619. _this.ang2Y = 0;
  24620. _this.ang2Z = 0;
  24621. row.rhs = 0;
  24622. row.cfm = 0;
  24623. row.minImpulse = 0;
  24624. row.maxImpulse = 0;
  24625. row.motorSpeed = 0;
  24626. row.motorMaxImpulse = 0;
  24627. row.impulse = null;
  24628. row.impulse = impulse;
  24629. this.setSolverInfoRowAngular(row,this._angleY,this._rotLms[1],motorMassY,this._rotSds[1],timeStep,isPositionPart);
  24630. j = row.jacobian;
  24631. j.ang1X = this._axisYX;
  24632. j.ang1Y = this._axisYY;
  24633. j.ang1Z = this._axisYZ;
  24634. j.ang2X = this._axisYX;
  24635. j.ang2Y = this._axisYY;
  24636. j.ang2Z = this._axisYZ;
  24637. }
  24638. if(!this.zSingular && (this._rotSds[2].frequency <= 0 || !isPositionPart)) {
  24639. let impulse = this._impulses[5];
  24640. let row = info.rows[info.numRows++];
  24641. let _this = row.jacobian;
  24642. _this.lin1X = 0;
  24643. _this.lin1Y = 0;
  24644. _this.lin1Z = 0;
  24645. _this.lin2X = 0;
  24646. _this.lin2Y = 0;
  24647. _this.lin2Z = 0;
  24648. _this.ang1X = 0;
  24649. _this.ang1Y = 0;
  24650. _this.ang1Z = 0;
  24651. _this.ang2X = 0;
  24652. _this.ang2Y = 0;
  24653. _this.ang2Z = 0;
  24654. row.rhs = 0;
  24655. row.cfm = 0;
  24656. row.minImpulse = 0;
  24657. row.maxImpulse = 0;
  24658. row.motorSpeed = 0;
  24659. row.motorMaxImpulse = 0;
  24660. row.impulse = null;
  24661. row.impulse = impulse;
  24662. this.setSolverInfoRowAngular(row,this._angleZ,this._rotLms[2],motorMassZ,this._rotSds[2],timeStep,isPositionPart);
  24663. j = row.jacobian;
  24664. j.ang1X = this._axisZX;
  24665. j.ang1Y = this._axisZY;
  24666. j.ang1Z = this._axisZZ;
  24667. j.ang2X = this._axisZX;
  24668. j.ang2Y = this._axisZY;
  24669. j.ang2Z = this._axisZZ;
  24670. }
  24671. }
  24672. _syncAnchors() {
  24673. super._syncAnchors();
  24674. let angleAxisXX;
  24675. let angleAxisXY;
  24676. let angleAxisXZ;
  24677. let angleAxisYX;
  24678. let angleAxisYY;
  24679. let angleAxisYZ;
  24680. let angleAxisZX;
  24681. let angleAxisZY;
  24682. let angleAxisZZ;
  24683. angleAxisXX = this._basisX1X;
  24684. angleAxisXY = this._basisX1Y;
  24685. angleAxisXZ = this._basisX1Z;
  24686. angleAxisZX = this._basisZ2X;
  24687. angleAxisZY = this._basisZ2Y;
  24688. angleAxisZZ = this._basisZ2Z;
  24689. angleAxisYX = angleAxisZY * angleAxisXZ - angleAxisZZ * angleAxisXY;
  24690. angleAxisYY = angleAxisZZ * angleAxisXX - angleAxisZX * angleAxisXZ;
  24691. angleAxisYZ = angleAxisZX * angleAxisXY - angleAxisZY * angleAxisXX;
  24692. this._axisXX = angleAxisYY * angleAxisZZ - angleAxisYZ * angleAxisZY;
  24693. this._axisXY = angleAxisYZ * angleAxisZX - angleAxisYX * angleAxisZZ;
  24694. this._axisXZ = angleAxisYX * angleAxisZY - angleAxisYY * angleAxisZX;
  24695. this._axisYX = angleAxisYX;
  24696. this._axisYY = angleAxisYY;
  24697. this._axisYZ = angleAxisYZ;
  24698. this._axisZX = angleAxisXY * angleAxisYZ - angleAxisXZ * angleAxisYY;
  24699. this._axisZY = angleAxisXZ * angleAxisYX - angleAxisXX * angleAxisYZ;
  24700. this._axisZZ = angleAxisXX * angleAxisYY - angleAxisXY * angleAxisYX;
  24701. let l = this._axisXX * this._axisXX + this._axisXY * this._axisXY + this._axisXZ * this._axisXZ;
  24702. if(l > 0) {
  24703. l = 1 / Math.sqrt(l);
  24704. }
  24705. this._axisXX *= l;
  24706. this._axisXY *= l;
  24707. this._axisXZ *= l;
  24708. let l1 = this._axisYX * this._axisYX + this._axisYY * this._axisYY + this._axisYZ * this._axisYZ;
  24709. if(l1 > 0) {
  24710. l1 = 1 / Math.sqrt(l1);
  24711. }
  24712. this._axisYX *= l1;
  24713. this._axisYY *= l1;
  24714. this._axisYZ *= l1;
  24715. let l2 = this._axisZX * this._axisZX + this._axisZY * this._axisZY + this._axisZZ * this._axisZZ;
  24716. if(l2 > 0) {
  24717. l2 = 1 / Math.sqrt(l2);
  24718. }
  24719. this._axisZX *= l2;
  24720. this._axisZY *= l2;
  24721. this._axisZZ *= l2;
  24722. this.xSingular = this._axisXX * this._axisXX + this._axisXY * this._axisXY + this._axisXZ * this._axisXZ == 0;
  24723. this.ySingular = this._axisYX * this._axisYX + this._axisYY * this._axisYY + this._axisYZ * this._axisYZ == 0;
  24724. this.zSingular = this._axisZX * this._axisZX + this._axisZY * this._axisZY + this._axisZZ * this._axisZZ == 0;
  24725. let rot100;
  24726. let rot101;
  24727. let rot102;
  24728. let rot110;
  24729. let rot111;
  24730. let rot112;
  24731. let rot120;
  24732. let rot121;
  24733. let rot122;
  24734. let rot200;
  24735. let rot201;
  24736. let rot202;
  24737. let rot210;
  24738. let rot211;
  24739. let rot212;
  24740. let rot220;
  24741. let rot221;
  24742. let rot222;
  24743. rot100 = this._basisX1X;
  24744. rot101 = this._basisY1X;
  24745. rot102 = this._basisZ1X;
  24746. rot110 = this._basisX1Y;
  24747. rot111 = this._basisY1Y;
  24748. rot112 = this._basisZ1Y;
  24749. rot120 = this._basisX1Z;
  24750. rot121 = this._basisY1Z;
  24751. rot122 = this._basisZ1Z;
  24752. rot200 = this._basisX2X;
  24753. rot201 = this._basisY2X;
  24754. rot202 = this._basisZ2X;
  24755. rot210 = this._basisX2Y;
  24756. rot211 = this._basisY2Y;
  24757. rot212 = this._basisZ2Y;
  24758. rot220 = this._basisX2Z;
  24759. rot221 = this._basisY2Z;
  24760. rot222 = this._basisZ2Z;
  24761. let relRot00;
  24762. let relRot01;
  24763. let relRot02;
  24764. let relRot11;
  24765. let relRot12;
  24766. let relRot21;
  24767. let relRot22;
  24768. let __tmp__00;
  24769. let __tmp__01;
  24770. let __tmp__02;
  24771. let __tmp__11;
  24772. let __tmp__12;
  24773. let __tmp__21;
  24774. let __tmp__22;
  24775. __tmp__00 = rot100 * rot200 + rot110 * rot210 + rot120 * rot220;
  24776. __tmp__01 = rot100 * rot201 + rot110 * rot211 + rot120 * rot221;
  24777. __tmp__02 = rot100 * rot202 + rot110 * rot212 + rot120 * rot222;
  24778. __tmp__11 = rot101 * rot201 + rot111 * rot211 + rot121 * rot221;
  24779. __tmp__12 = rot101 * rot202 + rot111 * rot212 + rot121 * rot222;
  24780. __tmp__21 = rot102 * rot201 + rot112 * rot211 + rot122 * rot221;
  24781. __tmp__22 = rot102 * rot202 + rot112 * rot212 + rot122 * rot222;
  24782. relRot00 = __tmp__00;
  24783. relRot01 = __tmp__01;
  24784. relRot02 = __tmp__02;
  24785. relRot11 = __tmp__11;
  24786. relRot12 = __tmp__12;
  24787. relRot21 = __tmp__21;
  24788. relRot22 = __tmp__22;
  24789. let anglesX;
  24790. let anglesY;
  24791. let anglesZ;
  24792. let sy = relRot02;
  24793. if(sy <= -1) {
  24794. let xSubZ = Math.atan2(relRot21,relRot11);
  24795. anglesX = xSubZ * 0.5;
  24796. anglesY = -1.570796326794895;
  24797. anglesZ = -xSubZ * 0.5;
  24798. } else if(sy >= 1) {
  24799. let xAddZ = Math.atan2(relRot21,relRot11);
  24800. anglesX = xAddZ * 0.5;
  24801. anglesY = 1.570796326794895;
  24802. anglesZ = xAddZ * 0.5;
  24803. } else {
  24804. anglesX = Math.atan2(-relRot12,relRot22);
  24805. anglesY = Math.asin(sy);
  24806. anglesZ = Math.atan2(-relRot01,relRot00);
  24807. }
  24808. this._angleX = anglesX;
  24809. this._angleY = anglesY;
  24810. this._angleZ = anglesZ;
  24811. let anchorDiffX;
  24812. let anchorDiffY;
  24813. let anchorDiffZ;
  24814. anchorDiffX = this._anchor2X - this._anchor1X;
  24815. anchorDiffY = this._anchor2Y - this._anchor1Y;
  24816. anchorDiffZ = this._anchor2Z - this._anchor1Z;
  24817. this.translationX = anchorDiffX * this._basisX1X + anchorDiffY * this._basisX1Y + anchorDiffZ * this._basisX1Z;
  24818. this.translationY = anchorDiffX * this._basisY1X + anchorDiffY * this._basisY1Y + anchorDiffZ * this._basisY1Z;
  24819. this.translationZ = anchorDiffX * this._basisZ1X + anchorDiffY * this._basisZ1Y + anchorDiffZ * this._basisZ1Z;
  24820. }
  24821. _getVelocitySolverInfo(timeStep,info) {
  24822. super._getVelocitySolverInfo(timeStep,info);
  24823. this.getInfo(info,timeStep,false);
  24824. }
  24825. _getPositionSolverInfo(info) {
  24826. super._getPositionSolverInfo(info);
  24827. this.getInfo(info,null,true);
  24828. }
  24829. getAxisX() {
  24830. let v = new oimo.common.Vec3();
  24831. v.x = this._basisX1X;
  24832. v.y = this._basisX1Y;
  24833. v.z = this._basisX1Z;
  24834. return v;
  24835. }
  24836. getAxisY() {
  24837. let v = new oimo.common.Vec3();
  24838. v.x = this._axisYX;
  24839. v.y = this._axisYY;
  24840. v.z = this._axisYZ;
  24841. return v;
  24842. }
  24843. getAxisZ() {
  24844. let v = new oimo.common.Vec3();
  24845. v.x = this._basisZ2X;
  24846. v.y = this._basisZ2Y;
  24847. v.z = this._basisZ2Z;
  24848. return v;
  24849. }
  24850. getTranslationalSpringDampers() {
  24851. return this._translSds.slice(0);
  24852. }
  24853. getRotationalSpringDampers() {
  24854. return this._translSds.slice(0);
  24855. }
  24856. getTranslationalLimitMotors() {
  24857. return this._translLms.slice(0);
  24858. }
  24859. getRotationalLimitMotors() {
  24860. return this._rotLms.slice(0);
  24861. }
  24862. getAngles() {
  24863. return new oimo.common.Vec3(this._angleX,this._angleY,this._angleZ);
  24864. }
  24865. getTranslations() {
  24866. return new oimo.common.Vec3(this.translationX,this.translationY,this.translationZ);
  24867. }
  24868. }
  24869. oimo.dynamics.constraint.joint.GenericJointConfig = class oimo_dynamics_constraint_joint_GenericJointConfig extends oimo.dynamics.constraint.joint.JointConfig {
  24870. constructor() {
  24871. super();
  24872. this.localBasis1 = new oimo.common.Mat3();
  24873. this.localBasis2 = new oimo.common.Mat3();
  24874. let _g = [];
  24875. _g.push(new oimo.dynamics.constraint.joint.TranslationalLimitMotor().setLimits(0,0));
  24876. _g.push(new oimo.dynamics.constraint.joint.TranslationalLimitMotor().setLimits(0,0));
  24877. _g.push(new oimo.dynamics.constraint.joint.TranslationalLimitMotor().setLimits(0,0));
  24878. this.translationalLimitMotors = _g;
  24879. let _g1 = [];
  24880. _g1.push(new oimo.dynamics.constraint.joint.RotationalLimitMotor().setLimits(0,0));
  24881. _g1.push(new oimo.dynamics.constraint.joint.RotationalLimitMotor().setLimits(0,0));
  24882. _g1.push(new oimo.dynamics.constraint.joint.RotationalLimitMotor().setLimits(0,0));
  24883. this.rotationalLimitMotors = _g1;
  24884. this.translationalSpringDampers = [new oimo.dynamics.constraint.joint.SpringDamper(),new oimo.dynamics.constraint.joint.SpringDamper(),new oimo.dynamics.constraint.joint.SpringDamper()];
  24885. this.rotationalSpringDampers = [new oimo.dynamics.constraint.joint.SpringDamper(),new oimo.dynamics.constraint.joint.SpringDamper(),new oimo.dynamics.constraint.joint.SpringDamper()];
  24886. }
  24887. init(rigidBody1,rigidBody2,worldAnchor,worldBasis1,worldBasis2) {
  24888. this._init(rigidBody1,rigidBody2,worldAnchor);
  24889. let tf1 = rigidBody1._transform;
  24890. let tf2 = rigidBody2._transform;
  24891. let wb100;
  24892. let wb101;
  24893. let wb102;
  24894. let wb110;
  24895. let wb111;
  24896. let wb112;
  24897. let wb120;
  24898. let wb121;
  24899. let wb122;
  24900. let wb200;
  24901. let wb201;
  24902. let wb202;
  24903. let wb210;
  24904. let wb211;
  24905. let wb212;
  24906. let wb220;
  24907. let wb221;
  24908. let wb222;
  24909. let lb100;
  24910. let lb101;
  24911. let lb102;
  24912. let lb110;
  24913. let lb111;
  24914. let lb112;
  24915. let lb120;
  24916. let lb121;
  24917. let lb122;
  24918. let lb200;
  24919. let lb201;
  24920. let lb202;
  24921. let lb210;
  24922. let lb211;
  24923. let lb212;
  24924. let lb220;
  24925. let lb221;
  24926. let lb222;
  24927. wb100 = worldBasis1.e00;
  24928. wb101 = worldBasis1.e01;
  24929. wb102 = worldBasis1.e02;
  24930. wb110 = worldBasis1.e10;
  24931. wb111 = worldBasis1.e11;
  24932. wb112 = worldBasis1.e12;
  24933. wb120 = worldBasis1.e20;
  24934. wb121 = worldBasis1.e21;
  24935. wb122 = worldBasis1.e22;
  24936. wb200 = worldBasis2.e00;
  24937. wb201 = worldBasis2.e01;
  24938. wb202 = worldBasis2.e02;
  24939. wb210 = worldBasis2.e10;
  24940. wb211 = worldBasis2.e11;
  24941. wb212 = worldBasis2.e12;
  24942. wb220 = worldBasis2.e20;
  24943. wb221 = worldBasis2.e21;
  24944. wb222 = worldBasis2.e22;
  24945. let __tmp__00;
  24946. let __tmp__01;
  24947. let __tmp__02;
  24948. let __tmp__10;
  24949. let __tmp__11;
  24950. let __tmp__12;
  24951. let __tmp__20;
  24952. let __tmp__21;
  24953. let __tmp__22;
  24954. __tmp__00 = tf1._rotation00 * wb100 + tf1._rotation10 * wb110 + tf1._rotation20 * wb120;
  24955. __tmp__01 = tf1._rotation00 * wb101 + tf1._rotation10 * wb111 + tf1._rotation20 * wb121;
  24956. __tmp__02 = tf1._rotation00 * wb102 + tf1._rotation10 * wb112 + tf1._rotation20 * wb122;
  24957. __tmp__10 = tf1._rotation01 * wb100 + tf1._rotation11 * wb110 + tf1._rotation21 * wb120;
  24958. __tmp__11 = tf1._rotation01 * wb101 + tf1._rotation11 * wb111 + tf1._rotation21 * wb121;
  24959. __tmp__12 = tf1._rotation01 * wb102 + tf1._rotation11 * wb112 + tf1._rotation21 * wb122;
  24960. __tmp__20 = tf1._rotation02 * wb100 + tf1._rotation12 * wb110 + tf1._rotation22 * wb120;
  24961. __tmp__21 = tf1._rotation02 * wb101 + tf1._rotation12 * wb111 + tf1._rotation22 * wb121;
  24962. __tmp__22 = tf1._rotation02 * wb102 + tf1._rotation12 * wb112 + tf1._rotation22 * wb122;
  24963. lb100 = __tmp__00;
  24964. lb101 = __tmp__01;
  24965. lb102 = __tmp__02;
  24966. lb110 = __tmp__10;
  24967. lb111 = __tmp__11;
  24968. lb112 = __tmp__12;
  24969. lb120 = __tmp__20;
  24970. lb121 = __tmp__21;
  24971. lb122 = __tmp__22;
  24972. let __tmp__001;
  24973. let __tmp__011;
  24974. let __tmp__021;
  24975. let __tmp__101;
  24976. let __tmp__111;
  24977. let __tmp__121;
  24978. let __tmp__201;
  24979. let __tmp__211;
  24980. let __tmp__221;
  24981. __tmp__001 = tf2._rotation00 * wb200 + tf2._rotation10 * wb210 + tf2._rotation20 * wb220;
  24982. __tmp__011 = tf2._rotation00 * wb201 + tf2._rotation10 * wb211 + tf2._rotation20 * wb221;
  24983. __tmp__021 = tf2._rotation00 * wb202 + tf2._rotation10 * wb212 + tf2._rotation20 * wb222;
  24984. __tmp__101 = tf2._rotation01 * wb200 + tf2._rotation11 * wb210 + tf2._rotation21 * wb220;
  24985. __tmp__111 = tf2._rotation01 * wb201 + tf2._rotation11 * wb211 + tf2._rotation21 * wb221;
  24986. __tmp__121 = tf2._rotation01 * wb202 + tf2._rotation11 * wb212 + tf2._rotation21 * wb222;
  24987. __tmp__201 = tf2._rotation02 * wb200 + tf2._rotation12 * wb210 + tf2._rotation22 * wb220;
  24988. __tmp__211 = tf2._rotation02 * wb201 + tf2._rotation12 * wb211 + tf2._rotation22 * wb221;
  24989. __tmp__221 = tf2._rotation02 * wb202 + tf2._rotation12 * wb212 + tf2._rotation22 * wb222;
  24990. lb200 = __tmp__001;
  24991. lb201 = __tmp__011;
  24992. lb202 = __tmp__021;
  24993. lb210 = __tmp__101;
  24994. lb211 = __tmp__111;
  24995. lb212 = __tmp__121;
  24996. lb220 = __tmp__201;
  24997. lb221 = __tmp__211;
  24998. lb222 = __tmp__221;
  24999. let m = this.localBasis1;
  25000. m.e00 = lb100;
  25001. m.e01 = lb101;
  25002. m.e02 = lb102;
  25003. m.e10 = lb110;
  25004. m.e11 = lb111;
  25005. m.e12 = lb112;
  25006. m.e20 = lb120;
  25007. m.e21 = lb121;
  25008. m.e22 = lb122;
  25009. let m1 = this.localBasis2;
  25010. m1.e00 = lb200;
  25011. m1.e01 = lb201;
  25012. m1.e02 = lb202;
  25013. m1.e10 = lb210;
  25014. m1.e11 = lb211;
  25015. m1.e12 = lb212;
  25016. m1.e20 = lb220;
  25017. m1.e21 = lb221;
  25018. m1.e22 = lb222;
  25019. return this;
  25020. }
  25021. }
  25022. oimo.dynamics.constraint.joint.JointImpulse = class oimo_dynamics_constraint_joint_JointImpulse {
  25023. constructor() {
  25024. this.impulse = 0;
  25025. this.impulseM = 0;
  25026. this.impulseP = 0;
  25027. }
  25028. }
  25029. oimo.dynamics.constraint.joint.JointLink = class oimo_dynamics_constraint_joint_JointLink {
  25030. constructor(joint) {
  25031. this._joint = joint;
  25032. }
  25033. getContact() {
  25034. return this._joint;
  25035. }
  25036. getOther() {
  25037. return this._other;
  25038. }
  25039. getPrev() {
  25040. return this._prev;
  25041. }
  25042. getNext() {
  25043. return this._next;
  25044. }
  25045. }
  25046. oimo.dynamics.constraint.joint.JointMacro = class oimo_dynamics_constraint_joint_JointMacro {
  25047. }
  25048. oimo.dynamics.constraint.joint.JointType = class oimo_dynamics_constraint_joint_JointType {
  25049. }
  25050. oimo.dynamics.constraint.joint.PrismaticJoint = class oimo_dynamics_constraint_joint_PrismaticJoint extends oimo.dynamics.constraint.joint.Joint {
  25051. constructor(config) {
  25052. super(config,oimo.dynamics.constraint.joint.JointType.PRISMATIC);
  25053. let v = config.localAxis1;
  25054. this._localBasisX1X = v.x;
  25055. this._localBasisX1Y = v.y;
  25056. this._localBasisX1Z = v.z;
  25057. let v1 = config.localAxis2;
  25058. this._localBasisX2X = v1.x;
  25059. this._localBasisX2Y = v1.y;
  25060. this._localBasisX2Z = v1.z;
  25061. this.buildLocalBasesFromX();
  25062. this._basis = new oimo.dynamics.constraint.joint.BasisTracker(this);
  25063. this.translation = 0;
  25064. this.linearErrorY = 0;
  25065. this.linearErrorZ = 0;
  25066. this.angularErrorX = 0;
  25067. this.angularErrorY = 0;
  25068. this.angularErrorZ = 0;
  25069. this._sd = config.springDamper.clone();
  25070. this._lm = config.limitMotor.clone();
  25071. }
  25072. getInfo(info,timeStep,isPositionPart) {
  25073. let erp = this.getErp(timeStep,isPositionPart);
  25074. let linRhsY = this.linearErrorY * erp;
  25075. let linRhsZ = this.linearErrorZ * erp;
  25076. let angRhsX = this.angularErrorX * erp;
  25077. let angRhsY = this.angularErrorY * erp;
  25078. let angRhsZ = this.angularErrorZ * erp;
  25079. let j;
  25080. if(this._sd.frequency <= 0 || !isPositionPart) {
  25081. let impulse = this._impulses[0];
  25082. let row = info.rows[info.numRows++];
  25083. let _this = row.jacobian;
  25084. _this.lin1X = 0;
  25085. _this.lin1Y = 0;
  25086. _this.lin1Z = 0;
  25087. _this.lin2X = 0;
  25088. _this.lin2Y = 0;
  25089. _this.lin2Z = 0;
  25090. _this.ang1X = 0;
  25091. _this.ang1Y = 0;
  25092. _this.ang1Z = 0;
  25093. _this.ang2X = 0;
  25094. _this.ang2Y = 0;
  25095. _this.ang2Z = 0;
  25096. row.rhs = 0;
  25097. row.cfm = 0;
  25098. row.minImpulse = 0;
  25099. row.maxImpulse = 0;
  25100. row.motorSpeed = 0;
  25101. row.motorMaxImpulse = 0;
  25102. row.impulse = null;
  25103. row.impulse = impulse;
  25104. this.setSolverInfoRowLinear(row,this.translation,this._lm,1 / (this._b1._invMass + this._b2._invMass),this._sd,timeStep,isPositionPart);
  25105. j = row.jacobian;
  25106. j.lin1X = this._basis.xX;
  25107. j.lin1Y = this._basis.xY;
  25108. j.lin1Z = this._basis.xZ;
  25109. j.lin2X = this._basis.xX;
  25110. j.lin2Y = this._basis.xY;
  25111. j.lin2Z = this._basis.xZ;
  25112. j.ang1X = this._relativeAnchor1Y * this._basis.xZ - this._relativeAnchor1Z * this._basis.xY;
  25113. j.ang1Y = this._relativeAnchor1Z * this._basis.xX - this._relativeAnchor1X * this._basis.xZ;
  25114. j.ang1Z = this._relativeAnchor1X * this._basis.xY - this._relativeAnchor1Y * this._basis.xX;
  25115. j.ang2X = this._relativeAnchor2Y * this._basis.xZ - this._relativeAnchor2Z * this._basis.xY;
  25116. j.ang2Y = this._relativeAnchor2Z * this._basis.xX - this._relativeAnchor2X * this._basis.xZ;
  25117. j.ang2Z = this._relativeAnchor2X * this._basis.xY - this._relativeAnchor2Y * this._basis.xX;
  25118. }
  25119. let impulse = this._impulses[1];
  25120. let row = info.rows[info.numRows++];
  25121. let _this = row.jacobian;
  25122. _this.lin1X = 0;
  25123. _this.lin1Y = 0;
  25124. _this.lin1Z = 0;
  25125. _this.lin2X = 0;
  25126. _this.lin2Y = 0;
  25127. _this.lin2Z = 0;
  25128. _this.ang1X = 0;
  25129. _this.ang1Y = 0;
  25130. _this.ang1Z = 0;
  25131. _this.ang2X = 0;
  25132. _this.ang2Y = 0;
  25133. _this.ang2Z = 0;
  25134. row.rhs = 0;
  25135. row.cfm = 0;
  25136. row.minImpulse = 0;
  25137. row.maxImpulse = 0;
  25138. row.motorSpeed = 0;
  25139. row.motorMaxImpulse = 0;
  25140. row.impulse = null;
  25141. row.impulse = impulse;
  25142. row.rhs = linRhsY;
  25143. row.cfm = 0;
  25144. row.minImpulse = -1e65536;
  25145. row.maxImpulse = 1e65536;
  25146. j = row.jacobian;
  25147. j.lin1X = this._basis.yX;
  25148. j.lin1Y = this._basis.yY;
  25149. j.lin1Z = this._basis.yZ;
  25150. j.lin2X = this._basis.yX;
  25151. j.lin2Y = this._basis.yY;
  25152. j.lin2Z = this._basis.yZ;
  25153. j.ang1X = this._relativeAnchor1Y * this._basis.yZ - this._relativeAnchor1Z * this._basis.yY;
  25154. j.ang1Y = this._relativeAnchor1Z * this._basis.yX - this._relativeAnchor1X * this._basis.yZ;
  25155. j.ang1Z = this._relativeAnchor1X * this._basis.yY - this._relativeAnchor1Y * this._basis.yX;
  25156. j.ang2X = this._relativeAnchor2Y * this._basis.yZ - this._relativeAnchor2Z * this._basis.yY;
  25157. j.ang2Y = this._relativeAnchor2Z * this._basis.yX - this._relativeAnchor2X * this._basis.yZ;
  25158. j.ang2Z = this._relativeAnchor2X * this._basis.yY - this._relativeAnchor2Y * this._basis.yX;
  25159. let impulse1 = this._impulses[2];
  25160. let row1 = info.rows[info.numRows++];
  25161. let _this1 = row1.jacobian;
  25162. _this1.lin1X = 0;
  25163. _this1.lin1Y = 0;
  25164. _this1.lin1Z = 0;
  25165. _this1.lin2X = 0;
  25166. _this1.lin2Y = 0;
  25167. _this1.lin2Z = 0;
  25168. _this1.ang1X = 0;
  25169. _this1.ang1Y = 0;
  25170. _this1.ang1Z = 0;
  25171. _this1.ang2X = 0;
  25172. _this1.ang2Y = 0;
  25173. _this1.ang2Z = 0;
  25174. row1.rhs = 0;
  25175. row1.cfm = 0;
  25176. row1.minImpulse = 0;
  25177. row1.maxImpulse = 0;
  25178. row1.motorSpeed = 0;
  25179. row1.motorMaxImpulse = 0;
  25180. row1.impulse = null;
  25181. row1.impulse = impulse1;
  25182. row1.rhs = linRhsZ;
  25183. row1.cfm = 0;
  25184. row1.minImpulse = -1e65536;
  25185. row1.maxImpulse = 1e65536;
  25186. j = row1.jacobian;
  25187. j.lin1X = this._basis.zX;
  25188. j.lin1Y = this._basis.zY;
  25189. j.lin1Z = this._basis.zZ;
  25190. j.lin2X = this._basis.zX;
  25191. j.lin2Y = this._basis.zY;
  25192. j.lin2Z = this._basis.zZ;
  25193. j.ang1X = this._relativeAnchor1Y * this._basis.zZ - this._relativeAnchor1Z * this._basis.zY;
  25194. j.ang1Y = this._relativeAnchor1Z * this._basis.zX - this._relativeAnchor1X * this._basis.zZ;
  25195. j.ang1Z = this._relativeAnchor1X * this._basis.zY - this._relativeAnchor1Y * this._basis.zX;
  25196. j.ang2X = this._relativeAnchor2Y * this._basis.zZ - this._relativeAnchor2Z * this._basis.zY;
  25197. j.ang2Y = this._relativeAnchor2Z * this._basis.zX - this._relativeAnchor2X * this._basis.zZ;
  25198. j.ang2Z = this._relativeAnchor2X * this._basis.zY - this._relativeAnchor2Y * this._basis.zX;
  25199. let impulse2 = this._impulses[3];
  25200. let row2 = info.rows[info.numRows++];
  25201. let _this2 = row2.jacobian;
  25202. _this2.lin1X = 0;
  25203. _this2.lin1Y = 0;
  25204. _this2.lin1Z = 0;
  25205. _this2.lin2X = 0;
  25206. _this2.lin2Y = 0;
  25207. _this2.lin2Z = 0;
  25208. _this2.ang1X = 0;
  25209. _this2.ang1Y = 0;
  25210. _this2.ang1Z = 0;
  25211. _this2.ang2X = 0;
  25212. _this2.ang2Y = 0;
  25213. _this2.ang2Z = 0;
  25214. row2.rhs = 0;
  25215. row2.cfm = 0;
  25216. row2.minImpulse = 0;
  25217. row2.maxImpulse = 0;
  25218. row2.motorSpeed = 0;
  25219. row2.motorMaxImpulse = 0;
  25220. row2.impulse = null;
  25221. row2.impulse = impulse2;
  25222. row2.rhs = angRhsX;
  25223. row2.cfm = 0;
  25224. row2.minImpulse = -1e65536;
  25225. row2.maxImpulse = 1e65536;
  25226. j = row2.jacobian;
  25227. j.ang1X = 1;
  25228. j.ang1Y = 0;
  25229. j.ang1Z = 0;
  25230. j.ang2X = 1;
  25231. j.ang2Y = 0;
  25232. j.ang2Z = 0;
  25233. let impulse3 = this._impulses[4];
  25234. let row3 = info.rows[info.numRows++];
  25235. let _this3 = row3.jacobian;
  25236. _this3.lin1X = 0;
  25237. _this3.lin1Y = 0;
  25238. _this3.lin1Z = 0;
  25239. _this3.lin2X = 0;
  25240. _this3.lin2Y = 0;
  25241. _this3.lin2Z = 0;
  25242. _this3.ang1X = 0;
  25243. _this3.ang1Y = 0;
  25244. _this3.ang1Z = 0;
  25245. _this3.ang2X = 0;
  25246. _this3.ang2Y = 0;
  25247. _this3.ang2Z = 0;
  25248. row3.rhs = 0;
  25249. row3.cfm = 0;
  25250. row3.minImpulse = 0;
  25251. row3.maxImpulse = 0;
  25252. row3.motorSpeed = 0;
  25253. row3.motorMaxImpulse = 0;
  25254. row3.impulse = null;
  25255. row3.impulse = impulse3;
  25256. row3.rhs = angRhsY;
  25257. row3.cfm = 0;
  25258. row3.minImpulse = -1e65536;
  25259. row3.maxImpulse = 1e65536;
  25260. j = row3.jacobian;
  25261. j.ang1X = 0;
  25262. j.ang1Y = 1;
  25263. j.ang1Z = 0;
  25264. j.ang2X = 0;
  25265. j.ang2Y = 1;
  25266. j.ang2Z = 0;
  25267. let impulse4 = this._impulses[5];
  25268. let row4 = info.rows[info.numRows++];
  25269. let _this4 = row4.jacobian;
  25270. _this4.lin1X = 0;
  25271. _this4.lin1Y = 0;
  25272. _this4.lin1Z = 0;
  25273. _this4.lin2X = 0;
  25274. _this4.lin2Y = 0;
  25275. _this4.lin2Z = 0;
  25276. _this4.ang1X = 0;
  25277. _this4.ang1Y = 0;
  25278. _this4.ang1Z = 0;
  25279. _this4.ang2X = 0;
  25280. _this4.ang2Y = 0;
  25281. _this4.ang2Z = 0;
  25282. row4.rhs = 0;
  25283. row4.cfm = 0;
  25284. row4.minImpulse = 0;
  25285. row4.maxImpulse = 0;
  25286. row4.motorSpeed = 0;
  25287. row4.motorMaxImpulse = 0;
  25288. row4.impulse = null;
  25289. row4.impulse = impulse4;
  25290. row4.rhs = angRhsZ;
  25291. row4.cfm = 0;
  25292. row4.minImpulse = -1e65536;
  25293. row4.maxImpulse = 1e65536;
  25294. j = row4.jacobian;
  25295. j.ang1X = 0;
  25296. j.ang1Y = 0;
  25297. j.ang1Z = 1;
  25298. j.ang2X = 0;
  25299. j.ang2Y = 0;
  25300. j.ang2Z = 1;
  25301. }
  25302. _syncAnchors() {
  25303. super._syncAnchors();
  25304. let _this = this._basis;
  25305. let invM1 = _this.joint._b1._invMass;
  25306. let invM2 = _this.joint._b2._invMass;
  25307. let qX;
  25308. let qY;
  25309. let qZ;
  25310. let qW;
  25311. let idQX;
  25312. let idQY;
  25313. let idQZ;
  25314. let idQW;
  25315. let slerpQX;
  25316. let slerpQY;
  25317. let slerpQZ;
  25318. let slerpQW;
  25319. let slerpM00;
  25320. let slerpM01;
  25321. let slerpM02;
  25322. let slerpM10;
  25323. let slerpM11;
  25324. let slerpM12;
  25325. let slerpM20;
  25326. let slerpM21;
  25327. let slerpM22;
  25328. let newXX;
  25329. let newXY;
  25330. let newXZ;
  25331. let newYX;
  25332. let newYY;
  25333. let newYZ;
  25334. let newZX;
  25335. let newZY;
  25336. let newZZ;
  25337. let prevXX;
  25338. let prevXY;
  25339. let prevXZ;
  25340. let prevYX;
  25341. let prevYY;
  25342. let prevYZ;
  25343. let d = _this.joint._basisX1X * _this.joint._basisX2X + _this.joint._basisX1Y * _this.joint._basisX2Y + _this.joint._basisX1Z * _this.joint._basisX2Z;
  25344. if(d < -0.999999999) {
  25345. let vX;
  25346. let vY;
  25347. let vZ;
  25348. let x1 = _this.joint._basisX1X;
  25349. let y1 = _this.joint._basisX1Y;
  25350. let z1 = _this.joint._basisX1Z;
  25351. let x2 = x1 * x1;
  25352. let y2 = y1 * y1;
  25353. let z2 = z1 * z1;
  25354. let d;
  25355. if(x2 < y2) {
  25356. if(x2 < z2) {
  25357. d = 1 / Math.sqrt(y2 + z2);
  25358. vX = 0;
  25359. vY = z1 * d;
  25360. vZ = -y1 * d;
  25361. } else {
  25362. d = 1 / Math.sqrt(x2 + y2);
  25363. vX = y1 * d;
  25364. vY = -x1 * d;
  25365. vZ = 0;
  25366. }
  25367. } else if(y2 < z2) {
  25368. d = 1 / Math.sqrt(z2 + x2);
  25369. vX = -z1 * d;
  25370. vY = 0;
  25371. vZ = x1 * d;
  25372. } else {
  25373. d = 1 / Math.sqrt(x2 + y2);
  25374. vX = y1 * d;
  25375. vY = -x1 * d;
  25376. vZ = 0;
  25377. }
  25378. qX = vX;
  25379. qY = vY;
  25380. qZ = vZ;
  25381. qW = 0;
  25382. } else {
  25383. let cX;
  25384. let cY;
  25385. let cZ;
  25386. cX = _this.joint._basisX1Y * _this.joint._basisX2Z - _this.joint._basisX1Z * _this.joint._basisX2Y;
  25387. cY = _this.joint._basisX1Z * _this.joint._basisX2X - _this.joint._basisX1X * _this.joint._basisX2Z;
  25388. cZ = _this.joint._basisX1X * _this.joint._basisX2Y - _this.joint._basisX1Y * _this.joint._basisX2X;
  25389. let w = Math.sqrt((1 + d) * 0.5);
  25390. d = 0.5 / w;
  25391. cX *= d;
  25392. cY *= d;
  25393. cZ *= d;
  25394. qX = cX;
  25395. qY = cY;
  25396. qZ = cZ;
  25397. qW = w;
  25398. }
  25399. idQX = 0;
  25400. idQY = 0;
  25401. idQZ = 0;
  25402. idQW = 1;
  25403. let q1X;
  25404. let q1Y;
  25405. let q1Z;
  25406. let q1W;
  25407. let q2X;
  25408. let q2Y;
  25409. let q2Z;
  25410. let q2W;
  25411. q1X = idQX;
  25412. q1Y = idQY;
  25413. q1Z = idQZ;
  25414. q1W = idQW;
  25415. q2X = qX;
  25416. q2Y = qY;
  25417. q2Z = qZ;
  25418. q2W = qW;
  25419. let d1 = q1X * q2X + q1Y * q2Y + q1Z * q2Z + q1W * q2W;
  25420. if(d1 < 0) {
  25421. d1 = -d1;
  25422. q2X = -q2X;
  25423. q2Y = -q2Y;
  25424. q2Z = -q2Z;
  25425. q2W = -q2W;
  25426. }
  25427. if(d1 > 0.999999) {
  25428. let dqX;
  25429. let dqY;
  25430. let dqZ;
  25431. let dqW;
  25432. dqX = q2X - q1X;
  25433. dqY = q2Y - q1Y;
  25434. dqZ = q2Z - q1Z;
  25435. dqW = q2W - q1W;
  25436. q2X = q1X + dqX * (invM1 / (invM1 + invM2));
  25437. q2Y = q1Y + dqY * (invM1 / (invM1 + invM2));
  25438. q2Z = q1Z + dqZ * (invM1 / (invM1 + invM2));
  25439. q2W = q1W + dqW * (invM1 / (invM1 + invM2));
  25440. let l = q2X * q2X + q2Y * q2Y + q2Z * q2Z + q2W * q2W;
  25441. if(l > 1e-32) {
  25442. l = 1 / Math.sqrt(l);
  25443. }
  25444. slerpQX = q2X * l;
  25445. slerpQY = q2Y * l;
  25446. slerpQZ = q2Z * l;
  25447. slerpQW = q2W * l;
  25448. } else {
  25449. let theta = invM1 / (invM1 + invM2) * Math.acos(d1);
  25450. q2X += q1X * -d1;
  25451. q2Y += q1Y * -d1;
  25452. q2Z += q1Z * -d1;
  25453. q2W += q1W * -d1;
  25454. let l = q2X * q2X + q2Y * q2Y + q2Z * q2Z + q2W * q2W;
  25455. if(l > 1e-32) {
  25456. l = 1 / Math.sqrt(l);
  25457. }
  25458. q2X *= l;
  25459. q2Y *= l;
  25460. q2Z *= l;
  25461. q2W *= l;
  25462. let sin = Math.sin(theta);
  25463. let cos = Math.cos(theta);
  25464. q1X *= cos;
  25465. q1Y *= cos;
  25466. q1Z *= cos;
  25467. q1W *= cos;
  25468. slerpQX = q1X + q2X * sin;
  25469. slerpQY = q1Y + q2Y * sin;
  25470. slerpQZ = q1Z + q2Z * sin;
  25471. slerpQW = q1W + q2W * sin;
  25472. }
  25473. let x = slerpQX;
  25474. let y = slerpQY;
  25475. let z = slerpQZ;
  25476. let w = slerpQW;
  25477. let x2 = 2 * x;
  25478. let y2 = 2 * y;
  25479. let z2 = 2 * z;
  25480. let xx = x * x2;
  25481. let yy = y * y2;
  25482. let zz = z * z2;
  25483. let xy = x * y2;
  25484. let yz = y * z2;
  25485. let xz = x * z2;
  25486. let wx = w * x2;
  25487. let wy = w * y2;
  25488. let wz = w * z2;
  25489. slerpM00 = 1 - yy - zz;
  25490. slerpM01 = xy - wz;
  25491. slerpM02 = xz + wy;
  25492. slerpM10 = xy + wz;
  25493. slerpM11 = 1 - xx - zz;
  25494. slerpM12 = yz - wx;
  25495. slerpM20 = xz - wy;
  25496. slerpM21 = yz + wx;
  25497. slerpM22 = 1 - xx - yy;
  25498. let __tmp__X;
  25499. let __tmp__Y;
  25500. let __tmp__Z;
  25501. __tmp__X = slerpM00 * _this.joint._basisX1X + slerpM01 * _this.joint._basisX1Y + slerpM02 * _this.joint._basisX1Z;
  25502. __tmp__Y = slerpM10 * _this.joint._basisX1X + slerpM11 * _this.joint._basisX1Y + slerpM12 * _this.joint._basisX1Z;
  25503. __tmp__Z = slerpM20 * _this.joint._basisX1X + slerpM21 * _this.joint._basisX1Y + slerpM22 * _this.joint._basisX1Z;
  25504. newXX = __tmp__X;
  25505. newXY = __tmp__Y;
  25506. newXZ = __tmp__Z;
  25507. prevXX = _this.xX;
  25508. prevXY = _this.xY;
  25509. prevXZ = _this.xZ;
  25510. prevYX = _this.yX;
  25511. prevYY = _this.yY;
  25512. prevYZ = _this.yZ;
  25513. let d2 = prevXX * newXX + prevXY * newXY + prevXZ * newXZ;
  25514. if(d2 < -0.999999999) {
  25515. let vX;
  25516. let vY;
  25517. let vZ;
  25518. let x1 = prevXX;
  25519. let y1 = prevXY;
  25520. let z1 = prevXZ;
  25521. let x2 = x1 * x1;
  25522. let y2 = y1 * y1;
  25523. let z2 = z1 * z1;
  25524. let d;
  25525. if(x2 < y2) {
  25526. if(x2 < z2) {
  25527. d = 1 / Math.sqrt(y2 + z2);
  25528. vX = 0;
  25529. vY = z1 * d;
  25530. vZ = -y1 * d;
  25531. } else {
  25532. d = 1 / Math.sqrt(x2 + y2);
  25533. vX = y1 * d;
  25534. vY = -x1 * d;
  25535. vZ = 0;
  25536. }
  25537. } else if(y2 < z2) {
  25538. d = 1 / Math.sqrt(z2 + x2);
  25539. vX = -z1 * d;
  25540. vY = 0;
  25541. vZ = x1 * d;
  25542. } else {
  25543. d = 1 / Math.sqrt(x2 + y2);
  25544. vX = y1 * d;
  25545. vY = -x1 * d;
  25546. vZ = 0;
  25547. }
  25548. slerpQX = vX;
  25549. slerpQY = vY;
  25550. slerpQZ = vZ;
  25551. slerpQW = 0;
  25552. } else {
  25553. let cX;
  25554. let cY;
  25555. let cZ;
  25556. cX = prevXY * newXZ - prevXZ * newXY;
  25557. cY = prevXZ * newXX - prevXX * newXZ;
  25558. cZ = prevXX * newXY - prevXY * newXX;
  25559. let w = Math.sqrt((1 + d2) * 0.5);
  25560. d2 = 0.5 / w;
  25561. cX *= d2;
  25562. cY *= d2;
  25563. cZ *= d2;
  25564. slerpQX = cX;
  25565. slerpQY = cY;
  25566. slerpQZ = cZ;
  25567. slerpQW = w;
  25568. }
  25569. let x1 = slerpQX;
  25570. let y1 = slerpQY;
  25571. let z1 = slerpQZ;
  25572. let w1 = slerpQW;
  25573. let x21 = 2 * x1;
  25574. let y21 = 2 * y1;
  25575. let z21 = 2 * z1;
  25576. let xx1 = x1 * x21;
  25577. let yy1 = y1 * y21;
  25578. let zz1 = z1 * z21;
  25579. let xy1 = x1 * y21;
  25580. let yz1 = y1 * z21;
  25581. let xz1 = x1 * z21;
  25582. let wx1 = w1 * x21;
  25583. let wy1 = w1 * y21;
  25584. let wz1 = w1 * z21;
  25585. slerpM00 = 1 - yy1 - zz1;
  25586. slerpM01 = xy1 - wz1;
  25587. slerpM02 = xz1 + wy1;
  25588. slerpM10 = xy1 + wz1;
  25589. slerpM11 = 1 - xx1 - zz1;
  25590. slerpM12 = yz1 - wx1;
  25591. slerpM20 = xz1 - wy1;
  25592. slerpM21 = yz1 + wx1;
  25593. slerpM22 = 1 - xx1 - yy1;
  25594. let __tmp__X1;
  25595. let __tmp__Y1;
  25596. let __tmp__Z1;
  25597. __tmp__X1 = slerpM00 * prevYX + slerpM01 * prevYY + slerpM02 * prevYZ;
  25598. __tmp__Y1 = slerpM10 * prevYX + slerpM11 * prevYY + slerpM12 * prevYZ;
  25599. __tmp__Z1 = slerpM20 * prevYX + slerpM21 * prevYY + slerpM22 * prevYZ;
  25600. newYX = __tmp__X1;
  25601. newYY = __tmp__Y1;
  25602. newYZ = __tmp__Z1;
  25603. newZX = newXY * newYZ - newXZ * newYY;
  25604. newZY = newXZ * newYX - newXX * newYZ;
  25605. newZZ = newXX * newYY - newXY * newYX;
  25606. if(newZX * newZX + newZY * newZY + newZZ * newZZ > 1e-6) {
  25607. let l = newZX * newZX + newZY * newZY + newZZ * newZZ;
  25608. if(l > 0) {
  25609. l = 1 / Math.sqrt(l);
  25610. }
  25611. newZX *= l;
  25612. newZY *= l;
  25613. newZZ *= l;
  25614. } else {
  25615. let x1 = newXX;
  25616. let y1 = newXY;
  25617. let z1 = newXZ;
  25618. let x2 = x1 * x1;
  25619. let y2 = y1 * y1;
  25620. let z2 = z1 * z1;
  25621. let d;
  25622. if(x2 < y2) {
  25623. if(x2 < z2) {
  25624. d = 1 / Math.sqrt(y2 + z2);
  25625. newZX = 0;
  25626. newZY = z1 * d;
  25627. newZZ = -y1 * d;
  25628. } else {
  25629. d = 1 / Math.sqrt(x2 + y2);
  25630. newZX = y1 * d;
  25631. newZY = -x1 * d;
  25632. newZZ = 0;
  25633. }
  25634. } else if(y2 < z2) {
  25635. d = 1 / Math.sqrt(z2 + x2);
  25636. newZX = -z1 * d;
  25637. newZY = 0;
  25638. newZZ = x1 * d;
  25639. } else {
  25640. d = 1 / Math.sqrt(x2 + y2);
  25641. newZX = y1 * d;
  25642. newZY = -x1 * d;
  25643. newZZ = 0;
  25644. }
  25645. }
  25646. newYX = newZY * newXZ - newZZ * newXY;
  25647. newYY = newZZ * newXX - newZX * newXZ;
  25648. newYZ = newZX * newXY - newZY * newXX;
  25649. _this.xX = newXX;
  25650. _this.xY = newXY;
  25651. _this.xZ = newXZ;
  25652. _this.yX = newYX;
  25653. _this.yY = newYY;
  25654. _this.yZ = newYZ;
  25655. _this.zX = newZX;
  25656. _this.zY = newZY;
  25657. _this.zZ = newZZ;
  25658. let rot100;
  25659. let rot101;
  25660. let rot102;
  25661. let rot110;
  25662. let rot111;
  25663. let rot112;
  25664. let rot120;
  25665. let rot121;
  25666. let rot122;
  25667. let rot200;
  25668. let rot201;
  25669. let rot202;
  25670. let rot210;
  25671. let rot211;
  25672. let rot212;
  25673. let rot220;
  25674. let rot221;
  25675. let rot222;
  25676. rot100 = this._basisX1X;
  25677. rot101 = this._basisY1X;
  25678. rot102 = this._basisZ1X;
  25679. rot110 = this._basisX1Y;
  25680. rot111 = this._basisY1Y;
  25681. rot112 = this._basisZ1Y;
  25682. rot120 = this._basisX1Z;
  25683. rot121 = this._basisY1Z;
  25684. rot122 = this._basisZ1Z;
  25685. rot200 = this._basisX2X;
  25686. rot201 = this._basisY2X;
  25687. rot202 = this._basisZ2X;
  25688. rot210 = this._basisX2Y;
  25689. rot211 = this._basisY2Y;
  25690. rot212 = this._basisZ2Y;
  25691. rot220 = this._basisX2Z;
  25692. rot221 = this._basisY2Z;
  25693. rot222 = this._basisZ2Z;
  25694. let relRot00;
  25695. let relRot01;
  25696. let relRot02;
  25697. let relRot10;
  25698. let relRot11;
  25699. let relRot12;
  25700. let relRot20;
  25701. let relRot21;
  25702. let relRot22;
  25703. let __tmp__00;
  25704. let __tmp__01;
  25705. let __tmp__02;
  25706. let __tmp__10;
  25707. let __tmp__11;
  25708. let __tmp__12;
  25709. let __tmp__20;
  25710. let __tmp__21;
  25711. let __tmp__22;
  25712. __tmp__00 = rot200 * rot100 + rot201 * rot101 + rot202 * rot102;
  25713. __tmp__01 = rot200 * rot110 + rot201 * rot111 + rot202 * rot112;
  25714. __tmp__02 = rot200 * rot120 + rot201 * rot121 + rot202 * rot122;
  25715. __tmp__10 = rot210 * rot100 + rot211 * rot101 + rot212 * rot102;
  25716. __tmp__11 = rot210 * rot110 + rot211 * rot111 + rot212 * rot112;
  25717. __tmp__12 = rot210 * rot120 + rot211 * rot121 + rot212 * rot122;
  25718. __tmp__20 = rot220 * rot100 + rot221 * rot101 + rot222 * rot102;
  25719. __tmp__21 = rot220 * rot110 + rot221 * rot111 + rot222 * rot112;
  25720. __tmp__22 = rot220 * rot120 + rot221 * rot121 + rot222 * rot122;
  25721. relRot00 = __tmp__00;
  25722. relRot01 = __tmp__01;
  25723. relRot02 = __tmp__02;
  25724. relRot10 = __tmp__10;
  25725. relRot11 = __tmp__11;
  25726. relRot12 = __tmp__12;
  25727. relRot20 = __tmp__20;
  25728. relRot21 = __tmp__21;
  25729. relRot22 = __tmp__22;
  25730. let relQX;
  25731. let relQY;
  25732. let relQZ;
  25733. let relQW;
  25734. let e00 = relRot00;
  25735. let e11 = relRot11;
  25736. let e22 = relRot22;
  25737. let t = e00 + e11 + e22;
  25738. let s;
  25739. if(t > 0) {
  25740. s = Math.sqrt(t + 1);
  25741. relQW = 0.5 * s;
  25742. s = 0.5 / s;
  25743. relQX = (relRot21 - relRot12) * s;
  25744. relQY = (relRot02 - relRot20) * s;
  25745. relQZ = (relRot10 - relRot01) * s;
  25746. } else if(e00 > e11) {
  25747. if(e00 > e22) {
  25748. s = Math.sqrt(e00 - e11 - e22 + 1);
  25749. relQX = 0.5 * s;
  25750. s = 0.5 / s;
  25751. relQY = (relRot01 + relRot10) * s;
  25752. relQZ = (relRot02 + relRot20) * s;
  25753. relQW = (relRot21 - relRot12) * s;
  25754. } else {
  25755. s = Math.sqrt(e22 - e00 - e11 + 1);
  25756. relQZ = 0.5 * s;
  25757. s = 0.5 / s;
  25758. relQX = (relRot02 + relRot20) * s;
  25759. relQY = (relRot12 + relRot21) * s;
  25760. relQW = (relRot10 - relRot01) * s;
  25761. }
  25762. } else if(e11 > e22) {
  25763. s = Math.sqrt(e11 - e22 - e00 + 1);
  25764. relQY = 0.5 * s;
  25765. s = 0.5 / s;
  25766. relQX = (relRot01 + relRot10) * s;
  25767. relQZ = (relRot12 + relRot21) * s;
  25768. relQW = (relRot02 - relRot20) * s;
  25769. } else {
  25770. s = Math.sqrt(e22 - e00 - e11 + 1);
  25771. relQZ = 0.5 * s;
  25772. s = 0.5 / s;
  25773. relQX = (relRot02 + relRot20) * s;
  25774. relQY = (relRot12 + relRot21) * s;
  25775. relQW = (relRot10 - relRot01) * s;
  25776. }
  25777. let cosHalfTheta = relQW;
  25778. let theta = (cosHalfTheta <= -1 ? 3.14159265358979 : cosHalfTheta >= 1 ? 0 : Math.acos(cosHalfTheta)) * 2;
  25779. this.angularErrorX = relQX;
  25780. this.angularErrorY = relQY;
  25781. this.angularErrorZ = relQZ;
  25782. let l = this.angularErrorX * this.angularErrorX + this.angularErrorY * this.angularErrorY + this.angularErrorZ * this.angularErrorZ;
  25783. if(l > 0) {
  25784. l = 1 / Math.sqrt(l);
  25785. }
  25786. this.angularErrorX *= l;
  25787. this.angularErrorY *= l;
  25788. this.angularErrorZ *= l;
  25789. this.angularErrorX *= theta;
  25790. this.angularErrorY *= theta;
  25791. this.angularErrorZ *= theta;
  25792. let anchorDiffX;
  25793. let anchorDiffY;
  25794. let anchorDiffZ;
  25795. anchorDiffX = this._anchor2X - this._anchor1X;
  25796. anchorDiffY = this._anchor2Y - this._anchor1Y;
  25797. anchorDiffZ = this._anchor2Z - this._anchor1Z;
  25798. this.translation = anchorDiffX * this._basis.xX + anchorDiffY * this._basis.xY + anchorDiffZ * this._basis.xZ;
  25799. this.linearErrorY = anchorDiffX * this._basis.yX + anchorDiffY * this._basis.yY + anchorDiffZ * this._basis.yZ;
  25800. this.linearErrorZ = anchorDiffX * this._basis.zX + anchorDiffY * this._basis.zY + anchorDiffZ * this._basis.zZ;
  25801. }
  25802. _getVelocitySolverInfo(timeStep,info) {
  25803. super._getVelocitySolverInfo(timeStep,info);
  25804. this.getInfo(info,timeStep,false);
  25805. }
  25806. _getPositionSolverInfo(info) {
  25807. super._getPositionSolverInfo(info);
  25808. this.getInfo(info,null,true);
  25809. }
  25810. getAxis1() {
  25811. let v = new oimo.common.Vec3();
  25812. v.x = this._basisX1X;
  25813. v.y = this._basisX1Y;
  25814. v.z = this._basisX1Z;
  25815. return v;
  25816. }
  25817. getAxis2() {
  25818. let v = new oimo.common.Vec3();
  25819. v.x = this._basisX2X;
  25820. v.y = this._basisX2Y;
  25821. v.z = this._basisX2Z;
  25822. return v;
  25823. }
  25824. getAxis1To(axis) {
  25825. axis.x = this._basisX1X;
  25826. axis.y = this._basisX1Y;
  25827. axis.z = this._basisX1Z;
  25828. }
  25829. getAxis2To(axis) {
  25830. axis.x = this._basisX2X;
  25831. axis.y = this._basisX2Y;
  25832. axis.z = this._basisX2Z;
  25833. }
  25834. getLocalAxis1() {
  25835. let v = new oimo.common.Vec3();
  25836. v.x = this._localBasisX1X;
  25837. v.y = this._localBasisX1Y;
  25838. v.z = this._localBasisX1Z;
  25839. return v;
  25840. }
  25841. getLocalAxis2() {
  25842. let v = new oimo.common.Vec3();
  25843. v.x = this._localBasisX2X;
  25844. v.y = this._localBasisX2Y;
  25845. v.z = this._localBasisX2Z;
  25846. return v;
  25847. }
  25848. getLocalAxis1To(axis) {
  25849. axis.x = this._localBasisX1X;
  25850. axis.y = this._localBasisX1Y;
  25851. axis.z = this._localBasisX1Z;
  25852. }
  25853. getLocalAxis2To(axis) {
  25854. axis.x = this._localBasisX2X;
  25855. axis.y = this._localBasisX2Y;
  25856. axis.z = this._localBasisX2Z;
  25857. }
  25858. getSpringDamper() {
  25859. return this._sd;
  25860. }
  25861. getLimitMotor() {
  25862. return this._lm;
  25863. }
  25864. getTranslation() {
  25865. return this.translation;
  25866. }
  25867. }
  25868. oimo.dynamics.constraint.joint.PrismaticJointConfig = class oimo_dynamics_constraint_joint_PrismaticJointConfig extends oimo.dynamics.constraint.joint.JointConfig {
  25869. constructor() {
  25870. super();
  25871. this.localAxis1 = new oimo.common.Vec3(1,0,0);
  25872. this.localAxis2 = new oimo.common.Vec3(1,0,0);
  25873. this.limitMotor = new oimo.dynamics.constraint.joint.TranslationalLimitMotor();
  25874. this.springDamper = new oimo.dynamics.constraint.joint.SpringDamper();
  25875. }
  25876. init(rigidBody1,rigidBody2,worldAnchor,worldAxis) {
  25877. this._init(rigidBody1,rigidBody2,worldAnchor);
  25878. let localVector = this.localAxis1;
  25879. let vX;
  25880. let vY;
  25881. let vZ;
  25882. vX = worldAxis.x;
  25883. vY = worldAxis.y;
  25884. vZ = worldAxis.z;
  25885. let __tmp__X;
  25886. let __tmp__Y;
  25887. let __tmp__Z;
  25888. __tmp__X = rigidBody1._transform._rotation00 * vX + rigidBody1._transform._rotation10 * vY + rigidBody1._transform._rotation20 * vZ;
  25889. __tmp__Y = rigidBody1._transform._rotation01 * vX + rigidBody1._transform._rotation11 * vY + rigidBody1._transform._rotation21 * vZ;
  25890. __tmp__Z = rigidBody1._transform._rotation02 * vX + rigidBody1._transform._rotation12 * vY + rigidBody1._transform._rotation22 * vZ;
  25891. vX = __tmp__X;
  25892. vY = __tmp__Y;
  25893. vZ = __tmp__Z;
  25894. localVector.x = vX;
  25895. localVector.y = vY;
  25896. localVector.z = vZ;
  25897. let localVector1 = this.localAxis2;
  25898. let vX1;
  25899. let vY1;
  25900. let vZ1;
  25901. vX1 = worldAxis.x;
  25902. vY1 = worldAxis.y;
  25903. vZ1 = worldAxis.z;
  25904. let __tmp__X1;
  25905. let __tmp__Y1;
  25906. let __tmp__Z1;
  25907. __tmp__X1 = rigidBody2._transform._rotation00 * vX1 + rigidBody2._transform._rotation10 * vY1 + rigidBody2._transform._rotation20 * vZ1;
  25908. __tmp__Y1 = rigidBody2._transform._rotation01 * vX1 + rigidBody2._transform._rotation11 * vY1 + rigidBody2._transform._rotation21 * vZ1;
  25909. __tmp__Z1 = rigidBody2._transform._rotation02 * vX1 + rigidBody2._transform._rotation12 * vY1 + rigidBody2._transform._rotation22 * vZ1;
  25910. vX1 = __tmp__X1;
  25911. vY1 = __tmp__Y1;
  25912. vZ1 = __tmp__Z1;
  25913. localVector1.x = vX1;
  25914. localVector1.y = vY1;
  25915. localVector1.z = vZ1;
  25916. return this;
  25917. }
  25918. }
  25919. oimo.dynamics.constraint.joint.RagdollJoint = class oimo_dynamics_constraint_joint_RagdollJoint extends oimo.dynamics.constraint.joint.Joint {
  25920. constructor(config) {
  25921. super(config,oimo.dynamics.constraint.joint.JointType.RAGDOLL);
  25922. let v = config.localTwistAxis1;
  25923. this._localBasisX1X = v.x;
  25924. this._localBasisX1Y = v.y;
  25925. this._localBasisX1Z = v.z;
  25926. let v1 = config.localSwingAxis1;
  25927. this._localBasisY1X = v1.x;
  25928. this._localBasisY1Y = v1.y;
  25929. this._localBasisY1Z = v1.z;
  25930. let v2 = config.localTwistAxis2;
  25931. this._localBasisX2X = v2.x;
  25932. this._localBasisX2Y = v2.y;
  25933. this._localBasisX2Z = v2.z;
  25934. this.buildLocalBasesFromXY1X2();
  25935. this._twistSd = config.twistSpringDamper.clone();
  25936. this._twistLm = config.twistLimitMotor.clone();
  25937. this._swingSd = config.swingSpringDamper.clone();
  25938. this._maxSwingAngle1 = config.maxSwingAngle1;
  25939. this._maxSwingAngle2 = config.maxSwingAngle2;
  25940. if(this._maxSwingAngle1 < oimo.common.Setting.minRagdollMaxSwingAngle) {
  25941. this._maxSwingAngle1 = oimo.common.Setting.minRagdollMaxSwingAngle;
  25942. }
  25943. if(this._maxSwingAngle2 < oimo.common.Setting.minRagdollMaxSwingAngle) {
  25944. this._maxSwingAngle2 = oimo.common.Setting.minRagdollMaxSwingAngle;
  25945. }
  25946. this.dummySwingLm = new oimo.dynamics.constraint.joint.RotationalLimitMotor();
  25947. this.dummySwingLm.lowerLimit = -1;
  25948. this.dummySwingLm.upperLimit = 0;
  25949. this._swingAngle = 0;
  25950. this._twistAngle = 0;
  25951. this.swingError = 0;
  25952. this.swingAxisX = 0;
  25953. this.swingAxisY = 0;
  25954. this.swingAxisZ = 0;
  25955. this.twistAxisX = 0;
  25956. this.twistAxisY = 0;
  25957. this.twistAxisZ = 0;
  25958. }
  25959. getInfo(info,timeStep,isPositionPart) {
  25960. let erp = this.getErp(timeStep,isPositionPart);
  25961. let linearRhsX;
  25962. let linearRhsY;
  25963. let linearRhsZ;
  25964. linearRhsX = this.linearErrorX * erp;
  25965. linearRhsY = this.linearErrorY * erp;
  25966. linearRhsZ = this.linearErrorZ * erp;
  25967. let crossR100;
  25968. let crossR101;
  25969. let crossR102;
  25970. let crossR110;
  25971. let crossR111;
  25972. let crossR112;
  25973. let crossR120;
  25974. let crossR121;
  25975. let crossR122;
  25976. let crossR200;
  25977. let crossR201;
  25978. let crossR202;
  25979. let crossR210;
  25980. let crossR211;
  25981. let crossR212;
  25982. let crossR220;
  25983. let crossR221;
  25984. let crossR222;
  25985. crossR100 = 0;
  25986. crossR101 = -this._relativeAnchor1Z;
  25987. crossR102 = this._relativeAnchor1Y;
  25988. crossR110 = this._relativeAnchor1Z;
  25989. crossR111 = 0;
  25990. crossR112 = -this._relativeAnchor1X;
  25991. crossR120 = -this._relativeAnchor1Y;
  25992. crossR121 = this._relativeAnchor1X;
  25993. crossR122 = 0;
  25994. crossR200 = 0;
  25995. crossR201 = -this._relativeAnchor2Z;
  25996. crossR202 = this._relativeAnchor2Y;
  25997. crossR210 = this._relativeAnchor2Z;
  25998. crossR211 = 0;
  25999. crossR212 = -this._relativeAnchor2X;
  26000. crossR220 = -this._relativeAnchor2Y;
  26001. crossR221 = this._relativeAnchor2X;
  26002. crossR222 = 0;
  26003. crossR100 = -crossR100;
  26004. crossR101 = -crossR101;
  26005. crossR102 = -crossR102;
  26006. crossR110 = -crossR110;
  26007. crossR111 = -crossR111;
  26008. crossR112 = -crossR112;
  26009. crossR120 = -crossR120;
  26010. crossR121 = -crossR121;
  26011. crossR122 = -crossR122;
  26012. crossR200 = -crossR200;
  26013. crossR201 = -crossR201;
  26014. crossR202 = -crossR202;
  26015. crossR210 = -crossR210;
  26016. crossR211 = -crossR211;
  26017. crossR212 = -crossR212;
  26018. crossR220 = -crossR220;
  26019. crossR221 = -crossR221;
  26020. crossR222 = -crossR222;
  26021. let swingMass = this.computeEffectiveInertiaMoment(this.swingAxisX,this.swingAxisY,this.swingAxisZ);
  26022. let twistMass = this.computeEffectiveInertiaMoment(this._basisX2X,this._basisX2Y,this._basisX2Z);
  26023. let impulse = this._impulses[0];
  26024. let row = info.rows[info.numRows++];
  26025. let _this = row.jacobian;
  26026. _this.lin1X = 0;
  26027. _this.lin1Y = 0;
  26028. _this.lin1Z = 0;
  26029. _this.lin2X = 0;
  26030. _this.lin2Y = 0;
  26031. _this.lin2Z = 0;
  26032. _this.ang1X = 0;
  26033. _this.ang1Y = 0;
  26034. _this.ang1Z = 0;
  26035. _this.ang2X = 0;
  26036. _this.ang2Y = 0;
  26037. _this.ang2Z = 0;
  26038. row.rhs = 0;
  26039. row.cfm = 0;
  26040. row.minImpulse = 0;
  26041. row.maxImpulse = 0;
  26042. row.motorSpeed = 0;
  26043. row.motorMaxImpulse = 0;
  26044. row.impulse = null;
  26045. row.impulse = impulse;
  26046. row.rhs = linearRhsX;
  26047. row.cfm = 0;
  26048. row.minImpulse = -1e65536;
  26049. row.maxImpulse = 1e65536;
  26050. let j = row.jacobian;
  26051. j.lin1X = 1;
  26052. j.lin1Y = 0;
  26053. j.lin1Z = 0;
  26054. j.lin2X = 1;
  26055. j.lin2Y = 0;
  26056. j.lin2Z = 0;
  26057. j.ang1X = crossR100;
  26058. j.ang1Y = crossR101;
  26059. j.ang1Z = crossR102;
  26060. j.ang2X = crossR200;
  26061. j.ang2Y = crossR201;
  26062. j.ang2Z = crossR202;
  26063. let impulse1 = this._impulses[1];
  26064. let row1 = info.rows[info.numRows++];
  26065. let _this1 = row1.jacobian;
  26066. _this1.lin1X = 0;
  26067. _this1.lin1Y = 0;
  26068. _this1.lin1Z = 0;
  26069. _this1.lin2X = 0;
  26070. _this1.lin2Y = 0;
  26071. _this1.lin2Z = 0;
  26072. _this1.ang1X = 0;
  26073. _this1.ang1Y = 0;
  26074. _this1.ang1Z = 0;
  26075. _this1.ang2X = 0;
  26076. _this1.ang2Y = 0;
  26077. _this1.ang2Z = 0;
  26078. row1.rhs = 0;
  26079. row1.cfm = 0;
  26080. row1.minImpulse = 0;
  26081. row1.maxImpulse = 0;
  26082. row1.motorSpeed = 0;
  26083. row1.motorMaxImpulse = 0;
  26084. row1.impulse = null;
  26085. row1.impulse = impulse1;
  26086. row1.rhs = linearRhsY;
  26087. row1.cfm = 0;
  26088. row1.minImpulse = -1e65536;
  26089. row1.maxImpulse = 1e65536;
  26090. j = row1.jacobian;
  26091. j.lin1X = 0;
  26092. j.lin1Y = 1;
  26093. j.lin1Z = 0;
  26094. j.lin2X = 0;
  26095. j.lin2Y = 1;
  26096. j.lin2Z = 0;
  26097. j.ang1X = crossR110;
  26098. j.ang1Y = crossR111;
  26099. j.ang1Z = crossR112;
  26100. j.ang2X = crossR210;
  26101. j.ang2Y = crossR211;
  26102. j.ang2Z = crossR212;
  26103. let impulse2 = this._impulses[2];
  26104. let row2 = info.rows[info.numRows++];
  26105. let _this2 = row2.jacobian;
  26106. _this2.lin1X = 0;
  26107. _this2.lin1Y = 0;
  26108. _this2.lin1Z = 0;
  26109. _this2.lin2X = 0;
  26110. _this2.lin2Y = 0;
  26111. _this2.lin2Z = 0;
  26112. _this2.ang1X = 0;
  26113. _this2.ang1Y = 0;
  26114. _this2.ang1Z = 0;
  26115. _this2.ang2X = 0;
  26116. _this2.ang2Y = 0;
  26117. _this2.ang2Z = 0;
  26118. row2.rhs = 0;
  26119. row2.cfm = 0;
  26120. row2.minImpulse = 0;
  26121. row2.maxImpulse = 0;
  26122. row2.motorSpeed = 0;
  26123. row2.motorMaxImpulse = 0;
  26124. row2.impulse = null;
  26125. row2.impulse = impulse2;
  26126. row2.rhs = linearRhsZ;
  26127. row2.cfm = 0;
  26128. row2.minImpulse = -1e65536;
  26129. row2.maxImpulse = 1e65536;
  26130. j = row2.jacobian;
  26131. j.lin1X = 0;
  26132. j.lin1Y = 0;
  26133. j.lin1Z = 1;
  26134. j.lin2X = 0;
  26135. j.lin2Y = 0;
  26136. j.lin2Z = 1;
  26137. j.ang1X = crossR120;
  26138. j.ang1Y = crossR121;
  26139. j.ang1Z = crossR122;
  26140. j.ang2X = crossR220;
  26141. j.ang2Y = crossR221;
  26142. j.ang2Z = crossR222;
  26143. if(this.swingError > 0 && (this._swingSd.frequency <= 0 || !isPositionPart)) {
  26144. let impulse = this._impulses[3];
  26145. let row = info.rows[info.numRows++];
  26146. let _this = row.jacobian;
  26147. _this.lin1X = 0;
  26148. _this.lin1Y = 0;
  26149. _this.lin1Z = 0;
  26150. _this.lin2X = 0;
  26151. _this.lin2Y = 0;
  26152. _this.lin2Z = 0;
  26153. _this.ang1X = 0;
  26154. _this.ang1Y = 0;
  26155. _this.ang1Z = 0;
  26156. _this.ang2X = 0;
  26157. _this.ang2Y = 0;
  26158. _this.ang2Z = 0;
  26159. row.rhs = 0;
  26160. row.cfm = 0;
  26161. row.minImpulse = 0;
  26162. row.maxImpulse = 0;
  26163. row.motorSpeed = 0;
  26164. row.motorMaxImpulse = 0;
  26165. row.impulse = null;
  26166. row.impulse = impulse;
  26167. this.setSolverInfoRowAngular(row,this.swingError,this.dummySwingLm,swingMass,this._swingSd,timeStep,isPositionPart);
  26168. j = row.jacobian;
  26169. j.ang1X = this.swingAxisX;
  26170. j.ang1Y = this.swingAxisY;
  26171. j.ang1Z = this.swingAxisZ;
  26172. j.ang2X = this.swingAxisX;
  26173. j.ang2Y = this.swingAxisY;
  26174. j.ang2Z = this.swingAxisZ;
  26175. }
  26176. if(this._twistSd.frequency <= 0 || !isPositionPart) {
  26177. let impulse = this._impulses[4];
  26178. let row = info.rows[info.numRows++];
  26179. let _this = row.jacobian;
  26180. _this.lin1X = 0;
  26181. _this.lin1Y = 0;
  26182. _this.lin1Z = 0;
  26183. _this.lin2X = 0;
  26184. _this.lin2Y = 0;
  26185. _this.lin2Z = 0;
  26186. _this.ang1X = 0;
  26187. _this.ang1Y = 0;
  26188. _this.ang1Z = 0;
  26189. _this.ang2X = 0;
  26190. _this.ang2Y = 0;
  26191. _this.ang2Z = 0;
  26192. row.rhs = 0;
  26193. row.cfm = 0;
  26194. row.minImpulse = 0;
  26195. row.maxImpulse = 0;
  26196. row.motorSpeed = 0;
  26197. row.motorMaxImpulse = 0;
  26198. row.impulse = null;
  26199. row.impulse = impulse;
  26200. this.setSolverInfoRowAngular(row,this._twistAngle,this._twistLm,twistMass,this._twistSd,timeStep,isPositionPart);
  26201. j = row.jacobian;
  26202. j.ang1X = this.twistAxisX;
  26203. j.ang1Y = this.twistAxisY;
  26204. j.ang1Z = this.twistAxisZ;
  26205. j.ang2X = this.twistAxisX;
  26206. j.ang2Y = this.twistAxisY;
  26207. j.ang2Z = this.twistAxisZ;
  26208. }
  26209. }
  26210. _syncAnchors() {
  26211. super._syncAnchors();
  26212. let axis1X;
  26213. let axis1Y;
  26214. let axis1Z;
  26215. let axis2X;
  26216. let axis2Y;
  26217. let axis2Z;
  26218. axis1X = this._basisX1X;
  26219. axis1Y = this._basisX1Y;
  26220. axis1Z = this._basisX1Z;
  26221. axis2X = this._basisX2X;
  26222. axis2Y = this._basisX2Y;
  26223. axis2Z = this._basisX2Z;
  26224. let basis1Mat00;
  26225. let basis1Mat01;
  26226. let basis1Mat02;
  26227. let basis1Mat10;
  26228. let basis1Mat11;
  26229. let basis1Mat12;
  26230. let basis1Mat20;
  26231. let basis1Mat21;
  26232. let basis1Mat22;
  26233. basis1Mat00 = this._basisX1X;
  26234. basis1Mat01 = this._basisY1X;
  26235. basis1Mat02 = this._basisZ1X;
  26236. basis1Mat10 = this._basisX1Y;
  26237. basis1Mat11 = this._basisY1Y;
  26238. basis1Mat12 = this._basisZ1Y;
  26239. basis1Mat20 = this._basisX1Z;
  26240. basis1Mat21 = this._basisY1Z;
  26241. basis1Mat22 = this._basisZ1Z;
  26242. let swingQX;
  26243. let swingQY;
  26244. let swingQZ;
  26245. let swingQW;
  26246. let swingM00;
  26247. let swingM01;
  26248. let swingM02;
  26249. let swingM10;
  26250. let swingM11;
  26251. let swingM12;
  26252. let swingM20;
  26253. let swingM21;
  26254. let swingM22;
  26255. let swingVX;
  26256. let swingVY;
  26257. let swingVZ;
  26258. let d = axis1X * axis2X + axis1Y * axis2Y + axis1Z * axis2Z;
  26259. if(d < -0.999999999) {
  26260. let vX;
  26261. let vY;
  26262. let vZ;
  26263. let x1 = axis1X;
  26264. let y1 = axis1Y;
  26265. let z1 = axis1Z;
  26266. let x2 = x1 * x1;
  26267. let y2 = y1 * y1;
  26268. let z2 = z1 * z1;
  26269. let d;
  26270. if(x2 < y2) {
  26271. if(x2 < z2) {
  26272. d = 1 / Math.sqrt(y2 + z2);
  26273. vX = 0;
  26274. vY = z1 * d;
  26275. vZ = -y1 * d;
  26276. } else {
  26277. d = 1 / Math.sqrt(x2 + y2);
  26278. vX = y1 * d;
  26279. vY = -x1 * d;
  26280. vZ = 0;
  26281. }
  26282. } else if(y2 < z2) {
  26283. d = 1 / Math.sqrt(z2 + x2);
  26284. vX = -z1 * d;
  26285. vY = 0;
  26286. vZ = x1 * d;
  26287. } else {
  26288. d = 1 / Math.sqrt(x2 + y2);
  26289. vX = y1 * d;
  26290. vY = -x1 * d;
  26291. vZ = 0;
  26292. }
  26293. swingQX = vX;
  26294. swingQY = vY;
  26295. swingQZ = vZ;
  26296. swingQW = 0;
  26297. } else {
  26298. let cX;
  26299. let cY;
  26300. let cZ;
  26301. cX = axis1Y * axis2Z - axis1Z * axis2Y;
  26302. cY = axis1Z * axis2X - axis1X * axis2Z;
  26303. cZ = axis1X * axis2Y - axis1Y * axis2X;
  26304. let w = Math.sqrt((1 + d) * 0.5);
  26305. d = 0.5 / w;
  26306. cX *= d;
  26307. cY *= d;
  26308. cZ *= d;
  26309. swingQX = cX;
  26310. swingQY = cY;
  26311. swingQZ = cZ;
  26312. swingQW = w;
  26313. }
  26314. let x = swingQX;
  26315. let y = swingQY;
  26316. let z = swingQZ;
  26317. let w = swingQW;
  26318. let x2 = 2 * x;
  26319. let y2 = 2 * y;
  26320. let z2 = 2 * z;
  26321. let xx = x * x2;
  26322. let yy = y * y2;
  26323. let zz = z * z2;
  26324. let xy = x * y2;
  26325. let yz = y * z2;
  26326. let xz = x * z2;
  26327. let wx = w * x2;
  26328. let wy = w * y2;
  26329. let wz = w * z2;
  26330. swingM00 = 1 - yy - zz;
  26331. swingM01 = xy - wz;
  26332. swingM02 = xz + wy;
  26333. swingM10 = xy + wz;
  26334. swingM11 = 1 - xx - zz;
  26335. swingM12 = yz - wx;
  26336. swingM20 = xz - wy;
  26337. swingM21 = yz + wx;
  26338. swingM22 = 1 - xx - yy;
  26339. this._swingAngle = (swingQW <= -1 ? 3.14159265358979 : swingQW >= 1 ? 0 : Math.acos(swingQW)) * 2;
  26340. swingVX = swingQX;
  26341. swingVY = swingQY;
  26342. swingVZ = swingQZ;
  26343. let basisY2In1X;
  26344. let basisY2In1Y;
  26345. let basisY2In1Z;
  26346. let __tmp__X;
  26347. let __tmp__Y;
  26348. let __tmp__Z;
  26349. __tmp__X = swingM00 * this._basisY2X + swingM10 * this._basisY2Y + swingM20 * this._basisY2Z;
  26350. __tmp__Y = swingM01 * this._basisY2X + swingM11 * this._basisY2Y + swingM21 * this._basisY2Z;
  26351. __tmp__Z = swingM02 * this._basisY2X + swingM12 * this._basisY2Y + swingM22 * this._basisY2Z;
  26352. basisY2In1X = __tmp__X;
  26353. basisY2In1Y = __tmp__Y;
  26354. basisY2In1Z = __tmp__Z;
  26355. this._twistAngle = Math.atan2(this._basisZ1X * basisY2In1X + this._basisZ1Y * basisY2In1Y + this._basisZ1Z * basisY2In1Z,this._basisY1X * basisY2In1X + this._basisY1Y * basisY2In1Y + this._basisY1Z * basisY2In1Z);
  26356. this.twistAxisX = this._basisX1X + this._basisX2X;
  26357. this.twistAxisY = this._basisX1Y + this._basisX2Y;
  26358. this.twistAxisZ = this._basisX1Z + this._basisX2Z;
  26359. let l = this.twistAxisX * this.twistAxisX + this.twistAxisY * this.twistAxisY + this.twistAxisZ * this.twistAxisZ;
  26360. if(l > 0) {
  26361. l = 1 / Math.sqrt(l);
  26362. }
  26363. this.twistAxisX *= l;
  26364. this.twistAxisY *= l;
  26365. this.twistAxisZ *= l;
  26366. let invLen = Math.sqrt(swingVX * swingVX + swingVY * swingVY + swingVZ * swingVZ);
  26367. if(invLen > 0) {
  26368. invLen = 1 / invLen;
  26369. }
  26370. swingVX *= invLen * this._swingAngle;
  26371. swingVY *= invLen * this._swingAngle;
  26372. swingVZ *= invLen * this._swingAngle;
  26373. let __tmp__Y1;
  26374. let __tmp__Z1;
  26375. __tmp__Y1 = basis1Mat01 * swingVX + basis1Mat11 * swingVY + basis1Mat21 * swingVZ;
  26376. __tmp__Z1 = basis1Mat02 * swingVX + basis1Mat12 * swingVY + basis1Mat22 * swingVZ;
  26377. swingVY = __tmp__Y1;
  26378. swingVZ = __tmp__Z1;
  26379. let x1 = swingVY;
  26380. let y1 = swingVZ;
  26381. let a = this._maxSwingAngle1;
  26382. let b = this._maxSwingAngle2;
  26383. let invA2 = 1 / (a * a);
  26384. let invB2 = 1 / (b * b);
  26385. let w1 = x1 * x1 * invA2 + y1 * y1 * invB2;
  26386. if(w1 == 0) {
  26387. this.swingAxisX = 0;
  26388. this.swingAxisY = 0;
  26389. this.swingAxisZ = 0;
  26390. this.swingError = 0;
  26391. } else {
  26392. let t = Math.sqrt(1 / w1);
  26393. let x0 = x1 * t;
  26394. let y0 = y1 * t;
  26395. let nx = x0 * invA2;
  26396. let ny = y0 * invB2;
  26397. invLen = 1 / Math.sqrt(nx * nx + ny * ny);
  26398. nx *= invLen;
  26399. ny *= invLen;
  26400. let depth = (x1 - x0) * nx + (y1 - y0) * ny;
  26401. if(depth > 0) {
  26402. this.swingError = depth;
  26403. this.swingAxisX = 0;
  26404. this.swingAxisY = nx;
  26405. this.swingAxisZ = ny;
  26406. let __tmp__X;
  26407. let __tmp__Y;
  26408. let __tmp__Z;
  26409. __tmp__X = basis1Mat00 * this.swingAxisX + basis1Mat01 * this.swingAxisY + basis1Mat02 * this.swingAxisZ;
  26410. __tmp__Y = basis1Mat10 * this.swingAxisX + basis1Mat11 * this.swingAxisY + basis1Mat12 * this.swingAxisZ;
  26411. __tmp__Z = basis1Mat20 * this.swingAxisX + basis1Mat21 * this.swingAxisY + basis1Mat22 * this.swingAxisZ;
  26412. this.swingAxisX = __tmp__X;
  26413. this.swingAxisY = __tmp__Y;
  26414. this.swingAxisZ = __tmp__Z;
  26415. let __tmp__X1;
  26416. let __tmp__Y1;
  26417. let __tmp__Z1;
  26418. __tmp__X1 = swingM00 * this.swingAxisX + swingM01 * this.swingAxisY + swingM02 * this.swingAxisZ;
  26419. __tmp__Y1 = swingM10 * this.swingAxisX + swingM11 * this.swingAxisY + swingM12 * this.swingAxisZ;
  26420. __tmp__Z1 = swingM20 * this.swingAxisX + swingM21 * this.swingAxisY + swingM22 * this.swingAxisZ;
  26421. this.swingAxisX = __tmp__X1;
  26422. this.swingAxisY = __tmp__Y1;
  26423. this.swingAxisZ = __tmp__Z1;
  26424. } else {
  26425. this.swingError = 0;
  26426. }
  26427. }
  26428. this.linearErrorX = this._anchor2X - this._anchor1X;
  26429. this.linearErrorY = this._anchor2Y - this._anchor1Y;
  26430. this.linearErrorZ = this._anchor2Z - this._anchor1Z;
  26431. }
  26432. _getVelocitySolverInfo(timeStep,info) {
  26433. super._getVelocitySolverInfo(timeStep,info);
  26434. this.getInfo(info,timeStep,false);
  26435. }
  26436. _getPositionSolverInfo(info) {
  26437. super._getPositionSolverInfo(info);
  26438. this.getInfo(info,null,true);
  26439. }
  26440. getAxis1() {
  26441. let v = new oimo.common.Vec3();
  26442. v.x = this._basisX1X;
  26443. v.y = this._basisX1Y;
  26444. v.z = this._basisX1Z;
  26445. return v;
  26446. }
  26447. getAxis2() {
  26448. let v = new oimo.common.Vec3();
  26449. v.x = this._basisX2X;
  26450. v.y = this._basisX2Y;
  26451. v.z = this._basisX2Z;
  26452. return v;
  26453. }
  26454. getAxis1To(axis) {
  26455. axis.x = this._basisX1X;
  26456. axis.y = this._basisX1Y;
  26457. axis.z = this._basisX1Z;
  26458. }
  26459. getAxis2To(axis) {
  26460. axis.x = this._basisX2X;
  26461. axis.y = this._basisX2Y;
  26462. axis.z = this._basisX2Z;
  26463. }
  26464. getLocalAxis1() {
  26465. let v = new oimo.common.Vec3();
  26466. v.x = this._localBasisX1X;
  26467. v.y = this._localBasisX1Y;
  26468. v.z = this._localBasisX1Z;
  26469. return v;
  26470. }
  26471. getLocalAxis2() {
  26472. let v = new oimo.common.Vec3();
  26473. v.x = this._localBasisX2X;
  26474. v.y = this._localBasisX2Y;
  26475. v.z = this._localBasisX2Z;
  26476. return v;
  26477. }
  26478. getLocalAxis1To(axis) {
  26479. axis.x = this._localBasisX1X;
  26480. axis.y = this._localBasisX1Y;
  26481. axis.z = this._localBasisX1Z;
  26482. }
  26483. getLocalAxis2To(axis) {
  26484. axis.x = this._localBasisX2X;
  26485. axis.y = this._localBasisX2Y;
  26486. axis.z = this._localBasisX2Z;
  26487. }
  26488. getTwistSpringDamper() {
  26489. return this._twistSd;
  26490. }
  26491. getTwistLimitMotor() {
  26492. return this._twistLm;
  26493. }
  26494. getSwingSpringDamper() {
  26495. return this._swingSd;
  26496. }
  26497. getSwingAxis() {
  26498. let v = new oimo.common.Vec3();
  26499. v.x = this.swingAxisX;
  26500. v.y = this.swingAxisY;
  26501. v.z = this.swingAxisZ;
  26502. return v;
  26503. }
  26504. getSwingAxisTo(axis) {
  26505. axis.x = this.swingAxisX;
  26506. axis.y = this.swingAxisY;
  26507. axis.z = this.swingAxisZ;
  26508. }
  26509. getSwingAngle() {
  26510. return this._swingAngle;
  26511. }
  26512. getTwistAngle() {
  26513. return this._twistAngle;
  26514. }
  26515. }
  26516. oimo.dynamics.constraint.joint.RagdollJointConfig = class oimo_dynamics_constraint_joint_RagdollJointConfig extends oimo.dynamics.constraint.joint.JointConfig {
  26517. constructor() {
  26518. super();
  26519. this.localTwistAxis1 = new oimo.common.Vec3(1,0,0);
  26520. this.localTwistAxis2 = new oimo.common.Vec3(1,0,0);
  26521. this.localSwingAxis1 = new oimo.common.Vec3(0,1,0);
  26522. this.twistSpringDamper = new oimo.dynamics.constraint.joint.SpringDamper();
  26523. this.swingSpringDamper = new oimo.dynamics.constraint.joint.SpringDamper();
  26524. this.twistLimitMotor = new oimo.dynamics.constraint.joint.RotationalLimitMotor();
  26525. this.maxSwingAngle1 = 3.14159265358979;
  26526. this.maxSwingAngle2 = 3.14159265358979;
  26527. }
  26528. init(rigidBody1,rigidBody2,worldAnchor,worldTwistAxis,worldSwingAxis) {
  26529. this._init(rigidBody1,rigidBody2,worldAnchor);
  26530. let localVector = this.localTwistAxis1;
  26531. let vX;
  26532. let vY;
  26533. let vZ;
  26534. vX = worldTwistAxis.x;
  26535. vY = worldTwistAxis.y;
  26536. vZ = worldTwistAxis.z;
  26537. let __tmp__X;
  26538. let __tmp__Y;
  26539. let __tmp__Z;
  26540. __tmp__X = rigidBody1._transform._rotation00 * vX + rigidBody1._transform._rotation10 * vY + rigidBody1._transform._rotation20 * vZ;
  26541. __tmp__Y = rigidBody1._transform._rotation01 * vX + rigidBody1._transform._rotation11 * vY + rigidBody1._transform._rotation21 * vZ;
  26542. __tmp__Z = rigidBody1._transform._rotation02 * vX + rigidBody1._transform._rotation12 * vY + rigidBody1._transform._rotation22 * vZ;
  26543. vX = __tmp__X;
  26544. vY = __tmp__Y;
  26545. vZ = __tmp__Z;
  26546. localVector.x = vX;
  26547. localVector.y = vY;
  26548. localVector.z = vZ;
  26549. let localVector1 = this.localTwistAxis2;
  26550. let vX1;
  26551. let vY1;
  26552. let vZ1;
  26553. vX1 = worldTwistAxis.x;
  26554. vY1 = worldTwistAxis.y;
  26555. vZ1 = worldTwistAxis.z;
  26556. let __tmp__X1;
  26557. let __tmp__Y1;
  26558. let __tmp__Z1;
  26559. __tmp__X1 = rigidBody2._transform._rotation00 * vX1 + rigidBody2._transform._rotation10 * vY1 + rigidBody2._transform._rotation20 * vZ1;
  26560. __tmp__Y1 = rigidBody2._transform._rotation01 * vX1 + rigidBody2._transform._rotation11 * vY1 + rigidBody2._transform._rotation21 * vZ1;
  26561. __tmp__Z1 = rigidBody2._transform._rotation02 * vX1 + rigidBody2._transform._rotation12 * vY1 + rigidBody2._transform._rotation22 * vZ1;
  26562. vX1 = __tmp__X1;
  26563. vY1 = __tmp__Y1;
  26564. vZ1 = __tmp__Z1;
  26565. localVector1.x = vX1;
  26566. localVector1.y = vY1;
  26567. localVector1.z = vZ1;
  26568. let localVector2 = this.localSwingAxis1;
  26569. let vX2;
  26570. let vY2;
  26571. let vZ2;
  26572. vX2 = worldSwingAxis.x;
  26573. vY2 = worldSwingAxis.y;
  26574. vZ2 = worldSwingAxis.z;
  26575. let __tmp__X2;
  26576. let __tmp__Y2;
  26577. let __tmp__Z2;
  26578. __tmp__X2 = rigidBody1._transform._rotation00 * vX2 + rigidBody1._transform._rotation10 * vY2 + rigidBody1._transform._rotation20 * vZ2;
  26579. __tmp__Y2 = rigidBody1._transform._rotation01 * vX2 + rigidBody1._transform._rotation11 * vY2 + rigidBody1._transform._rotation21 * vZ2;
  26580. __tmp__Z2 = rigidBody1._transform._rotation02 * vX2 + rigidBody1._transform._rotation12 * vY2 + rigidBody1._transform._rotation22 * vZ2;
  26581. vX2 = __tmp__X2;
  26582. vY2 = __tmp__Y2;
  26583. vZ2 = __tmp__Z2;
  26584. localVector2.x = vX2;
  26585. localVector2.y = vY2;
  26586. localVector2.z = vZ2;
  26587. return this;
  26588. }
  26589. }
  26590. oimo.dynamics.constraint.joint.RevoluteJoint = class oimo_dynamics_constraint_joint_RevoluteJoint extends oimo.dynamics.constraint.joint.Joint {
  26591. constructor(config) {
  26592. super(config,1);
  26593. let v = config.localAxis1;
  26594. this._localBasisX1X = v.x;
  26595. this._localBasisX1Y = v.y;
  26596. this._localBasisX1Z = v.z;
  26597. let v1 = config.localAxis2;
  26598. this._localBasisX2X = v1.x;
  26599. this._localBasisX2Y = v1.y;
  26600. this._localBasisX2Z = v1.z;
  26601. this.buildLocalBasesFromX();
  26602. this.angle = 0;
  26603. this.angularErrorY = 0;
  26604. this.angularErrorZ = 0;
  26605. this._basis = new oimo.dynamics.constraint.joint.BasisTracker(this);
  26606. this._sd = config.springDamper.clone();
  26607. this._lm = config.limitMotor.clone();
  26608. }
  26609. getInfo(info,timeStep,isPositionPart) {
  26610. let erp = this.getErp(timeStep,isPositionPart);
  26611. let linearRhsX;
  26612. let linearRhsY;
  26613. let linearRhsZ;
  26614. linearRhsX = this.linearErrorX * erp;
  26615. linearRhsY = this.linearErrorY * erp;
  26616. linearRhsZ = this.linearErrorZ * erp;
  26617. let angRhsY = this.angularErrorY * erp;
  26618. let angRhsZ = this.angularErrorZ * erp;
  26619. let crossR100;
  26620. let crossR101;
  26621. let crossR102;
  26622. let crossR110;
  26623. let crossR111;
  26624. let crossR112;
  26625. let crossR120;
  26626. let crossR121;
  26627. let crossR122;
  26628. let crossR200;
  26629. let crossR201;
  26630. let crossR202;
  26631. let crossR210;
  26632. let crossR211;
  26633. let crossR212;
  26634. let crossR220;
  26635. let crossR221;
  26636. let crossR222;
  26637. crossR100 = 0;
  26638. crossR101 = -this._relativeAnchor1Z;
  26639. crossR102 = this._relativeAnchor1Y;
  26640. crossR110 = this._relativeAnchor1Z;
  26641. crossR111 = 0;
  26642. crossR112 = -this._relativeAnchor1X;
  26643. crossR120 = -this._relativeAnchor1Y;
  26644. crossR121 = this._relativeAnchor1X;
  26645. crossR122 = 0;
  26646. crossR200 = 0;
  26647. crossR201 = -this._relativeAnchor2Z;
  26648. crossR202 = this._relativeAnchor2Y;
  26649. crossR210 = this._relativeAnchor2Z;
  26650. crossR211 = 0;
  26651. crossR212 = -this._relativeAnchor2X;
  26652. crossR220 = -this._relativeAnchor2Y;
  26653. crossR221 = this._relativeAnchor2X;
  26654. crossR222 = 0;
  26655. crossR100 = -crossR100;
  26656. crossR101 = -crossR101;
  26657. crossR102 = -crossR102;
  26658. crossR110 = -crossR110;
  26659. crossR111 = -crossR111;
  26660. crossR112 = -crossR112;
  26661. crossR120 = -crossR120;
  26662. crossR121 = -crossR121;
  26663. crossR122 = -crossR122;
  26664. crossR200 = -crossR200;
  26665. crossR201 = -crossR201;
  26666. crossR202 = -crossR202;
  26667. crossR210 = -crossR210;
  26668. crossR211 = -crossR211;
  26669. crossR212 = -crossR212;
  26670. crossR220 = -crossR220;
  26671. crossR221 = -crossR221;
  26672. crossR222 = -crossR222;
  26673. let motorMass = this.computeEffectiveInertiaMoment(this._basis.xX,this._basis.xY,this._basis.xZ);
  26674. let impulse = this._impulses[0];
  26675. let row = info.rows[info.numRows++];
  26676. let _this = row.jacobian;
  26677. _this.lin1X = 0;
  26678. _this.lin1Y = 0;
  26679. _this.lin1Z = 0;
  26680. _this.lin2X = 0;
  26681. _this.lin2Y = 0;
  26682. _this.lin2Z = 0;
  26683. _this.ang1X = 0;
  26684. _this.ang1Y = 0;
  26685. _this.ang1Z = 0;
  26686. _this.ang2X = 0;
  26687. _this.ang2Y = 0;
  26688. _this.ang2Z = 0;
  26689. row.rhs = 0;
  26690. row.cfm = 0;
  26691. row.minImpulse = 0;
  26692. row.maxImpulse = 0;
  26693. row.motorSpeed = 0;
  26694. row.motorMaxImpulse = 0;
  26695. row.impulse = null;
  26696. row.impulse = impulse;
  26697. row.rhs = linearRhsX;
  26698. row.cfm = 0;
  26699. row.minImpulse = -1e65536;
  26700. row.maxImpulse = 1e65536;
  26701. let j = row.jacobian;
  26702. j.lin1X = 1;
  26703. j.lin1Y = 0;
  26704. j.lin1Z = 0;
  26705. j.lin2X = 1;
  26706. j.lin2Y = 0;
  26707. j.lin2Z = 0;
  26708. j.ang1X = crossR100;
  26709. j.ang1Y = crossR101;
  26710. j.ang1Z = crossR102;
  26711. j.ang2X = crossR200;
  26712. j.ang2Y = crossR201;
  26713. j.ang2Z = crossR202;
  26714. let impulse1 = this._impulses[1];
  26715. let row1 = info.rows[info.numRows++];
  26716. let _this1 = row1.jacobian;
  26717. _this1.lin1X = 0;
  26718. _this1.lin1Y = 0;
  26719. _this1.lin1Z = 0;
  26720. _this1.lin2X = 0;
  26721. _this1.lin2Y = 0;
  26722. _this1.lin2Z = 0;
  26723. _this1.ang1X = 0;
  26724. _this1.ang1Y = 0;
  26725. _this1.ang1Z = 0;
  26726. _this1.ang2X = 0;
  26727. _this1.ang2Y = 0;
  26728. _this1.ang2Z = 0;
  26729. row1.rhs = 0;
  26730. row1.cfm = 0;
  26731. row1.minImpulse = 0;
  26732. row1.maxImpulse = 0;
  26733. row1.motorSpeed = 0;
  26734. row1.motorMaxImpulse = 0;
  26735. row1.impulse = null;
  26736. row1.impulse = impulse1;
  26737. row1.rhs = linearRhsY;
  26738. row1.cfm = 0;
  26739. row1.minImpulse = -1e65536;
  26740. row1.maxImpulse = 1e65536;
  26741. j = row1.jacobian;
  26742. j.lin1X = 0;
  26743. j.lin1Y = 1;
  26744. j.lin1Z = 0;
  26745. j.lin2X = 0;
  26746. j.lin2Y = 1;
  26747. j.lin2Z = 0;
  26748. j.ang1X = crossR110;
  26749. j.ang1Y = crossR111;
  26750. j.ang1Z = crossR112;
  26751. j.ang2X = crossR210;
  26752. j.ang2Y = crossR211;
  26753. j.ang2Z = crossR212;
  26754. let impulse2 = this._impulses[2];
  26755. let row2 = info.rows[info.numRows++];
  26756. let _this2 = row2.jacobian;
  26757. _this2.lin1X = 0;
  26758. _this2.lin1Y = 0;
  26759. _this2.lin1Z = 0;
  26760. _this2.lin2X = 0;
  26761. _this2.lin2Y = 0;
  26762. _this2.lin2Z = 0;
  26763. _this2.ang1X = 0;
  26764. _this2.ang1Y = 0;
  26765. _this2.ang1Z = 0;
  26766. _this2.ang2X = 0;
  26767. _this2.ang2Y = 0;
  26768. _this2.ang2Z = 0;
  26769. row2.rhs = 0;
  26770. row2.cfm = 0;
  26771. row2.minImpulse = 0;
  26772. row2.maxImpulse = 0;
  26773. row2.motorSpeed = 0;
  26774. row2.motorMaxImpulse = 0;
  26775. row2.impulse = null;
  26776. row2.impulse = impulse2;
  26777. row2.rhs = linearRhsZ;
  26778. row2.cfm = 0;
  26779. row2.minImpulse = -1e65536;
  26780. row2.maxImpulse = 1e65536;
  26781. j = row2.jacobian;
  26782. j.lin1X = 0;
  26783. j.lin1Y = 0;
  26784. j.lin1Z = 1;
  26785. j.lin2X = 0;
  26786. j.lin2Y = 0;
  26787. j.lin2Z = 1;
  26788. j.ang1X = crossR120;
  26789. j.ang1Y = crossR121;
  26790. j.ang1Z = crossR122;
  26791. j.ang2X = crossR220;
  26792. j.ang2Y = crossR221;
  26793. j.ang2Z = crossR222;
  26794. if(this._sd.frequency <= 0 || !isPositionPart) {
  26795. let impulse = this._impulses[3];
  26796. let row = info.rows[info.numRows++];
  26797. let _this = row.jacobian;
  26798. _this.lin1X = 0;
  26799. _this.lin1Y = 0;
  26800. _this.lin1Z = 0;
  26801. _this.lin2X = 0;
  26802. _this.lin2Y = 0;
  26803. _this.lin2Z = 0;
  26804. _this.ang1X = 0;
  26805. _this.ang1Y = 0;
  26806. _this.ang1Z = 0;
  26807. _this.ang2X = 0;
  26808. _this.ang2Y = 0;
  26809. _this.ang2Z = 0;
  26810. row.rhs = 0;
  26811. row.cfm = 0;
  26812. row.minImpulse = 0;
  26813. row.maxImpulse = 0;
  26814. row.motorSpeed = 0;
  26815. row.motorMaxImpulse = 0;
  26816. row.impulse = null;
  26817. row.impulse = impulse;
  26818. this.setSolverInfoRowAngular(row,this.angle,this._lm,motorMass,this._sd,timeStep,isPositionPart);
  26819. j = row.jacobian;
  26820. j.ang1X = this._basis.xX;
  26821. j.ang1Y = this._basis.xY;
  26822. j.ang1Z = this._basis.xZ;
  26823. j.ang2X = this._basis.xX;
  26824. j.ang2Y = this._basis.xY;
  26825. j.ang2Z = this._basis.xZ;
  26826. }
  26827. let impulse3 = this._impulses[4];
  26828. let row3 = info.rows[info.numRows++];
  26829. let _this3 = row3.jacobian;
  26830. _this3.lin1X = 0;
  26831. _this3.lin1Y = 0;
  26832. _this3.lin1Z = 0;
  26833. _this3.lin2X = 0;
  26834. _this3.lin2Y = 0;
  26835. _this3.lin2Z = 0;
  26836. _this3.ang1X = 0;
  26837. _this3.ang1Y = 0;
  26838. _this3.ang1Z = 0;
  26839. _this3.ang2X = 0;
  26840. _this3.ang2Y = 0;
  26841. _this3.ang2Z = 0;
  26842. row3.rhs = 0;
  26843. row3.cfm = 0;
  26844. row3.minImpulse = 0;
  26845. row3.maxImpulse = 0;
  26846. row3.motorSpeed = 0;
  26847. row3.motorMaxImpulse = 0;
  26848. row3.impulse = null;
  26849. row3.impulse = impulse3;
  26850. row3.rhs = angRhsY;
  26851. row3.cfm = 0;
  26852. row3.minImpulse = -1e65536;
  26853. row3.maxImpulse = 1e65536;
  26854. j = row3.jacobian;
  26855. j.ang1X = this._basis.yX;
  26856. j.ang1Y = this._basis.yY;
  26857. j.ang1Z = this._basis.yZ;
  26858. j.ang2X = this._basis.yX;
  26859. j.ang2Y = this._basis.yY;
  26860. j.ang2Z = this._basis.yZ;
  26861. let impulse4 = this._impulses[5];
  26862. let row4 = info.rows[info.numRows++];
  26863. let _this4 = row4.jacobian;
  26864. _this4.lin1X = 0;
  26865. _this4.lin1Y = 0;
  26866. _this4.lin1Z = 0;
  26867. _this4.lin2X = 0;
  26868. _this4.lin2Y = 0;
  26869. _this4.lin2Z = 0;
  26870. _this4.ang1X = 0;
  26871. _this4.ang1Y = 0;
  26872. _this4.ang1Z = 0;
  26873. _this4.ang2X = 0;
  26874. _this4.ang2Y = 0;
  26875. _this4.ang2Z = 0;
  26876. row4.rhs = 0;
  26877. row4.cfm = 0;
  26878. row4.minImpulse = 0;
  26879. row4.maxImpulse = 0;
  26880. row4.motorSpeed = 0;
  26881. row4.motorMaxImpulse = 0;
  26882. row4.impulse = null;
  26883. row4.impulse = impulse4;
  26884. row4.rhs = angRhsZ;
  26885. row4.cfm = 0;
  26886. row4.minImpulse = -1e65536;
  26887. row4.maxImpulse = 1e65536;
  26888. j = row4.jacobian;
  26889. j.ang1X = this._basis.zX;
  26890. j.ang1Y = this._basis.zY;
  26891. j.ang1Z = this._basis.zZ;
  26892. j.ang2X = this._basis.zX;
  26893. j.ang2Y = this._basis.zY;
  26894. j.ang2Z = this._basis.zZ;
  26895. }
  26896. _syncAnchors() {
  26897. super._syncAnchors();
  26898. let _this = this._basis;
  26899. let invM1 = _this.joint._b1._invMass;
  26900. let invM2 = _this.joint._b2._invMass;
  26901. let qX;
  26902. let qY;
  26903. let qZ;
  26904. let qW;
  26905. let idQX;
  26906. let idQY;
  26907. let idQZ;
  26908. let idQW;
  26909. let slerpQX;
  26910. let slerpQY;
  26911. let slerpQZ;
  26912. let slerpQW;
  26913. let slerpM00;
  26914. let slerpM01;
  26915. let slerpM02;
  26916. let slerpM10;
  26917. let slerpM11;
  26918. let slerpM12;
  26919. let slerpM20;
  26920. let slerpM21;
  26921. let slerpM22;
  26922. let newXX;
  26923. let newXY;
  26924. let newXZ;
  26925. let newYX;
  26926. let newYY;
  26927. let newYZ;
  26928. let newZX;
  26929. let newZY;
  26930. let newZZ;
  26931. let prevXX;
  26932. let prevXY;
  26933. let prevXZ;
  26934. let prevYX;
  26935. let prevYY;
  26936. let prevYZ;
  26937. let d = _this.joint._basisX1X * _this.joint._basisX2X + _this.joint._basisX1Y * _this.joint._basisX2Y + _this.joint._basisX1Z * _this.joint._basisX2Z;
  26938. if(d < -0.999999999) {
  26939. let vX;
  26940. let vY;
  26941. let vZ;
  26942. let x1 = _this.joint._basisX1X;
  26943. let y1 = _this.joint._basisX1Y;
  26944. let z1 = _this.joint._basisX1Z;
  26945. let x2 = x1 * x1;
  26946. let y2 = y1 * y1;
  26947. let z2 = z1 * z1;
  26948. let d;
  26949. if(x2 < y2) {
  26950. if(x2 < z2) {
  26951. d = 1 / Math.sqrt(y2 + z2);
  26952. vX = 0;
  26953. vY = z1 * d;
  26954. vZ = -y1 * d;
  26955. } else {
  26956. d = 1 / Math.sqrt(x2 + y2);
  26957. vX = y1 * d;
  26958. vY = -x1 * d;
  26959. vZ = 0;
  26960. }
  26961. } else if(y2 < z2) {
  26962. d = 1 / Math.sqrt(z2 + x2);
  26963. vX = -z1 * d;
  26964. vY = 0;
  26965. vZ = x1 * d;
  26966. } else {
  26967. d = 1 / Math.sqrt(x2 + y2);
  26968. vX = y1 * d;
  26969. vY = -x1 * d;
  26970. vZ = 0;
  26971. }
  26972. qX = vX;
  26973. qY = vY;
  26974. qZ = vZ;
  26975. qW = 0;
  26976. } else {
  26977. let cX;
  26978. let cY;
  26979. let cZ;
  26980. cX = _this.joint._basisX1Y * _this.joint._basisX2Z - _this.joint._basisX1Z * _this.joint._basisX2Y;
  26981. cY = _this.joint._basisX1Z * _this.joint._basisX2X - _this.joint._basisX1X * _this.joint._basisX2Z;
  26982. cZ = _this.joint._basisX1X * _this.joint._basisX2Y - _this.joint._basisX1Y * _this.joint._basisX2X;
  26983. let w = Math.sqrt((1 + d) * 0.5);
  26984. d = 0.5 / w;
  26985. cX *= d;
  26986. cY *= d;
  26987. cZ *= d;
  26988. qX = cX;
  26989. qY = cY;
  26990. qZ = cZ;
  26991. qW = w;
  26992. }
  26993. idQX = 0;
  26994. idQY = 0;
  26995. idQZ = 0;
  26996. idQW = 1;
  26997. let q1X;
  26998. let q1Y;
  26999. let q1Z;
  27000. let q1W;
  27001. let q2X;
  27002. let q2Y;
  27003. let q2Z;
  27004. let q2W;
  27005. q1X = idQX;
  27006. q1Y = idQY;
  27007. q1Z = idQZ;
  27008. q1W = idQW;
  27009. q2X = qX;
  27010. q2Y = qY;
  27011. q2Z = qZ;
  27012. q2W = qW;
  27013. let d1 = q1X * q2X + q1Y * q2Y + q1Z * q2Z + q1W * q2W;
  27014. if(d1 < 0) {
  27015. d1 = -d1;
  27016. q2X = -q2X;
  27017. q2Y = -q2Y;
  27018. q2Z = -q2Z;
  27019. q2W = -q2W;
  27020. }
  27021. if(d1 > 0.999999) {
  27022. let dqX;
  27023. let dqY;
  27024. let dqZ;
  27025. let dqW;
  27026. dqX = q2X - q1X;
  27027. dqY = q2Y - q1Y;
  27028. dqZ = q2Z - q1Z;
  27029. dqW = q2W - q1W;
  27030. q2X = q1X + dqX * (invM1 / (invM1 + invM2));
  27031. q2Y = q1Y + dqY * (invM1 / (invM1 + invM2));
  27032. q2Z = q1Z + dqZ * (invM1 / (invM1 + invM2));
  27033. q2W = q1W + dqW * (invM1 / (invM1 + invM2));
  27034. let l = q2X * q2X + q2Y * q2Y + q2Z * q2Z + q2W * q2W;
  27035. if(l > 1e-32) {
  27036. l = 1 / Math.sqrt(l);
  27037. }
  27038. slerpQX = q2X * l;
  27039. slerpQY = q2Y * l;
  27040. slerpQZ = q2Z * l;
  27041. slerpQW = q2W * l;
  27042. } else {
  27043. let theta = invM1 / (invM1 + invM2) * Math.acos(d1);
  27044. q2X += q1X * -d1;
  27045. q2Y += q1Y * -d1;
  27046. q2Z += q1Z * -d1;
  27047. q2W += q1W * -d1;
  27048. let l = q2X * q2X + q2Y * q2Y + q2Z * q2Z + q2W * q2W;
  27049. if(l > 1e-32) {
  27050. l = 1 / Math.sqrt(l);
  27051. }
  27052. q2X *= l;
  27053. q2Y *= l;
  27054. q2Z *= l;
  27055. q2W *= l;
  27056. let sin = Math.sin(theta);
  27057. let cos = Math.cos(theta);
  27058. q1X *= cos;
  27059. q1Y *= cos;
  27060. q1Z *= cos;
  27061. q1W *= cos;
  27062. slerpQX = q1X + q2X * sin;
  27063. slerpQY = q1Y + q2Y * sin;
  27064. slerpQZ = q1Z + q2Z * sin;
  27065. slerpQW = q1W + q2W * sin;
  27066. }
  27067. let x = slerpQX;
  27068. let y = slerpQY;
  27069. let z = slerpQZ;
  27070. let w = slerpQW;
  27071. let x2 = 2 * x;
  27072. let y2 = 2 * y;
  27073. let z2 = 2 * z;
  27074. let xx = x * x2;
  27075. let yy = y * y2;
  27076. let zz = z * z2;
  27077. let xy = x * y2;
  27078. let yz = y * z2;
  27079. let xz = x * z2;
  27080. let wx = w * x2;
  27081. let wy = w * y2;
  27082. let wz = w * z2;
  27083. slerpM00 = 1 - yy - zz;
  27084. slerpM01 = xy - wz;
  27085. slerpM02 = xz + wy;
  27086. slerpM10 = xy + wz;
  27087. slerpM11 = 1 - xx - zz;
  27088. slerpM12 = yz - wx;
  27089. slerpM20 = xz - wy;
  27090. slerpM21 = yz + wx;
  27091. slerpM22 = 1 - xx - yy;
  27092. let __tmp__X;
  27093. let __tmp__Y;
  27094. let __tmp__Z;
  27095. __tmp__X = slerpM00 * _this.joint._basisX1X + slerpM01 * _this.joint._basisX1Y + slerpM02 * _this.joint._basisX1Z;
  27096. __tmp__Y = slerpM10 * _this.joint._basisX1X + slerpM11 * _this.joint._basisX1Y + slerpM12 * _this.joint._basisX1Z;
  27097. __tmp__Z = slerpM20 * _this.joint._basisX1X + slerpM21 * _this.joint._basisX1Y + slerpM22 * _this.joint._basisX1Z;
  27098. newXX = __tmp__X;
  27099. newXY = __tmp__Y;
  27100. newXZ = __tmp__Z;
  27101. prevXX = _this.xX;
  27102. prevXY = _this.xY;
  27103. prevXZ = _this.xZ;
  27104. prevYX = _this.yX;
  27105. prevYY = _this.yY;
  27106. prevYZ = _this.yZ;
  27107. let d2 = prevXX * newXX + prevXY * newXY + prevXZ * newXZ;
  27108. if(d2 < -0.999999999) {
  27109. let vX;
  27110. let vY;
  27111. let vZ;
  27112. let x1 = prevXX;
  27113. let y1 = prevXY;
  27114. let z1 = prevXZ;
  27115. let x2 = x1 * x1;
  27116. let y2 = y1 * y1;
  27117. let z2 = z1 * z1;
  27118. let d;
  27119. if(x2 < y2) {
  27120. if(x2 < z2) {
  27121. d = 1 / Math.sqrt(y2 + z2);
  27122. vX = 0;
  27123. vY = z1 * d;
  27124. vZ = -y1 * d;
  27125. } else {
  27126. d = 1 / Math.sqrt(x2 + y2);
  27127. vX = y1 * d;
  27128. vY = -x1 * d;
  27129. vZ = 0;
  27130. }
  27131. } else if(y2 < z2) {
  27132. d = 1 / Math.sqrt(z2 + x2);
  27133. vX = -z1 * d;
  27134. vY = 0;
  27135. vZ = x1 * d;
  27136. } else {
  27137. d = 1 / Math.sqrt(x2 + y2);
  27138. vX = y1 * d;
  27139. vY = -x1 * d;
  27140. vZ = 0;
  27141. }
  27142. slerpQX = vX;
  27143. slerpQY = vY;
  27144. slerpQZ = vZ;
  27145. slerpQW = 0;
  27146. } else {
  27147. let cX;
  27148. let cY;
  27149. let cZ;
  27150. cX = prevXY * newXZ - prevXZ * newXY;
  27151. cY = prevXZ * newXX - prevXX * newXZ;
  27152. cZ = prevXX * newXY - prevXY * newXX;
  27153. let w = Math.sqrt((1 + d2) * 0.5);
  27154. d2 = 0.5 / w;
  27155. cX *= d2;
  27156. cY *= d2;
  27157. cZ *= d2;
  27158. slerpQX = cX;
  27159. slerpQY = cY;
  27160. slerpQZ = cZ;
  27161. slerpQW = w;
  27162. }
  27163. let x1 = slerpQX;
  27164. let y1 = slerpQY;
  27165. let z1 = slerpQZ;
  27166. let w1 = slerpQW;
  27167. let x21 = 2 * x1;
  27168. let y21 = 2 * y1;
  27169. let z21 = 2 * z1;
  27170. let xx1 = x1 * x21;
  27171. let yy1 = y1 * y21;
  27172. let zz1 = z1 * z21;
  27173. let xy1 = x1 * y21;
  27174. let yz1 = y1 * z21;
  27175. let xz1 = x1 * z21;
  27176. let wx1 = w1 * x21;
  27177. let wy1 = w1 * y21;
  27178. let wz1 = w1 * z21;
  27179. slerpM00 = 1 - yy1 - zz1;
  27180. slerpM01 = xy1 - wz1;
  27181. slerpM02 = xz1 + wy1;
  27182. slerpM10 = xy1 + wz1;
  27183. slerpM11 = 1 - xx1 - zz1;
  27184. slerpM12 = yz1 - wx1;
  27185. slerpM20 = xz1 - wy1;
  27186. slerpM21 = yz1 + wx1;
  27187. slerpM22 = 1 - xx1 - yy1;
  27188. let __tmp__X1;
  27189. let __tmp__Y1;
  27190. let __tmp__Z1;
  27191. __tmp__X1 = slerpM00 * prevYX + slerpM01 * prevYY + slerpM02 * prevYZ;
  27192. __tmp__Y1 = slerpM10 * prevYX + slerpM11 * prevYY + slerpM12 * prevYZ;
  27193. __tmp__Z1 = slerpM20 * prevYX + slerpM21 * prevYY + slerpM22 * prevYZ;
  27194. newYX = __tmp__X1;
  27195. newYY = __tmp__Y1;
  27196. newYZ = __tmp__Z1;
  27197. newZX = newXY * newYZ - newXZ * newYY;
  27198. newZY = newXZ * newYX - newXX * newYZ;
  27199. newZZ = newXX * newYY - newXY * newYX;
  27200. if(newZX * newZX + newZY * newZY + newZZ * newZZ > 1e-6) {
  27201. let l = newZX * newZX + newZY * newZY + newZZ * newZZ;
  27202. if(l > 0) {
  27203. l = 1 / Math.sqrt(l);
  27204. }
  27205. newZX *= l;
  27206. newZY *= l;
  27207. newZZ *= l;
  27208. } else {
  27209. let x1 = newXX;
  27210. let y1 = newXY;
  27211. let z1 = newXZ;
  27212. let x2 = x1 * x1;
  27213. let y2 = y1 * y1;
  27214. let z2 = z1 * z1;
  27215. let d;
  27216. if(x2 < y2) {
  27217. if(x2 < z2) {
  27218. d = 1 / Math.sqrt(y2 + z2);
  27219. newZX = 0;
  27220. newZY = z1 * d;
  27221. newZZ = -y1 * d;
  27222. } else {
  27223. d = 1 / Math.sqrt(x2 + y2);
  27224. newZX = y1 * d;
  27225. newZY = -x1 * d;
  27226. newZZ = 0;
  27227. }
  27228. } else if(y2 < z2) {
  27229. d = 1 / Math.sqrt(z2 + x2);
  27230. newZX = -z1 * d;
  27231. newZY = 0;
  27232. newZZ = x1 * d;
  27233. } else {
  27234. d = 1 / Math.sqrt(x2 + y2);
  27235. newZX = y1 * d;
  27236. newZY = -x1 * d;
  27237. newZZ = 0;
  27238. }
  27239. }
  27240. newYX = newZY * newXZ - newZZ * newXY;
  27241. newYY = newZZ * newXX - newZX * newXZ;
  27242. newYZ = newZX * newXY - newZY * newXX;
  27243. _this.xX = newXX;
  27244. _this.xY = newXY;
  27245. _this.xZ = newXZ;
  27246. _this.yX = newYX;
  27247. _this.yY = newYY;
  27248. _this.yZ = newYZ;
  27249. _this.zX = newZX;
  27250. _this.zY = newZY;
  27251. _this.zZ = newZZ;
  27252. let angErrorX;
  27253. let angErrorY;
  27254. let angErrorZ;
  27255. angErrorX = this._basisX1Y * this._basisX2Z - this._basisX1Z * this._basisX2Y;
  27256. angErrorY = this._basisX1Z * this._basisX2X - this._basisX1X * this._basisX2Z;
  27257. angErrorZ = this._basisX1X * this._basisX2Y - this._basisX1Y * this._basisX2X;
  27258. let cos = this._basisX1X * this._basisX2X + this._basisX1Y * this._basisX2Y + this._basisX1Z * this._basisX2Z;
  27259. let theta = cos <= -1 ? 3.14159265358979 : cos >= 1 ? 0 : Math.acos(cos);
  27260. let l = angErrorX * angErrorX + angErrorY * angErrorY + angErrorZ * angErrorZ;
  27261. if(l > 0) {
  27262. l = 1 / Math.sqrt(l);
  27263. }
  27264. angErrorX *= l;
  27265. angErrorY *= l;
  27266. angErrorZ *= l;
  27267. angErrorX *= theta;
  27268. angErrorY *= theta;
  27269. angErrorZ *= theta;
  27270. this.angularErrorY = angErrorX * this._basis.yX + angErrorY * this._basis.yY + angErrorZ * this._basis.yZ;
  27271. this.angularErrorZ = angErrorX * this._basis.zX + angErrorY * this._basis.zY + angErrorZ * this._basis.zZ;
  27272. let perpCrossX;
  27273. let perpCrossY;
  27274. let perpCrossZ;
  27275. perpCrossX = this._basisY1Y * this._basisY2Z - this._basisY1Z * this._basisY2Y;
  27276. perpCrossY = this._basisY1Z * this._basisY2X - this._basisY1X * this._basisY2Z;
  27277. perpCrossZ = this._basisY1X * this._basisY2Y - this._basisY1Y * this._basisY2X;
  27278. cos = this._basisY1X * this._basisY2X + this._basisY1Y * this._basisY2Y + this._basisY1Z * this._basisY2Z;
  27279. this.angle = cos <= -1 ? 3.14159265358979 : cos >= 1 ? 0 : Math.acos(cos);
  27280. if(perpCrossX * this._basis.xX + perpCrossY * this._basis.xY + perpCrossZ * this._basis.xZ < 0) {
  27281. this.angle = -this.angle;
  27282. }
  27283. this.linearErrorX = this._anchor2X - this._anchor1X;
  27284. this.linearErrorY = this._anchor2Y - this._anchor1Y;
  27285. this.linearErrorZ = this._anchor2Z - this._anchor1Z;
  27286. }
  27287. _getVelocitySolverInfo(timeStep,info) {
  27288. super._getVelocitySolverInfo(timeStep,info);
  27289. this.getInfo(info,timeStep,false);
  27290. }
  27291. _getPositionSolverInfo(info) {
  27292. super._getPositionSolverInfo(info);
  27293. this.getInfo(info,null,true);
  27294. }
  27295. getAxis1() {
  27296. let v = new oimo.common.Vec3();
  27297. v.x = this._basisX1X;
  27298. v.y = this._basisX1Y;
  27299. v.z = this._basisX1Z;
  27300. return v;
  27301. }
  27302. getAxis2() {
  27303. let v = new oimo.common.Vec3();
  27304. v.x = this._basisX2X;
  27305. v.y = this._basisX2Y;
  27306. v.z = this._basisX2Z;
  27307. return v;
  27308. }
  27309. getAxis1To(axis) {
  27310. axis.x = this._basisX1X;
  27311. axis.y = this._basisX1Y;
  27312. axis.z = this._basisX1Z;
  27313. }
  27314. getAxis2To(axis) {
  27315. axis.x = this._basisX2X;
  27316. axis.y = this._basisX2Y;
  27317. axis.z = this._basisX2Z;
  27318. }
  27319. getLocalAxis1() {
  27320. let v = new oimo.common.Vec3();
  27321. v.x = this._localBasisX1X;
  27322. v.y = this._localBasisX1Y;
  27323. v.z = this._localBasisX1Z;
  27324. return v;
  27325. }
  27326. getLocalAxis2() {
  27327. let v = new oimo.common.Vec3();
  27328. v.x = this._localBasisX2X;
  27329. v.y = this._localBasisX2Y;
  27330. v.z = this._localBasisX2Z;
  27331. return v;
  27332. }
  27333. getLocalAxis1To(axis) {
  27334. axis.x = this._localBasisX1X;
  27335. axis.y = this._localBasisX1Y;
  27336. axis.z = this._localBasisX1Z;
  27337. }
  27338. getLocalAxis2To(axis) {
  27339. axis.x = this._localBasisX2X;
  27340. axis.y = this._localBasisX2Y;
  27341. axis.z = this._localBasisX2Z;
  27342. }
  27343. getSpringDamper() {
  27344. return this._sd;
  27345. }
  27346. getLimitMotor() {
  27347. return this._lm;
  27348. }
  27349. getAngle() {
  27350. return this.angle;
  27351. }
  27352. }
  27353. oimo.dynamics.constraint.joint.RevoluteJointConfig = class oimo_dynamics_constraint_joint_RevoluteJointConfig extends oimo.dynamics.constraint.joint.JointConfig {
  27354. constructor() {
  27355. super();
  27356. this.localAxis1 = new oimo.common.Vec3(1,0,0);
  27357. this.localAxis2 = new oimo.common.Vec3(1,0,0);
  27358. this.springDamper = new oimo.dynamics.constraint.joint.SpringDamper();
  27359. this.limitMotor = new oimo.dynamics.constraint.joint.RotationalLimitMotor();
  27360. }
  27361. init(rigidBody1,rigidBody2,worldAnchor,worldAxis) {
  27362. this._init(rigidBody1,rigidBody2,worldAnchor);
  27363. let localVector = this.localAxis1;
  27364. let vX;
  27365. let vY;
  27366. let vZ;
  27367. vX = worldAxis.x;
  27368. vY = worldAxis.y;
  27369. vZ = worldAxis.z;
  27370. let __tmp__X;
  27371. let __tmp__Y;
  27372. let __tmp__Z;
  27373. __tmp__X = rigidBody1._transform._rotation00 * vX + rigidBody1._transform._rotation10 * vY + rigidBody1._transform._rotation20 * vZ;
  27374. __tmp__Y = rigidBody1._transform._rotation01 * vX + rigidBody1._transform._rotation11 * vY + rigidBody1._transform._rotation21 * vZ;
  27375. __tmp__Z = rigidBody1._transform._rotation02 * vX + rigidBody1._transform._rotation12 * vY + rigidBody1._transform._rotation22 * vZ;
  27376. vX = __tmp__X;
  27377. vY = __tmp__Y;
  27378. vZ = __tmp__Z;
  27379. localVector.x = vX;
  27380. localVector.y = vY;
  27381. localVector.z = vZ;
  27382. let localVector1 = this.localAxis2;
  27383. let vX1;
  27384. let vY1;
  27385. let vZ1;
  27386. vX1 = worldAxis.x;
  27387. vY1 = worldAxis.y;
  27388. vZ1 = worldAxis.z;
  27389. let __tmp__X1;
  27390. let __tmp__Y1;
  27391. let __tmp__Z1;
  27392. __tmp__X1 = rigidBody2._transform._rotation00 * vX1 + rigidBody2._transform._rotation10 * vY1 + rigidBody2._transform._rotation20 * vZ1;
  27393. __tmp__Y1 = rigidBody2._transform._rotation01 * vX1 + rigidBody2._transform._rotation11 * vY1 + rigidBody2._transform._rotation21 * vZ1;
  27394. __tmp__Z1 = rigidBody2._transform._rotation02 * vX1 + rigidBody2._transform._rotation12 * vY1 + rigidBody2._transform._rotation22 * vZ1;
  27395. vX1 = __tmp__X1;
  27396. vY1 = __tmp__Y1;
  27397. vZ1 = __tmp__Z1;
  27398. localVector1.x = vX1;
  27399. localVector1.y = vY1;
  27400. localVector1.z = vZ1;
  27401. return this;
  27402. }
  27403. }
  27404. oimo.dynamics.constraint.joint.RotationalLimitMotor = class oimo_dynamics_constraint_joint_RotationalLimitMotor {
  27405. constructor() {
  27406. this.lowerLimit = 1;
  27407. this.upperLimit = 0;
  27408. this.motorTorque = 0;
  27409. }
  27410. setLimits(lower,upper) {
  27411. this.lowerLimit = lower;
  27412. this.upperLimit = upper;
  27413. return this;
  27414. }
  27415. setMotor(speed,torque) {
  27416. this.motorSpeed = speed;
  27417. this.motorTorque = torque;
  27418. return this;
  27419. }
  27420. clone() {
  27421. let lm = new oimo.dynamics.constraint.joint.RotationalLimitMotor();
  27422. lm.lowerLimit = this.lowerLimit;
  27423. lm.upperLimit = this.upperLimit;
  27424. lm.motorSpeed = this.motorSpeed;
  27425. lm.motorTorque = this.motorTorque;
  27426. return lm;
  27427. }
  27428. }
  27429. oimo.dynamics.constraint.joint.SphericalJoint = class oimo_dynamics_constraint_joint_SphericalJoint extends oimo.dynamics.constraint.joint.Joint {
  27430. constructor(config) {
  27431. super(config,0);
  27432. this._sd = config.springDamper.clone();
  27433. }
  27434. getInfo(info,timeStep,isPositionPart) {
  27435. if(this._sd.frequency > 0 && isPositionPart) {
  27436. return;
  27437. }
  27438. let errorX;
  27439. let errorY;
  27440. let errorZ;
  27441. errorX = this._anchor2X - this._anchor1X;
  27442. errorY = this._anchor2Y - this._anchor1Y;
  27443. errorZ = this._anchor2Z - this._anchor1Z;
  27444. let cfm;
  27445. let erp;
  27446. if(this._sd.frequency > 0) {
  27447. let omega = 6.28318530717958 * this._sd.frequency;
  27448. let zeta = this._sd.dampingRatio;
  27449. if(zeta < oimo.common.Setting.minSpringDamperDampingRatio) {
  27450. zeta = oimo.common.Setting.minSpringDamperDampingRatio;
  27451. }
  27452. let h = timeStep.dt;
  27453. let c = 2 * zeta * omega;
  27454. let k = omega * omega;
  27455. if(this._sd.useSymplecticEuler) {
  27456. cfm = 1 / (h * c);
  27457. erp = k / c;
  27458. } else {
  27459. cfm = 1 / (h * (h * k + c));
  27460. erp = k / (h * k + c);
  27461. }
  27462. cfm *= this._b1._invMass + this._b2._invMass;
  27463. } else {
  27464. cfm = 0;
  27465. erp = this.getErp(timeStep,isPositionPart);
  27466. }
  27467. let linearRhsX;
  27468. let linearRhsY;
  27469. let linearRhsZ;
  27470. linearRhsX = errorX * erp;
  27471. linearRhsY = errorY * erp;
  27472. linearRhsZ = errorZ * erp;
  27473. let crossR100;
  27474. let crossR101;
  27475. let crossR102;
  27476. let crossR110;
  27477. let crossR111;
  27478. let crossR112;
  27479. let crossR120;
  27480. let crossR121;
  27481. let crossR122;
  27482. let crossR200;
  27483. let crossR201;
  27484. let crossR202;
  27485. let crossR210;
  27486. let crossR211;
  27487. let crossR212;
  27488. let crossR220;
  27489. let crossR221;
  27490. let crossR222;
  27491. crossR100 = 0;
  27492. crossR101 = -this._relativeAnchor1Z;
  27493. crossR102 = this._relativeAnchor1Y;
  27494. crossR110 = this._relativeAnchor1Z;
  27495. crossR111 = 0;
  27496. crossR112 = -this._relativeAnchor1X;
  27497. crossR120 = -this._relativeAnchor1Y;
  27498. crossR121 = this._relativeAnchor1X;
  27499. crossR122 = 0;
  27500. crossR200 = 0;
  27501. crossR201 = -this._relativeAnchor2Z;
  27502. crossR202 = this._relativeAnchor2Y;
  27503. crossR210 = this._relativeAnchor2Z;
  27504. crossR211 = 0;
  27505. crossR212 = -this._relativeAnchor2X;
  27506. crossR220 = -this._relativeAnchor2Y;
  27507. crossR221 = this._relativeAnchor2X;
  27508. crossR222 = 0;
  27509. crossR100 = -crossR100;
  27510. crossR101 = -crossR101;
  27511. crossR102 = -crossR102;
  27512. crossR110 = -crossR110;
  27513. crossR111 = -crossR111;
  27514. crossR112 = -crossR112;
  27515. crossR120 = -crossR120;
  27516. crossR121 = -crossR121;
  27517. crossR122 = -crossR122;
  27518. crossR200 = -crossR200;
  27519. crossR201 = -crossR201;
  27520. crossR202 = -crossR202;
  27521. crossR210 = -crossR210;
  27522. crossR211 = -crossR211;
  27523. crossR212 = -crossR212;
  27524. crossR220 = -crossR220;
  27525. crossR221 = -crossR221;
  27526. crossR222 = -crossR222;
  27527. let impulse = this._impulses[0];
  27528. let row = info.rows[info.numRows++];
  27529. let _this = row.jacobian;
  27530. _this.lin1X = 0;
  27531. _this.lin1Y = 0;
  27532. _this.lin1Z = 0;
  27533. _this.lin2X = 0;
  27534. _this.lin2Y = 0;
  27535. _this.lin2Z = 0;
  27536. _this.ang1X = 0;
  27537. _this.ang1Y = 0;
  27538. _this.ang1Z = 0;
  27539. _this.ang2X = 0;
  27540. _this.ang2Y = 0;
  27541. _this.ang2Z = 0;
  27542. row.rhs = 0;
  27543. row.cfm = 0;
  27544. row.minImpulse = 0;
  27545. row.maxImpulse = 0;
  27546. row.motorSpeed = 0;
  27547. row.motorMaxImpulse = 0;
  27548. row.impulse = null;
  27549. row.impulse = impulse;
  27550. row.rhs = linearRhsX;
  27551. row.cfm = cfm;
  27552. row.minImpulse = -1e65536;
  27553. row.maxImpulse = 1e65536;
  27554. let j = row.jacobian;
  27555. j.lin1X = 1;
  27556. j.lin1Y = 0;
  27557. j.lin1Z = 0;
  27558. j.lin2X = 1;
  27559. j.lin2Y = 0;
  27560. j.lin2Z = 0;
  27561. j.ang1X = crossR100;
  27562. j.ang1Y = crossR101;
  27563. j.ang1Z = crossR102;
  27564. j.ang2X = crossR200;
  27565. j.ang2Y = crossR201;
  27566. j.ang2Z = crossR202;
  27567. let impulse1 = this._impulses[1];
  27568. let row1 = info.rows[info.numRows++];
  27569. let _this1 = row1.jacobian;
  27570. _this1.lin1X = 0;
  27571. _this1.lin1Y = 0;
  27572. _this1.lin1Z = 0;
  27573. _this1.lin2X = 0;
  27574. _this1.lin2Y = 0;
  27575. _this1.lin2Z = 0;
  27576. _this1.ang1X = 0;
  27577. _this1.ang1Y = 0;
  27578. _this1.ang1Z = 0;
  27579. _this1.ang2X = 0;
  27580. _this1.ang2Y = 0;
  27581. _this1.ang2Z = 0;
  27582. row1.rhs = 0;
  27583. row1.cfm = 0;
  27584. row1.minImpulse = 0;
  27585. row1.maxImpulse = 0;
  27586. row1.motorSpeed = 0;
  27587. row1.motorMaxImpulse = 0;
  27588. row1.impulse = null;
  27589. row1.impulse = impulse1;
  27590. row1.rhs = linearRhsY;
  27591. row1.cfm = cfm;
  27592. row1.minImpulse = -1e65536;
  27593. row1.maxImpulse = 1e65536;
  27594. j = row1.jacobian;
  27595. j.lin1X = 0;
  27596. j.lin1Y = 1;
  27597. j.lin1Z = 0;
  27598. j.lin2X = 0;
  27599. j.lin2Y = 1;
  27600. j.lin2Z = 0;
  27601. j.ang1X = crossR110;
  27602. j.ang1Y = crossR111;
  27603. j.ang1Z = crossR112;
  27604. j.ang2X = crossR210;
  27605. j.ang2Y = crossR211;
  27606. j.ang2Z = crossR212;
  27607. let impulse2 = this._impulses[2];
  27608. let row2 = info.rows[info.numRows++];
  27609. let _this2 = row2.jacobian;
  27610. _this2.lin1X = 0;
  27611. _this2.lin1Y = 0;
  27612. _this2.lin1Z = 0;
  27613. _this2.lin2X = 0;
  27614. _this2.lin2Y = 0;
  27615. _this2.lin2Z = 0;
  27616. _this2.ang1X = 0;
  27617. _this2.ang1Y = 0;
  27618. _this2.ang1Z = 0;
  27619. _this2.ang2X = 0;
  27620. _this2.ang2Y = 0;
  27621. _this2.ang2Z = 0;
  27622. row2.rhs = 0;
  27623. row2.cfm = 0;
  27624. row2.minImpulse = 0;
  27625. row2.maxImpulse = 0;
  27626. row2.motorSpeed = 0;
  27627. row2.motorMaxImpulse = 0;
  27628. row2.impulse = null;
  27629. row2.impulse = impulse2;
  27630. row2.rhs = linearRhsZ;
  27631. row2.cfm = cfm;
  27632. row2.minImpulse = -1e65536;
  27633. row2.maxImpulse = 1e65536;
  27634. j = row2.jacobian;
  27635. j.lin1X = 0;
  27636. j.lin1Y = 0;
  27637. j.lin1Z = 1;
  27638. j.lin2X = 0;
  27639. j.lin2Y = 0;
  27640. j.lin2Z = 1;
  27641. j.ang1X = crossR120;
  27642. j.ang1Y = crossR121;
  27643. j.ang1Z = crossR122;
  27644. j.ang2X = crossR220;
  27645. j.ang2Y = crossR221;
  27646. j.ang2Z = crossR222;
  27647. }
  27648. _getVelocitySolverInfo(timeStep,info) {
  27649. super._getVelocitySolverInfo(timeStep,info);
  27650. this.getInfo(info,timeStep,false);
  27651. }
  27652. _getPositionSolverInfo(info) {
  27653. super._getPositionSolverInfo(info);
  27654. this.getInfo(info,null,true);
  27655. }
  27656. getSpringDamper() {
  27657. return this._sd;
  27658. }
  27659. }
  27660. oimo.dynamics.constraint.joint.SphericalJointConfig = class oimo_dynamics_constraint_joint_SphericalJointConfig extends oimo.dynamics.constraint.joint.JointConfig {
  27661. constructor() {
  27662. super();
  27663. this.springDamper = new oimo.dynamics.constraint.joint.SpringDamper();
  27664. }
  27665. init(rigidBody1,rigidBody2,worldAnchor) {
  27666. this._init(rigidBody1,rigidBody2,worldAnchor);
  27667. return this;
  27668. }
  27669. }
  27670. oimo.dynamics.constraint.joint.SpringDamper = class oimo_dynamics_constraint_joint_SpringDamper {
  27671. constructor() {
  27672. this.frequency = 0;
  27673. this.dampingRatio = 0;
  27674. this.useSymplecticEuler = false;
  27675. }
  27676. setSpring(frequency,dampingRatio) {
  27677. this.frequency = frequency;
  27678. this.dampingRatio = dampingRatio;
  27679. return this;
  27680. }
  27681. setSymplecticEuler(useSymplecticEuler) {
  27682. this.useSymplecticEuler = useSymplecticEuler;
  27683. return this;
  27684. }
  27685. clone() {
  27686. let sd = new oimo.dynamics.constraint.joint.SpringDamper();
  27687. sd.frequency = this.frequency;
  27688. sd.dampingRatio = this.dampingRatio;
  27689. sd.useSymplecticEuler = this.useSymplecticEuler;
  27690. return sd;
  27691. }
  27692. }
  27693. oimo.dynamics.constraint.joint.TranslationalLimitMotor = class oimo_dynamics_constraint_joint_TranslationalLimitMotor {
  27694. constructor() {
  27695. this.lowerLimit = 1;
  27696. this.upperLimit = 0;
  27697. this.motorForce = 0;
  27698. }
  27699. setLimits(lower,upper) {
  27700. this.lowerLimit = lower;
  27701. this.upperLimit = upper;
  27702. return this;
  27703. }
  27704. setMotor(speed,force) {
  27705. this.motorSpeed = speed;
  27706. this.motorForce = force;
  27707. return this;
  27708. }
  27709. clone() {
  27710. let lm = new oimo.dynamics.constraint.joint.TranslationalLimitMotor();
  27711. lm.lowerLimit = this.lowerLimit;
  27712. lm.upperLimit = this.upperLimit;
  27713. lm.motorSpeed = this.motorSpeed;
  27714. lm.motorForce = this.motorForce;
  27715. return lm;
  27716. }
  27717. }
  27718. oimo.dynamics.constraint.joint.UniversalJoint = class oimo_dynamics_constraint_joint_UniversalJoint extends oimo.dynamics.constraint.joint.Joint {
  27719. constructor(config) {
  27720. super(config,oimo.dynamics.constraint.joint.JointType.UNIVERSAL);
  27721. let v = config.localAxis1;
  27722. this._localBasisX1X = v.x;
  27723. this._localBasisX1Y = v.y;
  27724. this._localBasisX1Z = v.z;
  27725. let v1 = config.localAxis2;
  27726. this._localBasisZ2X = v1.x;
  27727. this._localBasisZ2Y = v1.y;
  27728. this._localBasisZ2Z = v1.z;
  27729. this.buildLocalBasesFromX1Z2();
  27730. this._angleX = 0;
  27731. this._angleY = 0;
  27732. this._angleZ = 0;
  27733. this.xSingular = false;
  27734. this.ySingular = false;
  27735. this.zSingular = false;
  27736. this._sd1 = config.springDamper1.clone();
  27737. this._sd2 = config.springDamper2.clone();
  27738. this._lm1 = config.limitMotor1.clone();
  27739. this._lm2 = config.limitMotor2.clone();
  27740. }
  27741. getInfo(info,timeStep,isPositionPart) {
  27742. let erp = this.getErp(timeStep,isPositionPart);
  27743. let linearRhsX;
  27744. let linearRhsY;
  27745. let linearRhsZ;
  27746. linearRhsX = this.linearErrorX * erp;
  27747. linearRhsY = this.linearErrorY * erp;
  27748. linearRhsZ = this.linearErrorZ * erp;
  27749. let angRhsY = this._angleY * erp;
  27750. let crossR100;
  27751. let crossR101;
  27752. let crossR102;
  27753. let crossR110;
  27754. let crossR111;
  27755. let crossR112;
  27756. let crossR120;
  27757. let crossR121;
  27758. let crossR122;
  27759. let crossR200;
  27760. let crossR201;
  27761. let crossR202;
  27762. let crossR210;
  27763. let crossR211;
  27764. let crossR212;
  27765. let crossR220;
  27766. let crossR221;
  27767. let crossR222;
  27768. crossR100 = 0;
  27769. crossR101 = -this._relativeAnchor1Z;
  27770. crossR102 = this._relativeAnchor1Y;
  27771. crossR110 = this._relativeAnchor1Z;
  27772. crossR111 = 0;
  27773. crossR112 = -this._relativeAnchor1X;
  27774. crossR120 = -this._relativeAnchor1Y;
  27775. crossR121 = this._relativeAnchor1X;
  27776. crossR122 = 0;
  27777. crossR200 = 0;
  27778. crossR201 = -this._relativeAnchor2Z;
  27779. crossR202 = this._relativeAnchor2Y;
  27780. crossR210 = this._relativeAnchor2Z;
  27781. crossR211 = 0;
  27782. crossR212 = -this._relativeAnchor2X;
  27783. crossR220 = -this._relativeAnchor2Y;
  27784. crossR221 = this._relativeAnchor2X;
  27785. crossR222 = 0;
  27786. crossR100 = -crossR100;
  27787. crossR101 = -crossR101;
  27788. crossR102 = -crossR102;
  27789. crossR110 = -crossR110;
  27790. crossR111 = -crossR111;
  27791. crossR112 = -crossR112;
  27792. crossR120 = -crossR120;
  27793. crossR121 = -crossR121;
  27794. crossR122 = -crossR122;
  27795. crossR200 = -crossR200;
  27796. crossR201 = -crossR201;
  27797. crossR202 = -crossR202;
  27798. crossR210 = -crossR210;
  27799. crossR211 = -crossR211;
  27800. crossR212 = -crossR212;
  27801. crossR220 = -crossR220;
  27802. crossR221 = -crossR221;
  27803. crossR222 = -crossR222;
  27804. let motorMassX = this.computeEffectiveInertiaMoment(this._axisXX,this._axisXY,this._axisXZ);
  27805. let motorMassZ = this.computeEffectiveInertiaMoment(this._axisZX,this._axisZY,this._axisZZ);
  27806. let impulse = this._impulses[0];
  27807. let row = info.rows[info.numRows++];
  27808. let _this = row.jacobian;
  27809. _this.lin1X = 0;
  27810. _this.lin1Y = 0;
  27811. _this.lin1Z = 0;
  27812. _this.lin2X = 0;
  27813. _this.lin2Y = 0;
  27814. _this.lin2Z = 0;
  27815. _this.ang1X = 0;
  27816. _this.ang1Y = 0;
  27817. _this.ang1Z = 0;
  27818. _this.ang2X = 0;
  27819. _this.ang2Y = 0;
  27820. _this.ang2Z = 0;
  27821. row.rhs = 0;
  27822. row.cfm = 0;
  27823. row.minImpulse = 0;
  27824. row.maxImpulse = 0;
  27825. row.motorSpeed = 0;
  27826. row.motorMaxImpulse = 0;
  27827. row.impulse = null;
  27828. row.impulse = impulse;
  27829. row.rhs = linearRhsX;
  27830. row.cfm = 0;
  27831. row.minImpulse = -1e65536;
  27832. row.maxImpulse = 1e65536;
  27833. let j = row.jacobian;
  27834. j.lin1X = 1;
  27835. j.lin1Y = 0;
  27836. j.lin1Z = 0;
  27837. j.lin2X = 1;
  27838. j.lin2Y = 0;
  27839. j.lin2Z = 0;
  27840. j.ang1X = crossR100;
  27841. j.ang1Y = crossR101;
  27842. j.ang1Z = crossR102;
  27843. j.ang2X = crossR200;
  27844. j.ang2Y = crossR201;
  27845. j.ang2Z = crossR202;
  27846. let impulse1 = this._impulses[1];
  27847. let row1 = info.rows[info.numRows++];
  27848. let _this1 = row1.jacobian;
  27849. _this1.lin1X = 0;
  27850. _this1.lin1Y = 0;
  27851. _this1.lin1Z = 0;
  27852. _this1.lin2X = 0;
  27853. _this1.lin2Y = 0;
  27854. _this1.lin2Z = 0;
  27855. _this1.ang1X = 0;
  27856. _this1.ang1Y = 0;
  27857. _this1.ang1Z = 0;
  27858. _this1.ang2X = 0;
  27859. _this1.ang2Y = 0;
  27860. _this1.ang2Z = 0;
  27861. row1.rhs = 0;
  27862. row1.cfm = 0;
  27863. row1.minImpulse = 0;
  27864. row1.maxImpulse = 0;
  27865. row1.motorSpeed = 0;
  27866. row1.motorMaxImpulse = 0;
  27867. row1.impulse = null;
  27868. row1.impulse = impulse1;
  27869. row1.rhs = linearRhsY;
  27870. row1.cfm = 0;
  27871. row1.minImpulse = -1e65536;
  27872. row1.maxImpulse = 1e65536;
  27873. j = row1.jacobian;
  27874. j.lin1X = 0;
  27875. j.lin1Y = 1;
  27876. j.lin1Z = 0;
  27877. j.lin2X = 0;
  27878. j.lin2Y = 1;
  27879. j.lin2Z = 0;
  27880. j.ang1X = crossR110;
  27881. j.ang1Y = crossR111;
  27882. j.ang1Z = crossR112;
  27883. j.ang2X = crossR210;
  27884. j.ang2Y = crossR211;
  27885. j.ang2Z = crossR212;
  27886. let impulse2 = this._impulses[2];
  27887. let row2 = info.rows[info.numRows++];
  27888. let _this2 = row2.jacobian;
  27889. _this2.lin1X = 0;
  27890. _this2.lin1Y = 0;
  27891. _this2.lin1Z = 0;
  27892. _this2.lin2X = 0;
  27893. _this2.lin2Y = 0;
  27894. _this2.lin2Z = 0;
  27895. _this2.ang1X = 0;
  27896. _this2.ang1Y = 0;
  27897. _this2.ang1Z = 0;
  27898. _this2.ang2X = 0;
  27899. _this2.ang2Y = 0;
  27900. _this2.ang2Z = 0;
  27901. row2.rhs = 0;
  27902. row2.cfm = 0;
  27903. row2.minImpulse = 0;
  27904. row2.maxImpulse = 0;
  27905. row2.motorSpeed = 0;
  27906. row2.motorMaxImpulse = 0;
  27907. row2.impulse = null;
  27908. row2.impulse = impulse2;
  27909. row2.rhs = linearRhsZ;
  27910. row2.cfm = 0;
  27911. row2.minImpulse = -1e65536;
  27912. row2.maxImpulse = 1e65536;
  27913. j = row2.jacobian;
  27914. j.lin1X = 0;
  27915. j.lin1Y = 0;
  27916. j.lin1Z = 1;
  27917. j.lin2X = 0;
  27918. j.lin2Y = 0;
  27919. j.lin2Z = 1;
  27920. j.ang1X = crossR120;
  27921. j.ang1Y = crossR121;
  27922. j.ang1Z = crossR122;
  27923. j.ang2X = crossR220;
  27924. j.ang2Y = crossR221;
  27925. j.ang2Z = crossR222;
  27926. if(!this.xSingular && (this._sd1.frequency <= 0 || !isPositionPart)) {
  27927. let impulse = this._impulses[3];
  27928. let row = info.rows[info.numRows++];
  27929. let _this = row.jacobian;
  27930. _this.lin1X = 0;
  27931. _this.lin1Y = 0;
  27932. _this.lin1Z = 0;
  27933. _this.lin2X = 0;
  27934. _this.lin2Y = 0;
  27935. _this.lin2Z = 0;
  27936. _this.ang1X = 0;
  27937. _this.ang1Y = 0;
  27938. _this.ang1Z = 0;
  27939. _this.ang2X = 0;
  27940. _this.ang2Y = 0;
  27941. _this.ang2Z = 0;
  27942. row.rhs = 0;
  27943. row.cfm = 0;
  27944. row.minImpulse = 0;
  27945. row.maxImpulse = 0;
  27946. row.motorSpeed = 0;
  27947. row.motorMaxImpulse = 0;
  27948. row.impulse = null;
  27949. row.impulse = impulse;
  27950. this.setSolverInfoRowAngular(row,this._angleX,this._lm1,motorMassX,this._sd1,timeStep,isPositionPart);
  27951. j = row.jacobian;
  27952. j.ang1X = this._axisXX;
  27953. j.ang1Y = this._axisXY;
  27954. j.ang1Z = this._axisXZ;
  27955. j.ang2X = this._axisXX;
  27956. j.ang2Y = this._axisXY;
  27957. j.ang2Z = this._axisXZ;
  27958. }
  27959. if(!this.ySingular) {
  27960. let impulse = this._impulses[4];
  27961. let row = info.rows[info.numRows++];
  27962. let _this = row.jacobian;
  27963. _this.lin1X = 0;
  27964. _this.lin1Y = 0;
  27965. _this.lin1Z = 0;
  27966. _this.lin2X = 0;
  27967. _this.lin2Y = 0;
  27968. _this.lin2Z = 0;
  27969. _this.ang1X = 0;
  27970. _this.ang1Y = 0;
  27971. _this.ang1Z = 0;
  27972. _this.ang2X = 0;
  27973. _this.ang2Y = 0;
  27974. _this.ang2Z = 0;
  27975. row.rhs = 0;
  27976. row.cfm = 0;
  27977. row.minImpulse = 0;
  27978. row.maxImpulse = 0;
  27979. row.motorSpeed = 0;
  27980. row.motorMaxImpulse = 0;
  27981. row.impulse = null;
  27982. row.impulse = impulse;
  27983. row.rhs = angRhsY;
  27984. row.cfm = 0;
  27985. row.minImpulse = -1e65536;
  27986. row.maxImpulse = 1e65536;
  27987. j = row.jacobian;
  27988. j.ang1X = this._axisYX;
  27989. j.ang1Y = this._axisYY;
  27990. j.ang1Z = this._axisYZ;
  27991. j.ang2X = this._axisYX;
  27992. j.ang2Y = this._axisYY;
  27993. j.ang2Z = this._axisYZ;
  27994. }
  27995. if(!this.zSingular && (this._sd2.frequency <= 0 || !isPositionPart)) {
  27996. let impulse = this._impulses[5];
  27997. let row = info.rows[info.numRows++];
  27998. let _this = row.jacobian;
  27999. _this.lin1X = 0;
  28000. _this.lin1Y = 0;
  28001. _this.lin1Z = 0;
  28002. _this.lin2X = 0;
  28003. _this.lin2Y = 0;
  28004. _this.lin2Z = 0;
  28005. _this.ang1X = 0;
  28006. _this.ang1Y = 0;
  28007. _this.ang1Z = 0;
  28008. _this.ang2X = 0;
  28009. _this.ang2Y = 0;
  28010. _this.ang2Z = 0;
  28011. row.rhs = 0;
  28012. row.cfm = 0;
  28013. row.minImpulse = 0;
  28014. row.maxImpulse = 0;
  28015. row.motorSpeed = 0;
  28016. row.motorMaxImpulse = 0;
  28017. row.impulse = null;
  28018. row.impulse = impulse;
  28019. this.setSolverInfoRowAngular(row,this._angleZ,this._lm2,motorMassZ,this._sd2,timeStep,isPositionPart);
  28020. j = row.jacobian;
  28021. j.ang1X = this._axisZX;
  28022. j.ang1Y = this._axisZY;
  28023. j.ang1Z = this._axisZZ;
  28024. j.ang2X = this._axisZX;
  28025. j.ang2Y = this._axisZY;
  28026. j.ang2Z = this._axisZZ;
  28027. }
  28028. }
  28029. _syncAnchors() {
  28030. super._syncAnchors();
  28031. let angleAxisXX;
  28032. let angleAxisXY;
  28033. let angleAxisXZ;
  28034. let angleAxisYX;
  28035. let angleAxisYY;
  28036. let angleAxisYZ;
  28037. let angleAxisZX;
  28038. let angleAxisZY;
  28039. let angleAxisZZ;
  28040. angleAxisXX = this._basisX1X;
  28041. angleAxisXY = this._basisX1Y;
  28042. angleAxisXZ = this._basisX1Z;
  28043. angleAxisZX = this._basisZ2X;
  28044. angleAxisZY = this._basisZ2Y;
  28045. angleAxisZZ = this._basisZ2Z;
  28046. angleAxisYX = angleAxisZY * angleAxisXZ - angleAxisZZ * angleAxisXY;
  28047. angleAxisYY = angleAxisZZ * angleAxisXX - angleAxisZX * angleAxisXZ;
  28048. angleAxisYZ = angleAxisZX * angleAxisXY - angleAxisZY * angleAxisXX;
  28049. this._axisXX = angleAxisYY * angleAxisZZ - angleAxisYZ * angleAxisZY;
  28050. this._axisXY = angleAxisYZ * angleAxisZX - angleAxisYX * angleAxisZZ;
  28051. this._axisXZ = angleAxisYX * angleAxisZY - angleAxisYY * angleAxisZX;
  28052. this._axisYX = angleAxisYX;
  28053. this._axisYY = angleAxisYY;
  28054. this._axisYZ = angleAxisYZ;
  28055. this._axisZX = angleAxisXY * angleAxisYZ - angleAxisXZ * angleAxisYY;
  28056. this._axisZY = angleAxisXZ * angleAxisYX - angleAxisXX * angleAxisYZ;
  28057. this._axisZZ = angleAxisXX * angleAxisYY - angleAxisXY * angleAxisYX;
  28058. let l = this._axisXX * this._axisXX + this._axisXY * this._axisXY + this._axisXZ * this._axisXZ;
  28059. if(l > 0) {
  28060. l = 1 / Math.sqrt(l);
  28061. }
  28062. this._axisXX *= l;
  28063. this._axisXY *= l;
  28064. this._axisXZ *= l;
  28065. let l1 = this._axisYX * this._axisYX + this._axisYY * this._axisYY + this._axisYZ * this._axisYZ;
  28066. if(l1 > 0) {
  28067. l1 = 1 / Math.sqrt(l1);
  28068. }
  28069. this._axisYX *= l1;
  28070. this._axisYY *= l1;
  28071. this._axisYZ *= l1;
  28072. let l2 = this._axisZX * this._axisZX + this._axisZY * this._axisZY + this._axisZZ * this._axisZZ;
  28073. if(l2 > 0) {
  28074. l2 = 1 / Math.sqrt(l2);
  28075. }
  28076. this._axisZX *= l2;
  28077. this._axisZY *= l2;
  28078. this._axisZZ *= l2;
  28079. this.xSingular = this._axisXX * this._axisXX + this._axisXY * this._axisXY + this._axisXZ * this._axisXZ == 0;
  28080. this.ySingular = this._axisYX * this._axisYX + this._axisYY * this._axisYY + this._axisYZ * this._axisYZ == 0;
  28081. this.zSingular = this._axisZX * this._axisZX + this._axisZY * this._axisZY + this._axisZZ * this._axisZZ == 0;
  28082. let rot100;
  28083. let rot101;
  28084. let rot102;
  28085. let rot110;
  28086. let rot111;
  28087. let rot112;
  28088. let rot120;
  28089. let rot121;
  28090. let rot122;
  28091. let rot200;
  28092. let rot201;
  28093. let rot202;
  28094. let rot210;
  28095. let rot211;
  28096. let rot212;
  28097. let rot220;
  28098. let rot221;
  28099. let rot222;
  28100. rot100 = this._basisX1X;
  28101. rot101 = this._basisY1X;
  28102. rot102 = this._basisZ1X;
  28103. rot110 = this._basisX1Y;
  28104. rot111 = this._basisY1Y;
  28105. rot112 = this._basisZ1Y;
  28106. rot120 = this._basisX1Z;
  28107. rot121 = this._basisY1Z;
  28108. rot122 = this._basisZ1Z;
  28109. rot200 = this._basisX2X;
  28110. rot201 = this._basisY2X;
  28111. rot202 = this._basisZ2X;
  28112. rot210 = this._basisX2Y;
  28113. rot211 = this._basisY2Y;
  28114. rot212 = this._basisZ2Y;
  28115. rot220 = this._basisX2Z;
  28116. rot221 = this._basisY2Z;
  28117. rot222 = this._basisZ2Z;
  28118. let relRot00;
  28119. let relRot01;
  28120. let relRot02;
  28121. let relRot11;
  28122. let relRot12;
  28123. let relRot21;
  28124. let relRot22;
  28125. let __tmp__00;
  28126. let __tmp__01;
  28127. let __tmp__02;
  28128. let __tmp__11;
  28129. let __tmp__12;
  28130. let __tmp__21;
  28131. let __tmp__22;
  28132. __tmp__00 = rot100 * rot200 + rot110 * rot210 + rot120 * rot220;
  28133. __tmp__01 = rot100 * rot201 + rot110 * rot211 + rot120 * rot221;
  28134. __tmp__02 = rot100 * rot202 + rot110 * rot212 + rot120 * rot222;
  28135. __tmp__11 = rot101 * rot201 + rot111 * rot211 + rot121 * rot221;
  28136. __tmp__12 = rot101 * rot202 + rot111 * rot212 + rot121 * rot222;
  28137. __tmp__21 = rot102 * rot201 + rot112 * rot211 + rot122 * rot221;
  28138. __tmp__22 = rot102 * rot202 + rot112 * rot212 + rot122 * rot222;
  28139. relRot00 = __tmp__00;
  28140. relRot01 = __tmp__01;
  28141. relRot02 = __tmp__02;
  28142. relRot11 = __tmp__11;
  28143. relRot12 = __tmp__12;
  28144. relRot21 = __tmp__21;
  28145. relRot22 = __tmp__22;
  28146. let anglesX;
  28147. let anglesY;
  28148. let anglesZ;
  28149. let sy = relRot02;
  28150. if(sy <= -1) {
  28151. let xSubZ = Math.atan2(relRot21,relRot11);
  28152. anglesX = xSubZ * 0.5;
  28153. anglesY = -1.570796326794895;
  28154. anglesZ = -xSubZ * 0.5;
  28155. } else if(sy >= 1) {
  28156. let xAddZ = Math.atan2(relRot21,relRot11);
  28157. anglesX = xAddZ * 0.5;
  28158. anglesY = 1.570796326794895;
  28159. anglesZ = xAddZ * 0.5;
  28160. } else {
  28161. anglesX = Math.atan2(-relRot12,relRot22);
  28162. anglesY = Math.asin(sy);
  28163. anglesZ = Math.atan2(-relRot01,relRot00);
  28164. }
  28165. this._angleX = anglesX;
  28166. this._angleY = anglesY;
  28167. this._angleZ = anglesZ;
  28168. this.linearErrorX = this._anchor2X - this._anchor1X;
  28169. this.linearErrorY = this._anchor2Y - this._anchor1Y;
  28170. this.linearErrorZ = this._anchor2Z - this._anchor1Z;
  28171. }
  28172. _getVelocitySolverInfo(timeStep,info) {
  28173. super._getVelocitySolverInfo(timeStep,info);
  28174. this.getInfo(info,timeStep,false);
  28175. }
  28176. _getPositionSolverInfo(info) {
  28177. super._getPositionSolverInfo(info);
  28178. this.getInfo(info,null,true);
  28179. }
  28180. getAxis1() {
  28181. let v = new oimo.common.Vec3();
  28182. v.x = this._basisX1X;
  28183. v.y = this._basisX1Y;
  28184. v.z = this._basisX1Z;
  28185. return v;
  28186. }
  28187. getAxis2() {
  28188. let v = new oimo.common.Vec3();
  28189. v.x = this._basisZ2X;
  28190. v.y = this._basisZ2Y;
  28191. v.z = this._basisZ2Z;
  28192. return v;
  28193. }
  28194. getAxis1To(axis) {
  28195. axis.x = this._basisX1X;
  28196. axis.y = this._basisX1Y;
  28197. axis.z = this._basisX1Z;
  28198. }
  28199. getAxis2To(axis) {
  28200. axis.x = this._basisZ2X;
  28201. axis.y = this._basisZ2Y;
  28202. axis.z = this._basisZ2Z;
  28203. }
  28204. getLocalAxis1() {
  28205. let v = new oimo.common.Vec3();
  28206. v.x = this._localBasisX1X;
  28207. v.y = this._localBasisX1Y;
  28208. v.z = this._localBasisX1Z;
  28209. return v;
  28210. }
  28211. getLocalAxis2() {
  28212. let v = new oimo.common.Vec3();
  28213. v.x = this._localBasisZ2X;
  28214. v.y = this._localBasisZ2Y;
  28215. v.z = this._localBasisZ2Z;
  28216. return v;
  28217. }
  28218. getLocalAxis1To(axis) {
  28219. axis.x = this._localBasisX1X;
  28220. axis.y = this._localBasisX1Y;
  28221. axis.z = this._localBasisX1Z;
  28222. }
  28223. getLocalAxis2To(axis) {
  28224. axis.x = this._localBasisZ2X;
  28225. axis.y = this._localBasisZ2Y;
  28226. axis.z = this._localBasisZ2Z;
  28227. }
  28228. getSpringDamper1() {
  28229. return this._sd1;
  28230. }
  28231. getSpringDamper2() {
  28232. return this._sd2;
  28233. }
  28234. getLimitMotor1() {
  28235. return this._lm1;
  28236. }
  28237. getLimitMotor2() {
  28238. return this._lm2;
  28239. }
  28240. getAngle1() {
  28241. return this._angleX;
  28242. }
  28243. getAngle2() {
  28244. return this._angleZ;
  28245. }
  28246. }
  28247. oimo.dynamics.constraint.joint.UniversalJointConfig = class oimo_dynamics_constraint_joint_UniversalJointConfig extends oimo.dynamics.constraint.joint.JointConfig {
  28248. constructor() {
  28249. super();
  28250. this.localAxis1 = new oimo.common.Vec3(1,0,0);
  28251. this.localAxis2 = new oimo.common.Vec3(1,0,0);
  28252. this.springDamper1 = new oimo.dynamics.constraint.joint.SpringDamper();
  28253. this.springDamper2 = new oimo.dynamics.constraint.joint.SpringDamper();
  28254. this.limitMotor1 = new oimo.dynamics.constraint.joint.RotationalLimitMotor();
  28255. this.limitMotor2 = new oimo.dynamics.constraint.joint.RotationalLimitMotor();
  28256. }
  28257. init(rigidBody1,rigidBody2,worldAnchor,worldAxis1,worldAxis2) {
  28258. this._init(rigidBody1,rigidBody2,worldAnchor);
  28259. let localVector = this.localAxis1;
  28260. let vX;
  28261. let vY;
  28262. let vZ;
  28263. vX = worldAxis1.x;
  28264. vY = worldAxis1.y;
  28265. vZ = worldAxis1.z;
  28266. let __tmp__X;
  28267. let __tmp__Y;
  28268. let __tmp__Z;
  28269. __tmp__X = rigidBody1._transform._rotation00 * vX + rigidBody1._transform._rotation10 * vY + rigidBody1._transform._rotation20 * vZ;
  28270. __tmp__Y = rigidBody1._transform._rotation01 * vX + rigidBody1._transform._rotation11 * vY + rigidBody1._transform._rotation21 * vZ;
  28271. __tmp__Z = rigidBody1._transform._rotation02 * vX + rigidBody1._transform._rotation12 * vY + rigidBody1._transform._rotation22 * vZ;
  28272. vX = __tmp__X;
  28273. vY = __tmp__Y;
  28274. vZ = __tmp__Z;
  28275. localVector.x = vX;
  28276. localVector.y = vY;
  28277. localVector.z = vZ;
  28278. let localVector1 = this.localAxis2;
  28279. let vX1;
  28280. let vY1;
  28281. let vZ1;
  28282. vX1 = worldAxis2.x;
  28283. vY1 = worldAxis2.y;
  28284. vZ1 = worldAxis2.z;
  28285. let __tmp__X1;
  28286. let __tmp__Y1;
  28287. let __tmp__Z1;
  28288. __tmp__X1 = rigidBody2._transform._rotation00 * vX1 + rigidBody2._transform._rotation10 * vY1 + rigidBody2._transform._rotation20 * vZ1;
  28289. __tmp__Y1 = rigidBody2._transform._rotation01 * vX1 + rigidBody2._transform._rotation11 * vY1 + rigidBody2._transform._rotation21 * vZ1;
  28290. __tmp__Z1 = rigidBody2._transform._rotation02 * vX1 + rigidBody2._transform._rotation12 * vY1 + rigidBody2._transform._rotation22 * vZ1;
  28291. vX1 = __tmp__X1;
  28292. vY1 = __tmp__Y1;
  28293. vZ1 = __tmp__Z1;
  28294. localVector1.x = vX1;
  28295. localVector1.y = vY1;
  28296. localVector1.z = vZ1;
  28297. return this;
  28298. }
  28299. }
  28300. if(!oimo.dynamics.constraint.solver) oimo.dynamics.constraint.solver = {};
  28301. oimo.dynamics.constraint.solver.ConstraintSolverType = class oimo_dynamics_constraint_solver_ConstraintSolverType {
  28302. }
  28303. if(!oimo.dynamics.constraint.solver.common) oimo.dynamics.constraint.solver.common = {};
  28304. oimo.dynamics.constraint.solver.common.ContactSolverMassDataRow = class oimo_dynamics_constraint_solver_common_ContactSolverMassDataRow {
  28305. constructor() {
  28306. this.invMLinN1X = 0;
  28307. this.invMLinN1Y = 0;
  28308. this.invMLinN1Z = 0;
  28309. this.invMLinN2X = 0;
  28310. this.invMLinN2Y = 0;
  28311. this.invMLinN2Z = 0;
  28312. this.invMAngN1X = 0;
  28313. this.invMAngN1Y = 0;
  28314. this.invMAngN1Z = 0;
  28315. this.invMAngN2X = 0;
  28316. this.invMAngN2Y = 0;
  28317. this.invMAngN2Z = 0;
  28318. this.invMLinT1X = 0;
  28319. this.invMLinT1Y = 0;
  28320. this.invMLinT1Z = 0;
  28321. this.invMLinT2X = 0;
  28322. this.invMLinT2Y = 0;
  28323. this.invMLinT2Z = 0;
  28324. this.invMAngT1X = 0;
  28325. this.invMAngT1Y = 0;
  28326. this.invMAngT1Z = 0;
  28327. this.invMAngT2X = 0;
  28328. this.invMAngT2Y = 0;
  28329. this.invMAngT2Z = 0;
  28330. this.invMLinB1X = 0;
  28331. this.invMLinB1Y = 0;
  28332. this.invMLinB1Z = 0;
  28333. this.invMLinB2X = 0;
  28334. this.invMLinB2Y = 0;
  28335. this.invMLinB2Z = 0;
  28336. this.invMAngB1X = 0;
  28337. this.invMAngB1Y = 0;
  28338. this.invMAngB1Z = 0;
  28339. this.invMAngB2X = 0;
  28340. this.invMAngB2Y = 0;
  28341. this.invMAngB2Z = 0;
  28342. this.massN = 0;
  28343. this.massTB00 = 0;
  28344. this.massTB01 = 0;
  28345. this.massTB10 = 0;
  28346. this.massTB11 = 0;
  28347. }
  28348. }
  28349. oimo.dynamics.constraint.solver.common.JointSolverMassDataRow = class oimo_dynamics_constraint_solver_common_JointSolverMassDataRow {
  28350. constructor() {
  28351. this.invMLin1X = 0;
  28352. this.invMLin1Y = 0;
  28353. this.invMLin1Z = 0;
  28354. this.invMLin2X = 0;
  28355. this.invMLin2Y = 0;
  28356. this.invMLin2Z = 0;
  28357. this.invMAng1X = 0;
  28358. this.invMAng1Y = 0;
  28359. this.invMAng1Z = 0;
  28360. this.invMAng2X = 0;
  28361. this.invMAng2Y = 0;
  28362. this.invMAng2Z = 0;
  28363. this.mass = 0;
  28364. this.massWithoutCfm = 0;
  28365. }
  28366. }
  28367. if(!oimo.dynamics.constraint.solver.direct) oimo.dynamics.constraint.solver.direct = {};
  28368. oimo.dynamics.constraint.solver.direct.Boundary = class oimo_dynamics_constraint_solver_direct_Boundary {
  28369. constructor(maxRows) {
  28370. this.iBounded = new Array(maxRows);
  28371. this.iUnbounded = new Array(maxRows);
  28372. this.signs = new Array(maxRows);
  28373. this.b = new Array(maxRows);
  28374. this.numBounded = 0;
  28375. this.numUnbounded = 0;
  28376. this.matrixId = 0;
  28377. }
  28378. init(buildInfo) {
  28379. this.numBounded = buildInfo.numBounded;
  28380. let _g = 0;
  28381. let _g1 = this.numBounded;
  28382. while(_g < _g1) {
  28383. let i = _g++;
  28384. this.iBounded[i] = buildInfo.iBounded[i];
  28385. this.signs[i] = buildInfo.signs[i];
  28386. }
  28387. this.numUnbounded = buildInfo.numUnbounded;
  28388. this.matrixId = 0;
  28389. let _g2 = 0;
  28390. let _g3 = this.numUnbounded;
  28391. while(_g2 < _g3) {
  28392. let i = _g2++;
  28393. let idx = buildInfo.iUnbounded[i];
  28394. this.iUnbounded[i] = idx;
  28395. this.matrixId |= 1 << idx;
  28396. }
  28397. }
  28398. computeImpulses(info,mass,relVels,impulses,dImpulses,impulseFactor,noCheck) {
  28399. let _g = 0;
  28400. let _g1 = this.numUnbounded;
  28401. while(_g < _g1) {
  28402. let idx = this.iUnbounded[_g++];
  28403. let row = info.rows[idx];
  28404. this.b[idx] = row.rhs * impulseFactor - relVels[idx] - row.cfm * impulses[idx];
  28405. }
  28406. let invMassWithoutCfm = mass._invMassWithoutCfm;
  28407. let _g2 = 0;
  28408. let _g3 = this.numBounded;
  28409. while(_g2 < _g3) {
  28410. let i = _g2++;
  28411. let idx = this.iBounded[i];
  28412. let sign = this.signs[i];
  28413. let row = info.rows[idx];
  28414. let dImpulse = (sign < 0 ? row.minImpulse : sign > 0 ? row.maxImpulse : 0) - impulses[idx];
  28415. dImpulses[idx] = dImpulse;
  28416. if(dImpulse != 0) {
  28417. let _g = 0;
  28418. let _g1 = this.numUnbounded;
  28419. while(_g < _g1) {
  28420. let idx2 = this.iUnbounded[_g++];
  28421. this.b[idx2] -= invMassWithoutCfm[idx][idx2] * dImpulse;
  28422. }
  28423. }
  28424. }
  28425. let indices = this.iUnbounded;
  28426. let n = this.numUnbounded;
  28427. let id = 0;
  28428. let _g4 = 0;
  28429. while(_g4 < n) id |= 1 << indices[_g4++];
  28430. let massMatrix;
  28431. if(mass._cacheComputed[id]) {
  28432. massMatrix = mass._cachedSubmatrices[id];
  28433. } else {
  28434. mass.computeSubmatrix(id,indices,n);
  28435. mass._cacheComputed[id] = true;
  28436. massMatrix = mass._cachedSubmatrices[id];
  28437. }
  28438. let ok = true;
  28439. let _g5 = 0;
  28440. let _g6 = this.numUnbounded;
  28441. while(_g5 < _g6) {
  28442. let i = _g5++;
  28443. let idx = this.iUnbounded[i];
  28444. let row = info.rows[idx];
  28445. let oldImpulse = impulses[idx];
  28446. let impulse = oldImpulse;
  28447. let _g = 0;
  28448. let _g1 = this.numUnbounded;
  28449. while(_g < _g1) {
  28450. let j = _g++;
  28451. impulse += this.b[this.iUnbounded[j]] * massMatrix[i][j];
  28452. }
  28453. if(impulse < row.minImpulse - oimo.common.Setting.directMlcpSolverEps || impulse > row.maxImpulse + oimo.common.Setting.directMlcpSolverEps) {
  28454. ok = false;
  28455. break;
  28456. }
  28457. dImpulses[idx] = impulse - oldImpulse;
  28458. }
  28459. if(noCheck) {
  28460. return true;
  28461. }
  28462. if(!ok) {
  28463. return false;
  28464. }
  28465. let _g7 = 0;
  28466. let _g8 = this.numBounded;
  28467. while(_g7 < _g8) {
  28468. let i = _g7++;
  28469. let idx = this.iBounded[i];
  28470. let row = info.rows[idx];
  28471. let sign = this.signs[i];
  28472. let error = 0;
  28473. let newImpulse = impulses[idx] + dImpulses[idx];
  28474. let relVel = relVels[idx];
  28475. let _g = 0;
  28476. let _g1 = info.numRows;
  28477. while(_g < _g1) {
  28478. let j = _g++;
  28479. relVel += invMassWithoutCfm[idx][j] * dImpulses[j];
  28480. }
  28481. error = row.rhs * impulseFactor - relVel - row.cfm * newImpulse;
  28482. if(sign < 0 && error > oimo.common.Setting.directMlcpSolverEps || sign > 0 && error < -oimo.common.Setting.directMlcpSolverEps) {
  28483. ok = false;
  28484. break;
  28485. }
  28486. }
  28487. return ok;
  28488. }
  28489. }
  28490. oimo.dynamics.constraint.solver.direct.BoundaryBuildInfo = class oimo_dynamics_constraint_solver_direct_BoundaryBuildInfo {
  28491. constructor(size) {
  28492. this.size = size;
  28493. this.numBounded = 0;
  28494. this.iBounded = new Array(size);
  28495. this.signs = new Array(size);
  28496. this.numUnbounded = 0;
  28497. this.iUnbounded = new Array(size);
  28498. }
  28499. }
  28500. oimo.dynamics.constraint.solver.direct.BoundaryBuilder = class oimo_dynamics_constraint_solver_direct_BoundaryBuilder {
  28501. constructor(maxRows) {
  28502. this.maxRows = maxRows;
  28503. this.numBoundaries = 0;
  28504. this.boundaries = new Array(1 << maxRows);
  28505. this.bbInfo = new oimo.dynamics.constraint.solver.direct.BoundaryBuildInfo(maxRows);
  28506. }
  28507. buildBoundariesRecursive(info,i) {
  28508. if(i == info.numRows) {
  28509. if(this.boundaries[this.numBoundaries] == null) {
  28510. this.boundaries[this.numBoundaries] = new oimo.dynamics.constraint.solver.direct.Boundary(this.maxRows);
  28511. }
  28512. this.boundaries[this.numBoundaries++].init(this.bbInfo);
  28513. return;
  28514. }
  28515. let row = info.rows[i];
  28516. let lowerLimitEnabled = row.minImpulse > -1e65536;
  28517. let upperLimitEnabled = row.maxImpulse < 1e65536;
  28518. if(row.minImpulse == 0 && row.maxImpulse == 0) {
  28519. let _this = this.bbInfo;
  28520. _this.iBounded[_this.numBounded] = i;
  28521. _this.signs[_this.numBounded] = 0;
  28522. _this.numBounded++;
  28523. this.buildBoundariesRecursive(info,i + 1);
  28524. this.bbInfo.numBounded--;
  28525. return;
  28526. }
  28527. let _this = this.bbInfo;
  28528. _this.iUnbounded[_this.numUnbounded] = i;
  28529. _this.numUnbounded++;
  28530. this.buildBoundariesRecursive(info,i + 1);
  28531. this.bbInfo.numUnbounded--;
  28532. if(lowerLimitEnabled) {
  28533. let _this = this.bbInfo;
  28534. _this.iBounded[_this.numBounded] = i;
  28535. _this.signs[_this.numBounded] = -1;
  28536. _this.numBounded++;
  28537. this.buildBoundariesRecursive(info,i + 1);
  28538. this.bbInfo.numBounded--;
  28539. }
  28540. if(upperLimitEnabled) {
  28541. let _this = this.bbInfo;
  28542. _this.iBounded[_this.numBounded] = i;
  28543. _this.signs[_this.numBounded] = 1;
  28544. _this.numBounded++;
  28545. this.buildBoundariesRecursive(info,i + 1);
  28546. this.bbInfo.numBounded--;
  28547. }
  28548. }
  28549. buildBoundaries(info) {
  28550. this.numBoundaries = 0;
  28551. let _this = this.bbInfo;
  28552. _this.numBounded = 0;
  28553. _this.numUnbounded = 0;
  28554. this.buildBoundariesRecursive(info,0);
  28555. }
  28556. }
  28557. oimo.dynamics.constraint.solver.direct.BoundarySelector = class oimo_dynamics_constraint_solver_direct_BoundarySelector {
  28558. constructor(n) {
  28559. this.n = n;
  28560. this.indices = new Array(n);
  28561. this.tmpIndices = new Array(n);
  28562. let _g = 0;
  28563. while(_g < n) {
  28564. let i = _g++;
  28565. this.indices[i] = i;
  28566. }
  28567. }
  28568. getIndex(i) {
  28569. return this.indices[i];
  28570. }
  28571. select(index) {
  28572. let i = 0;
  28573. while(this.indices[i] != index) ++i;
  28574. while(i > 0) {
  28575. let tmp = this.indices[i];
  28576. this.indices[i] = this.indices[i - 1];
  28577. this.indices[i - 1] = tmp;
  28578. --i;
  28579. }
  28580. }
  28581. setSize(size) {
  28582. let numSmaller = 0;
  28583. let numGreater = 0;
  28584. let _g = 0;
  28585. let _g1 = this.n;
  28586. while(_g < _g1) {
  28587. let idx = this.indices[_g++];
  28588. if(idx < size) {
  28589. this.tmpIndices[numSmaller] = idx;
  28590. ++numSmaller;
  28591. } else {
  28592. this.tmpIndices[size + numGreater] = idx;
  28593. ++numGreater;
  28594. }
  28595. }
  28596. let tmp = this.indices;
  28597. this.indices = this.tmpIndices;
  28598. this.tmpIndices = tmp;
  28599. }
  28600. }
  28601. oimo.dynamics.constraint.solver.direct.DirectJointConstraintSolver = class oimo_dynamics_constraint_solver_direct_DirectJointConstraintSolver extends oimo.dynamics.constraint.ConstraintSolver {
  28602. constructor(joint) {
  28603. super();
  28604. this.joint = joint;
  28605. this.info = new oimo.dynamics.constraint.info.joint.JointSolverInfo();
  28606. let maxRows = oimo.common.Setting.maxJacobianRows;
  28607. this.massMatrix = new oimo.dynamics.constraint.solver.direct.MassMatrix(maxRows);
  28608. this.boundaryBuilder = new oimo.dynamics.constraint.solver.direct.BoundaryBuilder(maxRows);
  28609. this.massData = new Array(maxRows);
  28610. let _g = 0;
  28611. let _g1 = this.massData.length;
  28612. while(_g < _g1) this.massData[_g++] = new oimo.dynamics.constraint.solver.common.JointSolverMassDataRow();
  28613. let numMaxBoundaries = this.boundaryBuilder.boundaries.length;
  28614. this.velBoundarySelector = new oimo.dynamics.constraint.solver.direct.BoundarySelector(numMaxBoundaries);
  28615. this.posBoundarySelector = new oimo.dynamics.constraint.solver.direct.BoundarySelector(numMaxBoundaries);
  28616. this.relVels = new Array(maxRows);
  28617. this.impulses = new Array(maxRows);
  28618. this.dImpulses = new Array(maxRows);
  28619. this.dTotalImpulses = new Array(maxRows);
  28620. let _g2 = 0;
  28621. while(_g2 < maxRows) {
  28622. let i = _g2++;
  28623. this.relVels[i] = 0;
  28624. this.impulses[i] = 0;
  28625. this.dImpulses[i] = 0;
  28626. this.dTotalImpulses[i] = 0;
  28627. }
  28628. }
  28629. preSolveVelocity(timeStep) {
  28630. this.joint._syncAnchors();
  28631. this.joint._getVelocitySolverInfo(timeStep,this.info);
  28632. this._b1 = this.info.b1;
  28633. this._b2 = this.info.b2;
  28634. this.massMatrix.computeInvMass(this.info,this.massData);
  28635. let _this = this.boundaryBuilder;
  28636. _this.numBoundaries = 0;
  28637. let _this1 = _this.bbInfo;
  28638. _this1.numBounded = 0;
  28639. _this1.numUnbounded = 0;
  28640. _this.buildBoundariesRecursive(this.info,0);
  28641. let _this2 = this.velBoundarySelector;
  28642. let size = this.boundaryBuilder.numBoundaries;
  28643. let numSmaller = 0;
  28644. let numGreater = 0;
  28645. let _g = 0;
  28646. let _g1 = _this2.n;
  28647. while(_g < _g1) {
  28648. let idx = _this2.indices[_g++];
  28649. if(idx < size) {
  28650. _this2.tmpIndices[numSmaller] = idx;
  28651. ++numSmaller;
  28652. } else {
  28653. _this2.tmpIndices[size + numGreater] = idx;
  28654. ++numGreater;
  28655. }
  28656. }
  28657. let tmp = _this2.indices;
  28658. _this2.indices = _this2.tmpIndices;
  28659. _this2.tmpIndices = tmp;
  28660. }
  28661. warmStart(timeStep) {
  28662. let factor = this.joint._positionCorrectionAlgorithm == oimo.dynamics.constraint.PositionCorrectionAlgorithm.BAUMGARTE ? oimo.common.Setting.jointWarmStartingFactorForBaungarte : oimo.common.Setting.jointWarmStartingFactor;
  28663. factor *= timeStep.dtRatio;
  28664. if(factor <= 0) {
  28665. let _g = 0;
  28666. let _g1 = this.info.numRows;
  28667. while(_g < _g1) {
  28668. let _this = this.info.rows[_g++].impulse;
  28669. _this.impulse = 0;
  28670. _this.impulseM = 0;
  28671. _this.impulseP = 0;
  28672. }
  28673. return;
  28674. }
  28675. let _g = 0;
  28676. let _g1 = this.info.numRows;
  28677. while(_g < _g1) {
  28678. let i = _g++;
  28679. let row = this.info.rows[i];
  28680. let imp = row.impulse;
  28681. let impulse = imp.impulse * factor;
  28682. if(impulse < row.minImpulse) {
  28683. impulse = row.minImpulse;
  28684. } else if(impulse > row.maxImpulse) {
  28685. impulse = row.maxImpulse;
  28686. }
  28687. imp.impulse = impulse;
  28688. if(row.motorMaxImpulse > 0) {
  28689. let impulseM = imp.impulseM * factor;
  28690. let max = row.motorMaxImpulse;
  28691. if(impulseM < -max) {
  28692. impulseM = -max;
  28693. } else if(impulseM > max) {
  28694. impulseM = max;
  28695. }
  28696. imp.impulseM = impulseM;
  28697. } else {
  28698. imp.impulseM = 0;
  28699. }
  28700. this.dImpulses[i] = imp.impulse + imp.impulseM;
  28701. }
  28702. let impulses = this.dImpulses;
  28703. let linearSet = false;
  28704. let angularSet = false;
  28705. let lv1X;
  28706. let lv1Y;
  28707. let lv1Z;
  28708. let lv2X;
  28709. let lv2Y;
  28710. let lv2Z;
  28711. let av1X;
  28712. let av1Y;
  28713. let av1Z;
  28714. let av2X;
  28715. let av2Y;
  28716. let av2Z;
  28717. lv1X = this._b1._velX;
  28718. lv1Y = this._b1._velY;
  28719. lv1Z = this._b1._velZ;
  28720. lv2X = this._b2._velX;
  28721. lv2Y = this._b2._velY;
  28722. lv2Z = this._b2._velZ;
  28723. av1X = this._b1._angVelX;
  28724. av1Y = this._b1._angVelY;
  28725. av1Z = this._b1._angVelZ;
  28726. av2X = this._b2._angVelX;
  28727. av2Y = this._b2._angVelY;
  28728. av2Z = this._b2._angVelZ;
  28729. let _g2 = 0;
  28730. let _g3 = this.info.numRows;
  28731. while(_g2 < _g3) {
  28732. let i = _g2++;
  28733. let j = this.info.rows[i].jacobian;
  28734. let md = this.massData[i];
  28735. let imp = impulses[i];
  28736. if((j.flag & 1) != 0) {
  28737. lv1X += md.invMLin1X * imp;
  28738. lv1Y += md.invMLin1Y * imp;
  28739. lv1Z += md.invMLin1Z * imp;
  28740. lv2X += md.invMLin2X * -imp;
  28741. lv2Y += md.invMLin2Y * -imp;
  28742. lv2Z += md.invMLin2Z * -imp;
  28743. linearSet = true;
  28744. }
  28745. if((j.flag & 2) != 0) {
  28746. av1X += md.invMAng1X * imp;
  28747. av1Y += md.invMAng1Y * imp;
  28748. av1Z += md.invMAng1Z * imp;
  28749. av2X += md.invMAng2X * -imp;
  28750. av2Y += md.invMAng2Y * -imp;
  28751. av2Z += md.invMAng2Z * -imp;
  28752. angularSet = true;
  28753. }
  28754. }
  28755. if(linearSet) {
  28756. this._b1._velX = lv1X;
  28757. this._b1._velY = lv1Y;
  28758. this._b1._velZ = lv1Z;
  28759. this._b2._velX = lv2X;
  28760. this._b2._velY = lv2Y;
  28761. this._b2._velZ = lv2Z;
  28762. }
  28763. if(angularSet) {
  28764. this._b1._angVelX = av1X;
  28765. this._b1._angVelY = av1Y;
  28766. this._b1._angVelZ = av1Z;
  28767. this._b2._angVelX = av2X;
  28768. this._b2._angVelY = av2Y;
  28769. this._b2._angVelZ = av2Z;
  28770. }
  28771. }
  28772. solveVelocity() {
  28773. let numRows = this.info.numRows;
  28774. let lv1X;
  28775. let lv1Y;
  28776. let lv1Z;
  28777. let lv2X;
  28778. let lv2Y;
  28779. let lv2Z;
  28780. let av1X;
  28781. let av1Y;
  28782. let av1Z;
  28783. let av2X;
  28784. let av2Y;
  28785. let av2Z;
  28786. lv1X = this._b1._velX;
  28787. lv1Y = this._b1._velY;
  28788. lv1Z = this._b1._velZ;
  28789. lv2X = this._b2._velX;
  28790. lv2Y = this._b2._velY;
  28791. lv2Z = this._b2._velZ;
  28792. av1X = this._b1._angVelX;
  28793. av1Y = this._b1._angVelY;
  28794. av1Z = this._b1._angVelZ;
  28795. av2X = this._b2._angVelX;
  28796. av2Y = this._b2._angVelY;
  28797. av2Z = this._b2._angVelZ;
  28798. let _g = 0;
  28799. while(_g < numRows) {
  28800. let i = _g++;
  28801. let row = this.info.rows[i];
  28802. let j = row.jacobian;
  28803. let relVel = 0;
  28804. relVel += lv1X * j.lin1X + lv1Y * j.lin1Y + lv1Z * j.lin1Z;
  28805. relVel -= lv2X * j.lin2X + lv2Y * j.lin2Y + lv2Z * j.lin2Z;
  28806. relVel += av1X * j.ang1X + av1Y * j.ang1Y + av1Z * j.ang1Z;
  28807. relVel -= av2X * j.ang2X + av2Y * j.ang2Y + av2Z * j.ang2Z;
  28808. this.relVels[i] = relVel;
  28809. this.impulses[i] = row.impulse.impulse;
  28810. this.dTotalImpulses[i] = 0;
  28811. }
  28812. let invMass = this.massMatrix._invMassWithoutCfm;
  28813. let _g1 = 0;
  28814. while(_g1 < numRows) {
  28815. let i = _g1++;
  28816. let row = this.info.rows[i];
  28817. let imp = row.impulse;
  28818. if(row.motorMaxImpulse > 0) {
  28819. let oldImpulseM = imp.impulseM;
  28820. let impulseM = oldImpulseM + this.massData[i].massWithoutCfm * (-row.motorSpeed - this.relVels[i]);
  28821. let maxImpulseM = row.motorMaxImpulse;
  28822. if(impulseM < -maxImpulseM) {
  28823. impulseM = -maxImpulseM;
  28824. } else if(impulseM > maxImpulseM) {
  28825. impulseM = maxImpulseM;
  28826. }
  28827. imp.impulseM = impulseM;
  28828. let dImpulseM = impulseM - oldImpulseM;
  28829. this.dTotalImpulses[i] = dImpulseM;
  28830. let _g = 0;
  28831. while(_g < numRows) {
  28832. let j = _g++;
  28833. this.relVels[j] += dImpulseM * invMass[i][j];
  28834. }
  28835. }
  28836. }
  28837. let solved = false;
  28838. let _g2 = 0;
  28839. let _g3 = this.boundaryBuilder.numBoundaries;
  28840. while(_g2 < _g3) {
  28841. let idx = this.velBoundarySelector.indices[_g2++];
  28842. if(this.boundaryBuilder.boundaries[idx].computeImpulses(this.info,this.massMatrix,this.relVels,this.impulses,this.dImpulses,1,false)) {
  28843. let _g = 0;
  28844. while(_g < numRows) {
  28845. let j = _g++;
  28846. let dimp = this.dImpulses[j];
  28847. this.info.rows[j].impulse.impulse += dimp;
  28848. this.dTotalImpulses[j] += dimp;
  28849. }
  28850. let impulses = this.dTotalImpulses;
  28851. let linearSet = false;
  28852. let angularSet = false;
  28853. let lv1X;
  28854. let lv1Y;
  28855. let lv1Z;
  28856. let lv2X;
  28857. let lv2Y;
  28858. let lv2Z;
  28859. let av1X;
  28860. let av1Y;
  28861. let av1Z;
  28862. let av2X;
  28863. let av2Y;
  28864. let av2Z;
  28865. lv1X = this._b1._velX;
  28866. lv1Y = this._b1._velY;
  28867. lv1Z = this._b1._velZ;
  28868. lv2X = this._b2._velX;
  28869. lv2Y = this._b2._velY;
  28870. lv2Z = this._b2._velZ;
  28871. av1X = this._b1._angVelX;
  28872. av1Y = this._b1._angVelY;
  28873. av1Z = this._b1._angVelZ;
  28874. av2X = this._b2._angVelX;
  28875. av2Y = this._b2._angVelY;
  28876. av2Z = this._b2._angVelZ;
  28877. let _g1 = 0;
  28878. let _g2 = this.info.numRows;
  28879. while(_g1 < _g2) {
  28880. let i = _g1++;
  28881. let j = this.info.rows[i].jacobian;
  28882. let md = this.massData[i];
  28883. let imp = impulses[i];
  28884. if((j.flag & 1) != 0) {
  28885. lv1X += md.invMLin1X * imp;
  28886. lv1Y += md.invMLin1Y * imp;
  28887. lv1Z += md.invMLin1Z * imp;
  28888. lv2X += md.invMLin2X * -imp;
  28889. lv2Y += md.invMLin2Y * -imp;
  28890. lv2Z += md.invMLin2Z * -imp;
  28891. linearSet = true;
  28892. }
  28893. if((j.flag & 2) != 0) {
  28894. av1X += md.invMAng1X * imp;
  28895. av1Y += md.invMAng1Y * imp;
  28896. av1Z += md.invMAng1Z * imp;
  28897. av2X += md.invMAng2X * -imp;
  28898. av2Y += md.invMAng2Y * -imp;
  28899. av2Z += md.invMAng2Z * -imp;
  28900. angularSet = true;
  28901. }
  28902. }
  28903. if(linearSet) {
  28904. this._b1._velX = lv1X;
  28905. this._b1._velY = lv1Y;
  28906. this._b1._velZ = lv1Z;
  28907. this._b2._velX = lv2X;
  28908. this._b2._velY = lv2Y;
  28909. this._b2._velZ = lv2Z;
  28910. }
  28911. if(angularSet) {
  28912. this._b1._angVelX = av1X;
  28913. this._b1._angVelY = av1Y;
  28914. this._b1._angVelZ = av1Z;
  28915. this._b2._angVelX = av2X;
  28916. this._b2._angVelY = av2Y;
  28917. this._b2._angVelZ = av2Z;
  28918. }
  28919. let _this = this.velBoundarySelector;
  28920. let i = 0;
  28921. while(_this.indices[i] != idx) ++i;
  28922. while(i > 0) {
  28923. let tmp = _this.indices[i];
  28924. _this.indices[i] = _this.indices[i - 1];
  28925. _this.indices[i - 1] = tmp;
  28926. --i;
  28927. }
  28928. solved = true;
  28929. break;
  28930. }
  28931. }
  28932. if(!solved) {
  28933. console.log("src/oimo/dynamics/constraint/solver/direct/DirectJointConstraintSolver.hx:335:","could not find solution. (velocity)");
  28934. return;
  28935. }
  28936. }
  28937. postSolveVelocity(timeStep) {
  28938. let linX;
  28939. let linY;
  28940. let linZ;
  28941. let angX;
  28942. let angY;
  28943. let angZ;
  28944. linX = 0;
  28945. linY = 0;
  28946. linZ = 0;
  28947. angX = 0;
  28948. angY = 0;
  28949. angZ = 0;
  28950. let _g = 0;
  28951. let _g1 = this.info.numRows;
  28952. while(_g < _g1) {
  28953. let row = this.info.rows[_g++];
  28954. let imp = row.impulse;
  28955. let j = row.jacobian;
  28956. if((j.flag & 1) != 0) {
  28957. linX += j.lin1X * imp.impulse;
  28958. linY += j.lin1Y * imp.impulse;
  28959. linZ += j.lin1Z * imp.impulse;
  28960. } else if((j.flag & 2) != 0) {
  28961. angX += j.ang1X * imp.impulse;
  28962. angY += j.ang1Y * imp.impulse;
  28963. angZ += j.ang1Z * imp.impulse;
  28964. }
  28965. }
  28966. this.joint._appliedForceX = linX * timeStep.invDt;
  28967. this.joint._appliedForceY = linY * timeStep.invDt;
  28968. this.joint._appliedForceZ = linZ * timeStep.invDt;
  28969. this.joint._appliedTorqueX = angX * timeStep.invDt;
  28970. this.joint._appliedTorqueY = angY * timeStep.invDt;
  28971. this.joint._appliedTorqueZ = angZ * timeStep.invDt;
  28972. }
  28973. preSolvePosition(timeStep) {
  28974. this.joint._syncAnchors();
  28975. this.joint._getPositionSolverInfo(this.info);
  28976. this._b1 = this.info.b1;
  28977. this._b2 = this.info.b2;
  28978. this.massMatrix.computeInvMass(this.info,this.massData);
  28979. let _this = this.boundaryBuilder;
  28980. _this.numBoundaries = 0;
  28981. let _this1 = _this.bbInfo;
  28982. _this1.numBounded = 0;
  28983. _this1.numUnbounded = 0;
  28984. _this.buildBoundariesRecursive(this.info,0);
  28985. let _this2 = this.posBoundarySelector;
  28986. let size = this.boundaryBuilder.numBoundaries;
  28987. let numSmaller = 0;
  28988. let numGreater = 0;
  28989. let _g = 0;
  28990. let _g1 = _this2.n;
  28991. while(_g < _g1) {
  28992. let idx = _this2.indices[_g++];
  28993. if(idx < size) {
  28994. _this2.tmpIndices[numSmaller] = idx;
  28995. ++numSmaller;
  28996. } else {
  28997. _this2.tmpIndices[size + numGreater] = idx;
  28998. ++numGreater;
  28999. }
  29000. }
  29001. let tmp = _this2.indices;
  29002. _this2.indices = _this2.tmpIndices;
  29003. _this2.tmpIndices = tmp;
  29004. let _g2 = 0;
  29005. let _g3 = this.info.numRows;
  29006. while(_g2 < _g3) this.info.rows[_g2++].impulse.impulseP = 0;
  29007. }
  29008. solvePositionSplitImpulse() {
  29009. let numRows = this.info.numRows;
  29010. let lv1X;
  29011. let lv1Y;
  29012. let lv1Z;
  29013. let lv2X;
  29014. let lv2Y;
  29015. let lv2Z;
  29016. let av1X;
  29017. let av1Y;
  29018. let av1Z;
  29019. let av2X;
  29020. let av2Y;
  29021. let av2Z;
  29022. lv1X = this._b1._pseudoVelX;
  29023. lv1Y = this._b1._pseudoVelY;
  29024. lv1Z = this._b1._pseudoVelZ;
  29025. lv2X = this._b2._pseudoVelX;
  29026. lv2Y = this._b2._pseudoVelY;
  29027. lv2Z = this._b2._pseudoVelZ;
  29028. av1X = this._b1._angPseudoVelX;
  29029. av1Y = this._b1._angPseudoVelY;
  29030. av1Z = this._b1._angPseudoVelZ;
  29031. av2X = this._b2._angPseudoVelX;
  29032. av2Y = this._b2._angPseudoVelY;
  29033. av2Z = this._b2._angPseudoVelZ;
  29034. let _g = 0;
  29035. while(_g < numRows) {
  29036. let i = _g++;
  29037. let row = this.info.rows[i];
  29038. let j = row.jacobian;
  29039. let relVel = 0;
  29040. relVel += lv1X * j.lin1X + lv1Y * j.lin1Y + lv1Z * j.lin1Z;
  29041. relVel -= lv2X * j.lin2X + lv2Y * j.lin2Y + lv2Z * j.lin2Z;
  29042. relVel += av1X * j.ang1X + av1Y * j.ang1Y + av1Z * j.ang1Z;
  29043. relVel -= av2X * j.ang2X + av2Y * j.ang2Y + av2Z * j.ang2Z;
  29044. this.relVels[i] = relVel;
  29045. this.impulses[i] = row.impulse.impulseP;
  29046. }
  29047. let solved = false;
  29048. let _g1 = 0;
  29049. let _g2 = this.boundaryBuilder.numBoundaries;
  29050. while(_g1 < _g2) {
  29051. let idx = this.posBoundarySelector.indices[_g1++];
  29052. if(this.boundaryBuilder.boundaries[idx].computeImpulses(this.info,this.massMatrix,this.relVels,this.impulses,this.dImpulses,oimo.common.Setting.positionSplitImpulseBaumgarte,false)) {
  29053. let _g = 0;
  29054. while(_g < numRows) {
  29055. let j = _g++;
  29056. this.info.rows[j].impulse.impulseP += this.dImpulses[j];
  29057. }
  29058. let impulses = this.dImpulses;
  29059. let linearSet = false;
  29060. let angularSet = false;
  29061. let lv1X;
  29062. let lv1Y;
  29063. let lv1Z;
  29064. let lv2X;
  29065. let lv2Y;
  29066. let lv2Z;
  29067. let av1X;
  29068. let av1Y;
  29069. let av1Z;
  29070. let av2X;
  29071. let av2Y;
  29072. let av2Z;
  29073. lv1X = this._b1._pseudoVelX;
  29074. lv1Y = this._b1._pseudoVelY;
  29075. lv1Z = this._b1._pseudoVelZ;
  29076. lv2X = this._b2._pseudoVelX;
  29077. lv2Y = this._b2._pseudoVelY;
  29078. lv2Z = this._b2._pseudoVelZ;
  29079. av1X = this._b1._angPseudoVelX;
  29080. av1Y = this._b1._angPseudoVelY;
  29081. av1Z = this._b1._angPseudoVelZ;
  29082. av2X = this._b2._angPseudoVelX;
  29083. av2Y = this._b2._angPseudoVelY;
  29084. av2Z = this._b2._angPseudoVelZ;
  29085. let _g1 = 0;
  29086. let _g2 = this.info.numRows;
  29087. while(_g1 < _g2) {
  29088. let i = _g1++;
  29089. let j = this.info.rows[i].jacobian;
  29090. let md = this.massData[i];
  29091. let imp = impulses[i];
  29092. if((j.flag & 1) != 0) {
  29093. lv1X += md.invMLin1X * imp;
  29094. lv1Y += md.invMLin1Y * imp;
  29095. lv1Z += md.invMLin1Z * imp;
  29096. lv2X += md.invMLin2X * -imp;
  29097. lv2Y += md.invMLin2Y * -imp;
  29098. lv2Z += md.invMLin2Z * -imp;
  29099. linearSet = true;
  29100. }
  29101. if((j.flag & 2) != 0) {
  29102. av1X += md.invMAng1X * imp;
  29103. av1Y += md.invMAng1Y * imp;
  29104. av1Z += md.invMAng1Z * imp;
  29105. av2X += md.invMAng2X * -imp;
  29106. av2Y += md.invMAng2Y * -imp;
  29107. av2Z += md.invMAng2Z * -imp;
  29108. angularSet = true;
  29109. }
  29110. }
  29111. if(linearSet) {
  29112. this._b1._pseudoVelX = lv1X;
  29113. this._b1._pseudoVelY = lv1Y;
  29114. this._b1._pseudoVelZ = lv1Z;
  29115. this._b2._pseudoVelX = lv2X;
  29116. this._b2._pseudoVelY = lv2Y;
  29117. this._b2._pseudoVelZ = lv2Z;
  29118. }
  29119. if(angularSet) {
  29120. this._b1._angPseudoVelX = av1X;
  29121. this._b1._angPseudoVelY = av1Y;
  29122. this._b1._angPseudoVelZ = av1Z;
  29123. this._b2._angPseudoVelX = av2X;
  29124. this._b2._angPseudoVelY = av2Y;
  29125. this._b2._angPseudoVelZ = av2Z;
  29126. }
  29127. let _this = this.posBoundarySelector;
  29128. let i = 0;
  29129. while(_this.indices[i] != idx) ++i;
  29130. while(i > 0) {
  29131. let tmp = _this.indices[i];
  29132. _this.indices[i] = _this.indices[i - 1];
  29133. _this.indices[i - 1] = tmp;
  29134. --i;
  29135. }
  29136. solved = true;
  29137. break;
  29138. }
  29139. }
  29140. if(!solved) {
  29141. console.log("src/oimo/dynamics/constraint/solver/direct/DirectJointConstraintSolver.hx:450:","could not find solution. (split impulse)");
  29142. return;
  29143. }
  29144. }
  29145. solvePositionNgs(timeStep) {
  29146. this.joint._syncAnchors();
  29147. this.joint._getPositionSolverInfo(this.info);
  29148. this._b1 = this.info.b1;
  29149. this._b2 = this.info.b2;
  29150. this.massMatrix.computeInvMass(this.info,this.massData);
  29151. let _this = this.boundaryBuilder;
  29152. _this.numBoundaries = 0;
  29153. let _this1 = _this.bbInfo;
  29154. _this1.numBounded = 0;
  29155. _this1.numUnbounded = 0;
  29156. _this.buildBoundariesRecursive(this.info,0);
  29157. let _this2 = this.posBoundarySelector;
  29158. let size = this.boundaryBuilder.numBoundaries;
  29159. let numSmaller = 0;
  29160. let numGreater = 0;
  29161. let _g = 0;
  29162. let _g1 = _this2.n;
  29163. while(_g < _g1) {
  29164. let idx = _this2.indices[_g++];
  29165. if(idx < size) {
  29166. _this2.tmpIndices[numSmaller] = idx;
  29167. ++numSmaller;
  29168. } else {
  29169. _this2.tmpIndices[size + numGreater] = idx;
  29170. ++numGreater;
  29171. }
  29172. }
  29173. let tmp = _this2.indices;
  29174. _this2.indices = _this2.tmpIndices;
  29175. _this2.tmpIndices = tmp;
  29176. let numRows = this.info.numRows;
  29177. let _g2 = 0;
  29178. while(_g2 < numRows) {
  29179. let i = _g2++;
  29180. let imp = this.info.rows[i].impulse;
  29181. this.relVels[i] = 0;
  29182. this.impulses[i] = imp.impulseP;
  29183. }
  29184. let solved = false;
  29185. let _g3 = 0;
  29186. let _g4 = this.boundaryBuilder.numBoundaries;
  29187. while(_g3 < _g4) {
  29188. let idx = this.posBoundarySelector.indices[_g3++];
  29189. if(this.boundaryBuilder.boundaries[idx].computeImpulses(this.info,this.massMatrix,this.relVels,this.impulses,this.dImpulses,oimo.common.Setting.positionNgsBaumgarte,false)) {
  29190. let _g = 0;
  29191. while(_g < numRows) {
  29192. let j = _g++;
  29193. this.info.rows[j].impulse.impulseP += this.dImpulses[j];
  29194. }
  29195. let impulses = this.dImpulses;
  29196. let linearSet = false;
  29197. let angularSet = false;
  29198. let lv1X;
  29199. let lv1Y;
  29200. let lv1Z;
  29201. let lv2X;
  29202. let lv2Y;
  29203. let lv2Z;
  29204. let av1X;
  29205. let av1Y;
  29206. let av1Z;
  29207. let av2X;
  29208. let av2Y;
  29209. let av2Z;
  29210. lv1X = 0;
  29211. lv1Y = 0;
  29212. lv1Z = 0;
  29213. lv2X = 0;
  29214. lv2Y = 0;
  29215. lv2Z = 0;
  29216. av1X = 0;
  29217. av1Y = 0;
  29218. av1Z = 0;
  29219. av2X = 0;
  29220. av2Y = 0;
  29221. av2Z = 0;
  29222. let _g1 = 0;
  29223. let _g2 = this.info.numRows;
  29224. while(_g1 < _g2) {
  29225. let i = _g1++;
  29226. let j = this.info.rows[i].jacobian;
  29227. let md = this.massData[i];
  29228. let imp = impulses[i];
  29229. if((j.flag & 1) != 0) {
  29230. lv1X += md.invMLin1X * imp;
  29231. lv1Y += md.invMLin1Y * imp;
  29232. lv1Z += md.invMLin1Z * imp;
  29233. lv2X += md.invMLin2X * -imp;
  29234. lv2Y += md.invMLin2Y * -imp;
  29235. lv2Z += md.invMLin2Z * -imp;
  29236. linearSet = true;
  29237. }
  29238. if((j.flag & 2) != 0) {
  29239. av1X += md.invMAng1X * imp;
  29240. av1Y += md.invMAng1Y * imp;
  29241. av1Z += md.invMAng1Z * imp;
  29242. av2X += md.invMAng2X * -imp;
  29243. av2Y += md.invMAng2Y * -imp;
  29244. av2Z += md.invMAng2Z * -imp;
  29245. angularSet = true;
  29246. }
  29247. }
  29248. if(linearSet) {
  29249. let _this = this._b1;
  29250. _this._transform._positionX += lv1X;
  29251. _this._transform._positionY += lv1Y;
  29252. _this._transform._positionZ += lv1Z;
  29253. let _this1 = this._b2;
  29254. _this1._transform._positionX += lv2X;
  29255. _this1._transform._positionY += lv2Y;
  29256. _this1._transform._positionZ += lv2Z;
  29257. }
  29258. if(angularSet) {
  29259. let _this = this._b1;
  29260. let theta = Math.sqrt(av1X * av1X + av1Y * av1Y + av1Z * av1Z);
  29261. let halfTheta = theta * 0.5;
  29262. let rotationToSinAxisFactor;
  29263. let cosHalfTheta;
  29264. if(halfTheta < 0.5) {
  29265. let ht2 = halfTheta * halfTheta;
  29266. rotationToSinAxisFactor = 0.5 * (1 - ht2 * 0.16666666666666666 + ht2 * ht2 * 0.0083333333333333332);
  29267. cosHalfTheta = 1 - ht2 * 0.5 + ht2 * ht2 * 0.041666666666666664;
  29268. } else {
  29269. rotationToSinAxisFactor = Math.sin(halfTheta) / theta;
  29270. cosHalfTheta = Math.cos(halfTheta);
  29271. }
  29272. let sinAxisX;
  29273. let sinAxisY;
  29274. let sinAxisZ;
  29275. sinAxisX = av1X * rotationToSinAxisFactor;
  29276. sinAxisY = av1Y * rotationToSinAxisFactor;
  29277. sinAxisZ = av1Z * rotationToSinAxisFactor;
  29278. let dqX;
  29279. let dqY;
  29280. let dqZ;
  29281. let dqW;
  29282. dqX = sinAxisX;
  29283. dqY = sinAxisY;
  29284. dqZ = sinAxisZ;
  29285. dqW = cosHalfTheta;
  29286. let qX;
  29287. let qY;
  29288. let qZ;
  29289. let qW;
  29290. let e00 = _this._transform._rotation00;
  29291. let e11 = _this._transform._rotation11;
  29292. let e22 = _this._transform._rotation22;
  29293. let t = e00 + e11 + e22;
  29294. let s;
  29295. if(t > 0) {
  29296. s = Math.sqrt(t + 1);
  29297. qW = 0.5 * s;
  29298. s = 0.5 / s;
  29299. qX = (_this._transform._rotation21 - _this._transform._rotation12) * s;
  29300. qY = (_this._transform._rotation02 - _this._transform._rotation20) * s;
  29301. qZ = (_this._transform._rotation10 - _this._transform._rotation01) * s;
  29302. } else if(e00 > e11) {
  29303. if(e00 > e22) {
  29304. s = Math.sqrt(e00 - e11 - e22 + 1);
  29305. qX = 0.5 * s;
  29306. s = 0.5 / s;
  29307. qY = (_this._transform._rotation01 + _this._transform._rotation10) * s;
  29308. qZ = (_this._transform._rotation02 + _this._transform._rotation20) * s;
  29309. qW = (_this._transform._rotation21 - _this._transform._rotation12) * s;
  29310. } else {
  29311. s = Math.sqrt(e22 - e00 - e11 + 1);
  29312. qZ = 0.5 * s;
  29313. s = 0.5 / s;
  29314. qX = (_this._transform._rotation02 + _this._transform._rotation20) * s;
  29315. qY = (_this._transform._rotation12 + _this._transform._rotation21) * s;
  29316. qW = (_this._transform._rotation10 - _this._transform._rotation01) * s;
  29317. }
  29318. } else if(e11 > e22) {
  29319. s = Math.sqrt(e11 - e22 - e00 + 1);
  29320. qY = 0.5 * s;
  29321. s = 0.5 / s;
  29322. qX = (_this._transform._rotation01 + _this._transform._rotation10) * s;
  29323. qZ = (_this._transform._rotation12 + _this._transform._rotation21) * s;
  29324. qW = (_this._transform._rotation02 - _this._transform._rotation20) * s;
  29325. } else {
  29326. s = Math.sqrt(e22 - e00 - e11 + 1);
  29327. qZ = 0.5 * s;
  29328. s = 0.5 / s;
  29329. qX = (_this._transform._rotation02 + _this._transform._rotation20) * s;
  29330. qY = (_this._transform._rotation12 + _this._transform._rotation21) * s;
  29331. qW = (_this._transform._rotation10 - _this._transform._rotation01) * s;
  29332. }
  29333. qX = dqW * qX + dqX * qW + dqY * qZ - dqZ * qY;
  29334. qY = dqW * qY - dqX * qZ + dqY * qW + dqZ * qX;
  29335. qZ = dqW * qZ + dqX * qY - dqY * qX + dqZ * qW;
  29336. qW = dqW * qW - dqX * qX - dqY * qY - dqZ * qZ;
  29337. let l = qX * qX + qY * qY + qZ * qZ + qW * qW;
  29338. if(l > 1e-32) {
  29339. l = 1 / Math.sqrt(l);
  29340. }
  29341. qX *= l;
  29342. qY *= l;
  29343. qZ *= l;
  29344. qW *= l;
  29345. let x = qX;
  29346. let y = qY;
  29347. let z = qZ;
  29348. let w = qW;
  29349. let x2 = 2 * x;
  29350. let y2 = 2 * y;
  29351. let z2 = 2 * z;
  29352. let xx = x * x2;
  29353. let yy = y * y2;
  29354. let zz = z * z2;
  29355. let xy = x * y2;
  29356. let yz = y * z2;
  29357. let xz = x * z2;
  29358. let wx = w * x2;
  29359. let wy = w * y2;
  29360. let wz = w * z2;
  29361. _this._transform._rotation00 = 1 - yy - zz;
  29362. _this._transform._rotation01 = xy - wz;
  29363. _this._transform._rotation02 = xz + wy;
  29364. _this._transform._rotation10 = xy + wz;
  29365. _this._transform._rotation11 = 1 - xx - zz;
  29366. _this._transform._rotation12 = yz - wx;
  29367. _this._transform._rotation20 = xz - wy;
  29368. _this._transform._rotation21 = yz + wx;
  29369. _this._transform._rotation22 = 1 - xx - yy;
  29370. let __tmp__00;
  29371. let __tmp__01;
  29372. let __tmp__02;
  29373. let __tmp__10;
  29374. let __tmp__11;
  29375. let __tmp__12;
  29376. let __tmp__20;
  29377. let __tmp__21;
  29378. let __tmp__22;
  29379. __tmp__00 = _this._transform._rotation00 * _this._invLocalInertia00 + _this._transform._rotation01 * _this._invLocalInertia10 + _this._transform._rotation02 * _this._invLocalInertia20;
  29380. __tmp__01 = _this._transform._rotation00 * _this._invLocalInertia01 + _this._transform._rotation01 * _this._invLocalInertia11 + _this._transform._rotation02 * _this._invLocalInertia21;
  29381. __tmp__02 = _this._transform._rotation00 * _this._invLocalInertia02 + _this._transform._rotation01 * _this._invLocalInertia12 + _this._transform._rotation02 * _this._invLocalInertia22;
  29382. __tmp__10 = _this._transform._rotation10 * _this._invLocalInertia00 + _this._transform._rotation11 * _this._invLocalInertia10 + _this._transform._rotation12 * _this._invLocalInertia20;
  29383. __tmp__11 = _this._transform._rotation10 * _this._invLocalInertia01 + _this._transform._rotation11 * _this._invLocalInertia11 + _this._transform._rotation12 * _this._invLocalInertia21;
  29384. __tmp__12 = _this._transform._rotation10 * _this._invLocalInertia02 + _this._transform._rotation11 * _this._invLocalInertia12 + _this._transform._rotation12 * _this._invLocalInertia22;
  29385. __tmp__20 = _this._transform._rotation20 * _this._invLocalInertia00 + _this._transform._rotation21 * _this._invLocalInertia10 + _this._transform._rotation22 * _this._invLocalInertia20;
  29386. __tmp__21 = _this._transform._rotation20 * _this._invLocalInertia01 + _this._transform._rotation21 * _this._invLocalInertia11 + _this._transform._rotation22 * _this._invLocalInertia21;
  29387. __tmp__22 = _this._transform._rotation20 * _this._invLocalInertia02 + _this._transform._rotation21 * _this._invLocalInertia12 + _this._transform._rotation22 * _this._invLocalInertia22;
  29388. _this._invInertia00 = __tmp__00;
  29389. _this._invInertia01 = __tmp__01;
  29390. _this._invInertia02 = __tmp__02;
  29391. _this._invInertia10 = __tmp__10;
  29392. _this._invInertia11 = __tmp__11;
  29393. _this._invInertia12 = __tmp__12;
  29394. _this._invInertia20 = __tmp__20;
  29395. _this._invInertia21 = __tmp__21;
  29396. _this._invInertia22 = __tmp__22;
  29397. let __tmp__001;
  29398. let __tmp__011;
  29399. let __tmp__021;
  29400. let __tmp__101;
  29401. let __tmp__111;
  29402. let __tmp__121;
  29403. let __tmp__201;
  29404. let __tmp__211;
  29405. let __tmp__221;
  29406. __tmp__001 = _this._invInertia00 * _this._transform._rotation00 + _this._invInertia01 * _this._transform._rotation01 + _this._invInertia02 * _this._transform._rotation02;
  29407. __tmp__011 = _this._invInertia00 * _this._transform._rotation10 + _this._invInertia01 * _this._transform._rotation11 + _this._invInertia02 * _this._transform._rotation12;
  29408. __tmp__021 = _this._invInertia00 * _this._transform._rotation20 + _this._invInertia01 * _this._transform._rotation21 + _this._invInertia02 * _this._transform._rotation22;
  29409. __tmp__101 = _this._invInertia10 * _this._transform._rotation00 + _this._invInertia11 * _this._transform._rotation01 + _this._invInertia12 * _this._transform._rotation02;
  29410. __tmp__111 = _this._invInertia10 * _this._transform._rotation10 + _this._invInertia11 * _this._transform._rotation11 + _this._invInertia12 * _this._transform._rotation12;
  29411. __tmp__121 = _this._invInertia10 * _this._transform._rotation20 + _this._invInertia11 * _this._transform._rotation21 + _this._invInertia12 * _this._transform._rotation22;
  29412. __tmp__201 = _this._invInertia20 * _this._transform._rotation00 + _this._invInertia21 * _this._transform._rotation01 + _this._invInertia22 * _this._transform._rotation02;
  29413. __tmp__211 = _this._invInertia20 * _this._transform._rotation10 + _this._invInertia21 * _this._transform._rotation11 + _this._invInertia22 * _this._transform._rotation12;
  29414. __tmp__221 = _this._invInertia20 * _this._transform._rotation20 + _this._invInertia21 * _this._transform._rotation21 + _this._invInertia22 * _this._transform._rotation22;
  29415. _this._invInertia00 = __tmp__001;
  29416. _this._invInertia01 = __tmp__011;
  29417. _this._invInertia02 = __tmp__021;
  29418. _this._invInertia10 = __tmp__101;
  29419. _this._invInertia11 = __tmp__111;
  29420. _this._invInertia12 = __tmp__121;
  29421. _this._invInertia20 = __tmp__201;
  29422. _this._invInertia21 = __tmp__211;
  29423. _this._invInertia22 = __tmp__221;
  29424. _this._invInertia00 *= _this._rotFactor.x;
  29425. _this._invInertia01 *= _this._rotFactor.x;
  29426. _this._invInertia02 *= _this._rotFactor.x;
  29427. _this._invInertia10 *= _this._rotFactor.y;
  29428. _this._invInertia11 *= _this._rotFactor.y;
  29429. _this._invInertia12 *= _this._rotFactor.y;
  29430. _this._invInertia20 *= _this._rotFactor.z;
  29431. _this._invInertia21 *= _this._rotFactor.z;
  29432. _this._invInertia22 *= _this._rotFactor.z;
  29433. let _this1 = this._b2;
  29434. let theta1 = Math.sqrt(av2X * av2X + av2Y * av2Y + av2Z * av2Z);
  29435. let halfTheta1 = theta1 * 0.5;
  29436. let rotationToSinAxisFactor1;
  29437. let cosHalfTheta1;
  29438. if(halfTheta1 < 0.5) {
  29439. let ht2 = halfTheta1 * halfTheta1;
  29440. rotationToSinAxisFactor1 = 0.5 * (1 - ht2 * 0.16666666666666666 + ht2 * ht2 * 0.0083333333333333332);
  29441. cosHalfTheta1 = 1 - ht2 * 0.5 + ht2 * ht2 * 0.041666666666666664;
  29442. } else {
  29443. rotationToSinAxisFactor1 = Math.sin(halfTheta1) / theta1;
  29444. cosHalfTheta1 = Math.cos(halfTheta1);
  29445. }
  29446. let sinAxisX1;
  29447. let sinAxisY1;
  29448. let sinAxisZ1;
  29449. sinAxisX1 = av2X * rotationToSinAxisFactor1;
  29450. sinAxisY1 = av2Y * rotationToSinAxisFactor1;
  29451. sinAxisZ1 = av2Z * rotationToSinAxisFactor1;
  29452. let dqX1;
  29453. let dqY1;
  29454. let dqZ1;
  29455. let dqW1;
  29456. dqX1 = sinAxisX1;
  29457. dqY1 = sinAxisY1;
  29458. dqZ1 = sinAxisZ1;
  29459. dqW1 = cosHalfTheta1;
  29460. let qX1;
  29461. let qY1;
  29462. let qZ1;
  29463. let qW1;
  29464. let e001 = _this1._transform._rotation00;
  29465. let e111 = _this1._transform._rotation11;
  29466. let e221 = _this1._transform._rotation22;
  29467. let t1 = e001 + e111 + e221;
  29468. let s1;
  29469. if(t1 > 0) {
  29470. s1 = Math.sqrt(t1 + 1);
  29471. qW1 = 0.5 * s1;
  29472. s1 = 0.5 / s1;
  29473. qX1 = (_this1._transform._rotation21 - _this1._transform._rotation12) * s1;
  29474. qY1 = (_this1._transform._rotation02 - _this1._transform._rotation20) * s1;
  29475. qZ1 = (_this1._transform._rotation10 - _this1._transform._rotation01) * s1;
  29476. } else if(e001 > e111) {
  29477. if(e001 > e221) {
  29478. s1 = Math.sqrt(e001 - e111 - e221 + 1);
  29479. qX1 = 0.5 * s1;
  29480. s1 = 0.5 / s1;
  29481. qY1 = (_this1._transform._rotation01 + _this1._transform._rotation10) * s1;
  29482. qZ1 = (_this1._transform._rotation02 + _this1._transform._rotation20) * s1;
  29483. qW1 = (_this1._transform._rotation21 - _this1._transform._rotation12) * s1;
  29484. } else {
  29485. s1 = Math.sqrt(e221 - e001 - e111 + 1);
  29486. qZ1 = 0.5 * s1;
  29487. s1 = 0.5 / s1;
  29488. qX1 = (_this1._transform._rotation02 + _this1._transform._rotation20) * s1;
  29489. qY1 = (_this1._transform._rotation12 + _this1._transform._rotation21) * s1;
  29490. qW1 = (_this1._transform._rotation10 - _this1._transform._rotation01) * s1;
  29491. }
  29492. } else if(e111 > e221) {
  29493. s1 = Math.sqrt(e111 - e221 - e001 + 1);
  29494. qY1 = 0.5 * s1;
  29495. s1 = 0.5 / s1;
  29496. qX1 = (_this1._transform._rotation01 + _this1._transform._rotation10) * s1;
  29497. qZ1 = (_this1._transform._rotation12 + _this1._transform._rotation21) * s1;
  29498. qW1 = (_this1._transform._rotation02 - _this1._transform._rotation20) * s1;
  29499. } else {
  29500. s1 = Math.sqrt(e221 - e001 - e111 + 1);
  29501. qZ1 = 0.5 * s1;
  29502. s1 = 0.5 / s1;
  29503. qX1 = (_this1._transform._rotation02 + _this1._transform._rotation20) * s1;
  29504. qY1 = (_this1._transform._rotation12 + _this1._transform._rotation21) * s1;
  29505. qW1 = (_this1._transform._rotation10 - _this1._transform._rotation01) * s1;
  29506. }
  29507. qX1 = dqW1 * qX1 + dqX1 * qW1 + dqY1 * qZ1 - dqZ1 * qY1;
  29508. qY1 = dqW1 * qY1 - dqX1 * qZ1 + dqY1 * qW1 + dqZ1 * qX1;
  29509. qZ1 = dqW1 * qZ1 + dqX1 * qY1 - dqY1 * qX1 + dqZ1 * qW1;
  29510. qW1 = dqW1 * qW1 - dqX1 * qX1 - dqY1 * qY1 - dqZ1 * qZ1;
  29511. let l1 = qX1 * qX1 + qY1 * qY1 + qZ1 * qZ1 + qW1 * qW1;
  29512. if(l1 > 1e-32) {
  29513. l1 = 1 / Math.sqrt(l1);
  29514. }
  29515. qX1 *= l1;
  29516. qY1 *= l1;
  29517. qZ1 *= l1;
  29518. qW1 *= l1;
  29519. let x1 = qX1;
  29520. let y1 = qY1;
  29521. let z1 = qZ1;
  29522. let w1 = qW1;
  29523. let x21 = 2 * x1;
  29524. let y21 = 2 * y1;
  29525. let z21 = 2 * z1;
  29526. let xx1 = x1 * x21;
  29527. let yy1 = y1 * y21;
  29528. let zz1 = z1 * z21;
  29529. let xy1 = x1 * y21;
  29530. let yz1 = y1 * z21;
  29531. let xz1 = x1 * z21;
  29532. let wx1 = w1 * x21;
  29533. let wy1 = w1 * y21;
  29534. let wz1 = w1 * z21;
  29535. _this1._transform._rotation00 = 1 - yy1 - zz1;
  29536. _this1._transform._rotation01 = xy1 - wz1;
  29537. _this1._transform._rotation02 = xz1 + wy1;
  29538. _this1._transform._rotation10 = xy1 + wz1;
  29539. _this1._transform._rotation11 = 1 - xx1 - zz1;
  29540. _this1._transform._rotation12 = yz1 - wx1;
  29541. _this1._transform._rotation20 = xz1 - wy1;
  29542. _this1._transform._rotation21 = yz1 + wx1;
  29543. _this1._transform._rotation22 = 1 - xx1 - yy1;
  29544. let __tmp__002;
  29545. let __tmp__012;
  29546. let __tmp__022;
  29547. let __tmp__102;
  29548. let __tmp__112;
  29549. let __tmp__122;
  29550. let __tmp__202;
  29551. let __tmp__212;
  29552. let __tmp__222;
  29553. __tmp__002 = _this1._transform._rotation00 * _this1._invLocalInertia00 + _this1._transform._rotation01 * _this1._invLocalInertia10 + _this1._transform._rotation02 * _this1._invLocalInertia20;
  29554. __tmp__012 = _this1._transform._rotation00 * _this1._invLocalInertia01 + _this1._transform._rotation01 * _this1._invLocalInertia11 + _this1._transform._rotation02 * _this1._invLocalInertia21;
  29555. __tmp__022 = _this1._transform._rotation00 * _this1._invLocalInertia02 + _this1._transform._rotation01 * _this1._invLocalInertia12 + _this1._transform._rotation02 * _this1._invLocalInertia22;
  29556. __tmp__102 = _this1._transform._rotation10 * _this1._invLocalInertia00 + _this1._transform._rotation11 * _this1._invLocalInertia10 + _this1._transform._rotation12 * _this1._invLocalInertia20;
  29557. __tmp__112 = _this1._transform._rotation10 * _this1._invLocalInertia01 + _this1._transform._rotation11 * _this1._invLocalInertia11 + _this1._transform._rotation12 * _this1._invLocalInertia21;
  29558. __tmp__122 = _this1._transform._rotation10 * _this1._invLocalInertia02 + _this1._transform._rotation11 * _this1._invLocalInertia12 + _this1._transform._rotation12 * _this1._invLocalInertia22;
  29559. __tmp__202 = _this1._transform._rotation20 * _this1._invLocalInertia00 + _this1._transform._rotation21 * _this1._invLocalInertia10 + _this1._transform._rotation22 * _this1._invLocalInertia20;
  29560. __tmp__212 = _this1._transform._rotation20 * _this1._invLocalInertia01 + _this1._transform._rotation21 * _this1._invLocalInertia11 + _this1._transform._rotation22 * _this1._invLocalInertia21;
  29561. __tmp__222 = _this1._transform._rotation20 * _this1._invLocalInertia02 + _this1._transform._rotation21 * _this1._invLocalInertia12 + _this1._transform._rotation22 * _this1._invLocalInertia22;
  29562. _this1._invInertia00 = __tmp__002;
  29563. _this1._invInertia01 = __tmp__012;
  29564. _this1._invInertia02 = __tmp__022;
  29565. _this1._invInertia10 = __tmp__102;
  29566. _this1._invInertia11 = __tmp__112;
  29567. _this1._invInertia12 = __tmp__122;
  29568. _this1._invInertia20 = __tmp__202;
  29569. _this1._invInertia21 = __tmp__212;
  29570. _this1._invInertia22 = __tmp__222;
  29571. let __tmp__003;
  29572. let __tmp__013;
  29573. let __tmp__023;
  29574. let __tmp__103;
  29575. let __tmp__113;
  29576. let __tmp__123;
  29577. let __tmp__203;
  29578. let __tmp__213;
  29579. let __tmp__223;
  29580. __tmp__003 = _this1._invInertia00 * _this1._transform._rotation00 + _this1._invInertia01 * _this1._transform._rotation01 + _this1._invInertia02 * _this1._transform._rotation02;
  29581. __tmp__013 = _this1._invInertia00 * _this1._transform._rotation10 + _this1._invInertia01 * _this1._transform._rotation11 + _this1._invInertia02 * _this1._transform._rotation12;
  29582. __tmp__023 = _this1._invInertia00 * _this1._transform._rotation20 + _this1._invInertia01 * _this1._transform._rotation21 + _this1._invInertia02 * _this1._transform._rotation22;
  29583. __tmp__103 = _this1._invInertia10 * _this1._transform._rotation00 + _this1._invInertia11 * _this1._transform._rotation01 + _this1._invInertia12 * _this1._transform._rotation02;
  29584. __tmp__113 = _this1._invInertia10 * _this1._transform._rotation10 + _this1._invInertia11 * _this1._transform._rotation11 + _this1._invInertia12 * _this1._transform._rotation12;
  29585. __tmp__123 = _this1._invInertia10 * _this1._transform._rotation20 + _this1._invInertia11 * _this1._transform._rotation21 + _this1._invInertia12 * _this1._transform._rotation22;
  29586. __tmp__203 = _this1._invInertia20 * _this1._transform._rotation00 + _this1._invInertia21 * _this1._transform._rotation01 + _this1._invInertia22 * _this1._transform._rotation02;
  29587. __tmp__213 = _this1._invInertia20 * _this1._transform._rotation10 + _this1._invInertia21 * _this1._transform._rotation11 + _this1._invInertia22 * _this1._transform._rotation12;
  29588. __tmp__223 = _this1._invInertia20 * _this1._transform._rotation20 + _this1._invInertia21 * _this1._transform._rotation21 + _this1._invInertia22 * _this1._transform._rotation22;
  29589. _this1._invInertia00 = __tmp__003;
  29590. _this1._invInertia01 = __tmp__013;
  29591. _this1._invInertia02 = __tmp__023;
  29592. _this1._invInertia10 = __tmp__103;
  29593. _this1._invInertia11 = __tmp__113;
  29594. _this1._invInertia12 = __tmp__123;
  29595. _this1._invInertia20 = __tmp__203;
  29596. _this1._invInertia21 = __tmp__213;
  29597. _this1._invInertia22 = __tmp__223;
  29598. _this1._invInertia00 *= _this1._rotFactor.x;
  29599. _this1._invInertia01 *= _this1._rotFactor.x;
  29600. _this1._invInertia02 *= _this1._rotFactor.x;
  29601. _this1._invInertia10 *= _this1._rotFactor.y;
  29602. _this1._invInertia11 *= _this1._rotFactor.y;
  29603. _this1._invInertia12 *= _this1._rotFactor.y;
  29604. _this1._invInertia20 *= _this1._rotFactor.z;
  29605. _this1._invInertia21 *= _this1._rotFactor.z;
  29606. _this1._invInertia22 *= _this1._rotFactor.z;
  29607. }
  29608. let _this = this.posBoundarySelector;
  29609. let i = 0;
  29610. while(_this.indices[i] != idx) ++i;
  29611. while(i > 0) {
  29612. let tmp = _this.indices[i];
  29613. _this.indices[i] = _this.indices[i - 1];
  29614. _this.indices[i - 1] = tmp;
  29615. --i;
  29616. }
  29617. solved = true;
  29618. break;
  29619. }
  29620. }
  29621. if(!solved) {
  29622. console.log("src/oimo/dynamics/constraint/solver/direct/DirectJointConstraintSolver.hx:502:","could not find solution. (NGS)");
  29623. return;
  29624. }
  29625. }
  29626. postSolve() {
  29627. this.joint._syncAnchors();
  29628. this.joint._checkDestruction();
  29629. }
  29630. }
  29631. oimo.dynamics.constraint.solver.direct.MassMatrix = class oimo_dynamics_constraint_solver_direct_MassMatrix {
  29632. constructor(size) {
  29633. this._size = size;
  29634. this.tmpMatrix = new Array(this._size);
  29635. this._invMass = new Array(this._size);
  29636. this._invMassWithoutCfm = new Array(this._size);
  29637. let _g = 0;
  29638. let _g1 = this._size;
  29639. while(_g < _g1) {
  29640. let i = _g++;
  29641. this.tmpMatrix[i] = new Array(this._size);
  29642. this._invMass[i] = new Array(this._size);
  29643. this._invMassWithoutCfm[i] = new Array(this._size);
  29644. let _g1 = 0;
  29645. let _g2 = this._size;
  29646. while(_g1 < _g2) {
  29647. let j = _g1++;
  29648. this.tmpMatrix[i][j] = 0;
  29649. this._invMass[i][j] = 0;
  29650. this._invMassWithoutCfm[i][j] = 0;
  29651. }
  29652. }
  29653. this._maxSubmatrixId = 1 << this._size;
  29654. this._cacheComputed = new Array(this._maxSubmatrixId);
  29655. this._cachedSubmatrices = new Array(this._maxSubmatrixId);
  29656. let _g2 = 0;
  29657. let _g3 = this._maxSubmatrixId;
  29658. while(_g2 < _g3) {
  29659. let i = _g2++;
  29660. let t;
  29661. t = (i & 85) + (i >> 1 & 85);
  29662. t = (t & 51) + (t >> 2 & 51);
  29663. t = (t & 15) + (t >> 4 & 15);
  29664. let matrixSize = t;
  29665. let subMatrix = new Array(matrixSize);
  29666. let _g = 0;
  29667. while(_g < matrixSize) {
  29668. let j = _g++;
  29669. subMatrix[j] = new Array(matrixSize);
  29670. let _g1 = 0;
  29671. while(_g1 < matrixSize) subMatrix[j][_g1++] = 0;
  29672. }
  29673. this._cacheComputed[i] = false;
  29674. this._cachedSubmatrices[i] = subMatrix;
  29675. }
  29676. }
  29677. computeSubmatrix(id,indices,size) {
  29678. let _g = 0;
  29679. while(_g < size) {
  29680. let i = _g++;
  29681. let ii = indices[i];
  29682. let _g1 = 0;
  29683. while(_g1 < size) {
  29684. let j = _g1++;
  29685. this.tmpMatrix[i][j] = this._invMass[ii][indices[j]];
  29686. }
  29687. }
  29688. let src = this.tmpMatrix;
  29689. let dst = this._cachedSubmatrices[id];
  29690. let srci;
  29691. let dsti;
  29692. let srcj;
  29693. let dstj;
  29694. let diag;
  29695. switch(size) {
  29696. case 4:
  29697. srci = src[0];
  29698. dsti = dst[0];
  29699. diag = 1 / srci[0];
  29700. dsti[0] = diag;
  29701. srci[1] *= diag;
  29702. srci[2] *= diag;
  29703. srci[3] *= diag;
  29704. srcj = src[1];
  29705. dstj = dst[1];
  29706. dstj[0] = -diag * srcj[0];
  29707. srcj[1] -= srci[1] * srcj[0];
  29708. srcj[2] -= srci[2] * srcj[0];
  29709. srcj[3] -= srci[3] * srcj[0];
  29710. srcj = src[2];
  29711. dstj = dst[2];
  29712. dstj[0] = -diag * srcj[0];
  29713. srcj[1] -= srci[1] * srcj[0];
  29714. srcj[2] -= srci[2] * srcj[0];
  29715. srcj[3] -= srci[3] * srcj[0];
  29716. srcj = src[3];
  29717. dstj = dst[3];
  29718. dstj[0] = -diag * srcj[0];
  29719. srcj[1] -= srci[1] * srcj[0];
  29720. srcj[2] -= srci[2] * srcj[0];
  29721. srcj[3] -= srci[3] * srcj[0];
  29722. srci = src[1];
  29723. dsti = dst[1];
  29724. diag = 1 / srci[1];
  29725. dsti[1] = diag;
  29726. dsti[0] *= diag;
  29727. srci[2] *= diag;
  29728. srci[3] *= diag;
  29729. srcj = src[0];
  29730. dstj = dst[0];
  29731. dstj[0] -= dsti[0] * srcj[1];
  29732. srcj[2] -= srci[2] * srcj[1];
  29733. srcj[3] -= srci[3] * srcj[1];
  29734. srcj = src[2];
  29735. dstj = dst[2];
  29736. dstj[0] -= dsti[0] * srcj[1];
  29737. dstj[1] = -diag * srcj[1];
  29738. srcj[2] -= srci[2] * srcj[1];
  29739. srcj[3] -= srci[3] * srcj[1];
  29740. srcj = src[3];
  29741. dstj = dst[3];
  29742. dstj[0] -= dsti[0] * srcj[1];
  29743. dstj[1] = -diag * srcj[1];
  29744. srcj[2] -= srci[2] * srcj[1];
  29745. srcj[3] -= srci[3] * srcj[1];
  29746. srci = src[2];
  29747. dsti = dst[2];
  29748. diag = 1 / srci[2];
  29749. dsti[2] = diag;
  29750. dsti[0] *= diag;
  29751. dsti[1] *= diag;
  29752. srci[3] *= diag;
  29753. srcj = src[0];
  29754. dstj = dst[0];
  29755. dstj[0] -= dsti[0] * srcj[2];
  29756. srcj[3] -= srci[3] * srcj[2];
  29757. srcj = src[1];
  29758. dstj = dst[1];
  29759. dstj[0] -= dsti[0] * srcj[2];
  29760. dstj[1] -= dsti[1] * srcj[2];
  29761. srcj[3] -= srci[3] * srcj[2];
  29762. srcj = src[3];
  29763. dstj = dst[3];
  29764. dstj[0] -= dsti[0] * srcj[2];
  29765. dstj[1] -= dsti[1] * srcj[2];
  29766. dstj[2] = -diag * srcj[2];
  29767. srcj[3] -= srci[3] * srcj[2];
  29768. srci = src[3];
  29769. dsti = dst[3];
  29770. diag = 1 / srci[3];
  29771. dsti[3] = diag;
  29772. dsti[0] *= diag;
  29773. dsti[1] *= diag;
  29774. dsti[2] *= diag;
  29775. srcj = src[0];
  29776. dstj = dst[0];
  29777. dstj[0] -= dsti[0] * srcj[3];
  29778. srcj = src[1];
  29779. dstj = dst[1];
  29780. dstj[0] -= dsti[0] * srcj[3];
  29781. dstj[1] -= dsti[1] * srcj[3];
  29782. srcj = src[2];
  29783. dstj = dst[2];
  29784. dstj[0] -= dsti[0] * srcj[3];
  29785. dstj[1] -= dsti[1] * srcj[3];
  29786. dstj[2] -= dsti[2] * srcj[3];
  29787. dsti = dst[1];
  29788. dst[0][1] = dsti[0];
  29789. dsti = dst[2];
  29790. dst[0][2] = dsti[0];
  29791. dst[1][2] = dsti[1];
  29792. dsti = dst[3];
  29793. dst[0][3] = dsti[0];
  29794. dst[1][3] = dsti[1];
  29795. dst[2][3] = dsti[2];
  29796. break;
  29797. case 5:
  29798. srci = src[0];
  29799. dsti = dst[0];
  29800. diag = 1 / srci[0];
  29801. dsti[0] = diag;
  29802. srci[1] *= diag;
  29803. srci[2] *= diag;
  29804. srci[3] *= diag;
  29805. srci[4] *= diag;
  29806. srcj = src[1];
  29807. dstj = dst[1];
  29808. dstj[0] = -diag * srcj[0];
  29809. srcj[1] -= srci[1] * srcj[0];
  29810. srcj[2] -= srci[2] * srcj[0];
  29811. srcj[3] -= srci[3] * srcj[0];
  29812. srcj[4] -= srci[4] * srcj[0];
  29813. srcj = src[2];
  29814. dstj = dst[2];
  29815. dstj[0] = -diag * srcj[0];
  29816. srcj[1] -= srci[1] * srcj[0];
  29817. srcj[2] -= srci[2] * srcj[0];
  29818. srcj[3] -= srci[3] * srcj[0];
  29819. srcj[4] -= srci[4] * srcj[0];
  29820. srcj = src[3];
  29821. dstj = dst[3];
  29822. dstj[0] = -diag * srcj[0];
  29823. srcj[1] -= srci[1] * srcj[0];
  29824. srcj[2] -= srci[2] * srcj[0];
  29825. srcj[3] -= srci[3] * srcj[0];
  29826. srcj[4] -= srci[4] * srcj[0];
  29827. srcj = src[4];
  29828. dstj = dst[4];
  29829. dstj[0] = -diag * srcj[0];
  29830. srcj[1] -= srci[1] * srcj[0];
  29831. srcj[2] -= srci[2] * srcj[0];
  29832. srcj[3] -= srci[3] * srcj[0];
  29833. srcj[4] -= srci[4] * srcj[0];
  29834. srci = src[1];
  29835. dsti = dst[1];
  29836. diag = 1 / srci[1];
  29837. dsti[1] = diag;
  29838. dsti[0] *= diag;
  29839. srci[2] *= diag;
  29840. srci[3] *= diag;
  29841. srci[4] *= diag;
  29842. srcj = src[0];
  29843. dstj = dst[0];
  29844. dstj[0] -= dsti[0] * srcj[1];
  29845. srcj[2] -= srci[2] * srcj[1];
  29846. srcj[3] -= srci[3] * srcj[1];
  29847. srcj[4] -= srci[4] * srcj[1];
  29848. srcj = src[2];
  29849. dstj = dst[2];
  29850. dstj[0] -= dsti[0] * srcj[1];
  29851. dstj[1] = -diag * srcj[1];
  29852. srcj[2] -= srci[2] * srcj[1];
  29853. srcj[3] -= srci[3] * srcj[1];
  29854. srcj[4] -= srci[4] * srcj[1];
  29855. srcj = src[3];
  29856. dstj = dst[3];
  29857. dstj[0] -= dsti[0] * srcj[1];
  29858. dstj[1] = -diag * srcj[1];
  29859. srcj[2] -= srci[2] * srcj[1];
  29860. srcj[3] -= srci[3] * srcj[1];
  29861. srcj[4] -= srci[4] * srcj[1];
  29862. srcj = src[4];
  29863. dstj = dst[4];
  29864. dstj[0] -= dsti[0] * srcj[1];
  29865. dstj[1] = -diag * srcj[1];
  29866. srcj[2] -= srci[2] * srcj[1];
  29867. srcj[3] -= srci[3] * srcj[1];
  29868. srcj[4] -= srci[4] * srcj[1];
  29869. srci = src[2];
  29870. dsti = dst[2];
  29871. diag = 1 / srci[2];
  29872. dsti[2] = diag;
  29873. dsti[0] *= diag;
  29874. dsti[1] *= diag;
  29875. srci[3] *= diag;
  29876. srci[4] *= diag;
  29877. srcj = src[0];
  29878. dstj = dst[0];
  29879. dstj[0] -= dsti[0] * srcj[2];
  29880. srcj[3] -= srci[3] * srcj[2];
  29881. srcj[4] -= srci[4] * srcj[2];
  29882. srcj = src[1];
  29883. dstj = dst[1];
  29884. dstj[0] -= dsti[0] * srcj[2];
  29885. dstj[1] -= dsti[1] * srcj[2];
  29886. srcj[3] -= srci[3] * srcj[2];
  29887. srcj[4] -= srci[4] * srcj[2];
  29888. srcj = src[3];
  29889. dstj = dst[3];
  29890. dstj[0] -= dsti[0] * srcj[2];
  29891. dstj[1] -= dsti[1] * srcj[2];
  29892. dstj[2] = -diag * srcj[2];
  29893. srcj[3] -= srci[3] * srcj[2];
  29894. srcj[4] -= srci[4] * srcj[2];
  29895. srcj = src[4];
  29896. dstj = dst[4];
  29897. dstj[0] -= dsti[0] * srcj[2];
  29898. dstj[1] -= dsti[1] * srcj[2];
  29899. dstj[2] = -diag * srcj[2];
  29900. srcj[3] -= srci[3] * srcj[2];
  29901. srcj[4] -= srci[4] * srcj[2];
  29902. srci = src[3];
  29903. dsti = dst[3];
  29904. diag = 1 / srci[3];
  29905. dsti[3] = diag;
  29906. dsti[0] *= diag;
  29907. dsti[1] *= diag;
  29908. dsti[2] *= diag;
  29909. srci[4] *= diag;
  29910. srcj = src[0];
  29911. dstj = dst[0];
  29912. dstj[0] -= dsti[0] * srcj[3];
  29913. srcj[4] -= srci[4] * srcj[3];
  29914. srcj = src[1];
  29915. dstj = dst[1];
  29916. dstj[0] -= dsti[0] * srcj[3];
  29917. dstj[1] -= dsti[1] * srcj[3];
  29918. srcj[4] -= srci[4] * srcj[3];
  29919. srcj = src[2];
  29920. dstj = dst[2];
  29921. dstj[0] -= dsti[0] * srcj[3];
  29922. dstj[1] -= dsti[1] * srcj[3];
  29923. dstj[2] -= dsti[2] * srcj[3];
  29924. srcj[4] -= srci[4] * srcj[3];
  29925. srcj = src[4];
  29926. dstj = dst[4];
  29927. dstj[0] -= dsti[0] * srcj[3];
  29928. dstj[1] -= dsti[1] * srcj[3];
  29929. dstj[2] -= dsti[2] * srcj[3];
  29930. dstj[3] = -diag * srcj[3];
  29931. srcj[4] -= srci[4] * srcj[3];
  29932. srci = src[4];
  29933. dsti = dst[4];
  29934. diag = 1 / srci[4];
  29935. dsti[4] = diag;
  29936. dsti[0] *= diag;
  29937. dsti[1] *= diag;
  29938. dsti[2] *= diag;
  29939. dsti[3] *= diag;
  29940. srcj = src[0];
  29941. dstj = dst[0];
  29942. dstj[0] -= dsti[0] * srcj[4];
  29943. srcj = src[1];
  29944. dstj = dst[1];
  29945. dstj[0] -= dsti[0] * srcj[4];
  29946. dstj[1] -= dsti[1] * srcj[4];
  29947. srcj = src[2];
  29948. dstj = dst[2];
  29949. dstj[0] -= dsti[0] * srcj[4];
  29950. dstj[1] -= dsti[1] * srcj[4];
  29951. dstj[2] -= dsti[2] * srcj[4];
  29952. srcj = src[3];
  29953. dstj = dst[3];
  29954. dstj[0] -= dsti[0] * srcj[4];
  29955. dstj[1] -= dsti[1] * srcj[4];
  29956. dstj[2] -= dsti[2] * srcj[4];
  29957. dstj[3] -= dsti[3] * srcj[4];
  29958. dsti = dst[1];
  29959. dst[0][1] = dsti[0];
  29960. dsti = dst[2];
  29961. dst[0][2] = dsti[0];
  29962. dst[1][2] = dsti[1];
  29963. dsti = dst[3];
  29964. dst[0][3] = dsti[0];
  29965. dst[1][3] = dsti[1];
  29966. dst[2][3] = dsti[2];
  29967. dsti = dst[4];
  29968. dst[0][4] = dsti[0];
  29969. dst[1][4] = dsti[1];
  29970. dst[2][4] = dsti[2];
  29971. dst[3][4] = dsti[3];
  29972. break;
  29973. case 6:
  29974. srci = src[0];
  29975. dsti = dst[0];
  29976. diag = 1 / srci[0];
  29977. dsti[0] = diag;
  29978. srci[1] *= diag;
  29979. srci[2] *= diag;
  29980. srci[3] *= diag;
  29981. srci[4] *= diag;
  29982. srci[5] *= diag;
  29983. srcj = src[1];
  29984. dstj = dst[1];
  29985. dstj[0] = -diag * srcj[0];
  29986. srcj[1] -= srci[1] * srcj[0];
  29987. srcj[2] -= srci[2] * srcj[0];
  29988. srcj[3] -= srci[3] * srcj[0];
  29989. srcj[4] -= srci[4] * srcj[0];
  29990. srcj[5] -= srci[5] * srcj[0];
  29991. srcj = src[2];
  29992. dstj = dst[2];
  29993. dstj[0] = -diag * srcj[0];
  29994. srcj[1] -= srci[1] * srcj[0];
  29995. srcj[2] -= srci[2] * srcj[0];
  29996. srcj[3] -= srci[3] * srcj[0];
  29997. srcj[4] -= srci[4] * srcj[0];
  29998. srcj[5] -= srci[5] * srcj[0];
  29999. srcj = src[3];
  30000. dstj = dst[3];
  30001. dstj[0] = -diag * srcj[0];
  30002. srcj[1] -= srci[1] * srcj[0];
  30003. srcj[2] -= srci[2] * srcj[0];
  30004. srcj[3] -= srci[3] * srcj[0];
  30005. srcj[4] -= srci[4] * srcj[0];
  30006. srcj[5] -= srci[5] * srcj[0];
  30007. srcj = src[4];
  30008. dstj = dst[4];
  30009. dstj[0] = -diag * srcj[0];
  30010. srcj[1] -= srci[1] * srcj[0];
  30011. srcj[2] -= srci[2] * srcj[0];
  30012. srcj[3] -= srci[3] * srcj[0];
  30013. srcj[4] -= srci[4] * srcj[0];
  30014. srcj[5] -= srci[5] * srcj[0];
  30015. srcj = src[5];
  30016. dstj = dst[5];
  30017. dstj[0] = -diag * srcj[0];
  30018. srcj[1] -= srci[1] * srcj[0];
  30019. srcj[2] -= srci[2] * srcj[0];
  30020. srcj[3] -= srci[3] * srcj[0];
  30021. srcj[4] -= srci[4] * srcj[0];
  30022. srcj[5] -= srci[5] * srcj[0];
  30023. srci = src[1];
  30024. dsti = dst[1];
  30025. diag = 1 / srci[1];
  30026. dsti[1] = diag;
  30027. dsti[0] *= diag;
  30028. srci[2] *= diag;
  30029. srci[3] *= diag;
  30030. srci[4] *= diag;
  30031. srci[5] *= diag;
  30032. srcj = src[0];
  30033. dstj = dst[0];
  30034. dstj[0] -= dsti[0] * srcj[1];
  30035. srcj[2] -= srci[2] * srcj[1];
  30036. srcj[3] -= srci[3] * srcj[1];
  30037. srcj[4] -= srci[4] * srcj[1];
  30038. srcj[5] -= srci[5] * srcj[1];
  30039. srcj = src[2];
  30040. dstj = dst[2];
  30041. dstj[0] -= dsti[0] * srcj[1];
  30042. dstj[1] = -diag * srcj[1];
  30043. srcj[2] -= srci[2] * srcj[1];
  30044. srcj[3] -= srci[3] * srcj[1];
  30045. srcj[4] -= srci[4] * srcj[1];
  30046. srcj[5] -= srci[5] * srcj[1];
  30047. srcj = src[3];
  30048. dstj = dst[3];
  30049. dstj[0] -= dsti[0] * srcj[1];
  30050. dstj[1] = -diag * srcj[1];
  30051. srcj[2] -= srci[2] * srcj[1];
  30052. srcj[3] -= srci[3] * srcj[1];
  30053. srcj[4] -= srci[4] * srcj[1];
  30054. srcj[5] -= srci[5] * srcj[1];
  30055. srcj = src[4];
  30056. dstj = dst[4];
  30057. dstj[0] -= dsti[0] * srcj[1];
  30058. dstj[1] = -diag * srcj[1];
  30059. srcj[2] -= srci[2] * srcj[1];
  30060. srcj[3] -= srci[3] * srcj[1];
  30061. srcj[4] -= srci[4] * srcj[1];
  30062. srcj[5] -= srci[5] * srcj[1];
  30063. srcj = src[5];
  30064. dstj = dst[5];
  30065. dstj[0] -= dsti[0] * srcj[1];
  30066. dstj[1] = -diag * srcj[1];
  30067. srcj[2] -= srci[2] * srcj[1];
  30068. srcj[3] -= srci[3] * srcj[1];
  30069. srcj[4] -= srci[4] * srcj[1];
  30070. srcj[5] -= srci[5] * srcj[1];
  30071. srci = src[2];
  30072. dsti = dst[2];
  30073. diag = 1 / srci[2];
  30074. dsti[2] = diag;
  30075. dsti[0] *= diag;
  30076. dsti[1] *= diag;
  30077. srci[3] *= diag;
  30078. srci[4] *= diag;
  30079. srci[5] *= diag;
  30080. srcj = src[0];
  30081. dstj = dst[0];
  30082. dstj[0] -= dsti[0] * srcj[2];
  30083. srcj[3] -= srci[3] * srcj[2];
  30084. srcj[4] -= srci[4] * srcj[2];
  30085. srcj[5] -= srci[5] * srcj[2];
  30086. srcj = src[1];
  30087. dstj = dst[1];
  30088. dstj[0] -= dsti[0] * srcj[2];
  30089. dstj[1] -= dsti[1] * srcj[2];
  30090. srcj[3] -= srci[3] * srcj[2];
  30091. srcj[4] -= srci[4] * srcj[2];
  30092. srcj[5] -= srci[5] * srcj[2];
  30093. srcj = src[3];
  30094. dstj = dst[3];
  30095. dstj[0] -= dsti[0] * srcj[2];
  30096. dstj[1] -= dsti[1] * srcj[2];
  30097. dstj[2] = -diag * srcj[2];
  30098. srcj[3] -= srci[3] * srcj[2];
  30099. srcj[4] -= srci[4] * srcj[2];
  30100. srcj[5] -= srci[5] * srcj[2];
  30101. srcj = src[4];
  30102. dstj = dst[4];
  30103. dstj[0] -= dsti[0] * srcj[2];
  30104. dstj[1] -= dsti[1] * srcj[2];
  30105. dstj[2] = -diag * srcj[2];
  30106. srcj[3] -= srci[3] * srcj[2];
  30107. srcj[4] -= srci[4] * srcj[2];
  30108. srcj[5] -= srci[5] * srcj[2];
  30109. srcj = src[5];
  30110. dstj = dst[5];
  30111. dstj[0] -= dsti[0] * srcj[2];
  30112. dstj[1] -= dsti[1] * srcj[2];
  30113. dstj[2] = -diag * srcj[2];
  30114. srcj[3] -= srci[3] * srcj[2];
  30115. srcj[4] -= srci[4] * srcj[2];
  30116. srcj[5] -= srci[5] * srcj[2];
  30117. srci = src[3];
  30118. dsti = dst[3];
  30119. diag = 1 / srci[3];
  30120. dsti[3] = diag;
  30121. dsti[0] *= diag;
  30122. dsti[1] *= diag;
  30123. dsti[2] *= diag;
  30124. srci[4] *= diag;
  30125. srci[5] *= diag;
  30126. srcj = src[0];
  30127. dstj = dst[0];
  30128. dstj[0] -= dsti[0] * srcj[3];
  30129. srcj[4] -= srci[4] * srcj[3];
  30130. srcj[5] -= srci[5] * srcj[3];
  30131. srcj = src[1];
  30132. dstj = dst[1];
  30133. dstj[0] -= dsti[0] * srcj[3];
  30134. dstj[1] -= dsti[1] * srcj[3];
  30135. srcj[4] -= srci[4] * srcj[3];
  30136. srcj[5] -= srci[5] * srcj[3];
  30137. srcj = src[2];
  30138. dstj = dst[2];
  30139. dstj[0] -= dsti[0] * srcj[3];
  30140. dstj[1] -= dsti[1] * srcj[3];
  30141. dstj[2] -= dsti[2] * srcj[3];
  30142. srcj[4] -= srci[4] * srcj[3];
  30143. srcj[5] -= srci[5] * srcj[3];
  30144. srcj = src[4];
  30145. dstj = dst[4];
  30146. dstj[0] -= dsti[0] * srcj[3];
  30147. dstj[1] -= dsti[1] * srcj[3];
  30148. dstj[2] -= dsti[2] * srcj[3];
  30149. dstj[3] = -diag * srcj[3];
  30150. srcj[4] -= srci[4] * srcj[3];
  30151. srcj[5] -= srci[5] * srcj[3];
  30152. srcj = src[5];
  30153. dstj = dst[5];
  30154. dstj[0] -= dsti[0] * srcj[3];
  30155. dstj[1] -= dsti[1] * srcj[3];
  30156. dstj[2] -= dsti[2] * srcj[3];
  30157. dstj[3] = -diag * srcj[3];
  30158. srcj[4] -= srci[4] * srcj[3];
  30159. srcj[5] -= srci[5] * srcj[3];
  30160. srci = src[4];
  30161. dsti = dst[4];
  30162. diag = 1 / srci[4];
  30163. dsti[4] = diag;
  30164. dsti[0] *= diag;
  30165. dsti[1] *= diag;
  30166. dsti[2] *= diag;
  30167. dsti[3] *= diag;
  30168. srci[5] *= diag;
  30169. srcj = src[0];
  30170. dstj = dst[0];
  30171. dstj[0] -= dsti[0] * srcj[4];
  30172. srcj[5] -= srci[5] * srcj[4];
  30173. srcj = src[1];
  30174. dstj = dst[1];
  30175. dstj[0] -= dsti[0] * srcj[4];
  30176. dstj[1] -= dsti[1] * srcj[4];
  30177. srcj[5] -= srci[5] * srcj[4];
  30178. srcj = src[2];
  30179. dstj = dst[2];
  30180. dstj[0] -= dsti[0] * srcj[4];
  30181. dstj[1] -= dsti[1] * srcj[4];
  30182. dstj[2] -= dsti[2] * srcj[4];
  30183. srcj[5] -= srci[5] * srcj[4];
  30184. srcj = src[3];
  30185. dstj = dst[3];
  30186. dstj[0] -= dsti[0] * srcj[4];
  30187. dstj[1] -= dsti[1] * srcj[4];
  30188. dstj[2] -= dsti[2] * srcj[4];
  30189. dstj[3] -= dsti[3] * srcj[4];
  30190. srcj[5] -= srci[5] * srcj[4];
  30191. srcj = src[5];
  30192. dstj = dst[5];
  30193. dstj[0] -= dsti[0] * srcj[4];
  30194. dstj[1] -= dsti[1] * srcj[4];
  30195. dstj[2] -= dsti[2] * srcj[4];
  30196. dstj[3] -= dsti[3] * srcj[4];
  30197. dstj[4] = -diag * srcj[4];
  30198. srcj[5] -= srci[5] * srcj[4];
  30199. srci = src[5];
  30200. dsti = dst[5];
  30201. diag = 1 / srci[5];
  30202. dsti[5] = diag;
  30203. dsti[0] *= diag;
  30204. dsti[1] *= diag;
  30205. dsti[2] *= diag;
  30206. dsti[3] *= diag;
  30207. dsti[4] *= diag;
  30208. srcj = src[0];
  30209. dstj = dst[0];
  30210. dstj[0] -= dsti[0] * srcj[5];
  30211. srcj = src[1];
  30212. dstj = dst[1];
  30213. dstj[0] -= dsti[0] * srcj[5];
  30214. dstj[1] -= dsti[1] * srcj[5];
  30215. srcj = src[2];
  30216. dstj = dst[2];
  30217. dstj[0] -= dsti[0] * srcj[5];
  30218. dstj[1] -= dsti[1] * srcj[5];
  30219. dstj[2] -= dsti[2] * srcj[5];
  30220. srcj = src[3];
  30221. dstj = dst[3];
  30222. dstj[0] -= dsti[0] * srcj[5];
  30223. dstj[1] -= dsti[1] * srcj[5];
  30224. dstj[2] -= dsti[2] * srcj[5];
  30225. dstj[3] -= dsti[3] * srcj[5];
  30226. srcj = src[4];
  30227. dstj = dst[4];
  30228. dstj[0] -= dsti[0] * srcj[5];
  30229. dstj[1] -= dsti[1] * srcj[5];
  30230. dstj[2] -= dsti[2] * srcj[5];
  30231. dstj[3] -= dsti[3] * srcj[5];
  30232. dstj[4] -= dsti[4] * srcj[5];
  30233. dsti = dst[1];
  30234. dst[0][1] = dsti[0];
  30235. dsti = dst[2];
  30236. dst[0][2] = dsti[0];
  30237. dst[1][2] = dsti[1];
  30238. dsti = dst[3];
  30239. dst[0][3] = dsti[0];
  30240. dst[1][3] = dsti[1];
  30241. dst[2][3] = dsti[2];
  30242. dsti = dst[4];
  30243. dst[0][4] = dsti[0];
  30244. dst[1][4] = dsti[1];
  30245. dst[2][4] = dsti[2];
  30246. dst[3][4] = dsti[3];
  30247. dsti = dst[5];
  30248. dst[0][5] = dsti[0];
  30249. dst[1][5] = dsti[1];
  30250. dst[2][5] = dsti[2];
  30251. dst[3][5] = dsti[3];
  30252. dst[4][5] = dsti[4];
  30253. break;
  30254. default:
  30255. let _g1 = 0;
  30256. while(_g1 < size) {
  30257. let i = _g1++;
  30258. srci = src[i];
  30259. dsti = dst[i];
  30260. let diag = 1 / srci[i];
  30261. dsti[i] = diag;
  30262. let _g = 0;
  30263. while(_g < i) dsti[_g++] *= diag;
  30264. let _g2 = i + 1;
  30265. while(_g2 < size) srci[_g2++] *= diag;
  30266. let _g3 = 0;
  30267. while(_g3 < i) {
  30268. let j = _g3++;
  30269. srcj = src[j];
  30270. dstj = dst[j];
  30271. let _g = 0;
  30272. let _g1 = j + 1;
  30273. while(_g < _g1) {
  30274. let k = _g++;
  30275. dstj[k] -= dsti[k] * srcj[i];
  30276. }
  30277. let _g2 = i + 1;
  30278. while(_g2 < size) {
  30279. let k = _g2++;
  30280. srcj[k] -= srci[k] * srcj[i];
  30281. }
  30282. }
  30283. let _g4 = i + 1;
  30284. while(_g4 < size) {
  30285. let j = _g4++;
  30286. srcj = src[j];
  30287. dstj = dst[j];
  30288. let _g = 0;
  30289. while(_g < i) {
  30290. let k = _g++;
  30291. dstj[k] -= dsti[k] * srcj[i];
  30292. }
  30293. dstj[i] = -diag * srcj[i];
  30294. let _g1 = i + 1;
  30295. while(_g1 < size) {
  30296. let k = _g1++;
  30297. srcj[k] -= srci[k] * srcj[i];
  30298. }
  30299. }
  30300. }
  30301. let _g2 = 1;
  30302. while(_g2 < size) {
  30303. let i = _g2++;
  30304. dsti = dst[i];
  30305. let _g = 0;
  30306. while(_g < i) {
  30307. let j = _g++;
  30308. dst[j][i] = dsti[j];
  30309. }
  30310. }
  30311. }
  30312. }
  30313. computeInvMass(info,massData) {
  30314. let invMass = this._invMass;
  30315. let invMassWithoutCfm = this._invMassWithoutCfm;
  30316. let numRows = info.numRows;
  30317. let b1 = info.b1;
  30318. let b2 = info.b2;
  30319. let invM1 = b1._invMass;
  30320. let invM2 = b2._invMass;
  30321. let invI100;
  30322. let invI101;
  30323. let invI102;
  30324. let invI110;
  30325. let invI111;
  30326. let invI112;
  30327. let invI120;
  30328. let invI121;
  30329. let invI122;
  30330. let invI200;
  30331. let invI201;
  30332. let invI202;
  30333. let invI210;
  30334. let invI211;
  30335. let invI212;
  30336. let invI220;
  30337. let invI221;
  30338. let invI222;
  30339. invI100 = b1._invInertia00;
  30340. invI101 = b1._invInertia01;
  30341. invI102 = b1._invInertia02;
  30342. invI110 = b1._invInertia10;
  30343. invI111 = b1._invInertia11;
  30344. invI112 = b1._invInertia12;
  30345. invI120 = b1._invInertia20;
  30346. invI121 = b1._invInertia21;
  30347. invI122 = b1._invInertia22;
  30348. invI200 = b2._invInertia00;
  30349. invI201 = b2._invInertia01;
  30350. invI202 = b2._invInertia02;
  30351. invI210 = b2._invInertia10;
  30352. invI211 = b2._invInertia11;
  30353. invI212 = b2._invInertia12;
  30354. invI220 = b2._invInertia20;
  30355. invI221 = b2._invInertia21;
  30356. invI222 = b2._invInertia22;
  30357. let _g = 0;
  30358. while(_g < numRows) {
  30359. let i = _g++;
  30360. let j = info.rows[i].jacobian;
  30361. let md = massData[i];
  30362. j.updateSparsity();
  30363. if((j.flag & 1) != 0) {
  30364. md.invMLin1X = j.lin1X * invM1;
  30365. md.invMLin1Y = j.lin1Y * invM1;
  30366. md.invMLin1Z = j.lin1Z * invM1;
  30367. md.invMLin2X = j.lin2X * invM2;
  30368. md.invMLin2Y = j.lin2Y * invM2;
  30369. md.invMLin2Z = j.lin2Z * invM2;
  30370. } else {
  30371. md.invMLin1X = 0;
  30372. md.invMLin1Y = 0;
  30373. md.invMLin1Z = 0;
  30374. md.invMLin2X = 0;
  30375. md.invMLin2Y = 0;
  30376. md.invMLin2Z = 0;
  30377. }
  30378. if((j.flag & 2) != 0) {
  30379. let __tmp__X;
  30380. let __tmp__Y;
  30381. let __tmp__Z;
  30382. __tmp__X = invI100 * j.ang1X + invI101 * j.ang1Y + invI102 * j.ang1Z;
  30383. __tmp__Y = invI110 * j.ang1X + invI111 * j.ang1Y + invI112 * j.ang1Z;
  30384. __tmp__Z = invI120 * j.ang1X + invI121 * j.ang1Y + invI122 * j.ang1Z;
  30385. md.invMAng1X = __tmp__X;
  30386. md.invMAng1Y = __tmp__Y;
  30387. md.invMAng1Z = __tmp__Z;
  30388. let __tmp__X1;
  30389. let __tmp__Y1;
  30390. let __tmp__Z1;
  30391. __tmp__X1 = invI200 * j.ang2X + invI201 * j.ang2Y + invI202 * j.ang2Z;
  30392. __tmp__Y1 = invI210 * j.ang2X + invI211 * j.ang2Y + invI212 * j.ang2Z;
  30393. __tmp__Z1 = invI220 * j.ang2X + invI221 * j.ang2Y + invI222 * j.ang2Z;
  30394. md.invMAng2X = __tmp__X1;
  30395. md.invMAng2Y = __tmp__Y1;
  30396. md.invMAng2Z = __tmp__Z1;
  30397. } else {
  30398. md.invMAng1X = 0;
  30399. md.invMAng1Y = 0;
  30400. md.invMAng1Z = 0;
  30401. md.invMAng2X = 0;
  30402. md.invMAng2Y = 0;
  30403. md.invMAng2Z = 0;
  30404. }
  30405. }
  30406. let _g1 = 0;
  30407. while(_g1 < numRows) {
  30408. let i = _g1++;
  30409. let j1 = info.rows[i].jacobian;
  30410. let _g = i;
  30411. while(_g < numRows) {
  30412. let j = _g++;
  30413. let md2 = massData[j];
  30414. let val = j1.lin1X * md2.invMLin1X + j1.lin1Y * md2.invMLin1Y + j1.lin1Z * md2.invMLin1Z + (j1.ang1X * md2.invMAng1X + j1.ang1Y * md2.invMAng1Y + j1.ang1Z * md2.invMAng1Z) + (j1.lin2X * md2.invMLin2X + j1.lin2Y * md2.invMLin2Y + j1.lin2Z * md2.invMLin2Z) + (j1.ang2X * md2.invMAng2X + j1.ang2Y * md2.invMAng2Y + j1.ang2Z * md2.invMAng2Z);
  30415. if(i == j) {
  30416. invMass[i][j] = val + info.rows[i].cfm;
  30417. invMassWithoutCfm[i][j] = val;
  30418. md2.mass = val + info.rows[i].cfm;
  30419. md2.massWithoutCfm = val;
  30420. if(md2.mass != 0) {
  30421. md2.mass = 1 / md2.mass;
  30422. }
  30423. if(md2.massWithoutCfm != 0) {
  30424. md2.massWithoutCfm = 1 / md2.massWithoutCfm;
  30425. }
  30426. } else {
  30427. invMass[i][j] = val;
  30428. invMass[j][i] = val;
  30429. invMassWithoutCfm[i][j] = val;
  30430. invMassWithoutCfm[j][i] = val;
  30431. }
  30432. }
  30433. }
  30434. let _g2 = 0;
  30435. let _g3 = this._maxSubmatrixId;
  30436. while(_g2 < _g3) this._cacheComputed[_g2++] = false;
  30437. }
  30438. }
  30439. if(!oimo.dynamics.constraint.solver.pgs) oimo.dynamics.constraint.solver.pgs = {};
  30440. oimo.dynamics.constraint.solver.pgs.PgsContactConstraintSolver = class oimo_dynamics_constraint_solver_pgs_PgsContactConstraintSolver extends oimo.dynamics.constraint.ConstraintSolver {
  30441. constructor(constraint) {
  30442. super();
  30443. this.constraint = constraint;
  30444. this.info = new oimo.dynamics.constraint.info.contact.ContactSolverInfo();
  30445. this.massData = new Array(oimo.common.Setting.maxManifoldPoints);
  30446. let _g = 0;
  30447. let _g1 = this.massData.length;
  30448. while(_g < _g1) this.massData[_g++] = new oimo.dynamics.constraint.solver.common.ContactSolverMassDataRow();
  30449. }
  30450. preSolveVelocity(timeStep) {
  30451. this.constraint._getVelocitySolverInfo(timeStep,this.info);
  30452. this._b1 = this.info.b1;
  30453. this._b2 = this.info.b2;
  30454. let invM1 = this._b1._invMass;
  30455. let invM2 = this._b2._invMass;
  30456. let invI100;
  30457. let invI101;
  30458. let invI102;
  30459. let invI110;
  30460. let invI111;
  30461. let invI112;
  30462. let invI120;
  30463. let invI121;
  30464. let invI122;
  30465. let invI200;
  30466. let invI201;
  30467. let invI202;
  30468. let invI210;
  30469. let invI211;
  30470. let invI212;
  30471. let invI220;
  30472. let invI221;
  30473. let invI222;
  30474. invI100 = this._b1._invInertia00;
  30475. invI101 = this._b1._invInertia01;
  30476. invI102 = this._b1._invInertia02;
  30477. invI110 = this._b1._invInertia10;
  30478. invI111 = this._b1._invInertia11;
  30479. invI112 = this._b1._invInertia12;
  30480. invI120 = this._b1._invInertia20;
  30481. invI121 = this._b1._invInertia21;
  30482. invI122 = this._b1._invInertia22;
  30483. invI200 = this._b2._invInertia00;
  30484. invI201 = this._b2._invInertia01;
  30485. invI202 = this._b2._invInertia02;
  30486. invI210 = this._b2._invInertia10;
  30487. invI211 = this._b2._invInertia11;
  30488. invI212 = this._b2._invInertia12;
  30489. invI220 = this._b2._invInertia20;
  30490. invI221 = this._b2._invInertia21;
  30491. invI222 = this._b2._invInertia22;
  30492. let _g = 0;
  30493. let _g1 = this.info.numRows;
  30494. while(_g < _g1) {
  30495. let i = _g++;
  30496. let row = this.info.rows[i];
  30497. let md = this.massData[i];
  30498. let j = row.jacobianN;
  30499. md.invMLinN1X = j.lin1X * invM1;
  30500. md.invMLinN1Y = j.lin1Y * invM1;
  30501. md.invMLinN1Z = j.lin1Z * invM1;
  30502. md.invMLinN2X = j.lin2X * invM2;
  30503. md.invMLinN2Y = j.lin2Y * invM2;
  30504. md.invMLinN2Z = j.lin2Z * invM2;
  30505. let __tmp__X;
  30506. let __tmp__Y;
  30507. let __tmp__Z;
  30508. __tmp__X = invI100 * j.ang1X + invI101 * j.ang1Y + invI102 * j.ang1Z;
  30509. __tmp__Y = invI110 * j.ang1X + invI111 * j.ang1Y + invI112 * j.ang1Z;
  30510. __tmp__Z = invI120 * j.ang1X + invI121 * j.ang1Y + invI122 * j.ang1Z;
  30511. md.invMAngN1X = __tmp__X;
  30512. md.invMAngN1Y = __tmp__Y;
  30513. md.invMAngN1Z = __tmp__Z;
  30514. let __tmp__X1;
  30515. let __tmp__Y1;
  30516. let __tmp__Z1;
  30517. __tmp__X1 = invI200 * j.ang2X + invI201 * j.ang2Y + invI202 * j.ang2Z;
  30518. __tmp__Y1 = invI210 * j.ang2X + invI211 * j.ang2Y + invI212 * j.ang2Z;
  30519. __tmp__Z1 = invI220 * j.ang2X + invI221 * j.ang2Y + invI222 * j.ang2Z;
  30520. md.invMAngN2X = __tmp__X1;
  30521. md.invMAngN2Y = __tmp__Y1;
  30522. md.invMAngN2Z = __tmp__Z1;
  30523. md.massN = invM1 + invM2 + (md.invMAngN1X * j.ang1X + md.invMAngN1Y * j.ang1Y + md.invMAngN1Z * j.ang1Z) + (md.invMAngN2X * j.ang2X + md.invMAngN2Y * j.ang2Y + md.invMAngN2Z * j.ang2Z);
  30524. if(md.massN != 0) {
  30525. md.massN = 1 / md.massN;
  30526. }
  30527. let jt = row.jacobianT;
  30528. let jb = row.jacobianB;
  30529. md.invMLinT1X = jt.lin1X * invM1;
  30530. md.invMLinT1Y = jt.lin1Y * invM1;
  30531. md.invMLinT1Z = jt.lin1Z * invM1;
  30532. md.invMLinT2X = jt.lin2X * invM2;
  30533. md.invMLinT2Y = jt.lin2Y * invM2;
  30534. md.invMLinT2Z = jt.lin2Z * invM2;
  30535. md.invMLinB1X = jb.lin1X * invM1;
  30536. md.invMLinB1Y = jb.lin1Y * invM1;
  30537. md.invMLinB1Z = jb.lin1Z * invM1;
  30538. md.invMLinB2X = jb.lin2X * invM2;
  30539. md.invMLinB2Y = jb.lin2Y * invM2;
  30540. md.invMLinB2Z = jb.lin2Z * invM2;
  30541. let __tmp__X2;
  30542. let __tmp__Y2;
  30543. let __tmp__Z2;
  30544. __tmp__X2 = invI100 * jt.ang1X + invI101 * jt.ang1Y + invI102 * jt.ang1Z;
  30545. __tmp__Y2 = invI110 * jt.ang1X + invI111 * jt.ang1Y + invI112 * jt.ang1Z;
  30546. __tmp__Z2 = invI120 * jt.ang1X + invI121 * jt.ang1Y + invI122 * jt.ang1Z;
  30547. md.invMAngT1X = __tmp__X2;
  30548. md.invMAngT1Y = __tmp__Y2;
  30549. md.invMAngT1Z = __tmp__Z2;
  30550. let __tmp__X3;
  30551. let __tmp__Y3;
  30552. let __tmp__Z3;
  30553. __tmp__X3 = invI200 * jt.ang2X + invI201 * jt.ang2Y + invI202 * jt.ang2Z;
  30554. __tmp__Y3 = invI210 * jt.ang2X + invI211 * jt.ang2Y + invI212 * jt.ang2Z;
  30555. __tmp__Z3 = invI220 * jt.ang2X + invI221 * jt.ang2Y + invI222 * jt.ang2Z;
  30556. md.invMAngT2X = __tmp__X3;
  30557. md.invMAngT2Y = __tmp__Y3;
  30558. md.invMAngT2Z = __tmp__Z3;
  30559. let __tmp__X4;
  30560. let __tmp__Y4;
  30561. let __tmp__Z4;
  30562. __tmp__X4 = invI100 * jb.ang1X + invI101 * jb.ang1Y + invI102 * jb.ang1Z;
  30563. __tmp__Y4 = invI110 * jb.ang1X + invI111 * jb.ang1Y + invI112 * jb.ang1Z;
  30564. __tmp__Z4 = invI120 * jb.ang1X + invI121 * jb.ang1Y + invI122 * jb.ang1Z;
  30565. md.invMAngB1X = __tmp__X4;
  30566. md.invMAngB1Y = __tmp__Y4;
  30567. md.invMAngB1Z = __tmp__Z4;
  30568. let __tmp__X5;
  30569. let __tmp__Y5;
  30570. let __tmp__Z5;
  30571. __tmp__X5 = invI200 * jb.ang2X + invI201 * jb.ang2Y + invI202 * jb.ang2Z;
  30572. __tmp__Y5 = invI210 * jb.ang2X + invI211 * jb.ang2Y + invI212 * jb.ang2Z;
  30573. __tmp__Z5 = invI220 * jb.ang2X + invI221 * jb.ang2Y + invI222 * jb.ang2Z;
  30574. md.invMAngB2X = __tmp__X5;
  30575. md.invMAngB2Y = __tmp__Y5;
  30576. md.invMAngB2Z = __tmp__Z5;
  30577. let invMassTB00 = invM1 + invM2 + (md.invMAngT1X * jt.ang1X + md.invMAngT1Y * jt.ang1Y + md.invMAngT1Z * jt.ang1Z) + (md.invMAngT2X * jt.ang2X + md.invMAngT2Y * jt.ang2Y + md.invMAngT2Z * jt.ang2Z);
  30578. let invMassTB01 = md.invMAngT1X * jb.ang1X + md.invMAngT1Y * jb.ang1Y + md.invMAngT1Z * jb.ang1Z + (md.invMAngT2X * jb.ang2X + md.invMAngT2Y * jb.ang2Y + md.invMAngT2Z * jb.ang2Z);
  30579. let invMassTB11 = invM1 + invM2 + (md.invMAngB1X * jb.ang1X + md.invMAngB1Y * jb.ang1Y + md.invMAngB1Z * jb.ang1Z) + (md.invMAngB2X * jb.ang2X + md.invMAngB2Y * jb.ang2Y + md.invMAngB2Z * jb.ang2Z);
  30580. let invDet = invMassTB00 * invMassTB11 - invMassTB01 * invMassTB01;
  30581. if(invDet != 0) {
  30582. invDet = 1 / invDet;
  30583. }
  30584. md.massTB00 = invMassTB11 * invDet;
  30585. md.massTB01 = -invMassTB01 * invDet;
  30586. md.massTB10 = -invMassTB01 * invDet;
  30587. md.massTB11 = invMassTB00 * invDet;
  30588. }
  30589. }
  30590. warmStart(timeStep) {
  30591. let lv1X;
  30592. let lv1Y;
  30593. let lv1Z;
  30594. let lv2X;
  30595. let lv2Y;
  30596. let lv2Z;
  30597. let av1X;
  30598. let av1Y;
  30599. let av1Z;
  30600. let av2X;
  30601. let av2Y;
  30602. let av2Z;
  30603. lv1X = this._b1._velX;
  30604. lv1Y = this._b1._velY;
  30605. lv1Z = this._b1._velZ;
  30606. lv2X = this._b2._velX;
  30607. lv2Y = this._b2._velY;
  30608. lv2Z = this._b2._velZ;
  30609. av1X = this._b1._angVelX;
  30610. av1Y = this._b1._angVelY;
  30611. av1Z = this._b1._angVelZ;
  30612. av2X = this._b2._angVelX;
  30613. av2Y = this._b2._angVelY;
  30614. av2Z = this._b2._angVelZ;
  30615. let _g = 0;
  30616. let _g1 = this.info.numRows;
  30617. while(_g < _g1) {
  30618. let i = _g++;
  30619. let row = this.info.rows[i];
  30620. let imp = row.impulse;
  30621. let md = this.massData[i];
  30622. let jt = row.jacobianT;
  30623. let jb = row.jacobianB;
  30624. let impulseN = imp.impulseN;
  30625. let impulseT = imp.impulseLX * jt.lin1X + imp.impulseLY * jt.lin1Y + imp.impulseLZ * jt.lin1Z;
  30626. let impulseB = imp.impulseLX * jb.lin1X + imp.impulseLY * jb.lin1Y + imp.impulseLZ * jb.lin1Z;
  30627. imp.impulseT = impulseT;
  30628. imp.impulseB = impulseB;
  30629. imp.impulseN *= timeStep.dtRatio;
  30630. imp.impulseT *= timeStep.dtRatio;
  30631. imp.impulseB *= timeStep.dtRatio;
  30632. lv1X += md.invMLinN1X * impulseN;
  30633. lv1Y += md.invMLinN1Y * impulseN;
  30634. lv1Z += md.invMLinN1Z * impulseN;
  30635. lv1X += md.invMLinT1X * impulseT;
  30636. lv1Y += md.invMLinT1Y * impulseT;
  30637. lv1Z += md.invMLinT1Z * impulseT;
  30638. lv1X += md.invMLinB1X * impulseB;
  30639. lv1Y += md.invMLinB1Y * impulseB;
  30640. lv1Z += md.invMLinB1Z * impulseB;
  30641. lv2X += md.invMLinN2X * -impulseN;
  30642. lv2Y += md.invMLinN2Y * -impulseN;
  30643. lv2Z += md.invMLinN2Z * -impulseN;
  30644. lv2X += md.invMLinT2X * -impulseT;
  30645. lv2Y += md.invMLinT2Y * -impulseT;
  30646. lv2Z += md.invMLinT2Z * -impulseT;
  30647. lv2X += md.invMLinB2X * -impulseB;
  30648. lv2Y += md.invMLinB2Y * -impulseB;
  30649. lv2Z += md.invMLinB2Z * -impulseB;
  30650. av1X += md.invMAngN1X * impulseN;
  30651. av1Y += md.invMAngN1Y * impulseN;
  30652. av1Z += md.invMAngN1Z * impulseN;
  30653. av1X += md.invMAngT1X * impulseT;
  30654. av1Y += md.invMAngT1Y * impulseT;
  30655. av1Z += md.invMAngT1Z * impulseT;
  30656. av1X += md.invMAngB1X * impulseB;
  30657. av1Y += md.invMAngB1Y * impulseB;
  30658. av1Z += md.invMAngB1Z * impulseB;
  30659. av2X += md.invMAngN2X * -impulseN;
  30660. av2Y += md.invMAngN2Y * -impulseN;
  30661. av2Z += md.invMAngN2Z * -impulseN;
  30662. av2X += md.invMAngT2X * -impulseT;
  30663. av2Y += md.invMAngT2Y * -impulseT;
  30664. av2Z += md.invMAngT2Z * -impulseT;
  30665. av2X += md.invMAngB2X * -impulseB;
  30666. av2Y += md.invMAngB2Y * -impulseB;
  30667. av2Z += md.invMAngB2Z * -impulseB;
  30668. }
  30669. this._b1._velX = lv1X;
  30670. this._b1._velY = lv1Y;
  30671. this._b1._velZ = lv1Z;
  30672. this._b2._velX = lv2X;
  30673. this._b2._velY = lv2Y;
  30674. this._b2._velZ = lv2Z;
  30675. this._b1._angVelX = av1X;
  30676. this._b1._angVelY = av1Y;
  30677. this._b1._angVelZ = av1Z;
  30678. this._b2._angVelX = av2X;
  30679. this._b2._angVelY = av2Y;
  30680. this._b2._angVelZ = av2Z;
  30681. }
  30682. solveVelocity() {
  30683. let lv1X;
  30684. let lv1Y;
  30685. let lv1Z;
  30686. let lv2X;
  30687. let lv2Y;
  30688. let lv2Z;
  30689. let av1X;
  30690. let av1Y;
  30691. let av1Z;
  30692. let av2X;
  30693. let av2Y;
  30694. let av2Z;
  30695. lv1X = this._b1._velX;
  30696. lv1Y = this._b1._velY;
  30697. lv1Z = this._b1._velZ;
  30698. lv2X = this._b2._velX;
  30699. lv2Y = this._b2._velY;
  30700. lv2Z = this._b2._velZ;
  30701. av1X = this._b1._angVelX;
  30702. av1Y = this._b1._angVelY;
  30703. av1Z = this._b1._angVelZ;
  30704. av2X = this._b2._angVelX;
  30705. av2Y = this._b2._angVelY;
  30706. av2Z = this._b2._angVelZ;
  30707. let _g = 0;
  30708. let _g1 = this.info.numRows;
  30709. while(_g < _g1) {
  30710. let i = _g++;
  30711. let row = this.info.rows[i];
  30712. let md = this.massData[i];
  30713. let imp = row.impulse;
  30714. let rvt = 0;
  30715. let j = row.jacobianT;
  30716. rvt += lv1X * j.lin1X + lv1Y * j.lin1Y + lv1Z * j.lin1Z;
  30717. rvt -= lv2X * j.lin2X + lv2Y * j.lin2Y + lv2Z * j.lin2Z;
  30718. rvt += av1X * j.ang1X + av1Y * j.ang1Y + av1Z * j.ang1Z;
  30719. rvt -= av2X * j.ang2X + av2Y * j.ang2Y + av2Z * j.ang2Z;
  30720. let rvb = 0;
  30721. j = row.jacobianB;
  30722. rvb += lv1X * j.lin1X + lv1Y * j.lin1Y + lv1Z * j.lin1Z;
  30723. rvb -= lv2X * j.lin2X + lv2Y * j.lin2Y + lv2Z * j.lin2Z;
  30724. rvb += av1X * j.ang1X + av1Y * j.ang1Y + av1Z * j.ang1Z;
  30725. rvb -= av2X * j.ang2X + av2Y * j.ang2Y + av2Z * j.ang2Z;
  30726. let impulseT = -(rvt * md.massTB00 + rvb * md.massTB01);
  30727. let impulseB = -(rvt * md.massTB10 + rvb * md.massTB11);
  30728. let oldImpulseT = imp.impulseT;
  30729. let oldImpulseB = imp.impulseB;
  30730. imp.impulseT += impulseT;
  30731. imp.impulseB += impulseB;
  30732. let maxImpulse = row.friction * imp.impulseN;
  30733. if(maxImpulse == 0) {
  30734. imp.impulseT = 0;
  30735. imp.impulseB = 0;
  30736. } else {
  30737. let impulseLengthSq = imp.impulseT * imp.impulseT + imp.impulseB * imp.impulseB;
  30738. if(impulseLengthSq > maxImpulse * maxImpulse) {
  30739. let invL = maxImpulse / Math.sqrt(impulseLengthSq);
  30740. imp.impulseT *= invL;
  30741. imp.impulseB *= invL;
  30742. }
  30743. }
  30744. impulseT = imp.impulseT - oldImpulseT;
  30745. impulseB = imp.impulseB - oldImpulseB;
  30746. lv1X += md.invMLinT1X * impulseT;
  30747. lv1Y += md.invMLinT1Y * impulseT;
  30748. lv1Z += md.invMLinT1Z * impulseT;
  30749. lv1X += md.invMLinB1X * impulseB;
  30750. lv1Y += md.invMLinB1Y * impulseB;
  30751. lv1Z += md.invMLinB1Z * impulseB;
  30752. lv2X += md.invMLinT2X * -impulseT;
  30753. lv2Y += md.invMLinT2Y * -impulseT;
  30754. lv2Z += md.invMLinT2Z * -impulseT;
  30755. lv2X += md.invMLinB2X * -impulseB;
  30756. lv2Y += md.invMLinB2Y * -impulseB;
  30757. lv2Z += md.invMLinB2Z * -impulseB;
  30758. av1X += md.invMAngT1X * impulseT;
  30759. av1Y += md.invMAngT1Y * impulseT;
  30760. av1Z += md.invMAngT1Z * impulseT;
  30761. av1X += md.invMAngB1X * impulseB;
  30762. av1Y += md.invMAngB1Y * impulseB;
  30763. av1Z += md.invMAngB1Z * impulseB;
  30764. av2X += md.invMAngT2X * -impulseT;
  30765. av2Y += md.invMAngT2Y * -impulseT;
  30766. av2Z += md.invMAngT2Z * -impulseT;
  30767. av2X += md.invMAngB2X * -impulseB;
  30768. av2Y += md.invMAngB2Y * -impulseB;
  30769. av2Z += md.invMAngB2Z * -impulseB;
  30770. }
  30771. let _g2 = 0;
  30772. let _g3 = this.info.numRows;
  30773. while(_g2 < _g3) {
  30774. let i = _g2++;
  30775. let row = this.info.rows[i];
  30776. let md = this.massData[i];
  30777. let imp = row.impulse;
  30778. let rvn = 0;
  30779. let j = row.jacobianN;
  30780. rvn += lv1X * j.lin1X + lv1Y * j.lin1Y + lv1Z * j.lin1Z;
  30781. rvn -= lv2X * j.lin2X + lv2Y * j.lin2Y + lv2Z * j.lin2Z;
  30782. rvn += av1X * j.ang1X + av1Y * j.ang1Y + av1Z * j.ang1Z;
  30783. rvn -= av2X * j.ang2X + av2Y * j.ang2Y + av2Z * j.ang2Z;
  30784. let impulseN = (row.rhs - rvn) * md.massN;
  30785. let oldImpulseN = imp.impulseN;
  30786. imp.impulseN += impulseN;
  30787. if(imp.impulseN < 0) {
  30788. imp.impulseN = 0;
  30789. }
  30790. impulseN = imp.impulseN - oldImpulseN;
  30791. lv1X += md.invMLinN1X * impulseN;
  30792. lv1Y += md.invMLinN1Y * impulseN;
  30793. lv1Z += md.invMLinN1Z * impulseN;
  30794. lv2X += md.invMLinN2X * -impulseN;
  30795. lv2Y += md.invMLinN2Y * -impulseN;
  30796. lv2Z += md.invMLinN2Z * -impulseN;
  30797. av1X += md.invMAngN1X * impulseN;
  30798. av1Y += md.invMAngN1Y * impulseN;
  30799. av1Z += md.invMAngN1Z * impulseN;
  30800. av2X += md.invMAngN2X * -impulseN;
  30801. av2Y += md.invMAngN2Y * -impulseN;
  30802. av2Z += md.invMAngN2Z * -impulseN;
  30803. }
  30804. this._b1._velX = lv1X;
  30805. this._b1._velY = lv1Y;
  30806. this._b1._velZ = lv1Z;
  30807. this._b2._velX = lv2X;
  30808. this._b2._velY = lv2Y;
  30809. this._b2._velZ = lv2Z;
  30810. this._b1._angVelX = av1X;
  30811. this._b1._angVelY = av1Y;
  30812. this._b1._angVelZ = av1Z;
  30813. this._b2._angVelX = av2X;
  30814. this._b2._angVelY = av2Y;
  30815. this._b2._angVelZ = av2Z;
  30816. }
  30817. preSolvePosition(timeStep) {
  30818. this.constraint._syncManifold();
  30819. this.constraint._getPositionSolverInfo(this.info);
  30820. let invM1 = this._b1._invMass;
  30821. let invM2 = this._b2._invMass;
  30822. let invI100;
  30823. let invI101;
  30824. let invI102;
  30825. let invI110;
  30826. let invI111;
  30827. let invI112;
  30828. let invI120;
  30829. let invI121;
  30830. let invI122;
  30831. let invI200;
  30832. let invI201;
  30833. let invI202;
  30834. let invI210;
  30835. let invI211;
  30836. let invI212;
  30837. let invI220;
  30838. let invI221;
  30839. let invI222;
  30840. invI100 = this._b1._invInertia00;
  30841. invI101 = this._b1._invInertia01;
  30842. invI102 = this._b1._invInertia02;
  30843. invI110 = this._b1._invInertia10;
  30844. invI111 = this._b1._invInertia11;
  30845. invI112 = this._b1._invInertia12;
  30846. invI120 = this._b1._invInertia20;
  30847. invI121 = this._b1._invInertia21;
  30848. invI122 = this._b1._invInertia22;
  30849. invI200 = this._b2._invInertia00;
  30850. invI201 = this._b2._invInertia01;
  30851. invI202 = this._b2._invInertia02;
  30852. invI210 = this._b2._invInertia10;
  30853. invI211 = this._b2._invInertia11;
  30854. invI212 = this._b2._invInertia12;
  30855. invI220 = this._b2._invInertia20;
  30856. invI221 = this._b2._invInertia21;
  30857. invI222 = this._b2._invInertia22;
  30858. let _g = 0;
  30859. let _g1 = this.info.numRows;
  30860. while(_g < _g1) {
  30861. let i = _g++;
  30862. let md = this.massData[i];
  30863. let j = this.info.rows[i].jacobianN;
  30864. md.invMLinN1X = j.lin1X * invM1;
  30865. md.invMLinN1Y = j.lin1Y * invM1;
  30866. md.invMLinN1Z = j.lin1Z * invM1;
  30867. md.invMLinN2X = j.lin2X * invM2;
  30868. md.invMLinN2Y = j.lin2Y * invM2;
  30869. md.invMLinN2Z = j.lin2Z * invM2;
  30870. let __tmp__X;
  30871. let __tmp__Y;
  30872. let __tmp__Z;
  30873. __tmp__X = invI100 * j.ang1X + invI101 * j.ang1Y + invI102 * j.ang1Z;
  30874. __tmp__Y = invI110 * j.ang1X + invI111 * j.ang1Y + invI112 * j.ang1Z;
  30875. __tmp__Z = invI120 * j.ang1X + invI121 * j.ang1Y + invI122 * j.ang1Z;
  30876. md.invMAngN1X = __tmp__X;
  30877. md.invMAngN1Y = __tmp__Y;
  30878. md.invMAngN1Z = __tmp__Z;
  30879. let __tmp__X1;
  30880. let __tmp__Y1;
  30881. let __tmp__Z1;
  30882. __tmp__X1 = invI200 * j.ang2X + invI201 * j.ang2Y + invI202 * j.ang2Z;
  30883. __tmp__Y1 = invI210 * j.ang2X + invI211 * j.ang2Y + invI212 * j.ang2Z;
  30884. __tmp__Z1 = invI220 * j.ang2X + invI221 * j.ang2Y + invI222 * j.ang2Z;
  30885. md.invMAngN2X = __tmp__X1;
  30886. md.invMAngN2Y = __tmp__Y1;
  30887. md.invMAngN2Z = __tmp__Z1;
  30888. md.massN = invM1 + invM2 + (md.invMAngN1X * j.ang1X + md.invMAngN1Y * j.ang1Y + md.invMAngN1Z * j.ang1Z) + (md.invMAngN2X * j.ang2X + md.invMAngN2Y * j.ang2Y + md.invMAngN2Z * j.ang2Z);
  30889. if(md.massN != 0) {
  30890. md.massN = 1 / md.massN;
  30891. }
  30892. }
  30893. let _g2 = 0;
  30894. let _g3 = this.info.numRows;
  30895. while(_g2 < _g3) this.info.rows[_g2++].impulse.impulseP = 0;
  30896. }
  30897. solvePositionSplitImpulse() {
  30898. let lv1X;
  30899. let lv1Y;
  30900. let lv1Z;
  30901. let lv2X;
  30902. let lv2Y;
  30903. let lv2Z;
  30904. let av1X;
  30905. let av1Y;
  30906. let av1Z;
  30907. let av2X;
  30908. let av2Y;
  30909. let av2Z;
  30910. lv1X = this._b1._pseudoVelX;
  30911. lv1Y = this._b1._pseudoVelY;
  30912. lv1Z = this._b1._pseudoVelZ;
  30913. lv2X = this._b2._pseudoVelX;
  30914. lv2Y = this._b2._pseudoVelY;
  30915. lv2Z = this._b2._pseudoVelZ;
  30916. av1X = this._b1._angPseudoVelX;
  30917. av1Y = this._b1._angPseudoVelY;
  30918. av1Z = this._b1._angPseudoVelZ;
  30919. av2X = this._b2._angPseudoVelX;
  30920. av2Y = this._b2._angPseudoVelY;
  30921. av2Z = this._b2._angPseudoVelZ;
  30922. let _g = 0;
  30923. let _g1 = this.info.numRows;
  30924. while(_g < _g1) {
  30925. let i = _g++;
  30926. let row = this.info.rows[i];
  30927. let md = this.massData[i];
  30928. let imp = row.impulse;
  30929. let j = row.jacobianN;
  30930. let rvn = 0;
  30931. rvn += lv1X * j.lin1X + lv1Y * j.lin1Y + lv1Z * j.lin1Z;
  30932. rvn -= lv2X * j.lin2X + lv2Y * j.lin2Y + lv2Z * j.lin2Z;
  30933. rvn += av1X * j.ang1X + av1Y * j.ang1Y + av1Z * j.ang1Z;
  30934. rvn -= av2X * j.ang2X + av2Y * j.ang2Y + av2Z * j.ang2Z;
  30935. let impulseP = (row.rhs - rvn) * md.massN * oimo.common.Setting.positionSplitImpulseBaumgarte;
  30936. let oldImpulseP = imp.impulseP;
  30937. imp.impulseP += impulseP;
  30938. if(imp.impulseP < 0) {
  30939. imp.impulseP = 0;
  30940. }
  30941. impulseP = imp.impulseP - oldImpulseP;
  30942. lv1X += md.invMLinN1X * impulseP;
  30943. lv1Y += md.invMLinN1Y * impulseP;
  30944. lv1Z += md.invMLinN1Z * impulseP;
  30945. lv2X += md.invMLinN2X * -impulseP;
  30946. lv2Y += md.invMLinN2Y * -impulseP;
  30947. lv2Z += md.invMLinN2Z * -impulseP;
  30948. av1X += md.invMAngN1X * impulseP;
  30949. av1Y += md.invMAngN1Y * impulseP;
  30950. av1Z += md.invMAngN1Z * impulseP;
  30951. av2X += md.invMAngN2X * -impulseP;
  30952. av2Y += md.invMAngN2Y * -impulseP;
  30953. av2Z += md.invMAngN2Z * -impulseP;
  30954. }
  30955. this._b1._pseudoVelX = lv1X;
  30956. this._b1._pseudoVelY = lv1Y;
  30957. this._b1._pseudoVelZ = lv1Z;
  30958. this._b2._pseudoVelX = lv2X;
  30959. this._b2._pseudoVelY = lv2Y;
  30960. this._b2._pseudoVelZ = lv2Z;
  30961. this._b1._angPseudoVelX = av1X;
  30962. this._b1._angPseudoVelY = av1Y;
  30963. this._b1._angPseudoVelZ = av1Z;
  30964. this._b2._angPseudoVelX = av2X;
  30965. this._b2._angPseudoVelY = av2Y;
  30966. this._b2._angPseudoVelZ = av2Z;
  30967. }
  30968. solvePositionNgs(timeStep) {
  30969. this.constraint._syncManifold();
  30970. this.constraint._getPositionSolverInfo(this.info);
  30971. let invM1 = this._b1._invMass;
  30972. let invM2 = this._b2._invMass;
  30973. let invI100;
  30974. let invI101;
  30975. let invI102;
  30976. let invI110;
  30977. let invI111;
  30978. let invI112;
  30979. let invI120;
  30980. let invI121;
  30981. let invI122;
  30982. let invI200;
  30983. let invI201;
  30984. let invI202;
  30985. let invI210;
  30986. let invI211;
  30987. let invI212;
  30988. let invI220;
  30989. let invI221;
  30990. let invI222;
  30991. invI100 = this._b1._invInertia00;
  30992. invI101 = this._b1._invInertia01;
  30993. invI102 = this._b1._invInertia02;
  30994. invI110 = this._b1._invInertia10;
  30995. invI111 = this._b1._invInertia11;
  30996. invI112 = this._b1._invInertia12;
  30997. invI120 = this._b1._invInertia20;
  30998. invI121 = this._b1._invInertia21;
  30999. invI122 = this._b1._invInertia22;
  31000. invI200 = this._b2._invInertia00;
  31001. invI201 = this._b2._invInertia01;
  31002. invI202 = this._b2._invInertia02;
  31003. invI210 = this._b2._invInertia10;
  31004. invI211 = this._b2._invInertia11;
  31005. invI212 = this._b2._invInertia12;
  31006. invI220 = this._b2._invInertia20;
  31007. invI221 = this._b2._invInertia21;
  31008. invI222 = this._b2._invInertia22;
  31009. let _g = 0;
  31010. let _g1 = this.info.numRows;
  31011. while(_g < _g1) {
  31012. let i = _g++;
  31013. let md = this.massData[i];
  31014. let j = this.info.rows[i].jacobianN;
  31015. md.invMLinN1X = j.lin1X * invM1;
  31016. md.invMLinN1Y = j.lin1Y * invM1;
  31017. md.invMLinN1Z = j.lin1Z * invM1;
  31018. md.invMLinN2X = j.lin2X * invM2;
  31019. md.invMLinN2Y = j.lin2Y * invM2;
  31020. md.invMLinN2Z = j.lin2Z * invM2;
  31021. let __tmp__X;
  31022. let __tmp__Y;
  31023. let __tmp__Z;
  31024. __tmp__X = invI100 * j.ang1X + invI101 * j.ang1Y + invI102 * j.ang1Z;
  31025. __tmp__Y = invI110 * j.ang1X + invI111 * j.ang1Y + invI112 * j.ang1Z;
  31026. __tmp__Z = invI120 * j.ang1X + invI121 * j.ang1Y + invI122 * j.ang1Z;
  31027. md.invMAngN1X = __tmp__X;
  31028. md.invMAngN1Y = __tmp__Y;
  31029. md.invMAngN1Z = __tmp__Z;
  31030. let __tmp__X1;
  31031. let __tmp__Y1;
  31032. let __tmp__Z1;
  31033. __tmp__X1 = invI200 * j.ang2X + invI201 * j.ang2Y + invI202 * j.ang2Z;
  31034. __tmp__Y1 = invI210 * j.ang2X + invI211 * j.ang2Y + invI212 * j.ang2Z;
  31035. __tmp__Z1 = invI220 * j.ang2X + invI221 * j.ang2Y + invI222 * j.ang2Z;
  31036. md.invMAngN2X = __tmp__X1;
  31037. md.invMAngN2Y = __tmp__Y1;
  31038. md.invMAngN2Z = __tmp__Z1;
  31039. md.massN = invM1 + invM2 + (md.invMAngN1X * j.ang1X + md.invMAngN1Y * j.ang1Y + md.invMAngN1Z * j.ang1Z) + (md.invMAngN2X * j.ang2X + md.invMAngN2Y * j.ang2Y + md.invMAngN2Z * j.ang2Z);
  31040. if(md.massN != 0) {
  31041. md.massN = 1 / md.massN;
  31042. }
  31043. }
  31044. let lv1X;
  31045. let lv1Y;
  31046. let lv1Z;
  31047. let lv2X;
  31048. let lv2Y;
  31049. let lv2Z;
  31050. let av1X;
  31051. let av1Y;
  31052. let av1Z;
  31053. let av2X;
  31054. let av2Y;
  31055. let av2Z;
  31056. lv1X = 0;
  31057. lv1Y = 0;
  31058. lv1Z = 0;
  31059. lv2X = 0;
  31060. lv2Y = 0;
  31061. lv2Z = 0;
  31062. av1X = 0;
  31063. av1Y = 0;
  31064. av1Z = 0;
  31065. av2X = 0;
  31066. av2Y = 0;
  31067. av2Z = 0;
  31068. let _g2 = 0;
  31069. let _g3 = this.info.numRows;
  31070. while(_g2 < _g3) {
  31071. let i = _g2++;
  31072. let row = this.info.rows[i];
  31073. let md = this.massData[i];
  31074. let imp = row.impulse;
  31075. let j = row.jacobianN;
  31076. let rvn = 0;
  31077. rvn += lv1X * j.lin1X + lv1Y * j.lin1Y + lv1Z * j.lin1Z;
  31078. rvn -= lv2X * j.lin2X + lv2Y * j.lin2Y + lv2Z * j.lin2Z;
  31079. rvn += av1X * j.ang1X + av1Y * j.ang1Y + av1Z * j.ang1Z;
  31080. rvn -= av2X * j.ang2X + av2Y * j.ang2Y + av2Z * j.ang2Z;
  31081. let impulseP = (row.rhs - rvn) * md.massN * oimo.common.Setting.positionNgsBaumgarte;
  31082. let oldImpulseP = imp.impulseP;
  31083. imp.impulseP += impulseP;
  31084. if(imp.impulseP < 0) {
  31085. imp.impulseP = 0;
  31086. }
  31087. impulseP = imp.impulseP - oldImpulseP;
  31088. lv1X += md.invMLinN1X * impulseP;
  31089. lv1Y += md.invMLinN1Y * impulseP;
  31090. lv1Z += md.invMLinN1Z * impulseP;
  31091. lv2X += md.invMLinN2X * -impulseP;
  31092. lv2Y += md.invMLinN2Y * -impulseP;
  31093. lv2Z += md.invMLinN2Z * -impulseP;
  31094. av1X += md.invMAngN1X * impulseP;
  31095. av1Y += md.invMAngN1Y * impulseP;
  31096. av1Z += md.invMAngN1Z * impulseP;
  31097. av2X += md.invMAngN2X * -impulseP;
  31098. av2Y += md.invMAngN2Y * -impulseP;
  31099. av2Z += md.invMAngN2Z * -impulseP;
  31100. }
  31101. let _this = this._b1;
  31102. _this._transform._positionX += lv1X;
  31103. _this._transform._positionY += lv1Y;
  31104. _this._transform._positionZ += lv1Z;
  31105. let _this1 = this._b2;
  31106. _this1._transform._positionX += lv2X;
  31107. _this1._transform._positionY += lv2Y;
  31108. _this1._transform._positionZ += lv2Z;
  31109. let _this2 = this._b1;
  31110. let theta = Math.sqrt(av1X * av1X + av1Y * av1Y + av1Z * av1Z);
  31111. let halfTheta = theta * 0.5;
  31112. let rotationToSinAxisFactor;
  31113. let cosHalfTheta;
  31114. if(halfTheta < 0.5) {
  31115. let ht2 = halfTheta * halfTheta;
  31116. rotationToSinAxisFactor = 0.5 * (1 - ht2 * 0.16666666666666666 + ht2 * ht2 * 0.0083333333333333332);
  31117. cosHalfTheta = 1 - ht2 * 0.5 + ht2 * ht2 * 0.041666666666666664;
  31118. } else {
  31119. rotationToSinAxisFactor = Math.sin(halfTheta) / theta;
  31120. cosHalfTheta = Math.cos(halfTheta);
  31121. }
  31122. let sinAxisX;
  31123. let sinAxisY;
  31124. let sinAxisZ;
  31125. sinAxisX = av1X * rotationToSinAxisFactor;
  31126. sinAxisY = av1Y * rotationToSinAxisFactor;
  31127. sinAxisZ = av1Z * rotationToSinAxisFactor;
  31128. let dqX;
  31129. let dqY;
  31130. let dqZ;
  31131. let dqW;
  31132. dqX = sinAxisX;
  31133. dqY = sinAxisY;
  31134. dqZ = sinAxisZ;
  31135. dqW = cosHalfTheta;
  31136. let qX;
  31137. let qY;
  31138. let qZ;
  31139. let qW;
  31140. let e00 = _this2._transform._rotation00;
  31141. let e11 = _this2._transform._rotation11;
  31142. let e22 = _this2._transform._rotation22;
  31143. let t = e00 + e11 + e22;
  31144. let s;
  31145. if(t > 0) {
  31146. s = Math.sqrt(t + 1);
  31147. qW = 0.5 * s;
  31148. s = 0.5 / s;
  31149. qX = (_this2._transform._rotation21 - _this2._transform._rotation12) * s;
  31150. qY = (_this2._transform._rotation02 - _this2._transform._rotation20) * s;
  31151. qZ = (_this2._transform._rotation10 - _this2._transform._rotation01) * s;
  31152. } else if(e00 > e11) {
  31153. if(e00 > e22) {
  31154. s = Math.sqrt(e00 - e11 - e22 + 1);
  31155. qX = 0.5 * s;
  31156. s = 0.5 / s;
  31157. qY = (_this2._transform._rotation01 + _this2._transform._rotation10) * s;
  31158. qZ = (_this2._transform._rotation02 + _this2._transform._rotation20) * s;
  31159. qW = (_this2._transform._rotation21 - _this2._transform._rotation12) * s;
  31160. } else {
  31161. s = Math.sqrt(e22 - e00 - e11 + 1);
  31162. qZ = 0.5 * s;
  31163. s = 0.5 / s;
  31164. qX = (_this2._transform._rotation02 + _this2._transform._rotation20) * s;
  31165. qY = (_this2._transform._rotation12 + _this2._transform._rotation21) * s;
  31166. qW = (_this2._transform._rotation10 - _this2._transform._rotation01) * s;
  31167. }
  31168. } else if(e11 > e22) {
  31169. s = Math.sqrt(e11 - e22 - e00 + 1);
  31170. qY = 0.5 * s;
  31171. s = 0.5 / s;
  31172. qX = (_this2._transform._rotation01 + _this2._transform._rotation10) * s;
  31173. qZ = (_this2._transform._rotation12 + _this2._transform._rotation21) * s;
  31174. qW = (_this2._transform._rotation02 - _this2._transform._rotation20) * s;
  31175. } else {
  31176. s = Math.sqrt(e22 - e00 - e11 + 1);
  31177. qZ = 0.5 * s;
  31178. s = 0.5 / s;
  31179. qX = (_this2._transform._rotation02 + _this2._transform._rotation20) * s;
  31180. qY = (_this2._transform._rotation12 + _this2._transform._rotation21) * s;
  31181. qW = (_this2._transform._rotation10 - _this2._transform._rotation01) * s;
  31182. }
  31183. qX = dqW * qX + dqX * qW + dqY * qZ - dqZ * qY;
  31184. qY = dqW * qY - dqX * qZ + dqY * qW + dqZ * qX;
  31185. qZ = dqW * qZ + dqX * qY - dqY * qX + dqZ * qW;
  31186. qW = dqW * qW - dqX * qX - dqY * qY - dqZ * qZ;
  31187. let l = qX * qX + qY * qY + qZ * qZ + qW * qW;
  31188. if(l > 1e-32) {
  31189. l = 1 / Math.sqrt(l);
  31190. }
  31191. qX *= l;
  31192. qY *= l;
  31193. qZ *= l;
  31194. qW *= l;
  31195. let x = qX;
  31196. let y = qY;
  31197. let z = qZ;
  31198. let w = qW;
  31199. let x2 = 2 * x;
  31200. let y2 = 2 * y;
  31201. let z2 = 2 * z;
  31202. let xx = x * x2;
  31203. let yy = y * y2;
  31204. let zz = z * z2;
  31205. let xy = x * y2;
  31206. let yz = y * z2;
  31207. let xz = x * z2;
  31208. let wx = w * x2;
  31209. let wy = w * y2;
  31210. let wz = w * z2;
  31211. _this2._transform._rotation00 = 1 - yy - zz;
  31212. _this2._transform._rotation01 = xy - wz;
  31213. _this2._transform._rotation02 = xz + wy;
  31214. _this2._transform._rotation10 = xy + wz;
  31215. _this2._transform._rotation11 = 1 - xx - zz;
  31216. _this2._transform._rotation12 = yz - wx;
  31217. _this2._transform._rotation20 = xz - wy;
  31218. _this2._transform._rotation21 = yz + wx;
  31219. _this2._transform._rotation22 = 1 - xx - yy;
  31220. let __tmp__00;
  31221. let __tmp__01;
  31222. let __tmp__02;
  31223. let __tmp__10;
  31224. let __tmp__11;
  31225. let __tmp__12;
  31226. let __tmp__20;
  31227. let __tmp__21;
  31228. let __tmp__22;
  31229. __tmp__00 = _this2._transform._rotation00 * _this2._invLocalInertia00 + _this2._transform._rotation01 * _this2._invLocalInertia10 + _this2._transform._rotation02 * _this2._invLocalInertia20;
  31230. __tmp__01 = _this2._transform._rotation00 * _this2._invLocalInertia01 + _this2._transform._rotation01 * _this2._invLocalInertia11 + _this2._transform._rotation02 * _this2._invLocalInertia21;
  31231. __tmp__02 = _this2._transform._rotation00 * _this2._invLocalInertia02 + _this2._transform._rotation01 * _this2._invLocalInertia12 + _this2._transform._rotation02 * _this2._invLocalInertia22;
  31232. __tmp__10 = _this2._transform._rotation10 * _this2._invLocalInertia00 + _this2._transform._rotation11 * _this2._invLocalInertia10 + _this2._transform._rotation12 * _this2._invLocalInertia20;
  31233. __tmp__11 = _this2._transform._rotation10 * _this2._invLocalInertia01 + _this2._transform._rotation11 * _this2._invLocalInertia11 + _this2._transform._rotation12 * _this2._invLocalInertia21;
  31234. __tmp__12 = _this2._transform._rotation10 * _this2._invLocalInertia02 + _this2._transform._rotation11 * _this2._invLocalInertia12 + _this2._transform._rotation12 * _this2._invLocalInertia22;
  31235. __tmp__20 = _this2._transform._rotation20 * _this2._invLocalInertia00 + _this2._transform._rotation21 * _this2._invLocalInertia10 + _this2._transform._rotation22 * _this2._invLocalInertia20;
  31236. __tmp__21 = _this2._transform._rotation20 * _this2._invLocalInertia01 + _this2._transform._rotation21 * _this2._invLocalInertia11 + _this2._transform._rotation22 * _this2._invLocalInertia21;
  31237. __tmp__22 = _this2._transform._rotation20 * _this2._invLocalInertia02 + _this2._transform._rotation21 * _this2._invLocalInertia12 + _this2._transform._rotation22 * _this2._invLocalInertia22;
  31238. _this2._invInertia00 = __tmp__00;
  31239. _this2._invInertia01 = __tmp__01;
  31240. _this2._invInertia02 = __tmp__02;
  31241. _this2._invInertia10 = __tmp__10;
  31242. _this2._invInertia11 = __tmp__11;
  31243. _this2._invInertia12 = __tmp__12;
  31244. _this2._invInertia20 = __tmp__20;
  31245. _this2._invInertia21 = __tmp__21;
  31246. _this2._invInertia22 = __tmp__22;
  31247. let __tmp__001;
  31248. let __tmp__011;
  31249. let __tmp__021;
  31250. let __tmp__101;
  31251. let __tmp__111;
  31252. let __tmp__121;
  31253. let __tmp__201;
  31254. let __tmp__211;
  31255. let __tmp__221;
  31256. __tmp__001 = _this2._invInertia00 * _this2._transform._rotation00 + _this2._invInertia01 * _this2._transform._rotation01 + _this2._invInertia02 * _this2._transform._rotation02;
  31257. __tmp__011 = _this2._invInertia00 * _this2._transform._rotation10 + _this2._invInertia01 * _this2._transform._rotation11 + _this2._invInertia02 * _this2._transform._rotation12;
  31258. __tmp__021 = _this2._invInertia00 * _this2._transform._rotation20 + _this2._invInertia01 * _this2._transform._rotation21 + _this2._invInertia02 * _this2._transform._rotation22;
  31259. __tmp__101 = _this2._invInertia10 * _this2._transform._rotation00 + _this2._invInertia11 * _this2._transform._rotation01 + _this2._invInertia12 * _this2._transform._rotation02;
  31260. __tmp__111 = _this2._invInertia10 * _this2._transform._rotation10 + _this2._invInertia11 * _this2._transform._rotation11 + _this2._invInertia12 * _this2._transform._rotation12;
  31261. __tmp__121 = _this2._invInertia10 * _this2._transform._rotation20 + _this2._invInertia11 * _this2._transform._rotation21 + _this2._invInertia12 * _this2._transform._rotation22;
  31262. __tmp__201 = _this2._invInertia20 * _this2._transform._rotation00 + _this2._invInertia21 * _this2._transform._rotation01 + _this2._invInertia22 * _this2._transform._rotation02;
  31263. __tmp__211 = _this2._invInertia20 * _this2._transform._rotation10 + _this2._invInertia21 * _this2._transform._rotation11 + _this2._invInertia22 * _this2._transform._rotation12;
  31264. __tmp__221 = _this2._invInertia20 * _this2._transform._rotation20 + _this2._invInertia21 * _this2._transform._rotation21 + _this2._invInertia22 * _this2._transform._rotation22;
  31265. _this2._invInertia00 = __tmp__001;
  31266. _this2._invInertia01 = __tmp__011;
  31267. _this2._invInertia02 = __tmp__021;
  31268. _this2._invInertia10 = __tmp__101;
  31269. _this2._invInertia11 = __tmp__111;
  31270. _this2._invInertia12 = __tmp__121;
  31271. _this2._invInertia20 = __tmp__201;
  31272. _this2._invInertia21 = __tmp__211;
  31273. _this2._invInertia22 = __tmp__221;
  31274. _this2._invInertia00 *= _this2._rotFactor.x;
  31275. _this2._invInertia01 *= _this2._rotFactor.x;
  31276. _this2._invInertia02 *= _this2._rotFactor.x;
  31277. _this2._invInertia10 *= _this2._rotFactor.y;
  31278. _this2._invInertia11 *= _this2._rotFactor.y;
  31279. _this2._invInertia12 *= _this2._rotFactor.y;
  31280. _this2._invInertia20 *= _this2._rotFactor.z;
  31281. _this2._invInertia21 *= _this2._rotFactor.z;
  31282. _this2._invInertia22 *= _this2._rotFactor.z;
  31283. let _this3 = this._b2;
  31284. let theta1 = Math.sqrt(av2X * av2X + av2Y * av2Y + av2Z * av2Z);
  31285. let halfTheta1 = theta1 * 0.5;
  31286. let rotationToSinAxisFactor1;
  31287. let cosHalfTheta1;
  31288. if(halfTheta1 < 0.5) {
  31289. let ht2 = halfTheta1 * halfTheta1;
  31290. rotationToSinAxisFactor1 = 0.5 * (1 - ht2 * 0.16666666666666666 + ht2 * ht2 * 0.0083333333333333332);
  31291. cosHalfTheta1 = 1 - ht2 * 0.5 + ht2 * ht2 * 0.041666666666666664;
  31292. } else {
  31293. rotationToSinAxisFactor1 = Math.sin(halfTheta1) / theta1;
  31294. cosHalfTheta1 = Math.cos(halfTheta1);
  31295. }
  31296. let sinAxisX1;
  31297. let sinAxisY1;
  31298. let sinAxisZ1;
  31299. sinAxisX1 = av2X * rotationToSinAxisFactor1;
  31300. sinAxisY1 = av2Y * rotationToSinAxisFactor1;
  31301. sinAxisZ1 = av2Z * rotationToSinAxisFactor1;
  31302. let dqX1;
  31303. let dqY1;
  31304. let dqZ1;
  31305. let dqW1;
  31306. dqX1 = sinAxisX1;
  31307. dqY1 = sinAxisY1;
  31308. dqZ1 = sinAxisZ1;
  31309. dqW1 = cosHalfTheta1;
  31310. let qX1;
  31311. let qY1;
  31312. let qZ1;
  31313. let qW1;
  31314. let e001 = _this3._transform._rotation00;
  31315. let e111 = _this3._transform._rotation11;
  31316. let e221 = _this3._transform._rotation22;
  31317. let t1 = e001 + e111 + e221;
  31318. let s1;
  31319. if(t1 > 0) {
  31320. s1 = Math.sqrt(t1 + 1);
  31321. qW1 = 0.5 * s1;
  31322. s1 = 0.5 / s1;
  31323. qX1 = (_this3._transform._rotation21 - _this3._transform._rotation12) * s1;
  31324. qY1 = (_this3._transform._rotation02 - _this3._transform._rotation20) * s1;
  31325. qZ1 = (_this3._transform._rotation10 - _this3._transform._rotation01) * s1;
  31326. } else if(e001 > e111) {
  31327. if(e001 > e221) {
  31328. s1 = Math.sqrt(e001 - e111 - e221 + 1);
  31329. qX1 = 0.5 * s1;
  31330. s1 = 0.5 / s1;
  31331. qY1 = (_this3._transform._rotation01 + _this3._transform._rotation10) * s1;
  31332. qZ1 = (_this3._transform._rotation02 + _this3._transform._rotation20) * s1;
  31333. qW1 = (_this3._transform._rotation21 - _this3._transform._rotation12) * s1;
  31334. } else {
  31335. s1 = Math.sqrt(e221 - e001 - e111 + 1);
  31336. qZ1 = 0.5 * s1;
  31337. s1 = 0.5 / s1;
  31338. qX1 = (_this3._transform._rotation02 + _this3._transform._rotation20) * s1;
  31339. qY1 = (_this3._transform._rotation12 + _this3._transform._rotation21) * s1;
  31340. qW1 = (_this3._transform._rotation10 - _this3._transform._rotation01) * s1;
  31341. }
  31342. } else if(e111 > e221) {
  31343. s1 = Math.sqrt(e111 - e221 - e001 + 1);
  31344. qY1 = 0.5 * s1;
  31345. s1 = 0.5 / s1;
  31346. qX1 = (_this3._transform._rotation01 + _this3._transform._rotation10) * s1;
  31347. qZ1 = (_this3._transform._rotation12 + _this3._transform._rotation21) * s1;
  31348. qW1 = (_this3._transform._rotation02 - _this3._transform._rotation20) * s1;
  31349. } else {
  31350. s1 = Math.sqrt(e221 - e001 - e111 + 1);
  31351. qZ1 = 0.5 * s1;
  31352. s1 = 0.5 / s1;
  31353. qX1 = (_this3._transform._rotation02 + _this3._transform._rotation20) * s1;
  31354. qY1 = (_this3._transform._rotation12 + _this3._transform._rotation21) * s1;
  31355. qW1 = (_this3._transform._rotation10 - _this3._transform._rotation01) * s1;
  31356. }
  31357. qX1 = dqW1 * qX1 + dqX1 * qW1 + dqY1 * qZ1 - dqZ1 * qY1;
  31358. qY1 = dqW1 * qY1 - dqX1 * qZ1 + dqY1 * qW1 + dqZ1 * qX1;
  31359. qZ1 = dqW1 * qZ1 + dqX1 * qY1 - dqY1 * qX1 + dqZ1 * qW1;
  31360. qW1 = dqW1 * qW1 - dqX1 * qX1 - dqY1 * qY1 - dqZ1 * qZ1;
  31361. let l1 = qX1 * qX1 + qY1 * qY1 + qZ1 * qZ1 + qW1 * qW1;
  31362. if(l1 > 1e-32) {
  31363. l1 = 1 / Math.sqrt(l1);
  31364. }
  31365. qX1 *= l1;
  31366. qY1 *= l1;
  31367. qZ1 *= l1;
  31368. qW1 *= l1;
  31369. let x1 = qX1;
  31370. let y1 = qY1;
  31371. let z1 = qZ1;
  31372. let w1 = qW1;
  31373. let x21 = 2 * x1;
  31374. let y21 = 2 * y1;
  31375. let z21 = 2 * z1;
  31376. let xx1 = x1 * x21;
  31377. let yy1 = y1 * y21;
  31378. let zz1 = z1 * z21;
  31379. let xy1 = x1 * y21;
  31380. let yz1 = y1 * z21;
  31381. let xz1 = x1 * z21;
  31382. let wx1 = w1 * x21;
  31383. let wy1 = w1 * y21;
  31384. let wz1 = w1 * z21;
  31385. _this3._transform._rotation00 = 1 - yy1 - zz1;
  31386. _this3._transform._rotation01 = xy1 - wz1;
  31387. _this3._transform._rotation02 = xz1 + wy1;
  31388. _this3._transform._rotation10 = xy1 + wz1;
  31389. _this3._transform._rotation11 = 1 - xx1 - zz1;
  31390. _this3._transform._rotation12 = yz1 - wx1;
  31391. _this3._transform._rotation20 = xz1 - wy1;
  31392. _this3._transform._rotation21 = yz1 + wx1;
  31393. _this3._transform._rotation22 = 1 - xx1 - yy1;
  31394. let __tmp__002;
  31395. let __tmp__012;
  31396. let __tmp__022;
  31397. let __tmp__102;
  31398. let __tmp__112;
  31399. let __tmp__122;
  31400. let __tmp__202;
  31401. let __tmp__212;
  31402. let __tmp__222;
  31403. __tmp__002 = _this3._transform._rotation00 * _this3._invLocalInertia00 + _this3._transform._rotation01 * _this3._invLocalInertia10 + _this3._transform._rotation02 * _this3._invLocalInertia20;
  31404. __tmp__012 = _this3._transform._rotation00 * _this3._invLocalInertia01 + _this3._transform._rotation01 * _this3._invLocalInertia11 + _this3._transform._rotation02 * _this3._invLocalInertia21;
  31405. __tmp__022 = _this3._transform._rotation00 * _this3._invLocalInertia02 + _this3._transform._rotation01 * _this3._invLocalInertia12 + _this3._transform._rotation02 * _this3._invLocalInertia22;
  31406. __tmp__102 = _this3._transform._rotation10 * _this3._invLocalInertia00 + _this3._transform._rotation11 * _this3._invLocalInertia10 + _this3._transform._rotation12 * _this3._invLocalInertia20;
  31407. __tmp__112 = _this3._transform._rotation10 * _this3._invLocalInertia01 + _this3._transform._rotation11 * _this3._invLocalInertia11 + _this3._transform._rotation12 * _this3._invLocalInertia21;
  31408. __tmp__122 = _this3._transform._rotation10 * _this3._invLocalInertia02 + _this3._transform._rotation11 * _this3._invLocalInertia12 + _this3._transform._rotation12 * _this3._invLocalInertia22;
  31409. __tmp__202 = _this3._transform._rotation20 * _this3._invLocalInertia00 + _this3._transform._rotation21 * _this3._invLocalInertia10 + _this3._transform._rotation22 * _this3._invLocalInertia20;
  31410. __tmp__212 = _this3._transform._rotation20 * _this3._invLocalInertia01 + _this3._transform._rotation21 * _this3._invLocalInertia11 + _this3._transform._rotation22 * _this3._invLocalInertia21;
  31411. __tmp__222 = _this3._transform._rotation20 * _this3._invLocalInertia02 + _this3._transform._rotation21 * _this3._invLocalInertia12 + _this3._transform._rotation22 * _this3._invLocalInertia22;
  31412. _this3._invInertia00 = __tmp__002;
  31413. _this3._invInertia01 = __tmp__012;
  31414. _this3._invInertia02 = __tmp__022;
  31415. _this3._invInertia10 = __tmp__102;
  31416. _this3._invInertia11 = __tmp__112;
  31417. _this3._invInertia12 = __tmp__122;
  31418. _this3._invInertia20 = __tmp__202;
  31419. _this3._invInertia21 = __tmp__212;
  31420. _this3._invInertia22 = __tmp__222;
  31421. let __tmp__003;
  31422. let __tmp__013;
  31423. let __tmp__023;
  31424. let __tmp__103;
  31425. let __tmp__113;
  31426. let __tmp__123;
  31427. let __tmp__203;
  31428. let __tmp__213;
  31429. let __tmp__223;
  31430. __tmp__003 = _this3._invInertia00 * _this3._transform._rotation00 + _this3._invInertia01 * _this3._transform._rotation01 + _this3._invInertia02 * _this3._transform._rotation02;
  31431. __tmp__013 = _this3._invInertia00 * _this3._transform._rotation10 + _this3._invInertia01 * _this3._transform._rotation11 + _this3._invInertia02 * _this3._transform._rotation12;
  31432. __tmp__023 = _this3._invInertia00 * _this3._transform._rotation20 + _this3._invInertia01 * _this3._transform._rotation21 + _this3._invInertia02 * _this3._transform._rotation22;
  31433. __tmp__103 = _this3._invInertia10 * _this3._transform._rotation00 + _this3._invInertia11 * _this3._transform._rotation01 + _this3._invInertia12 * _this3._transform._rotation02;
  31434. __tmp__113 = _this3._invInertia10 * _this3._transform._rotation10 + _this3._invInertia11 * _this3._transform._rotation11 + _this3._invInertia12 * _this3._transform._rotation12;
  31435. __tmp__123 = _this3._invInertia10 * _this3._transform._rotation20 + _this3._invInertia11 * _this3._transform._rotation21 + _this3._invInertia12 * _this3._transform._rotation22;
  31436. __tmp__203 = _this3._invInertia20 * _this3._transform._rotation00 + _this3._invInertia21 * _this3._transform._rotation01 + _this3._invInertia22 * _this3._transform._rotation02;
  31437. __tmp__213 = _this3._invInertia20 * _this3._transform._rotation10 + _this3._invInertia21 * _this3._transform._rotation11 + _this3._invInertia22 * _this3._transform._rotation12;
  31438. __tmp__223 = _this3._invInertia20 * _this3._transform._rotation20 + _this3._invInertia21 * _this3._transform._rotation21 + _this3._invInertia22 * _this3._transform._rotation22;
  31439. _this3._invInertia00 = __tmp__003;
  31440. _this3._invInertia01 = __tmp__013;
  31441. _this3._invInertia02 = __tmp__023;
  31442. _this3._invInertia10 = __tmp__103;
  31443. _this3._invInertia11 = __tmp__113;
  31444. _this3._invInertia12 = __tmp__123;
  31445. _this3._invInertia20 = __tmp__203;
  31446. _this3._invInertia21 = __tmp__213;
  31447. _this3._invInertia22 = __tmp__223;
  31448. _this3._invInertia00 *= _this3._rotFactor.x;
  31449. _this3._invInertia01 *= _this3._rotFactor.x;
  31450. _this3._invInertia02 *= _this3._rotFactor.x;
  31451. _this3._invInertia10 *= _this3._rotFactor.y;
  31452. _this3._invInertia11 *= _this3._rotFactor.y;
  31453. _this3._invInertia12 *= _this3._rotFactor.y;
  31454. _this3._invInertia20 *= _this3._rotFactor.z;
  31455. _this3._invInertia21 *= _this3._rotFactor.z;
  31456. _this3._invInertia22 *= _this3._rotFactor.z;
  31457. }
  31458. postSolve() {
  31459. let lin1X;
  31460. let lin1Y;
  31461. let lin1Z;
  31462. let ang1X;
  31463. let ang1Y;
  31464. let ang1Z;
  31465. let ang2X;
  31466. let ang2Y;
  31467. let ang2Z;
  31468. lin1X = 0;
  31469. lin1Y = 0;
  31470. lin1Z = 0;
  31471. ang1X = 0;
  31472. ang1Y = 0;
  31473. ang1Z = 0;
  31474. ang2X = 0;
  31475. ang2Y = 0;
  31476. ang2Z = 0;
  31477. let _g = 0;
  31478. let _g1 = this.info.numRows;
  31479. while(_g < _g1) {
  31480. let row = this.info.rows[_g++];
  31481. let imp = row.impulse;
  31482. let jn = row.jacobianN;
  31483. let jt = row.jacobianT;
  31484. let jb = row.jacobianB;
  31485. let impN = imp.impulseN;
  31486. let impT = imp.impulseT;
  31487. let impB = imp.impulseB;
  31488. let impulseLX;
  31489. let impulseLY;
  31490. let impulseLZ;
  31491. impulseLX = 0;
  31492. impulseLY = 0;
  31493. impulseLZ = 0;
  31494. impulseLX += jt.lin1X * impT;
  31495. impulseLY += jt.lin1Y * impT;
  31496. impulseLZ += jt.lin1Z * impT;
  31497. impulseLX += jb.lin1X * impB;
  31498. impulseLY += jb.lin1Y * impB;
  31499. impulseLZ += jb.lin1Z * impB;
  31500. imp.impulseLX = impulseLX;
  31501. imp.impulseLY = impulseLY;
  31502. imp.impulseLZ = impulseLZ;
  31503. lin1X += jn.lin1X * impN;
  31504. lin1Y += jn.lin1Y * impN;
  31505. lin1Z += jn.lin1Z * impN;
  31506. ang1X += jn.ang1X * impN;
  31507. ang1Y += jn.ang1Y * impN;
  31508. ang1Z += jn.ang1Z * impN;
  31509. ang2X += jn.ang2X * impN;
  31510. ang2Y += jn.ang2Y * impN;
  31511. ang2Z += jn.ang2Z * impN;
  31512. lin1X += jt.lin1X * impT;
  31513. lin1Y += jt.lin1Y * impT;
  31514. lin1Z += jt.lin1Z * impT;
  31515. ang1X += jt.ang1X * impT;
  31516. ang1Y += jt.ang1Y * impT;
  31517. ang1Z += jt.ang1Z * impT;
  31518. ang2X += jt.ang2X * impT;
  31519. ang2Y += jt.ang2Y * impT;
  31520. ang2Z += jt.ang2Z * impT;
  31521. lin1X += jb.lin1X * impB;
  31522. lin1Y += jb.lin1Y * impB;
  31523. lin1Z += jb.lin1Z * impB;
  31524. ang1X += jb.ang1X * impB;
  31525. ang1Y += jb.ang1Y * impB;
  31526. ang1Z += jb.ang1Z * impB;
  31527. ang2X += jb.ang2X * impB;
  31528. ang2Y += jb.ang2Y * impB;
  31529. ang2Z += jb.ang2Z * impB;
  31530. }
  31531. this._b1._linearContactImpulseX += lin1X;
  31532. this._b1._linearContactImpulseY += lin1Y;
  31533. this._b1._linearContactImpulseZ += lin1Z;
  31534. this._b1._angularContactImpulseX += ang1X;
  31535. this._b1._angularContactImpulseY += ang1Y;
  31536. this._b1._angularContactImpulseZ += ang1Z;
  31537. this._b2._linearContactImpulseX -= lin1X;
  31538. this._b2._linearContactImpulseY -= lin1Y;
  31539. this._b2._linearContactImpulseZ -= lin1Z;
  31540. this._b2._angularContactImpulseX -= ang2X;
  31541. this._b2._angularContactImpulseY -= ang2Y;
  31542. this._b2._angularContactImpulseZ -= ang2Z;
  31543. this.constraint._syncManifold();
  31544. }
  31545. }
  31546. oimo.dynamics.constraint.solver.pgs.PgsJointConstraintSolver = class oimo_dynamics_constraint_solver_pgs_PgsJointConstraintSolver extends oimo.dynamics.constraint.ConstraintSolver {
  31547. constructor(joint) {
  31548. super();
  31549. this.joint = joint;
  31550. this.info = new oimo.dynamics.constraint.info.joint.JointSolverInfo();
  31551. this.massData = new Array(oimo.common.Setting.maxJacobianRows);
  31552. let _g = 0;
  31553. let _g1 = this.massData.length;
  31554. while(_g < _g1) this.massData[_g++] = new oimo.dynamics.constraint.solver.common.JointSolverMassDataRow();
  31555. }
  31556. preSolveVelocity(timeStep) {
  31557. this.joint._syncAnchors();
  31558. this.joint._getVelocitySolverInfo(timeStep,this.info);
  31559. this._b1 = this.info.b1;
  31560. this._b2 = this.info.b2;
  31561. let invM1 = this._b1._invMass;
  31562. let invM2 = this._b2._invMass;
  31563. let invI100;
  31564. let invI101;
  31565. let invI102;
  31566. let invI110;
  31567. let invI111;
  31568. let invI112;
  31569. let invI120;
  31570. let invI121;
  31571. let invI122;
  31572. let invI200;
  31573. let invI201;
  31574. let invI202;
  31575. let invI210;
  31576. let invI211;
  31577. let invI212;
  31578. let invI220;
  31579. let invI221;
  31580. let invI222;
  31581. invI100 = this._b1._invInertia00;
  31582. invI101 = this._b1._invInertia01;
  31583. invI102 = this._b1._invInertia02;
  31584. invI110 = this._b1._invInertia10;
  31585. invI111 = this._b1._invInertia11;
  31586. invI112 = this._b1._invInertia12;
  31587. invI120 = this._b1._invInertia20;
  31588. invI121 = this._b1._invInertia21;
  31589. invI122 = this._b1._invInertia22;
  31590. invI200 = this._b2._invInertia00;
  31591. invI201 = this._b2._invInertia01;
  31592. invI202 = this._b2._invInertia02;
  31593. invI210 = this._b2._invInertia10;
  31594. invI211 = this._b2._invInertia11;
  31595. invI212 = this._b2._invInertia12;
  31596. invI220 = this._b2._invInertia20;
  31597. invI221 = this._b2._invInertia21;
  31598. invI222 = this._b2._invInertia22;
  31599. let _g = 0;
  31600. let _g1 = this.info.numRows;
  31601. while(_g < _g1) {
  31602. let i = _g++;
  31603. let row = this.info.rows[i];
  31604. let md = this.massData[i];
  31605. let j = row.jacobian;
  31606. j.updateSparsity();
  31607. if((j.flag & 1) != 0) {
  31608. md.invMLin1X = j.lin1X * invM1;
  31609. md.invMLin1Y = j.lin1Y * invM1;
  31610. md.invMLin1Z = j.lin1Z * invM1;
  31611. md.invMLin2X = j.lin2X * invM2;
  31612. md.invMLin2Y = j.lin2Y * invM2;
  31613. md.invMLin2Z = j.lin2Z * invM2;
  31614. } else {
  31615. md.invMLin1X = 0;
  31616. md.invMLin1Y = 0;
  31617. md.invMLin1Z = 0;
  31618. md.invMLin2X = 0;
  31619. md.invMLin2Y = 0;
  31620. md.invMLin2Z = 0;
  31621. }
  31622. if((j.flag & 2) != 0) {
  31623. let __tmp__X;
  31624. let __tmp__Y;
  31625. let __tmp__Z;
  31626. __tmp__X = invI100 * j.ang1X + invI101 * j.ang1Y + invI102 * j.ang1Z;
  31627. __tmp__Y = invI110 * j.ang1X + invI111 * j.ang1Y + invI112 * j.ang1Z;
  31628. __tmp__Z = invI120 * j.ang1X + invI121 * j.ang1Y + invI122 * j.ang1Z;
  31629. md.invMAng1X = __tmp__X;
  31630. md.invMAng1Y = __tmp__Y;
  31631. md.invMAng1Z = __tmp__Z;
  31632. let __tmp__X1;
  31633. let __tmp__Y1;
  31634. let __tmp__Z1;
  31635. __tmp__X1 = invI200 * j.ang2X + invI201 * j.ang2Y + invI202 * j.ang2Z;
  31636. __tmp__Y1 = invI210 * j.ang2X + invI211 * j.ang2Y + invI212 * j.ang2Z;
  31637. __tmp__Z1 = invI220 * j.ang2X + invI221 * j.ang2Y + invI222 * j.ang2Z;
  31638. md.invMAng2X = __tmp__X1;
  31639. md.invMAng2Y = __tmp__Y1;
  31640. md.invMAng2Z = __tmp__Z1;
  31641. } else {
  31642. md.invMAng1X = 0;
  31643. md.invMAng1Y = 0;
  31644. md.invMAng1Z = 0;
  31645. md.invMAng2X = 0;
  31646. md.invMAng2Y = 0;
  31647. md.invMAng2Z = 0;
  31648. }
  31649. md.massWithoutCfm = md.invMLin1X * j.lin1X + md.invMLin1Y * j.lin1Y + md.invMLin1Z * j.lin1Z + (md.invMLin2X * j.lin2X + md.invMLin2Y * j.lin2Y + md.invMLin2Z * j.lin2Z) + (md.invMAng1X * j.ang1X + md.invMAng1Y * j.ang1Y + md.invMAng1Z * j.ang1Z) + (md.invMAng2X * j.ang2X + md.invMAng2Y * j.ang2Y + md.invMAng2Z * j.ang2Z);
  31650. md.mass = md.massWithoutCfm + row.cfm;
  31651. if(md.massWithoutCfm != 0) {
  31652. md.massWithoutCfm = 1 / md.massWithoutCfm;
  31653. }
  31654. if(md.mass != 0) {
  31655. md.mass = 1 / md.mass;
  31656. }
  31657. }
  31658. }
  31659. warmStart(timeStep) {
  31660. let factor = this.joint._positionCorrectionAlgorithm == oimo.dynamics.constraint.PositionCorrectionAlgorithm.BAUMGARTE ? oimo.common.Setting.jointWarmStartingFactorForBaungarte : oimo.common.Setting.jointWarmStartingFactor;
  31661. factor *= timeStep.dtRatio;
  31662. if(factor <= 0) {
  31663. let _g = 0;
  31664. let _g1 = this.info.numRows;
  31665. while(_g < _g1) {
  31666. let _this = this.info.rows[_g++].impulse;
  31667. _this.impulse = 0;
  31668. _this.impulseM = 0;
  31669. _this.impulseP = 0;
  31670. }
  31671. return;
  31672. }
  31673. let lv1X;
  31674. let lv1Y;
  31675. let lv1Z;
  31676. let lv2X;
  31677. let lv2Y;
  31678. let lv2Z;
  31679. let av1X;
  31680. let av1Y;
  31681. let av1Z;
  31682. let av2X;
  31683. let av2Y;
  31684. let av2Z;
  31685. lv1X = this._b1._velX;
  31686. lv1Y = this._b1._velY;
  31687. lv1Z = this._b1._velZ;
  31688. lv2X = this._b2._velX;
  31689. lv2Y = this._b2._velY;
  31690. lv2Z = this._b2._velZ;
  31691. av1X = this._b1._angVelX;
  31692. av1Y = this._b1._angVelY;
  31693. av1Z = this._b1._angVelZ;
  31694. av2X = this._b2._angVelX;
  31695. av2Y = this._b2._angVelY;
  31696. av2Z = this._b2._angVelZ;
  31697. let _g = 0;
  31698. let _g1 = this.info.numRows;
  31699. while(_g < _g1) {
  31700. let i = _g++;
  31701. let md = this.massData[i];
  31702. let imp = this.info.rows[i].impulse;
  31703. imp.impulse *= factor;
  31704. imp.impulseM *= factor;
  31705. let impulse = imp.impulse + imp.impulseM;
  31706. lv1X += md.invMLin1X * impulse;
  31707. lv1Y += md.invMLin1Y * impulse;
  31708. lv1Z += md.invMLin1Z * impulse;
  31709. lv2X += md.invMLin2X * -impulse;
  31710. lv2Y += md.invMLin2Y * -impulse;
  31711. lv2Z += md.invMLin2Z * -impulse;
  31712. av1X += md.invMAng1X * impulse;
  31713. av1Y += md.invMAng1Y * impulse;
  31714. av1Z += md.invMAng1Z * impulse;
  31715. av2X += md.invMAng2X * -impulse;
  31716. av2Y += md.invMAng2Y * -impulse;
  31717. av2Z += md.invMAng2Z * -impulse;
  31718. }
  31719. this._b1._velX = lv1X;
  31720. this._b1._velY = lv1Y;
  31721. this._b1._velZ = lv1Z;
  31722. this._b2._velX = lv2X;
  31723. this._b2._velY = lv2Y;
  31724. this._b2._velZ = lv2Z;
  31725. this._b1._angVelX = av1X;
  31726. this._b1._angVelY = av1Y;
  31727. this._b1._angVelZ = av1Z;
  31728. this._b2._angVelX = av2X;
  31729. this._b2._angVelY = av2Y;
  31730. this._b2._angVelZ = av2Z;
  31731. }
  31732. solveVelocity() {
  31733. let lv1X;
  31734. let lv1Y;
  31735. let lv1Z;
  31736. let lv2X;
  31737. let lv2Y;
  31738. let lv2Z;
  31739. let av1X;
  31740. let av1Y;
  31741. let av1Z;
  31742. let av2X;
  31743. let av2Y;
  31744. let av2Z;
  31745. lv1X = this._b1._velX;
  31746. lv1Y = this._b1._velY;
  31747. lv1Z = this._b1._velZ;
  31748. lv2X = this._b2._velX;
  31749. lv2Y = this._b2._velY;
  31750. lv2Z = this._b2._velZ;
  31751. av1X = this._b1._angVelX;
  31752. av1Y = this._b1._angVelY;
  31753. av1Z = this._b1._angVelZ;
  31754. av2X = this._b2._angVelX;
  31755. av2Y = this._b2._angVelY;
  31756. av2Z = this._b2._angVelZ;
  31757. let _g = 0;
  31758. let _g1 = this.info.numRows;
  31759. while(_g < _g1) {
  31760. let i = _g++;
  31761. let row = this.info.rows[i];
  31762. let md = this.massData[i];
  31763. let imp = row.impulse;
  31764. let j = row.jacobian;
  31765. if(row.motorMaxImpulse == 0) {
  31766. continue;
  31767. }
  31768. let rv = 0;
  31769. rv += lv1X * j.lin1X + lv1Y * j.lin1Y + lv1Z * j.lin1Z;
  31770. rv -= lv2X * j.lin2X + lv2Y * j.lin2Y + lv2Z * j.lin2Z;
  31771. rv += av1X * j.ang1X + av1Y * j.ang1Y + av1Z * j.ang1Z;
  31772. rv -= av2X * j.ang2X + av2Y * j.ang2Y + av2Z * j.ang2Z;
  31773. let impulseM = (-row.motorSpeed - rv) * md.massWithoutCfm;
  31774. let oldImpulseM = imp.impulseM;
  31775. imp.impulseM += impulseM;
  31776. if(imp.impulseM < -row.motorMaxImpulse) {
  31777. imp.impulseM = -row.motorMaxImpulse;
  31778. } else if(imp.impulseM > row.motorMaxImpulse) {
  31779. imp.impulseM = row.motorMaxImpulse;
  31780. }
  31781. impulseM = imp.impulseM - oldImpulseM;
  31782. if((j.flag & 1) != 0) {
  31783. lv1X += md.invMLin1X * impulseM;
  31784. lv1Y += md.invMLin1Y * impulseM;
  31785. lv1Z += md.invMLin1Z * impulseM;
  31786. lv2X += md.invMLin2X * -impulseM;
  31787. lv2Y += md.invMLin2Y * -impulseM;
  31788. lv2Z += md.invMLin2Z * -impulseM;
  31789. }
  31790. if((j.flag & 2) != 0) {
  31791. av1X += md.invMAng1X * impulseM;
  31792. av1Y += md.invMAng1Y * impulseM;
  31793. av1Z += md.invMAng1Z * impulseM;
  31794. av2X += md.invMAng2X * -impulseM;
  31795. av2Y += md.invMAng2Y * -impulseM;
  31796. av2Z += md.invMAng2Z * -impulseM;
  31797. }
  31798. }
  31799. let _g2 = 0;
  31800. let _g3 = this.info.numRows;
  31801. while(_g2 < _g3) {
  31802. let i = _g2++;
  31803. let row = this.info.rows[i];
  31804. let md = this.massData[i];
  31805. let imp = row.impulse;
  31806. let j = row.jacobian;
  31807. let rv = 0;
  31808. rv += lv1X * j.lin1X + lv1Y * j.lin1Y + lv1Z * j.lin1Z;
  31809. rv -= lv2X * j.lin2X + lv2Y * j.lin2Y + lv2Z * j.lin2Z;
  31810. rv += av1X * j.ang1X + av1Y * j.ang1Y + av1Z * j.ang1Z;
  31811. rv -= av2X * j.ang2X + av2Y * j.ang2Y + av2Z * j.ang2Z;
  31812. let impulse = (row.rhs - rv - imp.impulse * row.cfm) * md.mass;
  31813. let oldImpulse = imp.impulse;
  31814. imp.impulse += impulse;
  31815. if(imp.impulse < row.minImpulse) {
  31816. imp.impulse = row.minImpulse;
  31817. } else if(imp.impulse > row.maxImpulse) {
  31818. imp.impulse = row.maxImpulse;
  31819. }
  31820. impulse = imp.impulse - oldImpulse;
  31821. if((j.flag & 1) != 0) {
  31822. lv1X += md.invMLin1X * impulse;
  31823. lv1Y += md.invMLin1Y * impulse;
  31824. lv1Z += md.invMLin1Z * impulse;
  31825. lv2X += md.invMLin2X * -impulse;
  31826. lv2Y += md.invMLin2Y * -impulse;
  31827. lv2Z += md.invMLin2Z * -impulse;
  31828. }
  31829. if((j.flag & 2) != 0) {
  31830. av1X += md.invMAng1X * impulse;
  31831. av1Y += md.invMAng1Y * impulse;
  31832. av1Z += md.invMAng1Z * impulse;
  31833. av2X += md.invMAng2X * -impulse;
  31834. av2Y += md.invMAng2Y * -impulse;
  31835. av2Z += md.invMAng2Z * -impulse;
  31836. }
  31837. }
  31838. this._b1._velX = lv1X;
  31839. this._b1._velY = lv1Y;
  31840. this._b1._velZ = lv1Z;
  31841. this._b2._velX = lv2X;
  31842. this._b2._velY = lv2Y;
  31843. this._b2._velZ = lv2Z;
  31844. this._b1._angVelX = av1X;
  31845. this._b1._angVelY = av1Y;
  31846. this._b1._angVelZ = av1Z;
  31847. this._b2._angVelX = av2X;
  31848. this._b2._angVelY = av2Y;
  31849. this._b2._angVelZ = av2Z;
  31850. }
  31851. postSolveVelocity(timeStep) {
  31852. let linX;
  31853. let linY;
  31854. let linZ;
  31855. let angX;
  31856. let angY;
  31857. let angZ;
  31858. linX = 0;
  31859. linY = 0;
  31860. linZ = 0;
  31861. angX = 0;
  31862. angY = 0;
  31863. angZ = 0;
  31864. let _g = 0;
  31865. let _g1 = this.info.numRows;
  31866. while(_g < _g1) {
  31867. let row = this.info.rows[_g++];
  31868. let imp = row.impulse;
  31869. let j = row.jacobian;
  31870. if((j.flag & 1) != 0) {
  31871. linX += j.lin1X * imp.impulse;
  31872. linY += j.lin1Y * imp.impulse;
  31873. linZ += j.lin1Z * imp.impulse;
  31874. } else if((j.flag & 2) != 0) {
  31875. angX += j.ang1X * imp.impulse;
  31876. angY += j.ang1Y * imp.impulse;
  31877. angZ += j.ang1Z * imp.impulse;
  31878. }
  31879. }
  31880. this.joint._appliedForceX = linX * timeStep.invDt;
  31881. this.joint._appliedForceY = linY * timeStep.invDt;
  31882. this.joint._appliedForceZ = linZ * timeStep.invDt;
  31883. this.joint._appliedTorqueX = angX * timeStep.invDt;
  31884. this.joint._appliedTorqueY = angY * timeStep.invDt;
  31885. this.joint._appliedTorqueZ = angZ * timeStep.invDt;
  31886. }
  31887. preSolvePosition(timeStep) {
  31888. this.joint._syncAnchors();
  31889. this.joint._getPositionSolverInfo(this.info);
  31890. this._b1 = this.info.b1;
  31891. this._b2 = this.info.b2;
  31892. let invM1 = this._b1._invMass;
  31893. let invM2 = this._b2._invMass;
  31894. let invI100;
  31895. let invI101;
  31896. let invI102;
  31897. let invI110;
  31898. let invI111;
  31899. let invI112;
  31900. let invI120;
  31901. let invI121;
  31902. let invI122;
  31903. let invI200;
  31904. let invI201;
  31905. let invI202;
  31906. let invI210;
  31907. let invI211;
  31908. let invI212;
  31909. let invI220;
  31910. let invI221;
  31911. let invI222;
  31912. invI100 = this._b1._invInertia00;
  31913. invI101 = this._b1._invInertia01;
  31914. invI102 = this._b1._invInertia02;
  31915. invI110 = this._b1._invInertia10;
  31916. invI111 = this._b1._invInertia11;
  31917. invI112 = this._b1._invInertia12;
  31918. invI120 = this._b1._invInertia20;
  31919. invI121 = this._b1._invInertia21;
  31920. invI122 = this._b1._invInertia22;
  31921. invI200 = this._b2._invInertia00;
  31922. invI201 = this._b2._invInertia01;
  31923. invI202 = this._b2._invInertia02;
  31924. invI210 = this._b2._invInertia10;
  31925. invI211 = this._b2._invInertia11;
  31926. invI212 = this._b2._invInertia12;
  31927. invI220 = this._b2._invInertia20;
  31928. invI221 = this._b2._invInertia21;
  31929. invI222 = this._b2._invInertia22;
  31930. let _g = 0;
  31931. let _g1 = this.info.numRows;
  31932. while(_g < _g1) {
  31933. let i = _g++;
  31934. let md = this.massData[i];
  31935. let j = this.info.rows[i].jacobian;
  31936. md.invMLin1X = j.lin1X * invM1;
  31937. md.invMLin1Y = j.lin1Y * invM1;
  31938. md.invMLin1Z = j.lin1Z * invM1;
  31939. md.invMLin2X = j.lin2X * invM2;
  31940. md.invMLin2Y = j.lin2Y * invM2;
  31941. md.invMLin2Z = j.lin2Z * invM2;
  31942. let __tmp__X;
  31943. let __tmp__Y;
  31944. let __tmp__Z;
  31945. __tmp__X = invI100 * j.ang1X + invI101 * j.ang1Y + invI102 * j.ang1Z;
  31946. __tmp__Y = invI110 * j.ang1X + invI111 * j.ang1Y + invI112 * j.ang1Z;
  31947. __tmp__Z = invI120 * j.ang1X + invI121 * j.ang1Y + invI122 * j.ang1Z;
  31948. md.invMAng1X = __tmp__X;
  31949. md.invMAng1Y = __tmp__Y;
  31950. md.invMAng1Z = __tmp__Z;
  31951. let __tmp__X1;
  31952. let __tmp__Y1;
  31953. let __tmp__Z1;
  31954. __tmp__X1 = invI200 * j.ang2X + invI201 * j.ang2Y + invI202 * j.ang2Z;
  31955. __tmp__Y1 = invI210 * j.ang2X + invI211 * j.ang2Y + invI212 * j.ang2Z;
  31956. __tmp__Z1 = invI220 * j.ang2X + invI221 * j.ang2Y + invI222 * j.ang2Z;
  31957. md.invMAng2X = __tmp__X1;
  31958. md.invMAng2Y = __tmp__Y1;
  31959. md.invMAng2Z = __tmp__Z1;
  31960. md.mass = md.invMLin1X * j.lin1X + md.invMLin1Y * j.lin1Y + md.invMLin1Z * j.lin1Z + (md.invMLin2X * j.lin2X + md.invMLin2Y * j.lin2Y + md.invMLin2Z * j.lin2Z) + (md.invMAng1X * j.ang1X + md.invMAng1Y * j.ang1Y + md.invMAng1Z * j.ang1Z) + (md.invMAng2X * j.ang2X + md.invMAng2Y * j.ang2Y + md.invMAng2Z * j.ang2Z);
  31961. if(md.mass != 0) {
  31962. md.mass = 1 / md.mass;
  31963. }
  31964. }
  31965. let _g2 = 0;
  31966. let _g3 = this.info.numRows;
  31967. while(_g2 < _g3) this.info.rows[_g2++].impulse.impulseP = 0;
  31968. }
  31969. solvePositionSplitImpulse() {
  31970. let lv1X;
  31971. let lv1Y;
  31972. let lv1Z;
  31973. let lv2X;
  31974. let lv2Y;
  31975. let lv2Z;
  31976. let av1X;
  31977. let av1Y;
  31978. let av1Z;
  31979. let av2X;
  31980. let av2Y;
  31981. let av2Z;
  31982. lv1X = this._b1._pseudoVelX;
  31983. lv1Y = this._b1._pseudoVelY;
  31984. lv1Z = this._b1._pseudoVelZ;
  31985. lv2X = this._b2._pseudoVelX;
  31986. lv2Y = this._b2._pseudoVelY;
  31987. lv2Z = this._b2._pseudoVelZ;
  31988. av1X = this._b1._angPseudoVelX;
  31989. av1Y = this._b1._angPseudoVelY;
  31990. av1Z = this._b1._angPseudoVelZ;
  31991. av2X = this._b2._angPseudoVelX;
  31992. av2Y = this._b2._angPseudoVelY;
  31993. av2Z = this._b2._angPseudoVelZ;
  31994. let _g = 0;
  31995. let _g1 = this.info.numRows;
  31996. while(_g < _g1) {
  31997. let i = _g++;
  31998. let row = this.info.rows[i];
  31999. let md = this.massData[i];
  32000. let imp = row.impulse;
  32001. let j = row.jacobian;
  32002. let rv = 0;
  32003. rv += lv1X * j.lin1X + lv1Y * j.lin1Y + lv1Z * j.lin1Z;
  32004. rv -= lv2X * j.lin2X + lv2Y * j.lin2Y + lv2Z * j.lin2Z;
  32005. rv += av1X * j.ang1X + av1Y * j.ang1Y + av1Z * j.ang1Z;
  32006. rv -= av2X * j.ang2X + av2Y * j.ang2Y + av2Z * j.ang2Z;
  32007. let impulseP = (row.rhs * oimo.common.Setting.positionSplitImpulseBaumgarte - rv) * md.mass;
  32008. let oldImpulseP = imp.impulseP;
  32009. imp.impulseP += impulseP;
  32010. if(imp.impulseP < row.minImpulse) {
  32011. imp.impulseP = row.minImpulse;
  32012. } else if(imp.impulseP > row.maxImpulse) {
  32013. imp.impulseP = row.maxImpulse;
  32014. }
  32015. impulseP = imp.impulseP - oldImpulseP;
  32016. lv1X += md.invMLin1X * impulseP;
  32017. lv1Y += md.invMLin1Y * impulseP;
  32018. lv1Z += md.invMLin1Z * impulseP;
  32019. lv2X += md.invMLin2X * -impulseP;
  32020. lv2Y += md.invMLin2Y * -impulseP;
  32021. lv2Z += md.invMLin2Z * -impulseP;
  32022. av1X += md.invMAng1X * impulseP;
  32023. av1Y += md.invMAng1Y * impulseP;
  32024. av1Z += md.invMAng1Z * impulseP;
  32025. av2X += md.invMAng2X * -impulseP;
  32026. av2Y += md.invMAng2Y * -impulseP;
  32027. av2Z += md.invMAng2Z * -impulseP;
  32028. }
  32029. this._b1._pseudoVelX = lv1X;
  32030. this._b1._pseudoVelY = lv1Y;
  32031. this._b1._pseudoVelZ = lv1Z;
  32032. this._b2._pseudoVelX = lv2X;
  32033. this._b2._pseudoVelY = lv2Y;
  32034. this._b2._pseudoVelZ = lv2Z;
  32035. this._b1._angPseudoVelX = av1X;
  32036. this._b1._angPseudoVelY = av1Y;
  32037. this._b1._angPseudoVelZ = av1Z;
  32038. this._b2._angPseudoVelX = av2X;
  32039. this._b2._angPseudoVelY = av2Y;
  32040. this._b2._angPseudoVelZ = av2Z;
  32041. }
  32042. solvePositionNgs(timeStep) {
  32043. this.joint._syncAnchors();
  32044. this.joint._getPositionSolverInfo(this.info);
  32045. this._b1 = this.info.b1;
  32046. this._b2 = this.info.b2;
  32047. let invM1 = this._b1._invMass;
  32048. let invM2 = this._b2._invMass;
  32049. let invI100;
  32050. let invI101;
  32051. let invI102;
  32052. let invI110;
  32053. let invI111;
  32054. let invI112;
  32055. let invI120;
  32056. let invI121;
  32057. let invI122;
  32058. let invI200;
  32059. let invI201;
  32060. let invI202;
  32061. let invI210;
  32062. let invI211;
  32063. let invI212;
  32064. let invI220;
  32065. let invI221;
  32066. let invI222;
  32067. invI100 = this._b1._invInertia00;
  32068. invI101 = this._b1._invInertia01;
  32069. invI102 = this._b1._invInertia02;
  32070. invI110 = this._b1._invInertia10;
  32071. invI111 = this._b1._invInertia11;
  32072. invI112 = this._b1._invInertia12;
  32073. invI120 = this._b1._invInertia20;
  32074. invI121 = this._b1._invInertia21;
  32075. invI122 = this._b1._invInertia22;
  32076. invI200 = this._b2._invInertia00;
  32077. invI201 = this._b2._invInertia01;
  32078. invI202 = this._b2._invInertia02;
  32079. invI210 = this._b2._invInertia10;
  32080. invI211 = this._b2._invInertia11;
  32081. invI212 = this._b2._invInertia12;
  32082. invI220 = this._b2._invInertia20;
  32083. invI221 = this._b2._invInertia21;
  32084. invI222 = this._b2._invInertia22;
  32085. let _g = 0;
  32086. let _g1 = this.info.numRows;
  32087. while(_g < _g1) {
  32088. let i = _g++;
  32089. let md = this.massData[i];
  32090. let j = this.info.rows[i].jacobian;
  32091. md.invMLin1X = j.lin1X * invM1;
  32092. md.invMLin1Y = j.lin1Y * invM1;
  32093. md.invMLin1Z = j.lin1Z * invM1;
  32094. md.invMLin2X = j.lin2X * invM2;
  32095. md.invMLin2Y = j.lin2Y * invM2;
  32096. md.invMLin2Z = j.lin2Z * invM2;
  32097. let __tmp__X;
  32098. let __tmp__Y;
  32099. let __tmp__Z;
  32100. __tmp__X = invI100 * j.ang1X + invI101 * j.ang1Y + invI102 * j.ang1Z;
  32101. __tmp__Y = invI110 * j.ang1X + invI111 * j.ang1Y + invI112 * j.ang1Z;
  32102. __tmp__Z = invI120 * j.ang1X + invI121 * j.ang1Y + invI122 * j.ang1Z;
  32103. md.invMAng1X = __tmp__X;
  32104. md.invMAng1Y = __tmp__Y;
  32105. md.invMAng1Z = __tmp__Z;
  32106. let __tmp__X1;
  32107. let __tmp__Y1;
  32108. let __tmp__Z1;
  32109. __tmp__X1 = invI200 * j.ang2X + invI201 * j.ang2Y + invI202 * j.ang2Z;
  32110. __tmp__Y1 = invI210 * j.ang2X + invI211 * j.ang2Y + invI212 * j.ang2Z;
  32111. __tmp__Z1 = invI220 * j.ang2X + invI221 * j.ang2Y + invI222 * j.ang2Z;
  32112. md.invMAng2X = __tmp__X1;
  32113. md.invMAng2Y = __tmp__Y1;
  32114. md.invMAng2Z = __tmp__Z1;
  32115. md.mass = md.invMLin1X * j.lin1X + md.invMLin1Y * j.lin1Y + md.invMLin1Z * j.lin1Z + (md.invMLin2X * j.lin2X + md.invMLin2Y * j.lin2Y + md.invMLin2Z * j.lin2Z) + (md.invMAng1X * j.ang1X + md.invMAng1Y * j.ang1Y + md.invMAng1Z * j.ang1Z) + (md.invMAng2X * j.ang2X + md.invMAng2Y * j.ang2Y + md.invMAng2Z * j.ang2Z);
  32116. if(md.mass != 0) {
  32117. md.mass = 1 / md.mass;
  32118. }
  32119. }
  32120. let lv1X;
  32121. let lv1Y;
  32122. let lv1Z;
  32123. let lv2X;
  32124. let lv2Y;
  32125. let lv2Z;
  32126. let av1X;
  32127. let av1Y;
  32128. let av1Z;
  32129. let av2X;
  32130. let av2Y;
  32131. let av2Z;
  32132. lv1X = 0;
  32133. lv1Y = 0;
  32134. lv1Z = 0;
  32135. lv2X = 0;
  32136. lv2Y = 0;
  32137. lv2Z = 0;
  32138. av1X = 0;
  32139. av1Y = 0;
  32140. av1Z = 0;
  32141. av2X = 0;
  32142. av2Y = 0;
  32143. av2Z = 0;
  32144. let _g2 = 0;
  32145. let _g3 = this.info.numRows;
  32146. while(_g2 < _g3) {
  32147. let i = _g2++;
  32148. let row = this.info.rows[i];
  32149. let md = this.massData[i];
  32150. let imp = row.impulse;
  32151. let j = row.jacobian;
  32152. let rv = 0;
  32153. rv += lv1X * j.lin1X + lv1Y * j.lin1Y + lv1Z * j.lin1Z;
  32154. rv -= lv2X * j.lin2X + lv2Y * j.lin2Y + lv2Z * j.lin2Z;
  32155. rv += av1X * j.ang1X + av1Y * j.ang1Y + av1Z * j.ang1Z;
  32156. rv -= av2X * j.ang2X + av2Y * j.ang2Y + av2Z * j.ang2Z;
  32157. let impulseP = (row.rhs * oimo.common.Setting.positionNgsBaumgarte - rv) * md.mass;
  32158. let oldImpulseP = imp.impulseP;
  32159. imp.impulseP += impulseP;
  32160. if(imp.impulseP < row.minImpulse) {
  32161. imp.impulseP = row.minImpulse;
  32162. } else if(imp.impulseP > row.maxImpulse) {
  32163. imp.impulseP = row.maxImpulse;
  32164. }
  32165. impulseP = imp.impulseP - oldImpulseP;
  32166. lv1X += md.invMLin1X * impulseP;
  32167. lv1Y += md.invMLin1Y * impulseP;
  32168. lv1Z += md.invMLin1Z * impulseP;
  32169. lv2X += md.invMLin2X * -impulseP;
  32170. lv2Y += md.invMLin2Y * -impulseP;
  32171. lv2Z += md.invMLin2Z * -impulseP;
  32172. av1X += md.invMAng1X * impulseP;
  32173. av1Y += md.invMAng1Y * impulseP;
  32174. av1Z += md.invMAng1Z * impulseP;
  32175. av2X += md.invMAng2X * -impulseP;
  32176. av2Y += md.invMAng2Y * -impulseP;
  32177. av2Z += md.invMAng2Z * -impulseP;
  32178. }
  32179. let _this = this._b1;
  32180. _this._transform._positionX += lv1X;
  32181. _this._transform._positionY += lv1Y;
  32182. _this._transform._positionZ += lv1Z;
  32183. let _this1 = this._b2;
  32184. _this1._transform._positionX += lv2X;
  32185. _this1._transform._positionY += lv2Y;
  32186. _this1._transform._positionZ += lv2Z;
  32187. let _this2 = this._b1;
  32188. let theta = Math.sqrt(av1X * av1X + av1Y * av1Y + av1Z * av1Z);
  32189. let halfTheta = theta * 0.5;
  32190. let rotationToSinAxisFactor;
  32191. let cosHalfTheta;
  32192. if(halfTheta < 0.5) {
  32193. let ht2 = halfTheta * halfTheta;
  32194. rotationToSinAxisFactor = 0.5 * (1 - ht2 * 0.16666666666666666 + ht2 * ht2 * 0.0083333333333333332);
  32195. cosHalfTheta = 1 - ht2 * 0.5 + ht2 * ht2 * 0.041666666666666664;
  32196. } else {
  32197. rotationToSinAxisFactor = Math.sin(halfTheta) / theta;
  32198. cosHalfTheta = Math.cos(halfTheta);
  32199. }
  32200. let sinAxisX;
  32201. let sinAxisY;
  32202. let sinAxisZ;
  32203. sinAxisX = av1X * rotationToSinAxisFactor;
  32204. sinAxisY = av1Y * rotationToSinAxisFactor;
  32205. sinAxisZ = av1Z * rotationToSinAxisFactor;
  32206. let dqX;
  32207. let dqY;
  32208. let dqZ;
  32209. let dqW;
  32210. dqX = sinAxisX;
  32211. dqY = sinAxisY;
  32212. dqZ = sinAxisZ;
  32213. dqW = cosHalfTheta;
  32214. let qX;
  32215. let qY;
  32216. let qZ;
  32217. let qW;
  32218. let e00 = _this2._transform._rotation00;
  32219. let e11 = _this2._transform._rotation11;
  32220. let e22 = _this2._transform._rotation22;
  32221. let t = e00 + e11 + e22;
  32222. let s;
  32223. if(t > 0) {
  32224. s = Math.sqrt(t + 1);
  32225. qW = 0.5 * s;
  32226. s = 0.5 / s;
  32227. qX = (_this2._transform._rotation21 - _this2._transform._rotation12) * s;
  32228. qY = (_this2._transform._rotation02 - _this2._transform._rotation20) * s;
  32229. qZ = (_this2._transform._rotation10 - _this2._transform._rotation01) * s;
  32230. } else if(e00 > e11) {
  32231. if(e00 > e22) {
  32232. s = Math.sqrt(e00 - e11 - e22 + 1);
  32233. qX = 0.5 * s;
  32234. s = 0.5 / s;
  32235. qY = (_this2._transform._rotation01 + _this2._transform._rotation10) * s;
  32236. qZ = (_this2._transform._rotation02 + _this2._transform._rotation20) * s;
  32237. qW = (_this2._transform._rotation21 - _this2._transform._rotation12) * s;
  32238. } else {
  32239. s = Math.sqrt(e22 - e00 - e11 + 1);
  32240. qZ = 0.5 * s;
  32241. s = 0.5 / s;
  32242. qX = (_this2._transform._rotation02 + _this2._transform._rotation20) * s;
  32243. qY = (_this2._transform._rotation12 + _this2._transform._rotation21) * s;
  32244. qW = (_this2._transform._rotation10 - _this2._transform._rotation01) * s;
  32245. }
  32246. } else if(e11 > e22) {
  32247. s = Math.sqrt(e11 - e22 - e00 + 1);
  32248. qY = 0.5 * s;
  32249. s = 0.5 / s;
  32250. qX = (_this2._transform._rotation01 + _this2._transform._rotation10) * s;
  32251. qZ = (_this2._transform._rotation12 + _this2._transform._rotation21) * s;
  32252. qW = (_this2._transform._rotation02 - _this2._transform._rotation20) * s;
  32253. } else {
  32254. s = Math.sqrt(e22 - e00 - e11 + 1);
  32255. qZ = 0.5 * s;
  32256. s = 0.5 / s;
  32257. qX = (_this2._transform._rotation02 + _this2._transform._rotation20) * s;
  32258. qY = (_this2._transform._rotation12 + _this2._transform._rotation21) * s;
  32259. qW = (_this2._transform._rotation10 - _this2._transform._rotation01) * s;
  32260. }
  32261. qX = dqW * qX + dqX * qW + dqY * qZ - dqZ * qY;
  32262. qY = dqW * qY - dqX * qZ + dqY * qW + dqZ * qX;
  32263. qZ = dqW * qZ + dqX * qY - dqY * qX + dqZ * qW;
  32264. qW = dqW * qW - dqX * qX - dqY * qY - dqZ * qZ;
  32265. let l = qX * qX + qY * qY + qZ * qZ + qW * qW;
  32266. if(l > 1e-32) {
  32267. l = 1 / Math.sqrt(l);
  32268. }
  32269. qX *= l;
  32270. qY *= l;
  32271. qZ *= l;
  32272. qW *= l;
  32273. let x = qX;
  32274. let y = qY;
  32275. let z = qZ;
  32276. let w = qW;
  32277. let x2 = 2 * x;
  32278. let y2 = 2 * y;
  32279. let z2 = 2 * z;
  32280. let xx = x * x2;
  32281. let yy = y * y2;
  32282. let zz = z * z2;
  32283. let xy = x * y2;
  32284. let yz = y * z2;
  32285. let xz = x * z2;
  32286. let wx = w * x2;
  32287. let wy = w * y2;
  32288. let wz = w * z2;
  32289. _this2._transform._rotation00 = 1 - yy - zz;
  32290. _this2._transform._rotation01 = xy - wz;
  32291. _this2._transform._rotation02 = xz + wy;
  32292. _this2._transform._rotation10 = xy + wz;
  32293. _this2._transform._rotation11 = 1 - xx - zz;
  32294. _this2._transform._rotation12 = yz - wx;
  32295. _this2._transform._rotation20 = xz - wy;
  32296. _this2._transform._rotation21 = yz + wx;
  32297. _this2._transform._rotation22 = 1 - xx - yy;
  32298. let __tmp__00;
  32299. let __tmp__01;
  32300. let __tmp__02;
  32301. let __tmp__10;
  32302. let __tmp__11;
  32303. let __tmp__12;
  32304. let __tmp__20;
  32305. let __tmp__21;
  32306. let __tmp__22;
  32307. __tmp__00 = _this2._transform._rotation00 * _this2._invLocalInertia00 + _this2._transform._rotation01 * _this2._invLocalInertia10 + _this2._transform._rotation02 * _this2._invLocalInertia20;
  32308. __tmp__01 = _this2._transform._rotation00 * _this2._invLocalInertia01 + _this2._transform._rotation01 * _this2._invLocalInertia11 + _this2._transform._rotation02 * _this2._invLocalInertia21;
  32309. __tmp__02 = _this2._transform._rotation00 * _this2._invLocalInertia02 + _this2._transform._rotation01 * _this2._invLocalInertia12 + _this2._transform._rotation02 * _this2._invLocalInertia22;
  32310. __tmp__10 = _this2._transform._rotation10 * _this2._invLocalInertia00 + _this2._transform._rotation11 * _this2._invLocalInertia10 + _this2._transform._rotation12 * _this2._invLocalInertia20;
  32311. __tmp__11 = _this2._transform._rotation10 * _this2._invLocalInertia01 + _this2._transform._rotation11 * _this2._invLocalInertia11 + _this2._transform._rotation12 * _this2._invLocalInertia21;
  32312. __tmp__12 = _this2._transform._rotation10 * _this2._invLocalInertia02 + _this2._transform._rotation11 * _this2._invLocalInertia12 + _this2._transform._rotation12 * _this2._invLocalInertia22;
  32313. __tmp__20 = _this2._transform._rotation20 * _this2._invLocalInertia00 + _this2._transform._rotation21 * _this2._invLocalInertia10 + _this2._transform._rotation22 * _this2._invLocalInertia20;
  32314. __tmp__21 = _this2._transform._rotation20 * _this2._invLocalInertia01 + _this2._transform._rotation21 * _this2._invLocalInertia11 + _this2._transform._rotation22 * _this2._invLocalInertia21;
  32315. __tmp__22 = _this2._transform._rotation20 * _this2._invLocalInertia02 + _this2._transform._rotation21 * _this2._invLocalInertia12 + _this2._transform._rotation22 * _this2._invLocalInertia22;
  32316. _this2._invInertia00 = __tmp__00;
  32317. _this2._invInertia01 = __tmp__01;
  32318. _this2._invInertia02 = __tmp__02;
  32319. _this2._invInertia10 = __tmp__10;
  32320. _this2._invInertia11 = __tmp__11;
  32321. _this2._invInertia12 = __tmp__12;
  32322. _this2._invInertia20 = __tmp__20;
  32323. _this2._invInertia21 = __tmp__21;
  32324. _this2._invInertia22 = __tmp__22;
  32325. let __tmp__001;
  32326. let __tmp__011;
  32327. let __tmp__021;
  32328. let __tmp__101;
  32329. let __tmp__111;
  32330. let __tmp__121;
  32331. let __tmp__201;
  32332. let __tmp__211;
  32333. let __tmp__221;
  32334. __tmp__001 = _this2._invInertia00 * _this2._transform._rotation00 + _this2._invInertia01 * _this2._transform._rotation01 + _this2._invInertia02 * _this2._transform._rotation02;
  32335. __tmp__011 = _this2._invInertia00 * _this2._transform._rotation10 + _this2._invInertia01 * _this2._transform._rotation11 + _this2._invInertia02 * _this2._transform._rotation12;
  32336. __tmp__021 = _this2._invInertia00 * _this2._transform._rotation20 + _this2._invInertia01 * _this2._transform._rotation21 + _this2._invInertia02 * _this2._transform._rotation22;
  32337. __tmp__101 = _this2._invInertia10 * _this2._transform._rotation00 + _this2._invInertia11 * _this2._transform._rotation01 + _this2._invInertia12 * _this2._transform._rotation02;
  32338. __tmp__111 = _this2._invInertia10 * _this2._transform._rotation10 + _this2._invInertia11 * _this2._transform._rotation11 + _this2._invInertia12 * _this2._transform._rotation12;
  32339. __tmp__121 = _this2._invInertia10 * _this2._transform._rotation20 + _this2._invInertia11 * _this2._transform._rotation21 + _this2._invInertia12 * _this2._transform._rotation22;
  32340. __tmp__201 = _this2._invInertia20 * _this2._transform._rotation00 + _this2._invInertia21 * _this2._transform._rotation01 + _this2._invInertia22 * _this2._transform._rotation02;
  32341. __tmp__211 = _this2._invInertia20 * _this2._transform._rotation10 + _this2._invInertia21 * _this2._transform._rotation11 + _this2._invInertia22 * _this2._transform._rotation12;
  32342. __tmp__221 = _this2._invInertia20 * _this2._transform._rotation20 + _this2._invInertia21 * _this2._transform._rotation21 + _this2._invInertia22 * _this2._transform._rotation22;
  32343. _this2._invInertia00 = __tmp__001;
  32344. _this2._invInertia01 = __tmp__011;
  32345. _this2._invInertia02 = __tmp__021;
  32346. _this2._invInertia10 = __tmp__101;
  32347. _this2._invInertia11 = __tmp__111;
  32348. _this2._invInertia12 = __tmp__121;
  32349. _this2._invInertia20 = __tmp__201;
  32350. _this2._invInertia21 = __tmp__211;
  32351. _this2._invInertia22 = __tmp__221;
  32352. _this2._invInertia00 *= _this2._rotFactor.x;
  32353. _this2._invInertia01 *= _this2._rotFactor.x;
  32354. _this2._invInertia02 *= _this2._rotFactor.x;
  32355. _this2._invInertia10 *= _this2._rotFactor.y;
  32356. _this2._invInertia11 *= _this2._rotFactor.y;
  32357. _this2._invInertia12 *= _this2._rotFactor.y;
  32358. _this2._invInertia20 *= _this2._rotFactor.z;
  32359. _this2._invInertia21 *= _this2._rotFactor.z;
  32360. _this2._invInertia22 *= _this2._rotFactor.z;
  32361. let _this3 = this._b2;
  32362. let theta1 = Math.sqrt(av2X * av2X + av2Y * av2Y + av2Z * av2Z);
  32363. let halfTheta1 = theta1 * 0.5;
  32364. let rotationToSinAxisFactor1;
  32365. let cosHalfTheta1;
  32366. if(halfTheta1 < 0.5) {
  32367. let ht2 = halfTheta1 * halfTheta1;
  32368. rotationToSinAxisFactor1 = 0.5 * (1 - ht2 * 0.16666666666666666 + ht2 * ht2 * 0.0083333333333333332);
  32369. cosHalfTheta1 = 1 - ht2 * 0.5 + ht2 * ht2 * 0.041666666666666664;
  32370. } else {
  32371. rotationToSinAxisFactor1 = Math.sin(halfTheta1) / theta1;
  32372. cosHalfTheta1 = Math.cos(halfTheta1);
  32373. }
  32374. let sinAxisX1;
  32375. let sinAxisY1;
  32376. let sinAxisZ1;
  32377. sinAxisX1 = av2X * rotationToSinAxisFactor1;
  32378. sinAxisY1 = av2Y * rotationToSinAxisFactor1;
  32379. sinAxisZ1 = av2Z * rotationToSinAxisFactor1;
  32380. let dqX1;
  32381. let dqY1;
  32382. let dqZ1;
  32383. let dqW1;
  32384. dqX1 = sinAxisX1;
  32385. dqY1 = sinAxisY1;
  32386. dqZ1 = sinAxisZ1;
  32387. dqW1 = cosHalfTheta1;
  32388. let qX1;
  32389. let qY1;
  32390. let qZ1;
  32391. let qW1;
  32392. let e001 = _this3._transform._rotation00;
  32393. let e111 = _this3._transform._rotation11;
  32394. let e221 = _this3._transform._rotation22;
  32395. let t1 = e001 + e111 + e221;
  32396. let s1;
  32397. if(t1 > 0) {
  32398. s1 = Math.sqrt(t1 + 1);
  32399. qW1 = 0.5 * s1;
  32400. s1 = 0.5 / s1;
  32401. qX1 = (_this3._transform._rotation21 - _this3._transform._rotation12) * s1;
  32402. qY1 = (_this3._transform._rotation02 - _this3._transform._rotation20) * s1;
  32403. qZ1 = (_this3._transform._rotation10 - _this3._transform._rotation01) * s1;
  32404. } else if(e001 > e111) {
  32405. if(e001 > e221) {
  32406. s1 = Math.sqrt(e001 - e111 - e221 + 1);
  32407. qX1 = 0.5 * s1;
  32408. s1 = 0.5 / s1;
  32409. qY1 = (_this3._transform._rotation01 + _this3._transform._rotation10) * s1;
  32410. qZ1 = (_this3._transform._rotation02 + _this3._transform._rotation20) * s1;
  32411. qW1 = (_this3._transform._rotation21 - _this3._transform._rotation12) * s1;
  32412. } else {
  32413. s1 = Math.sqrt(e221 - e001 - e111 + 1);
  32414. qZ1 = 0.5 * s1;
  32415. s1 = 0.5 / s1;
  32416. qX1 = (_this3._transform._rotation02 + _this3._transform._rotation20) * s1;
  32417. qY1 = (_this3._transform._rotation12 + _this3._transform._rotation21) * s1;
  32418. qW1 = (_this3._transform._rotation10 - _this3._transform._rotation01) * s1;
  32419. }
  32420. } else if(e111 > e221) {
  32421. s1 = Math.sqrt(e111 - e221 - e001 + 1);
  32422. qY1 = 0.5 * s1;
  32423. s1 = 0.5 / s1;
  32424. qX1 = (_this3._transform._rotation01 + _this3._transform._rotation10) * s1;
  32425. qZ1 = (_this3._transform._rotation12 + _this3._transform._rotation21) * s1;
  32426. qW1 = (_this3._transform._rotation02 - _this3._transform._rotation20) * s1;
  32427. } else {
  32428. s1 = Math.sqrt(e221 - e001 - e111 + 1);
  32429. qZ1 = 0.5 * s1;
  32430. s1 = 0.5 / s1;
  32431. qX1 = (_this3._transform._rotation02 + _this3._transform._rotation20) * s1;
  32432. qY1 = (_this3._transform._rotation12 + _this3._transform._rotation21) * s1;
  32433. qW1 = (_this3._transform._rotation10 - _this3._transform._rotation01) * s1;
  32434. }
  32435. qX1 = dqW1 * qX1 + dqX1 * qW1 + dqY1 * qZ1 - dqZ1 * qY1;
  32436. qY1 = dqW1 * qY1 - dqX1 * qZ1 + dqY1 * qW1 + dqZ1 * qX1;
  32437. qZ1 = dqW1 * qZ1 + dqX1 * qY1 - dqY1 * qX1 + dqZ1 * qW1;
  32438. qW1 = dqW1 * qW1 - dqX1 * qX1 - dqY1 * qY1 - dqZ1 * qZ1;
  32439. let l1 = qX1 * qX1 + qY1 * qY1 + qZ1 * qZ1 + qW1 * qW1;
  32440. if(l1 > 1e-32) {
  32441. l1 = 1 / Math.sqrt(l1);
  32442. }
  32443. qX1 *= l1;
  32444. qY1 *= l1;
  32445. qZ1 *= l1;
  32446. qW1 *= l1;
  32447. let x1 = qX1;
  32448. let y1 = qY1;
  32449. let z1 = qZ1;
  32450. let w1 = qW1;
  32451. let x21 = 2 * x1;
  32452. let y21 = 2 * y1;
  32453. let z21 = 2 * z1;
  32454. let xx1 = x1 * x21;
  32455. let yy1 = y1 * y21;
  32456. let zz1 = z1 * z21;
  32457. let xy1 = x1 * y21;
  32458. let yz1 = y1 * z21;
  32459. let xz1 = x1 * z21;
  32460. let wx1 = w1 * x21;
  32461. let wy1 = w1 * y21;
  32462. let wz1 = w1 * z21;
  32463. _this3._transform._rotation00 = 1 - yy1 - zz1;
  32464. _this3._transform._rotation01 = xy1 - wz1;
  32465. _this3._transform._rotation02 = xz1 + wy1;
  32466. _this3._transform._rotation10 = xy1 + wz1;
  32467. _this3._transform._rotation11 = 1 - xx1 - zz1;
  32468. _this3._transform._rotation12 = yz1 - wx1;
  32469. _this3._transform._rotation20 = xz1 - wy1;
  32470. _this3._transform._rotation21 = yz1 + wx1;
  32471. _this3._transform._rotation22 = 1 - xx1 - yy1;
  32472. let __tmp__002;
  32473. let __tmp__012;
  32474. let __tmp__022;
  32475. let __tmp__102;
  32476. let __tmp__112;
  32477. let __tmp__122;
  32478. let __tmp__202;
  32479. let __tmp__212;
  32480. let __tmp__222;
  32481. __tmp__002 = _this3._transform._rotation00 * _this3._invLocalInertia00 + _this3._transform._rotation01 * _this3._invLocalInertia10 + _this3._transform._rotation02 * _this3._invLocalInertia20;
  32482. __tmp__012 = _this3._transform._rotation00 * _this3._invLocalInertia01 + _this3._transform._rotation01 * _this3._invLocalInertia11 + _this3._transform._rotation02 * _this3._invLocalInertia21;
  32483. __tmp__022 = _this3._transform._rotation00 * _this3._invLocalInertia02 + _this3._transform._rotation01 * _this3._invLocalInertia12 + _this3._transform._rotation02 * _this3._invLocalInertia22;
  32484. __tmp__102 = _this3._transform._rotation10 * _this3._invLocalInertia00 + _this3._transform._rotation11 * _this3._invLocalInertia10 + _this3._transform._rotation12 * _this3._invLocalInertia20;
  32485. __tmp__112 = _this3._transform._rotation10 * _this3._invLocalInertia01 + _this3._transform._rotation11 * _this3._invLocalInertia11 + _this3._transform._rotation12 * _this3._invLocalInertia21;
  32486. __tmp__122 = _this3._transform._rotation10 * _this3._invLocalInertia02 + _this3._transform._rotation11 * _this3._invLocalInertia12 + _this3._transform._rotation12 * _this3._invLocalInertia22;
  32487. __tmp__202 = _this3._transform._rotation20 * _this3._invLocalInertia00 + _this3._transform._rotation21 * _this3._invLocalInertia10 + _this3._transform._rotation22 * _this3._invLocalInertia20;
  32488. __tmp__212 = _this3._transform._rotation20 * _this3._invLocalInertia01 + _this3._transform._rotation21 * _this3._invLocalInertia11 + _this3._transform._rotation22 * _this3._invLocalInertia21;
  32489. __tmp__222 = _this3._transform._rotation20 * _this3._invLocalInertia02 + _this3._transform._rotation21 * _this3._invLocalInertia12 + _this3._transform._rotation22 * _this3._invLocalInertia22;
  32490. _this3._invInertia00 = __tmp__002;
  32491. _this3._invInertia01 = __tmp__012;
  32492. _this3._invInertia02 = __tmp__022;
  32493. _this3._invInertia10 = __tmp__102;
  32494. _this3._invInertia11 = __tmp__112;
  32495. _this3._invInertia12 = __tmp__122;
  32496. _this3._invInertia20 = __tmp__202;
  32497. _this3._invInertia21 = __tmp__212;
  32498. _this3._invInertia22 = __tmp__222;
  32499. let __tmp__003;
  32500. let __tmp__013;
  32501. let __tmp__023;
  32502. let __tmp__103;
  32503. let __tmp__113;
  32504. let __tmp__123;
  32505. let __tmp__203;
  32506. let __tmp__213;
  32507. let __tmp__223;
  32508. __tmp__003 = _this3._invInertia00 * _this3._transform._rotation00 + _this3._invInertia01 * _this3._transform._rotation01 + _this3._invInertia02 * _this3._transform._rotation02;
  32509. __tmp__013 = _this3._invInertia00 * _this3._transform._rotation10 + _this3._invInertia01 * _this3._transform._rotation11 + _this3._invInertia02 * _this3._transform._rotation12;
  32510. __tmp__023 = _this3._invInertia00 * _this3._transform._rotation20 + _this3._invInertia01 * _this3._transform._rotation21 + _this3._invInertia02 * _this3._transform._rotation22;
  32511. __tmp__103 = _this3._invInertia10 * _this3._transform._rotation00 + _this3._invInertia11 * _this3._transform._rotation01 + _this3._invInertia12 * _this3._transform._rotation02;
  32512. __tmp__113 = _this3._invInertia10 * _this3._transform._rotation10 + _this3._invInertia11 * _this3._transform._rotation11 + _this3._invInertia12 * _this3._transform._rotation12;
  32513. __tmp__123 = _this3._invInertia10 * _this3._transform._rotation20 + _this3._invInertia11 * _this3._transform._rotation21 + _this3._invInertia12 * _this3._transform._rotation22;
  32514. __tmp__203 = _this3._invInertia20 * _this3._transform._rotation00 + _this3._invInertia21 * _this3._transform._rotation01 + _this3._invInertia22 * _this3._transform._rotation02;
  32515. __tmp__213 = _this3._invInertia20 * _this3._transform._rotation10 + _this3._invInertia21 * _this3._transform._rotation11 + _this3._invInertia22 * _this3._transform._rotation12;
  32516. __tmp__223 = _this3._invInertia20 * _this3._transform._rotation20 + _this3._invInertia21 * _this3._transform._rotation21 + _this3._invInertia22 * _this3._transform._rotation22;
  32517. _this3._invInertia00 = __tmp__003;
  32518. _this3._invInertia01 = __tmp__013;
  32519. _this3._invInertia02 = __tmp__023;
  32520. _this3._invInertia10 = __tmp__103;
  32521. _this3._invInertia11 = __tmp__113;
  32522. _this3._invInertia12 = __tmp__123;
  32523. _this3._invInertia20 = __tmp__203;
  32524. _this3._invInertia21 = __tmp__213;
  32525. _this3._invInertia22 = __tmp__223;
  32526. _this3._invInertia00 *= _this3._rotFactor.x;
  32527. _this3._invInertia01 *= _this3._rotFactor.x;
  32528. _this3._invInertia02 *= _this3._rotFactor.x;
  32529. _this3._invInertia10 *= _this3._rotFactor.y;
  32530. _this3._invInertia11 *= _this3._rotFactor.y;
  32531. _this3._invInertia12 *= _this3._rotFactor.y;
  32532. _this3._invInertia20 *= _this3._rotFactor.z;
  32533. _this3._invInertia21 *= _this3._rotFactor.z;
  32534. _this3._invInertia22 *= _this3._rotFactor.z;
  32535. }
  32536. postSolve() {
  32537. this.joint._syncAnchors();
  32538. this.joint._checkDestruction();
  32539. }
  32540. }
  32541. if(!oimo.dynamics.rigidbody) oimo.dynamics.rigidbody = {};
  32542. oimo.dynamics.rigidbody.MassData = class oimo_dynamics_rigidbody_MassData {
  32543. constructor() {
  32544. this.mass = 0;
  32545. this.localInertia = new oimo.common.Mat3();
  32546. }
  32547. }
  32548. oimo.dynamics.rigidbody.RigidBody = class oimo_dynamics_rigidbody_RigidBody {
  32549. constructor(config) {
  32550. this._next = null;
  32551. this._prev = null;
  32552. this._shapeList = null;
  32553. this._shapeListLast = null;
  32554. this._numShapes = 0;
  32555. this._contactLinkList = null;
  32556. this._contactLinkListLast = null;
  32557. this._numContactLinks = 0;
  32558. this._jointLinkList = null;
  32559. this._jointLinkListLast = null;
  32560. this._numJointLinks = 0;
  32561. let v = config.linearVelocity;
  32562. this._velX = v.x;
  32563. this._velY = v.y;
  32564. this._velZ = v.z;
  32565. let v1 = config.angularVelocity;
  32566. this._angVelX = v1.x;
  32567. this._angVelY = v1.y;
  32568. this._angVelZ = v1.z;
  32569. this._pseudoVelX = 0;
  32570. this._pseudoVelY = 0;
  32571. this._pseudoVelZ = 0;
  32572. this._angPseudoVelX = 0;
  32573. this._angPseudoVelY = 0;
  32574. this._angPseudoVelZ = 0;
  32575. this._ptransform = new oimo.common.Transform();
  32576. this._transform = new oimo.common.Transform();
  32577. let v2 = config.position;
  32578. this._ptransform._positionX = v2.x;
  32579. this._ptransform._positionY = v2.y;
  32580. this._ptransform._positionZ = v2.z;
  32581. let m = config.rotation;
  32582. this._ptransform._rotation00 = m.e00;
  32583. this._ptransform._rotation01 = m.e01;
  32584. this._ptransform._rotation02 = m.e02;
  32585. this._ptransform._rotation10 = m.e10;
  32586. this._ptransform._rotation11 = m.e11;
  32587. this._ptransform._rotation12 = m.e12;
  32588. this._ptransform._rotation20 = m.e20;
  32589. this._ptransform._rotation21 = m.e21;
  32590. this._ptransform._rotation22 = m.e22;
  32591. let dst = this._transform;
  32592. let src = this._ptransform;
  32593. dst._positionX = src._positionX;
  32594. dst._positionY = src._positionY;
  32595. dst._positionZ = src._positionZ;
  32596. dst._rotation00 = src._rotation00;
  32597. dst._rotation01 = src._rotation01;
  32598. dst._rotation02 = src._rotation02;
  32599. dst._rotation10 = src._rotation10;
  32600. dst._rotation11 = src._rotation11;
  32601. dst._rotation12 = src._rotation12;
  32602. dst._rotation20 = src._rotation20;
  32603. dst._rotation21 = src._rotation21;
  32604. dst._rotation22 = src._rotation22;
  32605. this._type = config.type;
  32606. this._sleepTime = 0;
  32607. this._sleeping = false;
  32608. this._autoSleep = config.autoSleep;
  32609. this._mass = 0;
  32610. this._invMass = 0;
  32611. this._localInertia00 = 0;
  32612. this._localInertia01 = 0;
  32613. this._localInertia02 = 0;
  32614. this._localInertia10 = 0;
  32615. this._localInertia11 = 0;
  32616. this._localInertia12 = 0;
  32617. this._localInertia20 = 0;
  32618. this._localInertia21 = 0;
  32619. this._localInertia22 = 0;
  32620. this._invLocalInertia00 = 0;
  32621. this._invLocalInertia01 = 0;
  32622. this._invLocalInertia02 = 0;
  32623. this._invLocalInertia10 = 0;
  32624. this._invLocalInertia11 = 0;
  32625. this._invLocalInertia12 = 0;
  32626. this._invLocalInertia20 = 0;
  32627. this._invLocalInertia21 = 0;
  32628. this._invLocalInertia22 = 0;
  32629. this._invLocalInertiaWithoutRotFactor00 = 0;
  32630. this._invLocalInertiaWithoutRotFactor01 = 0;
  32631. this._invLocalInertiaWithoutRotFactor02 = 0;
  32632. this._invLocalInertiaWithoutRotFactor10 = 0;
  32633. this._invLocalInertiaWithoutRotFactor11 = 0;
  32634. this._invLocalInertiaWithoutRotFactor12 = 0;
  32635. this._invLocalInertiaWithoutRotFactor20 = 0;
  32636. this._invLocalInertiaWithoutRotFactor21 = 0;
  32637. this._invLocalInertiaWithoutRotFactor22 = 0;
  32638. this._invInertia00 = 0;
  32639. this._invInertia01 = 0;
  32640. this._invInertia02 = 0;
  32641. this._invInertia10 = 0;
  32642. this._invInertia11 = 0;
  32643. this._invInertia12 = 0;
  32644. this._invInertia20 = 0;
  32645. this._invInertia21 = 0;
  32646. this._invInertia22 = 0;
  32647. this._linearDamping = config.linearDamping;
  32648. this._angularDamping = config.angularDamping;
  32649. this._forceX = 0;
  32650. this._forceY = 0;
  32651. this._forceZ = 0;
  32652. this._torqueX = 0;
  32653. this._torqueY = 0;
  32654. this._torqueZ = 0;
  32655. this._linearContactImpulseX = 0;
  32656. this._linearContactImpulseY = 0;
  32657. this._linearContactImpulseZ = 0;
  32658. this._angularContactImpulseX = 0;
  32659. this._angularContactImpulseY = 0;
  32660. this._angularContactImpulseZ = 0;
  32661. this._rotFactor = new oimo.common.Vec3(1,1,1);
  32662. this._addedToIsland = false;
  32663. this._gravityScale = 1;
  32664. this._world = null;
  32665. }
  32666. _integrate(dt) {
  32667. switch(this._type) {
  32668. case 1:
  32669. this._velX = 0;
  32670. this._velY = 0;
  32671. this._velZ = 0;
  32672. this._angVelX = 0;
  32673. this._angVelY = 0;
  32674. this._angVelZ = 0;
  32675. this._pseudoVelX = 0;
  32676. this._pseudoVelY = 0;
  32677. this._pseudoVelZ = 0;
  32678. this._angPseudoVelX = 0;
  32679. this._angPseudoVelY = 0;
  32680. this._angPseudoVelZ = 0;
  32681. break;
  32682. case 0:case 2:
  32683. let translationX;
  32684. let translationY;
  32685. let translationZ;
  32686. let rotationX;
  32687. let rotationY;
  32688. let rotationZ;
  32689. translationX = this._velX * dt;
  32690. translationY = this._velY * dt;
  32691. translationZ = this._velZ * dt;
  32692. rotationX = this._angVelX * dt;
  32693. rotationY = this._angVelY * dt;
  32694. rotationZ = this._angVelZ * dt;
  32695. let translationLengthSq = translationX * translationX + translationY * translationY + translationZ * translationZ;
  32696. let rotationLengthSq = rotationX * rotationX + rotationY * rotationY + rotationZ * rotationZ;
  32697. if(translationLengthSq == 0 && rotationLengthSq == 0) {
  32698. return;
  32699. }
  32700. if(translationLengthSq > oimo.common.Setting.maxTranslationPerStep * oimo.common.Setting.maxTranslationPerStep) {
  32701. let l = oimo.common.Setting.maxTranslationPerStep / Math.sqrt(translationLengthSq);
  32702. this._velX *= l;
  32703. this._velY *= l;
  32704. this._velZ *= l;
  32705. translationX *= l;
  32706. translationY *= l;
  32707. translationZ *= l;
  32708. }
  32709. if(rotationLengthSq > oimo.common.Setting.maxRotationPerStep * oimo.common.Setting.maxRotationPerStep) {
  32710. let l = oimo.common.Setting.maxRotationPerStep / Math.sqrt(rotationLengthSq);
  32711. this._angVelX *= l;
  32712. this._angVelY *= l;
  32713. this._angVelZ *= l;
  32714. rotationX *= l;
  32715. rotationY *= l;
  32716. rotationZ *= l;
  32717. }
  32718. this._transform._positionX += translationX;
  32719. this._transform._positionY += translationY;
  32720. this._transform._positionZ += translationZ;
  32721. let theta = Math.sqrt(rotationX * rotationX + rotationY * rotationY + rotationZ * rotationZ);
  32722. let halfTheta = theta * 0.5;
  32723. let rotationToSinAxisFactor;
  32724. let cosHalfTheta;
  32725. if(halfTheta < 0.5) {
  32726. let ht2 = halfTheta * halfTheta;
  32727. rotationToSinAxisFactor = 0.5 * (1 - ht2 * 0.16666666666666666 + ht2 * ht2 * 0.0083333333333333332);
  32728. cosHalfTheta = 1 - ht2 * 0.5 + ht2 * ht2 * 0.041666666666666664;
  32729. } else {
  32730. rotationToSinAxisFactor = Math.sin(halfTheta) / theta;
  32731. cosHalfTheta = Math.cos(halfTheta);
  32732. }
  32733. let sinAxisX;
  32734. let sinAxisY;
  32735. let sinAxisZ;
  32736. sinAxisX = rotationX * rotationToSinAxisFactor;
  32737. sinAxisY = rotationY * rotationToSinAxisFactor;
  32738. sinAxisZ = rotationZ * rotationToSinAxisFactor;
  32739. let dqX;
  32740. let dqY;
  32741. let dqZ;
  32742. let dqW;
  32743. dqX = sinAxisX;
  32744. dqY = sinAxisY;
  32745. dqZ = sinAxisZ;
  32746. dqW = cosHalfTheta;
  32747. let qX;
  32748. let qY;
  32749. let qZ;
  32750. let qW;
  32751. let e00 = this._transform._rotation00;
  32752. let e11 = this._transform._rotation11;
  32753. let e22 = this._transform._rotation22;
  32754. let t = e00 + e11 + e22;
  32755. let s;
  32756. if(t > 0) {
  32757. s = Math.sqrt(t + 1);
  32758. qW = 0.5 * s;
  32759. s = 0.5 / s;
  32760. qX = (this._transform._rotation21 - this._transform._rotation12) * s;
  32761. qY = (this._transform._rotation02 - this._transform._rotation20) * s;
  32762. qZ = (this._transform._rotation10 - this._transform._rotation01) * s;
  32763. } else if(e00 > e11) {
  32764. if(e00 > e22) {
  32765. s = Math.sqrt(e00 - e11 - e22 + 1);
  32766. qX = 0.5 * s;
  32767. s = 0.5 / s;
  32768. qY = (this._transform._rotation01 + this._transform._rotation10) * s;
  32769. qZ = (this._transform._rotation02 + this._transform._rotation20) * s;
  32770. qW = (this._transform._rotation21 - this._transform._rotation12) * s;
  32771. } else {
  32772. s = Math.sqrt(e22 - e00 - e11 + 1);
  32773. qZ = 0.5 * s;
  32774. s = 0.5 / s;
  32775. qX = (this._transform._rotation02 + this._transform._rotation20) * s;
  32776. qY = (this._transform._rotation12 + this._transform._rotation21) * s;
  32777. qW = (this._transform._rotation10 - this._transform._rotation01) * s;
  32778. }
  32779. } else if(e11 > e22) {
  32780. s = Math.sqrt(e11 - e22 - e00 + 1);
  32781. qY = 0.5 * s;
  32782. s = 0.5 / s;
  32783. qX = (this._transform._rotation01 + this._transform._rotation10) * s;
  32784. qZ = (this._transform._rotation12 + this._transform._rotation21) * s;
  32785. qW = (this._transform._rotation02 - this._transform._rotation20) * s;
  32786. } else {
  32787. s = Math.sqrt(e22 - e00 - e11 + 1);
  32788. qZ = 0.5 * s;
  32789. s = 0.5 / s;
  32790. qX = (this._transform._rotation02 + this._transform._rotation20) * s;
  32791. qY = (this._transform._rotation12 + this._transform._rotation21) * s;
  32792. qW = (this._transform._rotation10 - this._transform._rotation01) * s;
  32793. }
  32794. qX = dqW * qX + dqX * qW + dqY * qZ - dqZ * qY;
  32795. qY = dqW * qY - dqX * qZ + dqY * qW + dqZ * qX;
  32796. qZ = dqW * qZ + dqX * qY - dqY * qX + dqZ * qW;
  32797. qW = dqW * qW - dqX * qX - dqY * qY - dqZ * qZ;
  32798. let l = qX * qX + qY * qY + qZ * qZ + qW * qW;
  32799. if(l > 1e-32) {
  32800. l = 1 / Math.sqrt(l);
  32801. }
  32802. qX *= l;
  32803. qY *= l;
  32804. qZ *= l;
  32805. qW *= l;
  32806. let x = qX;
  32807. let y = qY;
  32808. let z = qZ;
  32809. let w = qW;
  32810. let x2 = 2 * x;
  32811. let y2 = 2 * y;
  32812. let z2 = 2 * z;
  32813. let xx = x * x2;
  32814. let yy = y * y2;
  32815. let zz = z * z2;
  32816. let xy = x * y2;
  32817. let yz = y * z2;
  32818. let xz = x * z2;
  32819. let wx = w * x2;
  32820. let wy = w * y2;
  32821. let wz = w * z2;
  32822. this._transform._rotation00 = 1 - yy - zz;
  32823. this._transform._rotation01 = xy - wz;
  32824. this._transform._rotation02 = xz + wy;
  32825. this._transform._rotation10 = xy + wz;
  32826. this._transform._rotation11 = 1 - xx - zz;
  32827. this._transform._rotation12 = yz - wx;
  32828. this._transform._rotation20 = xz - wy;
  32829. this._transform._rotation21 = yz + wx;
  32830. this._transform._rotation22 = 1 - xx - yy;
  32831. let __tmp__00;
  32832. let __tmp__01;
  32833. let __tmp__02;
  32834. let __tmp__10;
  32835. let __tmp__11;
  32836. let __tmp__12;
  32837. let __tmp__20;
  32838. let __tmp__21;
  32839. let __tmp__22;
  32840. __tmp__00 = this._transform._rotation00 * this._invLocalInertia00 + this._transform._rotation01 * this._invLocalInertia10 + this._transform._rotation02 * this._invLocalInertia20;
  32841. __tmp__01 = this._transform._rotation00 * this._invLocalInertia01 + this._transform._rotation01 * this._invLocalInertia11 + this._transform._rotation02 * this._invLocalInertia21;
  32842. __tmp__02 = this._transform._rotation00 * this._invLocalInertia02 + this._transform._rotation01 * this._invLocalInertia12 + this._transform._rotation02 * this._invLocalInertia22;
  32843. __tmp__10 = this._transform._rotation10 * this._invLocalInertia00 + this._transform._rotation11 * this._invLocalInertia10 + this._transform._rotation12 * this._invLocalInertia20;
  32844. __tmp__11 = this._transform._rotation10 * this._invLocalInertia01 + this._transform._rotation11 * this._invLocalInertia11 + this._transform._rotation12 * this._invLocalInertia21;
  32845. __tmp__12 = this._transform._rotation10 * this._invLocalInertia02 + this._transform._rotation11 * this._invLocalInertia12 + this._transform._rotation12 * this._invLocalInertia22;
  32846. __tmp__20 = this._transform._rotation20 * this._invLocalInertia00 + this._transform._rotation21 * this._invLocalInertia10 + this._transform._rotation22 * this._invLocalInertia20;
  32847. __tmp__21 = this._transform._rotation20 * this._invLocalInertia01 + this._transform._rotation21 * this._invLocalInertia11 + this._transform._rotation22 * this._invLocalInertia21;
  32848. __tmp__22 = this._transform._rotation20 * this._invLocalInertia02 + this._transform._rotation21 * this._invLocalInertia12 + this._transform._rotation22 * this._invLocalInertia22;
  32849. this._invInertia00 = __tmp__00;
  32850. this._invInertia01 = __tmp__01;
  32851. this._invInertia02 = __tmp__02;
  32852. this._invInertia10 = __tmp__10;
  32853. this._invInertia11 = __tmp__11;
  32854. this._invInertia12 = __tmp__12;
  32855. this._invInertia20 = __tmp__20;
  32856. this._invInertia21 = __tmp__21;
  32857. this._invInertia22 = __tmp__22;
  32858. let __tmp__001;
  32859. let __tmp__011;
  32860. let __tmp__021;
  32861. let __tmp__101;
  32862. let __tmp__111;
  32863. let __tmp__121;
  32864. let __tmp__201;
  32865. let __tmp__211;
  32866. let __tmp__221;
  32867. __tmp__001 = this._invInertia00 * this._transform._rotation00 + this._invInertia01 * this._transform._rotation01 + this._invInertia02 * this._transform._rotation02;
  32868. __tmp__011 = this._invInertia00 * this._transform._rotation10 + this._invInertia01 * this._transform._rotation11 + this._invInertia02 * this._transform._rotation12;
  32869. __tmp__021 = this._invInertia00 * this._transform._rotation20 + this._invInertia01 * this._transform._rotation21 + this._invInertia02 * this._transform._rotation22;
  32870. __tmp__101 = this._invInertia10 * this._transform._rotation00 + this._invInertia11 * this._transform._rotation01 + this._invInertia12 * this._transform._rotation02;
  32871. __tmp__111 = this._invInertia10 * this._transform._rotation10 + this._invInertia11 * this._transform._rotation11 + this._invInertia12 * this._transform._rotation12;
  32872. __tmp__121 = this._invInertia10 * this._transform._rotation20 + this._invInertia11 * this._transform._rotation21 + this._invInertia12 * this._transform._rotation22;
  32873. __tmp__201 = this._invInertia20 * this._transform._rotation00 + this._invInertia21 * this._transform._rotation01 + this._invInertia22 * this._transform._rotation02;
  32874. __tmp__211 = this._invInertia20 * this._transform._rotation10 + this._invInertia21 * this._transform._rotation11 + this._invInertia22 * this._transform._rotation12;
  32875. __tmp__221 = this._invInertia20 * this._transform._rotation20 + this._invInertia21 * this._transform._rotation21 + this._invInertia22 * this._transform._rotation22;
  32876. this._invInertia00 = __tmp__001;
  32877. this._invInertia01 = __tmp__011;
  32878. this._invInertia02 = __tmp__021;
  32879. this._invInertia10 = __tmp__101;
  32880. this._invInertia11 = __tmp__111;
  32881. this._invInertia12 = __tmp__121;
  32882. this._invInertia20 = __tmp__201;
  32883. this._invInertia21 = __tmp__211;
  32884. this._invInertia22 = __tmp__221;
  32885. this._invInertia00 *= this._rotFactor.x;
  32886. this._invInertia01 *= this._rotFactor.x;
  32887. this._invInertia02 *= this._rotFactor.x;
  32888. this._invInertia10 *= this._rotFactor.y;
  32889. this._invInertia11 *= this._rotFactor.y;
  32890. this._invInertia12 *= this._rotFactor.y;
  32891. this._invInertia20 *= this._rotFactor.z;
  32892. this._invInertia21 *= this._rotFactor.z;
  32893. this._invInertia22 *= this._rotFactor.z;
  32894. break;
  32895. }
  32896. }
  32897. _integratePseudoVelocity() {
  32898. if(this._pseudoVelX * this._pseudoVelX + this._pseudoVelY * this._pseudoVelY + this._pseudoVelZ * this._pseudoVelZ == 0 && this._angPseudoVelX * this._angPseudoVelX + this._angPseudoVelY * this._angPseudoVelY + this._angPseudoVelZ * this._angPseudoVelZ == 0) {
  32899. return;
  32900. }
  32901. switch(this._type) {
  32902. case 1:
  32903. this._pseudoVelX = 0;
  32904. this._pseudoVelY = 0;
  32905. this._pseudoVelZ = 0;
  32906. this._angPseudoVelX = 0;
  32907. this._angPseudoVelY = 0;
  32908. this._angPseudoVelZ = 0;
  32909. break;
  32910. case 0:case 2:
  32911. let translationX;
  32912. let translationY;
  32913. let translationZ;
  32914. let rotationX;
  32915. let rotationY;
  32916. let rotationZ;
  32917. translationX = this._pseudoVelX;
  32918. translationY = this._pseudoVelY;
  32919. translationZ = this._pseudoVelZ;
  32920. rotationX = this._angPseudoVelX;
  32921. rotationY = this._angPseudoVelY;
  32922. rotationZ = this._angPseudoVelZ;
  32923. this._pseudoVelX = 0;
  32924. this._pseudoVelY = 0;
  32925. this._pseudoVelZ = 0;
  32926. this._angPseudoVelX = 0;
  32927. this._angPseudoVelY = 0;
  32928. this._angPseudoVelZ = 0;
  32929. this._transform._positionX += translationX;
  32930. this._transform._positionY += translationY;
  32931. this._transform._positionZ += translationZ;
  32932. let theta = Math.sqrt(rotationX * rotationX + rotationY * rotationY + rotationZ * rotationZ);
  32933. let halfTheta = theta * 0.5;
  32934. let rotationToSinAxisFactor;
  32935. let cosHalfTheta;
  32936. if(halfTheta < 0.5) {
  32937. let ht2 = halfTheta * halfTheta;
  32938. rotationToSinAxisFactor = 0.5 * (1 - ht2 * 0.16666666666666666 + ht2 * ht2 * 0.0083333333333333332);
  32939. cosHalfTheta = 1 - ht2 * 0.5 + ht2 * ht2 * 0.041666666666666664;
  32940. } else {
  32941. rotationToSinAxisFactor = Math.sin(halfTheta) / theta;
  32942. cosHalfTheta = Math.cos(halfTheta);
  32943. }
  32944. let sinAxisX;
  32945. let sinAxisY;
  32946. let sinAxisZ;
  32947. sinAxisX = rotationX * rotationToSinAxisFactor;
  32948. sinAxisY = rotationY * rotationToSinAxisFactor;
  32949. sinAxisZ = rotationZ * rotationToSinAxisFactor;
  32950. let dqX;
  32951. let dqY;
  32952. let dqZ;
  32953. let dqW;
  32954. dqX = sinAxisX;
  32955. dqY = sinAxisY;
  32956. dqZ = sinAxisZ;
  32957. dqW = cosHalfTheta;
  32958. let qX;
  32959. let qY;
  32960. let qZ;
  32961. let qW;
  32962. let e00 = this._transform._rotation00;
  32963. let e11 = this._transform._rotation11;
  32964. let e22 = this._transform._rotation22;
  32965. let t = e00 + e11 + e22;
  32966. let s;
  32967. if(t > 0) {
  32968. s = Math.sqrt(t + 1);
  32969. qW = 0.5 * s;
  32970. s = 0.5 / s;
  32971. qX = (this._transform._rotation21 - this._transform._rotation12) * s;
  32972. qY = (this._transform._rotation02 - this._transform._rotation20) * s;
  32973. qZ = (this._transform._rotation10 - this._transform._rotation01) * s;
  32974. } else if(e00 > e11) {
  32975. if(e00 > e22) {
  32976. s = Math.sqrt(e00 - e11 - e22 + 1);
  32977. qX = 0.5 * s;
  32978. s = 0.5 / s;
  32979. qY = (this._transform._rotation01 + this._transform._rotation10) * s;
  32980. qZ = (this._transform._rotation02 + this._transform._rotation20) * s;
  32981. qW = (this._transform._rotation21 - this._transform._rotation12) * s;
  32982. } else {
  32983. s = Math.sqrt(e22 - e00 - e11 + 1);
  32984. qZ = 0.5 * s;
  32985. s = 0.5 / s;
  32986. qX = (this._transform._rotation02 + this._transform._rotation20) * s;
  32987. qY = (this._transform._rotation12 + this._transform._rotation21) * s;
  32988. qW = (this._transform._rotation10 - this._transform._rotation01) * s;
  32989. }
  32990. } else if(e11 > e22) {
  32991. s = Math.sqrt(e11 - e22 - e00 + 1);
  32992. qY = 0.5 * s;
  32993. s = 0.5 / s;
  32994. qX = (this._transform._rotation01 + this._transform._rotation10) * s;
  32995. qZ = (this._transform._rotation12 + this._transform._rotation21) * s;
  32996. qW = (this._transform._rotation02 - this._transform._rotation20) * s;
  32997. } else {
  32998. s = Math.sqrt(e22 - e00 - e11 + 1);
  32999. qZ = 0.5 * s;
  33000. s = 0.5 / s;
  33001. qX = (this._transform._rotation02 + this._transform._rotation20) * s;
  33002. qY = (this._transform._rotation12 + this._transform._rotation21) * s;
  33003. qW = (this._transform._rotation10 - this._transform._rotation01) * s;
  33004. }
  33005. qX = dqW * qX + dqX * qW + dqY * qZ - dqZ * qY;
  33006. qY = dqW * qY - dqX * qZ + dqY * qW + dqZ * qX;
  33007. qZ = dqW * qZ + dqX * qY - dqY * qX + dqZ * qW;
  33008. qW = dqW * qW - dqX * qX - dqY * qY - dqZ * qZ;
  33009. let l = qX * qX + qY * qY + qZ * qZ + qW * qW;
  33010. if(l > 1e-32) {
  33011. l = 1 / Math.sqrt(l);
  33012. }
  33013. qX *= l;
  33014. qY *= l;
  33015. qZ *= l;
  33016. qW *= l;
  33017. let x = qX;
  33018. let y = qY;
  33019. let z = qZ;
  33020. let w = qW;
  33021. let x2 = 2 * x;
  33022. let y2 = 2 * y;
  33023. let z2 = 2 * z;
  33024. let xx = x * x2;
  33025. let yy = y * y2;
  33026. let zz = z * z2;
  33027. let xy = x * y2;
  33028. let yz = y * z2;
  33029. let xz = x * z2;
  33030. let wx = w * x2;
  33031. let wy = w * y2;
  33032. let wz = w * z2;
  33033. this._transform._rotation00 = 1 - yy - zz;
  33034. this._transform._rotation01 = xy - wz;
  33035. this._transform._rotation02 = xz + wy;
  33036. this._transform._rotation10 = xy + wz;
  33037. this._transform._rotation11 = 1 - xx - zz;
  33038. this._transform._rotation12 = yz - wx;
  33039. this._transform._rotation20 = xz - wy;
  33040. this._transform._rotation21 = yz + wx;
  33041. this._transform._rotation22 = 1 - xx - yy;
  33042. let __tmp__00;
  33043. let __tmp__01;
  33044. let __tmp__02;
  33045. let __tmp__10;
  33046. let __tmp__11;
  33047. let __tmp__12;
  33048. let __tmp__20;
  33049. let __tmp__21;
  33050. let __tmp__22;
  33051. __tmp__00 = this._transform._rotation00 * this._invLocalInertia00 + this._transform._rotation01 * this._invLocalInertia10 + this._transform._rotation02 * this._invLocalInertia20;
  33052. __tmp__01 = this._transform._rotation00 * this._invLocalInertia01 + this._transform._rotation01 * this._invLocalInertia11 + this._transform._rotation02 * this._invLocalInertia21;
  33053. __tmp__02 = this._transform._rotation00 * this._invLocalInertia02 + this._transform._rotation01 * this._invLocalInertia12 + this._transform._rotation02 * this._invLocalInertia22;
  33054. __tmp__10 = this._transform._rotation10 * this._invLocalInertia00 + this._transform._rotation11 * this._invLocalInertia10 + this._transform._rotation12 * this._invLocalInertia20;
  33055. __tmp__11 = this._transform._rotation10 * this._invLocalInertia01 + this._transform._rotation11 * this._invLocalInertia11 + this._transform._rotation12 * this._invLocalInertia21;
  33056. __tmp__12 = this._transform._rotation10 * this._invLocalInertia02 + this._transform._rotation11 * this._invLocalInertia12 + this._transform._rotation12 * this._invLocalInertia22;
  33057. __tmp__20 = this._transform._rotation20 * this._invLocalInertia00 + this._transform._rotation21 * this._invLocalInertia10 + this._transform._rotation22 * this._invLocalInertia20;
  33058. __tmp__21 = this._transform._rotation20 * this._invLocalInertia01 + this._transform._rotation21 * this._invLocalInertia11 + this._transform._rotation22 * this._invLocalInertia21;
  33059. __tmp__22 = this._transform._rotation20 * this._invLocalInertia02 + this._transform._rotation21 * this._invLocalInertia12 + this._transform._rotation22 * this._invLocalInertia22;
  33060. this._invInertia00 = __tmp__00;
  33061. this._invInertia01 = __tmp__01;
  33062. this._invInertia02 = __tmp__02;
  33063. this._invInertia10 = __tmp__10;
  33064. this._invInertia11 = __tmp__11;
  33065. this._invInertia12 = __tmp__12;
  33066. this._invInertia20 = __tmp__20;
  33067. this._invInertia21 = __tmp__21;
  33068. this._invInertia22 = __tmp__22;
  33069. let __tmp__001;
  33070. let __tmp__011;
  33071. let __tmp__021;
  33072. let __tmp__101;
  33073. let __tmp__111;
  33074. let __tmp__121;
  33075. let __tmp__201;
  33076. let __tmp__211;
  33077. let __tmp__221;
  33078. __tmp__001 = this._invInertia00 * this._transform._rotation00 + this._invInertia01 * this._transform._rotation01 + this._invInertia02 * this._transform._rotation02;
  33079. __tmp__011 = this._invInertia00 * this._transform._rotation10 + this._invInertia01 * this._transform._rotation11 + this._invInertia02 * this._transform._rotation12;
  33080. __tmp__021 = this._invInertia00 * this._transform._rotation20 + this._invInertia01 * this._transform._rotation21 + this._invInertia02 * this._transform._rotation22;
  33081. __tmp__101 = this._invInertia10 * this._transform._rotation00 + this._invInertia11 * this._transform._rotation01 + this._invInertia12 * this._transform._rotation02;
  33082. __tmp__111 = this._invInertia10 * this._transform._rotation10 + this._invInertia11 * this._transform._rotation11 + this._invInertia12 * this._transform._rotation12;
  33083. __tmp__121 = this._invInertia10 * this._transform._rotation20 + this._invInertia11 * this._transform._rotation21 + this._invInertia12 * this._transform._rotation22;
  33084. __tmp__201 = this._invInertia20 * this._transform._rotation00 + this._invInertia21 * this._transform._rotation01 + this._invInertia22 * this._transform._rotation02;
  33085. __tmp__211 = this._invInertia20 * this._transform._rotation10 + this._invInertia21 * this._transform._rotation11 + this._invInertia22 * this._transform._rotation12;
  33086. __tmp__221 = this._invInertia20 * this._transform._rotation20 + this._invInertia21 * this._transform._rotation21 + this._invInertia22 * this._transform._rotation22;
  33087. this._invInertia00 = __tmp__001;
  33088. this._invInertia01 = __tmp__011;
  33089. this._invInertia02 = __tmp__021;
  33090. this._invInertia10 = __tmp__101;
  33091. this._invInertia11 = __tmp__111;
  33092. this._invInertia12 = __tmp__121;
  33093. this._invInertia20 = __tmp__201;
  33094. this._invInertia21 = __tmp__211;
  33095. this._invInertia22 = __tmp__221;
  33096. this._invInertia00 *= this._rotFactor.x;
  33097. this._invInertia01 *= this._rotFactor.x;
  33098. this._invInertia02 *= this._rotFactor.x;
  33099. this._invInertia10 *= this._rotFactor.y;
  33100. this._invInertia11 *= this._rotFactor.y;
  33101. this._invInertia12 *= this._rotFactor.y;
  33102. this._invInertia20 *= this._rotFactor.z;
  33103. this._invInertia21 *= this._rotFactor.z;
  33104. this._invInertia22 *= this._rotFactor.z;
  33105. break;
  33106. }
  33107. }
  33108. updateMass() {
  33109. let totalInertia00;
  33110. let totalInertia01;
  33111. let totalInertia02;
  33112. let totalInertia10;
  33113. let totalInertia11;
  33114. let totalInertia12;
  33115. let totalInertia20;
  33116. let totalInertia21;
  33117. let totalInertia22;
  33118. totalInertia00 = 0;
  33119. totalInertia01 = 0;
  33120. totalInertia02 = 0;
  33121. totalInertia10 = 0;
  33122. totalInertia11 = 0;
  33123. totalInertia12 = 0;
  33124. totalInertia20 = 0;
  33125. totalInertia21 = 0;
  33126. totalInertia22 = 0;
  33127. let totalMass = 0;
  33128. let s = this._shapeList;
  33129. while(s != null) {
  33130. let n = s._next;
  33131. let g = s._geom;
  33132. g._updateMass();
  33133. let mass = s._density * g._volume;
  33134. let inertia00;
  33135. let inertia01;
  33136. let inertia02;
  33137. let inertia10;
  33138. let inertia11;
  33139. let inertia12;
  33140. let inertia20;
  33141. let inertia21;
  33142. let inertia22;
  33143. let __tmp__00;
  33144. let __tmp__01;
  33145. let __tmp__02;
  33146. let __tmp__10;
  33147. let __tmp__11;
  33148. let __tmp__12;
  33149. let __tmp__20;
  33150. let __tmp__21;
  33151. let __tmp__22;
  33152. __tmp__00 = s._localTransform._rotation00 * g._inertiaCoeff00 + s._localTransform._rotation01 * g._inertiaCoeff10 + s._localTransform._rotation02 * g._inertiaCoeff20;
  33153. __tmp__01 = s._localTransform._rotation00 * g._inertiaCoeff01 + s._localTransform._rotation01 * g._inertiaCoeff11 + s._localTransform._rotation02 * g._inertiaCoeff21;
  33154. __tmp__02 = s._localTransform._rotation00 * g._inertiaCoeff02 + s._localTransform._rotation01 * g._inertiaCoeff12 + s._localTransform._rotation02 * g._inertiaCoeff22;
  33155. __tmp__10 = s._localTransform._rotation10 * g._inertiaCoeff00 + s._localTransform._rotation11 * g._inertiaCoeff10 + s._localTransform._rotation12 * g._inertiaCoeff20;
  33156. __tmp__11 = s._localTransform._rotation10 * g._inertiaCoeff01 + s._localTransform._rotation11 * g._inertiaCoeff11 + s._localTransform._rotation12 * g._inertiaCoeff21;
  33157. __tmp__12 = s._localTransform._rotation10 * g._inertiaCoeff02 + s._localTransform._rotation11 * g._inertiaCoeff12 + s._localTransform._rotation12 * g._inertiaCoeff22;
  33158. __tmp__20 = s._localTransform._rotation20 * g._inertiaCoeff00 + s._localTransform._rotation21 * g._inertiaCoeff10 + s._localTransform._rotation22 * g._inertiaCoeff20;
  33159. __tmp__21 = s._localTransform._rotation20 * g._inertiaCoeff01 + s._localTransform._rotation21 * g._inertiaCoeff11 + s._localTransform._rotation22 * g._inertiaCoeff21;
  33160. __tmp__22 = s._localTransform._rotation20 * g._inertiaCoeff02 + s._localTransform._rotation21 * g._inertiaCoeff12 + s._localTransform._rotation22 * g._inertiaCoeff22;
  33161. inertia00 = __tmp__00;
  33162. inertia01 = __tmp__01;
  33163. inertia02 = __tmp__02;
  33164. inertia10 = __tmp__10;
  33165. inertia11 = __tmp__11;
  33166. inertia12 = __tmp__12;
  33167. inertia20 = __tmp__20;
  33168. inertia21 = __tmp__21;
  33169. inertia22 = __tmp__22;
  33170. let __tmp__001;
  33171. let __tmp__011;
  33172. let __tmp__021;
  33173. let __tmp__101;
  33174. let __tmp__111;
  33175. let __tmp__121;
  33176. let __tmp__201;
  33177. let __tmp__211;
  33178. let __tmp__221;
  33179. __tmp__001 = inertia00 * s._localTransform._rotation00 + inertia01 * s._localTransform._rotation01 + inertia02 * s._localTransform._rotation02;
  33180. __tmp__011 = inertia00 * s._localTransform._rotation10 + inertia01 * s._localTransform._rotation11 + inertia02 * s._localTransform._rotation12;
  33181. __tmp__021 = inertia00 * s._localTransform._rotation20 + inertia01 * s._localTransform._rotation21 + inertia02 * s._localTransform._rotation22;
  33182. __tmp__101 = inertia10 * s._localTransform._rotation00 + inertia11 * s._localTransform._rotation01 + inertia12 * s._localTransform._rotation02;
  33183. __tmp__111 = inertia10 * s._localTransform._rotation10 + inertia11 * s._localTransform._rotation11 + inertia12 * s._localTransform._rotation12;
  33184. __tmp__121 = inertia10 * s._localTransform._rotation20 + inertia11 * s._localTransform._rotation21 + inertia12 * s._localTransform._rotation22;
  33185. __tmp__201 = inertia20 * s._localTransform._rotation00 + inertia21 * s._localTransform._rotation01 + inertia22 * s._localTransform._rotation02;
  33186. __tmp__211 = inertia20 * s._localTransform._rotation10 + inertia21 * s._localTransform._rotation11 + inertia22 * s._localTransform._rotation12;
  33187. __tmp__221 = inertia20 * s._localTransform._rotation20 + inertia21 * s._localTransform._rotation21 + inertia22 * s._localTransform._rotation22;
  33188. inertia00 = __tmp__001;
  33189. inertia01 = __tmp__011;
  33190. inertia02 = __tmp__021;
  33191. inertia10 = __tmp__101;
  33192. inertia11 = __tmp__111;
  33193. inertia12 = __tmp__121;
  33194. inertia20 = __tmp__201;
  33195. inertia21 = __tmp__211;
  33196. inertia22 = __tmp__221;
  33197. inertia00 *= mass;
  33198. inertia01 *= mass;
  33199. inertia02 *= mass;
  33200. inertia10 *= mass;
  33201. inertia11 *= mass;
  33202. inertia12 *= mass;
  33203. inertia20 *= mass;
  33204. inertia21 *= mass;
  33205. inertia22 *= mass;
  33206. let cogInertia00;
  33207. let cogInertia01;
  33208. let cogInertia02;
  33209. let cogInertia10;
  33210. let cogInertia11;
  33211. let cogInertia12;
  33212. let cogInertia20;
  33213. let cogInertia21;
  33214. let cogInertia22;
  33215. let xx = s._localTransform._positionX * s._localTransform._positionX;
  33216. let yy = s._localTransform._positionY * s._localTransform._positionY;
  33217. let zz = s._localTransform._positionZ * s._localTransform._positionZ;
  33218. let xy = -s._localTransform._positionX * s._localTransform._positionY;
  33219. let yz = -s._localTransform._positionY * s._localTransform._positionZ;
  33220. let zx = -s._localTransform._positionZ * s._localTransform._positionX;
  33221. cogInertia00 = yy + zz;
  33222. cogInertia01 = xy;
  33223. cogInertia02 = zx;
  33224. cogInertia10 = xy;
  33225. cogInertia11 = xx + zz;
  33226. cogInertia12 = yz;
  33227. cogInertia20 = zx;
  33228. cogInertia21 = yz;
  33229. cogInertia22 = xx + yy;
  33230. inertia00 += cogInertia00 * mass;
  33231. inertia01 += cogInertia01 * mass;
  33232. inertia02 += cogInertia02 * mass;
  33233. inertia10 += cogInertia10 * mass;
  33234. inertia11 += cogInertia11 * mass;
  33235. inertia12 += cogInertia12 * mass;
  33236. inertia20 += cogInertia20 * mass;
  33237. inertia21 += cogInertia21 * mass;
  33238. inertia22 += cogInertia22 * mass;
  33239. totalMass += mass;
  33240. totalInertia00 += inertia00;
  33241. totalInertia01 += inertia01;
  33242. totalInertia02 += inertia02;
  33243. totalInertia10 += inertia10;
  33244. totalInertia11 += inertia11;
  33245. totalInertia12 += inertia12;
  33246. totalInertia20 += inertia20;
  33247. totalInertia21 += inertia21;
  33248. totalInertia22 += inertia22;
  33249. s = n;
  33250. }
  33251. this._mass = totalMass;
  33252. this._localInertia00 = totalInertia00;
  33253. this._localInertia01 = totalInertia01;
  33254. this._localInertia02 = totalInertia02;
  33255. this._localInertia10 = totalInertia10;
  33256. this._localInertia11 = totalInertia11;
  33257. this._localInertia12 = totalInertia12;
  33258. this._localInertia20 = totalInertia20;
  33259. this._localInertia21 = totalInertia21;
  33260. this._localInertia22 = totalInertia22;
  33261. if(this._mass > 0 && this._localInertia00 * (this._localInertia11 * this._localInertia22 - this._localInertia12 * this._localInertia21) - this._localInertia01 * (this._localInertia10 * this._localInertia22 - this._localInertia12 * this._localInertia20) + this._localInertia02 * (this._localInertia10 * this._localInertia21 - this._localInertia11 * this._localInertia20) > 0 && this._type == 0) {
  33262. this._invMass = 1 / this._mass;
  33263. let d00 = this._localInertia11 * this._localInertia22 - this._localInertia12 * this._localInertia21;
  33264. let d01 = this._localInertia10 * this._localInertia22 - this._localInertia12 * this._localInertia20;
  33265. let d02 = this._localInertia10 * this._localInertia21 - this._localInertia11 * this._localInertia20;
  33266. let d = this._localInertia00 * d00 - this._localInertia01 * d01 + this._localInertia02 * d02;
  33267. if(d < -1e-32 || d > 1e-32) {
  33268. d = 1 / d;
  33269. }
  33270. this._invLocalInertia00 = d00 * d;
  33271. this._invLocalInertia01 = -(this._localInertia01 * this._localInertia22 - this._localInertia02 * this._localInertia21) * d;
  33272. this._invLocalInertia02 = (this._localInertia01 * this._localInertia12 - this._localInertia02 * this._localInertia11) * d;
  33273. this._invLocalInertia10 = -d01 * d;
  33274. this._invLocalInertia11 = (this._localInertia00 * this._localInertia22 - this._localInertia02 * this._localInertia20) * d;
  33275. this._invLocalInertia12 = -(this._localInertia00 * this._localInertia12 - this._localInertia02 * this._localInertia10) * d;
  33276. this._invLocalInertia20 = d02 * d;
  33277. this._invLocalInertia21 = -(this._localInertia00 * this._localInertia21 - this._localInertia01 * this._localInertia20) * d;
  33278. this._invLocalInertia22 = (this._localInertia00 * this._localInertia11 - this._localInertia01 * this._localInertia10) * d;
  33279. this._invLocalInertiaWithoutRotFactor00 = this._invLocalInertia00;
  33280. this._invLocalInertiaWithoutRotFactor01 = this._invLocalInertia01;
  33281. this._invLocalInertiaWithoutRotFactor02 = this._invLocalInertia02;
  33282. this._invLocalInertiaWithoutRotFactor10 = this._invLocalInertia10;
  33283. this._invLocalInertiaWithoutRotFactor11 = this._invLocalInertia11;
  33284. this._invLocalInertiaWithoutRotFactor12 = this._invLocalInertia12;
  33285. this._invLocalInertiaWithoutRotFactor20 = this._invLocalInertia20;
  33286. this._invLocalInertiaWithoutRotFactor21 = this._invLocalInertia21;
  33287. this._invLocalInertiaWithoutRotFactor22 = this._invLocalInertia22;
  33288. this._invLocalInertia00 = this._invLocalInertiaWithoutRotFactor00 * this._rotFactor.x;
  33289. this._invLocalInertia01 = this._invLocalInertiaWithoutRotFactor01 * this._rotFactor.x;
  33290. this._invLocalInertia02 = this._invLocalInertiaWithoutRotFactor02 * this._rotFactor.x;
  33291. this._invLocalInertia10 = this._invLocalInertiaWithoutRotFactor10 * this._rotFactor.y;
  33292. this._invLocalInertia11 = this._invLocalInertiaWithoutRotFactor11 * this._rotFactor.y;
  33293. this._invLocalInertia12 = this._invLocalInertiaWithoutRotFactor12 * this._rotFactor.y;
  33294. this._invLocalInertia20 = this._invLocalInertiaWithoutRotFactor20 * this._rotFactor.z;
  33295. this._invLocalInertia21 = this._invLocalInertiaWithoutRotFactor21 * this._rotFactor.z;
  33296. this._invLocalInertia22 = this._invLocalInertiaWithoutRotFactor22 * this._rotFactor.z;
  33297. } else {
  33298. this._invMass = 0;
  33299. this._invLocalInertia00 = 0;
  33300. this._invLocalInertia01 = 0;
  33301. this._invLocalInertia02 = 0;
  33302. this._invLocalInertia10 = 0;
  33303. this._invLocalInertia11 = 0;
  33304. this._invLocalInertia12 = 0;
  33305. this._invLocalInertia20 = 0;
  33306. this._invLocalInertia21 = 0;
  33307. this._invLocalInertia22 = 0;
  33308. this._invLocalInertiaWithoutRotFactor00 = 0;
  33309. this._invLocalInertiaWithoutRotFactor01 = 0;
  33310. this._invLocalInertiaWithoutRotFactor02 = 0;
  33311. this._invLocalInertiaWithoutRotFactor10 = 0;
  33312. this._invLocalInertiaWithoutRotFactor11 = 0;
  33313. this._invLocalInertiaWithoutRotFactor12 = 0;
  33314. this._invLocalInertiaWithoutRotFactor20 = 0;
  33315. this._invLocalInertiaWithoutRotFactor21 = 0;
  33316. this._invLocalInertiaWithoutRotFactor22 = 0;
  33317. if(this._type == 0) {
  33318. this._type = 1;
  33319. }
  33320. }
  33321. let __tmp__00;
  33322. let __tmp__01;
  33323. let __tmp__02;
  33324. let __tmp__10;
  33325. let __tmp__11;
  33326. let __tmp__12;
  33327. let __tmp__20;
  33328. let __tmp__21;
  33329. let __tmp__22;
  33330. __tmp__00 = this._transform._rotation00 * this._invLocalInertia00 + this._transform._rotation01 * this._invLocalInertia10 + this._transform._rotation02 * this._invLocalInertia20;
  33331. __tmp__01 = this._transform._rotation00 * this._invLocalInertia01 + this._transform._rotation01 * this._invLocalInertia11 + this._transform._rotation02 * this._invLocalInertia21;
  33332. __tmp__02 = this._transform._rotation00 * this._invLocalInertia02 + this._transform._rotation01 * this._invLocalInertia12 + this._transform._rotation02 * this._invLocalInertia22;
  33333. __tmp__10 = this._transform._rotation10 * this._invLocalInertia00 + this._transform._rotation11 * this._invLocalInertia10 + this._transform._rotation12 * this._invLocalInertia20;
  33334. __tmp__11 = this._transform._rotation10 * this._invLocalInertia01 + this._transform._rotation11 * this._invLocalInertia11 + this._transform._rotation12 * this._invLocalInertia21;
  33335. __tmp__12 = this._transform._rotation10 * this._invLocalInertia02 + this._transform._rotation11 * this._invLocalInertia12 + this._transform._rotation12 * this._invLocalInertia22;
  33336. __tmp__20 = this._transform._rotation20 * this._invLocalInertia00 + this._transform._rotation21 * this._invLocalInertia10 + this._transform._rotation22 * this._invLocalInertia20;
  33337. __tmp__21 = this._transform._rotation20 * this._invLocalInertia01 + this._transform._rotation21 * this._invLocalInertia11 + this._transform._rotation22 * this._invLocalInertia21;
  33338. __tmp__22 = this._transform._rotation20 * this._invLocalInertia02 + this._transform._rotation21 * this._invLocalInertia12 + this._transform._rotation22 * this._invLocalInertia22;
  33339. this._invInertia00 = __tmp__00;
  33340. this._invInertia01 = __tmp__01;
  33341. this._invInertia02 = __tmp__02;
  33342. this._invInertia10 = __tmp__10;
  33343. this._invInertia11 = __tmp__11;
  33344. this._invInertia12 = __tmp__12;
  33345. this._invInertia20 = __tmp__20;
  33346. this._invInertia21 = __tmp__21;
  33347. this._invInertia22 = __tmp__22;
  33348. let __tmp__001;
  33349. let __tmp__011;
  33350. let __tmp__021;
  33351. let __tmp__101;
  33352. let __tmp__111;
  33353. let __tmp__121;
  33354. let __tmp__201;
  33355. let __tmp__211;
  33356. let __tmp__221;
  33357. __tmp__001 = this._invInertia00 * this._transform._rotation00 + this._invInertia01 * this._transform._rotation01 + this._invInertia02 * this._transform._rotation02;
  33358. __tmp__011 = this._invInertia00 * this._transform._rotation10 + this._invInertia01 * this._transform._rotation11 + this._invInertia02 * this._transform._rotation12;
  33359. __tmp__021 = this._invInertia00 * this._transform._rotation20 + this._invInertia01 * this._transform._rotation21 + this._invInertia02 * this._transform._rotation22;
  33360. __tmp__101 = this._invInertia10 * this._transform._rotation00 + this._invInertia11 * this._transform._rotation01 + this._invInertia12 * this._transform._rotation02;
  33361. __tmp__111 = this._invInertia10 * this._transform._rotation10 + this._invInertia11 * this._transform._rotation11 + this._invInertia12 * this._transform._rotation12;
  33362. __tmp__121 = this._invInertia10 * this._transform._rotation20 + this._invInertia11 * this._transform._rotation21 + this._invInertia12 * this._transform._rotation22;
  33363. __tmp__201 = this._invInertia20 * this._transform._rotation00 + this._invInertia21 * this._transform._rotation01 + this._invInertia22 * this._transform._rotation02;
  33364. __tmp__211 = this._invInertia20 * this._transform._rotation10 + this._invInertia21 * this._transform._rotation11 + this._invInertia22 * this._transform._rotation12;
  33365. __tmp__221 = this._invInertia20 * this._transform._rotation20 + this._invInertia21 * this._transform._rotation21 + this._invInertia22 * this._transform._rotation22;
  33366. this._invInertia00 = __tmp__001;
  33367. this._invInertia01 = __tmp__011;
  33368. this._invInertia02 = __tmp__021;
  33369. this._invInertia10 = __tmp__101;
  33370. this._invInertia11 = __tmp__111;
  33371. this._invInertia12 = __tmp__121;
  33372. this._invInertia20 = __tmp__201;
  33373. this._invInertia21 = __tmp__211;
  33374. this._invInertia22 = __tmp__221;
  33375. this._invInertia00 *= this._rotFactor.x;
  33376. this._invInertia01 *= this._rotFactor.x;
  33377. this._invInertia02 *= this._rotFactor.x;
  33378. this._invInertia10 *= this._rotFactor.y;
  33379. this._invInertia11 *= this._rotFactor.y;
  33380. this._invInertia12 *= this._rotFactor.y;
  33381. this._invInertia20 *= this._rotFactor.z;
  33382. this._invInertia21 *= this._rotFactor.z;
  33383. this._invInertia22 *= this._rotFactor.z;
  33384. this._sleeping = false;
  33385. this._sleepTime = 0;
  33386. }
  33387. getPosition() {
  33388. let v = new oimo.common.Vec3();
  33389. v.x = this._transform._positionX;
  33390. v.y = this._transform._positionY;
  33391. v.z = this._transform._positionZ;
  33392. return v;
  33393. }
  33394. getPositionTo(position) {
  33395. position.x = this._transform._positionX;
  33396. position.y = this._transform._positionY;
  33397. position.z = this._transform._positionZ;
  33398. }
  33399. setPosition(position) {
  33400. this._transform._positionX = position.x;
  33401. this._transform._positionY = position.y;
  33402. this._transform._positionZ = position.z;
  33403. let dst = this._ptransform;
  33404. let src = this._transform;
  33405. dst._positionX = src._positionX;
  33406. dst._positionY = src._positionY;
  33407. dst._positionZ = src._positionZ;
  33408. dst._rotation00 = src._rotation00;
  33409. dst._rotation01 = src._rotation01;
  33410. dst._rotation02 = src._rotation02;
  33411. dst._rotation10 = src._rotation10;
  33412. dst._rotation11 = src._rotation11;
  33413. dst._rotation12 = src._rotation12;
  33414. dst._rotation20 = src._rotation20;
  33415. dst._rotation21 = src._rotation21;
  33416. dst._rotation22 = src._rotation22;
  33417. let s = this._shapeList;
  33418. while(s != null) {
  33419. let n = s._next;
  33420. let tf1 = this._ptransform;
  33421. let tf2 = this._transform;
  33422. let dst = s._ptransform;
  33423. let src1 = s._localTransform;
  33424. let __tmp__00;
  33425. let __tmp__01;
  33426. let __tmp__02;
  33427. let __tmp__10;
  33428. let __tmp__11;
  33429. let __tmp__12;
  33430. let __tmp__20;
  33431. let __tmp__21;
  33432. let __tmp__22;
  33433. __tmp__00 = tf1._rotation00 * src1._rotation00 + tf1._rotation01 * src1._rotation10 + tf1._rotation02 * src1._rotation20;
  33434. __tmp__01 = tf1._rotation00 * src1._rotation01 + tf1._rotation01 * src1._rotation11 + tf1._rotation02 * src1._rotation21;
  33435. __tmp__02 = tf1._rotation00 * src1._rotation02 + tf1._rotation01 * src1._rotation12 + tf1._rotation02 * src1._rotation22;
  33436. __tmp__10 = tf1._rotation10 * src1._rotation00 + tf1._rotation11 * src1._rotation10 + tf1._rotation12 * src1._rotation20;
  33437. __tmp__11 = tf1._rotation10 * src1._rotation01 + tf1._rotation11 * src1._rotation11 + tf1._rotation12 * src1._rotation21;
  33438. __tmp__12 = tf1._rotation10 * src1._rotation02 + tf1._rotation11 * src1._rotation12 + tf1._rotation12 * src1._rotation22;
  33439. __tmp__20 = tf1._rotation20 * src1._rotation00 + tf1._rotation21 * src1._rotation10 + tf1._rotation22 * src1._rotation20;
  33440. __tmp__21 = tf1._rotation20 * src1._rotation01 + tf1._rotation21 * src1._rotation11 + tf1._rotation22 * src1._rotation21;
  33441. __tmp__22 = tf1._rotation20 * src1._rotation02 + tf1._rotation21 * src1._rotation12 + tf1._rotation22 * src1._rotation22;
  33442. dst._rotation00 = __tmp__00;
  33443. dst._rotation01 = __tmp__01;
  33444. dst._rotation02 = __tmp__02;
  33445. dst._rotation10 = __tmp__10;
  33446. dst._rotation11 = __tmp__11;
  33447. dst._rotation12 = __tmp__12;
  33448. dst._rotation20 = __tmp__20;
  33449. dst._rotation21 = __tmp__21;
  33450. dst._rotation22 = __tmp__22;
  33451. let __tmp__X;
  33452. let __tmp__Y;
  33453. let __tmp__Z;
  33454. __tmp__X = tf1._rotation00 * src1._positionX + tf1._rotation01 * src1._positionY + tf1._rotation02 * src1._positionZ;
  33455. __tmp__Y = tf1._rotation10 * src1._positionX + tf1._rotation11 * src1._positionY + tf1._rotation12 * src1._positionZ;
  33456. __tmp__Z = tf1._rotation20 * src1._positionX + tf1._rotation21 * src1._positionY + tf1._rotation22 * src1._positionZ;
  33457. dst._positionX = __tmp__X;
  33458. dst._positionY = __tmp__Y;
  33459. dst._positionZ = __tmp__Z;
  33460. dst._positionX += tf1._positionX;
  33461. dst._positionY += tf1._positionY;
  33462. dst._positionZ += tf1._positionZ;
  33463. let dst1 = s._transform;
  33464. let src11 = s._localTransform;
  33465. let __tmp__001;
  33466. let __tmp__011;
  33467. let __tmp__021;
  33468. let __tmp__101;
  33469. let __tmp__111;
  33470. let __tmp__121;
  33471. let __tmp__201;
  33472. let __tmp__211;
  33473. let __tmp__221;
  33474. __tmp__001 = tf2._rotation00 * src11._rotation00 + tf2._rotation01 * src11._rotation10 + tf2._rotation02 * src11._rotation20;
  33475. __tmp__011 = tf2._rotation00 * src11._rotation01 + tf2._rotation01 * src11._rotation11 + tf2._rotation02 * src11._rotation21;
  33476. __tmp__021 = tf2._rotation00 * src11._rotation02 + tf2._rotation01 * src11._rotation12 + tf2._rotation02 * src11._rotation22;
  33477. __tmp__101 = tf2._rotation10 * src11._rotation00 + tf2._rotation11 * src11._rotation10 + tf2._rotation12 * src11._rotation20;
  33478. __tmp__111 = tf2._rotation10 * src11._rotation01 + tf2._rotation11 * src11._rotation11 + tf2._rotation12 * src11._rotation21;
  33479. __tmp__121 = tf2._rotation10 * src11._rotation02 + tf2._rotation11 * src11._rotation12 + tf2._rotation12 * src11._rotation22;
  33480. __tmp__201 = tf2._rotation20 * src11._rotation00 + tf2._rotation21 * src11._rotation10 + tf2._rotation22 * src11._rotation20;
  33481. __tmp__211 = tf2._rotation20 * src11._rotation01 + tf2._rotation21 * src11._rotation11 + tf2._rotation22 * src11._rotation21;
  33482. __tmp__221 = tf2._rotation20 * src11._rotation02 + tf2._rotation21 * src11._rotation12 + tf2._rotation22 * src11._rotation22;
  33483. dst1._rotation00 = __tmp__001;
  33484. dst1._rotation01 = __tmp__011;
  33485. dst1._rotation02 = __tmp__021;
  33486. dst1._rotation10 = __tmp__101;
  33487. dst1._rotation11 = __tmp__111;
  33488. dst1._rotation12 = __tmp__121;
  33489. dst1._rotation20 = __tmp__201;
  33490. dst1._rotation21 = __tmp__211;
  33491. dst1._rotation22 = __tmp__221;
  33492. let __tmp__X1;
  33493. let __tmp__Y1;
  33494. let __tmp__Z1;
  33495. __tmp__X1 = tf2._rotation00 * src11._positionX + tf2._rotation01 * src11._positionY + tf2._rotation02 * src11._positionZ;
  33496. __tmp__Y1 = tf2._rotation10 * src11._positionX + tf2._rotation11 * src11._positionY + tf2._rotation12 * src11._positionZ;
  33497. __tmp__Z1 = tf2._rotation20 * src11._positionX + tf2._rotation21 * src11._positionY + tf2._rotation22 * src11._positionZ;
  33498. dst1._positionX = __tmp__X1;
  33499. dst1._positionY = __tmp__Y1;
  33500. dst1._positionZ = __tmp__Z1;
  33501. dst1._positionX += tf2._positionX;
  33502. dst1._positionY += tf2._positionY;
  33503. dst1._positionZ += tf2._positionZ;
  33504. let minX;
  33505. let minY;
  33506. let minZ;
  33507. let maxX;
  33508. let maxY;
  33509. let maxZ;
  33510. s._geom._computeAabb(s._aabb,s._ptransform);
  33511. minX = s._aabb._minX;
  33512. minY = s._aabb._minY;
  33513. minZ = s._aabb._minZ;
  33514. maxX = s._aabb._maxX;
  33515. maxY = s._aabb._maxY;
  33516. maxZ = s._aabb._maxZ;
  33517. s._geom._computeAabb(s._aabb,s._transform);
  33518. s._aabb._minX = minX < s._aabb._minX ? minX : s._aabb._minX;
  33519. s._aabb._minY = minY < s._aabb._minY ? minY : s._aabb._minY;
  33520. s._aabb._minZ = minZ < s._aabb._minZ ? minZ : s._aabb._minZ;
  33521. s._aabb._maxX = maxX > s._aabb._maxX ? maxX : s._aabb._maxX;
  33522. s._aabb._maxY = maxY > s._aabb._maxY ? maxY : s._aabb._maxY;
  33523. s._aabb._maxZ = maxZ > s._aabb._maxZ ? maxZ : s._aabb._maxZ;
  33524. if(s._proxy != null) {
  33525. let dX;
  33526. let dY;
  33527. let dZ;
  33528. dX = s._transform._positionX - s._ptransform._positionX;
  33529. dY = s._transform._positionY - s._ptransform._positionY;
  33530. dZ = s._transform._positionZ - s._ptransform._positionZ;
  33531. let v = s.displacement;
  33532. v.x = dX;
  33533. v.y = dY;
  33534. v.z = dZ;
  33535. s._rigidBody._world._broadPhase.moveProxy(s._proxy,s._aabb,s.displacement);
  33536. }
  33537. s = n;
  33538. }
  33539. this._sleeping = false;
  33540. this._sleepTime = 0;
  33541. }
  33542. translate(translation) {
  33543. let diffX;
  33544. let diffY;
  33545. let diffZ;
  33546. diffX = translation.x;
  33547. diffY = translation.y;
  33548. diffZ = translation.z;
  33549. this._transform._positionX += diffX;
  33550. this._transform._positionY += diffY;
  33551. this._transform._positionZ += diffZ;
  33552. let dst = this._ptransform;
  33553. let src = this._transform;
  33554. dst._positionX = src._positionX;
  33555. dst._positionY = src._positionY;
  33556. dst._positionZ = src._positionZ;
  33557. dst._rotation00 = src._rotation00;
  33558. dst._rotation01 = src._rotation01;
  33559. dst._rotation02 = src._rotation02;
  33560. dst._rotation10 = src._rotation10;
  33561. dst._rotation11 = src._rotation11;
  33562. dst._rotation12 = src._rotation12;
  33563. dst._rotation20 = src._rotation20;
  33564. dst._rotation21 = src._rotation21;
  33565. dst._rotation22 = src._rotation22;
  33566. let s = this._shapeList;
  33567. while(s != null) {
  33568. let n = s._next;
  33569. let tf1 = this._ptransform;
  33570. let tf2 = this._transform;
  33571. let dst = s._ptransform;
  33572. let src1 = s._localTransform;
  33573. let __tmp__00;
  33574. let __tmp__01;
  33575. let __tmp__02;
  33576. let __tmp__10;
  33577. let __tmp__11;
  33578. let __tmp__12;
  33579. let __tmp__20;
  33580. let __tmp__21;
  33581. let __tmp__22;
  33582. __tmp__00 = tf1._rotation00 * src1._rotation00 + tf1._rotation01 * src1._rotation10 + tf1._rotation02 * src1._rotation20;
  33583. __tmp__01 = tf1._rotation00 * src1._rotation01 + tf1._rotation01 * src1._rotation11 + tf1._rotation02 * src1._rotation21;
  33584. __tmp__02 = tf1._rotation00 * src1._rotation02 + tf1._rotation01 * src1._rotation12 + tf1._rotation02 * src1._rotation22;
  33585. __tmp__10 = tf1._rotation10 * src1._rotation00 + tf1._rotation11 * src1._rotation10 + tf1._rotation12 * src1._rotation20;
  33586. __tmp__11 = tf1._rotation10 * src1._rotation01 + tf1._rotation11 * src1._rotation11 + tf1._rotation12 * src1._rotation21;
  33587. __tmp__12 = tf1._rotation10 * src1._rotation02 + tf1._rotation11 * src1._rotation12 + tf1._rotation12 * src1._rotation22;
  33588. __tmp__20 = tf1._rotation20 * src1._rotation00 + tf1._rotation21 * src1._rotation10 + tf1._rotation22 * src1._rotation20;
  33589. __tmp__21 = tf1._rotation20 * src1._rotation01 + tf1._rotation21 * src1._rotation11 + tf1._rotation22 * src1._rotation21;
  33590. __tmp__22 = tf1._rotation20 * src1._rotation02 + tf1._rotation21 * src1._rotation12 + tf1._rotation22 * src1._rotation22;
  33591. dst._rotation00 = __tmp__00;
  33592. dst._rotation01 = __tmp__01;
  33593. dst._rotation02 = __tmp__02;
  33594. dst._rotation10 = __tmp__10;
  33595. dst._rotation11 = __tmp__11;
  33596. dst._rotation12 = __tmp__12;
  33597. dst._rotation20 = __tmp__20;
  33598. dst._rotation21 = __tmp__21;
  33599. dst._rotation22 = __tmp__22;
  33600. let __tmp__X;
  33601. let __tmp__Y;
  33602. let __tmp__Z;
  33603. __tmp__X = tf1._rotation00 * src1._positionX + tf1._rotation01 * src1._positionY + tf1._rotation02 * src1._positionZ;
  33604. __tmp__Y = tf1._rotation10 * src1._positionX + tf1._rotation11 * src1._positionY + tf1._rotation12 * src1._positionZ;
  33605. __tmp__Z = tf1._rotation20 * src1._positionX + tf1._rotation21 * src1._positionY + tf1._rotation22 * src1._positionZ;
  33606. dst._positionX = __tmp__X;
  33607. dst._positionY = __tmp__Y;
  33608. dst._positionZ = __tmp__Z;
  33609. dst._positionX += tf1._positionX;
  33610. dst._positionY += tf1._positionY;
  33611. dst._positionZ += tf1._positionZ;
  33612. let dst1 = s._transform;
  33613. let src11 = s._localTransform;
  33614. let __tmp__001;
  33615. let __tmp__011;
  33616. let __tmp__021;
  33617. let __tmp__101;
  33618. let __tmp__111;
  33619. let __tmp__121;
  33620. let __tmp__201;
  33621. let __tmp__211;
  33622. let __tmp__221;
  33623. __tmp__001 = tf2._rotation00 * src11._rotation00 + tf2._rotation01 * src11._rotation10 + tf2._rotation02 * src11._rotation20;
  33624. __tmp__011 = tf2._rotation00 * src11._rotation01 + tf2._rotation01 * src11._rotation11 + tf2._rotation02 * src11._rotation21;
  33625. __tmp__021 = tf2._rotation00 * src11._rotation02 + tf2._rotation01 * src11._rotation12 + tf2._rotation02 * src11._rotation22;
  33626. __tmp__101 = tf2._rotation10 * src11._rotation00 + tf2._rotation11 * src11._rotation10 + tf2._rotation12 * src11._rotation20;
  33627. __tmp__111 = tf2._rotation10 * src11._rotation01 + tf2._rotation11 * src11._rotation11 + tf2._rotation12 * src11._rotation21;
  33628. __tmp__121 = tf2._rotation10 * src11._rotation02 + tf2._rotation11 * src11._rotation12 + tf2._rotation12 * src11._rotation22;
  33629. __tmp__201 = tf2._rotation20 * src11._rotation00 + tf2._rotation21 * src11._rotation10 + tf2._rotation22 * src11._rotation20;
  33630. __tmp__211 = tf2._rotation20 * src11._rotation01 + tf2._rotation21 * src11._rotation11 + tf2._rotation22 * src11._rotation21;
  33631. __tmp__221 = tf2._rotation20 * src11._rotation02 + tf2._rotation21 * src11._rotation12 + tf2._rotation22 * src11._rotation22;
  33632. dst1._rotation00 = __tmp__001;
  33633. dst1._rotation01 = __tmp__011;
  33634. dst1._rotation02 = __tmp__021;
  33635. dst1._rotation10 = __tmp__101;
  33636. dst1._rotation11 = __tmp__111;
  33637. dst1._rotation12 = __tmp__121;
  33638. dst1._rotation20 = __tmp__201;
  33639. dst1._rotation21 = __tmp__211;
  33640. dst1._rotation22 = __tmp__221;
  33641. let __tmp__X1;
  33642. let __tmp__Y1;
  33643. let __tmp__Z1;
  33644. __tmp__X1 = tf2._rotation00 * src11._positionX + tf2._rotation01 * src11._positionY + tf2._rotation02 * src11._positionZ;
  33645. __tmp__Y1 = tf2._rotation10 * src11._positionX + tf2._rotation11 * src11._positionY + tf2._rotation12 * src11._positionZ;
  33646. __tmp__Z1 = tf2._rotation20 * src11._positionX + tf2._rotation21 * src11._positionY + tf2._rotation22 * src11._positionZ;
  33647. dst1._positionX = __tmp__X1;
  33648. dst1._positionY = __tmp__Y1;
  33649. dst1._positionZ = __tmp__Z1;
  33650. dst1._positionX += tf2._positionX;
  33651. dst1._positionY += tf2._positionY;
  33652. dst1._positionZ += tf2._positionZ;
  33653. let minX;
  33654. let minY;
  33655. let minZ;
  33656. let maxX;
  33657. let maxY;
  33658. let maxZ;
  33659. s._geom._computeAabb(s._aabb,s._ptransform);
  33660. minX = s._aabb._minX;
  33661. minY = s._aabb._minY;
  33662. minZ = s._aabb._minZ;
  33663. maxX = s._aabb._maxX;
  33664. maxY = s._aabb._maxY;
  33665. maxZ = s._aabb._maxZ;
  33666. s._geom._computeAabb(s._aabb,s._transform);
  33667. s._aabb._minX = minX < s._aabb._minX ? minX : s._aabb._minX;
  33668. s._aabb._minY = minY < s._aabb._minY ? minY : s._aabb._minY;
  33669. s._aabb._minZ = minZ < s._aabb._minZ ? minZ : s._aabb._minZ;
  33670. s._aabb._maxX = maxX > s._aabb._maxX ? maxX : s._aabb._maxX;
  33671. s._aabb._maxY = maxY > s._aabb._maxY ? maxY : s._aabb._maxY;
  33672. s._aabb._maxZ = maxZ > s._aabb._maxZ ? maxZ : s._aabb._maxZ;
  33673. if(s._proxy != null) {
  33674. let dX;
  33675. let dY;
  33676. let dZ;
  33677. dX = s._transform._positionX - s._ptransform._positionX;
  33678. dY = s._transform._positionY - s._ptransform._positionY;
  33679. dZ = s._transform._positionZ - s._ptransform._positionZ;
  33680. let v = s.displacement;
  33681. v.x = dX;
  33682. v.y = dY;
  33683. v.z = dZ;
  33684. s._rigidBody._world._broadPhase.moveProxy(s._proxy,s._aabb,s.displacement);
  33685. }
  33686. s = n;
  33687. }
  33688. this._sleeping = false;
  33689. this._sleepTime = 0;
  33690. }
  33691. getRotation() {
  33692. let m = new oimo.common.Mat3();
  33693. m.e00 = this._transform._rotation00;
  33694. m.e01 = this._transform._rotation01;
  33695. m.e02 = this._transform._rotation02;
  33696. m.e10 = this._transform._rotation10;
  33697. m.e11 = this._transform._rotation11;
  33698. m.e12 = this._transform._rotation12;
  33699. m.e20 = this._transform._rotation20;
  33700. m.e21 = this._transform._rotation21;
  33701. m.e22 = this._transform._rotation22;
  33702. return m;
  33703. }
  33704. getRotationTo(rotation) {
  33705. rotation.e00 = this._transform._rotation00;
  33706. rotation.e01 = this._transform._rotation01;
  33707. rotation.e02 = this._transform._rotation02;
  33708. rotation.e10 = this._transform._rotation10;
  33709. rotation.e11 = this._transform._rotation11;
  33710. rotation.e12 = this._transform._rotation12;
  33711. rotation.e20 = this._transform._rotation20;
  33712. rotation.e21 = this._transform._rotation21;
  33713. rotation.e22 = this._transform._rotation22;
  33714. }
  33715. setRotation(rotation) {
  33716. this._transform._rotation00 = rotation.e00;
  33717. this._transform._rotation01 = rotation.e01;
  33718. this._transform._rotation02 = rotation.e02;
  33719. this._transform._rotation10 = rotation.e10;
  33720. this._transform._rotation11 = rotation.e11;
  33721. this._transform._rotation12 = rotation.e12;
  33722. this._transform._rotation20 = rotation.e20;
  33723. this._transform._rotation21 = rotation.e21;
  33724. this._transform._rotation22 = rotation.e22;
  33725. let __tmp__00;
  33726. let __tmp__01;
  33727. let __tmp__02;
  33728. let __tmp__10;
  33729. let __tmp__11;
  33730. let __tmp__12;
  33731. let __tmp__20;
  33732. let __tmp__21;
  33733. let __tmp__22;
  33734. __tmp__00 = this._transform._rotation00 * this._invLocalInertia00 + this._transform._rotation01 * this._invLocalInertia10 + this._transform._rotation02 * this._invLocalInertia20;
  33735. __tmp__01 = this._transform._rotation00 * this._invLocalInertia01 + this._transform._rotation01 * this._invLocalInertia11 + this._transform._rotation02 * this._invLocalInertia21;
  33736. __tmp__02 = this._transform._rotation00 * this._invLocalInertia02 + this._transform._rotation01 * this._invLocalInertia12 + this._transform._rotation02 * this._invLocalInertia22;
  33737. __tmp__10 = this._transform._rotation10 * this._invLocalInertia00 + this._transform._rotation11 * this._invLocalInertia10 + this._transform._rotation12 * this._invLocalInertia20;
  33738. __tmp__11 = this._transform._rotation10 * this._invLocalInertia01 + this._transform._rotation11 * this._invLocalInertia11 + this._transform._rotation12 * this._invLocalInertia21;
  33739. __tmp__12 = this._transform._rotation10 * this._invLocalInertia02 + this._transform._rotation11 * this._invLocalInertia12 + this._transform._rotation12 * this._invLocalInertia22;
  33740. __tmp__20 = this._transform._rotation20 * this._invLocalInertia00 + this._transform._rotation21 * this._invLocalInertia10 + this._transform._rotation22 * this._invLocalInertia20;
  33741. __tmp__21 = this._transform._rotation20 * this._invLocalInertia01 + this._transform._rotation21 * this._invLocalInertia11 + this._transform._rotation22 * this._invLocalInertia21;
  33742. __tmp__22 = this._transform._rotation20 * this._invLocalInertia02 + this._transform._rotation21 * this._invLocalInertia12 + this._transform._rotation22 * this._invLocalInertia22;
  33743. this._invInertia00 = __tmp__00;
  33744. this._invInertia01 = __tmp__01;
  33745. this._invInertia02 = __tmp__02;
  33746. this._invInertia10 = __tmp__10;
  33747. this._invInertia11 = __tmp__11;
  33748. this._invInertia12 = __tmp__12;
  33749. this._invInertia20 = __tmp__20;
  33750. this._invInertia21 = __tmp__21;
  33751. this._invInertia22 = __tmp__22;
  33752. let __tmp__001;
  33753. let __tmp__011;
  33754. let __tmp__021;
  33755. let __tmp__101;
  33756. let __tmp__111;
  33757. let __tmp__121;
  33758. let __tmp__201;
  33759. let __tmp__211;
  33760. let __tmp__221;
  33761. __tmp__001 = this._invInertia00 * this._transform._rotation00 + this._invInertia01 * this._transform._rotation01 + this._invInertia02 * this._transform._rotation02;
  33762. __tmp__011 = this._invInertia00 * this._transform._rotation10 + this._invInertia01 * this._transform._rotation11 + this._invInertia02 * this._transform._rotation12;
  33763. __tmp__021 = this._invInertia00 * this._transform._rotation20 + this._invInertia01 * this._transform._rotation21 + this._invInertia02 * this._transform._rotation22;
  33764. __tmp__101 = this._invInertia10 * this._transform._rotation00 + this._invInertia11 * this._transform._rotation01 + this._invInertia12 * this._transform._rotation02;
  33765. __tmp__111 = this._invInertia10 * this._transform._rotation10 + this._invInertia11 * this._transform._rotation11 + this._invInertia12 * this._transform._rotation12;
  33766. __tmp__121 = this._invInertia10 * this._transform._rotation20 + this._invInertia11 * this._transform._rotation21 + this._invInertia12 * this._transform._rotation22;
  33767. __tmp__201 = this._invInertia20 * this._transform._rotation00 + this._invInertia21 * this._transform._rotation01 + this._invInertia22 * this._transform._rotation02;
  33768. __tmp__211 = this._invInertia20 * this._transform._rotation10 + this._invInertia21 * this._transform._rotation11 + this._invInertia22 * this._transform._rotation12;
  33769. __tmp__221 = this._invInertia20 * this._transform._rotation20 + this._invInertia21 * this._transform._rotation21 + this._invInertia22 * this._transform._rotation22;
  33770. this._invInertia00 = __tmp__001;
  33771. this._invInertia01 = __tmp__011;
  33772. this._invInertia02 = __tmp__021;
  33773. this._invInertia10 = __tmp__101;
  33774. this._invInertia11 = __tmp__111;
  33775. this._invInertia12 = __tmp__121;
  33776. this._invInertia20 = __tmp__201;
  33777. this._invInertia21 = __tmp__211;
  33778. this._invInertia22 = __tmp__221;
  33779. this._invInertia00 *= this._rotFactor.x;
  33780. this._invInertia01 *= this._rotFactor.x;
  33781. this._invInertia02 *= this._rotFactor.x;
  33782. this._invInertia10 *= this._rotFactor.y;
  33783. this._invInertia11 *= this._rotFactor.y;
  33784. this._invInertia12 *= this._rotFactor.y;
  33785. this._invInertia20 *= this._rotFactor.z;
  33786. this._invInertia21 *= this._rotFactor.z;
  33787. this._invInertia22 *= this._rotFactor.z;
  33788. let dst = this._ptransform;
  33789. let src = this._transform;
  33790. dst._positionX = src._positionX;
  33791. dst._positionY = src._positionY;
  33792. dst._positionZ = src._positionZ;
  33793. dst._rotation00 = src._rotation00;
  33794. dst._rotation01 = src._rotation01;
  33795. dst._rotation02 = src._rotation02;
  33796. dst._rotation10 = src._rotation10;
  33797. dst._rotation11 = src._rotation11;
  33798. dst._rotation12 = src._rotation12;
  33799. dst._rotation20 = src._rotation20;
  33800. dst._rotation21 = src._rotation21;
  33801. dst._rotation22 = src._rotation22;
  33802. let s = this._shapeList;
  33803. while(s != null) {
  33804. let n = s._next;
  33805. let tf1 = this._ptransform;
  33806. let tf2 = this._transform;
  33807. let dst = s._ptransform;
  33808. let src1 = s._localTransform;
  33809. let __tmp__00;
  33810. let __tmp__01;
  33811. let __tmp__02;
  33812. let __tmp__10;
  33813. let __tmp__11;
  33814. let __tmp__12;
  33815. let __tmp__20;
  33816. let __tmp__21;
  33817. let __tmp__22;
  33818. __tmp__00 = tf1._rotation00 * src1._rotation00 + tf1._rotation01 * src1._rotation10 + tf1._rotation02 * src1._rotation20;
  33819. __tmp__01 = tf1._rotation00 * src1._rotation01 + tf1._rotation01 * src1._rotation11 + tf1._rotation02 * src1._rotation21;
  33820. __tmp__02 = tf1._rotation00 * src1._rotation02 + tf1._rotation01 * src1._rotation12 + tf1._rotation02 * src1._rotation22;
  33821. __tmp__10 = tf1._rotation10 * src1._rotation00 + tf1._rotation11 * src1._rotation10 + tf1._rotation12 * src1._rotation20;
  33822. __tmp__11 = tf1._rotation10 * src1._rotation01 + tf1._rotation11 * src1._rotation11 + tf1._rotation12 * src1._rotation21;
  33823. __tmp__12 = tf1._rotation10 * src1._rotation02 + tf1._rotation11 * src1._rotation12 + tf1._rotation12 * src1._rotation22;
  33824. __tmp__20 = tf1._rotation20 * src1._rotation00 + tf1._rotation21 * src1._rotation10 + tf1._rotation22 * src1._rotation20;
  33825. __tmp__21 = tf1._rotation20 * src1._rotation01 + tf1._rotation21 * src1._rotation11 + tf1._rotation22 * src1._rotation21;
  33826. __tmp__22 = tf1._rotation20 * src1._rotation02 + tf1._rotation21 * src1._rotation12 + tf1._rotation22 * src1._rotation22;
  33827. dst._rotation00 = __tmp__00;
  33828. dst._rotation01 = __tmp__01;
  33829. dst._rotation02 = __tmp__02;
  33830. dst._rotation10 = __tmp__10;
  33831. dst._rotation11 = __tmp__11;
  33832. dst._rotation12 = __tmp__12;
  33833. dst._rotation20 = __tmp__20;
  33834. dst._rotation21 = __tmp__21;
  33835. dst._rotation22 = __tmp__22;
  33836. let __tmp__X;
  33837. let __tmp__Y;
  33838. let __tmp__Z;
  33839. __tmp__X = tf1._rotation00 * src1._positionX + tf1._rotation01 * src1._positionY + tf1._rotation02 * src1._positionZ;
  33840. __tmp__Y = tf1._rotation10 * src1._positionX + tf1._rotation11 * src1._positionY + tf1._rotation12 * src1._positionZ;
  33841. __tmp__Z = tf1._rotation20 * src1._positionX + tf1._rotation21 * src1._positionY + tf1._rotation22 * src1._positionZ;
  33842. dst._positionX = __tmp__X;
  33843. dst._positionY = __tmp__Y;
  33844. dst._positionZ = __tmp__Z;
  33845. dst._positionX += tf1._positionX;
  33846. dst._positionY += tf1._positionY;
  33847. dst._positionZ += tf1._positionZ;
  33848. let dst1 = s._transform;
  33849. let src11 = s._localTransform;
  33850. let __tmp__001;
  33851. let __tmp__011;
  33852. let __tmp__021;
  33853. let __tmp__101;
  33854. let __tmp__111;
  33855. let __tmp__121;
  33856. let __tmp__201;
  33857. let __tmp__211;
  33858. let __tmp__221;
  33859. __tmp__001 = tf2._rotation00 * src11._rotation00 + tf2._rotation01 * src11._rotation10 + tf2._rotation02 * src11._rotation20;
  33860. __tmp__011 = tf2._rotation00 * src11._rotation01 + tf2._rotation01 * src11._rotation11 + tf2._rotation02 * src11._rotation21;
  33861. __tmp__021 = tf2._rotation00 * src11._rotation02 + tf2._rotation01 * src11._rotation12 + tf2._rotation02 * src11._rotation22;
  33862. __tmp__101 = tf2._rotation10 * src11._rotation00 + tf2._rotation11 * src11._rotation10 + tf2._rotation12 * src11._rotation20;
  33863. __tmp__111 = tf2._rotation10 * src11._rotation01 + tf2._rotation11 * src11._rotation11 + tf2._rotation12 * src11._rotation21;
  33864. __tmp__121 = tf2._rotation10 * src11._rotation02 + tf2._rotation11 * src11._rotation12 + tf2._rotation12 * src11._rotation22;
  33865. __tmp__201 = tf2._rotation20 * src11._rotation00 + tf2._rotation21 * src11._rotation10 + tf2._rotation22 * src11._rotation20;
  33866. __tmp__211 = tf2._rotation20 * src11._rotation01 + tf2._rotation21 * src11._rotation11 + tf2._rotation22 * src11._rotation21;
  33867. __tmp__221 = tf2._rotation20 * src11._rotation02 + tf2._rotation21 * src11._rotation12 + tf2._rotation22 * src11._rotation22;
  33868. dst1._rotation00 = __tmp__001;
  33869. dst1._rotation01 = __tmp__011;
  33870. dst1._rotation02 = __tmp__021;
  33871. dst1._rotation10 = __tmp__101;
  33872. dst1._rotation11 = __tmp__111;
  33873. dst1._rotation12 = __tmp__121;
  33874. dst1._rotation20 = __tmp__201;
  33875. dst1._rotation21 = __tmp__211;
  33876. dst1._rotation22 = __tmp__221;
  33877. let __tmp__X1;
  33878. let __tmp__Y1;
  33879. let __tmp__Z1;
  33880. __tmp__X1 = tf2._rotation00 * src11._positionX + tf2._rotation01 * src11._positionY + tf2._rotation02 * src11._positionZ;
  33881. __tmp__Y1 = tf2._rotation10 * src11._positionX + tf2._rotation11 * src11._positionY + tf2._rotation12 * src11._positionZ;
  33882. __tmp__Z1 = tf2._rotation20 * src11._positionX + tf2._rotation21 * src11._positionY + tf2._rotation22 * src11._positionZ;
  33883. dst1._positionX = __tmp__X1;
  33884. dst1._positionY = __tmp__Y1;
  33885. dst1._positionZ = __tmp__Z1;
  33886. dst1._positionX += tf2._positionX;
  33887. dst1._positionY += tf2._positionY;
  33888. dst1._positionZ += tf2._positionZ;
  33889. let minX;
  33890. let minY;
  33891. let minZ;
  33892. let maxX;
  33893. let maxY;
  33894. let maxZ;
  33895. s._geom._computeAabb(s._aabb,s._ptransform);
  33896. minX = s._aabb._minX;
  33897. minY = s._aabb._minY;
  33898. minZ = s._aabb._minZ;
  33899. maxX = s._aabb._maxX;
  33900. maxY = s._aabb._maxY;
  33901. maxZ = s._aabb._maxZ;
  33902. s._geom._computeAabb(s._aabb,s._transform);
  33903. s._aabb._minX = minX < s._aabb._minX ? minX : s._aabb._minX;
  33904. s._aabb._minY = minY < s._aabb._minY ? minY : s._aabb._minY;
  33905. s._aabb._minZ = minZ < s._aabb._minZ ? minZ : s._aabb._minZ;
  33906. s._aabb._maxX = maxX > s._aabb._maxX ? maxX : s._aabb._maxX;
  33907. s._aabb._maxY = maxY > s._aabb._maxY ? maxY : s._aabb._maxY;
  33908. s._aabb._maxZ = maxZ > s._aabb._maxZ ? maxZ : s._aabb._maxZ;
  33909. if(s._proxy != null) {
  33910. let dX;
  33911. let dY;
  33912. let dZ;
  33913. dX = s._transform._positionX - s._ptransform._positionX;
  33914. dY = s._transform._positionY - s._ptransform._positionY;
  33915. dZ = s._transform._positionZ - s._ptransform._positionZ;
  33916. let v = s.displacement;
  33917. v.x = dX;
  33918. v.y = dY;
  33919. v.z = dZ;
  33920. s._rigidBody._world._broadPhase.moveProxy(s._proxy,s._aabb,s.displacement);
  33921. }
  33922. s = n;
  33923. }
  33924. this._sleeping = false;
  33925. this._sleepTime = 0;
  33926. }
  33927. setRotationXyz(eulerAngles) {
  33928. let xyzX;
  33929. let xyzY;
  33930. let xyzZ;
  33931. xyzX = eulerAngles.x;
  33932. xyzY = eulerAngles.y;
  33933. xyzZ = eulerAngles.z;
  33934. let sx = Math.sin(xyzX);
  33935. let sy = Math.sin(xyzY);
  33936. let sz = Math.sin(xyzZ);
  33937. let cx = Math.cos(xyzX);
  33938. let cy = Math.cos(xyzY);
  33939. let cz = Math.cos(xyzZ);
  33940. this._transform._rotation00 = cy * cz;
  33941. this._transform._rotation01 = -cy * sz;
  33942. this._transform._rotation02 = sy;
  33943. this._transform._rotation10 = cx * sz + cz * sx * sy;
  33944. this._transform._rotation11 = cx * cz - sx * sy * sz;
  33945. this._transform._rotation12 = -cy * sx;
  33946. this._transform._rotation20 = sx * sz - cx * cz * sy;
  33947. this._transform._rotation21 = cz * sx + cx * sy * sz;
  33948. this._transform._rotation22 = cx * cy;
  33949. let __tmp__00;
  33950. let __tmp__01;
  33951. let __tmp__02;
  33952. let __tmp__10;
  33953. let __tmp__11;
  33954. let __tmp__12;
  33955. let __tmp__20;
  33956. let __tmp__21;
  33957. let __tmp__22;
  33958. __tmp__00 = this._transform._rotation00 * this._invLocalInertia00 + this._transform._rotation01 * this._invLocalInertia10 + this._transform._rotation02 * this._invLocalInertia20;
  33959. __tmp__01 = this._transform._rotation00 * this._invLocalInertia01 + this._transform._rotation01 * this._invLocalInertia11 + this._transform._rotation02 * this._invLocalInertia21;
  33960. __tmp__02 = this._transform._rotation00 * this._invLocalInertia02 + this._transform._rotation01 * this._invLocalInertia12 + this._transform._rotation02 * this._invLocalInertia22;
  33961. __tmp__10 = this._transform._rotation10 * this._invLocalInertia00 + this._transform._rotation11 * this._invLocalInertia10 + this._transform._rotation12 * this._invLocalInertia20;
  33962. __tmp__11 = this._transform._rotation10 * this._invLocalInertia01 + this._transform._rotation11 * this._invLocalInertia11 + this._transform._rotation12 * this._invLocalInertia21;
  33963. __tmp__12 = this._transform._rotation10 * this._invLocalInertia02 + this._transform._rotation11 * this._invLocalInertia12 + this._transform._rotation12 * this._invLocalInertia22;
  33964. __tmp__20 = this._transform._rotation20 * this._invLocalInertia00 + this._transform._rotation21 * this._invLocalInertia10 + this._transform._rotation22 * this._invLocalInertia20;
  33965. __tmp__21 = this._transform._rotation20 * this._invLocalInertia01 + this._transform._rotation21 * this._invLocalInertia11 + this._transform._rotation22 * this._invLocalInertia21;
  33966. __tmp__22 = this._transform._rotation20 * this._invLocalInertia02 + this._transform._rotation21 * this._invLocalInertia12 + this._transform._rotation22 * this._invLocalInertia22;
  33967. this._invInertia00 = __tmp__00;
  33968. this._invInertia01 = __tmp__01;
  33969. this._invInertia02 = __tmp__02;
  33970. this._invInertia10 = __tmp__10;
  33971. this._invInertia11 = __tmp__11;
  33972. this._invInertia12 = __tmp__12;
  33973. this._invInertia20 = __tmp__20;
  33974. this._invInertia21 = __tmp__21;
  33975. this._invInertia22 = __tmp__22;
  33976. let __tmp__001;
  33977. let __tmp__011;
  33978. let __tmp__021;
  33979. let __tmp__101;
  33980. let __tmp__111;
  33981. let __tmp__121;
  33982. let __tmp__201;
  33983. let __tmp__211;
  33984. let __tmp__221;
  33985. __tmp__001 = this._invInertia00 * this._transform._rotation00 + this._invInertia01 * this._transform._rotation01 + this._invInertia02 * this._transform._rotation02;
  33986. __tmp__011 = this._invInertia00 * this._transform._rotation10 + this._invInertia01 * this._transform._rotation11 + this._invInertia02 * this._transform._rotation12;
  33987. __tmp__021 = this._invInertia00 * this._transform._rotation20 + this._invInertia01 * this._transform._rotation21 + this._invInertia02 * this._transform._rotation22;
  33988. __tmp__101 = this._invInertia10 * this._transform._rotation00 + this._invInertia11 * this._transform._rotation01 + this._invInertia12 * this._transform._rotation02;
  33989. __tmp__111 = this._invInertia10 * this._transform._rotation10 + this._invInertia11 * this._transform._rotation11 + this._invInertia12 * this._transform._rotation12;
  33990. __tmp__121 = this._invInertia10 * this._transform._rotation20 + this._invInertia11 * this._transform._rotation21 + this._invInertia12 * this._transform._rotation22;
  33991. __tmp__201 = this._invInertia20 * this._transform._rotation00 + this._invInertia21 * this._transform._rotation01 + this._invInertia22 * this._transform._rotation02;
  33992. __tmp__211 = this._invInertia20 * this._transform._rotation10 + this._invInertia21 * this._transform._rotation11 + this._invInertia22 * this._transform._rotation12;
  33993. __tmp__221 = this._invInertia20 * this._transform._rotation20 + this._invInertia21 * this._transform._rotation21 + this._invInertia22 * this._transform._rotation22;
  33994. this._invInertia00 = __tmp__001;
  33995. this._invInertia01 = __tmp__011;
  33996. this._invInertia02 = __tmp__021;
  33997. this._invInertia10 = __tmp__101;
  33998. this._invInertia11 = __tmp__111;
  33999. this._invInertia12 = __tmp__121;
  34000. this._invInertia20 = __tmp__201;
  34001. this._invInertia21 = __tmp__211;
  34002. this._invInertia22 = __tmp__221;
  34003. this._invInertia00 *= this._rotFactor.x;
  34004. this._invInertia01 *= this._rotFactor.x;
  34005. this._invInertia02 *= this._rotFactor.x;
  34006. this._invInertia10 *= this._rotFactor.y;
  34007. this._invInertia11 *= this._rotFactor.y;
  34008. this._invInertia12 *= this._rotFactor.y;
  34009. this._invInertia20 *= this._rotFactor.z;
  34010. this._invInertia21 *= this._rotFactor.z;
  34011. this._invInertia22 *= this._rotFactor.z;
  34012. let dst = this._ptransform;
  34013. let src = this._transform;
  34014. dst._positionX = src._positionX;
  34015. dst._positionY = src._positionY;
  34016. dst._positionZ = src._positionZ;
  34017. dst._rotation00 = src._rotation00;
  34018. dst._rotation01 = src._rotation01;
  34019. dst._rotation02 = src._rotation02;
  34020. dst._rotation10 = src._rotation10;
  34021. dst._rotation11 = src._rotation11;
  34022. dst._rotation12 = src._rotation12;
  34023. dst._rotation20 = src._rotation20;
  34024. dst._rotation21 = src._rotation21;
  34025. dst._rotation22 = src._rotation22;
  34026. let s = this._shapeList;
  34027. while(s != null) {
  34028. let n = s._next;
  34029. let tf1 = this._ptransform;
  34030. let tf2 = this._transform;
  34031. let dst = s._ptransform;
  34032. let src1 = s._localTransform;
  34033. let __tmp__00;
  34034. let __tmp__01;
  34035. let __tmp__02;
  34036. let __tmp__10;
  34037. let __tmp__11;
  34038. let __tmp__12;
  34039. let __tmp__20;
  34040. let __tmp__21;
  34041. let __tmp__22;
  34042. __tmp__00 = tf1._rotation00 * src1._rotation00 + tf1._rotation01 * src1._rotation10 + tf1._rotation02 * src1._rotation20;
  34043. __tmp__01 = tf1._rotation00 * src1._rotation01 + tf1._rotation01 * src1._rotation11 + tf1._rotation02 * src1._rotation21;
  34044. __tmp__02 = tf1._rotation00 * src1._rotation02 + tf1._rotation01 * src1._rotation12 + tf1._rotation02 * src1._rotation22;
  34045. __tmp__10 = tf1._rotation10 * src1._rotation00 + tf1._rotation11 * src1._rotation10 + tf1._rotation12 * src1._rotation20;
  34046. __tmp__11 = tf1._rotation10 * src1._rotation01 + tf1._rotation11 * src1._rotation11 + tf1._rotation12 * src1._rotation21;
  34047. __tmp__12 = tf1._rotation10 * src1._rotation02 + tf1._rotation11 * src1._rotation12 + tf1._rotation12 * src1._rotation22;
  34048. __tmp__20 = tf1._rotation20 * src1._rotation00 + tf1._rotation21 * src1._rotation10 + tf1._rotation22 * src1._rotation20;
  34049. __tmp__21 = tf1._rotation20 * src1._rotation01 + tf1._rotation21 * src1._rotation11 + tf1._rotation22 * src1._rotation21;
  34050. __tmp__22 = tf1._rotation20 * src1._rotation02 + tf1._rotation21 * src1._rotation12 + tf1._rotation22 * src1._rotation22;
  34051. dst._rotation00 = __tmp__00;
  34052. dst._rotation01 = __tmp__01;
  34053. dst._rotation02 = __tmp__02;
  34054. dst._rotation10 = __tmp__10;
  34055. dst._rotation11 = __tmp__11;
  34056. dst._rotation12 = __tmp__12;
  34057. dst._rotation20 = __tmp__20;
  34058. dst._rotation21 = __tmp__21;
  34059. dst._rotation22 = __tmp__22;
  34060. let __tmp__X;
  34061. let __tmp__Y;
  34062. let __tmp__Z;
  34063. __tmp__X = tf1._rotation00 * src1._positionX + tf1._rotation01 * src1._positionY + tf1._rotation02 * src1._positionZ;
  34064. __tmp__Y = tf1._rotation10 * src1._positionX + tf1._rotation11 * src1._positionY + tf1._rotation12 * src1._positionZ;
  34065. __tmp__Z = tf1._rotation20 * src1._positionX + tf1._rotation21 * src1._positionY + tf1._rotation22 * src1._positionZ;
  34066. dst._positionX = __tmp__X;
  34067. dst._positionY = __tmp__Y;
  34068. dst._positionZ = __tmp__Z;
  34069. dst._positionX += tf1._positionX;
  34070. dst._positionY += tf1._positionY;
  34071. dst._positionZ += tf1._positionZ;
  34072. let dst1 = s._transform;
  34073. let src11 = s._localTransform;
  34074. let __tmp__001;
  34075. let __tmp__011;
  34076. let __tmp__021;
  34077. let __tmp__101;
  34078. let __tmp__111;
  34079. let __tmp__121;
  34080. let __tmp__201;
  34081. let __tmp__211;
  34082. let __tmp__221;
  34083. __tmp__001 = tf2._rotation00 * src11._rotation00 + tf2._rotation01 * src11._rotation10 + tf2._rotation02 * src11._rotation20;
  34084. __tmp__011 = tf2._rotation00 * src11._rotation01 + tf2._rotation01 * src11._rotation11 + tf2._rotation02 * src11._rotation21;
  34085. __tmp__021 = tf2._rotation00 * src11._rotation02 + tf2._rotation01 * src11._rotation12 + tf2._rotation02 * src11._rotation22;
  34086. __tmp__101 = tf2._rotation10 * src11._rotation00 + tf2._rotation11 * src11._rotation10 + tf2._rotation12 * src11._rotation20;
  34087. __tmp__111 = tf2._rotation10 * src11._rotation01 + tf2._rotation11 * src11._rotation11 + tf2._rotation12 * src11._rotation21;
  34088. __tmp__121 = tf2._rotation10 * src11._rotation02 + tf2._rotation11 * src11._rotation12 + tf2._rotation12 * src11._rotation22;
  34089. __tmp__201 = tf2._rotation20 * src11._rotation00 + tf2._rotation21 * src11._rotation10 + tf2._rotation22 * src11._rotation20;
  34090. __tmp__211 = tf2._rotation20 * src11._rotation01 + tf2._rotation21 * src11._rotation11 + tf2._rotation22 * src11._rotation21;
  34091. __tmp__221 = tf2._rotation20 * src11._rotation02 + tf2._rotation21 * src11._rotation12 + tf2._rotation22 * src11._rotation22;
  34092. dst1._rotation00 = __tmp__001;
  34093. dst1._rotation01 = __tmp__011;
  34094. dst1._rotation02 = __tmp__021;
  34095. dst1._rotation10 = __tmp__101;
  34096. dst1._rotation11 = __tmp__111;
  34097. dst1._rotation12 = __tmp__121;
  34098. dst1._rotation20 = __tmp__201;
  34099. dst1._rotation21 = __tmp__211;
  34100. dst1._rotation22 = __tmp__221;
  34101. let __tmp__X1;
  34102. let __tmp__Y1;
  34103. let __tmp__Z1;
  34104. __tmp__X1 = tf2._rotation00 * src11._positionX + tf2._rotation01 * src11._positionY + tf2._rotation02 * src11._positionZ;
  34105. __tmp__Y1 = tf2._rotation10 * src11._positionX + tf2._rotation11 * src11._positionY + tf2._rotation12 * src11._positionZ;
  34106. __tmp__Z1 = tf2._rotation20 * src11._positionX + tf2._rotation21 * src11._positionY + tf2._rotation22 * src11._positionZ;
  34107. dst1._positionX = __tmp__X1;
  34108. dst1._positionY = __tmp__Y1;
  34109. dst1._positionZ = __tmp__Z1;
  34110. dst1._positionX += tf2._positionX;
  34111. dst1._positionY += tf2._positionY;
  34112. dst1._positionZ += tf2._positionZ;
  34113. let minX;
  34114. let minY;
  34115. let minZ;
  34116. let maxX;
  34117. let maxY;
  34118. let maxZ;
  34119. s._geom._computeAabb(s._aabb,s._ptransform);
  34120. minX = s._aabb._minX;
  34121. minY = s._aabb._minY;
  34122. minZ = s._aabb._minZ;
  34123. maxX = s._aabb._maxX;
  34124. maxY = s._aabb._maxY;
  34125. maxZ = s._aabb._maxZ;
  34126. s._geom._computeAabb(s._aabb,s._transform);
  34127. s._aabb._minX = minX < s._aabb._minX ? minX : s._aabb._minX;
  34128. s._aabb._minY = minY < s._aabb._minY ? minY : s._aabb._minY;
  34129. s._aabb._minZ = minZ < s._aabb._minZ ? minZ : s._aabb._minZ;
  34130. s._aabb._maxX = maxX > s._aabb._maxX ? maxX : s._aabb._maxX;
  34131. s._aabb._maxY = maxY > s._aabb._maxY ? maxY : s._aabb._maxY;
  34132. s._aabb._maxZ = maxZ > s._aabb._maxZ ? maxZ : s._aabb._maxZ;
  34133. if(s._proxy != null) {
  34134. let dX;
  34135. let dY;
  34136. let dZ;
  34137. dX = s._transform._positionX - s._ptransform._positionX;
  34138. dY = s._transform._positionY - s._ptransform._positionY;
  34139. dZ = s._transform._positionZ - s._ptransform._positionZ;
  34140. let v = s.displacement;
  34141. v.x = dX;
  34142. v.y = dY;
  34143. v.z = dZ;
  34144. s._rigidBody._world._broadPhase.moveProxy(s._proxy,s._aabb,s.displacement);
  34145. }
  34146. s = n;
  34147. }
  34148. this._sleeping = false;
  34149. this._sleepTime = 0;
  34150. }
  34151. rotate(rotation) {
  34152. let rot00;
  34153. let rot01;
  34154. let rot02;
  34155. let rot10;
  34156. let rot11;
  34157. let rot12;
  34158. let rot20;
  34159. let rot21;
  34160. let rot22;
  34161. rot00 = rotation.e00;
  34162. rot01 = rotation.e01;
  34163. rot02 = rotation.e02;
  34164. rot10 = rotation.e10;
  34165. rot11 = rotation.e11;
  34166. rot12 = rotation.e12;
  34167. rot20 = rotation.e20;
  34168. rot21 = rotation.e21;
  34169. rot22 = rotation.e22;
  34170. let __tmp__00;
  34171. let __tmp__01;
  34172. let __tmp__02;
  34173. let __tmp__10;
  34174. let __tmp__11;
  34175. let __tmp__12;
  34176. let __tmp__20;
  34177. let __tmp__21;
  34178. let __tmp__22;
  34179. __tmp__00 = rot00 * this._transform._rotation00 + rot01 * this._transform._rotation10 + rot02 * this._transform._rotation20;
  34180. __tmp__01 = rot00 * this._transform._rotation01 + rot01 * this._transform._rotation11 + rot02 * this._transform._rotation21;
  34181. __tmp__02 = rot00 * this._transform._rotation02 + rot01 * this._transform._rotation12 + rot02 * this._transform._rotation22;
  34182. __tmp__10 = rot10 * this._transform._rotation00 + rot11 * this._transform._rotation10 + rot12 * this._transform._rotation20;
  34183. __tmp__11 = rot10 * this._transform._rotation01 + rot11 * this._transform._rotation11 + rot12 * this._transform._rotation21;
  34184. __tmp__12 = rot10 * this._transform._rotation02 + rot11 * this._transform._rotation12 + rot12 * this._transform._rotation22;
  34185. __tmp__20 = rot20 * this._transform._rotation00 + rot21 * this._transform._rotation10 + rot22 * this._transform._rotation20;
  34186. __tmp__21 = rot20 * this._transform._rotation01 + rot21 * this._transform._rotation11 + rot22 * this._transform._rotation21;
  34187. __tmp__22 = rot20 * this._transform._rotation02 + rot21 * this._transform._rotation12 + rot22 * this._transform._rotation22;
  34188. this._transform._rotation00 = __tmp__00;
  34189. this._transform._rotation01 = __tmp__01;
  34190. this._transform._rotation02 = __tmp__02;
  34191. this._transform._rotation10 = __tmp__10;
  34192. this._transform._rotation11 = __tmp__11;
  34193. this._transform._rotation12 = __tmp__12;
  34194. this._transform._rotation20 = __tmp__20;
  34195. this._transform._rotation21 = __tmp__21;
  34196. this._transform._rotation22 = __tmp__22;
  34197. let __tmp__001;
  34198. let __tmp__011;
  34199. let __tmp__021;
  34200. let __tmp__101;
  34201. let __tmp__111;
  34202. let __tmp__121;
  34203. let __tmp__201;
  34204. let __tmp__211;
  34205. let __tmp__221;
  34206. __tmp__001 = this._transform._rotation00 * this._invLocalInertia00 + this._transform._rotation01 * this._invLocalInertia10 + this._transform._rotation02 * this._invLocalInertia20;
  34207. __tmp__011 = this._transform._rotation00 * this._invLocalInertia01 + this._transform._rotation01 * this._invLocalInertia11 + this._transform._rotation02 * this._invLocalInertia21;
  34208. __tmp__021 = this._transform._rotation00 * this._invLocalInertia02 + this._transform._rotation01 * this._invLocalInertia12 + this._transform._rotation02 * this._invLocalInertia22;
  34209. __tmp__101 = this._transform._rotation10 * this._invLocalInertia00 + this._transform._rotation11 * this._invLocalInertia10 + this._transform._rotation12 * this._invLocalInertia20;
  34210. __tmp__111 = this._transform._rotation10 * this._invLocalInertia01 + this._transform._rotation11 * this._invLocalInertia11 + this._transform._rotation12 * this._invLocalInertia21;
  34211. __tmp__121 = this._transform._rotation10 * this._invLocalInertia02 + this._transform._rotation11 * this._invLocalInertia12 + this._transform._rotation12 * this._invLocalInertia22;
  34212. __tmp__201 = this._transform._rotation20 * this._invLocalInertia00 + this._transform._rotation21 * this._invLocalInertia10 + this._transform._rotation22 * this._invLocalInertia20;
  34213. __tmp__211 = this._transform._rotation20 * this._invLocalInertia01 + this._transform._rotation21 * this._invLocalInertia11 + this._transform._rotation22 * this._invLocalInertia21;
  34214. __tmp__221 = this._transform._rotation20 * this._invLocalInertia02 + this._transform._rotation21 * this._invLocalInertia12 + this._transform._rotation22 * this._invLocalInertia22;
  34215. this._invInertia00 = __tmp__001;
  34216. this._invInertia01 = __tmp__011;
  34217. this._invInertia02 = __tmp__021;
  34218. this._invInertia10 = __tmp__101;
  34219. this._invInertia11 = __tmp__111;
  34220. this._invInertia12 = __tmp__121;
  34221. this._invInertia20 = __tmp__201;
  34222. this._invInertia21 = __tmp__211;
  34223. this._invInertia22 = __tmp__221;
  34224. let __tmp__002;
  34225. let __tmp__012;
  34226. let __tmp__022;
  34227. let __tmp__102;
  34228. let __tmp__112;
  34229. let __tmp__122;
  34230. let __tmp__202;
  34231. let __tmp__212;
  34232. let __tmp__222;
  34233. __tmp__002 = this._invInertia00 * this._transform._rotation00 + this._invInertia01 * this._transform._rotation01 + this._invInertia02 * this._transform._rotation02;
  34234. __tmp__012 = this._invInertia00 * this._transform._rotation10 + this._invInertia01 * this._transform._rotation11 + this._invInertia02 * this._transform._rotation12;
  34235. __tmp__022 = this._invInertia00 * this._transform._rotation20 + this._invInertia01 * this._transform._rotation21 + this._invInertia02 * this._transform._rotation22;
  34236. __tmp__102 = this._invInertia10 * this._transform._rotation00 + this._invInertia11 * this._transform._rotation01 + this._invInertia12 * this._transform._rotation02;
  34237. __tmp__112 = this._invInertia10 * this._transform._rotation10 + this._invInertia11 * this._transform._rotation11 + this._invInertia12 * this._transform._rotation12;
  34238. __tmp__122 = this._invInertia10 * this._transform._rotation20 + this._invInertia11 * this._transform._rotation21 + this._invInertia12 * this._transform._rotation22;
  34239. __tmp__202 = this._invInertia20 * this._transform._rotation00 + this._invInertia21 * this._transform._rotation01 + this._invInertia22 * this._transform._rotation02;
  34240. __tmp__212 = this._invInertia20 * this._transform._rotation10 + this._invInertia21 * this._transform._rotation11 + this._invInertia22 * this._transform._rotation12;
  34241. __tmp__222 = this._invInertia20 * this._transform._rotation20 + this._invInertia21 * this._transform._rotation21 + this._invInertia22 * this._transform._rotation22;
  34242. this._invInertia00 = __tmp__002;
  34243. this._invInertia01 = __tmp__012;
  34244. this._invInertia02 = __tmp__022;
  34245. this._invInertia10 = __tmp__102;
  34246. this._invInertia11 = __tmp__112;
  34247. this._invInertia12 = __tmp__122;
  34248. this._invInertia20 = __tmp__202;
  34249. this._invInertia21 = __tmp__212;
  34250. this._invInertia22 = __tmp__222;
  34251. this._invInertia00 *= this._rotFactor.x;
  34252. this._invInertia01 *= this._rotFactor.x;
  34253. this._invInertia02 *= this._rotFactor.x;
  34254. this._invInertia10 *= this._rotFactor.y;
  34255. this._invInertia11 *= this._rotFactor.y;
  34256. this._invInertia12 *= this._rotFactor.y;
  34257. this._invInertia20 *= this._rotFactor.z;
  34258. this._invInertia21 *= this._rotFactor.z;
  34259. this._invInertia22 *= this._rotFactor.z;
  34260. let dst = this._ptransform;
  34261. let src = this._transform;
  34262. dst._positionX = src._positionX;
  34263. dst._positionY = src._positionY;
  34264. dst._positionZ = src._positionZ;
  34265. dst._rotation00 = src._rotation00;
  34266. dst._rotation01 = src._rotation01;
  34267. dst._rotation02 = src._rotation02;
  34268. dst._rotation10 = src._rotation10;
  34269. dst._rotation11 = src._rotation11;
  34270. dst._rotation12 = src._rotation12;
  34271. dst._rotation20 = src._rotation20;
  34272. dst._rotation21 = src._rotation21;
  34273. dst._rotation22 = src._rotation22;
  34274. let s = this._shapeList;
  34275. while(s != null) {
  34276. let n = s._next;
  34277. let tf1 = this._ptransform;
  34278. let tf2 = this._transform;
  34279. let dst = s._ptransform;
  34280. let src1 = s._localTransform;
  34281. let __tmp__00;
  34282. let __tmp__01;
  34283. let __tmp__02;
  34284. let __tmp__10;
  34285. let __tmp__11;
  34286. let __tmp__12;
  34287. let __tmp__20;
  34288. let __tmp__21;
  34289. let __tmp__22;
  34290. __tmp__00 = tf1._rotation00 * src1._rotation00 + tf1._rotation01 * src1._rotation10 + tf1._rotation02 * src1._rotation20;
  34291. __tmp__01 = tf1._rotation00 * src1._rotation01 + tf1._rotation01 * src1._rotation11 + tf1._rotation02 * src1._rotation21;
  34292. __tmp__02 = tf1._rotation00 * src1._rotation02 + tf1._rotation01 * src1._rotation12 + tf1._rotation02 * src1._rotation22;
  34293. __tmp__10 = tf1._rotation10 * src1._rotation00 + tf1._rotation11 * src1._rotation10 + tf1._rotation12 * src1._rotation20;
  34294. __tmp__11 = tf1._rotation10 * src1._rotation01 + tf1._rotation11 * src1._rotation11 + tf1._rotation12 * src1._rotation21;
  34295. __tmp__12 = tf1._rotation10 * src1._rotation02 + tf1._rotation11 * src1._rotation12 + tf1._rotation12 * src1._rotation22;
  34296. __tmp__20 = tf1._rotation20 * src1._rotation00 + tf1._rotation21 * src1._rotation10 + tf1._rotation22 * src1._rotation20;
  34297. __tmp__21 = tf1._rotation20 * src1._rotation01 + tf1._rotation21 * src1._rotation11 + tf1._rotation22 * src1._rotation21;
  34298. __tmp__22 = tf1._rotation20 * src1._rotation02 + tf1._rotation21 * src1._rotation12 + tf1._rotation22 * src1._rotation22;
  34299. dst._rotation00 = __tmp__00;
  34300. dst._rotation01 = __tmp__01;
  34301. dst._rotation02 = __tmp__02;
  34302. dst._rotation10 = __tmp__10;
  34303. dst._rotation11 = __tmp__11;
  34304. dst._rotation12 = __tmp__12;
  34305. dst._rotation20 = __tmp__20;
  34306. dst._rotation21 = __tmp__21;
  34307. dst._rotation22 = __tmp__22;
  34308. let __tmp__X;
  34309. let __tmp__Y;
  34310. let __tmp__Z;
  34311. __tmp__X = tf1._rotation00 * src1._positionX + tf1._rotation01 * src1._positionY + tf1._rotation02 * src1._positionZ;
  34312. __tmp__Y = tf1._rotation10 * src1._positionX + tf1._rotation11 * src1._positionY + tf1._rotation12 * src1._positionZ;
  34313. __tmp__Z = tf1._rotation20 * src1._positionX + tf1._rotation21 * src1._positionY + tf1._rotation22 * src1._positionZ;
  34314. dst._positionX = __tmp__X;
  34315. dst._positionY = __tmp__Y;
  34316. dst._positionZ = __tmp__Z;
  34317. dst._positionX += tf1._positionX;
  34318. dst._positionY += tf1._positionY;
  34319. dst._positionZ += tf1._positionZ;
  34320. let dst1 = s._transform;
  34321. let src11 = s._localTransform;
  34322. let __tmp__001;
  34323. let __tmp__011;
  34324. let __tmp__021;
  34325. let __tmp__101;
  34326. let __tmp__111;
  34327. let __tmp__121;
  34328. let __tmp__201;
  34329. let __tmp__211;
  34330. let __tmp__221;
  34331. __tmp__001 = tf2._rotation00 * src11._rotation00 + tf2._rotation01 * src11._rotation10 + tf2._rotation02 * src11._rotation20;
  34332. __tmp__011 = tf2._rotation00 * src11._rotation01 + tf2._rotation01 * src11._rotation11 + tf2._rotation02 * src11._rotation21;
  34333. __tmp__021 = tf2._rotation00 * src11._rotation02 + tf2._rotation01 * src11._rotation12 + tf2._rotation02 * src11._rotation22;
  34334. __tmp__101 = tf2._rotation10 * src11._rotation00 + tf2._rotation11 * src11._rotation10 + tf2._rotation12 * src11._rotation20;
  34335. __tmp__111 = tf2._rotation10 * src11._rotation01 + tf2._rotation11 * src11._rotation11 + tf2._rotation12 * src11._rotation21;
  34336. __tmp__121 = tf2._rotation10 * src11._rotation02 + tf2._rotation11 * src11._rotation12 + tf2._rotation12 * src11._rotation22;
  34337. __tmp__201 = tf2._rotation20 * src11._rotation00 + tf2._rotation21 * src11._rotation10 + tf2._rotation22 * src11._rotation20;
  34338. __tmp__211 = tf2._rotation20 * src11._rotation01 + tf2._rotation21 * src11._rotation11 + tf2._rotation22 * src11._rotation21;
  34339. __tmp__221 = tf2._rotation20 * src11._rotation02 + tf2._rotation21 * src11._rotation12 + tf2._rotation22 * src11._rotation22;
  34340. dst1._rotation00 = __tmp__001;
  34341. dst1._rotation01 = __tmp__011;
  34342. dst1._rotation02 = __tmp__021;
  34343. dst1._rotation10 = __tmp__101;
  34344. dst1._rotation11 = __tmp__111;
  34345. dst1._rotation12 = __tmp__121;
  34346. dst1._rotation20 = __tmp__201;
  34347. dst1._rotation21 = __tmp__211;
  34348. dst1._rotation22 = __tmp__221;
  34349. let __tmp__X1;
  34350. let __tmp__Y1;
  34351. let __tmp__Z1;
  34352. __tmp__X1 = tf2._rotation00 * src11._positionX + tf2._rotation01 * src11._positionY + tf2._rotation02 * src11._positionZ;
  34353. __tmp__Y1 = tf2._rotation10 * src11._positionX + tf2._rotation11 * src11._positionY + tf2._rotation12 * src11._positionZ;
  34354. __tmp__Z1 = tf2._rotation20 * src11._positionX + tf2._rotation21 * src11._positionY + tf2._rotation22 * src11._positionZ;
  34355. dst1._positionX = __tmp__X1;
  34356. dst1._positionY = __tmp__Y1;
  34357. dst1._positionZ = __tmp__Z1;
  34358. dst1._positionX += tf2._positionX;
  34359. dst1._positionY += tf2._positionY;
  34360. dst1._positionZ += tf2._positionZ;
  34361. let minX;
  34362. let minY;
  34363. let minZ;
  34364. let maxX;
  34365. let maxY;
  34366. let maxZ;
  34367. s._geom._computeAabb(s._aabb,s._ptransform);
  34368. minX = s._aabb._minX;
  34369. minY = s._aabb._minY;
  34370. minZ = s._aabb._minZ;
  34371. maxX = s._aabb._maxX;
  34372. maxY = s._aabb._maxY;
  34373. maxZ = s._aabb._maxZ;
  34374. s._geom._computeAabb(s._aabb,s._transform);
  34375. s._aabb._minX = minX < s._aabb._minX ? minX : s._aabb._minX;
  34376. s._aabb._minY = minY < s._aabb._minY ? minY : s._aabb._minY;
  34377. s._aabb._minZ = minZ < s._aabb._minZ ? minZ : s._aabb._minZ;
  34378. s._aabb._maxX = maxX > s._aabb._maxX ? maxX : s._aabb._maxX;
  34379. s._aabb._maxY = maxY > s._aabb._maxY ? maxY : s._aabb._maxY;
  34380. s._aabb._maxZ = maxZ > s._aabb._maxZ ? maxZ : s._aabb._maxZ;
  34381. if(s._proxy != null) {
  34382. let dX;
  34383. let dY;
  34384. let dZ;
  34385. dX = s._transform._positionX - s._ptransform._positionX;
  34386. dY = s._transform._positionY - s._ptransform._positionY;
  34387. dZ = s._transform._positionZ - s._ptransform._positionZ;
  34388. let v = s.displacement;
  34389. v.x = dX;
  34390. v.y = dY;
  34391. v.z = dZ;
  34392. s._rigidBody._world._broadPhase.moveProxy(s._proxy,s._aabb,s.displacement);
  34393. }
  34394. s = n;
  34395. }
  34396. this._sleeping = false;
  34397. this._sleepTime = 0;
  34398. }
  34399. rotateXyz(eulerAngles) {
  34400. let xyzX;
  34401. let xyzY;
  34402. let xyzZ;
  34403. let rot00;
  34404. let rot01;
  34405. let rot02;
  34406. let rot10;
  34407. let rot11;
  34408. let rot12;
  34409. let rot20;
  34410. let rot21;
  34411. let rot22;
  34412. xyzX = eulerAngles.x;
  34413. xyzY = eulerAngles.y;
  34414. xyzZ = eulerAngles.z;
  34415. let sx = Math.sin(xyzX);
  34416. let sy = Math.sin(xyzY);
  34417. let sz = Math.sin(xyzZ);
  34418. let cx = Math.cos(xyzX);
  34419. let cy = Math.cos(xyzY);
  34420. let cz = Math.cos(xyzZ);
  34421. rot00 = cy * cz;
  34422. rot01 = -cy * sz;
  34423. rot02 = sy;
  34424. rot10 = cx * sz + cz * sx * sy;
  34425. rot11 = cx * cz - sx * sy * sz;
  34426. rot12 = -cy * sx;
  34427. rot20 = sx * sz - cx * cz * sy;
  34428. rot21 = cz * sx + cx * sy * sz;
  34429. rot22 = cx * cy;
  34430. let __tmp__00;
  34431. let __tmp__01;
  34432. let __tmp__02;
  34433. let __tmp__10;
  34434. let __tmp__11;
  34435. let __tmp__12;
  34436. let __tmp__20;
  34437. let __tmp__21;
  34438. let __tmp__22;
  34439. __tmp__00 = rot00 * this._transform._rotation00 + rot01 * this._transform._rotation10 + rot02 * this._transform._rotation20;
  34440. __tmp__01 = rot00 * this._transform._rotation01 + rot01 * this._transform._rotation11 + rot02 * this._transform._rotation21;
  34441. __tmp__02 = rot00 * this._transform._rotation02 + rot01 * this._transform._rotation12 + rot02 * this._transform._rotation22;
  34442. __tmp__10 = rot10 * this._transform._rotation00 + rot11 * this._transform._rotation10 + rot12 * this._transform._rotation20;
  34443. __tmp__11 = rot10 * this._transform._rotation01 + rot11 * this._transform._rotation11 + rot12 * this._transform._rotation21;
  34444. __tmp__12 = rot10 * this._transform._rotation02 + rot11 * this._transform._rotation12 + rot12 * this._transform._rotation22;
  34445. __tmp__20 = rot20 * this._transform._rotation00 + rot21 * this._transform._rotation10 + rot22 * this._transform._rotation20;
  34446. __tmp__21 = rot20 * this._transform._rotation01 + rot21 * this._transform._rotation11 + rot22 * this._transform._rotation21;
  34447. __tmp__22 = rot20 * this._transform._rotation02 + rot21 * this._transform._rotation12 + rot22 * this._transform._rotation22;
  34448. this._transform._rotation00 = __tmp__00;
  34449. this._transform._rotation01 = __tmp__01;
  34450. this._transform._rotation02 = __tmp__02;
  34451. this._transform._rotation10 = __tmp__10;
  34452. this._transform._rotation11 = __tmp__11;
  34453. this._transform._rotation12 = __tmp__12;
  34454. this._transform._rotation20 = __tmp__20;
  34455. this._transform._rotation21 = __tmp__21;
  34456. this._transform._rotation22 = __tmp__22;
  34457. let __tmp__001;
  34458. let __tmp__011;
  34459. let __tmp__021;
  34460. let __tmp__101;
  34461. let __tmp__111;
  34462. let __tmp__121;
  34463. let __tmp__201;
  34464. let __tmp__211;
  34465. let __tmp__221;
  34466. __tmp__001 = this._transform._rotation00 * this._invLocalInertia00 + this._transform._rotation01 * this._invLocalInertia10 + this._transform._rotation02 * this._invLocalInertia20;
  34467. __tmp__011 = this._transform._rotation00 * this._invLocalInertia01 + this._transform._rotation01 * this._invLocalInertia11 + this._transform._rotation02 * this._invLocalInertia21;
  34468. __tmp__021 = this._transform._rotation00 * this._invLocalInertia02 + this._transform._rotation01 * this._invLocalInertia12 + this._transform._rotation02 * this._invLocalInertia22;
  34469. __tmp__101 = this._transform._rotation10 * this._invLocalInertia00 + this._transform._rotation11 * this._invLocalInertia10 + this._transform._rotation12 * this._invLocalInertia20;
  34470. __tmp__111 = this._transform._rotation10 * this._invLocalInertia01 + this._transform._rotation11 * this._invLocalInertia11 + this._transform._rotation12 * this._invLocalInertia21;
  34471. __tmp__121 = this._transform._rotation10 * this._invLocalInertia02 + this._transform._rotation11 * this._invLocalInertia12 + this._transform._rotation12 * this._invLocalInertia22;
  34472. __tmp__201 = this._transform._rotation20 * this._invLocalInertia00 + this._transform._rotation21 * this._invLocalInertia10 + this._transform._rotation22 * this._invLocalInertia20;
  34473. __tmp__211 = this._transform._rotation20 * this._invLocalInertia01 + this._transform._rotation21 * this._invLocalInertia11 + this._transform._rotation22 * this._invLocalInertia21;
  34474. __tmp__221 = this._transform._rotation20 * this._invLocalInertia02 + this._transform._rotation21 * this._invLocalInertia12 + this._transform._rotation22 * this._invLocalInertia22;
  34475. this._invInertia00 = __tmp__001;
  34476. this._invInertia01 = __tmp__011;
  34477. this._invInertia02 = __tmp__021;
  34478. this._invInertia10 = __tmp__101;
  34479. this._invInertia11 = __tmp__111;
  34480. this._invInertia12 = __tmp__121;
  34481. this._invInertia20 = __tmp__201;
  34482. this._invInertia21 = __tmp__211;
  34483. this._invInertia22 = __tmp__221;
  34484. let __tmp__002;
  34485. let __tmp__012;
  34486. let __tmp__022;
  34487. let __tmp__102;
  34488. let __tmp__112;
  34489. let __tmp__122;
  34490. let __tmp__202;
  34491. let __tmp__212;
  34492. let __tmp__222;
  34493. __tmp__002 = this._invInertia00 * this._transform._rotation00 + this._invInertia01 * this._transform._rotation01 + this._invInertia02 * this._transform._rotation02;
  34494. __tmp__012 = this._invInertia00 * this._transform._rotation10 + this._invInertia01 * this._transform._rotation11 + this._invInertia02 * this._transform._rotation12;
  34495. __tmp__022 = this._invInertia00 * this._transform._rotation20 + this._invInertia01 * this._transform._rotation21 + this._invInertia02 * this._transform._rotation22;
  34496. __tmp__102 = this._invInertia10 * this._transform._rotation00 + this._invInertia11 * this._transform._rotation01 + this._invInertia12 * this._transform._rotation02;
  34497. __tmp__112 = this._invInertia10 * this._transform._rotation10 + this._invInertia11 * this._transform._rotation11 + this._invInertia12 * this._transform._rotation12;
  34498. __tmp__122 = this._invInertia10 * this._transform._rotation20 + this._invInertia11 * this._transform._rotation21 + this._invInertia12 * this._transform._rotation22;
  34499. __tmp__202 = this._invInertia20 * this._transform._rotation00 + this._invInertia21 * this._transform._rotation01 + this._invInertia22 * this._transform._rotation02;
  34500. __tmp__212 = this._invInertia20 * this._transform._rotation10 + this._invInertia21 * this._transform._rotation11 + this._invInertia22 * this._transform._rotation12;
  34501. __tmp__222 = this._invInertia20 * this._transform._rotation20 + this._invInertia21 * this._transform._rotation21 + this._invInertia22 * this._transform._rotation22;
  34502. this._invInertia00 = __tmp__002;
  34503. this._invInertia01 = __tmp__012;
  34504. this._invInertia02 = __tmp__022;
  34505. this._invInertia10 = __tmp__102;
  34506. this._invInertia11 = __tmp__112;
  34507. this._invInertia12 = __tmp__122;
  34508. this._invInertia20 = __tmp__202;
  34509. this._invInertia21 = __tmp__212;
  34510. this._invInertia22 = __tmp__222;
  34511. this._invInertia00 *= this._rotFactor.x;
  34512. this._invInertia01 *= this._rotFactor.x;
  34513. this._invInertia02 *= this._rotFactor.x;
  34514. this._invInertia10 *= this._rotFactor.y;
  34515. this._invInertia11 *= this._rotFactor.y;
  34516. this._invInertia12 *= this._rotFactor.y;
  34517. this._invInertia20 *= this._rotFactor.z;
  34518. this._invInertia21 *= this._rotFactor.z;
  34519. this._invInertia22 *= this._rotFactor.z;
  34520. let dst = this._ptransform;
  34521. let src = this._transform;
  34522. dst._positionX = src._positionX;
  34523. dst._positionY = src._positionY;
  34524. dst._positionZ = src._positionZ;
  34525. dst._rotation00 = src._rotation00;
  34526. dst._rotation01 = src._rotation01;
  34527. dst._rotation02 = src._rotation02;
  34528. dst._rotation10 = src._rotation10;
  34529. dst._rotation11 = src._rotation11;
  34530. dst._rotation12 = src._rotation12;
  34531. dst._rotation20 = src._rotation20;
  34532. dst._rotation21 = src._rotation21;
  34533. dst._rotation22 = src._rotation22;
  34534. let s = this._shapeList;
  34535. while(s != null) {
  34536. let n = s._next;
  34537. let tf1 = this._ptransform;
  34538. let tf2 = this._transform;
  34539. let dst = s._ptransform;
  34540. let src1 = s._localTransform;
  34541. let __tmp__00;
  34542. let __tmp__01;
  34543. let __tmp__02;
  34544. let __tmp__10;
  34545. let __tmp__11;
  34546. let __tmp__12;
  34547. let __tmp__20;
  34548. let __tmp__21;
  34549. let __tmp__22;
  34550. __tmp__00 = tf1._rotation00 * src1._rotation00 + tf1._rotation01 * src1._rotation10 + tf1._rotation02 * src1._rotation20;
  34551. __tmp__01 = tf1._rotation00 * src1._rotation01 + tf1._rotation01 * src1._rotation11 + tf1._rotation02 * src1._rotation21;
  34552. __tmp__02 = tf1._rotation00 * src1._rotation02 + tf1._rotation01 * src1._rotation12 + tf1._rotation02 * src1._rotation22;
  34553. __tmp__10 = tf1._rotation10 * src1._rotation00 + tf1._rotation11 * src1._rotation10 + tf1._rotation12 * src1._rotation20;
  34554. __tmp__11 = tf1._rotation10 * src1._rotation01 + tf1._rotation11 * src1._rotation11 + tf1._rotation12 * src1._rotation21;
  34555. __tmp__12 = tf1._rotation10 * src1._rotation02 + tf1._rotation11 * src1._rotation12 + tf1._rotation12 * src1._rotation22;
  34556. __tmp__20 = tf1._rotation20 * src1._rotation00 + tf1._rotation21 * src1._rotation10 + tf1._rotation22 * src1._rotation20;
  34557. __tmp__21 = tf1._rotation20 * src1._rotation01 + tf1._rotation21 * src1._rotation11 + tf1._rotation22 * src1._rotation21;
  34558. __tmp__22 = tf1._rotation20 * src1._rotation02 + tf1._rotation21 * src1._rotation12 + tf1._rotation22 * src1._rotation22;
  34559. dst._rotation00 = __tmp__00;
  34560. dst._rotation01 = __tmp__01;
  34561. dst._rotation02 = __tmp__02;
  34562. dst._rotation10 = __tmp__10;
  34563. dst._rotation11 = __tmp__11;
  34564. dst._rotation12 = __tmp__12;
  34565. dst._rotation20 = __tmp__20;
  34566. dst._rotation21 = __tmp__21;
  34567. dst._rotation22 = __tmp__22;
  34568. let __tmp__X;
  34569. let __tmp__Y;
  34570. let __tmp__Z;
  34571. __tmp__X = tf1._rotation00 * src1._positionX + tf1._rotation01 * src1._positionY + tf1._rotation02 * src1._positionZ;
  34572. __tmp__Y = tf1._rotation10 * src1._positionX + tf1._rotation11 * src1._positionY + tf1._rotation12 * src1._positionZ;
  34573. __tmp__Z = tf1._rotation20 * src1._positionX + tf1._rotation21 * src1._positionY + tf1._rotation22 * src1._positionZ;
  34574. dst._positionX = __tmp__X;
  34575. dst._positionY = __tmp__Y;
  34576. dst._positionZ = __tmp__Z;
  34577. dst._positionX += tf1._positionX;
  34578. dst._positionY += tf1._positionY;
  34579. dst._positionZ += tf1._positionZ;
  34580. let dst1 = s._transform;
  34581. let src11 = s._localTransform;
  34582. let __tmp__001;
  34583. let __tmp__011;
  34584. let __tmp__021;
  34585. let __tmp__101;
  34586. let __tmp__111;
  34587. let __tmp__121;
  34588. let __tmp__201;
  34589. let __tmp__211;
  34590. let __tmp__221;
  34591. __tmp__001 = tf2._rotation00 * src11._rotation00 + tf2._rotation01 * src11._rotation10 + tf2._rotation02 * src11._rotation20;
  34592. __tmp__011 = tf2._rotation00 * src11._rotation01 + tf2._rotation01 * src11._rotation11 + tf2._rotation02 * src11._rotation21;
  34593. __tmp__021 = tf2._rotation00 * src11._rotation02 + tf2._rotation01 * src11._rotation12 + tf2._rotation02 * src11._rotation22;
  34594. __tmp__101 = tf2._rotation10 * src11._rotation00 + tf2._rotation11 * src11._rotation10 + tf2._rotation12 * src11._rotation20;
  34595. __tmp__111 = tf2._rotation10 * src11._rotation01 + tf2._rotation11 * src11._rotation11 + tf2._rotation12 * src11._rotation21;
  34596. __tmp__121 = tf2._rotation10 * src11._rotation02 + tf2._rotation11 * src11._rotation12 + tf2._rotation12 * src11._rotation22;
  34597. __tmp__201 = tf2._rotation20 * src11._rotation00 + tf2._rotation21 * src11._rotation10 + tf2._rotation22 * src11._rotation20;
  34598. __tmp__211 = tf2._rotation20 * src11._rotation01 + tf2._rotation21 * src11._rotation11 + tf2._rotation22 * src11._rotation21;
  34599. __tmp__221 = tf2._rotation20 * src11._rotation02 + tf2._rotation21 * src11._rotation12 + tf2._rotation22 * src11._rotation22;
  34600. dst1._rotation00 = __tmp__001;
  34601. dst1._rotation01 = __tmp__011;
  34602. dst1._rotation02 = __tmp__021;
  34603. dst1._rotation10 = __tmp__101;
  34604. dst1._rotation11 = __tmp__111;
  34605. dst1._rotation12 = __tmp__121;
  34606. dst1._rotation20 = __tmp__201;
  34607. dst1._rotation21 = __tmp__211;
  34608. dst1._rotation22 = __tmp__221;
  34609. let __tmp__X1;
  34610. let __tmp__Y1;
  34611. let __tmp__Z1;
  34612. __tmp__X1 = tf2._rotation00 * src11._positionX + tf2._rotation01 * src11._positionY + tf2._rotation02 * src11._positionZ;
  34613. __tmp__Y1 = tf2._rotation10 * src11._positionX + tf2._rotation11 * src11._positionY + tf2._rotation12 * src11._positionZ;
  34614. __tmp__Z1 = tf2._rotation20 * src11._positionX + tf2._rotation21 * src11._positionY + tf2._rotation22 * src11._positionZ;
  34615. dst1._positionX = __tmp__X1;
  34616. dst1._positionY = __tmp__Y1;
  34617. dst1._positionZ = __tmp__Z1;
  34618. dst1._positionX += tf2._positionX;
  34619. dst1._positionY += tf2._positionY;
  34620. dst1._positionZ += tf2._positionZ;
  34621. let minX;
  34622. let minY;
  34623. let minZ;
  34624. let maxX;
  34625. let maxY;
  34626. let maxZ;
  34627. s._geom._computeAabb(s._aabb,s._ptransform);
  34628. minX = s._aabb._minX;
  34629. minY = s._aabb._minY;
  34630. minZ = s._aabb._minZ;
  34631. maxX = s._aabb._maxX;
  34632. maxY = s._aabb._maxY;
  34633. maxZ = s._aabb._maxZ;
  34634. s._geom._computeAabb(s._aabb,s._transform);
  34635. s._aabb._minX = minX < s._aabb._minX ? minX : s._aabb._minX;
  34636. s._aabb._minY = minY < s._aabb._minY ? minY : s._aabb._minY;
  34637. s._aabb._minZ = minZ < s._aabb._minZ ? minZ : s._aabb._minZ;
  34638. s._aabb._maxX = maxX > s._aabb._maxX ? maxX : s._aabb._maxX;
  34639. s._aabb._maxY = maxY > s._aabb._maxY ? maxY : s._aabb._maxY;
  34640. s._aabb._maxZ = maxZ > s._aabb._maxZ ? maxZ : s._aabb._maxZ;
  34641. if(s._proxy != null) {
  34642. let dX;
  34643. let dY;
  34644. let dZ;
  34645. dX = s._transform._positionX - s._ptransform._positionX;
  34646. dY = s._transform._positionY - s._ptransform._positionY;
  34647. dZ = s._transform._positionZ - s._ptransform._positionZ;
  34648. let v = s.displacement;
  34649. v.x = dX;
  34650. v.y = dY;
  34651. v.z = dZ;
  34652. s._rigidBody._world._broadPhase.moveProxy(s._proxy,s._aabb,s.displacement);
  34653. }
  34654. s = n;
  34655. }
  34656. this._sleeping = false;
  34657. this._sleepTime = 0;
  34658. }
  34659. getOrientation() {
  34660. let q = new oimo.common.Quat();
  34661. let iqX;
  34662. let iqY;
  34663. let iqZ;
  34664. let iqW;
  34665. let e00 = this._transform._rotation00;
  34666. let e11 = this._transform._rotation11;
  34667. let e22 = this._transform._rotation22;
  34668. let t = e00 + e11 + e22;
  34669. let s;
  34670. if(t > 0) {
  34671. s = Math.sqrt(t + 1);
  34672. iqW = 0.5 * s;
  34673. s = 0.5 / s;
  34674. iqX = (this._transform._rotation21 - this._transform._rotation12) * s;
  34675. iqY = (this._transform._rotation02 - this._transform._rotation20) * s;
  34676. iqZ = (this._transform._rotation10 - this._transform._rotation01) * s;
  34677. } else if(e00 > e11) {
  34678. if(e00 > e22) {
  34679. s = Math.sqrt(e00 - e11 - e22 + 1);
  34680. iqX = 0.5 * s;
  34681. s = 0.5 / s;
  34682. iqY = (this._transform._rotation01 + this._transform._rotation10) * s;
  34683. iqZ = (this._transform._rotation02 + this._transform._rotation20) * s;
  34684. iqW = (this._transform._rotation21 - this._transform._rotation12) * s;
  34685. } else {
  34686. s = Math.sqrt(e22 - e00 - e11 + 1);
  34687. iqZ = 0.5 * s;
  34688. s = 0.5 / s;
  34689. iqX = (this._transform._rotation02 + this._transform._rotation20) * s;
  34690. iqY = (this._transform._rotation12 + this._transform._rotation21) * s;
  34691. iqW = (this._transform._rotation10 - this._transform._rotation01) * s;
  34692. }
  34693. } else if(e11 > e22) {
  34694. s = Math.sqrt(e11 - e22 - e00 + 1);
  34695. iqY = 0.5 * s;
  34696. s = 0.5 / s;
  34697. iqX = (this._transform._rotation01 + this._transform._rotation10) * s;
  34698. iqZ = (this._transform._rotation12 + this._transform._rotation21) * s;
  34699. iqW = (this._transform._rotation02 - this._transform._rotation20) * s;
  34700. } else {
  34701. s = Math.sqrt(e22 - e00 - e11 + 1);
  34702. iqZ = 0.5 * s;
  34703. s = 0.5 / s;
  34704. iqX = (this._transform._rotation02 + this._transform._rotation20) * s;
  34705. iqY = (this._transform._rotation12 + this._transform._rotation21) * s;
  34706. iqW = (this._transform._rotation10 - this._transform._rotation01) * s;
  34707. }
  34708. q.x = iqX;
  34709. q.y = iqY;
  34710. q.z = iqZ;
  34711. q.w = iqW;
  34712. return q;
  34713. }
  34714. getOrientationTo(orientation) {
  34715. let iqX;
  34716. let iqY;
  34717. let iqZ;
  34718. let iqW;
  34719. let e00 = this._transform._rotation00;
  34720. let e11 = this._transform._rotation11;
  34721. let e22 = this._transform._rotation22;
  34722. let t = e00 + e11 + e22;
  34723. let s;
  34724. if(t > 0) {
  34725. s = Math.sqrt(t + 1);
  34726. iqW = 0.5 * s;
  34727. s = 0.5 / s;
  34728. iqX = (this._transform._rotation21 - this._transform._rotation12) * s;
  34729. iqY = (this._transform._rotation02 - this._transform._rotation20) * s;
  34730. iqZ = (this._transform._rotation10 - this._transform._rotation01) * s;
  34731. } else if(e00 > e11) {
  34732. if(e00 > e22) {
  34733. s = Math.sqrt(e00 - e11 - e22 + 1);
  34734. iqX = 0.5 * s;
  34735. s = 0.5 / s;
  34736. iqY = (this._transform._rotation01 + this._transform._rotation10) * s;
  34737. iqZ = (this._transform._rotation02 + this._transform._rotation20) * s;
  34738. iqW = (this._transform._rotation21 - this._transform._rotation12) * s;
  34739. } else {
  34740. s = Math.sqrt(e22 - e00 - e11 + 1);
  34741. iqZ = 0.5 * s;
  34742. s = 0.5 / s;
  34743. iqX = (this._transform._rotation02 + this._transform._rotation20) * s;
  34744. iqY = (this._transform._rotation12 + this._transform._rotation21) * s;
  34745. iqW = (this._transform._rotation10 - this._transform._rotation01) * s;
  34746. }
  34747. } else if(e11 > e22) {
  34748. s = Math.sqrt(e11 - e22 - e00 + 1);
  34749. iqY = 0.5 * s;
  34750. s = 0.5 / s;
  34751. iqX = (this._transform._rotation01 + this._transform._rotation10) * s;
  34752. iqZ = (this._transform._rotation12 + this._transform._rotation21) * s;
  34753. iqW = (this._transform._rotation02 - this._transform._rotation20) * s;
  34754. } else {
  34755. s = Math.sqrt(e22 - e00 - e11 + 1);
  34756. iqZ = 0.5 * s;
  34757. s = 0.5 / s;
  34758. iqX = (this._transform._rotation02 + this._transform._rotation20) * s;
  34759. iqY = (this._transform._rotation12 + this._transform._rotation21) * s;
  34760. iqW = (this._transform._rotation10 - this._transform._rotation01) * s;
  34761. }
  34762. orientation.x = iqX;
  34763. orientation.y = iqY;
  34764. orientation.z = iqZ;
  34765. orientation.w = iqW;
  34766. }
  34767. setOrientation(quaternion) {
  34768. let qX;
  34769. let qY;
  34770. let qZ;
  34771. let qW;
  34772. qX = quaternion.x;
  34773. qY = quaternion.y;
  34774. qZ = quaternion.z;
  34775. qW = quaternion.w;
  34776. let x = qX;
  34777. let y = qY;
  34778. let z = qZ;
  34779. let w = qW;
  34780. let x2 = 2 * x;
  34781. let y2 = 2 * y;
  34782. let z2 = 2 * z;
  34783. let xx = x * x2;
  34784. let yy = y * y2;
  34785. let zz = z * z2;
  34786. let xy = x * y2;
  34787. let yz = y * z2;
  34788. let xz = x * z2;
  34789. let wx = w * x2;
  34790. let wy = w * y2;
  34791. let wz = w * z2;
  34792. this._transform._rotation00 = 1 - yy - zz;
  34793. this._transform._rotation01 = xy - wz;
  34794. this._transform._rotation02 = xz + wy;
  34795. this._transform._rotation10 = xy + wz;
  34796. this._transform._rotation11 = 1 - xx - zz;
  34797. this._transform._rotation12 = yz - wx;
  34798. this._transform._rotation20 = xz - wy;
  34799. this._transform._rotation21 = yz + wx;
  34800. this._transform._rotation22 = 1 - xx - yy;
  34801. let __tmp__00;
  34802. let __tmp__01;
  34803. let __tmp__02;
  34804. let __tmp__10;
  34805. let __tmp__11;
  34806. let __tmp__12;
  34807. let __tmp__20;
  34808. let __tmp__21;
  34809. let __tmp__22;
  34810. __tmp__00 = this._transform._rotation00 * this._invLocalInertia00 + this._transform._rotation01 * this._invLocalInertia10 + this._transform._rotation02 * this._invLocalInertia20;
  34811. __tmp__01 = this._transform._rotation00 * this._invLocalInertia01 + this._transform._rotation01 * this._invLocalInertia11 + this._transform._rotation02 * this._invLocalInertia21;
  34812. __tmp__02 = this._transform._rotation00 * this._invLocalInertia02 + this._transform._rotation01 * this._invLocalInertia12 + this._transform._rotation02 * this._invLocalInertia22;
  34813. __tmp__10 = this._transform._rotation10 * this._invLocalInertia00 + this._transform._rotation11 * this._invLocalInertia10 + this._transform._rotation12 * this._invLocalInertia20;
  34814. __tmp__11 = this._transform._rotation10 * this._invLocalInertia01 + this._transform._rotation11 * this._invLocalInertia11 + this._transform._rotation12 * this._invLocalInertia21;
  34815. __tmp__12 = this._transform._rotation10 * this._invLocalInertia02 + this._transform._rotation11 * this._invLocalInertia12 + this._transform._rotation12 * this._invLocalInertia22;
  34816. __tmp__20 = this._transform._rotation20 * this._invLocalInertia00 + this._transform._rotation21 * this._invLocalInertia10 + this._transform._rotation22 * this._invLocalInertia20;
  34817. __tmp__21 = this._transform._rotation20 * this._invLocalInertia01 + this._transform._rotation21 * this._invLocalInertia11 + this._transform._rotation22 * this._invLocalInertia21;
  34818. __tmp__22 = this._transform._rotation20 * this._invLocalInertia02 + this._transform._rotation21 * this._invLocalInertia12 + this._transform._rotation22 * this._invLocalInertia22;
  34819. this._invInertia00 = __tmp__00;
  34820. this._invInertia01 = __tmp__01;
  34821. this._invInertia02 = __tmp__02;
  34822. this._invInertia10 = __tmp__10;
  34823. this._invInertia11 = __tmp__11;
  34824. this._invInertia12 = __tmp__12;
  34825. this._invInertia20 = __tmp__20;
  34826. this._invInertia21 = __tmp__21;
  34827. this._invInertia22 = __tmp__22;
  34828. let __tmp__001;
  34829. let __tmp__011;
  34830. let __tmp__021;
  34831. let __tmp__101;
  34832. let __tmp__111;
  34833. let __tmp__121;
  34834. let __tmp__201;
  34835. let __tmp__211;
  34836. let __tmp__221;
  34837. __tmp__001 = this._invInertia00 * this._transform._rotation00 + this._invInertia01 * this._transform._rotation01 + this._invInertia02 * this._transform._rotation02;
  34838. __tmp__011 = this._invInertia00 * this._transform._rotation10 + this._invInertia01 * this._transform._rotation11 + this._invInertia02 * this._transform._rotation12;
  34839. __tmp__021 = this._invInertia00 * this._transform._rotation20 + this._invInertia01 * this._transform._rotation21 + this._invInertia02 * this._transform._rotation22;
  34840. __tmp__101 = this._invInertia10 * this._transform._rotation00 + this._invInertia11 * this._transform._rotation01 + this._invInertia12 * this._transform._rotation02;
  34841. __tmp__111 = this._invInertia10 * this._transform._rotation10 + this._invInertia11 * this._transform._rotation11 + this._invInertia12 * this._transform._rotation12;
  34842. __tmp__121 = this._invInertia10 * this._transform._rotation20 + this._invInertia11 * this._transform._rotation21 + this._invInertia12 * this._transform._rotation22;
  34843. __tmp__201 = this._invInertia20 * this._transform._rotation00 + this._invInertia21 * this._transform._rotation01 + this._invInertia22 * this._transform._rotation02;
  34844. __tmp__211 = this._invInertia20 * this._transform._rotation10 + this._invInertia21 * this._transform._rotation11 + this._invInertia22 * this._transform._rotation12;
  34845. __tmp__221 = this._invInertia20 * this._transform._rotation20 + this._invInertia21 * this._transform._rotation21 + this._invInertia22 * this._transform._rotation22;
  34846. this._invInertia00 = __tmp__001;
  34847. this._invInertia01 = __tmp__011;
  34848. this._invInertia02 = __tmp__021;
  34849. this._invInertia10 = __tmp__101;
  34850. this._invInertia11 = __tmp__111;
  34851. this._invInertia12 = __tmp__121;
  34852. this._invInertia20 = __tmp__201;
  34853. this._invInertia21 = __tmp__211;
  34854. this._invInertia22 = __tmp__221;
  34855. this._invInertia00 *= this._rotFactor.x;
  34856. this._invInertia01 *= this._rotFactor.x;
  34857. this._invInertia02 *= this._rotFactor.x;
  34858. this._invInertia10 *= this._rotFactor.y;
  34859. this._invInertia11 *= this._rotFactor.y;
  34860. this._invInertia12 *= this._rotFactor.y;
  34861. this._invInertia20 *= this._rotFactor.z;
  34862. this._invInertia21 *= this._rotFactor.z;
  34863. this._invInertia22 *= this._rotFactor.z;
  34864. let dst = this._ptransform;
  34865. let src = this._transform;
  34866. dst._positionX = src._positionX;
  34867. dst._positionY = src._positionY;
  34868. dst._positionZ = src._positionZ;
  34869. dst._rotation00 = src._rotation00;
  34870. dst._rotation01 = src._rotation01;
  34871. dst._rotation02 = src._rotation02;
  34872. dst._rotation10 = src._rotation10;
  34873. dst._rotation11 = src._rotation11;
  34874. dst._rotation12 = src._rotation12;
  34875. dst._rotation20 = src._rotation20;
  34876. dst._rotation21 = src._rotation21;
  34877. dst._rotation22 = src._rotation22;
  34878. let s = this._shapeList;
  34879. while(s != null) {
  34880. let n = s._next;
  34881. let tf1 = this._ptransform;
  34882. let tf2 = this._transform;
  34883. let dst = s._ptransform;
  34884. let src1 = s._localTransform;
  34885. let __tmp__00;
  34886. let __tmp__01;
  34887. let __tmp__02;
  34888. let __tmp__10;
  34889. let __tmp__11;
  34890. let __tmp__12;
  34891. let __tmp__20;
  34892. let __tmp__21;
  34893. let __tmp__22;
  34894. __tmp__00 = tf1._rotation00 * src1._rotation00 + tf1._rotation01 * src1._rotation10 + tf1._rotation02 * src1._rotation20;
  34895. __tmp__01 = tf1._rotation00 * src1._rotation01 + tf1._rotation01 * src1._rotation11 + tf1._rotation02 * src1._rotation21;
  34896. __tmp__02 = tf1._rotation00 * src1._rotation02 + tf1._rotation01 * src1._rotation12 + tf1._rotation02 * src1._rotation22;
  34897. __tmp__10 = tf1._rotation10 * src1._rotation00 + tf1._rotation11 * src1._rotation10 + tf1._rotation12 * src1._rotation20;
  34898. __tmp__11 = tf1._rotation10 * src1._rotation01 + tf1._rotation11 * src1._rotation11 + tf1._rotation12 * src1._rotation21;
  34899. __tmp__12 = tf1._rotation10 * src1._rotation02 + tf1._rotation11 * src1._rotation12 + tf1._rotation12 * src1._rotation22;
  34900. __tmp__20 = tf1._rotation20 * src1._rotation00 + tf1._rotation21 * src1._rotation10 + tf1._rotation22 * src1._rotation20;
  34901. __tmp__21 = tf1._rotation20 * src1._rotation01 + tf1._rotation21 * src1._rotation11 + tf1._rotation22 * src1._rotation21;
  34902. __tmp__22 = tf1._rotation20 * src1._rotation02 + tf1._rotation21 * src1._rotation12 + tf1._rotation22 * src1._rotation22;
  34903. dst._rotation00 = __tmp__00;
  34904. dst._rotation01 = __tmp__01;
  34905. dst._rotation02 = __tmp__02;
  34906. dst._rotation10 = __tmp__10;
  34907. dst._rotation11 = __tmp__11;
  34908. dst._rotation12 = __tmp__12;
  34909. dst._rotation20 = __tmp__20;
  34910. dst._rotation21 = __tmp__21;
  34911. dst._rotation22 = __tmp__22;
  34912. let __tmp__X;
  34913. let __tmp__Y;
  34914. let __tmp__Z;
  34915. __tmp__X = tf1._rotation00 * src1._positionX + tf1._rotation01 * src1._positionY + tf1._rotation02 * src1._positionZ;
  34916. __tmp__Y = tf1._rotation10 * src1._positionX + tf1._rotation11 * src1._positionY + tf1._rotation12 * src1._positionZ;
  34917. __tmp__Z = tf1._rotation20 * src1._positionX + tf1._rotation21 * src1._positionY + tf1._rotation22 * src1._positionZ;
  34918. dst._positionX = __tmp__X;
  34919. dst._positionY = __tmp__Y;
  34920. dst._positionZ = __tmp__Z;
  34921. dst._positionX += tf1._positionX;
  34922. dst._positionY += tf1._positionY;
  34923. dst._positionZ += tf1._positionZ;
  34924. let dst1 = s._transform;
  34925. let src11 = s._localTransform;
  34926. let __tmp__001;
  34927. let __tmp__011;
  34928. let __tmp__021;
  34929. let __tmp__101;
  34930. let __tmp__111;
  34931. let __tmp__121;
  34932. let __tmp__201;
  34933. let __tmp__211;
  34934. let __tmp__221;
  34935. __tmp__001 = tf2._rotation00 * src11._rotation00 + tf2._rotation01 * src11._rotation10 + tf2._rotation02 * src11._rotation20;
  34936. __tmp__011 = tf2._rotation00 * src11._rotation01 + tf2._rotation01 * src11._rotation11 + tf2._rotation02 * src11._rotation21;
  34937. __tmp__021 = tf2._rotation00 * src11._rotation02 + tf2._rotation01 * src11._rotation12 + tf2._rotation02 * src11._rotation22;
  34938. __tmp__101 = tf2._rotation10 * src11._rotation00 + tf2._rotation11 * src11._rotation10 + tf2._rotation12 * src11._rotation20;
  34939. __tmp__111 = tf2._rotation10 * src11._rotation01 + tf2._rotation11 * src11._rotation11 + tf2._rotation12 * src11._rotation21;
  34940. __tmp__121 = tf2._rotation10 * src11._rotation02 + tf2._rotation11 * src11._rotation12 + tf2._rotation12 * src11._rotation22;
  34941. __tmp__201 = tf2._rotation20 * src11._rotation00 + tf2._rotation21 * src11._rotation10 + tf2._rotation22 * src11._rotation20;
  34942. __tmp__211 = tf2._rotation20 * src11._rotation01 + tf2._rotation21 * src11._rotation11 + tf2._rotation22 * src11._rotation21;
  34943. __tmp__221 = tf2._rotation20 * src11._rotation02 + tf2._rotation21 * src11._rotation12 + tf2._rotation22 * src11._rotation22;
  34944. dst1._rotation00 = __tmp__001;
  34945. dst1._rotation01 = __tmp__011;
  34946. dst1._rotation02 = __tmp__021;
  34947. dst1._rotation10 = __tmp__101;
  34948. dst1._rotation11 = __tmp__111;
  34949. dst1._rotation12 = __tmp__121;
  34950. dst1._rotation20 = __tmp__201;
  34951. dst1._rotation21 = __tmp__211;
  34952. dst1._rotation22 = __tmp__221;
  34953. let __tmp__X1;
  34954. let __tmp__Y1;
  34955. let __tmp__Z1;
  34956. __tmp__X1 = tf2._rotation00 * src11._positionX + tf2._rotation01 * src11._positionY + tf2._rotation02 * src11._positionZ;
  34957. __tmp__Y1 = tf2._rotation10 * src11._positionX + tf2._rotation11 * src11._positionY + tf2._rotation12 * src11._positionZ;
  34958. __tmp__Z1 = tf2._rotation20 * src11._positionX + tf2._rotation21 * src11._positionY + tf2._rotation22 * src11._positionZ;
  34959. dst1._positionX = __tmp__X1;
  34960. dst1._positionY = __tmp__Y1;
  34961. dst1._positionZ = __tmp__Z1;
  34962. dst1._positionX += tf2._positionX;
  34963. dst1._positionY += tf2._positionY;
  34964. dst1._positionZ += tf2._positionZ;
  34965. let minX;
  34966. let minY;
  34967. let minZ;
  34968. let maxX;
  34969. let maxY;
  34970. let maxZ;
  34971. s._geom._computeAabb(s._aabb,s._ptransform);
  34972. minX = s._aabb._minX;
  34973. minY = s._aabb._minY;
  34974. minZ = s._aabb._minZ;
  34975. maxX = s._aabb._maxX;
  34976. maxY = s._aabb._maxY;
  34977. maxZ = s._aabb._maxZ;
  34978. s._geom._computeAabb(s._aabb,s._transform);
  34979. s._aabb._minX = minX < s._aabb._minX ? minX : s._aabb._minX;
  34980. s._aabb._minY = minY < s._aabb._minY ? minY : s._aabb._minY;
  34981. s._aabb._minZ = minZ < s._aabb._minZ ? minZ : s._aabb._minZ;
  34982. s._aabb._maxX = maxX > s._aabb._maxX ? maxX : s._aabb._maxX;
  34983. s._aabb._maxY = maxY > s._aabb._maxY ? maxY : s._aabb._maxY;
  34984. s._aabb._maxZ = maxZ > s._aabb._maxZ ? maxZ : s._aabb._maxZ;
  34985. if(s._proxy != null) {
  34986. let dX;
  34987. let dY;
  34988. let dZ;
  34989. dX = s._transform._positionX - s._ptransform._positionX;
  34990. dY = s._transform._positionY - s._ptransform._positionY;
  34991. dZ = s._transform._positionZ - s._ptransform._positionZ;
  34992. let v = s.displacement;
  34993. v.x = dX;
  34994. v.y = dY;
  34995. v.z = dZ;
  34996. s._rigidBody._world._broadPhase.moveProxy(s._proxy,s._aabb,s.displacement);
  34997. }
  34998. s = n;
  34999. }
  35000. this._sleeping = false;
  35001. this._sleepTime = 0;
  35002. }
  35003. getTransform() {
  35004. let _this = this._transform;
  35005. let tf = new oimo.common.Transform();
  35006. tf._positionX = _this._positionX;
  35007. tf._positionY = _this._positionY;
  35008. tf._positionZ = _this._positionZ;
  35009. tf._rotation00 = _this._rotation00;
  35010. tf._rotation01 = _this._rotation01;
  35011. tf._rotation02 = _this._rotation02;
  35012. tf._rotation10 = _this._rotation10;
  35013. tf._rotation11 = _this._rotation11;
  35014. tf._rotation12 = _this._rotation12;
  35015. tf._rotation20 = _this._rotation20;
  35016. tf._rotation21 = _this._rotation21;
  35017. tf._rotation22 = _this._rotation22;
  35018. return tf;
  35019. }
  35020. getTransformTo(transform) {
  35021. let transform1 = this._transform;
  35022. transform._positionX = transform1._positionX;
  35023. transform._positionY = transform1._positionY;
  35024. transform._positionZ = transform1._positionZ;
  35025. transform._rotation00 = transform1._rotation00;
  35026. transform._rotation01 = transform1._rotation01;
  35027. transform._rotation02 = transform1._rotation02;
  35028. transform._rotation10 = transform1._rotation10;
  35029. transform._rotation11 = transform1._rotation11;
  35030. transform._rotation12 = transform1._rotation12;
  35031. transform._rotation20 = transform1._rotation20;
  35032. transform._rotation21 = transform1._rotation21;
  35033. transform._rotation22 = transform1._rotation22;
  35034. }
  35035. setTransform(transform) {
  35036. this._transform._positionX = transform._positionX;
  35037. this._transform._positionY = transform._positionY;
  35038. this._transform._positionZ = transform._positionZ;
  35039. this._transform._rotation00 = transform._rotation00;
  35040. this._transform._rotation01 = transform._rotation01;
  35041. this._transform._rotation02 = transform._rotation02;
  35042. this._transform._rotation10 = transform._rotation10;
  35043. this._transform._rotation11 = transform._rotation11;
  35044. this._transform._rotation12 = transform._rotation12;
  35045. this._transform._rotation20 = transform._rotation20;
  35046. this._transform._rotation21 = transform._rotation21;
  35047. this._transform._rotation22 = transform._rotation22;
  35048. let __tmp__00;
  35049. let __tmp__01;
  35050. let __tmp__02;
  35051. let __tmp__10;
  35052. let __tmp__11;
  35053. let __tmp__12;
  35054. let __tmp__20;
  35055. let __tmp__21;
  35056. let __tmp__22;
  35057. __tmp__00 = this._transform._rotation00 * this._invLocalInertia00 + this._transform._rotation01 * this._invLocalInertia10 + this._transform._rotation02 * this._invLocalInertia20;
  35058. __tmp__01 = this._transform._rotation00 * this._invLocalInertia01 + this._transform._rotation01 * this._invLocalInertia11 + this._transform._rotation02 * this._invLocalInertia21;
  35059. __tmp__02 = this._transform._rotation00 * this._invLocalInertia02 + this._transform._rotation01 * this._invLocalInertia12 + this._transform._rotation02 * this._invLocalInertia22;
  35060. __tmp__10 = this._transform._rotation10 * this._invLocalInertia00 + this._transform._rotation11 * this._invLocalInertia10 + this._transform._rotation12 * this._invLocalInertia20;
  35061. __tmp__11 = this._transform._rotation10 * this._invLocalInertia01 + this._transform._rotation11 * this._invLocalInertia11 + this._transform._rotation12 * this._invLocalInertia21;
  35062. __tmp__12 = this._transform._rotation10 * this._invLocalInertia02 + this._transform._rotation11 * this._invLocalInertia12 + this._transform._rotation12 * this._invLocalInertia22;
  35063. __tmp__20 = this._transform._rotation20 * this._invLocalInertia00 + this._transform._rotation21 * this._invLocalInertia10 + this._transform._rotation22 * this._invLocalInertia20;
  35064. __tmp__21 = this._transform._rotation20 * this._invLocalInertia01 + this._transform._rotation21 * this._invLocalInertia11 + this._transform._rotation22 * this._invLocalInertia21;
  35065. __tmp__22 = this._transform._rotation20 * this._invLocalInertia02 + this._transform._rotation21 * this._invLocalInertia12 + this._transform._rotation22 * this._invLocalInertia22;
  35066. this._invInertia00 = __tmp__00;
  35067. this._invInertia01 = __tmp__01;
  35068. this._invInertia02 = __tmp__02;
  35069. this._invInertia10 = __tmp__10;
  35070. this._invInertia11 = __tmp__11;
  35071. this._invInertia12 = __tmp__12;
  35072. this._invInertia20 = __tmp__20;
  35073. this._invInertia21 = __tmp__21;
  35074. this._invInertia22 = __tmp__22;
  35075. let __tmp__001;
  35076. let __tmp__011;
  35077. let __tmp__021;
  35078. let __tmp__101;
  35079. let __tmp__111;
  35080. let __tmp__121;
  35081. let __tmp__201;
  35082. let __tmp__211;
  35083. let __tmp__221;
  35084. __tmp__001 = this._invInertia00 * this._transform._rotation00 + this._invInertia01 * this._transform._rotation01 + this._invInertia02 * this._transform._rotation02;
  35085. __tmp__011 = this._invInertia00 * this._transform._rotation10 + this._invInertia01 * this._transform._rotation11 + this._invInertia02 * this._transform._rotation12;
  35086. __tmp__021 = this._invInertia00 * this._transform._rotation20 + this._invInertia01 * this._transform._rotation21 + this._invInertia02 * this._transform._rotation22;
  35087. __tmp__101 = this._invInertia10 * this._transform._rotation00 + this._invInertia11 * this._transform._rotation01 + this._invInertia12 * this._transform._rotation02;
  35088. __tmp__111 = this._invInertia10 * this._transform._rotation10 + this._invInertia11 * this._transform._rotation11 + this._invInertia12 * this._transform._rotation12;
  35089. __tmp__121 = this._invInertia10 * this._transform._rotation20 + this._invInertia11 * this._transform._rotation21 + this._invInertia12 * this._transform._rotation22;
  35090. __tmp__201 = this._invInertia20 * this._transform._rotation00 + this._invInertia21 * this._transform._rotation01 + this._invInertia22 * this._transform._rotation02;
  35091. __tmp__211 = this._invInertia20 * this._transform._rotation10 + this._invInertia21 * this._transform._rotation11 + this._invInertia22 * this._transform._rotation12;
  35092. __tmp__221 = this._invInertia20 * this._transform._rotation20 + this._invInertia21 * this._transform._rotation21 + this._invInertia22 * this._transform._rotation22;
  35093. this._invInertia00 = __tmp__001;
  35094. this._invInertia01 = __tmp__011;
  35095. this._invInertia02 = __tmp__021;
  35096. this._invInertia10 = __tmp__101;
  35097. this._invInertia11 = __tmp__111;
  35098. this._invInertia12 = __tmp__121;
  35099. this._invInertia20 = __tmp__201;
  35100. this._invInertia21 = __tmp__211;
  35101. this._invInertia22 = __tmp__221;
  35102. this._invInertia00 *= this._rotFactor.x;
  35103. this._invInertia01 *= this._rotFactor.x;
  35104. this._invInertia02 *= this._rotFactor.x;
  35105. this._invInertia10 *= this._rotFactor.y;
  35106. this._invInertia11 *= this._rotFactor.y;
  35107. this._invInertia12 *= this._rotFactor.y;
  35108. this._invInertia20 *= this._rotFactor.z;
  35109. this._invInertia21 *= this._rotFactor.z;
  35110. this._invInertia22 *= this._rotFactor.z;
  35111. let dst = this._ptransform;
  35112. let src = this._transform;
  35113. dst._positionX = src._positionX;
  35114. dst._positionY = src._positionY;
  35115. dst._positionZ = src._positionZ;
  35116. dst._rotation00 = src._rotation00;
  35117. dst._rotation01 = src._rotation01;
  35118. dst._rotation02 = src._rotation02;
  35119. dst._rotation10 = src._rotation10;
  35120. dst._rotation11 = src._rotation11;
  35121. dst._rotation12 = src._rotation12;
  35122. dst._rotation20 = src._rotation20;
  35123. dst._rotation21 = src._rotation21;
  35124. dst._rotation22 = src._rotation22;
  35125. let s = this._shapeList;
  35126. while(s != null) {
  35127. let n = s._next;
  35128. let tf1 = this._ptransform;
  35129. let tf2 = this._transform;
  35130. let dst = s._ptransform;
  35131. let src1 = s._localTransform;
  35132. let __tmp__00;
  35133. let __tmp__01;
  35134. let __tmp__02;
  35135. let __tmp__10;
  35136. let __tmp__11;
  35137. let __tmp__12;
  35138. let __tmp__20;
  35139. let __tmp__21;
  35140. let __tmp__22;
  35141. __tmp__00 = tf1._rotation00 * src1._rotation00 + tf1._rotation01 * src1._rotation10 + tf1._rotation02 * src1._rotation20;
  35142. __tmp__01 = tf1._rotation00 * src1._rotation01 + tf1._rotation01 * src1._rotation11 + tf1._rotation02 * src1._rotation21;
  35143. __tmp__02 = tf1._rotation00 * src1._rotation02 + tf1._rotation01 * src1._rotation12 + tf1._rotation02 * src1._rotation22;
  35144. __tmp__10 = tf1._rotation10 * src1._rotation00 + tf1._rotation11 * src1._rotation10 + tf1._rotation12 * src1._rotation20;
  35145. __tmp__11 = tf1._rotation10 * src1._rotation01 + tf1._rotation11 * src1._rotation11 + tf1._rotation12 * src1._rotation21;
  35146. __tmp__12 = tf1._rotation10 * src1._rotation02 + tf1._rotation11 * src1._rotation12 + tf1._rotation12 * src1._rotation22;
  35147. __tmp__20 = tf1._rotation20 * src1._rotation00 + tf1._rotation21 * src1._rotation10 + tf1._rotation22 * src1._rotation20;
  35148. __tmp__21 = tf1._rotation20 * src1._rotation01 + tf1._rotation21 * src1._rotation11 + tf1._rotation22 * src1._rotation21;
  35149. __tmp__22 = tf1._rotation20 * src1._rotation02 + tf1._rotation21 * src1._rotation12 + tf1._rotation22 * src1._rotation22;
  35150. dst._rotation00 = __tmp__00;
  35151. dst._rotation01 = __tmp__01;
  35152. dst._rotation02 = __tmp__02;
  35153. dst._rotation10 = __tmp__10;
  35154. dst._rotation11 = __tmp__11;
  35155. dst._rotation12 = __tmp__12;
  35156. dst._rotation20 = __tmp__20;
  35157. dst._rotation21 = __tmp__21;
  35158. dst._rotation22 = __tmp__22;
  35159. let __tmp__X;
  35160. let __tmp__Y;
  35161. let __tmp__Z;
  35162. __tmp__X = tf1._rotation00 * src1._positionX + tf1._rotation01 * src1._positionY + tf1._rotation02 * src1._positionZ;
  35163. __tmp__Y = tf1._rotation10 * src1._positionX + tf1._rotation11 * src1._positionY + tf1._rotation12 * src1._positionZ;
  35164. __tmp__Z = tf1._rotation20 * src1._positionX + tf1._rotation21 * src1._positionY + tf1._rotation22 * src1._positionZ;
  35165. dst._positionX = __tmp__X;
  35166. dst._positionY = __tmp__Y;
  35167. dst._positionZ = __tmp__Z;
  35168. dst._positionX += tf1._positionX;
  35169. dst._positionY += tf1._positionY;
  35170. dst._positionZ += tf1._positionZ;
  35171. let dst1 = s._transform;
  35172. let src11 = s._localTransform;
  35173. let __tmp__001;
  35174. let __tmp__011;
  35175. let __tmp__021;
  35176. let __tmp__101;
  35177. let __tmp__111;
  35178. let __tmp__121;
  35179. let __tmp__201;
  35180. let __tmp__211;
  35181. let __tmp__221;
  35182. __tmp__001 = tf2._rotation00 * src11._rotation00 + tf2._rotation01 * src11._rotation10 + tf2._rotation02 * src11._rotation20;
  35183. __tmp__011 = tf2._rotation00 * src11._rotation01 + tf2._rotation01 * src11._rotation11 + tf2._rotation02 * src11._rotation21;
  35184. __tmp__021 = tf2._rotation00 * src11._rotation02 + tf2._rotation01 * src11._rotation12 + tf2._rotation02 * src11._rotation22;
  35185. __tmp__101 = tf2._rotation10 * src11._rotation00 + tf2._rotation11 * src11._rotation10 + tf2._rotation12 * src11._rotation20;
  35186. __tmp__111 = tf2._rotation10 * src11._rotation01 + tf2._rotation11 * src11._rotation11 + tf2._rotation12 * src11._rotation21;
  35187. __tmp__121 = tf2._rotation10 * src11._rotation02 + tf2._rotation11 * src11._rotation12 + tf2._rotation12 * src11._rotation22;
  35188. __tmp__201 = tf2._rotation20 * src11._rotation00 + tf2._rotation21 * src11._rotation10 + tf2._rotation22 * src11._rotation20;
  35189. __tmp__211 = tf2._rotation20 * src11._rotation01 + tf2._rotation21 * src11._rotation11 + tf2._rotation22 * src11._rotation21;
  35190. __tmp__221 = tf2._rotation20 * src11._rotation02 + tf2._rotation21 * src11._rotation12 + tf2._rotation22 * src11._rotation22;
  35191. dst1._rotation00 = __tmp__001;
  35192. dst1._rotation01 = __tmp__011;
  35193. dst1._rotation02 = __tmp__021;
  35194. dst1._rotation10 = __tmp__101;
  35195. dst1._rotation11 = __tmp__111;
  35196. dst1._rotation12 = __tmp__121;
  35197. dst1._rotation20 = __tmp__201;
  35198. dst1._rotation21 = __tmp__211;
  35199. dst1._rotation22 = __tmp__221;
  35200. let __tmp__X1;
  35201. let __tmp__Y1;
  35202. let __tmp__Z1;
  35203. __tmp__X1 = tf2._rotation00 * src11._positionX + tf2._rotation01 * src11._positionY + tf2._rotation02 * src11._positionZ;
  35204. __tmp__Y1 = tf2._rotation10 * src11._positionX + tf2._rotation11 * src11._positionY + tf2._rotation12 * src11._positionZ;
  35205. __tmp__Z1 = tf2._rotation20 * src11._positionX + tf2._rotation21 * src11._positionY + tf2._rotation22 * src11._positionZ;
  35206. dst1._positionX = __tmp__X1;
  35207. dst1._positionY = __tmp__Y1;
  35208. dst1._positionZ = __tmp__Z1;
  35209. dst1._positionX += tf2._positionX;
  35210. dst1._positionY += tf2._positionY;
  35211. dst1._positionZ += tf2._positionZ;
  35212. let minX;
  35213. let minY;
  35214. let minZ;
  35215. let maxX;
  35216. let maxY;
  35217. let maxZ;
  35218. s._geom._computeAabb(s._aabb,s._ptransform);
  35219. minX = s._aabb._minX;
  35220. minY = s._aabb._minY;
  35221. minZ = s._aabb._minZ;
  35222. maxX = s._aabb._maxX;
  35223. maxY = s._aabb._maxY;
  35224. maxZ = s._aabb._maxZ;
  35225. s._geom._computeAabb(s._aabb,s._transform);
  35226. s._aabb._minX = minX < s._aabb._minX ? minX : s._aabb._minX;
  35227. s._aabb._minY = minY < s._aabb._minY ? minY : s._aabb._minY;
  35228. s._aabb._minZ = minZ < s._aabb._minZ ? minZ : s._aabb._minZ;
  35229. s._aabb._maxX = maxX > s._aabb._maxX ? maxX : s._aabb._maxX;
  35230. s._aabb._maxY = maxY > s._aabb._maxY ? maxY : s._aabb._maxY;
  35231. s._aabb._maxZ = maxZ > s._aabb._maxZ ? maxZ : s._aabb._maxZ;
  35232. if(s._proxy != null) {
  35233. let dX;
  35234. let dY;
  35235. let dZ;
  35236. dX = s._transform._positionX - s._ptransform._positionX;
  35237. dY = s._transform._positionY - s._ptransform._positionY;
  35238. dZ = s._transform._positionZ - s._ptransform._positionZ;
  35239. let v = s.displacement;
  35240. v.x = dX;
  35241. v.y = dY;
  35242. v.z = dZ;
  35243. s._rigidBody._world._broadPhase.moveProxy(s._proxy,s._aabb,s.displacement);
  35244. }
  35245. s = n;
  35246. }
  35247. this._sleeping = false;
  35248. this._sleepTime = 0;
  35249. }
  35250. getMass() {
  35251. return this._mass;
  35252. }
  35253. getLocalInertia() {
  35254. let m = new oimo.common.Mat3();
  35255. m.e00 = this._localInertia00;
  35256. m.e01 = this._localInertia01;
  35257. m.e02 = this._localInertia02;
  35258. m.e10 = this._localInertia10;
  35259. m.e11 = this._localInertia11;
  35260. m.e12 = this._localInertia12;
  35261. m.e20 = this._localInertia20;
  35262. m.e21 = this._localInertia21;
  35263. m.e22 = this._localInertia22;
  35264. return m;
  35265. }
  35266. getLocalInertiaTo(inertia) {
  35267. inertia.e00 = this._localInertia00;
  35268. inertia.e01 = this._localInertia01;
  35269. inertia.e02 = this._localInertia02;
  35270. inertia.e10 = this._localInertia10;
  35271. inertia.e11 = this._localInertia11;
  35272. inertia.e12 = this._localInertia12;
  35273. inertia.e20 = this._localInertia20;
  35274. inertia.e21 = this._localInertia21;
  35275. inertia.e22 = this._localInertia22;
  35276. }
  35277. getMassData() {
  35278. let md = new oimo.dynamics.rigidbody.MassData();
  35279. md.mass = this._mass;
  35280. let m = md.localInertia;
  35281. m.e00 = this._localInertia00;
  35282. m.e01 = this._localInertia01;
  35283. m.e02 = this._localInertia02;
  35284. m.e10 = this._localInertia10;
  35285. m.e11 = this._localInertia11;
  35286. m.e12 = this._localInertia12;
  35287. m.e20 = this._localInertia20;
  35288. m.e21 = this._localInertia21;
  35289. m.e22 = this._localInertia22;
  35290. return md;
  35291. }
  35292. getMassDataTo(massData) {
  35293. massData.mass = this._mass;
  35294. let m = massData.localInertia;
  35295. m.e00 = this._localInertia00;
  35296. m.e01 = this._localInertia01;
  35297. m.e02 = this._localInertia02;
  35298. m.e10 = this._localInertia10;
  35299. m.e11 = this._localInertia11;
  35300. m.e12 = this._localInertia12;
  35301. m.e20 = this._localInertia20;
  35302. m.e21 = this._localInertia21;
  35303. m.e22 = this._localInertia22;
  35304. }
  35305. setMassData(massData) {
  35306. this._mass = massData.mass;
  35307. let m = massData.localInertia;
  35308. this._localInertia00 = m.e00;
  35309. this._localInertia01 = m.e01;
  35310. this._localInertia02 = m.e02;
  35311. this._localInertia10 = m.e10;
  35312. this._localInertia11 = m.e11;
  35313. this._localInertia12 = m.e12;
  35314. this._localInertia20 = m.e20;
  35315. this._localInertia21 = m.e21;
  35316. this._localInertia22 = m.e22;
  35317. if(this._mass > 0 && this._localInertia00 * (this._localInertia11 * this._localInertia22 - this._localInertia12 * this._localInertia21) - this._localInertia01 * (this._localInertia10 * this._localInertia22 - this._localInertia12 * this._localInertia20) + this._localInertia02 * (this._localInertia10 * this._localInertia21 - this._localInertia11 * this._localInertia20) > 0 && this._type == 0) {
  35318. this._invMass = 1 / this._mass;
  35319. let d00 = this._localInertia11 * this._localInertia22 - this._localInertia12 * this._localInertia21;
  35320. let d01 = this._localInertia10 * this._localInertia22 - this._localInertia12 * this._localInertia20;
  35321. let d02 = this._localInertia10 * this._localInertia21 - this._localInertia11 * this._localInertia20;
  35322. let d = this._localInertia00 * d00 - this._localInertia01 * d01 + this._localInertia02 * d02;
  35323. if(d < -1e-32 || d > 1e-32) {
  35324. d = 1 / d;
  35325. }
  35326. this._invLocalInertia00 = d00 * d;
  35327. this._invLocalInertia01 = -(this._localInertia01 * this._localInertia22 - this._localInertia02 * this._localInertia21) * d;
  35328. this._invLocalInertia02 = (this._localInertia01 * this._localInertia12 - this._localInertia02 * this._localInertia11) * d;
  35329. this._invLocalInertia10 = -d01 * d;
  35330. this._invLocalInertia11 = (this._localInertia00 * this._localInertia22 - this._localInertia02 * this._localInertia20) * d;
  35331. this._invLocalInertia12 = -(this._localInertia00 * this._localInertia12 - this._localInertia02 * this._localInertia10) * d;
  35332. this._invLocalInertia20 = d02 * d;
  35333. this._invLocalInertia21 = -(this._localInertia00 * this._localInertia21 - this._localInertia01 * this._localInertia20) * d;
  35334. this._invLocalInertia22 = (this._localInertia00 * this._localInertia11 - this._localInertia01 * this._localInertia10) * d;
  35335. this._invLocalInertiaWithoutRotFactor00 = this._invLocalInertia00;
  35336. this._invLocalInertiaWithoutRotFactor01 = this._invLocalInertia01;
  35337. this._invLocalInertiaWithoutRotFactor02 = this._invLocalInertia02;
  35338. this._invLocalInertiaWithoutRotFactor10 = this._invLocalInertia10;
  35339. this._invLocalInertiaWithoutRotFactor11 = this._invLocalInertia11;
  35340. this._invLocalInertiaWithoutRotFactor12 = this._invLocalInertia12;
  35341. this._invLocalInertiaWithoutRotFactor20 = this._invLocalInertia20;
  35342. this._invLocalInertiaWithoutRotFactor21 = this._invLocalInertia21;
  35343. this._invLocalInertiaWithoutRotFactor22 = this._invLocalInertia22;
  35344. this._invLocalInertia00 = this._invLocalInertiaWithoutRotFactor00 * this._rotFactor.x;
  35345. this._invLocalInertia01 = this._invLocalInertiaWithoutRotFactor01 * this._rotFactor.x;
  35346. this._invLocalInertia02 = this._invLocalInertiaWithoutRotFactor02 * this._rotFactor.x;
  35347. this._invLocalInertia10 = this._invLocalInertiaWithoutRotFactor10 * this._rotFactor.y;
  35348. this._invLocalInertia11 = this._invLocalInertiaWithoutRotFactor11 * this._rotFactor.y;
  35349. this._invLocalInertia12 = this._invLocalInertiaWithoutRotFactor12 * this._rotFactor.y;
  35350. this._invLocalInertia20 = this._invLocalInertiaWithoutRotFactor20 * this._rotFactor.z;
  35351. this._invLocalInertia21 = this._invLocalInertiaWithoutRotFactor21 * this._rotFactor.z;
  35352. this._invLocalInertia22 = this._invLocalInertiaWithoutRotFactor22 * this._rotFactor.z;
  35353. } else {
  35354. this._invMass = 0;
  35355. this._invLocalInertia00 = 0;
  35356. this._invLocalInertia01 = 0;
  35357. this._invLocalInertia02 = 0;
  35358. this._invLocalInertia10 = 0;
  35359. this._invLocalInertia11 = 0;
  35360. this._invLocalInertia12 = 0;
  35361. this._invLocalInertia20 = 0;
  35362. this._invLocalInertia21 = 0;
  35363. this._invLocalInertia22 = 0;
  35364. this._invLocalInertiaWithoutRotFactor00 = 0;
  35365. this._invLocalInertiaWithoutRotFactor01 = 0;
  35366. this._invLocalInertiaWithoutRotFactor02 = 0;
  35367. this._invLocalInertiaWithoutRotFactor10 = 0;
  35368. this._invLocalInertiaWithoutRotFactor11 = 0;
  35369. this._invLocalInertiaWithoutRotFactor12 = 0;
  35370. this._invLocalInertiaWithoutRotFactor20 = 0;
  35371. this._invLocalInertiaWithoutRotFactor21 = 0;
  35372. this._invLocalInertiaWithoutRotFactor22 = 0;
  35373. if(this._type == 0) {
  35374. this._type = 1;
  35375. }
  35376. }
  35377. let __tmp__00;
  35378. let __tmp__01;
  35379. let __tmp__02;
  35380. let __tmp__10;
  35381. let __tmp__11;
  35382. let __tmp__12;
  35383. let __tmp__20;
  35384. let __tmp__21;
  35385. let __tmp__22;
  35386. __tmp__00 = this._transform._rotation00 * this._invLocalInertia00 + this._transform._rotation01 * this._invLocalInertia10 + this._transform._rotation02 * this._invLocalInertia20;
  35387. __tmp__01 = this._transform._rotation00 * this._invLocalInertia01 + this._transform._rotation01 * this._invLocalInertia11 + this._transform._rotation02 * this._invLocalInertia21;
  35388. __tmp__02 = this._transform._rotation00 * this._invLocalInertia02 + this._transform._rotation01 * this._invLocalInertia12 + this._transform._rotation02 * this._invLocalInertia22;
  35389. __tmp__10 = this._transform._rotation10 * this._invLocalInertia00 + this._transform._rotation11 * this._invLocalInertia10 + this._transform._rotation12 * this._invLocalInertia20;
  35390. __tmp__11 = this._transform._rotation10 * this._invLocalInertia01 + this._transform._rotation11 * this._invLocalInertia11 + this._transform._rotation12 * this._invLocalInertia21;
  35391. __tmp__12 = this._transform._rotation10 * this._invLocalInertia02 + this._transform._rotation11 * this._invLocalInertia12 + this._transform._rotation12 * this._invLocalInertia22;
  35392. __tmp__20 = this._transform._rotation20 * this._invLocalInertia00 + this._transform._rotation21 * this._invLocalInertia10 + this._transform._rotation22 * this._invLocalInertia20;
  35393. __tmp__21 = this._transform._rotation20 * this._invLocalInertia01 + this._transform._rotation21 * this._invLocalInertia11 + this._transform._rotation22 * this._invLocalInertia21;
  35394. __tmp__22 = this._transform._rotation20 * this._invLocalInertia02 + this._transform._rotation21 * this._invLocalInertia12 + this._transform._rotation22 * this._invLocalInertia22;
  35395. this._invInertia00 = __tmp__00;
  35396. this._invInertia01 = __tmp__01;
  35397. this._invInertia02 = __tmp__02;
  35398. this._invInertia10 = __tmp__10;
  35399. this._invInertia11 = __tmp__11;
  35400. this._invInertia12 = __tmp__12;
  35401. this._invInertia20 = __tmp__20;
  35402. this._invInertia21 = __tmp__21;
  35403. this._invInertia22 = __tmp__22;
  35404. let __tmp__001;
  35405. let __tmp__011;
  35406. let __tmp__021;
  35407. let __tmp__101;
  35408. let __tmp__111;
  35409. let __tmp__121;
  35410. let __tmp__201;
  35411. let __tmp__211;
  35412. let __tmp__221;
  35413. __tmp__001 = this._invInertia00 * this._transform._rotation00 + this._invInertia01 * this._transform._rotation01 + this._invInertia02 * this._transform._rotation02;
  35414. __tmp__011 = this._invInertia00 * this._transform._rotation10 + this._invInertia01 * this._transform._rotation11 + this._invInertia02 * this._transform._rotation12;
  35415. __tmp__021 = this._invInertia00 * this._transform._rotation20 + this._invInertia01 * this._transform._rotation21 + this._invInertia02 * this._transform._rotation22;
  35416. __tmp__101 = this._invInertia10 * this._transform._rotation00 + this._invInertia11 * this._transform._rotation01 + this._invInertia12 * this._transform._rotation02;
  35417. __tmp__111 = this._invInertia10 * this._transform._rotation10 + this._invInertia11 * this._transform._rotation11 + this._invInertia12 * this._transform._rotation12;
  35418. __tmp__121 = this._invInertia10 * this._transform._rotation20 + this._invInertia11 * this._transform._rotation21 + this._invInertia12 * this._transform._rotation22;
  35419. __tmp__201 = this._invInertia20 * this._transform._rotation00 + this._invInertia21 * this._transform._rotation01 + this._invInertia22 * this._transform._rotation02;
  35420. __tmp__211 = this._invInertia20 * this._transform._rotation10 + this._invInertia21 * this._transform._rotation11 + this._invInertia22 * this._transform._rotation12;
  35421. __tmp__221 = this._invInertia20 * this._transform._rotation20 + this._invInertia21 * this._transform._rotation21 + this._invInertia22 * this._transform._rotation22;
  35422. this._invInertia00 = __tmp__001;
  35423. this._invInertia01 = __tmp__011;
  35424. this._invInertia02 = __tmp__021;
  35425. this._invInertia10 = __tmp__101;
  35426. this._invInertia11 = __tmp__111;
  35427. this._invInertia12 = __tmp__121;
  35428. this._invInertia20 = __tmp__201;
  35429. this._invInertia21 = __tmp__211;
  35430. this._invInertia22 = __tmp__221;
  35431. this._invInertia00 *= this._rotFactor.x;
  35432. this._invInertia01 *= this._rotFactor.x;
  35433. this._invInertia02 *= this._rotFactor.x;
  35434. this._invInertia10 *= this._rotFactor.y;
  35435. this._invInertia11 *= this._rotFactor.y;
  35436. this._invInertia12 *= this._rotFactor.y;
  35437. this._invInertia20 *= this._rotFactor.z;
  35438. this._invInertia21 *= this._rotFactor.z;
  35439. this._invInertia22 *= this._rotFactor.z;
  35440. this._sleeping = false;
  35441. this._sleepTime = 0;
  35442. }
  35443. getRotationFactor() {
  35444. let _this = this._rotFactor;
  35445. return new oimo.common.Vec3(_this.x,_this.y,_this.z);
  35446. }
  35447. setRotationFactor(rotationFactor) {
  35448. let _this = this._rotFactor;
  35449. _this.x = rotationFactor.x;
  35450. _this.y = rotationFactor.y;
  35451. _this.z = rotationFactor.z;
  35452. let __tmp__00;
  35453. let __tmp__01;
  35454. let __tmp__02;
  35455. let __tmp__10;
  35456. let __tmp__11;
  35457. let __tmp__12;
  35458. let __tmp__20;
  35459. let __tmp__21;
  35460. let __tmp__22;
  35461. __tmp__00 = this._transform._rotation00 * this._invLocalInertia00 + this._transform._rotation01 * this._invLocalInertia10 + this._transform._rotation02 * this._invLocalInertia20;
  35462. __tmp__01 = this._transform._rotation00 * this._invLocalInertia01 + this._transform._rotation01 * this._invLocalInertia11 + this._transform._rotation02 * this._invLocalInertia21;
  35463. __tmp__02 = this._transform._rotation00 * this._invLocalInertia02 + this._transform._rotation01 * this._invLocalInertia12 + this._transform._rotation02 * this._invLocalInertia22;
  35464. __tmp__10 = this._transform._rotation10 * this._invLocalInertia00 + this._transform._rotation11 * this._invLocalInertia10 + this._transform._rotation12 * this._invLocalInertia20;
  35465. __tmp__11 = this._transform._rotation10 * this._invLocalInertia01 + this._transform._rotation11 * this._invLocalInertia11 + this._transform._rotation12 * this._invLocalInertia21;
  35466. __tmp__12 = this._transform._rotation10 * this._invLocalInertia02 + this._transform._rotation11 * this._invLocalInertia12 + this._transform._rotation12 * this._invLocalInertia22;
  35467. __tmp__20 = this._transform._rotation20 * this._invLocalInertia00 + this._transform._rotation21 * this._invLocalInertia10 + this._transform._rotation22 * this._invLocalInertia20;
  35468. __tmp__21 = this._transform._rotation20 * this._invLocalInertia01 + this._transform._rotation21 * this._invLocalInertia11 + this._transform._rotation22 * this._invLocalInertia21;
  35469. __tmp__22 = this._transform._rotation20 * this._invLocalInertia02 + this._transform._rotation21 * this._invLocalInertia12 + this._transform._rotation22 * this._invLocalInertia22;
  35470. this._invInertia00 = __tmp__00;
  35471. this._invInertia01 = __tmp__01;
  35472. this._invInertia02 = __tmp__02;
  35473. this._invInertia10 = __tmp__10;
  35474. this._invInertia11 = __tmp__11;
  35475. this._invInertia12 = __tmp__12;
  35476. this._invInertia20 = __tmp__20;
  35477. this._invInertia21 = __tmp__21;
  35478. this._invInertia22 = __tmp__22;
  35479. let __tmp__001;
  35480. let __tmp__011;
  35481. let __tmp__021;
  35482. let __tmp__101;
  35483. let __tmp__111;
  35484. let __tmp__121;
  35485. let __tmp__201;
  35486. let __tmp__211;
  35487. let __tmp__221;
  35488. __tmp__001 = this._invInertia00 * this._transform._rotation00 + this._invInertia01 * this._transform._rotation01 + this._invInertia02 * this._transform._rotation02;
  35489. __tmp__011 = this._invInertia00 * this._transform._rotation10 + this._invInertia01 * this._transform._rotation11 + this._invInertia02 * this._transform._rotation12;
  35490. __tmp__021 = this._invInertia00 * this._transform._rotation20 + this._invInertia01 * this._transform._rotation21 + this._invInertia02 * this._transform._rotation22;
  35491. __tmp__101 = this._invInertia10 * this._transform._rotation00 + this._invInertia11 * this._transform._rotation01 + this._invInertia12 * this._transform._rotation02;
  35492. __tmp__111 = this._invInertia10 * this._transform._rotation10 + this._invInertia11 * this._transform._rotation11 + this._invInertia12 * this._transform._rotation12;
  35493. __tmp__121 = this._invInertia10 * this._transform._rotation20 + this._invInertia11 * this._transform._rotation21 + this._invInertia12 * this._transform._rotation22;
  35494. __tmp__201 = this._invInertia20 * this._transform._rotation00 + this._invInertia21 * this._transform._rotation01 + this._invInertia22 * this._transform._rotation02;
  35495. __tmp__211 = this._invInertia20 * this._transform._rotation10 + this._invInertia21 * this._transform._rotation11 + this._invInertia22 * this._transform._rotation12;
  35496. __tmp__221 = this._invInertia20 * this._transform._rotation20 + this._invInertia21 * this._transform._rotation21 + this._invInertia22 * this._transform._rotation22;
  35497. this._invInertia00 = __tmp__001;
  35498. this._invInertia01 = __tmp__011;
  35499. this._invInertia02 = __tmp__021;
  35500. this._invInertia10 = __tmp__101;
  35501. this._invInertia11 = __tmp__111;
  35502. this._invInertia12 = __tmp__121;
  35503. this._invInertia20 = __tmp__201;
  35504. this._invInertia21 = __tmp__211;
  35505. this._invInertia22 = __tmp__221;
  35506. this._invInertia00 *= this._rotFactor.x;
  35507. this._invInertia01 *= this._rotFactor.x;
  35508. this._invInertia02 *= this._rotFactor.x;
  35509. this._invInertia10 *= this._rotFactor.y;
  35510. this._invInertia11 *= this._rotFactor.y;
  35511. this._invInertia12 *= this._rotFactor.y;
  35512. this._invInertia20 *= this._rotFactor.z;
  35513. this._invInertia21 *= this._rotFactor.z;
  35514. this._invInertia22 *= this._rotFactor.z;
  35515. this._sleeping = false;
  35516. this._sleepTime = 0;
  35517. }
  35518. getLinearVelocity() {
  35519. let v = new oimo.common.Vec3();
  35520. v.x = this._velX;
  35521. v.y = this._velY;
  35522. v.z = this._velZ;
  35523. return v;
  35524. }
  35525. getLinearVelocityTo(linearVelocity) {
  35526. linearVelocity.x = this._velX;
  35527. linearVelocity.y = this._velY;
  35528. linearVelocity.z = this._velZ;
  35529. }
  35530. setLinearVelocity(linearVelocity) {
  35531. if(this._type == 1) {
  35532. this._velX = 0;
  35533. this._velY = 0;
  35534. this._velZ = 0;
  35535. } else {
  35536. this._velX = linearVelocity.x;
  35537. this._velY = linearVelocity.y;
  35538. this._velZ = linearVelocity.z;
  35539. }
  35540. this._sleeping = false;
  35541. this._sleepTime = 0;
  35542. }
  35543. getAngularVelocity() {
  35544. let v = new oimo.common.Vec3();
  35545. v.x = this._angVelX;
  35546. v.y = this._angVelY;
  35547. v.z = this._angVelZ;
  35548. return v;
  35549. }
  35550. getAngularVelocityTo(angularVelocity) {
  35551. angularVelocity.x = this._velX;
  35552. angularVelocity.y = this._velY;
  35553. angularVelocity.z = this._velZ;
  35554. }
  35555. setAngularVelocity(angularVelocity) {
  35556. if(this._type == 1) {
  35557. this._angVelX = 0;
  35558. this._angVelY = 0;
  35559. this._angVelZ = 0;
  35560. } else {
  35561. this._angVelX = angularVelocity.x;
  35562. this._angVelY = angularVelocity.y;
  35563. this._angVelZ = angularVelocity.z;
  35564. }
  35565. this._sleeping = false;
  35566. this._sleepTime = 0;
  35567. }
  35568. addLinearVelocity(linearVelocityChange) {
  35569. if(this._type != 1) {
  35570. let dX;
  35571. let dY;
  35572. let dZ;
  35573. dX = linearVelocityChange.x;
  35574. dY = linearVelocityChange.y;
  35575. dZ = linearVelocityChange.z;
  35576. this._velX += dX;
  35577. this._velY += dY;
  35578. this._velZ += dZ;
  35579. }
  35580. this._sleeping = false;
  35581. this._sleepTime = 0;
  35582. }
  35583. addAngularVelocity(angularVelocityChange) {
  35584. if(this._type != 1) {
  35585. let dX;
  35586. let dY;
  35587. let dZ;
  35588. dX = angularVelocityChange.x;
  35589. dY = angularVelocityChange.y;
  35590. dZ = angularVelocityChange.z;
  35591. this._angVelX += dX;
  35592. this._angVelY += dY;
  35593. this._angVelZ += dZ;
  35594. }
  35595. this._sleeping = false;
  35596. this._sleepTime = 0;
  35597. }
  35598. applyImpulse(impulse,positionInWorld) {
  35599. let impX;
  35600. let impY;
  35601. let impZ;
  35602. impX = impulse.x;
  35603. impY = impulse.y;
  35604. impZ = impulse.z;
  35605. this._velX += impX * this._invMass;
  35606. this._velY += impY * this._invMass;
  35607. this._velZ += impZ * this._invMass;
  35608. let aimpX;
  35609. let aimpY;
  35610. let aimpZ;
  35611. let posX;
  35612. let posY;
  35613. let posZ;
  35614. posX = positionInWorld.x;
  35615. posY = positionInWorld.y;
  35616. posZ = positionInWorld.z;
  35617. posX -= this._transform._positionX;
  35618. posY -= this._transform._positionY;
  35619. posZ -= this._transform._positionZ;
  35620. aimpX = posY * impZ - posZ * impY;
  35621. aimpY = posZ * impX - posX * impZ;
  35622. aimpZ = posX * impY - posY * impX;
  35623. let __tmp__X;
  35624. let __tmp__Y;
  35625. let __tmp__Z;
  35626. __tmp__X = this._invInertia00 * aimpX + this._invInertia01 * aimpY + this._invInertia02 * aimpZ;
  35627. __tmp__Y = this._invInertia10 * aimpX + this._invInertia11 * aimpY + this._invInertia12 * aimpZ;
  35628. __tmp__Z = this._invInertia20 * aimpX + this._invInertia21 * aimpY + this._invInertia22 * aimpZ;
  35629. aimpX = __tmp__X;
  35630. aimpY = __tmp__Y;
  35631. aimpZ = __tmp__Z;
  35632. this._angVelX += aimpX;
  35633. this._angVelY += aimpY;
  35634. this._angVelZ += aimpZ;
  35635. this._sleeping = false;
  35636. this._sleepTime = 0;
  35637. }
  35638. applyLinearImpulse(impulse) {
  35639. let impX;
  35640. let impY;
  35641. let impZ;
  35642. impX = impulse.x;
  35643. impY = impulse.y;
  35644. impZ = impulse.z;
  35645. this._velX += impX * this._invMass;
  35646. this._velY += impY * this._invMass;
  35647. this._velZ += impZ * this._invMass;
  35648. this._sleeping = false;
  35649. this._sleepTime = 0;
  35650. }
  35651. applyAngularImpulse(impulse) {
  35652. let impX;
  35653. let impY;
  35654. let impZ;
  35655. impX = impulse.x;
  35656. impY = impulse.y;
  35657. impZ = impulse.z;
  35658. let __tmp__X;
  35659. let __tmp__Y;
  35660. let __tmp__Z;
  35661. __tmp__X = this._invInertia00 * impX + this._invInertia01 * impY + this._invInertia02 * impZ;
  35662. __tmp__Y = this._invInertia10 * impX + this._invInertia11 * impY + this._invInertia12 * impZ;
  35663. __tmp__Z = this._invInertia20 * impX + this._invInertia21 * impY + this._invInertia22 * impZ;
  35664. impX = __tmp__X;
  35665. impY = __tmp__Y;
  35666. impZ = __tmp__Z;
  35667. this._angVelX += impX;
  35668. this._angVelY += impY;
  35669. this._angVelZ += impZ;
  35670. this._sleeping = false;
  35671. this._sleepTime = 0;
  35672. }
  35673. applyForce(force,positionInWorld) {
  35674. let iforceX;
  35675. let iforceY;
  35676. let iforceZ;
  35677. iforceX = force.x;
  35678. iforceY = force.y;
  35679. iforceZ = force.z;
  35680. this._forceX += iforceX;
  35681. this._forceY += iforceY;
  35682. this._forceZ += iforceZ;
  35683. let itorqueX;
  35684. let itorqueY;
  35685. let itorqueZ;
  35686. let posX;
  35687. let posY;
  35688. let posZ;
  35689. posX = positionInWorld.x;
  35690. posY = positionInWorld.y;
  35691. posZ = positionInWorld.z;
  35692. posX -= this._transform._positionX;
  35693. posY -= this._transform._positionY;
  35694. posZ -= this._transform._positionZ;
  35695. itorqueX = posY * iforceZ - posZ * iforceY;
  35696. itorqueY = posZ * iforceX - posX * iforceZ;
  35697. itorqueZ = posX * iforceY - posY * iforceX;
  35698. this._torqueX += itorqueX;
  35699. this._torqueY += itorqueY;
  35700. this._torqueZ += itorqueZ;
  35701. this._sleeping = false;
  35702. this._sleepTime = 0;
  35703. }
  35704. applyForceToCenter(force) {
  35705. let iforceX;
  35706. let iforceY;
  35707. let iforceZ;
  35708. iforceX = force.x;
  35709. iforceY = force.y;
  35710. iforceZ = force.z;
  35711. this._forceX += iforceX;
  35712. this._forceY += iforceY;
  35713. this._forceZ += iforceZ;
  35714. this._sleeping = false;
  35715. this._sleepTime = 0;
  35716. }
  35717. applyTorque(torque) {
  35718. let itorqueX;
  35719. let itorqueY;
  35720. let itorqueZ;
  35721. itorqueX = torque.x;
  35722. itorqueY = torque.y;
  35723. itorqueZ = torque.z;
  35724. this._torqueX += itorqueX;
  35725. this._torqueY += itorqueY;
  35726. this._torqueZ += itorqueZ;
  35727. this._sleeping = false;
  35728. this._sleepTime = 0;
  35729. }
  35730. getLinearContactImpulse() {
  35731. let res = new oimo.common.Vec3();
  35732. res.x = this._linearContactImpulseX;
  35733. res.y = this._linearContactImpulseY;
  35734. res.z = this._linearContactImpulseZ;
  35735. return res;
  35736. }
  35737. getLinearContactImpulseTo(linearContactImpulse) {
  35738. linearContactImpulse.x = this._linearContactImpulseX;
  35739. linearContactImpulse.y = this._linearContactImpulseY;
  35740. linearContactImpulse.z = this._linearContactImpulseZ;
  35741. }
  35742. getAngularContactImpulse() {
  35743. let res = new oimo.common.Vec3();
  35744. res.x = this._angularContactImpulseX;
  35745. res.y = this._angularContactImpulseY;
  35746. res.z = this._angularContactImpulseZ;
  35747. return res;
  35748. }
  35749. getAngularContactImpulseTo(angularContactImpulse) {
  35750. angularContactImpulse.x = this._angularContactImpulseX;
  35751. angularContactImpulse.y = this._angularContactImpulseY;
  35752. angularContactImpulse.z = this._angularContactImpulseZ;
  35753. }
  35754. getGravityScale() {
  35755. return this._gravityScale;
  35756. }
  35757. setGravityScale(gravityScale) {
  35758. this._gravityScale = gravityScale;
  35759. this._sleeping = false;
  35760. this._sleepTime = 0;
  35761. }
  35762. getLocalPoint(worldPoint) {
  35763. let vX;
  35764. let vY;
  35765. let vZ;
  35766. vX = worldPoint.x;
  35767. vY = worldPoint.y;
  35768. vZ = worldPoint.z;
  35769. vX -= this._transform._positionX;
  35770. vY -= this._transform._positionY;
  35771. vZ -= this._transform._positionZ;
  35772. let __tmp__X;
  35773. let __tmp__Y;
  35774. let __tmp__Z;
  35775. __tmp__X = this._transform._rotation00 * vX + this._transform._rotation10 * vY + this._transform._rotation20 * vZ;
  35776. __tmp__Y = this._transform._rotation01 * vX + this._transform._rotation11 * vY + this._transform._rotation21 * vZ;
  35777. __tmp__Z = this._transform._rotation02 * vX + this._transform._rotation12 * vY + this._transform._rotation22 * vZ;
  35778. vX = __tmp__X;
  35779. vY = __tmp__Y;
  35780. vZ = __tmp__Z;
  35781. let res = new oimo.common.Vec3();
  35782. res.x = vX;
  35783. res.y = vY;
  35784. res.z = vZ;
  35785. return res;
  35786. }
  35787. getLocalPointTo(worldPoint,localPoint) {
  35788. let vX;
  35789. let vY;
  35790. let vZ;
  35791. vX = worldPoint.x;
  35792. vY = worldPoint.y;
  35793. vZ = worldPoint.z;
  35794. vX -= this._transform._positionX;
  35795. vY -= this._transform._positionY;
  35796. vZ -= this._transform._positionZ;
  35797. let __tmp__X;
  35798. let __tmp__Y;
  35799. let __tmp__Z;
  35800. __tmp__X = this._transform._rotation00 * vX + this._transform._rotation10 * vY + this._transform._rotation20 * vZ;
  35801. __tmp__Y = this._transform._rotation01 * vX + this._transform._rotation11 * vY + this._transform._rotation21 * vZ;
  35802. __tmp__Z = this._transform._rotation02 * vX + this._transform._rotation12 * vY + this._transform._rotation22 * vZ;
  35803. vX = __tmp__X;
  35804. vY = __tmp__Y;
  35805. vZ = __tmp__Z;
  35806. localPoint.x = vX;
  35807. localPoint.y = vY;
  35808. localPoint.z = vZ;
  35809. }
  35810. getLocalVector(worldVector) {
  35811. let vX;
  35812. let vY;
  35813. let vZ;
  35814. vX = worldVector.x;
  35815. vY = worldVector.y;
  35816. vZ = worldVector.z;
  35817. let __tmp__X;
  35818. let __tmp__Y;
  35819. let __tmp__Z;
  35820. __tmp__X = this._transform._rotation00 * vX + this._transform._rotation10 * vY + this._transform._rotation20 * vZ;
  35821. __tmp__Y = this._transform._rotation01 * vX + this._transform._rotation11 * vY + this._transform._rotation21 * vZ;
  35822. __tmp__Z = this._transform._rotation02 * vX + this._transform._rotation12 * vY + this._transform._rotation22 * vZ;
  35823. vX = __tmp__X;
  35824. vY = __tmp__Y;
  35825. vZ = __tmp__Z;
  35826. let res = new oimo.common.Vec3();
  35827. res.x = vX;
  35828. res.y = vY;
  35829. res.z = vZ;
  35830. return res;
  35831. }
  35832. getLocalVectorTo(worldVector,localVector) {
  35833. let vX;
  35834. let vY;
  35835. let vZ;
  35836. vX = worldVector.x;
  35837. vY = worldVector.y;
  35838. vZ = worldVector.z;
  35839. let __tmp__X;
  35840. let __tmp__Y;
  35841. let __tmp__Z;
  35842. __tmp__X = this._transform._rotation00 * vX + this._transform._rotation10 * vY + this._transform._rotation20 * vZ;
  35843. __tmp__Y = this._transform._rotation01 * vX + this._transform._rotation11 * vY + this._transform._rotation21 * vZ;
  35844. __tmp__Z = this._transform._rotation02 * vX + this._transform._rotation12 * vY + this._transform._rotation22 * vZ;
  35845. vX = __tmp__X;
  35846. vY = __tmp__Y;
  35847. vZ = __tmp__Z;
  35848. localVector.x = vX;
  35849. localVector.y = vY;
  35850. localVector.z = vZ;
  35851. }
  35852. getWorldPoint(localPoint) {
  35853. let vX;
  35854. let vY;
  35855. let vZ;
  35856. vX = localPoint.x;
  35857. vY = localPoint.y;
  35858. vZ = localPoint.z;
  35859. let __tmp__X;
  35860. let __tmp__Y;
  35861. let __tmp__Z;
  35862. __tmp__X = this._transform._rotation00 * vX + this._transform._rotation01 * vY + this._transform._rotation02 * vZ;
  35863. __tmp__Y = this._transform._rotation10 * vX + this._transform._rotation11 * vY + this._transform._rotation12 * vZ;
  35864. __tmp__Z = this._transform._rotation20 * vX + this._transform._rotation21 * vY + this._transform._rotation22 * vZ;
  35865. vX = __tmp__X;
  35866. vY = __tmp__Y;
  35867. vZ = __tmp__Z;
  35868. vX += this._transform._positionX;
  35869. vY += this._transform._positionY;
  35870. vZ += this._transform._positionZ;
  35871. let res = new oimo.common.Vec3();
  35872. res.x = vX;
  35873. res.y = vY;
  35874. res.z = vZ;
  35875. return res;
  35876. }
  35877. getWorldPointTo(localPoint,worldPoint) {
  35878. let vX;
  35879. let vY;
  35880. let vZ;
  35881. vX = localPoint.x;
  35882. vY = localPoint.y;
  35883. vZ = localPoint.z;
  35884. let __tmp__X;
  35885. let __tmp__Y;
  35886. let __tmp__Z;
  35887. __tmp__X = this._transform._rotation00 * vX + this._transform._rotation01 * vY + this._transform._rotation02 * vZ;
  35888. __tmp__Y = this._transform._rotation10 * vX + this._transform._rotation11 * vY + this._transform._rotation12 * vZ;
  35889. __tmp__Z = this._transform._rotation20 * vX + this._transform._rotation21 * vY + this._transform._rotation22 * vZ;
  35890. vX = __tmp__X;
  35891. vY = __tmp__Y;
  35892. vZ = __tmp__Z;
  35893. vX += this._transform._positionX;
  35894. vY += this._transform._positionY;
  35895. vZ += this._transform._positionZ;
  35896. worldPoint.x = vX;
  35897. worldPoint.y = vY;
  35898. worldPoint.z = vZ;
  35899. }
  35900. getWorldVector(localVector) {
  35901. let vX;
  35902. let vY;
  35903. let vZ;
  35904. vX = localVector.x;
  35905. vY = localVector.y;
  35906. vZ = localVector.z;
  35907. let __tmp__X;
  35908. let __tmp__Y;
  35909. let __tmp__Z;
  35910. __tmp__X = this._transform._rotation00 * vX + this._transform._rotation01 * vY + this._transform._rotation02 * vZ;
  35911. __tmp__Y = this._transform._rotation10 * vX + this._transform._rotation11 * vY + this._transform._rotation12 * vZ;
  35912. __tmp__Z = this._transform._rotation20 * vX + this._transform._rotation21 * vY + this._transform._rotation22 * vZ;
  35913. vX = __tmp__X;
  35914. vY = __tmp__Y;
  35915. vZ = __tmp__Z;
  35916. let res = new oimo.common.Vec3();
  35917. res.x = vX;
  35918. res.y = vY;
  35919. res.z = vZ;
  35920. return res;
  35921. }
  35922. getWorldVectorTo(localVector,worldVector) {
  35923. let vX;
  35924. let vY;
  35925. let vZ;
  35926. vX = localVector.x;
  35927. vY = localVector.y;
  35928. vZ = localVector.z;
  35929. let __tmp__X;
  35930. let __tmp__Y;
  35931. let __tmp__Z;
  35932. __tmp__X = this._transform._rotation00 * vX + this._transform._rotation01 * vY + this._transform._rotation02 * vZ;
  35933. __tmp__Y = this._transform._rotation10 * vX + this._transform._rotation11 * vY + this._transform._rotation12 * vZ;
  35934. __tmp__Z = this._transform._rotation20 * vX + this._transform._rotation21 * vY + this._transform._rotation22 * vZ;
  35935. vX = __tmp__X;
  35936. vY = __tmp__Y;
  35937. vZ = __tmp__Z;
  35938. worldVector.x = vX;
  35939. worldVector.y = vY;
  35940. worldVector.z = vZ;
  35941. }
  35942. getNumShapes() {
  35943. return this._numShapes;
  35944. }
  35945. getShapeList() {
  35946. return this._shapeList;
  35947. }
  35948. getNumContectLinks() {
  35949. return this._numContactLinks;
  35950. }
  35951. getContactLinkList() {
  35952. return this._contactLinkList;
  35953. }
  35954. getNumJointLinks() {
  35955. return this._numJointLinks;
  35956. }
  35957. getJointLinkList() {
  35958. return this._jointLinkList;
  35959. }
  35960. addShape(shape) {
  35961. if(this._shapeList == null) {
  35962. this._shapeList = shape;
  35963. this._shapeListLast = shape;
  35964. } else {
  35965. this._shapeListLast._next = shape;
  35966. shape._prev = this._shapeListLast;
  35967. this._shapeListLast = shape;
  35968. }
  35969. this._numShapes++;
  35970. shape._rigidBody = this;
  35971. if(this._world != null) {
  35972. let _this = this._world;
  35973. shape._proxy = _this._broadPhase.createProxy(shape,shape._aabb);
  35974. shape._id = _this._shapeIdCount++;
  35975. _this._numShapes++;
  35976. }
  35977. this.updateMass();
  35978. let s = this._shapeList;
  35979. while(s != null) {
  35980. let n = s._next;
  35981. let tf1 = this._ptransform;
  35982. let tf2 = this._transform;
  35983. let dst = s._ptransform;
  35984. let src1 = s._localTransform;
  35985. let __tmp__00;
  35986. let __tmp__01;
  35987. let __tmp__02;
  35988. let __tmp__10;
  35989. let __tmp__11;
  35990. let __tmp__12;
  35991. let __tmp__20;
  35992. let __tmp__21;
  35993. let __tmp__22;
  35994. __tmp__00 = tf1._rotation00 * src1._rotation00 + tf1._rotation01 * src1._rotation10 + tf1._rotation02 * src1._rotation20;
  35995. __tmp__01 = tf1._rotation00 * src1._rotation01 + tf1._rotation01 * src1._rotation11 + tf1._rotation02 * src1._rotation21;
  35996. __tmp__02 = tf1._rotation00 * src1._rotation02 + tf1._rotation01 * src1._rotation12 + tf1._rotation02 * src1._rotation22;
  35997. __tmp__10 = tf1._rotation10 * src1._rotation00 + tf1._rotation11 * src1._rotation10 + tf1._rotation12 * src1._rotation20;
  35998. __tmp__11 = tf1._rotation10 * src1._rotation01 + tf1._rotation11 * src1._rotation11 + tf1._rotation12 * src1._rotation21;
  35999. __tmp__12 = tf1._rotation10 * src1._rotation02 + tf1._rotation11 * src1._rotation12 + tf1._rotation12 * src1._rotation22;
  36000. __tmp__20 = tf1._rotation20 * src1._rotation00 + tf1._rotation21 * src1._rotation10 + tf1._rotation22 * src1._rotation20;
  36001. __tmp__21 = tf1._rotation20 * src1._rotation01 + tf1._rotation21 * src1._rotation11 + tf1._rotation22 * src1._rotation21;
  36002. __tmp__22 = tf1._rotation20 * src1._rotation02 + tf1._rotation21 * src1._rotation12 + tf1._rotation22 * src1._rotation22;
  36003. dst._rotation00 = __tmp__00;
  36004. dst._rotation01 = __tmp__01;
  36005. dst._rotation02 = __tmp__02;
  36006. dst._rotation10 = __tmp__10;
  36007. dst._rotation11 = __tmp__11;
  36008. dst._rotation12 = __tmp__12;
  36009. dst._rotation20 = __tmp__20;
  36010. dst._rotation21 = __tmp__21;
  36011. dst._rotation22 = __tmp__22;
  36012. let __tmp__X;
  36013. let __tmp__Y;
  36014. let __tmp__Z;
  36015. __tmp__X = tf1._rotation00 * src1._positionX + tf1._rotation01 * src1._positionY + tf1._rotation02 * src1._positionZ;
  36016. __tmp__Y = tf1._rotation10 * src1._positionX + tf1._rotation11 * src1._positionY + tf1._rotation12 * src1._positionZ;
  36017. __tmp__Z = tf1._rotation20 * src1._positionX + tf1._rotation21 * src1._positionY + tf1._rotation22 * src1._positionZ;
  36018. dst._positionX = __tmp__X;
  36019. dst._positionY = __tmp__Y;
  36020. dst._positionZ = __tmp__Z;
  36021. dst._positionX += tf1._positionX;
  36022. dst._positionY += tf1._positionY;
  36023. dst._positionZ += tf1._positionZ;
  36024. let dst1 = s._transform;
  36025. let src11 = s._localTransform;
  36026. let __tmp__001;
  36027. let __tmp__011;
  36028. let __tmp__021;
  36029. let __tmp__101;
  36030. let __tmp__111;
  36031. let __tmp__121;
  36032. let __tmp__201;
  36033. let __tmp__211;
  36034. let __tmp__221;
  36035. __tmp__001 = tf2._rotation00 * src11._rotation00 + tf2._rotation01 * src11._rotation10 + tf2._rotation02 * src11._rotation20;
  36036. __tmp__011 = tf2._rotation00 * src11._rotation01 + tf2._rotation01 * src11._rotation11 + tf2._rotation02 * src11._rotation21;
  36037. __tmp__021 = tf2._rotation00 * src11._rotation02 + tf2._rotation01 * src11._rotation12 + tf2._rotation02 * src11._rotation22;
  36038. __tmp__101 = tf2._rotation10 * src11._rotation00 + tf2._rotation11 * src11._rotation10 + tf2._rotation12 * src11._rotation20;
  36039. __tmp__111 = tf2._rotation10 * src11._rotation01 + tf2._rotation11 * src11._rotation11 + tf2._rotation12 * src11._rotation21;
  36040. __tmp__121 = tf2._rotation10 * src11._rotation02 + tf2._rotation11 * src11._rotation12 + tf2._rotation12 * src11._rotation22;
  36041. __tmp__201 = tf2._rotation20 * src11._rotation00 + tf2._rotation21 * src11._rotation10 + tf2._rotation22 * src11._rotation20;
  36042. __tmp__211 = tf2._rotation20 * src11._rotation01 + tf2._rotation21 * src11._rotation11 + tf2._rotation22 * src11._rotation21;
  36043. __tmp__221 = tf2._rotation20 * src11._rotation02 + tf2._rotation21 * src11._rotation12 + tf2._rotation22 * src11._rotation22;
  36044. dst1._rotation00 = __tmp__001;
  36045. dst1._rotation01 = __tmp__011;
  36046. dst1._rotation02 = __tmp__021;
  36047. dst1._rotation10 = __tmp__101;
  36048. dst1._rotation11 = __tmp__111;
  36049. dst1._rotation12 = __tmp__121;
  36050. dst1._rotation20 = __tmp__201;
  36051. dst1._rotation21 = __tmp__211;
  36052. dst1._rotation22 = __tmp__221;
  36053. let __tmp__X1;
  36054. let __tmp__Y1;
  36055. let __tmp__Z1;
  36056. __tmp__X1 = tf2._rotation00 * src11._positionX + tf2._rotation01 * src11._positionY + tf2._rotation02 * src11._positionZ;
  36057. __tmp__Y1 = tf2._rotation10 * src11._positionX + tf2._rotation11 * src11._positionY + tf2._rotation12 * src11._positionZ;
  36058. __tmp__Z1 = tf2._rotation20 * src11._positionX + tf2._rotation21 * src11._positionY + tf2._rotation22 * src11._positionZ;
  36059. dst1._positionX = __tmp__X1;
  36060. dst1._positionY = __tmp__Y1;
  36061. dst1._positionZ = __tmp__Z1;
  36062. dst1._positionX += tf2._positionX;
  36063. dst1._positionY += tf2._positionY;
  36064. dst1._positionZ += tf2._positionZ;
  36065. let minX;
  36066. let minY;
  36067. let minZ;
  36068. let maxX;
  36069. let maxY;
  36070. let maxZ;
  36071. s._geom._computeAabb(s._aabb,s._ptransform);
  36072. minX = s._aabb._minX;
  36073. minY = s._aabb._minY;
  36074. minZ = s._aabb._minZ;
  36075. maxX = s._aabb._maxX;
  36076. maxY = s._aabb._maxY;
  36077. maxZ = s._aabb._maxZ;
  36078. s._geom._computeAabb(s._aabb,s._transform);
  36079. s._aabb._minX = minX < s._aabb._minX ? minX : s._aabb._minX;
  36080. s._aabb._minY = minY < s._aabb._minY ? minY : s._aabb._minY;
  36081. s._aabb._minZ = minZ < s._aabb._minZ ? minZ : s._aabb._minZ;
  36082. s._aabb._maxX = maxX > s._aabb._maxX ? maxX : s._aabb._maxX;
  36083. s._aabb._maxY = maxY > s._aabb._maxY ? maxY : s._aabb._maxY;
  36084. s._aabb._maxZ = maxZ > s._aabb._maxZ ? maxZ : s._aabb._maxZ;
  36085. if(s._proxy != null) {
  36086. let dX;
  36087. let dY;
  36088. let dZ;
  36089. dX = s._transform._positionX - s._ptransform._positionX;
  36090. dY = s._transform._positionY - s._ptransform._positionY;
  36091. dZ = s._transform._positionZ - s._ptransform._positionZ;
  36092. let v = s.displacement;
  36093. v.x = dX;
  36094. v.y = dY;
  36095. v.z = dZ;
  36096. s._rigidBody._world._broadPhase.moveProxy(s._proxy,s._aabb,s.displacement);
  36097. }
  36098. s = n;
  36099. }
  36100. }
  36101. removeShape(shape) {
  36102. let prev = shape._prev;
  36103. let next = shape._next;
  36104. if(prev != null) {
  36105. prev._next = next;
  36106. }
  36107. if(next != null) {
  36108. next._prev = prev;
  36109. }
  36110. if(shape == this._shapeList) {
  36111. this._shapeList = this._shapeList._next;
  36112. }
  36113. if(shape == this._shapeListLast) {
  36114. this._shapeListLast = this._shapeListLast._prev;
  36115. }
  36116. shape._next = null;
  36117. shape._prev = null;
  36118. this._numShapes--;
  36119. shape._rigidBody = null;
  36120. if(this._world != null) {
  36121. let _this = this._world;
  36122. _this._broadPhase.destroyProxy(shape._proxy);
  36123. shape._proxy = null;
  36124. shape._id = -1;
  36125. let cl = shape._rigidBody._contactLinkList;
  36126. while(cl != null) {
  36127. let n = cl._next;
  36128. let c = cl._contact;
  36129. if(c._s1 == shape || c._s2 == shape) {
  36130. let _this1 = cl._other;
  36131. _this1._sleeping = false;
  36132. _this1._sleepTime = 0;
  36133. let _this2 = _this._contactManager;
  36134. let prev = c._prev;
  36135. let next = c._next;
  36136. if(prev != null) {
  36137. prev._next = next;
  36138. }
  36139. if(next != null) {
  36140. next._prev = prev;
  36141. }
  36142. if(c == _this2._contactList) {
  36143. _this2._contactList = _this2._contactList._next;
  36144. }
  36145. if(c == _this2._contactListLast) {
  36146. _this2._contactListLast = _this2._contactListLast._prev;
  36147. }
  36148. c._next = null;
  36149. c._prev = null;
  36150. if(c._touching) {
  36151. let cc1 = c._s1._contactCallback;
  36152. let cc2 = c._s2._contactCallback;
  36153. if(cc1 == cc2) {
  36154. cc2 = null;
  36155. }
  36156. if(cc1 != null) {
  36157. cc1.endContact(c);
  36158. }
  36159. if(cc2 != null) {
  36160. cc2.endContact(c);
  36161. }
  36162. }
  36163. let prev1 = c._link1._prev;
  36164. let next1 = c._link1._next;
  36165. if(prev1 != null) {
  36166. prev1._next = next1;
  36167. }
  36168. if(next1 != null) {
  36169. next1._prev = prev1;
  36170. }
  36171. if(c._link1 == c._b1._contactLinkList) {
  36172. c._b1._contactLinkList = c._b1._contactLinkList._next;
  36173. }
  36174. if(c._link1 == c._b1._contactLinkListLast) {
  36175. c._b1._contactLinkListLast = c._b1._contactLinkListLast._prev;
  36176. }
  36177. c._link1._next = null;
  36178. c._link1._prev = null;
  36179. let prev2 = c._link2._prev;
  36180. let next2 = c._link2._next;
  36181. if(prev2 != null) {
  36182. prev2._next = next2;
  36183. }
  36184. if(next2 != null) {
  36185. next2._prev = prev2;
  36186. }
  36187. if(c._link2 == c._b2._contactLinkList) {
  36188. c._b2._contactLinkList = c._b2._contactLinkList._next;
  36189. }
  36190. if(c._link2 == c._b2._contactLinkListLast) {
  36191. c._b2._contactLinkListLast = c._b2._contactLinkListLast._prev;
  36192. }
  36193. c._link2._next = null;
  36194. c._link2._prev = null;
  36195. c._b1._numContactLinks--;
  36196. c._b2._numContactLinks--;
  36197. c._link1._other = null;
  36198. c._link2._other = null;
  36199. c._link1._contact = null;
  36200. c._link2._contact = null;
  36201. c._s1 = null;
  36202. c._s2 = null;
  36203. c._b1 = null;
  36204. c._b2 = null;
  36205. c._touching = false;
  36206. c._cachedDetectorData._clear();
  36207. c._manifold._clear();
  36208. c._detector = null;
  36209. let _this3 = c._contactConstraint;
  36210. _this3._s1 = null;
  36211. _this3._s2 = null;
  36212. _this3._b1 = null;
  36213. _this3._b2 = null;
  36214. _this3._tf1 = null;
  36215. _this3._tf2 = null;
  36216. c._next = _this2._contactPool;
  36217. _this2._contactPool = c;
  36218. _this2._numContacts--;
  36219. }
  36220. cl = n;
  36221. }
  36222. _this._numShapes--;
  36223. }
  36224. this.updateMass();
  36225. let s = this._shapeList;
  36226. while(s != null) {
  36227. let n = s._next;
  36228. let tf1 = this._ptransform;
  36229. let tf2 = this._transform;
  36230. let dst = s._ptransform;
  36231. let src1 = s._localTransform;
  36232. let __tmp__00;
  36233. let __tmp__01;
  36234. let __tmp__02;
  36235. let __tmp__10;
  36236. let __tmp__11;
  36237. let __tmp__12;
  36238. let __tmp__20;
  36239. let __tmp__21;
  36240. let __tmp__22;
  36241. __tmp__00 = tf1._rotation00 * src1._rotation00 + tf1._rotation01 * src1._rotation10 + tf1._rotation02 * src1._rotation20;
  36242. __tmp__01 = tf1._rotation00 * src1._rotation01 + tf1._rotation01 * src1._rotation11 + tf1._rotation02 * src1._rotation21;
  36243. __tmp__02 = tf1._rotation00 * src1._rotation02 + tf1._rotation01 * src1._rotation12 + tf1._rotation02 * src1._rotation22;
  36244. __tmp__10 = tf1._rotation10 * src1._rotation00 + tf1._rotation11 * src1._rotation10 + tf1._rotation12 * src1._rotation20;
  36245. __tmp__11 = tf1._rotation10 * src1._rotation01 + tf1._rotation11 * src1._rotation11 + tf1._rotation12 * src1._rotation21;
  36246. __tmp__12 = tf1._rotation10 * src1._rotation02 + tf1._rotation11 * src1._rotation12 + tf1._rotation12 * src1._rotation22;
  36247. __tmp__20 = tf1._rotation20 * src1._rotation00 + tf1._rotation21 * src1._rotation10 + tf1._rotation22 * src1._rotation20;
  36248. __tmp__21 = tf1._rotation20 * src1._rotation01 + tf1._rotation21 * src1._rotation11 + tf1._rotation22 * src1._rotation21;
  36249. __tmp__22 = tf1._rotation20 * src1._rotation02 + tf1._rotation21 * src1._rotation12 + tf1._rotation22 * src1._rotation22;
  36250. dst._rotation00 = __tmp__00;
  36251. dst._rotation01 = __tmp__01;
  36252. dst._rotation02 = __tmp__02;
  36253. dst._rotation10 = __tmp__10;
  36254. dst._rotation11 = __tmp__11;
  36255. dst._rotation12 = __tmp__12;
  36256. dst._rotation20 = __tmp__20;
  36257. dst._rotation21 = __tmp__21;
  36258. dst._rotation22 = __tmp__22;
  36259. let __tmp__X;
  36260. let __tmp__Y;
  36261. let __tmp__Z;
  36262. __tmp__X = tf1._rotation00 * src1._positionX + tf1._rotation01 * src1._positionY + tf1._rotation02 * src1._positionZ;
  36263. __tmp__Y = tf1._rotation10 * src1._positionX + tf1._rotation11 * src1._positionY + tf1._rotation12 * src1._positionZ;
  36264. __tmp__Z = tf1._rotation20 * src1._positionX + tf1._rotation21 * src1._positionY + tf1._rotation22 * src1._positionZ;
  36265. dst._positionX = __tmp__X;
  36266. dst._positionY = __tmp__Y;
  36267. dst._positionZ = __tmp__Z;
  36268. dst._positionX += tf1._positionX;
  36269. dst._positionY += tf1._positionY;
  36270. dst._positionZ += tf1._positionZ;
  36271. let dst1 = s._transform;
  36272. let src11 = s._localTransform;
  36273. let __tmp__001;
  36274. let __tmp__011;
  36275. let __tmp__021;
  36276. let __tmp__101;
  36277. let __tmp__111;
  36278. let __tmp__121;
  36279. let __tmp__201;
  36280. let __tmp__211;
  36281. let __tmp__221;
  36282. __tmp__001 = tf2._rotation00 * src11._rotation00 + tf2._rotation01 * src11._rotation10 + tf2._rotation02 * src11._rotation20;
  36283. __tmp__011 = tf2._rotation00 * src11._rotation01 + tf2._rotation01 * src11._rotation11 + tf2._rotation02 * src11._rotation21;
  36284. __tmp__021 = tf2._rotation00 * src11._rotation02 + tf2._rotation01 * src11._rotation12 + tf2._rotation02 * src11._rotation22;
  36285. __tmp__101 = tf2._rotation10 * src11._rotation00 + tf2._rotation11 * src11._rotation10 + tf2._rotation12 * src11._rotation20;
  36286. __tmp__111 = tf2._rotation10 * src11._rotation01 + tf2._rotation11 * src11._rotation11 + tf2._rotation12 * src11._rotation21;
  36287. __tmp__121 = tf2._rotation10 * src11._rotation02 + tf2._rotation11 * src11._rotation12 + tf2._rotation12 * src11._rotation22;
  36288. __tmp__201 = tf2._rotation20 * src11._rotation00 + tf2._rotation21 * src11._rotation10 + tf2._rotation22 * src11._rotation20;
  36289. __tmp__211 = tf2._rotation20 * src11._rotation01 + tf2._rotation21 * src11._rotation11 + tf2._rotation22 * src11._rotation21;
  36290. __tmp__221 = tf2._rotation20 * src11._rotation02 + tf2._rotation21 * src11._rotation12 + tf2._rotation22 * src11._rotation22;
  36291. dst1._rotation00 = __tmp__001;
  36292. dst1._rotation01 = __tmp__011;
  36293. dst1._rotation02 = __tmp__021;
  36294. dst1._rotation10 = __tmp__101;
  36295. dst1._rotation11 = __tmp__111;
  36296. dst1._rotation12 = __tmp__121;
  36297. dst1._rotation20 = __tmp__201;
  36298. dst1._rotation21 = __tmp__211;
  36299. dst1._rotation22 = __tmp__221;
  36300. let __tmp__X1;
  36301. let __tmp__Y1;
  36302. let __tmp__Z1;
  36303. __tmp__X1 = tf2._rotation00 * src11._positionX + tf2._rotation01 * src11._positionY + tf2._rotation02 * src11._positionZ;
  36304. __tmp__Y1 = tf2._rotation10 * src11._positionX + tf2._rotation11 * src11._positionY + tf2._rotation12 * src11._positionZ;
  36305. __tmp__Z1 = tf2._rotation20 * src11._positionX + tf2._rotation21 * src11._positionY + tf2._rotation22 * src11._positionZ;
  36306. dst1._positionX = __tmp__X1;
  36307. dst1._positionY = __tmp__Y1;
  36308. dst1._positionZ = __tmp__Z1;
  36309. dst1._positionX += tf2._positionX;
  36310. dst1._positionY += tf2._positionY;
  36311. dst1._positionZ += tf2._positionZ;
  36312. let minX;
  36313. let minY;
  36314. let minZ;
  36315. let maxX;
  36316. let maxY;
  36317. let maxZ;
  36318. s._geom._computeAabb(s._aabb,s._ptransform);
  36319. minX = s._aabb._minX;
  36320. minY = s._aabb._minY;
  36321. minZ = s._aabb._minZ;
  36322. maxX = s._aabb._maxX;
  36323. maxY = s._aabb._maxY;
  36324. maxZ = s._aabb._maxZ;
  36325. s._geom._computeAabb(s._aabb,s._transform);
  36326. s._aabb._minX = minX < s._aabb._minX ? minX : s._aabb._minX;
  36327. s._aabb._minY = minY < s._aabb._minY ? minY : s._aabb._minY;
  36328. s._aabb._minZ = minZ < s._aabb._minZ ? minZ : s._aabb._minZ;
  36329. s._aabb._maxX = maxX > s._aabb._maxX ? maxX : s._aabb._maxX;
  36330. s._aabb._maxY = maxY > s._aabb._maxY ? maxY : s._aabb._maxY;
  36331. s._aabb._maxZ = maxZ > s._aabb._maxZ ? maxZ : s._aabb._maxZ;
  36332. if(s._proxy != null) {
  36333. let dX;
  36334. let dY;
  36335. let dZ;
  36336. dX = s._transform._positionX - s._ptransform._positionX;
  36337. dY = s._transform._positionY - s._ptransform._positionY;
  36338. dZ = s._transform._positionZ - s._ptransform._positionZ;
  36339. let v = s.displacement;
  36340. v.x = dX;
  36341. v.y = dY;
  36342. v.z = dZ;
  36343. s._rigidBody._world._broadPhase.moveProxy(s._proxy,s._aabb,s.displacement);
  36344. }
  36345. s = n;
  36346. }
  36347. }
  36348. getType() {
  36349. return this._type;
  36350. }
  36351. setType(type) {
  36352. this._type = type;
  36353. this.updateMass();
  36354. }
  36355. wakeUp() {
  36356. this._sleeping = false;
  36357. this._sleepTime = 0;
  36358. }
  36359. sleep() {
  36360. this._sleeping = true;
  36361. this._sleepTime = 0;
  36362. }
  36363. isSleeping() {
  36364. return this._sleeping;
  36365. }
  36366. getSleepTime() {
  36367. return this._sleepTime;
  36368. }
  36369. setAutoSleep(autoSleepEnabled) {
  36370. this._autoSleep = autoSleepEnabled;
  36371. this._sleeping = false;
  36372. this._sleepTime = 0;
  36373. }
  36374. getLinearDamping() {
  36375. return this._linearDamping;
  36376. }
  36377. setLinearDamping(damping) {
  36378. this._linearDamping = damping;
  36379. }
  36380. getAngularDamping() {
  36381. return this._angularDamping;
  36382. }
  36383. setAngularDamping(damping) {
  36384. this._angularDamping = damping;
  36385. }
  36386. getPrev() {
  36387. return this._prev;
  36388. }
  36389. getNext() {
  36390. return this._next;
  36391. }
  36392. }
  36393. oimo.dynamics.rigidbody.RigidBodyConfig = class oimo_dynamics_rigidbody_RigidBodyConfig {
  36394. constructor() {
  36395. this.position = new oimo.common.Vec3();
  36396. this.rotation = new oimo.common.Mat3();
  36397. this.linearVelocity = new oimo.common.Vec3();
  36398. this.angularVelocity = new oimo.common.Vec3();
  36399. this.type = 0;
  36400. this.autoSleep = true;
  36401. this.linearDamping = 0;
  36402. this.angularDamping = 0;
  36403. }
  36404. }
  36405. oimo.dynamics.rigidbody.RigidBodyType = class oimo_dynamics_rigidbody_RigidBodyType {
  36406. }
  36407. oimo.dynamics.rigidbody.Shape = class oimo_dynamics_rigidbody_Shape {
  36408. constructor(config) {
  36409. this._id = -1;
  36410. this._localTransform = new oimo.common.Transform();
  36411. this._ptransform = new oimo.common.Transform();
  36412. this._transform = new oimo.common.Transform();
  36413. let v = config.position;
  36414. this._localTransform._positionX = v.x;
  36415. this._localTransform._positionY = v.y;
  36416. this._localTransform._positionZ = v.z;
  36417. let m = config.rotation;
  36418. this._localTransform._rotation00 = m.e00;
  36419. this._localTransform._rotation01 = m.e01;
  36420. this._localTransform._rotation02 = m.e02;
  36421. this._localTransform._rotation10 = m.e10;
  36422. this._localTransform._rotation11 = m.e11;
  36423. this._localTransform._rotation12 = m.e12;
  36424. this._localTransform._rotation20 = m.e20;
  36425. this._localTransform._rotation21 = m.e21;
  36426. this._localTransform._rotation22 = m.e22;
  36427. let dst = this._ptransform;
  36428. let src = this._localTransform;
  36429. dst._positionX = src._positionX;
  36430. dst._positionY = src._positionY;
  36431. dst._positionZ = src._positionZ;
  36432. dst._rotation00 = src._rotation00;
  36433. dst._rotation01 = src._rotation01;
  36434. dst._rotation02 = src._rotation02;
  36435. dst._rotation10 = src._rotation10;
  36436. dst._rotation11 = src._rotation11;
  36437. dst._rotation12 = src._rotation12;
  36438. dst._rotation20 = src._rotation20;
  36439. dst._rotation21 = src._rotation21;
  36440. dst._rotation22 = src._rotation22;
  36441. let dst1 = this._transform;
  36442. let src1 = this._localTransform;
  36443. dst1._positionX = src1._positionX;
  36444. dst1._positionY = src1._positionY;
  36445. dst1._positionZ = src1._positionZ;
  36446. dst1._rotation00 = src1._rotation00;
  36447. dst1._rotation01 = src1._rotation01;
  36448. dst1._rotation02 = src1._rotation02;
  36449. dst1._rotation10 = src1._rotation10;
  36450. dst1._rotation11 = src1._rotation11;
  36451. dst1._rotation12 = src1._rotation12;
  36452. dst1._rotation20 = src1._rotation20;
  36453. dst1._rotation21 = src1._rotation21;
  36454. dst1._rotation22 = src1._rotation22;
  36455. this._restitution = config.restitution;
  36456. this._friction = config.friction;
  36457. this._density = config.density;
  36458. this._geom = config.geometry;
  36459. this._collisionGroup = config.collisionGroup;
  36460. this._collisionMask = config.collisionMask;
  36461. this._contactCallback = config.contactCallback;
  36462. this._aabb = new oimo.collision.geometry.Aabb();
  36463. this._proxy = null;
  36464. this.displacement = new oimo.common.Vec3();
  36465. }
  36466. getFriction() {
  36467. return this._friction;
  36468. }
  36469. setFriction(friction) {
  36470. this._friction = friction;
  36471. }
  36472. getRestitution() {
  36473. return this._restitution;
  36474. }
  36475. setRestitution(restitution) {
  36476. this._restitution = restitution;
  36477. }
  36478. getLocalTransform() {
  36479. let _this = this._localTransform;
  36480. let tf = new oimo.common.Transform();
  36481. tf._positionX = _this._positionX;
  36482. tf._positionY = _this._positionY;
  36483. tf._positionZ = _this._positionZ;
  36484. tf._rotation00 = _this._rotation00;
  36485. tf._rotation01 = _this._rotation01;
  36486. tf._rotation02 = _this._rotation02;
  36487. tf._rotation10 = _this._rotation10;
  36488. tf._rotation11 = _this._rotation11;
  36489. tf._rotation12 = _this._rotation12;
  36490. tf._rotation20 = _this._rotation20;
  36491. tf._rotation21 = _this._rotation21;
  36492. tf._rotation22 = _this._rotation22;
  36493. return tf;
  36494. }
  36495. getLocalTransformTo(transform) {
  36496. let transform1 = this._localTransform;
  36497. transform._positionX = transform1._positionX;
  36498. transform._positionY = transform1._positionY;
  36499. transform._positionZ = transform1._positionZ;
  36500. transform._rotation00 = transform1._rotation00;
  36501. transform._rotation01 = transform1._rotation01;
  36502. transform._rotation02 = transform1._rotation02;
  36503. transform._rotation10 = transform1._rotation10;
  36504. transform._rotation11 = transform1._rotation11;
  36505. transform._rotation12 = transform1._rotation12;
  36506. transform._rotation20 = transform1._rotation20;
  36507. transform._rotation21 = transform1._rotation21;
  36508. transform._rotation22 = transform1._rotation22;
  36509. }
  36510. getTransform() {
  36511. let _this = this._transform;
  36512. let tf = new oimo.common.Transform();
  36513. tf._positionX = _this._positionX;
  36514. tf._positionY = _this._positionY;
  36515. tf._positionZ = _this._positionZ;
  36516. tf._rotation00 = _this._rotation00;
  36517. tf._rotation01 = _this._rotation01;
  36518. tf._rotation02 = _this._rotation02;
  36519. tf._rotation10 = _this._rotation10;
  36520. tf._rotation11 = _this._rotation11;
  36521. tf._rotation12 = _this._rotation12;
  36522. tf._rotation20 = _this._rotation20;
  36523. tf._rotation21 = _this._rotation21;
  36524. tf._rotation22 = _this._rotation22;
  36525. return tf;
  36526. }
  36527. getTransformTo(transform) {
  36528. let transform1 = this._transform;
  36529. transform._positionX = transform1._positionX;
  36530. transform._positionY = transform1._positionY;
  36531. transform._positionZ = transform1._positionZ;
  36532. transform._rotation00 = transform1._rotation00;
  36533. transform._rotation01 = transform1._rotation01;
  36534. transform._rotation02 = transform1._rotation02;
  36535. transform._rotation10 = transform1._rotation10;
  36536. transform._rotation11 = transform1._rotation11;
  36537. transform._rotation12 = transform1._rotation12;
  36538. transform._rotation20 = transform1._rotation20;
  36539. transform._rotation21 = transform1._rotation21;
  36540. transform._rotation22 = transform1._rotation22;
  36541. }
  36542. setLocalTransform(transform) {
  36543. let _this = this._localTransform;
  36544. _this._positionX = transform._positionX;
  36545. _this._positionY = transform._positionY;
  36546. _this._positionZ = transform._positionZ;
  36547. _this._rotation00 = transform._rotation00;
  36548. _this._rotation01 = transform._rotation01;
  36549. _this._rotation02 = transform._rotation02;
  36550. _this._rotation10 = transform._rotation10;
  36551. _this._rotation11 = transform._rotation11;
  36552. _this._rotation12 = transform._rotation12;
  36553. _this._rotation20 = transform._rotation20;
  36554. _this._rotation21 = transform._rotation21;
  36555. _this._rotation22 = transform._rotation22;
  36556. if(this._rigidBody != null) {
  36557. let _this = this._rigidBody;
  36558. _this.updateMass();
  36559. let s = _this._shapeList;
  36560. while(s != null) {
  36561. let n = s._next;
  36562. let tf1 = _this._ptransform;
  36563. let tf2 = _this._transform;
  36564. let dst = s._ptransform;
  36565. let src1 = s._localTransform;
  36566. let __tmp__00;
  36567. let __tmp__01;
  36568. let __tmp__02;
  36569. let __tmp__10;
  36570. let __tmp__11;
  36571. let __tmp__12;
  36572. let __tmp__20;
  36573. let __tmp__21;
  36574. let __tmp__22;
  36575. __tmp__00 = tf1._rotation00 * src1._rotation00 + tf1._rotation01 * src1._rotation10 + tf1._rotation02 * src1._rotation20;
  36576. __tmp__01 = tf1._rotation00 * src1._rotation01 + tf1._rotation01 * src1._rotation11 + tf1._rotation02 * src1._rotation21;
  36577. __tmp__02 = tf1._rotation00 * src1._rotation02 + tf1._rotation01 * src1._rotation12 + tf1._rotation02 * src1._rotation22;
  36578. __tmp__10 = tf1._rotation10 * src1._rotation00 + tf1._rotation11 * src1._rotation10 + tf1._rotation12 * src1._rotation20;
  36579. __tmp__11 = tf1._rotation10 * src1._rotation01 + tf1._rotation11 * src1._rotation11 + tf1._rotation12 * src1._rotation21;
  36580. __tmp__12 = tf1._rotation10 * src1._rotation02 + tf1._rotation11 * src1._rotation12 + tf1._rotation12 * src1._rotation22;
  36581. __tmp__20 = tf1._rotation20 * src1._rotation00 + tf1._rotation21 * src1._rotation10 + tf1._rotation22 * src1._rotation20;
  36582. __tmp__21 = tf1._rotation20 * src1._rotation01 + tf1._rotation21 * src1._rotation11 + tf1._rotation22 * src1._rotation21;
  36583. __tmp__22 = tf1._rotation20 * src1._rotation02 + tf1._rotation21 * src1._rotation12 + tf1._rotation22 * src1._rotation22;
  36584. dst._rotation00 = __tmp__00;
  36585. dst._rotation01 = __tmp__01;
  36586. dst._rotation02 = __tmp__02;
  36587. dst._rotation10 = __tmp__10;
  36588. dst._rotation11 = __tmp__11;
  36589. dst._rotation12 = __tmp__12;
  36590. dst._rotation20 = __tmp__20;
  36591. dst._rotation21 = __tmp__21;
  36592. dst._rotation22 = __tmp__22;
  36593. let __tmp__X;
  36594. let __tmp__Y;
  36595. let __tmp__Z;
  36596. __tmp__X = tf1._rotation00 * src1._positionX + tf1._rotation01 * src1._positionY + tf1._rotation02 * src1._positionZ;
  36597. __tmp__Y = tf1._rotation10 * src1._positionX + tf1._rotation11 * src1._positionY + tf1._rotation12 * src1._positionZ;
  36598. __tmp__Z = tf1._rotation20 * src1._positionX + tf1._rotation21 * src1._positionY + tf1._rotation22 * src1._positionZ;
  36599. dst._positionX = __tmp__X;
  36600. dst._positionY = __tmp__Y;
  36601. dst._positionZ = __tmp__Z;
  36602. dst._positionX += tf1._positionX;
  36603. dst._positionY += tf1._positionY;
  36604. dst._positionZ += tf1._positionZ;
  36605. let dst1 = s._transform;
  36606. let src11 = s._localTransform;
  36607. let __tmp__001;
  36608. let __tmp__011;
  36609. let __tmp__021;
  36610. let __tmp__101;
  36611. let __tmp__111;
  36612. let __tmp__121;
  36613. let __tmp__201;
  36614. let __tmp__211;
  36615. let __tmp__221;
  36616. __tmp__001 = tf2._rotation00 * src11._rotation00 + tf2._rotation01 * src11._rotation10 + tf2._rotation02 * src11._rotation20;
  36617. __tmp__011 = tf2._rotation00 * src11._rotation01 + tf2._rotation01 * src11._rotation11 + tf2._rotation02 * src11._rotation21;
  36618. __tmp__021 = tf2._rotation00 * src11._rotation02 + tf2._rotation01 * src11._rotation12 + tf2._rotation02 * src11._rotation22;
  36619. __tmp__101 = tf2._rotation10 * src11._rotation00 + tf2._rotation11 * src11._rotation10 + tf2._rotation12 * src11._rotation20;
  36620. __tmp__111 = tf2._rotation10 * src11._rotation01 + tf2._rotation11 * src11._rotation11 + tf2._rotation12 * src11._rotation21;
  36621. __tmp__121 = tf2._rotation10 * src11._rotation02 + tf2._rotation11 * src11._rotation12 + tf2._rotation12 * src11._rotation22;
  36622. __tmp__201 = tf2._rotation20 * src11._rotation00 + tf2._rotation21 * src11._rotation10 + tf2._rotation22 * src11._rotation20;
  36623. __tmp__211 = tf2._rotation20 * src11._rotation01 + tf2._rotation21 * src11._rotation11 + tf2._rotation22 * src11._rotation21;
  36624. __tmp__221 = tf2._rotation20 * src11._rotation02 + tf2._rotation21 * src11._rotation12 + tf2._rotation22 * src11._rotation22;
  36625. dst1._rotation00 = __tmp__001;
  36626. dst1._rotation01 = __tmp__011;
  36627. dst1._rotation02 = __tmp__021;
  36628. dst1._rotation10 = __tmp__101;
  36629. dst1._rotation11 = __tmp__111;
  36630. dst1._rotation12 = __tmp__121;
  36631. dst1._rotation20 = __tmp__201;
  36632. dst1._rotation21 = __tmp__211;
  36633. dst1._rotation22 = __tmp__221;
  36634. let __tmp__X1;
  36635. let __tmp__Y1;
  36636. let __tmp__Z1;
  36637. __tmp__X1 = tf2._rotation00 * src11._positionX + tf2._rotation01 * src11._positionY + tf2._rotation02 * src11._positionZ;
  36638. __tmp__Y1 = tf2._rotation10 * src11._positionX + tf2._rotation11 * src11._positionY + tf2._rotation12 * src11._positionZ;
  36639. __tmp__Z1 = tf2._rotation20 * src11._positionX + tf2._rotation21 * src11._positionY + tf2._rotation22 * src11._positionZ;
  36640. dst1._positionX = __tmp__X1;
  36641. dst1._positionY = __tmp__Y1;
  36642. dst1._positionZ = __tmp__Z1;
  36643. dst1._positionX += tf2._positionX;
  36644. dst1._positionY += tf2._positionY;
  36645. dst1._positionZ += tf2._positionZ;
  36646. let minX;
  36647. let minY;
  36648. let minZ;
  36649. let maxX;
  36650. let maxY;
  36651. let maxZ;
  36652. s._geom._computeAabb(s._aabb,s._ptransform);
  36653. minX = s._aabb._minX;
  36654. minY = s._aabb._minY;
  36655. minZ = s._aabb._minZ;
  36656. maxX = s._aabb._maxX;
  36657. maxY = s._aabb._maxY;
  36658. maxZ = s._aabb._maxZ;
  36659. s._geom._computeAabb(s._aabb,s._transform);
  36660. s._aabb._minX = minX < s._aabb._minX ? minX : s._aabb._minX;
  36661. s._aabb._minY = minY < s._aabb._minY ? minY : s._aabb._minY;
  36662. s._aabb._minZ = minZ < s._aabb._minZ ? minZ : s._aabb._minZ;
  36663. s._aabb._maxX = maxX > s._aabb._maxX ? maxX : s._aabb._maxX;
  36664. s._aabb._maxY = maxY > s._aabb._maxY ? maxY : s._aabb._maxY;
  36665. s._aabb._maxZ = maxZ > s._aabb._maxZ ? maxZ : s._aabb._maxZ;
  36666. if(s._proxy != null) {
  36667. let dX;
  36668. let dY;
  36669. let dZ;
  36670. dX = s._transform._positionX - s._ptransform._positionX;
  36671. dY = s._transform._positionY - s._ptransform._positionY;
  36672. dZ = s._transform._positionZ - s._ptransform._positionZ;
  36673. let v = s.displacement;
  36674. v.x = dX;
  36675. v.y = dY;
  36676. v.z = dZ;
  36677. s._rigidBody._world._broadPhase.moveProxy(s._proxy,s._aabb,s.displacement);
  36678. }
  36679. s = n;
  36680. }
  36681. }
  36682. }
  36683. getDensity() {
  36684. return this._density;
  36685. }
  36686. setDensity(density) {
  36687. this._density = density;
  36688. if(this._rigidBody != null) {
  36689. let _this = this._rigidBody;
  36690. _this.updateMass();
  36691. let s = _this._shapeList;
  36692. while(s != null) {
  36693. let n = s._next;
  36694. let tf1 = _this._ptransform;
  36695. let tf2 = _this._transform;
  36696. let dst = s._ptransform;
  36697. let src1 = s._localTransform;
  36698. let __tmp__00;
  36699. let __tmp__01;
  36700. let __tmp__02;
  36701. let __tmp__10;
  36702. let __tmp__11;
  36703. let __tmp__12;
  36704. let __tmp__20;
  36705. let __tmp__21;
  36706. let __tmp__22;
  36707. __tmp__00 = tf1._rotation00 * src1._rotation00 + tf1._rotation01 * src1._rotation10 + tf1._rotation02 * src1._rotation20;
  36708. __tmp__01 = tf1._rotation00 * src1._rotation01 + tf1._rotation01 * src1._rotation11 + tf1._rotation02 * src1._rotation21;
  36709. __tmp__02 = tf1._rotation00 * src1._rotation02 + tf1._rotation01 * src1._rotation12 + tf1._rotation02 * src1._rotation22;
  36710. __tmp__10 = tf1._rotation10 * src1._rotation00 + tf1._rotation11 * src1._rotation10 + tf1._rotation12 * src1._rotation20;
  36711. __tmp__11 = tf1._rotation10 * src1._rotation01 + tf1._rotation11 * src1._rotation11 + tf1._rotation12 * src1._rotation21;
  36712. __tmp__12 = tf1._rotation10 * src1._rotation02 + tf1._rotation11 * src1._rotation12 + tf1._rotation12 * src1._rotation22;
  36713. __tmp__20 = tf1._rotation20 * src1._rotation00 + tf1._rotation21 * src1._rotation10 + tf1._rotation22 * src1._rotation20;
  36714. __tmp__21 = tf1._rotation20 * src1._rotation01 + tf1._rotation21 * src1._rotation11 + tf1._rotation22 * src1._rotation21;
  36715. __tmp__22 = tf1._rotation20 * src1._rotation02 + tf1._rotation21 * src1._rotation12 + tf1._rotation22 * src1._rotation22;
  36716. dst._rotation00 = __tmp__00;
  36717. dst._rotation01 = __tmp__01;
  36718. dst._rotation02 = __tmp__02;
  36719. dst._rotation10 = __tmp__10;
  36720. dst._rotation11 = __tmp__11;
  36721. dst._rotation12 = __tmp__12;
  36722. dst._rotation20 = __tmp__20;
  36723. dst._rotation21 = __tmp__21;
  36724. dst._rotation22 = __tmp__22;
  36725. let __tmp__X;
  36726. let __tmp__Y;
  36727. let __tmp__Z;
  36728. __tmp__X = tf1._rotation00 * src1._positionX + tf1._rotation01 * src1._positionY + tf1._rotation02 * src1._positionZ;
  36729. __tmp__Y = tf1._rotation10 * src1._positionX + tf1._rotation11 * src1._positionY + tf1._rotation12 * src1._positionZ;
  36730. __tmp__Z = tf1._rotation20 * src1._positionX + tf1._rotation21 * src1._positionY + tf1._rotation22 * src1._positionZ;
  36731. dst._positionX = __tmp__X;
  36732. dst._positionY = __tmp__Y;
  36733. dst._positionZ = __tmp__Z;
  36734. dst._positionX += tf1._positionX;
  36735. dst._positionY += tf1._positionY;
  36736. dst._positionZ += tf1._positionZ;
  36737. let dst1 = s._transform;
  36738. let src11 = s._localTransform;
  36739. let __tmp__001;
  36740. let __tmp__011;
  36741. let __tmp__021;
  36742. let __tmp__101;
  36743. let __tmp__111;
  36744. let __tmp__121;
  36745. let __tmp__201;
  36746. let __tmp__211;
  36747. let __tmp__221;
  36748. __tmp__001 = tf2._rotation00 * src11._rotation00 + tf2._rotation01 * src11._rotation10 + tf2._rotation02 * src11._rotation20;
  36749. __tmp__011 = tf2._rotation00 * src11._rotation01 + tf2._rotation01 * src11._rotation11 + tf2._rotation02 * src11._rotation21;
  36750. __tmp__021 = tf2._rotation00 * src11._rotation02 + tf2._rotation01 * src11._rotation12 + tf2._rotation02 * src11._rotation22;
  36751. __tmp__101 = tf2._rotation10 * src11._rotation00 + tf2._rotation11 * src11._rotation10 + tf2._rotation12 * src11._rotation20;
  36752. __tmp__111 = tf2._rotation10 * src11._rotation01 + tf2._rotation11 * src11._rotation11 + tf2._rotation12 * src11._rotation21;
  36753. __tmp__121 = tf2._rotation10 * src11._rotation02 + tf2._rotation11 * src11._rotation12 + tf2._rotation12 * src11._rotation22;
  36754. __tmp__201 = tf2._rotation20 * src11._rotation00 + tf2._rotation21 * src11._rotation10 + tf2._rotation22 * src11._rotation20;
  36755. __tmp__211 = tf2._rotation20 * src11._rotation01 + tf2._rotation21 * src11._rotation11 + tf2._rotation22 * src11._rotation21;
  36756. __tmp__221 = tf2._rotation20 * src11._rotation02 + tf2._rotation21 * src11._rotation12 + tf2._rotation22 * src11._rotation22;
  36757. dst1._rotation00 = __tmp__001;
  36758. dst1._rotation01 = __tmp__011;
  36759. dst1._rotation02 = __tmp__021;
  36760. dst1._rotation10 = __tmp__101;
  36761. dst1._rotation11 = __tmp__111;
  36762. dst1._rotation12 = __tmp__121;
  36763. dst1._rotation20 = __tmp__201;
  36764. dst1._rotation21 = __tmp__211;
  36765. dst1._rotation22 = __tmp__221;
  36766. let __tmp__X1;
  36767. let __tmp__Y1;
  36768. let __tmp__Z1;
  36769. __tmp__X1 = tf2._rotation00 * src11._positionX + tf2._rotation01 * src11._positionY + tf2._rotation02 * src11._positionZ;
  36770. __tmp__Y1 = tf2._rotation10 * src11._positionX + tf2._rotation11 * src11._positionY + tf2._rotation12 * src11._positionZ;
  36771. __tmp__Z1 = tf2._rotation20 * src11._positionX + tf2._rotation21 * src11._positionY + tf2._rotation22 * src11._positionZ;
  36772. dst1._positionX = __tmp__X1;
  36773. dst1._positionY = __tmp__Y1;
  36774. dst1._positionZ = __tmp__Z1;
  36775. dst1._positionX += tf2._positionX;
  36776. dst1._positionY += tf2._positionY;
  36777. dst1._positionZ += tf2._positionZ;
  36778. let minX;
  36779. let minY;
  36780. let minZ;
  36781. let maxX;
  36782. let maxY;
  36783. let maxZ;
  36784. s._geom._computeAabb(s._aabb,s._ptransform);
  36785. minX = s._aabb._minX;
  36786. minY = s._aabb._minY;
  36787. minZ = s._aabb._minZ;
  36788. maxX = s._aabb._maxX;
  36789. maxY = s._aabb._maxY;
  36790. maxZ = s._aabb._maxZ;
  36791. s._geom._computeAabb(s._aabb,s._transform);
  36792. s._aabb._minX = minX < s._aabb._minX ? minX : s._aabb._minX;
  36793. s._aabb._minY = minY < s._aabb._minY ? minY : s._aabb._minY;
  36794. s._aabb._minZ = minZ < s._aabb._minZ ? minZ : s._aabb._minZ;
  36795. s._aabb._maxX = maxX > s._aabb._maxX ? maxX : s._aabb._maxX;
  36796. s._aabb._maxY = maxY > s._aabb._maxY ? maxY : s._aabb._maxY;
  36797. s._aabb._maxZ = maxZ > s._aabb._maxZ ? maxZ : s._aabb._maxZ;
  36798. if(s._proxy != null) {
  36799. let dX;
  36800. let dY;
  36801. let dZ;
  36802. dX = s._transform._positionX - s._ptransform._positionX;
  36803. dY = s._transform._positionY - s._ptransform._positionY;
  36804. dZ = s._transform._positionZ - s._ptransform._positionZ;
  36805. let v = s.displacement;
  36806. v.x = dX;
  36807. v.y = dY;
  36808. v.z = dZ;
  36809. s._rigidBody._world._broadPhase.moveProxy(s._proxy,s._aabb,s.displacement);
  36810. }
  36811. s = n;
  36812. }
  36813. }
  36814. }
  36815. getAabb() {
  36816. return this._aabb.clone();
  36817. }
  36818. getAabbTo(aabb) {
  36819. aabb.copyFrom(this._aabb);
  36820. }
  36821. getGeometry() {
  36822. return this._geom;
  36823. }
  36824. getRigidBody() {
  36825. return this._rigidBody;
  36826. }
  36827. getCollisionGroup() {
  36828. return this._collisionGroup;
  36829. }
  36830. setCollisionGroup(collisionGroup) {
  36831. this._collisionGroup = collisionGroup;
  36832. }
  36833. getCollisionMask() {
  36834. return this._collisionMask;
  36835. }
  36836. setCollisionMask(collisionMask) {
  36837. this._collisionMask = collisionMask;
  36838. }
  36839. getContactCallback() {
  36840. return this._contactCallback;
  36841. }
  36842. setContactCallback(callback) {
  36843. this._contactCallback = callback;
  36844. }
  36845. getPrev() {
  36846. return this._prev;
  36847. }
  36848. getNext() {
  36849. return this._next;
  36850. }
  36851. }
  36852. oimo.dynamics.rigidbody.ShapeConfig = class oimo_dynamics_rigidbody_ShapeConfig {
  36853. constructor() {
  36854. this.position = new oimo.common.Vec3();
  36855. this.rotation = new oimo.common.Mat3();
  36856. this.friction = oimo.common.Setting.defaultFriction;
  36857. this.restitution = oimo.common.Setting.defaultRestitution;
  36858. this.density = oimo.common.Setting.defaultDensity;
  36859. this.collisionGroup = oimo.common.Setting.defaultCollisionGroup;
  36860. this.collisionMask = oimo.common.Setting.defaultCollisionMask;
  36861. this.geometry = null;
  36862. this.contactCallback = null;
  36863. }
  36864. }
  36865. if(!oimo.m) oimo.m = {};
  36866. oimo.m.M = class oimo_m_M {
  36867. }
  36868. oimo.collision.broadphase.BroadPhaseType._BRUTE_FORCE = 1;
  36869. oimo.collision.broadphase.BroadPhaseType._BVH = 2;
  36870. oimo.collision.broadphase.BroadPhaseType.BRUTE_FORCE = 1;
  36871. oimo.collision.broadphase.BroadPhaseType.BVH = 2;
  36872. oimo.collision.broadphase.bvh.BvhInsertionStrategy.SIMPLE = 0;
  36873. oimo.collision.broadphase.bvh.BvhInsertionStrategy.MINIMIZE_SURFACE_AREA = 1;
  36874. oimo.collision.geometry.GeometryType._SPHERE = 0;
  36875. oimo.collision.geometry.GeometryType._BOX = 1;
  36876. oimo.collision.geometry.GeometryType._CYLINDER = 2;
  36877. oimo.collision.geometry.GeometryType._CONE = 3;
  36878. oimo.collision.geometry.GeometryType._CAPSULE = 4;
  36879. oimo.collision.geometry.GeometryType._CONVEX_HULL = 5;
  36880. oimo.collision.geometry.GeometryType._CONVEX_MIN = 0;
  36881. oimo.collision.geometry.GeometryType._CONVEX_MAX = 5;
  36882. oimo.collision.geometry.GeometryType.SPHERE = 0;
  36883. oimo.collision.geometry.GeometryType.BOX = 1;
  36884. oimo.collision.geometry.GeometryType.CYLINDER = 2;
  36885. oimo.collision.geometry.GeometryType.CONE = 3;
  36886. oimo.collision.geometry.GeometryType.CAPSULE = 4;
  36887. oimo.collision.geometry.GeometryType.CONVEX_HULL = 5;
  36888. oimo.collision.narrowphase.detector.BoxBoxDetector.EDGE_BIAS_MULT = 1.0;
  36889. oimo.collision.narrowphase.detector.gjkepa.EpaPolyhedronState.OK = 0;
  36890. oimo.collision.narrowphase.detector.gjkepa.EpaPolyhedronState.INVALID_TRIANGLE = 1;
  36891. oimo.collision.narrowphase.detector.gjkepa.EpaPolyhedronState.NO_ADJACENT_PAIR_INDEX = 2;
  36892. oimo.collision.narrowphase.detector.gjkepa.EpaPolyhedronState.NO_ADJACENT_TRIANGLE = 3;
  36893. oimo.collision.narrowphase.detector.gjkepa.EpaPolyhedronState.EDGE_LOOP_BROKEN = 4;
  36894. oimo.collision.narrowphase.detector.gjkepa.EpaPolyhedronState.NO_OUTER_TRIANGLE = 5;
  36895. oimo.collision.narrowphase.detector.gjkepa.EpaPolyhedronState.TRIANGLE_INVISIBLE = 6;
  36896. oimo.collision.narrowphase.detector.gjkepa.EpaTriangle.count = 0;
  36897. oimo.common.Vec3.numCreations = 0;
  36898. oimo.common.Setting.defaultFriction = 0.2;
  36899. oimo.common.Setting.defaultRestitution = 0.2;
  36900. oimo.common.Setting.defaultDensity = 1;
  36901. oimo.common.Setting.defaultCollisionGroup = 1;
  36902. oimo.common.Setting.defaultCollisionMask = 1;
  36903. oimo.common.Setting.maxTranslationPerStep = 20;
  36904. oimo.common.Setting.maxRotationPerStep = 3.14159265358979;
  36905. oimo.common.Setting.bvhProxyPadding = 0.1;
  36906. oimo.common.Setting.bvhIncrementalCollisionThreshold = 0.45;
  36907. oimo.common.Setting.defaultGJKMargin = 0.05;
  36908. oimo.common.Setting.enableGJKCaching = true;
  36909. oimo.common.Setting.maxEPAVertices = 128;
  36910. oimo.common.Setting.maxEPAPolyhedronFaces = 128;
  36911. oimo.common.Setting.contactEnableBounceThreshold = 0.5;
  36912. oimo.common.Setting.velocityBaumgarte = 0.2;
  36913. oimo.common.Setting.positionSplitImpulseBaumgarte = 0.4;
  36914. oimo.common.Setting.positionNgsBaumgarte = 1.0;
  36915. oimo.common.Setting.contactUseAlternativePositionCorrectionAlgorithmDepthThreshold = 0.05;
  36916. oimo.common.Setting.defaultContactPositionCorrectionAlgorithm = 0;
  36917. oimo.common.Setting.alternativeContactPositionCorrectionAlgorithm = 1;
  36918. oimo.common.Setting.contactPersistenceThreshold = 0.05;
  36919. oimo.common.Setting.maxManifoldPoints = 4;
  36920. oimo.common.Setting.defaultJointConstraintSolverType = 0;
  36921. oimo.common.Setting.defaultJointPositionCorrectionAlgorithm = 0;
  36922. oimo.common.Setting.jointWarmStartingFactorForBaungarte = 0.8;
  36923. oimo.common.Setting.jointWarmStartingFactor = 0.95;
  36924. oimo.common.Setting.minSpringDamperDampingRatio = 1e-6;
  36925. oimo.common.Setting.minRagdollMaxSwingAngle = 1e-6;
  36926. oimo.common.Setting.maxJacobianRows = 6;
  36927. oimo.common.Setting.directMlcpSolverEps = 1e-9;
  36928. oimo.common.Setting.islandInitialRigidBodyArraySize = 128;
  36929. oimo.common.Setting.islandInitialConstraintArraySize = 128;
  36930. oimo.common.Setting.sleepingVelocityThreshold = 0.2;
  36931. oimo.common.Setting.sleepingAngularVelocityThreshold = 0.5;
  36932. oimo.common.Setting.sleepingTimeThreshold = 1.0;
  36933. oimo.common.Setting.disableSleeping = false;
  36934. oimo.common.Setting.linearSlop = 0.005;
  36935. oimo.common.Setting.angularSlop = 0.017453292519943278;
  36936. oimo.collision.narrowphase.detector.gjkepa.GjkEpa.instance = new oimo.collision.narrowphase.detector.gjkepa.GjkEpa();
  36937. oimo.collision.narrowphase.detector.gjkepa.GjkEpaResultState._SUCCEEDED = 0;
  36938. oimo.collision.narrowphase.detector.gjkepa.GjkEpaResultState._GJK_FAILED_TO_MAKE_TETRAHEDRON = 1;
  36939. oimo.collision.narrowphase.detector.gjkepa.GjkEpaResultState._GJK_DID_NOT_CONVERGE = 2;
  36940. oimo.collision.narrowphase.detector.gjkepa.GjkEpaResultState._EPA_FAILED_TO_INIT = 257;
  36941. oimo.collision.narrowphase.detector.gjkepa.GjkEpaResultState._EPA_FAILED_TO_ADD_VERTEX = 258;
  36942. oimo.collision.narrowphase.detector.gjkepa.GjkEpaResultState._EPA_DID_NOT_CONVERGE = 259;
  36943. oimo.collision.narrowphase.detector.gjkepa.GjkEpaResultState.SUCCEEDED = 0;
  36944. oimo.collision.narrowphase.detector.gjkepa.GjkEpaResultState.GJK_FAILED_TO_MAKE_TETRAHEDRON = 1;
  36945. oimo.collision.narrowphase.detector.gjkepa.GjkEpaResultState.GJK_DID_NOT_CONVERGE = 2;
  36946. oimo.collision.narrowphase.detector.gjkepa.GjkEpaResultState.EPA_FAILED_TO_INIT = 257;
  36947. oimo.collision.narrowphase.detector.gjkepa.GjkEpaResultState.EPA_FAILED_TO_ADD_VERTEX = 258;
  36948. oimo.collision.narrowphase.detector.gjkepa.GjkEpaResultState.EPA_DID_NOT_CONVERGE = 259;
  36949. oimo.common.Mat3.numCreations = 0;
  36950. oimo.common.Mat4.numCreations = 0;
  36951. oimo.common.MathUtil.POSITIVE_INFINITY = 1e65536;
  36952. oimo.common.MathUtil.NEGATIVE_INFINITY = -1e65536;
  36953. oimo.common.MathUtil.PI = 3.14159265358979;
  36954. oimo.common.MathUtil.TWO_PI = 6.28318530717958;
  36955. oimo.common.MathUtil.HALF_PI = 1.570796326794895;
  36956. oimo.common.MathUtil.TO_RADIANS = 0.017453292519943278;
  36957. oimo.common.MathUtil.TO_DEGREES = 57.29577951308238;
  36958. oimo.common.Quat.numCreations = 0;
  36959. oimo.dynamics.common.DebugDraw.SPHERE_PHI_DIVISION = 8;
  36960. oimo.dynamics.common.DebugDraw.SPHERE_THETA_DIVISION = 4;
  36961. oimo.dynamics.common.DebugDraw.CIRCLE_THETA_DIVISION = 8;
  36962. oimo.dynamics.common.Performance.broadPhaseCollisionTime = 0;
  36963. oimo.dynamics.common.Performance.narrowPhaseCollisionTime = 0;
  36964. oimo.dynamics.common.Performance.dynamicsTime = 0;
  36965. oimo.dynamics.common.Performance.totalTime = 0;
  36966. oimo.dynamics.constraint.PositionCorrectionAlgorithm._BAUMGARTE = 0;
  36967. oimo.dynamics.constraint.PositionCorrectionAlgorithm._SPLIT_IMPULSE = 1;
  36968. oimo.dynamics.constraint.PositionCorrectionAlgorithm._NGS = 2;
  36969. oimo.dynamics.constraint.PositionCorrectionAlgorithm.BAUMGARTE = 0;
  36970. oimo.dynamics.constraint.PositionCorrectionAlgorithm.SPLIT_IMPULSE = 1;
  36971. oimo.dynamics.constraint.PositionCorrectionAlgorithm.NGS = 2;
  36972. oimo.dynamics.constraint.info.JacobianRow.BIT_LINEAR_SET = 1;
  36973. oimo.dynamics.constraint.info.JacobianRow.BIT_ANGULAR_SET = 2;
  36974. oimo.dynamics.constraint.joint.JointType._SPHERICAL = 0;
  36975. oimo.dynamics.constraint.joint.JointType._REVOLUTE = 1;
  36976. oimo.dynamics.constraint.joint.JointType._CYLINDRICAL = 2;
  36977. oimo.dynamics.constraint.joint.JointType._PRISMATIC = 3;
  36978. oimo.dynamics.constraint.joint.JointType._UNIVERSAL = 4;
  36979. oimo.dynamics.constraint.joint.JointType._RAGDOLL = 5;
  36980. oimo.dynamics.constraint.joint.JointType._GENERIC = 6;
  36981. oimo.dynamics.constraint.joint.JointType.SPHERICAL = 0;
  36982. oimo.dynamics.constraint.joint.JointType.REVOLUTE = 1;
  36983. oimo.dynamics.constraint.joint.JointType.CYLINDRICAL = 2;
  36984. oimo.dynamics.constraint.joint.JointType.PRISMATIC = 3;
  36985. oimo.dynamics.constraint.joint.JointType.UNIVERSAL = 4;
  36986. oimo.dynamics.constraint.joint.JointType.RAGDOLL = 5;
  36987. oimo.dynamics.constraint.joint.JointType.GENERIC = 6;
  36988. oimo.dynamics.constraint.solver.ConstraintSolverType._ITERATIVE = 0;
  36989. oimo.dynamics.constraint.solver.ConstraintSolverType._DIRECT = 1;
  36990. oimo.dynamics.constraint.solver.ConstraintSolverType.ITERATIVE = 0;
  36991. oimo.dynamics.constraint.solver.ConstraintSolverType.DIRECT = 1;
  36992. oimo.dynamics.rigidbody.RigidBodyType._DYNAMIC = 0;
  36993. oimo.dynamics.rigidbody.RigidBodyType._STATIC = 1;
  36994. oimo.dynamics.rigidbody.RigidBodyType._KINEMATIC = 2;
  36995. oimo.dynamics.rigidbody.RigidBodyType.DYNAMIC = 0;
  36996. oimo.dynamics.rigidbody.RigidBodyType.STATIC = 1;
  36997. oimo.dynamics.rigidbody.RigidBodyType.KINEMATIC = 2;
  36998. export {oimo};